diff --git a/Engine/source/module/moduleDefinition.cpp b/Engine/source/module/moduleDefinition.cpp index 4fa82b856..093d90e59 100644 --- a/Engine/source/module/moduleDefinition.cpp +++ b/Engine/source/module/moduleDefinition.cpp @@ -51,6 +51,7 @@ mModuleId(StringTable->EmptyString()), mSynchronized( false ), mDeprecated( false ), mCriticalMerge( false ), + mOverrideExitingObjects(false), mModuleDescription( StringTable->EmptyString() ), mAuthor(StringTable->EmptyString()), mModuleGroup(StringTable->EmptyString()), @@ -91,6 +92,7 @@ void ModuleDefinition::initPersistFields() addProtectedField( "Synchronized", TypeBool, Offset(mSynchronized, ModuleDefinition), &setSynchronized, &defaultProtectedGetFn, &writeSynchronized, "Whether the module should be synchronized or not. Optional: If not specified then the module is not synchronized." ); addProtectedField( "Deprecated", TypeBool, Offset(mDeprecated, ModuleDefinition), &setDeprecated, &defaultProtectedGetFn, &writeDeprecated, "Whether the module is deprecated or not. Optional: If not specified then the module is not deprecated." ); addProtectedField( "CriticalMerge", TypeBool, Offset(mCriticalMerge, ModuleDefinition), &setDeprecated, &defaultProtectedGetFn, &writeCriticalMerge, "Whether the merging of a module prior to a restart is critical or not. Optional: If not specified then the module is not merge critical." ); + addProtectedField( "OverrideExistingObjects", TypeBool, Offset(mOverrideExitingObjects, ModuleDefinition), &setOverrideExistingObjects, &defaultProtectedGetFn, &writeOverrideExistingObjects, "Controls if when this module is loaded and the create function is executed, it will replace existing objects that share names or not."); addProtectedField( "Description", TypeString, Offset(mModuleDescription, ModuleDefinition), &setModuleDescription, &defaultProtectedGetFn, &writeModuleDescription, "The description typically used for debugging purposes but can be used for anything." ); addProtectedField( "Author", TypeString, Offset(mAuthor, ModuleDefinition), &setAuthor, &defaultProtectedGetFn, &writeAuthor, "The author of the module." ); addProtectedField( "Group", TypeString, Offset(mModuleGroup, ModuleDefinition), &setModuleGroup, &defaultProtectedGetFn, "The module group used typically when loading modules as a group." ); diff --git a/Engine/source/module/moduleDefinition.h b/Engine/source/module/moduleDefinition.h index c1c76d793..30c089637 100644 --- a/Engine/source/module/moduleDefinition.h +++ b/Engine/source/module/moduleDefinition.h @@ -89,6 +89,7 @@ private: bool mSynchronized; bool mDeprecated; bool mCriticalMerge; + bool mOverrideExitingObjects; StringTableEntry mModuleDescription; StringTableEntry mAuthor;; StringTableEntry mModuleGroup; @@ -141,6 +142,8 @@ public: inline bool getDeprecated( void ) const { return mDeprecated; } inline void setCriticalMerge( const bool mergeCritical ) { if ( checkUnlocked() ) { mCriticalMerge = mergeCritical; } } inline bool getCriticalMerge( void ) const { return mCriticalMerge; } + inline void setOverrideExistingObjects(const bool overrideExistingObj) { if (checkUnlocked()) { mOverrideExitingObjects = overrideExistingObj; } } + inline bool getOverrideExistingObjects(void) const { return mOverrideExitingObjects; } inline void setModuleDescription( const char* pModuleDescription ) { if ( checkUnlocked() ) { mModuleDescription = StringTable->insert(pModuleDescription); } } inline StringTableEntry getModuleDescription( void ) const { return mModuleDescription; } inline void setAuthor( const char* pAuthor ) { if ( checkUnlocked() ) { mAuthor = StringTable->insert(pAuthor); } } @@ -206,6 +209,8 @@ protected: static bool setDeprecated(void* obj, const char* index, const char* data) { static_cast(obj)->setDeprecated(dAtob(data)); return false; } static bool writeDeprecated( void* obj, StringTableEntry pFieldName ) { return static_cast(obj)->getDeprecated() == true; } static bool writeCriticalMerge( void* obj, StringTableEntry pFieldName ){ return static_cast(obj)->getCriticalMerge() == true; } + static bool setOverrideExistingObjects(void* obj, const char* index, const char* data) { static_cast(obj)->setOverrideExistingObjects(dAtob(data)); return false; } + static bool writeOverrideExistingObjects(void* obj, StringTableEntry pFieldName) { return static_cast(obj)->getOverrideExistingObjects() == true; } static bool setModuleDescription(void* obj, const char* index, const char* data) { static_cast(obj)->setModuleDescription(data); return false; } static bool writeModuleDescription( void* obj, StringTableEntry pFieldName ) { return static_cast(obj)->getModuleDescription() != StringTable->EmptyString(); } static bool setAuthor(void* obj, const char* index, const char* data) { static_cast(obj)->setAuthor(data); return false; } diff --git a/Engine/source/module/moduleManager.cpp b/Engine/source/module/moduleManager.cpp index 49cfeac9e..67a89e3e1 100644 --- a/Engine/source/module/moduleManager.cpp +++ b/Engine/source/module/moduleManager.cpp @@ -429,7 +429,22 @@ bool ModuleManager::loadModuleGroup( const char* pModuleGroup ) if ( pScopeSet->isMethod( pLoadReadyModuleDefinition->getCreateFunction() ) ) { // Yes, so call the create method. - Con::executef( pScopeSet, pLoadReadyModuleDefinition->getCreateFunction() ); + + //But first, check if we're overriding objects, and if so, set our console var to make that happen while we exec our create function + if (pLoadReadyModuleDefinition->getOverrideExistingObjects()) + { + String redefineBehaviorPrev = Con::getVariable("$Con::redefineBehavior"); + Con::setVariable("$Con::redefineBehavior", "replaceExisting"); + Con::executef(pScopeSet, pLoadReadyModuleDefinition->getCreateFunction()); + + //And now that we've executed, switch back to the prior behavior + Con::setVariable("$Con::redefineBehavior", redefineBehaviorPrev.c_str()); + } + else + { + //Nothing to do, just run the create function + Con::executef(pScopeSet, pLoadReadyModuleDefinition->getCreateFunction()); + } } } else