Skip to content

Commit

Permalink
UPBGE: Add the option to disable component execution on game start
Browse files Browse the repository at this point in the history
The new option is at user preferences under system tab. The component
execution is disable by default (similar to scripts).
  • Loading branch information
lordloki committed May 24, 2018
1 parent 9181356 commit a98a2bd
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ option(WITH_GAMEENGINE "Enable Game Engine" ${_init_GAMEENGINE})
option(WITH_GAMEENGINE_SECURITY "Disable game engine python debugging tools" OFF)
mark_as_advanced(WITH_GAMEENGINE_SECURITY)

option(WITH_GAMEENGINE_COMPONENTS_SECURITY "Disables execution of UPBGE components within blend files by default" ON)
mark_as_advanced(WITH_GAMEENGINE_COMPONENTS_SECURITY)

option(WITH_GAMEENGINE_GPU_SYNC "Enable GPU synchronization for VideoTexture module image rendering (ImageRender)" OFF)
mark_as_advanced(WITH_GAMEENGINE_GPU_SYNC)

Expand Down
1 change: 1 addition & 0 deletions release/scripts/startup/bl_ui/space_userpref.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,7 @@ def draw(self, context):
row = sub.split(percentage=0.3)
row.label(text="Auto Execution:")
row.prop(system, "use_scripts_auto_execute")
row.prop(system, "use_components_auto_execute")

if system.use_scripts_auto_execute:
box = sub.box()
Expand Down
2 changes: 2 additions & 0 deletions source/blender/blenkernel/BKE_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ typedef struct Global {
#define G_SCRIPT_AUTOEXEC_FAIL (1 << 15)
#define G_SCRIPT_AUTOEXEC_FAIL_QUIET (1 << 16)

#define G_COMPONENT_AUTOEXEC (1 << 18)

/* #define G_NOFROZEN (1 << 17) also removed */
/* #define G_GREASEPENCIL (1 << 17) also removed */

Expand Down
6 changes: 6 additions & 0 deletions source/blender/blenkernel/intern/blender.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ void BKE_blender_globals_init(void)
#else
G.f &= ~G_SCRIPT_AUTOEXEC;
#endif

#ifndef WITH_GAMEENGINE_COMPONENTS_SECURITY /* default */
G.f |= G_COMPONENT_AUTOEXEC;
#else
G.f &= ~G_COMPONENT_AUTOEXEC;
#endif
}

void BKE_blender_globals_clear(void)
Expand Down
3 changes: 3 additions & 0 deletions source/blender/blenloader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ if(WITH_PYTHON)
if(WITH_PYTHON_SECURITY)
add_definitions(-DWITH_PYTHON_SECURITY)
endif()
if(WITH_GAMEENGINE_COMPONENTS_SECURITY)
add_definitions(-DWITH_GAMEENGINE_COMPONENTS_SECURITY)
endif()
endif()

if(WITH_INTERNATIONAL)
Expand Down
6 changes: 6 additions & 0 deletions source/blender/blenloader/intern/versioning_defaults.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ void BLO_update_defaults_userpref_blend(void)
#else
U.flag &= ~USER_SCRIPT_AUTOEXEC_DISABLE;
#endif

#ifdef WITH_GAMEENGINE_COMPONENTS_SECURITY
U.flag |= USER_COMPONENT_AUTOEXEC_DISABLE;
#else
U.flag &= ~USER_COMPONENT_AUTOEXEC_DISABLE;
#endif
}

/**
Expand Down
1 change: 1 addition & 0 deletions source/blender/makesdna/DNA_userdef_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ typedef enum eUserPref_Flag {
USER_NONEGFRAMES = (1 << 24),
USER_TXT_TABSTOSPACES_DISABLE = (1 << 25),
USER_TOOLTIPS_PYTHON = (1 << 26),
USER_COMPONENT_AUTOEXEC_DISABLE = (1 << 27),
} eUserPref_Flag;

/* bPathCompare.flag */
Expand Down
14 changes: 14 additions & 0 deletions source/blender/makesrna/intern/rna_userdef.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ static void rna_userdef_script_autoexec_update(Main *UNUSED(bmain), Scene *UNUSE
else G.f |= G_SCRIPT_AUTOEXEC;
}

static void rna_userdef_component_autoexec_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
UserDef *userdef = (UserDef *)ptr->data;
if (userdef->flag & USER_COMPONENT_AUTOEXEC_DISABLE) G.f &= ~G_COMPONENT_AUTOEXEC;
else G.f |= G_COMPONENT_AUTOEXEC;
}

static void rna_userdef_load_ui_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
UserDef *userdef = (UserDef *)ptr->data;
Expand Down Expand Up @@ -4041,6 +4048,13 @@ static void rna_def_userdef_system(BlenderRNA *brna)
"(unsafe with blend files from an untrusted source)");
RNA_def_property_update(prop, 0, "rna_userdef_script_autoexec_update");

prop = RNA_def_property(srna, "use_components_auto_execute", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", USER_COMPONENT_AUTOEXEC_DISABLE);
RNA_def_property_ui_text(prop, "Auto Run UPBGE Components",
"Allow any .blend file to run python components automatically "
"(unsafe with blend files from an untrusted source)");
RNA_def_property_update(prop, 0, "rna_userdef_component_autoexec_update");

prop = RNA_def_property(srna, "use_tabs_as_spaces", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", USER_TXT_TABSTOSPACES_DISABLE);
RNA_def_property_ui_text(prop, "Tabs as Spaces",
Expand Down
20 changes: 11 additions & 9 deletions source/gameengine/Converter/BL_BlenderDataConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1730,16 +1730,18 @@ void BL_ConvertBlenderObjects(struct Main *maggie,
gameobj->ResetState();
}

// Convert the python components of each object.
for (KX_GameObject *gameobj : sumolist) {
Object *blenderobj = gameobj->GetBlenderObject();
BL_ConvertComponentsObject(gameobj, blenderobj);
}
// Convert the python components of each object if the component execution is available.
if (G.f & G_COMPONENT_AUTOEXEC) {
for (KX_GameObject *gameobj : sumolist) {
Object *blenderobj = gameobj->GetBlenderObject();
BL_ConvertComponentsObject(gameobj, blenderobj);
}

for (KX_GameObject *gameobj : objectlist) {
if (gameobj->GetComponents()) {
// Register object for component update.
kxscene->GetPythonComponentManager().RegisterObject(gameobj);
for (KX_GameObject *gameobj : objectlist) {
if (gameobj->GetComponents()) {
// Register object for component update.
kxscene->GetPythonComponentManager().RegisterObject(gameobj);
}
}
}

Expand Down

0 comments on commit a98a2bd

Please sign in to comment.