Cycles: svn merge -r41225:41232 ^/trunk/blender
[blender.git] / source / gameengine / GamePlayer / ghost / GPG_ghost.cpp
index 0ab6da240ce43f2d91b49e8745f9c13abeeff6a3..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
@@ -47,7 +45,6 @@
 //#include <Carbon/Carbon.h>
 //#include <CFBundle.h>
 #endif // __APPLE__
-#include "GEN_messaging.h"
 #include "KX_KetsjiEngine.h"
 #include "KX_PythonInit.h"
 
@@ -63,22 +60,23 @@ extern "C"
 #include "BKE_global.h"        
 #include "BKE_icons.h" 
 #include "BKE_node.h"  
-#include "BKE_report.h"        
+#include "BKE_report.h"
+#include "BKE_library.h"
+#include "BLI_threads.h"
 #include "BLI_blenlib.h"
 #include "DNA_scene_types.h"
 #include "DNA_userdef_types.h"
 #include "BLO_readfile.h"
-#include "BLO_readblenfile.h"
+#include "BLO_runtime.h"
 #include "IMB_imbuf.h"
 #include "BKE_text.h"
+#include "BKE_sound.h"
        
        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[];
 
@@ -92,7 +90,7 @@ extern char datatoc_bfont_ttf[];
 * End Blender include block
 **********************************/
 
-#include "SYS_System.h"
+#include "BL_System.h"
 #include "GPG_Application.h"
 
 #include "GHOST_ISystem.h"
@@ -113,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);
@@ -306,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;
@@ -314,11 +310,11 @@ static BlendFileData *load_game_data(char *progname, char *filename = NULL, char
        BKE_reports_init(&reports, RPT_STORE);
        
        /* try to load ourself, will only work if we are a runtime */
-       if (blo_is_a_runtime(progname)) {
-               bfd= blo_read_runtime(progname, &reports);
+       if (BLO_is_a_runtime(progname)) {
+               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);
@@ -346,7 +342,9 @@ int main(int argc, char** argv)
        bool fullScreen = false;
        bool fullScreenParFound = false;
        bool windowParFound = false;
+#ifdef WIN32
        bool closeConsole = true;
+#endif
        RAS_IRasterizer::StereoMode stereomode = RAS_IRasterizer::RAS_STEREO_NOSTEREO;
        bool stereoWindow = false;
        bool stereoParFound = false;
@@ -374,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);
@@ -394,8 +393,12 @@ 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();
 
@@ -403,15 +406,20 @@ int main(int argc, char** argv)
        
        initglobals();
 
-       GEN_init_messaging_system();
+       // We load our own G.main, so free the one that initglobals() gives us
+       free_main(G.main);
+       G.main = NULL;
 
        IMB_init();
 
        // 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]);
@@ -446,8 +454,13 @@ int main(int argc, char** argv)
        U.audioformat = 0x24;
        U.audiochannels = 2;
 
+       // XXX this one too
+       U.anisotropic_filter = 2;
+
+       sound_init_once();
+
        /* if running blenderplayer the last argument can't be parsed since it has to be the filename. */
-       isBlenderPlayer = !blo_is_a_runtime(argv[0]);
+       isBlenderPlayer = !BLO_is_a_runtime(argv[0]);
        if (isBlenderPlayer)
                validArguments = argc - 1;
        else
@@ -573,7 +586,9 @@ int main(int argc, char** argv)
                                break;
                        case 'c':
                                i++;
+#ifdef WIN32
                                closeConsole = false;
+#endif
                                break;
                        case 's':  // stereo
                                i++;
@@ -697,6 +712,8 @@ int main(int argc, char** argv)
                {
                        GPU_set_mipmap(0);
                }
+
+               GPU_set_anisotropic(U.anisotropic_filter);
                
                // Create the system
                if (GHOST_ISystem::createSystem() == GHOST_kSuccess)
@@ -727,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
@@ -738,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);
@@ -756,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);
@@ -780,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);
                                                
@@ -842,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));
@@ -938,6 +964,7 @@ int main(int argc, char** argv)
                                                        {
                                                                run = false;
                                                                exitstring = app.getExitString();
+                                                               gs = *app.getGlobalSettings();
                                                        }
                                                }
                                                app.StopGameEngine();
@@ -965,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();