Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2008-09-12 20:06:17 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2008-09-12 20:06:17 +0400
commit21d74deda6a26433ba36e5751ca74f0a162f3279 (patch)
tree849d7489a4d5b0b641f7d9806e63b13b2303b77c /source/gameengine
parent6ebd6cfa73aa96af2b97384242b716e75897766f (diff)
Fixes for game engine runtime on Mac OS X, there were issues
working with relative paths. Still doesn't work optimal, since paths are relative to game.blend which is in the app bundle under Contents/Resources, so other files need to be moved there manually at the moment.
Diffstat (limited to 'source/gameengine')
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_ghost.cpp96
1 files changed, 69 insertions, 27 deletions
diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
index 3a9e59c3c25..0b4fde61e1c 100644
--- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
+++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
@@ -198,7 +198,53 @@ void usage(char* program)
printf("example: %s -g show_framerate = 0 c:\\loadtest.blend\n", program);
}
-char *get_filename(int argc, char **argv) {
+static void make_absolute_filename(char *blendfilename)
+{
+ int abs = 0;
+ int filelen;
+ char cwd[FILE_MAXDIR + FILE_MAXFILE];
+ char filename[FILE_MAXDIR + FILE_MAXFILE];
+
+ cwd[0] = filename[0] = '\0';
+
+ BLI_strncpy(filename, blendfilename, sizeof(filename));
+ filelen = strlen(filename);
+
+ /* relative path checks, could do more tests here... */
+#ifdef WIN32
+ /* Account for X:/ and X:\ - should be enough */
+ if (filelen >= 3 && filename[1] == ':' && (filename[2] == '\\' || filename[2] == '/'))
+ abs = 1;
+#else
+ if (filelen >= 2 && filename[0] == '/')
+ abs = 1 ;
+#endif
+ if (!abs) {
+ BLI_getwdN(cwd); /* incase the full path to the blend isnt used */
+
+ if (cwd[0] == '\0') {
+ printf(
+ "Could not get the current working directory - $PWD for an unknown reason.\n\t"
+ "Relative linked files will not load if the entire blend path is not used.\n\t"
+ "The 'Play' button may also fail.\n"
+ );
+ } else {
+ /* uses the blend path relative to cwd important for loading relative linked files.
+ *
+ * cwd should contain c:\ etc on win32 so the relbase can be NULL
+ * relbase being NULL also prevents // being misunderstood as relative to the current
+ * blend file which isnt a feature we want to use in this case since were dealing
+ * with a path from the command line, rather then from inside Blender */
+
+ BLI_make_file_string(NULL, filename, cwd, blendfilename);
+ }
+ }
+
+ BLI_strncpy(blendfilename, filename, sizeof(filename));
+}
+
+static void get_filename(int argc, char **argv, char *filename)
+{
#ifdef __APPLE__
/* On Mac we park the game file (called game.blend) in the application bundle.
* The executable is located in the bundle as well.
@@ -206,22 +252,18 @@ char *get_filename(int argc, char **argv) {
*/
int srclen = ::strlen(argv[0]);
int len = 0;
- char *filename = NULL;
+ char *gamefile = NULL;
+ filename[0] = '\0';
+
if (argc > 1) {
if (BLI_exists(argv[argc-1])) {
- len = ::strlen(argv[argc-1]);
- filename = new char [len + 1];
- ::strcpy(filename, argv[argc-1]);
- return(filename);
+ BLI_strncpy(filename, argv[argc-1], FILE_MAXDIR + FILE_MAXFILE);
}
if (::strncmp(argv[argc-1], "-psn_", 5)==0) {
static char firstfilebuf[512];
if (GHOST_HACK_getFirstFile(firstfilebuf)) {
- len = ::strlen(firstfilebuf);
- filename = new char [len + 1];
- ::strcpy(filename, firstfilebuf);
- return(filename);
+ BLI_strncpy(filename, firstfilebuf, FILE_MAXDIR + FILE_MAXFILE);
}
}
}
@@ -229,23 +271,26 @@ char *get_filename(int argc, char **argv) {
srclen -= ::strlen("MacOS/blenderplayer");
if (srclen > 0) {
len = srclen + ::strlen("Resources/game.blend");
- filename = new char [len + 1];
- ::strcpy(filename, argv[0]);
- ::strcpy(filename + srclen, "Resources/game.blend");
+ gamefile = new char [len + 1];
+ ::strcpy(gamefile, argv[0]);
+ ::strcpy(gamefile + srclen, "Resources/game.blend");
//::printf("looking for file: %s\n", filename);
- if (BLI_exists(filename)) {
- return (filename);
- }
+ if (BLI_exists(gamefile))
+ BLI_strncpy(filename, gamefile, FILE_MAXDIR + FILE_MAXFILE);
+
+ delete gamefile;
}
- return(NULL);
#else
- return (argc>1)?argv[argc-1]:NULL;
+ filename[0] = '\0';
+
+ if(argc > 1)
+ BLI_strncpy(filename, argv[argc-1], FILE_MAXDIR + FILE_MAXFILE);
#endif // !_APPLE
}
-static BlendFileData *load_game_data(char *progname, char *filename = NULL) {
+static BlendFileData *load_game_data(char *progname, char *filename = NULL, char *relativename = NULL) {
BlendReadError error;
BlendFileData *bfd = NULL;
@@ -579,9 +624,12 @@ int main(int argc, char** argv)
STR_String exitstring = "";
GPG_Application app(system);
bool firstTimeRunning = true;
- char *filename = get_filename(argc, argv);
+ char filename[FILE_MAXDIR + FILE_MAXFILE];
char *titlename;
char pathname[160];
+
+ get_filename(argc, argv, filename);
+ make_absolute_filename(filename);
do
{
@@ -613,7 +661,7 @@ int main(int argc, char** argv)
}
else
{
- bfd = load_game_data(bprogname, filename);
+ bfd = load_game_data(bprogname, filename[0]? filename: NULL);
}
//::printf("game data loaded from %s\n", filename);
@@ -782,12 +830,6 @@ int main(int argc, char** argv)
pyGlobalDictString_Length = app.GetPyGlobalDictMarshalLength();
BLO_blendfiledata_free(bfd);
-
-#ifdef __APPLE__
- if (filename) {
- delete [] filename;
- }
-#endif // __APPLE__
}
} while (exitcode == KX_EXIT_REQUEST_RESTART_GAME || exitcode == KX_EXIT_REQUEST_START_OTHER_GAME);
}