Merge pull request #1342 from Areloch/SpawnObjectOverrideOverhaul

SpawnObject Override Overhaul
This commit is contained in:
Brian Roberts 2025-01-03 09:44:37 -06:00 committed by GitHub
commit 8274bbbca4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 305 additions and 114 deletions

View file

@ -68,7 +68,8 @@ mModuleId(StringTable->EmptyString()),
mLoadCount( 0 ),
mScopeSet( 0 ),
mLocked( false ),
mpModuleManager( NULL )
mpModuleManager( NULL ),
mPriority(0.0f)
{
// Set Vector Associations.
VECTOR_SET_ASSOCIATION( mDependencies );
@ -111,6 +112,8 @@ void ModuleDefinition::initPersistFields()
/// Misc.
addProtectedField( "Signature", TypeString, 0, &defaultProtectedNotSetFn, &getSignature, &defaultProtectedNotWriteFn, "A unique signature of the module definition based upon its Id, version and build. This is read-only and is available only after the module has been registered by a module manager." );
addProtectedField( "Priority", TypeF32, 0, &setPriority, &defaultProtectedGetFn, &defaultProtectedNotWriteFn, "A numeric value indicating execution priority for certain callback commands. 0 has the highest priority and is then sorted from there ascending in value. This is read-only and is available only after the module has been registered by a module manager.");
}
//-----------------------------------------------------------------------------

View file

@ -115,6 +115,7 @@ private:
SimObjectId mScopeSet;
bool mLocked;
ModuleManager* mpModuleManager;
F32 mPriority;
private:
inline bool checkUnlocked( void ) const { if ( mLocked ) { Con::warnf("Ignoring changes for locked module definition."); } return !mLocked; }
@ -195,6 +196,9 @@ public:
inline bool getModuleLocked( void ) const { return mLocked; }
inline ModuleManager* getModuleManager( void ) const { return mpModuleManager; }
inline void setPriority(const F32 pPriority) { if (checkUnlocked()) { mPriority = pPriority; } }
inline F32 getPriority(void) const { return mPriority; }
using Parent::save;
bool save( void );
@ -332,6 +336,8 @@ protected:
}
static bool writeDependencies( void* obj, StringTableEntry pFieldName ) { return static_cast<ModuleDefinition*>(obj)->getDependencies().size() > 0; }
static const char* getSignature(void* obj, const char* data) { return static_cast<ModuleDefinition*>(obj)->getSignature(); }
static bool setPriority(void* obj, const char* index, const char* data) { static_cast<ModuleDefinition*>(obj)->setPriority((F32)dAtof(data)); return false; }
};
#endif // _MODULE_DEFINITION_H

View file

@ -150,8 +150,14 @@ DefineEngineMethod(ModuleManager, findModuleByFilePath, String, (const char* fil
}
//-----------------------------------------------------------------------------
static S32 QSORT_CALLBACK _findModulesSortByPriority(ModuleDefinition* const* a, ModuleDefinition* const* b)
{
F32 diff = (*a)->getPriority() - (*b)->getPriority();
return diff > 0 ? 1 : diff < 0 ? -1 : 0;
}
DefineEngineMethod(ModuleManager, findModules, String, (bool loadedOnly), (true),
DefineEngineMethod(ModuleManager, findModules, String, (bool loadedOnly, bool sortByPriority, const char* moduleGroup), (true, false, ""),
"Find all the modules registered with the specified loaded state.\n"
"@param loadedOnly Whether to return only modules that are loaded or not.\n"
"@return A list of space - separated module definition object Ids.\n")
@ -174,12 +180,23 @@ DefineEngineMethod(ModuleManager, findModules, String, (bool loadedOnly), (true)
char* pReturnBuffer = Con::getReturnBuffer( bufferSize );
char* pBufferWrite = pReturnBuffer;
if (sortByPriority)
moduleDefinitions.sort(_findModulesSortByPriority);
StringTableEntry moduleGroupStr = StringTable->insert(moduleGroup);
// Iterate module definitions.
for ( ModuleManager::typeConstModuleDefinitionVector::const_iterator moduleDefinitionItr = moduleDefinitions.begin(); moduleDefinitionItr != moduleDefinitions.end(); ++moduleDefinitionItr )
{
// Fetch module definition.
const ModuleDefinition* pModuleDefinition = *moduleDefinitionItr;
if(moduleGroupStr != StringTable->EmptyString())
{
if (pModuleDefinition->getModuleGroup() != moduleGroupStr)
continue;
}
// Format module definition.
const U32 offset = dSprintf( pBufferWrite, bufferSize, "%d ", pModuleDefinition->getId() );
pBufferWrite += offset;