diff --git a/Engine/source/module/moduleManager.cpp b/Engine/source/module/moduleManager.cpp index d8620c1f0..22c877594 100644 --- a/Engine/source/module/moduleManager.cpp +++ b/Engine/source/module/moduleManager.cpp @@ -38,9 +38,16 @@ #include "console/consoleTypes.h" #endif +#ifndef _MODULE_DEFINITION_H +#include "module/moduleDefinition.h" +#endif + +#ifndef _STRINGFUNCTIONS_H_ +#include "core/strings/stringFunctions.h" +#endif + // Script bindings. #include "moduleManager_ScriptBinding.h" - //----------------------------------------------------------------------------- IMPLEMENT_CONOBJECT( ModuleManager ); @@ -65,6 +72,25 @@ S32 QSORT_CALLBACK moduleDefinitionVersionIdSort( const void* a, const void* b ) return versionId1 > versionId2 ? -1 : versionId1 < versionId2 ? 1 : 0; } +S32 QSORT_CALLBACK moduleDependencySort(const void* a, const void* b) +{ + // Fetch module definitions. + ModuleDefinition* pDefinition1 = *(ModuleDefinition * *)a; + ModuleDefinition* pDefinition2 = *(ModuleDefinition * *)b; + + // Fetch version Ids. + ModuleDefinition::typeModuleDependencyVector moduleDependencies = pDefinition1->getDependencies(); + bool foundDependant = false; + for (ModuleDefinition::typeModuleDependencyVector::const_iterator dependencyItr = moduleDependencies.begin(); dependencyItr != moduleDependencies.end(); ++dependencyItr) + { + if (dStrcmp(dependencyItr->mModuleId, pDefinition2->getModuleId()) + && (dependencyItr->mVersionId == pDefinition2->getVersionId())) + foundDependant = true; + } + + return foundDependant ? 1 : -1; +} + //----------------------------------------------------------------------------- ModuleManager::ModuleManager() : @@ -1087,6 +1113,7 @@ void ModuleManager::findModules( const bool loadedOnly, typeConstModuleDefinitio moduleDefinitions.push_back( pModuleDefinition ); } } + dQsort(moduleDefinitions.address(), moduleDefinitions.size(), sizeof(ModuleDefinition*), moduleDependencySort); } //----------------------------------------------------------------------------- diff --git a/Templates/BaseGame/game/core/utility/scripts/module.cs b/Templates/BaseGame/game/core/utility/scripts/module.cs index 2ff14c1e1..7d6cc5eed 100644 --- a/Templates/BaseGame/game/core/utility/scripts/module.cs +++ b/Templates/BaseGame/game/core/utility/scripts/module.cs @@ -1,5 +1,12 @@ +$traceModuleCalls=false; +$reportModuleFileConflicts=true; +if (!isObject(ExecFilesList)) + new ArrayObject(ExecFilesList); + function callOnModules(%functionName, %moduleGroup) { + //clear per module group file execution chain + ExecFilesList.empty(); //Get our modules so we can exec any specific client-side loading/handling %modulesList = ModuleDatabase.findModules(false); for(%i=0; %i < getWordCount(%modulesList); %i++) @@ -16,7 +23,14 @@ function callOnModules(%functionName, %moduleGroup) { eval(%module.scopeSet @ "." @ %functionName @ "();"); } - } + } + + %execFilecount = ExecFilesList.count(); + for (%i=0;%i<%execFilecount;%i++) + { + %filename = ExecFilesList.getKey(%i); + exec(%filename); + } } function loadModuleMaterials(%moduleGroup) @@ -69,10 +83,12 @@ function SimSet::getModulePath(%scopeSet) return ""; } -function SimSet::registerDatablock(%scopeSet, %datablockFilePath) +function SimSet::registerDatablock(%scopeSet, %datablockFilePath, %isExclusive) { + if ($traceModuleCalls) + warn("SimSet::registerDatablock"); %name = %scopeSet.getName(); - %moduleDef = ModuleDatabase.findModule(%name); + %moduleDef = ModuleDatabase.findModule(%name, 1); if(!isObject(%moduleDef)) { @@ -89,6 +105,176 @@ function SimSet::registerDatablock(%scopeSet, %datablockFilePath) %relativePath = makeRelativePath(%datablockFilePath); %fullPath = pathConcat(%moduleDef.ModulePath, %relativePath); + ///go through all entries + %locked = false; + %dbFilecount = DatablockFilesList.count(); + for (%i=0;%i<%dbFilecount;%i++) + { + %check = DatablockFilesList.getKey(%i); + //look for a substring match + %isMatch = strIsMatchExpr("*"@ %datablockFilePath,%check ); + if (%isMatch) + { + //check if we're already locked in + //and kill off any duplicates + //do note that doing it in this order means setting exclusive twice + //allows one to override exclusive with exclusive + %locked = DatablockFilesList.getValue(%i); + + if ((!%locked && !%isExclusive)&&($reportModuleFileConflicts)) + error("found" SPC %datablockFilePath SPC "duplicate file!"); + if (!%locked || (%locked && %isExclusive)) + { + DatablockFilesList.erase(%i); + } + } + } + //if we're not locked, or we are exclusive, go ahead and add it to the pile + //(ensures exclusives get re-added after that erasure) + if (!%locked || %isExclusive) + DatablockFilesList.add(%fullPath,%isExclusive); + if ($traceModuleCalls) + DatablockFilesList.echo(); +} + +function SimSet::unRegisterDatablock(%scopeSet, %datablockFilePath) +{ + if ($traceModuleCalls) + warn("SimSet::unRegisterDatablock"); + %name = %scopeSet.getName(); + %moduleDef = ModuleDatabase.findModule(%name, 1); + + if(!isObject(%moduleDef)) + { + error("Module::unRegisterDatablock() - unable to find a module with the moduleID of " @ %name); + return; + } - DatablockFilesList.add(%fullPath); + if(!isObject(DatablockFilesList)) + { + error("Module::unRegisterDatablock() - DatablockFilesList array object doesn't exist!"); + return; + } + + %relativePath = makeRelativePath(%datablockFilePath); + + %fullPath = pathConcat(%moduleDef.ModulePath, %relativePath); + ///go through all entries + %locked = false; + %dbFilecount = DatablockFilesList.count(); + for (%i=0;%i<%dbFilecount;%i++) + { + %check = DatablockFilesList.getKey(%i); + //look for a substring match + %isMatch = strIsMatchExpr("*"@ %datablockFilePath,%check ); + if (%isMatch) + { + //check if we're already locked in. if not, kill it. + %locked = DatablockFilesList.getValue(%i); + if (!%locked) + { + DatablockFilesList.erase(%i); + } + } + } + if ($traceModuleCalls) + DatablockFilesList.echo(); +} + +function SimSet::queueExec(%scopeSet, %execFilePath, %isExclusive) +{ + if ($traceModuleCalls) + warn("SimSet::queueExec"); + %name = %scopeSet.getName(); + %moduleDef = ModuleDatabase.findModule(%name, 1); + + if(!isObject(%moduleDef)) + { + error("Module::queueExec() - unable to find a module with the moduleID of " @ %name); + return; + } + + if(!isObject(ExecFilesList)) + { + error("Module::queueExec() - ExecFilesList array object doesn't exist!"); + return; + } + + if ($traceModuleCalls) + warn("module root path="@ makeRelativePath(%moduleDef.ModulePath)); + + %fullPath = makeRelativePath(%moduleDef.ModulePath) @ %execFilePath; + ///go through all entries + %locked = false; + %execFilecount = ExecFilesList.count(); + for (%i=0;%i<%execFilecount;%i++) + { + %check = ExecFilesList.getKey(%i); + //look for a substring match + %isMatch = strIsMatchExpr("*"@ %execFilePath,%check ); + if (%isMatch) + { + //check if we're already locked in + //and kill off any duplicates + //do note that doing it in this order means setting exclusive twice + //allows one to override exclusive with exclusive + %locked = ExecFilesList.getValue(%i); + if ((!%locked && !%isExclusive)&&($reportModuleFileConflicts)) + error("found" SPC %execFilePath SPC "duplicate file!"); + if (!%locked || (%locked && %isExclusive)) + { + ExecFilesList.erase(%i); + } + } + } + //if we're not locked, or we are exclusive, go ahead and add it to the pile + //(ensures exclusives get re-added after that erasure) + if (!%locked || %isExclusive) + ExecFilesList.add(%fullPath,%isExclusive); + if ($traceModuleCalls) + ExecFilesList.echo(); +} + +function SimSet::unQueueExec(%scopeSet, %execFilePath) +{ + if ($traceModuleCalls) + warn("SimSet::unRegisterDatablock"); + %name = %scopeSet.getName(); + %moduleDef = ModuleDatabase.findModule(%name, 1); + + if(!isObject(%moduleDef)) + { + error("Module::unRegisterDatablock() - unable to find a module with the moduleID of " @ %name); + return; + } + + if(!isObject(ExecFilesList)) + { + error("Module::unRegisterDatablock() - ExecFilesList array object doesn't exist!"); + return; + } + + %relativePath = makeRelativePath(%execFilePath); + + %fullPath = pathConcat(%moduleDef.ModulePath, %relativePath); + ///go through all entries + %locked = false; + %execFilecount = ExecFilesList.count(); + for (%i=0;%i<%execFilecount;%i++) + { + %check = ExecFilesList.getKey(%i); + //look for a substring match + %isMatch = strIsMatchExpr("*"@ %execFilePath,%check ); + if (%isMatch) + { + //check if we're already locked in. if not, kill it. + %locked = ExecFilesList.getValue(%i); + if (!%locked) + { + ExecFilesList.erase(%i); + } + } + } + if ($traceModuleCalls) + ExecFilesList.echo(); } \ No newline at end of file