Cycles: svn merge -r41225:41232 ^/trunk/blender
[blender.git] / source / gameengine / GamePlayer / ghost / GPG_ghost.cpp
index cbbeb9419d185483d64fdde5fb312d3d6c4b874b..fb07918ec5c3237a7a5386a7db175aa9b4d913f0 100644 (file)
@@ -1,6 +1,4 @@
 /*
-* $Id$
-*
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -25,8 +23,8 @@
  * Contributor(s): none yet.
  *
  * ***** END GPL LICENSE BLOCK *****
-* Start up of the Blender Player on GHOST.
-*/
+ * Start up of the Blender Player on GHOST.
+ */
 
 /** \file gameengine/GamePlayer/ghost/GPG_ghost.cpp
  *  \ingroup player
@@ -76,11 +74,9 @@ extern "C"
        
        int GHOST_HACK_getFirstFile(char buf[]);
        
-extern char bprogname[];       /* holds a copy of argv[0], from creator.c */
-extern char btempdir[];                /* use this to store a valid temp directory */
-
 // For BLF
 #include "BLF_api.h"
+#include "BLF_translation.h"
 extern int datatoc_bfont_ttf_size;
 extern char datatoc_bfont_ttf[];
 
@@ -115,8 +111,6 @@ extern char datatoc_bfont_ttf[];
 const int kMinWindowWidth = 100;
 const int kMinWindowHeight = 100;
 
-char bprogname[FILE_MAX];
-
 static void mem_error_cb(const char *errorStr)
 {
        fprintf(stderr, "%s", errorStr);
@@ -308,7 +302,7 @@ static void get_filename(int argc, char **argv, char *filename)
 #endif // !_APPLE
 }
 
-static BlendFileData *load_game_data(char *progname, char *filename = NULL, char *relativename = NULL)
+static BlendFileData *load_game_data(const char *progname, char *filename = NULL, char *relativename = NULL)
 {
        ReportList reports;
        BlendFileData *bfd = NULL;
@@ -320,7 +314,7 @@ static BlendFileData *load_game_data(char *progname, char *filename = NULL, char
                bfd= BLO_read_runtime(progname, &reports);
                if (bfd) {
                        bfd->type= BLENFILETYPE_RUNTIME;
-                       strcpy(bfd->main->name, progname);
+                       BLI_strncpy(bfd->main->name, progname, sizeof(bfd->main->name));
                }
        } else {
                bfd= BLO_read_from_file(progname, &reports);
@@ -378,14 +372,15 @@ int main(int argc, char** argv)
        signal (SIGFPE, SIG_IGN);
 #endif /* __alpha__ */
 #endif /* __linux__ */
-       BLI_where_am_i(bprogname, sizeof(bprogname), argv[0]);
+       BLI_init_program_path(argv[0]);
+       BLI_init_temporary_dir(NULL);
 #ifdef __APPLE__
-    // Can't use Carbon right now because of double defined type ID (In Carbon.h and DNA_ID.h, sigh)
-    /*
-    IBNibRef           nibRef;
-    WindowRef          window;
-    OSStatus           err;
-       
+       // Can't use Carbon right now because of double defined type ID (In Carbon.h and DNA_ID.h, sigh)
+       /*
+       IBNibRef                nibRef;
+       WindowRef               window;
+       OSStatus                err;
+
          // Create a Nib reference passing the name of the nib file (without the .nib extension)
          // CreateNibReference only searches into the application bundle.
          err = ::CreateNibReference(CFSTR("main"), &nibRef);
@@ -398,13 +393,13 @@ int main(int argc, char** argv)
                
                  // We don't need the nib reference anymore.
                  ::DisposeNibReference(nibRef);
-    */
+       */
 #endif // __APPLE__
        
        // We don't use threads directly in the BGE, but we need to call this so things like
        // freeing up GPU_Textures works correctly.
        BLI_threadapi_init();
-       
+
        RNA_init();
 
        init_nodesystem();
@@ -420,8 +415,11 @@ int main(int argc, char** argv)
        // Setup builtin font for BLF (mostly copied from creator.c, wm_init_exit.c and interface_style.c)
        BLF_init(11, U.dpi);
        BLF_lang_init();
+       BLF_lang_encoding("");
+       BLF_lang_set("");
+
        BLF_load_mem("default", (unsigned char*)datatoc_bfont_ttf, datatoc_bfont_ttf_size);
+
        // Parse command line options
 #if defined(DEBUG)
        printf("argv[0] = '%s'\n", argv[0]);
@@ -746,6 +744,11 @@ int main(int argc, char** argv)
                                if(filename[0])
                                        BLI_path_cwd(filename);
                                
+
+                               // fill the GlobalSettings with the first scene files
+                               // those may change during the game and persist after using Game Actuator
+                               GlobalSettings gs;
+
                                do
                                {
                                        // Read the Blender file
@@ -757,7 +760,7 @@ int main(int argc, char** argv)
                                                char basedpath[240];
                                                
                                                // base the actuator filename relative to the last file
-                                               strcpy(basedpath, exitstring.Ptr());
+                                               BLI_strncpy(basedpath, exitstring.Ptr(), sizeof(basedpath));
                                                BLI_path_abs(basedpath, pathname);
                                                
                                                bfd = load_game_data(basedpath);
@@ -775,7 +778,7 @@ int main(int argc, char** argv)
                                        }
                                        else
                                        {
-                                               bfd = load_game_data(bprogname, filename[0]? filename: NULL);
+                                               bfd = load_game_data(BLI_program_path(), filename[0]? filename: NULL);
                                        }
                                        
                                        //::printf("game data loaded from %s\n", filename);
@@ -799,9 +802,13 @@ int main(int argc, char** argv)
                                                Scene *scene = bfd->curscene;
                                                G.main = maggie;
 
-                                               if (firstTimeRunning)
+                                               if (firstTimeRunning) {
                                                        G.fileflags  = bfd->fileflags;
 
+                                                       gs.matmode= scene->gm.matmode;
+                                                       gs.glslflag= scene->gm.flag;
+                                               }
+
                                                //Seg Fault; icon.c gIcons == 0
                                                BKE_icons_init(1);
                                                
@@ -861,7 +868,7 @@ int main(int argc, char** argv)
                                                }
                                                
                                                //                                      GPG_Application app (system, maggie, startscenename);
-                                               app.SetGameEngineData(maggie, scene, argc, argv); /* this argc cant be argc_py_clamped, since python uses it */
+                                               app.SetGameEngineData(maggie, scene, &gs, argc, argv); /* this argc cant be argc_py_clamped, since python uses it */
                                                BLI_strncpy(pathname, maggie->name, sizeof(pathname));
                                                if(G.main != maggie) {
                                                        BLI_strncpy(G.main->name, maggie->name, sizeof(G.main->name));
@@ -957,6 +964,7 @@ int main(int argc, char** argv)
                                                        {
                                                                run = false;
                                                                exitstring = app.getExitString();
+                                                               gs = *app.getGlobalSettings();
                                                        }
                                                }
                                                app.StopGameEngine();
@@ -984,6 +992,11 @@ int main(int argc, char** argv)
        // Cleanup
        RNA_exit();
        BLF_exit();
+
+#ifdef WITH_INTERNATIONAL
+       BLF_free_unifont();
+#endif
+
        IMB_exit();
        free_nodesystem();