Revision: 40113
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40113
Author:   dfelinto
Date:     2011-09-11 05:54:07 +0000 (Sun, 11 Sep 2011)
Log Message:
-----------
bugfix: [bf-blender-Game Engine][28167] Restart game actuator don't get changed 
material mode

http://projects.blender.org/tracker/?func=detail&aid=28167&group_id=9&atid=306
Game Actuator (restart or load a new file) will not keep some settings alive (as
we had in 2.49).

In 2.49 the solution used was to use Blender globals (G.fileflags) to get/set
those settings. That was causing the blender file to change if you change the
material mode from the game.

In 2.5 this never worked, and the implementation was buggy (it's relying in the
scene settings, which get reset ever time we restart/load a new file).

My idea for fixing this is to create a new struct (GlobalSettings) where we
store any setting to be preserver during the course of the game. This is
specially important for options that require the game to restart/load new file
(graphic ones). But it later can be expanded to support other things such as
audio settings (e.g. volume), ...
I'm also planning to expand it for stereo and dome settings, but I prefer to
first get this committed and then build a new patch on top of that.


I had some problems in finding a correct way for build/link the blenderplayer
changes, so although it's working I'm not sure this is the best code (e.g. I
couldn't make forward declaration to work in GPG_Application.h for the struct
GlobalSettings so I ended up including KX_KetsjiEngine.h)

[note: I talked with Brecht and he find this is an ok solution. He implemented
it originally so it's good to have his go. However I still think there must be 
a way to make forward declaration to work. I will see with other devs if there 
is a better solution]
[also I'm likely renaming glsl to flags later if there are more settings stored 
in the flags to be used. But for now we are only handling glsl flags]

Modified Paths:
--------------
    trunk/blender/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
    trunk/blender/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
    trunk/blender/source/gameengine/GamePlayer/ghost/GPG_Application.h
    trunk/blender/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
    trunk/blender/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
    trunk/blender/source/gameengine/Ketsji/KX_KetsjiEngine.h
    trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp

Modified: 
trunk/blender/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
===================================================================
--- trunk/blender/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp     
2011-09-11 05:50:44 UTC (rev 40112)
+++ trunk/blender/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp     
2011-09-11 05:54:07 UTC (rev 40113)
@@ -169,6 +169,11 @@
        int disableVBO = (U.gameflags & USER_DISABLE_VBO);
        U.gameflags |= USER_DISABLE_VBO;
 
+       // Globals to be carried on over blender files
+       GlobalSettings gs;
+       gs.matmode= startscene->gm.matmode;
+       gs.glslflag= startscene->gm.flag;
+
        do
        {
                View3D *v3d= CTX_wm_view3d(C);
@@ -239,6 +244,9 @@
                ketsjiengine->SetTimingDisplay(frameRate, profile, properties);
                ketsjiengine->SetRestrictAnimationFPS(restrictAnimFPS);
 
+               //set the global settings (carried over if restart/load new 
files)
+               ketsjiengine->SetGlobalSettings(&gs);
+
 #ifdef WITH_PYTHON
                CValue::SetDeprecationWarnings(nodepwarnings);
 #endif
@@ -370,12 +378,12 @@
 
                        if(GPU_glsl_support())
                                useglslmat = true;
-                       else if(scene->gm.matmode == GAME_MAT_GLSL)
+                       else if(gs.matmode == GAME_MAT_GLSL)
                                usemat = false;
 
-                       if(usemat && (scene->gm.matmode != GAME_MAT_TEXFACE))
+                       if(usemat && (gs.matmode != GAME_MAT_TEXFACE))
                                sceneconverter->SetMaterials(true);
-                       if(useglslmat && (scene->gm.matmode == GAME_MAT_GLSL))
+                       if(useglslmat && (gs.matmode == GAME_MAT_GLSL))
                                sceneconverter->SetGLSLMaterials(true);
                                        
                        KX_Scene* startscene = new KX_Scene(keyboarddevice,
@@ -494,6 +502,7 @@
                                }
                                printf("Blender Game Engine Finished\n");
                                exitstring = ketsjiengine->GetExitString();
+                               gs = *(ketsjiengine->GetGlobalSettings());
 
 
                                // when exiting the mainloop

Modified: trunk/blender/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
===================================================================
--- trunk/blender/source/gameengine/GamePlayer/ghost/GPG_Application.cpp        
2011-09-11 05:50:44 UTC (rev 40112)
+++ trunk/blender/source/gameengine/GamePlayer/ghost/GPG_Application.cpp        
2011-09-11 05:54:07 UTC (rev 40113)
@@ -151,7 +151,7 @@
 
 
 
-bool GPG_Application::SetGameEngineData(struct Main* maggie, Scene *scene, int 
argc, char **argv)
+bool GPG_Application::SetGameEngineData(struct Main* maggie, Scene *scene, 
GlobalSettings *gs, int argc, char **argv)
 {
        bool result = false;
 
@@ -168,6 +168,9 @@
        m_argc= argc;
        m_argv= argv;
 
+       /* Global Settings */
+       m_globalSettings= gs;
+
        return result;
 }
 
@@ -511,7 +514,13 @@
 }
 
 
+GlobalSettings* GPG_Application::getGlobalSettings(void)
+{
+       return m_ketsjiengine->GetGlobalSettings();
+}
 
+
+
 const STR_String& GPG_Application::getExitString(void)
 {
        return m_exitString;
@@ -552,7 +561,7 @@
 
                if(GPU_glsl_support())
                        m_blenderglslmat = (SYS_GetCommandLineInt(syshandle, 
"blender_glsl_material", 1) != 0);
-               else if(gm->matmode == GAME_MAT_GLSL)
+               else if(m_globalSettings->matmode == GAME_MAT_GLSL)
                        m_blendermat = false;
 
                // create the canvas, rasterizer and rendertools
@@ -629,6 +638,9 @@
                m_ketsjiengine->SetTimingDisplay(frameRate, profile, 
properties);
                m_ketsjiengine->SetRestrictAnimationFPS(restrictAnimFPS);
 
+               //set the global settings (carried over if restart/load new 
files)
+               m_ketsjiengine->SetGlobalSettings(m_globalSettings);
+
                m_engineInitialized = true;
        }
 
@@ -685,9 +697,9 @@
 
                //      if (always_use_expand_framing)
                //              sceneconverter->SetAlwaysUseExpandFraming(true);
-               if(m_blendermat && (m_startScene->gm.matmode != 
GAME_MAT_TEXFACE))
+               if(m_blendermat && (m_globalSettings->matmode != 
GAME_MAT_TEXFACE))
                        m_sceneconverter->SetMaterials(true);
-               if(m_blenderglslmat && (m_startScene->gm.matmode == 
GAME_MAT_GLSL))
+               if(m_blenderglslmat && (m_globalSettings->matmode == 
GAME_MAT_GLSL))
                        m_sceneconverter->SetGLSLMaterials(true);
 
                KX_Scene* startscene = new KX_Scene(m_keyboard,

Modified: trunk/blender/source/gameengine/GamePlayer/ghost/GPG_Application.h
===================================================================
--- trunk/blender/source/gameengine/GamePlayer/ghost/GPG_Application.h  
2011-09-11 05:50:44 UTC (rev 40112)
+++ trunk/blender/source/gameengine/GamePlayer/ghost/GPG_Application.h  
2011-09-11 05:54:07 UTC (rev 40113)
@@ -39,6 +39,8 @@
 #include <wtypes.h>
 #endif
 
+#include "KX_KetsjiEngine.h"
+
 class KX_KetsjiEngine;
 class KX_ISceneConverter;
 class NG_LoopBackNetworkDeviceInterface;
@@ -61,7 +63,7 @@
        GPG_Application(GHOST_ISystem* system);
        ~GPG_Application(void);
 
-                       bool SetGameEngineData(struct Main* maggie, struct 
Scene* scene, int argc, char** argv);
+                       bool SetGameEngineData(struct Main* maggie, struct 
Scene* scene, GlobalSettings* gs, int argc, char** argv);
                        bool startWindow(STR_String& title, int windowLeft, int 
windowTop, int windowWidth, int windowHeight,
                        const bool stereoVisual, const int stereoMode, const 
GHOST_TUns16 samples=0);
                        bool startFullScreen(int width, int height, int bpp, 
int frequency, const bool stereoVisual, const int stereoMode, const 
GHOST_TUns16 samples=0);
@@ -74,6 +76,7 @@
        virtual bool processEvent(GHOST_IEvent* event);
                        int getExitRequested(void);
                        const STR_String& getExitString(void);
+                       GlobalSettings* getGlobalSettings(void);
                        bool StartGameEngine(int stereoMode);
                        void StopGameEngine();
 
@@ -111,6 +114,8 @@
        /* Exit state. */
        int                                             m_exitRequested;
        STR_String                              m_exitString;
+       GlobalSettings* m_globalSettings;
+
        /* GHOST system abstraction. */
        GHOST_ISystem*                  m_system;
        /* Main window. */

Modified: trunk/blender/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
===================================================================
--- trunk/blender/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp      
2011-09-11 05:50:44 UTC (rev 40112)
+++ trunk/blender/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp      
2011-09-11 05:54:07 UTC (rev 40113)
@@ -746,6 +746,11 @@
                                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
@@ -799,9 +804,13 @@
                                                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 +870,7 @@
                                                }
                                                
                                                //                              
        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 +966,7 @@
                                                        {
                                                                run = false;
                                                                exitstring = 
app.getExitString();
+                                                               gs = 
*app.getGlobalSettings();
                                                        }
                                                }
                                                app.StopGameEngine();

