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:
authorDalai Felinto <dfelinto@gmail.com>2011-09-11 09:54:07 +0400
committerDalai Felinto <dfelinto@gmail.com>2011-09-11 09:54:07 +0400
commit5184476fe1bd6c61a50a047bdba1f4b9756f323c (patch)
tree44b5d4c1377682b532a151c926c92f2cde6b9278 /source/gameengine
parentcfa83b0888075996664e3614b4f6392139de8996 (diff)
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]
Diffstat (limited to 'source/gameengine')
-rw-r--r--source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp15
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_Application.cpp20
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_Application.h7
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_ghost.cpp14
-rw-r--r--source/gameengine/Ketsji/KX_KetsjiEngine.cpp10
-rw-r--r--source/gameengine/Ketsji/KX_KetsjiEngine.h13
-rw-r--r--source/gameengine/Ketsji/KX_PythonInit.cpp28
7 files changed, 82 insertions, 25 deletions
diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
index 810e9b6ddfb..ce542671425 100644
--- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
+++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
@@ -169,6 +169,11 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c
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 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c
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 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c
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 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c
}
printf("Blender Game Engine Finished\n");
exitstring = ketsjiengine->GetExitString();
+ gs = *(ketsjiengine->GetGlobalSettings());
// when exiting the mainloop
diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
index 5bc6093a9ff..7b47d74d424 100644
--- a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
+++ b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
@@ -151,7 +151,7 @@ GPG_Application::~GPG_Application(void)
-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 @@ bool GPG_Application::SetGameEngineData(struct Main* maggie, Scene *scene, int a
m_argc= argc;
m_argv= argv;
+ /* Global Settings */
+ m_globalSettings= gs;
+
return result;
}
@@ -511,6 +514,12 @@ int GPG_Application::getExitRequested(void)
}
+GlobalSettings* GPG_Application::getGlobalSettings(void)
+{
+ return m_ketsjiengine->GetGlobalSettings();
+}
+
+
const STR_String& GPG_Application::getExitString(void)
{
@@ -552,7 +561,7 @@ bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode)
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 @@ bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode)
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 @@ bool GPG_Application::startEngine(void)
// 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,
diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.h b/source/gameengine/GamePlayer/ghost/GPG_Application.h
index c0638517657..df87aea1195 100644
--- a/source/gameengine/GamePlayer/ghost/GPG_Application.h
+++ b/source/gameengine/GamePlayer/ghost/GPG_Application.h
@@ -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 @@ public:
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 @@ public:
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 @@ protected:
/* Exit state. */
int m_exitRequested;
STR_String m_exitString;
+ GlobalSettings* m_globalSettings;
+
/* GHOST system abstraction. */
GHOST_ISystem* m_system;
/* Main window. */
diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
index 3f8bcf9e2ad..d4ce19de83f 100644
--- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
+++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
@@ -746,6 +746,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
@@ -799,9 +804,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 +870,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 +966,7 @@ int main(int argc, char** argv)
{
run = false;
exitstring = app.getExitString();
+ gs = *app.getGlobalSettings();
}
}
app.StopGameEngine();
diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
index db919b7bc5a..65ff06456b4 100644
--- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
+++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
@@ -1936,4 +1936,14 @@ void KX_KetsjiEngine::GetOverrideFrameColor(float& r, float& g, float& b) const
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;
+}
diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.h b/source/gameengine/Ketsji/KX_KetsjiEngine.h
index b1009c7d8f0..f2f978a0afa 100644
--- a/source/gameengine/Ketsji/KX_KetsjiEngine.h
+++ b/source/gameengine/Ketsji/KX_KetsjiEngine.h
@@ -62,6 +62,11 @@ enum KX_ExitRequestMode
KX_EXIT_REQUEST_MAX
};
+typedef struct {
+ short matmode;
+ short glslflag;
+} GlobalSettings;
+
/**
* KX_KetsjiEngine is the core game engine class.
*/
@@ -193,6 +198,9 @@ private:
/** 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 @@ public:
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.
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp
index 7ddaa97770b..62ca2910c60 100644
--- a/source/gameengine/Ketsji/KX_PythonInit.cpp
+++ b/source/gameengine/Ketsji/KX_PythonInit.cpp
@@ -1113,7 +1113,7 @@ static PyObject* gPySetGLSLMaterialSetting(PyObject*,
PyObject* args,
PyObject*)
{
- GameData *gm= &(gp_KetsjiScene->GetBlenderScene()->gm);
+ GlobalSettings *gs= gp_KetsjiEngine->GetGlobalSettings();
char *setting;
int enable, flag, sceneflag;
@@ -1127,15 +1127,15 @@ static PyObject* gPySetGLSLMaterialSetting(PyObject*,
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 @@ static PyObject* gPyGetGLSLMaterialSetting(PyObject*,
PyObject* args,
PyObject*)
{
- GameData *gm= &(gp_KetsjiScene->GetBlenderScene()->gm);
+ GlobalSettings *gs= gp_KetsjiEngine->GetGlobalSettings();
char *setting;
int enabled = 0, flag;
@@ -1170,7 +1170,7 @@ static PyObject* gPyGetGLSLMaterialSetting(PyObject*,
return NULL;
}
- enabled = ((gm->flag & flag) != 0);
+ enabled = ((gs->glslflag & flag) != 0);
return PyLong_FromSsize_t(enabled);
}
@@ -1182,18 +1182,18 @@ static PyObject* gPySetMaterialType(PyObject*,
PyObject* args,
PyObject*)
{
- GameData *gm= &(gp_KetsjiScene->GetBlenderScene()->gm);
+ GlobalSettings *gs= gp_KetsjiEngine->GetGlobalSettings();
int type;
if (!PyArg_ParseTuple(args,"i:setMaterialType",&type))
return NULL;
if(type == KX_BLENDER_GLSL_MATERIAL)
- gm->matmode= GAME_MAT_GLSL;
+ gs->matmode= GAME_MAT_GLSL;
else if(type == KX_BLENDER_MULTITEX_MATERIAL)
- gm->matmode= GAME_MAT_MULTITEX;
+ gs->matmode= GAME_MAT_MULTITEX;
else if(type == KX_TEXFACE_MATERIAL)
- gm->matmode= GAME_MAT_TEXFACE;
+ gs->matmode= GAME_MAT_TEXFACE;
else {
PyErr_SetString(PyExc_ValueError, "Rasterizer.setMaterialType(int): material type is not known");
return NULL;
@@ -1204,12 +1204,12 @@ static PyObject* gPySetMaterialType(PyObject*,
static PyObject* gPyGetMaterialType(PyObject*)
{
- GameData *gm= &(gp_KetsjiScene->GetBlenderScene()->gm);
+ GlobalSettings *gs= gp_KetsjiEngine->GetGlobalSettings();
int flag;
- if(gm->matmode == GAME_MAT_GLSL)
+ if(gs->matmode == GAME_MAT_GLSL)
flag = KX_BLENDER_GLSL_MATERIAL;
- else if(gm->matmode == GAME_MAT_MULTITEX)
+ else if(gs->matmode == GAME_MAT_MULTITEX)
flag = KX_BLENDER_MULTITEX_MATERIAL;
else
flag = KX_TEXFACE_MATERIAL;