[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14798] trunk/blender/source/gameengine: fix BGE bug #8668: Behavior of os.getcwd() is not consistent between operating systems
Benoit Bolsee
benoit.bolsee at online.be
Sun May 11 20:45:30 CEST 2008
Revision: 14798
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14798
Author: ben2610
Date: 2008-05-11 20:45:30 +0200 (Sun, 11 May 2008)
Log Message:
-----------
fix BGE bug #8668: Behavior of os.getcwd() is not consistent between operating systems
Add a function GameLogic.expandPath() that works like Blender.sys.expandpath() and is also available in the BlenderPlayer.
Fix the game actuator in the BlenderPlayer to work like in Blender:
- try first to load the .blend from the current working directory
- if not found, try to load from the startup .blend or runtime base directory
Modified Paths:
--------------
trunk/blender/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
trunk/blender/source/gameengine/PyDoc/GameLogic.py
Modified: trunk/blender/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
===================================================================
--- trunk/blender/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp 2008-05-11 14:29:11 UTC (rev 14797)
+++ trunk/blender/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp 2008-05-11 18:45:30 UTC (rev 14798)
@@ -562,13 +562,13 @@
STR_String exitstring = "";
GPG_Application app(system, NULL, exitstring);
bool firstTimeRunning = true;
+ char *filename = get_filename(argc, argv);
+ char *titlename;
+ char pathname[160];
do
{
// Read the Blender file
- char *filename = get_filename(argc, argv);
- char *titlename;
- char pathname[160];
BlendFileData *bfd;
// if we got an exitcode 3 (KX_EXIT_REQUEST_START_OTHER_GAME) load a different file
@@ -582,6 +582,17 @@
BLI_convertstringcode(basedpath, pathname);
bfd = load_game_data(basedpath);
+
+ if (!bfd)
+ {
+ // just add "//" in front of it
+ char temppath[242];
+ strcpy(temppath, "//");
+ strcat(temppath, basedpath);
+
+ BLI_convertstringcode(temppath, pathname);
+ bfd = load_game_data(temppath);
+ }
}
else
{
@@ -607,7 +618,6 @@
#endif // WIN32
Main *maggie = bfd->main;
Scene *scene = bfd->curscene;
- strcpy (pathname, maggie->name);
char *startscenename = scene->id.name + 2;
G.fileflags = bfd->fileflags;
@@ -651,7 +661,12 @@
if (firstTimeRunning)
{
firstTimeRunning = false;
-
+
+ // set the filename only the first time as in KetsjiEmbedded
+ strcpy (pathname, maggie->name);
+ // also copy here (used by GameLogic.getBaseDirectory)
+ strcpy (G.sce, maggie->name);
+
if (fullScreen)
{
#ifdef WIN32
Modified: trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp 2008-05-11 14:29:11 UTC (rev 14797)
+++ trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp 2008-05-11 18:45:30 UTC (rev 14798)
@@ -88,6 +88,10 @@
//#include "BPY_extern.h"
#endif
+#include "BKE_utildefines.h"
+#include "BKE_global.h"
+#include "BLI_blenlib.h"
+
static void setSandbox(TPythonSecurityLevel level);
@@ -140,7 +144,33 @@
return NULL;
}
+static char gPyExpandPath_doc[] =
+"(path) - Converts a blender internal path into a proper file system path.\n\
+path - the string path to convert.\n\n\
+Use / as directory separator in path\n\
+You can use '//' at the start of the string to define a relative path;\n\
+Blender replaces that string by the directory of the startup .blend or runtime\n\
+file to make a full path name (doesn't change during the game, even if you load\n\
+other .blend).\n\
+The function also converts the directory separator to the local file system format.";
+static PyObject* gPyExpandPath(PyObject*,
+ PyObject* args,
+ PyObject*)
+{
+ char expanded[FILE_MAXDIR + FILE_MAXFILE];
+ char* filename;
+
+ if (PyArg_ParseTuple(args,"s",&filename))
+ {
+ BLI_strncpy(expanded, filename, FILE_MAXDIR + FILE_MAXFILE);
+ BLI_convertstringcode(expanded, G.sce);
+ return PyString_FromString(expanded);
+ }
+ return NULL;
+}
+
+
static bool usedsp = false;
// this gets a pointer to an array filled with floats
@@ -361,6 +391,7 @@
static struct PyMethodDef game_methods[] = {
+ {"expandPath", (PyCFunction)gPyExpandPath, METH_VARARGS, gPyExpandPath_doc},
{"getCurrentController",
(PyCFunction) SCA_PythonController::sPyGetCurrentController,
METH_VARARGS, SCA_PythonController::sPyGetCurrentController__doc__},
Modified: trunk/blender/source/gameengine/PyDoc/GameLogic.py
===================================================================
--- trunk/blender/source/gameengine/PyDoc/GameLogic.py 2008-05-11 14:29:11 UTC (rev 14797)
+++ trunk/blender/source/gameengine/PyDoc/GameLogic.py 2008-05-11 18:45:30 UTC (rev 14798)
@@ -221,3 +221,18 @@
@type ticrate: float
"""
+def expandPath(path):
+ """
+ Converts a blender internal path into a proper file system path.
+
+ Use / as directory separator in path
+ You can use '//' at the start of the string to define a relative path;
+ Blender replaces that string by the directory of the startup .blend or runtime file
+ to make a full path name (doesn't change during the game, even if you load other .blend).
+ The function also converts the directory separator to the local file system format.
+
+ @param path: The path string to be converted/expanded.
+ @type path: string
+ @return: The converted string
+ @rtype: string
+ """
More information about the Bf-blender-cvs
mailing list