mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-12 19:31:41 +00:00
Added field to ModuleDefinition for priority, which can be used to process/sort them in priority order
Added logic to ModuleManager's findModules method to allow priority sorting as well as pre-filtering by a given module group Adjusts the %isFine argument for the onMapLoadFailed callback events to %canContinueOnFail for a bit more clarity on what the arg conveys Shifts the setSpawnObjectType, setSpawnPoint and onPostSpawn call stack to utilize an event manager to allow the setup process for spawners and gamemode prepwork to run in it's own time, if needbe. Such as if a gamemode has to generate a map and there's no guarantees on when it'll b e done for one client vs another Added getModulesAndGameModesList, callOnObjectList and getNumCanCallOnObjectList utility functions
This commit is contained in:
parent
c5ae9af0ae
commit
46f6f6a9da
6 changed files with 220 additions and 31 deletions
|
|
@ -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.");
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue