diff options
author | Benoit Bolsee <benoit.bolsee@online.be> | 2008-05-11 22:45:30 +0400 |
---|---|---|
committer | Benoit Bolsee <benoit.bolsee@online.be> | 2008-05-11 22:45:30 +0400 |
commit | 96486b356f7d035a7abc835adbef850c3f314264 (patch) | |
tree | 29a66d4ec0ef0b8188be7deed6ba818114ff7d39 /source/gameengine | |
parent | 6da415d406c5d46852aac65a4920fbf4a89d4fa7 (diff) |
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
Diffstat (limited to 'source/gameengine')
-rw-r--r-- | source/gameengine/GamePlayer/ghost/GPG_ghost.cpp | 25 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_PythonInit.cpp | 31 | ||||
-rw-r--r-- | source/gameengine/PyDoc/GameLogic.py | 15 |
3 files changed, 66 insertions, 5 deletions
diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp index 8817bc98886..bc80c0a7612 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp @@ -562,13 +562,13 @@ int main(int argc, char** argv) 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 @@ int main(int argc, char** argv) 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 @@ int main(int argc, char** argv) #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 @@ int main(int argc, char** argv) 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 diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index a2aff54d385..a80a7f04e8f 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -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,6 +144,32 @@ static PyObject* gPySetGravity(PyObject*, 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; @@ -361,6 +391,7 @@ static PyObject *pyPrintExt(PyObject *,PyObject *,PyObject *) static struct PyMethodDef game_methods[] = { + {"expandPath", (PyCFunction)gPyExpandPath, METH_VARARGS, gPyExpandPath_doc}, {"getCurrentController", (PyCFunction) SCA_PythonController::sPyGetCurrentController, METH_VARARGS, SCA_PythonController::sPyGetCurrentController__doc__}, diff --git a/source/gameengine/PyDoc/GameLogic.py b/source/gameengine/PyDoc/GameLogic.py index fcfd8bfc4eb..965c0522bd7 100644 --- a/source/gameengine/PyDoc/GameLogic.py +++ b/source/gameengine/PyDoc/GameLogic.py @@ -221,3 +221,18 @@ def setPhysicsTicRate(ticrate): @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 + """ |