HMODULE GetFrameworkDLL(const char* binariesDir) { MEMSTAT_CONTEXT_FMT(EMemStatContextTypes::MSC_Other, 0, "Load %s",GAME_FRAMEWORK_FILENAME ); if (!s_frameworkDLL) { if (binariesDir && binariesDir[0]) { string dllName = PathUtil::Make(binariesDir, GAME_FRAMEWORK_FILENAME); s_frameworkDLL = CryLoadLibrary(dllName.c_str()); } else { s_frameworkDLL = CryLoadLibrary(GAME_FRAMEWORK_FILENAME); } atexit( CleanupFrameworkDLL ); } return s_frameworkDLL; }
void CMaterialEffects::LoadFXLibrary(const char *name) { MEMSTAT_CONTEXT_FMT(EMemStatContextTypes::MSC_Other, 0, "FX Library XML (%s)", name); string path = PathUtil::Make(MATERIAL_EFFECTS_LIBRARIES_FOLDER, name); string fileName = name; int period = fileName.find("."); string libName = fileName.substr(0, period); XmlNodeRef libraryRootNode = gEnv->pSystem->LoadXmlFromFile(path); if (libraryRootNode != 0) { TFXLibrariesMap::iterator libIter = m_mfxLibraries.find(libName); if (libIter != m_mfxLibraries.end()) { GameWarning("[MatFX]: Library '%s' already exists, skipping library file loading '%s'", libName.c_str(), path.c_str()); return; } std::pair<TFXLibrariesMap::iterator, bool> iterPair = m_mfxLibraries.insert(TFXLibrariesMap::value_type(libName, CMFXLibrary())); assert (iterPair.second == true); libIter = iterPair.first; assert (libIter != m_mfxLibraries.end()); const TMFXNameId& libraryNameId = libIter->first; // uses CryString's ref-count feature CMFXLibrary& mfxLibrary = libIter->second; CMFXLibrary::SLoadingEnvironment libraryLoadingEnvironment(libraryNameId, libraryRootNode, m_effectContainers); mfxLibrary.LoadFromXml(libraryLoadingEnvironment); } else { GameWarning("[MatFX]: Failed to load library %s", path.c_str()); } }
bool CEntityPool::CreatePool(const CEntityPoolDefinition &definition) { FUNCTION_PROFILER(GetISystem(), PROFILE_ENTITY); assert(!gEnv->IsEditor()); MEMSTAT_CONTEXT_FMT(EMemStatContextTypes::MSC_Other, EMemStatContextFlags::MSF_Instance, "Create Pool %s", definition.GetName().c_str()); m_sDefaultClass = definition.GetDefaultClass(); m_sName = definition.GetName(); m_bDefinitionHasAI |= definition.HasAI(); m_uMaxSize = definition.GetMaxSize(); const uint32 uCount = definition.GetDesiredPoolCount(); m_InactivePoolIds.reserve(uCount); CEntity* pPoolEntity = NULL; bool bResult = (CreatePoolEntity(pPoolEntity) && m_Signature.CalculateFromEntity(pPoolEntity)); if (bResult) { // Already created one, so create the remaining.. for (uint32 i = 1; i < uCount; ++i) { bResult &= CreatePoolEntity(pPoolEntity); } m_PoolDefinitionIds.push_back(definition.GetId()); } if (!bResult) { EntityWarning("CEntityPool::CreatePool() Failed when prepairing the Pool for the default class \'%s\'", m_sDefaultClass.c_str()); } return bResult; }
// Load all equipment packs from a certain folder void CEquipmentManager::LoadEquipmentPacksFromPath(const char* path) { MEMSTAT_CONTEXT(EMemStatContextTypes::MSC_Other, 0, "Equipment Packs"); ICryPak * pCryPak = gEnv->pCryPak; _finddata_t fd; string realPath (path); realPath.TrimRight("/\\"); string search (realPath); search += "/*.xml"; intptr_t handle = pCryPak->FindFirst( search.c_str(), &fd ); if (handle != -1) { do { // fd.name contains the profile name string filename = path; filename += "/" ; filename += fd.name; MEMSTAT_CONTEXT_FMT(EMemStatContextTypes::MSC_Other, 0, "EquipmentPack XML (%s)", filename.c_str()); XmlNodeRef rootNode = gEnv->pSystem->LoadXmlFromFile(filename.c_str()); // load from XML node const bool ok = rootNode ? LoadEquipmentPack(rootNode) : false; if (!ok) { GameWarning("[EquipmentMgr]: Cannot load XML file '%s'. Skipping.", filename.c_str()); } } while ( pCryPak->FindNext( handle, &fd ) >= 0 ); pCryPak->FindClose( handle ); } }
//------------------------------------------------------------------------ bool CWeaponSystem::ScanXML(XmlNodeRef &root, const char *xmlFile) { MEMSTAT_CONTEXT_FMT(EMemStatContextTypes::MSC_Other, 0, "Weapon xml (%s)", xmlFile); if(strcmpi(root->getTag(), "ammo")) return false; const char *name = root->getAttr("name"); if(!name) { GameWarning("Missing ammo name in XML '%s'! Skipping...", xmlFile); return false; } const char *className = root->getAttr("class"); if(!className) { GameWarning("Missing ammo class in XML '%s'! Skipping...", xmlFile); return false; } TProjectileRegistry::iterator it = m_projectileregistry.find(CONST_TEMP_STRING(className)); if(it == m_projectileregistry.end()) { GameWarning("Unknown ammo class '%s' specified in XML '%s'! Skipping...", className, xmlFile); return false; } const char *scriptName = root->getAttr("script"); IEntityClassRegistry::SEntityClassDesc classDesc; classDesc.sName = name; classDesc.sScriptFile = scriptName?scriptName:""; //classDesc.pUserProxyData = (void *)it->second; //classDesc.pUserProxyCreateFunc = &CreateProxy<CProjectile>; classDesc.flags |= ECLF_INVISIBLE; IEntityClass *pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(name); if(!m_reloading && !pClass) { m_pGame->GetIGameFramework()->GetIGameObjectSystem()->RegisterExtension(name, it->second, &classDesc); pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(name); assert(pClass); } TAmmoTypeParams::iterator ait=m_ammoparams.find(pClass); if(ait==m_ammoparams.end()) { std::pair<TAmmoTypeParams::iterator, bool> result = m_ammoparams.insert(TAmmoTypeParams::value_type(pClass, SAmmoTypeDesc())); ait=result.first; } const char *configName = root->getAttr("configuration"); IItemParamsNode *params = m_pItemSystem->CreateParams(); params->ConvertFromXML(root); SAmmoParams *pAmmoParams=new SAmmoParams(params, pClass); SAmmoTypeDesc &desc=ait->second; if(!configName || !configName[0]) { if(desc.params) delete desc.params; desc.params=pAmmoParams; } else desc.configurations.insert(std::make_pair<string, const SAmmoParams *>(configName, pAmmoParams)); return true; }
IActionController *CMannequinInterface::CreateActionController(IEntity* pEntity, SAnimationContext &context) { MEMSTAT_CONTEXT_FMT(EMemStatContextTypes::MSC_Mannequin, 0, "ActionController (%s)", pEntity ? pEntity->GetName() ? pEntity->GetName() : "<unknown>" : "<no entity>"); return new CActionController(pEntity, context); }
bool CommunicationVoiceLibrary::LoadFromFile(const char* fileName) { MEMSTAT_CONTEXT(EMemStatContextTypes::MSC_Other, 0, "Communication Voice Library" ); MEMSTAT_CONTEXT_FMT(EMemStatContextTypes::MSC_Other, 0, "Voice Lib: %s",fileName ); XmlNodeRef root = GetISystem()->LoadXmlFromFile(fileName); if (!root) return false; XmlNodeRef nodeWorksheet = root->findChild("Worksheet"); if (!nodeWorksheet) return false; XmlNodeRef nodeTable = nodeWorksheet->findChild("Table"); if (!nodeTable) return false; stack_string libName(PathUtil::GetFileName(fileName)); VoiceLibraryID libraryID = GetVoiceLibraryID(libName.c_str()); std::pair<VoiceLibraries::iterator, bool> iresult = m_libraries.insert( VoiceLibraries::value_type(libraryID, VoiceLibrary())); if (!iresult.second) { if (iresult.first->second.name == libName.c_str()) { AIWarningID("<AICommunicationVoiceLibrary::LoadFromFile> ", "Duplicate voice library '%s'!", libName.c_str()); return false; } else { AIWarningID("<AICommunicationVoiceLibrary::LoadFromFile> ", "Hash collision for voice library name '%s' and '%s'!", libName.c_str(), iresult.first->second.name.c_str()); return false; } } VoiceLibrary& library = iresult.first->second; library.name = string(libName); VoiceGroup* voiceGroup = 0; string signalName; string lastSignalName; string voiceName; for (int rowCntr = 0, childN = 0; childN < nodeTable->getChildCount(); ++childN) { XmlNodeRef nodeRow = nodeTable->getChild(childN); if (!nodeRow->isTag("Row")) continue; ++rowCntr; if (rowCntr == 1) // skip language continue; if (rowCntr == 2) // path { int cellN = 0; for (int childrenCntr = 0; childrenCntr < nodeRow->getChildCount(); ++childrenCntr) { XmlNodeRef nodeCell = nodeRow->getChild(childrenCntr); if (!nodeCell->isTag("Cell")) continue; ++cellN; if (cellN == 2) { XmlNodeRef nodeCellData = nodeCell->findChild("Data"); if (!nodeCellData) break; library.base = PathUtil::GetLocalizationFolder() + nodeCellData->getContent(); if (!library.base.empty()) { library.base.replace("\\", "/"); if (library.base[library.base.length()-1] != '/') library.base.append("/"); } break; } } continue; } if (rowCntr == 3) // headers continue; signalName.clear(); voiceName.clear(); for (int childrenCntr = 0, cellIndex = 1; childrenCntr < nodeRow->getChildCount(); ++childrenCntr, ++cellIndex) { XmlNodeRef nodeCell = nodeRow->getChild(childrenCntr); if (!nodeCell->isTag("Cell")) continue; if (nodeCell->haveAttr("ss:Index")) { const char* strIdx = nodeCell->getAttr("ss:Index"); if (sscanf(strIdx, "%d", &cellIndex) != 1) continue; } XmlNodeRef nodeCellData = nodeCell->findChild("Data"); if (!nodeCellData) continue; switch (cellIndex) { case 1: signalName = nodeCellData->getContent(); break; case 2: voiceName = nodeCellData->getContent(); break; } } if (!signalName.empty()) { signalName.MakeLower(); std::pair<VoiceGroups::iterator, bool> itresult = library.voiceGroups.insert( VoiceGroups::value_type(signalName, VoiceGroup())); voiceGroup = &itresult.first->second; // The 20 here comes from inspection of the resulting contents in memreplay voiceGroup->variations.reserve(20); if (!itresult.second) { if (lastSignalName != signalName) AIWarningID("<AICommunicationVoiceLibrary::LoadFromFile> ", "Duplicate voice signal '%s' in file '%s'.", signalName.c_str(), libName.c_str()); } lastSignalName = signalName; } if (!voiceGroup || voiceName.empty()) continue; if ((library.base.find_first_of(':') == string::npos) && (voiceName.find_first_of(':') == string::npos)) voiceName.append(".wav"); if (voiceGroup->variations.size() < MaxVariationCount) voiceGroup->variations.push_back(voiceName); else AIWarningID("<AICommunicationVoiceLibrary::LoadFromFile> ", "Too many voice variations for signal '%s' in file '%s'. Limit is 32.", signalName.c_str(), libName.c_str()); } return true; }
void CEntityLayer::Enable( bool bEnable, bool bSerialize /*=true*/, bool bAllowRecursive /*=true*/ ) { // Wait for the physics thread to avoid massive amounts of ChangeRequest queuing gEnv->pSystem->SetThreadState(ESubsys_Physics, false); #ifdef ENABLE_PROFILING_CODE bool bChanged = (m_isEnabledBrush != bEnable) || (m_isEnabled != bEnable); float fStartTime = gEnv->pTimer->GetAsyncCurTime(); #endif //ENABLE_PROFILING_CODE if (bEnable && IsSkippedBySpec()) return; MEMSTAT_LABEL_FMT("Layer '%s' %s", m_name.c_str(), (bEnable ? "Activating" : "Deactivating")); MEMSTAT_CONTEXT_FMT(EMemStatContextTypes::MSC_Entity, 0, "Layer '%s' %s", m_name.c_str(), (bEnable ? "Activating" : "Deactivating")); if (bEnable) { if (m_pHeap) m_pGarbageHeaps->push_back(SEntityLayerGarbage(m_pHeap, m_name)); } else // make sure that children are hidden before parents and unhidden after them { if (bAllowRecursive && !gEnv->pSystem->IsSerializingFile()) // this check should not be needed now, because Enable() is not used in serialization anymore, but im keeping it for extra sanity check { for (std::vector<CEntityLayer*>::iterator it = m_childs.begin(); it != m_childs.end(); ++it) { (*it)->Enable( bEnable ); } } } EnableBrushes( bEnable ); EnableEntities( bEnable ); if (bEnable) // make sure that children are hidden before parents and unhidden after them { if (bAllowRecursive && !gEnv->pSystem->IsSerializingFile()) // this check should not be needed now, because Enable() is not used in serialization anymore, but im keeping it for extra sanity check { for (std::vector<CEntityLayer*>::iterator it = m_childs.begin(); it != m_childs.end(); ++it) { (*it)->Enable( bEnable ); } } } m_isSerialized = bSerialize; #ifdef ENABLE_PROFILING_CODE if (CVar::es_LayerDebugInfo == 5 && bChanged) { float fTimeMS = (gEnv->pTimer->GetAsyncCurTime() - fStartTime) * 1000.0f; CEntitySystem::SLayerProfile layerProfile; layerProfile.pLayer = this; layerProfile.fTimeOn = gEnv->pTimer->GetCurrTime(); layerProfile.isEnable = bEnable; layerProfile.fTimeMS = fTimeMS; g_pIEntitySystem->m_layerProfiles.insert( g_pIEntitySystem->m_layerProfiles.begin(), layerProfile); } #endif //ENABLE_PROFILING_CODE if (m_pHeap && m_pHeap->Cleanup()) { m_pHeap->Release(); m_pHeap = NULL; } MEMSTAT_LABEL_FMT("Layer '%s' %s", m_name.c_str(), (bEnable ? "Activated" : "Deactivated")); }