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]
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user