void CRevertibleConfigLoader::LoadConfiguration(const char *szConfig) { CryLog ("Loading %s configuration...", szConfig); INDENT_LOG_DURING_SCOPE(); gEnv->pSystem->LoadConfiguration(szConfig, this); CryLog ("Finished loading %s configuration, used %" PRISIZE_T "/%" PRISIZE_T " bytes storing old cvar values", szConfig, m_cvarsTextBlock.GetNumBytesUsed(), m_cvarsTextBlock.GetSizeNeeded()); }
void CMFXLibrary::LoadFromXml( SLoadingEnvironment& loadingEnvironment ) { CryLogAlways("[MFX] Loading FXLib '%s' ...", loadingEnvironment.libraryName.c_str()); INDENT_LOG_DURING_SCOPE(); for (int i = 0; i < loadingEnvironment.libraryParamsNode->getChildCount(); ++i) { XmlNodeRef currentEffectNode = loadingEnvironment.libraryParamsNode->getChild(i); if (!currentEffectNode) continue; TMFXContainerPtr pContainer = MaterialEffectsUtils::CreateContainer(); pContainer->BuildFromXML(currentEffectNode); const TMFXNameId& effectName = pContainer->GetParams().name; const bool effectAdded = AddContainer(effectName, pContainer); if (effectAdded) { loadingEnvironment.AddLibraryContainer(loadingEnvironment.libraryName, pContainer); } else { GameWarning("[MFX] Effect (at line %d) '%s:%s' already present, skipping redefinition!", currentEffectNode->getLine(), loadingEnvironment.libraryName.c_str(), effectName.c_str()); } } }
//-------------------------------------------------------------------------------------------------- // Name: CacheItemModel // Desc: Cache item model //-------------------------------------------------------------------------------------------------- void CFrontEndModelCache::CacheItemModel(const char* pItemName) { CItemSharedParams* pItemSharedParams = g_pGame->GetGameSharedParametersStorage()->GetItemSharedParameters(pItemName, false); if(pItemSharedParams) { const SGeometryDef* pGeomDef = pItemSharedParams->GetGeometryForSlot(eIGS_ThirdPerson); if(pGeomDef) { const char* pModelFileName = pGeomDef->modelPath.c_str(); FE_LOG ("Caching \"%s\" (for item '%s')", pModelFileName, pItemName); INDENT_LOG_DURING_SCOPE(); m_myGeometryCache.CacheGeometry(pModelFileName, false, IStatObj::ELoadingFlagsIgnoreLoDs); const char *pMaterialName = pGeomDef->material.c_str(); FE_LOG(" caching material '%s'", pMaterialName); IMaterial* pMaterial = gEnv->p3DEngine->GetMaterialManager()->LoadMaterial(pMaterialName); if(pMaterial) { m_materialCache.push_back(pMaterial); pMaterial->RequestTexturesLoading(0.0f); } } } else { GameWarning("Failed to find shared parameters for item '%s' - can't cache model", pItemName); } }//-------------------------------------------------------------------------------------------------
void CTacticalPointLanguageExtender::Initialize() { CryLogAlways("Registering TPS Extensions..."); INDENT_LOG_DURING_SCOPE(); if (gEnv->pAISystem->GetTacticalPointSystem()) { RegisterWithTacticalPointSystem(); RegisterQueries(); Script::Call(gEnv->pScriptSystem, "ReloadTPSExtensions"); } }
//-------------------------------------------------------------------------------------------------- // Name: ~CFrontEndModelCache // Desc: Destructor //-------------------------------------------------------------------------------------------------- CFrontEndModelCache::~CFrontEndModelCache() { FE_LOG("Front End model cache deletion"); INDENT_LOG_DURING_SCOPE(); CRY_ASSERT(s_pSingletonInstance == this); s_pSingletonInstance = NULL; m_myGeometryCache.FlushCaches(); m_materialCache.clear(); ReleaseSupportForFrontEnd3dModels(); }//-------------------------------------------------------------------------------------------------
int CScriptTable::StdCUserDataFunction( lua_State *L ) { unsigned char *pBuffer = (unsigned char*)lua_touserdata(L,lua_upvalueindex(1)); // Not very safe cast, but we sure what is in the upvalue 1 should be. UserDataFunction *pFunction = (UserDataFunction*)pBuffer; pBuffer += sizeof(UserDataFunction); int nSize = *((int*)pBuffer); // first 4 bytes are size of user data. pBuffer += sizeof(int); int8 nParamIdOffset = *(int8*)(pBuffer+nSize); const char *sFuncName = (const char*)(pBuffer+nSize+1); INDENT_LOG_DURING_SCOPE(true, "While calling function '%s'...", sFuncName); CFunctionHandler fh(m_pSS,L,sFuncName,nParamIdOffset); // Call functor. int nRet = (*pFunction)( &fh,pBuffer,nSize ); // int CallbackFunction( IFunctionHandler *pHandler,pBuffer,nSize ) return nRet; }
void CFlowAddModelToPostRender::ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { switch (event) { case eFE_Initialize: break; case eFE_Activate: if (IsPortActive(pActInfo, IN_ADD)) { INDENT_LOG_DURING_SCOPE(); //Create scene CMenuRender3DModelMgr *renderModels = CMenuRender3DModelMgr::GetInstance(); if (renderModels) { //Add model with animation if needed const float playSpeed = GetPortFloat(pActInfo, IN_ANIM_SPEED); const char * usePlayerModelName = GetPortString(pActInfo, IN_MODEL); const char * useAnimation = GetPortString(pActInfo, IN_ANIM); CMenuRender3DModelMgr::SModelParams params; params.pFilename = usePlayerModelName; params.posOffset = GetPortVec3(pActInfo, IN_ENTITYPOS); params.rot = Ang3(GetPortVec3(pActInfo, IN_ENTITYROT)); params.continuousRot = Ang3(GetPortVec3(pActInfo, IN_ENTITYCONTROT)); params.scale = GetPortFloat(pActInfo, IN_SCALE); params.pName = "char"; params.screenRect[0] = GetPortVec3(pActInfo, IN_SCREENUV).x; params.screenRect[1] = GetPortVec3(pActInfo, IN_SCREENUV).y; params.screenRect[2] = GetPortVec3(pActInfo, IN_SCREENU2V2).x; params.screenRect[3] = GetPortVec3(pActInfo, IN_SCREENU2V2).y; if(strcmp(usePlayerModelName, "") != 0) characterModelIndex = renderModels->AddModel(params); if(strcmp(useAnimation, "") != 0) renderModels->UpdateAnim(characterModelIndex, useAnimation, playSpeed); } } break; } }
void CFlowSetupModelPostRender::ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { switch (event) { case eFE_Initialize: break; case eFE_Activate: if (IsPortActive(pActInfo, IN_SHUTDOWN)) { CMenuRender3DModelMgr::Release(true); ITexture *tex = NULL; //unbind tex from MC if(gEnv->pConsole->GetCVar("r_UsePersistentRTForModelHUD")->GetIVal() > 0) tex = gEnv->pRenderer->EF_LoadTexture("$ModelHUD"); else tex = gEnv->pRenderer->EF_LoadTexture("$BackBuffer"); IUIElement* pElement = pFlashUI->GetUIElement(sUIElement.c_str()); IUIElement* pUIElement = pElement ? pElement->GetInstance(0) : NULL; if(pUIElement) pUIElement->UnloadTexFromMc(sMovieClipName.c_str(), tex); return; } if (IsPortActive(pActInfo, IN_START)) { INDENT_LOG_DURING_SCOPE(); // Setup scene settings CMenuRender3DModelMgr::SSceneSettings sceneSettings; sceneSettings.fovScale = 0.85f; sceneSettings.fadeInSpeed = 0.01f; sceneSettings.flashEdgeFadeScale = 0.0f; sceneSettings.ambientLight = Vec4(GetPortVec3(pActInfo, IN_AMBIENTLIGHTCOLOR), GetPortFloat(pActInfo, IN_AMBIENTLIGHTSTRENGTH)); sceneSettings.lights.resize(3); sceneSettings.lights[0].pos.Set(-25.f, -10.f, 30.f); sceneSettings.lights[0].color = GetPortVec3(pActInfo, IN_LIGHTCOLOR1); sceneSettings.lights[0].specular = 4.f; sceneSettings.lights[0].radius = 400.f; sceneSettings.lights[1].pos.Set(25.f, -4.f, 30.f); sceneSettings.lights[1].color = GetPortVec3(pActInfo, IN_LIGHTCOLOR2); sceneSettings.lights[1].specular = 10.f; sceneSettings.lights[1].radius = 400.f; sceneSettings.lights[2].pos.Set(60.f, 40.f, 10.f); sceneSettings.lights[2].color = GetPortVec3(pActInfo, IN_LIGHTCOLOR3); sceneSettings.lights[2].specular = 10.f; sceneSettings.lights[2].radius = 400.f; //Create scene CMenuRender3DModelMgr *renderModels = new CMenuRender3DModelMgr(); renderModels->SetSceneSettings(sceneSettings); ITexture *tex = NULL; //Fetch texture and send to movieclip if(gEnv->pConsole->GetCVar("r_UsePersistentRTForModelHUD")->GetIVal() > 0) tex = gEnv->pRenderer->EF_LoadTexture("$ModelHUD"); else tex = gEnv->pRenderer->EF_LoadTexture("$BackBuffer"); string sStr = GetPortString(pActInfo, IN_MC); string::size_type sPos = sStr.find( ':' ); sUIElement = sStr.substr( 0, sPos ); sMovieClipName = sStr.substr( sPos + 1 ); IUIElement* pElement = pFlashUI->GetUIElement(sUIElement.c_str()); IUIElement* pUIElement = pElement ? pElement->GetInstance(0) : NULL; if(pUIElement) pUIElement->LoadTexIntoMc(sMovieClipName.c_str(), tex); else CryWarning(VALIDATOR_MODULE_FLOWGRAPH, VALIDATOR_WARNING, "CFlowAdd3DModelToHUD: Movieclip not found"); //check debug info float debugscale = GetPortFloat(pActInfo, IN_DEBUGSCALE); ICVar* cv_debugRender = gEnv->pConsole->GetCVar("g_post3DRendererDebug"); if(debugscale > 0.0f) { if(cv_debugRender) { cv_debugRender->Set(2); CMenuRender3DModelMgr::GetInstance()->SetDebugScale(debugscale); } } else { cv_debugRender->Set(0); } } break; } }
//------------------------------------------------------------------------- void CGameRulesStandardState::Add3DWinningTeamMember() { IActor * localActor = g_pGame->GetIGameFramework()->GetClientActor(); if (localActor != NULL && static_cast<CActor*>(localActor)->GetSpectatorState() != CActor::eASS_SpectatorMode && !g_pGame->GetUI()->IsInMenu()) { IEntity * renderModelFromEntity = NULL; if (m_pGameRules->GetTeamCount() > 1) { // Only way to get in here is for it to be a team game (as opposed to every-man-for-himself Instant Action) const int teamId = m_pGameRules->GetTeam(localActor->GetEntityId()); assert(teamId == 1 || teamId == 2); const int enemyTeamId = 3 - teamId; const int clientTeamScore = m_pGameRules->GetTeamsScore(teamId); const int nonClientTeamScore = m_pGameRules->GetTeamsScore(enemyTeamId); bool winning = (clientTeamScore >= nonClientTeamScore); CryLog ("Want to add 3D model of winning team member... local player '%s' is %s", localActor->GetEntity()->GetName(), winning ? " on the winning team" : "not on the winning team"); if (! winning) { if (m_pGameRules->GetTeamPlayerCount(enemyTeamId, false)) { renderModelFromEntity = gEnv->pEntitySystem->GetEntity(m_pGameRules->GetTeamPlayer(enemyTeamId, 0)); } } } if (renderModelFromEntity == NULL) { // Local entity must exist (checked at top of function) so we'll _definitely_ have a renderModelFromEntity after this renderModelFromEntity = localActor->GetEntity(); } // Additional paranoia :) if (renderModelFromEntity) { CryLog ("Adding 3D model of '%s' to accompany scoreboard", renderModelFromEntity->GetName()); INDENT_LOG_DURING_SCOPE(); ICharacterInstance * characterInst = renderModelFromEntity->GetCharacter(0); if (characterInst != NULL) { CMenuRender3DModelMgr *pModelManager = new CMenuRender3DModelMgr(); CMenuRender3DModelMgr::SSceneSettings sceneSettings; sceneSettings.fovScale = 0.5f; sceneSettings.fadeInSpeed = 0.01f; sceneSettings.flashEdgeFadeScale = 0.2f; sceneSettings.ambientLight = Vec4(0.f, 0.f, 0.f, 0.8f); sceneSettings.lights.resize(3); sceneSettings.lights[0].pos.Set(-25.f, -10.f, 30.f); sceneSettings.lights[0].color.Set(5.f, 6.f, 5.5f); sceneSettings.lights[0].specular = 4.f; sceneSettings.lights[0].radius = 400.f; sceneSettings.lights[1].pos.Set(25.f, -4.f, 30.f); sceneSettings.lights[1].color.Set(0.7f, 0.7f, 0.7f); sceneSettings.lights[1].specular = 10.f; sceneSettings.lights[1].radius = 400.f; sceneSettings.lights[2].pos.Set(60.f, 40.f, 10.f); sceneSettings.lights[2].color.Set(0.5f, 1.0f, 0.7f); sceneSettings.lights[2].specular = 10.f; sceneSettings.lights[2].radius = 400.f; pModelManager->SetSceneSettings(sceneSettings); const char * usePlayerModelName = characterInst->GetFilePath(); CMenuRender3DModelMgr::SModelParams params; params.pFilename = usePlayerModelName; params.posOffset.Set(0.1f, 0.f, -0.2f); params.rot.Set(0.f, 0.f, 3.5f); params.scale = 1.35f; params.pName = "char"; params.screenRect[0] = 0.f; params.screenRect[1] = 0.f; params.screenRect[2] = 0.3f; params.screenRect[3] = 0.8f; const float ANIM_SPEED_MULTIPLIER = 0.5f; if (m_pGameRules->GetGameMode() == eGM_Gladiator) { // In Hunter mode, force the model to be a hunter params.pFilename = "_ObjectsSDK/Characters/Human/sdk_player/sdk_player.cdf"; } const CMenuRender3DModelMgr::TAddedModelIndex characterModelIndex = pModelManager->AddModel(params); pModelManager->UpdateAnim(characterModelIndex, "stand_tac_idle_nw_3p_01", ANIM_SPEED_MULTIPLIER); } } } }
//-------------------------------------------------------------------------------------------------- // Name: CFrontEndModelCache // Desc: Constructor //-------------------------------------------------------------------------------------------------- CFrontEndModelCache::CFrontEndModelCache() { #if FEMC_USE_LEVEL_HEAP SwitchToLevelHeap(); #endif // #if FEMC_USE_LEVEL_HEAP FE_LOG("Front End model cache creation"); INDENT_LOG_DURING_SCOPE(); IGameFramework* pGameFramework = g_pGame->GetIGameFramework(); if(pGameFramework) { pGameFramework->StartNetworkStallTicker(true); } m_bIsMultiplayerCache = gEnv->bMultiplayer; #if FEMC_FILE_ACCESS_LOG gEnv->pConsole->GetCVar("sys_FileAccessLog")->Set(1); #endif // #if FEMC_FILE_ACCESS_LOG #ifdef FEMC_LOG_CACHE_TIME const float startTime = gEnv->pTimer->GetAsyncCurTime(); #endif // #ifdef FEMC_LOG_CACHE_TIME #if FEMC_CACHE_FILE_ACCESSES if (g_pGameCVars->g_FEMenuCacheSaveList) { gEnv->pCryPak->RegisterFileAccessSink(this); m_recordedFiles.clear(); } int oldSaveLevelResourceList = 0; ICVar* pPakSaveLevelResourceListCvar = gEnv->pConsole->GetCVar("sys_PakSaveLevelResourceList"); if(pPakSaveLevelResourceListCvar) { oldSaveLevelResourceList = pPakSaveLevelResourceListCvar->GetIVal(); pPakSaveLevelResourceListCvar->Set(0); } m_pReasonForReportingFileOpen = "CFrontEndModelCache constructor"; #endif // #if FEMC_CACHE_FILE_ACCESSES CRY_ASSERT(s_pSingletonInstance == NULL); s_pSingletonInstance = this; // Load model list from xml, and cache each entry XmlNodeRef pRootNode = gEnv->pSystem->LoadXmlFromFile(FEMC_CACHE_LIST_FILENAME); if(pRootNode) { CGameXmlParamReader xmlParamReader(pRootNode); const char* pPakName = NULL; // Pak const char* const pGameFolder = gEnv->pCryPak->GetGameFolder(); const XmlNodeRef pPakData = xmlParamReader.FindFilteredChild("PakData"); if(pPakData && pPakData->getChildCount()) { const XmlNodeRef pPak = pPakData->getChild(0); if(pPak) { pPakName = pPak->getAttr("name"); bool bSucceeded = gEnv->pCryPak->OpenPack(pGameFolder,pPakName,ICryPak::FLAGS_FILENAMES_AS_CRC32); bSucceeded |= gEnv->pCryPak->LoadPakToMemory(pPakName,ICryPak::eInMemoryPakLocale_GPU); FE_LOG ("%s to open pack file '%s' bound to %s", bSucceeded ? "Managed" : "Failed", pPakName, pGameFolder); } // There is a pak, so reserve space for some materials in cache const uint materialCacheReserve = 64; m_materialCache.reserve(materialCacheReserve); } // Cache character models const XmlNodeRef pCharacterModelList = xmlParamReader.FindFilteredChild("CharacterModels"); if(pCharacterModelList) { const int characterModelCount = pCharacterModelList->getChildCount(); if(characterModelCount) { CreateSupportForFrontEnd3dModels(); } for(int i=0; i<characterModelCount; i++) { const XmlNodeRef pCharacterModel = pCharacterModelList->getChild(i); if(pCharacterModel) { const char* pCharacterModelName = pCharacterModel->getAttr("name"); CacheCharacterModel(pCharacterModelName); } } } // Cache item models const XmlNodeRef pItemModelsList = xmlParamReader.FindFilteredChild("ItemModels"); if(pItemModelsList) { const int itemModelCount = pItemModelsList->getChildCount(); if(itemModelCount) { CreateSupportForFrontEnd3dModels(); } for(int i=0; i<itemModelCount; i++) { const XmlNodeRef pItemModel = pItemModelsList->getChild(i); if(pItemModel) { const char* pItemModelName = pItemModel->getAttr("name"); if (strcmp(pItemModel->getTag(), "GeometryModels") == 0) { m_myGeometryCache.CacheGeometry(pItemModelName, false, IStatObj::ELoadingFlagsIgnoreLoDs); } else if (strcmp(pItemModel->getTag(), "ItemModel") == 0) { CacheItemModel(pItemModelName); } } } } // Unload pak if(pPakName) { gEnv->pCryPak->LoadPakToMemory( pPakName,ICryPak::eInMemoryPakLocale_Unload ); bool bSucceeded = gEnv->pCryPak->ClosePack( pPakName,0 ); FE_LOG ("%s to close pack file '%s'", bSucceeded ? "Managed" : "Failed", pPakName); } } #if FEMC_FILE_ACCESS_LOG gEnv->pConsole->GetCVar("sys_FileAccessLog")->Set(0); #endif // #if FEMC_FILE_ACCESS_LOG #ifdef FEMC_LOG_CACHE_TIME const float endTime = gEnv->pTimer->GetAsyncCurTime(); const float deltaTime = endTime - startTime; FE_LOG("FrontEndModelCache loading took %3.1f seconds", deltaTime); #endif // #FEMC_LOG_CACHE_TIME FE_MODEL_CACHE_LOG_CACHE_TIME #if FEMC_CACHE_FILE_ACCESSES m_pReasonForReportingFileOpen = NULL; if (g_pGameCVars->g_FEMenuCacheSaveList) { // To stop any other threads from messing gEnv->pCryPak->UnregisterFileAccessSink(this); std::set<string> fileset; // eliminate duplicate values std::vector<string>::iterator endLocation = std::unique( m_recordedFiles.begin(),m_recordedFiles.end() ); m_recordedFiles.erase( endLocation,m_recordedFiles.end() ); fileset.insert( m_recordedFiles.begin(),m_recordedFiles.end() ); string sResourceSetFilename = PathUtil::AddSlash("Levels/Multiplayer") + "mpmenu_list.txt"; { FILE* pFile = fxopen(sResourceSetFilename,"wb",true); if(pFile) { for(std::set<string>::iterator it = fileset.begin(); it != fileset.end(); ++it) { const char *pStr = it->c_str(); fprintf( pFile,"%s\n",pStr ); // Automatically add cgf->cgfm, cga->cgam, dds->dds.0 const char* const pExt = PathUtil::GetExt(pStr); if (strcmp(pExt, "cgf") == 0) { fprintf( pFile,"%sm\n",pStr ); } else if (strcmp(pExt, "cga") == 0) { fprintf( pFile,"%sm\n",pStr ); } else if (strcmp(pExt, "dds") == 0) { fprintf( pFile,"%s.0\n",pStr ); } } fclose(pFile); } } } if(pPakSaveLevelResourceListCvar) { pPakSaveLevelResourceListCvar->Set(oldSaveLevelResourceList); } #endif // #if FEMC_CACHE_FILE_ACCESSES if(pGameFramework) { pGameFramework->StopNetworkStallTicker(); } FE_LOG("Done caching items for front end"); #if FEMC_USE_LEVEL_HEAP SwitchToGlobalHeap(); #endif // #if FEMC_USE_LEVEL_HEAP }//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------- // Name: CacheCharacterModel // Desc: Cache character model //-------------------------------------------------------------------------------------------------- void CFrontEndModelCache::CacheCharacterModel(const char* pModelFileName) { FE_LOG("Caching \"%s\"", pModelFileName); INDENT_LOG_DURING_SCOPE(); m_myGeometryCache.CacheGeometry(pModelFileName, false, IStatObj::ELoadingFlagsIgnoreLoDs); }//-------------------------------------------------------------------------------------------------