Modified: trunk/blender/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_KetsjiEngine.cpp  2011-09-11 
05:50:44 UTC (rev 40112)
+++ trunk/blender/source/gameengine/Ketsji/KX_KetsjiEngine.cpp  2011-09-11 
05:54:07 UTC (rev 40113)
@@ -1936,4 +1936,14 @@
        b = m_overrideFrameColorB;
 }
 
+void KX_KetsjiEngine::SetGlobalSettings(GlobalSettings* gs)
+{
+       m_globalsettings.matmode = gs->matmode;
+       m_globalsettings.glslflag = gs->glslflag;
+}
 
+GlobalSettings* KX_KetsjiEngine::GetGlobalSettings(void)
+{
+       return &m_globalsettings;
+}
+

Modified: trunk/blender/source/gameengine/Ketsji/KX_KetsjiEngine.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_KetsjiEngine.h    2011-09-11 
05:50:44 UTC (rev 40112)
+++ trunk/blender/source/gameengine/Ketsji/KX_KetsjiEngine.h    2011-09-11 
05:54:07 UTC (rev 40113)
@@ -62,6 +62,11 @@
        KX_EXIT_REQUEST_MAX
 };
 
+typedef struct {
+       short matmode;
+       short glslflag;
+}      GlobalSettings;
+
 /**
  * KX_KetsjiEngine is the core game engine class.
  */
@@ -193,6 +198,9 @@
        /** Blue component of framing bar color. */
        float                                   m_overrideFrameColorB;
 
+       /** Settings that doesn't go away with Game Actuator */
+       GlobalSettings m_globalsettings;
+
        void                                    RenderFrame(KX_Scene* scene, 
KX_Camera* cam);
        void                                    PostRenderScene(KX_Scene* 
scene);
        void                                    RenderDebugProperties();
@@ -404,7 +412,10 @@
 
        KX_Scene*               CreateScene(const STR_String& scenename);
        KX_Scene*               CreateScene(Scene *scene);
-       
+
+       GlobalSettings* GetGlobalSettings(void);        
+       void                    SetGlobalSettings(GlobalSettings* gs);
+
 protected:
        /**
         * Processes all scheduled scene activity.

Modified: trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp    2011-09-11 
05:50:44 UTC (rev 40112)
+++ trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp    2011-09-11 
05:54:07 UTC (rev 40113)
@@ -1113,7 +1113,7 @@
                                                                                
        PyObject* args,
                                                                                
        PyObject*)
 {
-       GameData *gm= &(gp_KetsjiScene->GetBlenderScene()->gm);
+       GlobalSettings *gs= gp_KetsjiEngine->GetGlobalSettings();
        char *setting;
        int enable, flag, sceneflag;
 
@@ -1127,15 +1127,15 @@
                return NULL;
        }
 
-       sceneflag= gm->flag;
+       sceneflag= gs->glslflag;
        
        if (enable)
-               gm->flag &= ~flag;
+               gs->glslflag &= ~flag;
        else
-               gm->flag |= flag;
+               gs->glslflag |= flag;
 
        /* display lists and GLSL materials need to be remade */
-       if(sceneflag != gm->flag) {
+       if(sceneflag != gs->glslflag) {
                GPU_materials_free();
                if(gp_KetsjiEngine) {
                        KX_SceneList *scenes = gp_KetsjiEngine->CurrentScenes();
@@ -1156,7 +1156,7 @@
                                                                         
PyObject* args, 
                                                                         
PyObject*)
 {
-       GameData *gm= &(gp_KetsjiScene->GetBlenderScene()->gm);
+       GlobalSettings *gs= gp_KetsjiEngine->GetGlobalSettings();
        char *setting;
        int enabled = 0, flag;
 
@@ -1170,7 +1170,7 @@
                return NULL;
        }
 
-       enabled = ((gm->flag & flag) != 0);
+       enabled = ((gs->glslflag & flag) != 0);
        return PyLong_FromSsize_t(enabled);
 }
 
@@ -1182,18 +1182,18 @@
                                                                        
PyObject* args,
                                                                        
PyObject*)
 {

@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to