diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-10-11 04:56:49 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-10-11 04:56:49 +0400 |
commit | 9b948cad08067a6bedd49ccfb059874aba7555b9 (patch) | |
tree | 5fc5236ab893aaaadec1a83081b923ededd24e32 | |
parent | c3aef29ab704ba7ca9ec401ad0028d21d8b431be (diff) |
Fix for a relative paths issue in the game engine. G.sce was being
kept as the original file, but that can't work correct for solving
relative paths once a .blend in another directory is loaded. The
reason it went OK with the apricot tech demo is that the images there
were lib linked into the level file, which still worked.
Now it sets G.sce to the current loaded .blend file. Note that the
python config file path still uses the first loaded .blend file so it
looks in the same location each time.
Also added some NULL pointer checks in the joystick code because it
was crashing there on Mac, there's similar checks in related functions
so I'm assuming this was just a missed case.
6 files changed, 54 insertions, 32 deletions
diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp index ffc32a3ad97..1442458269b 100644 --- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp +++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp @@ -70,6 +70,7 @@ #include "DNA_view3d_types.h" #include "DNA_screen_types.h" #include "BKE_global.h" +#include "BKE_utildefines.h" #include "BIF_screen.h" #include "BIF_scrarea.h" @@ -110,11 +111,14 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, Main* blenderdata = maggie1; char* startscenename = scenename; - char pathname[160]; - strcpy (pathname, blenderdata->name); + char pathname[FILE_MAXDIR+FILE_MAXFILE], oldsce[FILE_MAXDIR+FILE_MAXFILE]; STR_String exitstring = ""; BlendFileData *bfd= NULL; + BLI_strncpy(pathname, blenderdata->name, sizeof(pathname)); + BLI_strncpy(oldsce, G.sce, sizeof(oldsce)); + setGamePythonPath(G.sce); + // Acquire Python's GIL (global interpreter lock) // so we can safely run Python code and API calls PyGILState_STATE gilstate = PyGILState_Ensure(); @@ -240,9 +244,14 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, char basedpath[240]; // base the actuator filename with respect // to the original file working directory + if (exitstring != "") strcpy(basedpath, exitstring.Ptr()); + // load relative to the last loaded file, this used to be relative + // to the first file but that makes no sense, relative paths in + // blend files should be relative to that file, not some other file + // that happened to be loaded first BLI_convertstringcode(basedpath, pathname); bfd = load_game_data(basedpath); @@ -263,6 +272,11 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, { blenderdata = bfd->main; startscenename = bfd->curscene->id.name + 2; + + if(blenderdata) { + BLI_strncpy(G.sce, blenderdata->name, sizeof(G.sce)); + BLI_strncpy(pathname, blenderdata->name, sizeof(pathname)); + } } // else forget it, we can't find it else @@ -507,6 +521,8 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, if (bfd) BLO_blendfiledata_free(bfd); + BLI_strncpy(G.sce, oldsce, sizeof(G.sce)); + // Release Python's GIL PyGILState_Release(gilstate); } @@ -522,10 +538,10 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area, Main* blenderdata = maggie; char* startscenename = scenename; - char pathname[160]; - strcpy (pathname, maggie->name); + char pathname[FILE_MAXDIR+FILE_MAXFILE]; STR_String exitstring = ""; - BlendFileData *bfd= NULL; + + BLI_strncpy(pathname, blenderdata->name, sizeof(pathname)); // Acquire Python's GIL (global interpreter lock) // so we can safely run Python code and API calls @@ -583,20 +599,17 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area, KX_KetsjiEngine* ketsjiengine = new KX_KetsjiEngine(kxsystem); Scene *blscene = NULL; - if (!bfd) + + blscene = (Scene*) maggie->scene.first; + for (Scene *sce= (Scene*) maggie->scene.first; sce; sce= (Scene*) sce->id.next) { - blscene = (Scene*) maggie->scene.first; - for (Scene *sce= (Scene*) maggie->scene.first; sce; sce= (Scene*) sce->id.next) + if (startscenename == (sce->id.name+2)) { - if (startscenename == (sce->id.name+2)) - { - blscene = sce; - break; - } + blscene = sce; + break; } - } else { - blscene = bfd->curscene; } + int cframe = 1, startFrame; if (blscene) { @@ -717,7 +730,6 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area, SND_DeviceManager::Unsubscribe(); } while (exitrequested == KX_EXIT_REQUEST_RESTART_GAME || exitrequested == KX_EXIT_REQUEST_START_OTHER_GAME); - if (bfd) BLO_blendfiledata_free(bfd); // Release Python's GIL PyGILState_Release(gilstate); diff --git a/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp b/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp index 89e2420f822..73ca288861d 100644 --- a/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp +++ b/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp @@ -89,7 +89,8 @@ void SCA_Joystick::HandleEvents(void) int i; for (i=0; i<JOYINDEX_MAX; i++) { - SCA_Joystick::m_instance[i]->OnNothing(&sdl_event); + if(SCA_Joystick::m_instance[i]) + SCA_Joystick::m_instance[i]->OnNothing(&sdl_event); } if(SDL_PollEvent(&sdl_event)) diff --git a/source/gameengine/GameLogic/SCA_JoystickManager.cpp b/source/gameengine/GameLogic/SCA_JoystickManager.cpp index d874b5b013a..f3ce549a637 100644 --- a/source/gameengine/GameLogic/SCA_JoystickManager.cpp +++ b/source/gameengine/GameLogic/SCA_JoystickManager.cpp @@ -51,7 +51,8 @@ SCA_JoystickManager::~SCA_JoystickManager() { int i; for (i=0; i<JOYINDEX_MAX; i++) { - m_joystick[i]->ReleaseInstance(); + if(m_joystick[i]) + m_joystick[i]->ReleaseInstance(); } } diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp index fbb8d6530ba..0bf0317d8f2 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp @@ -44,6 +44,7 @@ #endif // __APPLE__ #include "GEN_messaging.h" #include "KX_KetsjiEngine.h" +#include "KX_PythonInit.h" /********************************** * Begin Blender include block @@ -599,8 +600,8 @@ int main(int argc, char** argv) GPG_Application app(system); bool firstTimeRunning = true; char filename[FILE_MAXDIR + FILE_MAXFILE]; + char pathname[FILE_MAXDIR + FILE_MAXFILE]; char *titlename; - char pathname[160]; get_filename(argc, argv, filename); if(filename[0]) @@ -616,8 +617,7 @@ int main(int argc, char** argv) { char basedpath[240]; - // base the actuator filename with respect - // to the original file working directory + // base the actuator filename relative to the last file strcpy(basedpath, exitstring.Ptr()); BLI_convertstringcode(basedpath, pathname); @@ -700,15 +700,14 @@ int main(int argc, char** argv) // GPG_Application app (system, maggie, startscenename); app.SetGameEngineData(maggie, scene); + BLI_strncpy(pathname, maggie->name, sizeof(pathname)); + BLI_strncpy(G.sce, maggie->name, sizeof(G.sce)); + if (firstTimeRunning) { + setGamePythonPath(G.sce); 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 cdf7ebd0943..a30d9f4022d 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -97,6 +97,7 @@ static RAS_ICanvas* gp_Canvas = NULL; static KX_Scene* gp_KetsjiScene = NULL; static KX_KetsjiEngine* gp_KetsjiEngine = NULL; static RAS_IRasterizer* gp_Rasterizer = NULL; +static char gp_GamePythonPath[FILE_MAXDIR + FILE_MAXFILE] = ""; void KX_RasterizerDrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color) { @@ -155,7 +156,7 @@ static PyObject* gPyExpandPath(PyObject*, PyObject* args) return NULL; BLI_strncpy(expanded, filename, FILE_MAXDIR + FILE_MAXFILE); - BLI_convertstringcode(expanded, G.sce); + BLI_convertstringcode(expanded, gp_GamePythonPath); return PyString_FromString(expanded); } @@ -281,7 +282,7 @@ static PyObject* gPyGetAverageFrameRate(PyObject*) static PyObject* gPyGetBlendFileList(PyObject*, PyObject* args) { - char cpath[sizeof(G.sce)]; + char cpath[sizeof(gp_GamePythonPath)]; char *searchpath = NULL; PyObject* list, *value; @@ -295,10 +296,10 @@ static PyObject* gPyGetBlendFileList(PyObject*, PyObject* args) if (searchpath) { BLI_strncpy(cpath, searchpath, FILE_MAXDIR + FILE_MAXFILE); - BLI_convertstringcode(cpath, G.sce); + BLI_convertstringcode(cpath, gp_GamePythonPath); } else { /* Get the dir only */ - BLI_split_dirfile_basic(G.sce, cpath, NULL); + BLI_split_dirfile_basic(gp_GamePythonPath, cpath, NULL); } if((dp = opendir(cpath)) == NULL) { @@ -1541,9 +1542,10 @@ int loadGamePythonConfig(char *marshal_buffer, int marshal_length) void pathGamePythonConfig( char *path ) { - int len = strlen(G.sce); + int len = strlen(gp_GamePythonPath); - strncpy(path, G.sce, sizeof(G.sce)); + BLI_strncpy(path, gp_GamePythonPath, sizeof(gp_GamePythonPath)); + /* replace extension */ if (BLI_testextensie(path, ".blend")) { strcpy(path+(len-6), ".bgeconf"); @@ -1551,3 +1553,9 @@ void pathGamePythonConfig( char *path ) strcpy(path+len, ".bgeconf"); } } + +void setGamePythonPath(char *path) +{ + BLI_strncpy(gp_GamePythonPath, path, sizeof(gp_GamePythonPath)); +} + diff --git a/source/gameengine/Ketsji/KX_PythonInit.h b/source/gameengine/Ketsji/KX_PythonInit.h index 28d9d72a4c3..36e3db6ec35 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.h +++ b/source/gameengine/Ketsji/KX_PythonInit.h @@ -49,6 +49,7 @@ void exitGamePlayerPythonScripting(); PyObject* initGamePythonScripting(const STR_String& progname, TPythonSecurityLevel level); void exitGamePythonScripting(); +void setGamePythonPath(char *path); void pathGamePythonConfig( char *path ); int saveGamePythonConfig( char **marshal_buffer); int loadGamePythonConfig(char *marshal_buffer, int marshal_length); |