void CMaterialEffects::LoadFXLibraries()
{
	MEMSTAT_CONTEXT(EMemStatContextTypes::MSC_Other, 0, "MaterialEffects");

	m_mfxLibraries.clear();
	m_effectContainers.clear();
	m_effectContainers.push_back(0); // 0 -> invalid effect id

	ICryPak *pak = gEnv->pCryPak;
	_finddata_t fd;

	stack_string searchPath;
	searchPath.Format("%s/*.xml", MATERIAL_EFFECTS_LIBRARIES_FOLDER);
	intptr_t handle = pak->FindFirst(searchPath.c_str(), &fd);
	int res = 0;
	if (handle != -1)
	{
		do 
		{
			LoadFXLibrary(fd.name);
			res = pak->FindNext(handle, &fd);
			SLICE_AND_SLEEP();
		} while(res >= 0);
		pak->FindClose(handle);
	}

	m_canopySurfaceId = MaterialEffectsUtils::FindSurfaceIdByName(MATERIAL_EFFECTS_SURFACE_TYPE_CANOPY);
}
EntityId CAICorpseManager::SpawnAICorpseFromEntity( IEntity& sourceEntity, const SCorpseParameters& corpseParams )
{
	assert(gEnv->IsEditor() == false);
	assert(gEnv->bMultiplayer == false);

	if(g_pGameCVars->g_aiCorpses_Enable == 0)
		return 0;

	if(m_corpsesArray.size() == m_maxCorpses)
	{
		RemoveSomeCorpses();

		assert((uint32)m_corpsesArray.size() < m_maxCorpses);
	}

	MEMSTAT_CONTEXT(EMemStatContextTypes::MSC_Other, EMemStatContextFlags::MSF_None, "AICorpseManager::SpawnCorpse");

	EntityId corpseId = 0;
	IPhysicalEntity* pSourcePhysics = sourceEntity.GetPhysics();
	if ((pSourcePhysics != NULL) && (pSourcePhysics->GetType() == PE_ARTICULATED))
	{
		ICharacterInstance *pSourceCharacterInstance = sourceEntity.GetCharacter(0);

		if (pSourceCharacterInstance != NULL)
		{
			IEntityClass *pCorpseClass =  gEnv->pEntitySystem->GetClassRegistry()->FindClass("AICorpse");
			assert(pCorpseClass);

			stack_string corpseName;
			corpseName.Format("%s_Corpse", sourceEntity.GetName());
			SEntitySpawnParams params;
			params.pClass = pCorpseClass;
			params.sName = corpseName.c_str();

#if !AI_CORPSES_ENABLE_SERIALIZE
			params.nFlags |= ENTITY_FLAG_NO_SAVE;
#endif

			params.vPosition = sourceEntity.GetWorldPos();
			params.qRotation = sourceEntity.GetWorldRotation();

			IEntity *pCorpseEntity = gEnv->pEntitySystem->SpawnEntity(params, true);
			if(pCorpseEntity != NULL)
			{
				corpseId = pCorpseEntity->GetId();
				
				CorpseInfo* pCorpseInfo = FindCorpseInfo( corpseId );
				assert(pCorpseInfo != NULL);

				CAICorpse* pCorpse = pCorpseInfo->GetCorpse();
				assert(pCorpse != NULL);
				pCorpse->SetupFromSource( sourceEntity, *pSourceCharacterInstance, (uint32)corpseParams.priority);
			}
		}
	}

	return corpseId;
}
Exemple #3
0
bool CGameStartup::InitFramework(SSystemInitParams &startupParams)
{
	MEMSTAT_CONTEXT(EMemStatContextTypes::MSC_Other, 0, "Init Game Framework" );

#if !defined(_LIB)
	m_frameworkDll = GetFrameworkDLL(startupParams.szBinariesDir);

	if (!m_frameworkDll)
	{
		// failed to open the framework dll
		CryFatalError("Failed to open the GameFramework DLL!");
		
		return false;
	}

	IGameFramework::TEntryFunction CreateGameFramework = (IGameFramework::TEntryFunction)CryGetProcAddress(m_frameworkDll, DLL_INITFUNC_CREATEGAME );

	if (!CreateGameFramework)
	{
		// the dll is not a framework dll
		CryFatalError("Specified GameFramework DLL is not valid!");

		return false;
	}
#endif //_LIB

	m_pFramework = CreateGameFramework();

	if (!m_pFramework)
	{
		CryFatalError("Failed to create the GameFramework Interface!");
		// failed to create the framework

		return false;
	}

#ifdef WIN32
	if (startupParams.pSystem == NULL || (!startupParams.bEditor && !gEnv->IsDedicated()))
	{
		::ShowCursor(FALSE); // Hide the cursor during loading (it will be shown again in Run())
	}
#endif

	// initialize the engine
	if (!m_pFramework->Init(startupParams))
	{
		CryFatalError("Failed to initialize CryENGINE!");

		return false;
	}
	ModuleInitISystem(m_pFramework->GetISystem(),"CryGame");

#ifdef WIN32
	SetWindowLongPtr(reinterpret_cast<HWND>(gEnv->pRenderer->GetHWND()), GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
#endif
	return true;
}
// Loads equipment packs from rootNode 
void CEquipmentManager::LoadEquipmentPacks(const XmlNodeRef& rootNode)
{
	MEMSTAT_CONTEXT(EMemStatContextTypes::MSC_Other, 0, "Equipment Packs");

	if (rootNode->isTag("EquipPacks") == false)
		return;
	
	for (int i=0; i<rootNode->getChildCount(); ++i)
	{
		XmlNodeRef packNode = rootNode->getChild(i);
		LoadEquipmentPack(packNode, true);
	}
}
bool CGameStartup::InitFramework(SSystemInitParams& startupParams)
{
	MEMSTAT_CONTEXT(EMemStatContextTypes::MSC_Other, 0, "Init Game Framework" );

#if !defined(_LIB)
	m_frameworkDll = GetFrameworkDLL(startupParams.szBinariesDir);

	if (!m_frameworkDll)
	{
		CryFatalError("Failed to open the GameFramework DLL!");
		return false;
	}

	IGameFramework::TEntryFunction CreateGameFramework = (IGameFramework::TEntryFunction)CryGetProcAddress(m_frameworkDll, DLL_INITFUNC_CREATEGAME);

	if (!CreateGameFramework)
	{
		CryFatalError("Specified GameFramework DLL is not valid!");
		return false;
	}
#endif

	m_pFramework = CreateGameFramework();

	if (!m_pFramework)
	{
		CryFatalError("Failed to create the GameFramework Interface!");
		return false;
	}

	if (!m_pFramework->Init(startupParams))
	{
		CryFatalError("Failed to initialize CryENGINE!");
		return false;
	}

	ModuleInitISystem(m_pFramework->GetISystem(), GAME_NAME);

#if CRY_PLATFORM_WINDOWS
	SetWindowLongPtr(reinterpret_cast<HWND>(gEnv->pRenderer->GetHWND()), GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
#endif

	return true;
}
Exemple #6
0
bool CEntityPool::CreatePoolEntity(CEntity* &pOutEntity, bool bAddToInactiveList)
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_ENTITY);

	assert(!gEnv->IsEditor());

	MEMSTAT_CONTEXT(EMemStatContextTypes::MSC_Other, EMemStatContextFlags::MSF_Instance, "Create Pool Entity");

	bool bResult = false;

	assert(m_pEntityPoolManager);
	CEntitySystem* pEntitySystem = m_pEntityPoolManager->GetEntitySystem();

	if (pEntitySystem)
	{
		SEntitySpawnParams params;
		CreateSpawnParams(params);
		params.vScale.Set(1.0f,1.0f,1.0f);

		CEntity* pEntity = (CEntity*)pEntitySystem->SpawnEntity(params);
		if (pEntity)
		{
			pEntity->SetPoolControl(true);

			// Put into map
			if (bAddToInactiveList)
			{
				const EntityId poolId = pEntity->GetId();
				stl::push_back_unique(m_InactivePoolIds, poolId);
			}

			pOutEntity = pEntity;
			bResult    = true;
		}
	}

	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 );
	}
}
//------------------------------------------------------------------------
void CInventory::FullSerialize( TSerialize ser )
{
	MEMSTAT_CONTEXT(EMemStatContextTypes::MSC_Other, 0, "Inventory serialization");

	IEntityPoolManager* pMgr = gEnv->pEntitySystem->GetIEntityPoolManager();

	if(pMgr && !gEnv->pSystem->IsSerializingFile())
	{
		// Entities being activated from the pool shouldn't
		//	serialize their inventories. The item ids in the bookmark
		//	refer to the previous entities which no longer exist, instead the
		//	actor will have been given a new equipment pack instead. 
		//	In that case just holster the default weapon. We will have to
		//  select it after on the behavior or on the entity side
		
		if (ser.IsReading())
		{
			EntityId currentItemId = 0;
			bool isUsing = false;

			ser.Value("using", isUsing);
			ser.Value("CurrentItem", currentItemId);

			if (currentItemId)
			{
				IItem *pItem = m_pGameFrameWork->GetIItemSystem()->GetItem(currentItemId);
				if(pItem && isUsing && !pItem->IsUsed())
				{
					pItem->Use(GetEntityId());
				
					return;
				}
			}

			HolsterItem(true);
		}
		else
		{
			bool isUsing = false;
			if (IItem *pItem = m_pGameFrameWork->GetIItemSystem()->GetItem(m_stats.currentItemId))
				isUsing = pItem->IsUsed() && pItem->GetOwnerId() == GetEntityId();

			ser.Value("using", isUsing);
			ser.Value("CurrentItem", m_stats.currentItemId);
		}

		return;
	}
	
	ser.BeginGroup("InventoryItems");

	ser.Value("CurrentItem", m_stats.currentItemId);
	ser.Value("HolsterItem", m_stats.holsteredItemId);
	ser.Value("LastItem", m_stats.lastItemId);
	int s = m_stats.slots.size();
	ser.Value("InventorySize", s);
	if(ser.IsReading())
		m_stats.slots.resize(s);

	ser.Value("Slots", m_stats.slots );

	ser.BeginGroup("accessorySlots");
	int exSize = m_stats.accessorySlots.size();
	ser.Value("Size", exSize);

	for(int i = 0; i < IInventory::eInventorySlot_Last; ++i)
	{
		ser.BeginGroup("SlotInfo");
		ser.Value("slotInfoCount", m_stats.slotsInfo[i].count);
		ser.Value("slotInfoLastSelected", m_stats.slotsInfo[i].lastSelected);
		ser.EndGroup();
	}

	if(ser.IsReading())
	{
		m_stats.accessorySlots.resize(0);
		if(exSize>0)
			m_stats.accessorySlots.reserve(exSize);
	}
	for(int i = 0; i<exSize; ++i)
	{
		string accessoryName;
		if(ser.IsWriting())
			accessoryName = m_stats.accessorySlots[i]->GetName();

		ser.BeginGroup("Class");
		ser.Value("AccessoryName", accessoryName);
		ser.EndGroup();

		if(ser.IsReading())
		{
			IEntityClass* pAccessoryClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(accessoryName);
			CRY_ASSERT(pAccessoryClass);
			if (pAccessoryClass != NULL)
			{
				m_stats.accessorySlots.push_back(pAccessoryClass);
			}
		}
	}
	ser.EndGroup();//"accessorySlots"

	ser.BeginGroup("Ammo");
	if(ser.IsReading())
	{
		m_stats.ammoInfo.clear();
	}

	TAmmoInfoMap::iterator ammoInfoIt = m_stats.ammoInfo.begin();
	int ammoAmount = m_stats.ammoInfo.size();
	ser.Value("AmmoAmount", ammoAmount);
	for(int i = 0; i < ammoAmount; ++i)
	{
		string name;
		int amount = 0;
		int capacity = 0;
		if(ser.IsWriting())
		{
			IEntityClass* pAmmoClass = ammoInfoIt->first;
			CRY_ASSERT(pAmmoClass);
			name = (pAmmoClass) ? pAmmoClass->GetName() : "";

			const SAmmoInfo& ammoInfo = ammoInfoIt->second;

			amount = ammoInfo.GetCount();
			//users = ammoInfo.GetUserCount();
			capacity = ammoInfo.GetCapacity(); 
			// Only use this iterator writing. If we're reading, we change the size
			// of the map and end up with an out of sync (and invalid) iterator.
			++ammoInfoIt;
		}
		ser.BeginGroup("Ammo");
		ser.Value("AmmoName", name);
		ser.Value("Bullets", amount);
		ser.Value("Capacity", capacity);
		ser.EndGroup();
		if(ser.IsReading())
		{
			IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(name);
			CRY_ASSERT(pClass);
			TAmmoInfoMap::iterator it = m_stats.ammoInfo.find(pClass);
			if (it == m_stats.ammoInfo.end())
			{
				m_stats.ammoInfo[pClass] = SAmmoInfo(amount, capacity);
			}
			else
			{
				it->second.SetCount(amount);
				it->second.SetCapacity(capacity);
			}
		}
	}
	ser.EndGroup();

/*
	ser.BeginGroup("CategorySlots");

	for (TSlotsInfo::iterator it = m_stats.slotsInfo.begin(); it != m_stats.slotsInfo.end(); ++it)
	{
		ser.Value("Count", it->second.count);
	}

	ser.EndGroup();*/


	ser.EndGroup();
}
Exemple #9
0
IGameRef CGameStartup::Init(SSystemInitParams &startupParams)
{
	MEMSTAT_CONTEXT(EMemStatContextTypes::MSC_Other, 0, "Game startup initialization");

	LOADING("game_startup");

	if (!InitFramework(startupParams))
	{
		return 0;
	}

	// Configuration for this game
	ICVar *pCVar = gEnv->pConsole->GetCVar("ai_CompatibilityMode");
	if (pCVar)
		pCVar->Set("crysis");

  LOADING_TIME_PROFILE_SECTION(m_pFramework->GetISystem());

	ISystem* pSystem = m_pFramework->GetISystem();
	IConsole* pConsole = gEnv->pConsole;
	startupParams.pSystem = pSystem;

#if defined(ENABLE_STATS_AGENT)
	const ICmdLineArg *pPipeArg = pSystem->GetICmdLine()->FindArg(eCLAT_Pre,"lt_pipename");
	CStatsAgent::CreatePipe( pPipeArg );
#endif

	PluginManager::InitPluginManager(startupParams);
    PluginManager::InitPluginsBeforeFramework();

	REGISTER_COMMAND("g_loadMod", RequestLoadMod,VF_NULL,"");

	// load the appropriate game/mod
	const ICmdLineArg *pModArg = pSystem->GetICmdLine()->FindArg(eCLAT_Pre,"MOD");

	IGameRef pOut;
	if (pModArg && (*pModArg->GetValue() != 0) && (pSystem->IsMODValid(pModArg->GetValue())))
	{
		const char* pModName = pModArg->GetValue();
		assert(pModName);

		pOut = Reset(pModName);
	}
	else
	{
		pOut = Reset(GAME_NAME);
	}

	// Load all localized strings.
	LoadLocalizationData();

	if (!m_pFramework->CompleteInit())
	{
		pOut->Shutdown();
		return 0;
	}

	LOADING_DONE;

	// should be after init game (should be executed even if there is no game)
	if(startupParams.bExecuteCommandLine)
		pSystem->ExecuteCommandLine();

	pSystem->GetISystemEventDispatcher()->RegisterListener( &g_system_event_listener_game );

	// Creates and starts the realtime update system listener.
	if (pSystem->IsDevMode())
	{
		CGameRealtimeRemoteUpdateListener::GetGameRealtimeRemoteUpdateListener().Enable(true);
	}

	GCOV_FLUSH;

	if (gEnv && GetISystem())
	{
	}
	else
	{
		CryLogAlways("failed to find ISystem to register error observer");
		assert(0);
	}

	PluginManager::InitPluginsLast();
	return pOut;
}
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;
}
Exemple #11
0
IGameRef CGameStartup::Init(SSystemInitParams &startupParams)
{
	MEMSTAT_CONTEXT(EMemStatContextTypes::MSC_Other, 0, "Game startup initialisation");

#if defined(CVARS_WHITELIST)
	startupParams.pCVarsWhitelist = &g_CVarsWhiteList;
#endif // defined(CVARS_WHITELIST)
	startupParams.pGameStartup = this;

	if (!InitFramework(startupParams))
	{
		return 0;
	}

	InlineInitializationProcessing("CGameStartup::Init");

  LOADING_TIME_PROFILE_SECTION(m_pFramework->GetISystem());

	ISystem* pSystem = m_pFramework->GetISystem();
	startupParams.pSystem = pSystem;

	const ICmdLineArg* pSvBind = gEnv->pSystem->GetICmdLine()->FindArg(eCLAT_Pre, "sv_bind"); 
	IConsole* pConsole = pSystem->GetIConsole();
	if ((pSvBind != NULL) && (pConsole != NULL))
	{
		string command = pSvBind->GetName() + string(" ") + pSvBind->GetValue();
		pConsole->ExecuteString(command.c_str(), true, false);
	}

#if defined(ENABLE_STATS_AGENT)
	const ICmdLineArg *pPipeArg = pSystem->GetICmdLine()->FindArg(eCLAT_Pre,"lt_pipename");
	CStatsAgent::CreatePipe( pPipeArg );
#endif

	REGISTER_COMMAND("g_loadMod", CGameStartupStatic::RequestLoadMod,VF_NULL,"");
	REGISTER_COMMAND("g_unloadMod", CGameStartupStatic::RequestUnloadMod, VF_NULL, "");

	// load the appropriate game/mod
#if !defined(_RELEASE)
	const ICmdLineArg *pModArg = pSystem->GetICmdLine()->FindArg(eCLAT_Pre,"MOD");
#else
	const ICmdLineArg *pModArg = NULL;
#endif // !defined(_RELEASE)

	InlineInitializationProcessing("CGameStartup::Init LoadLocalizationData");

	IGameRef pOut;
	if (pModArg && (*pModArg->GetValue() != 0) && (pSystem->IsMODValid(pModArg->GetValue())))
	{
		const char* pModName = pModArg->GetValue();
		assert(pModName);

		pOut = Reset(pModName);
	}
	else
	{
		pOut = Reset(GAME_NAME);
	}

	if (!m_pFramework->CompleteInit())
	{
		pOut->Shutdown();
		return 0;
	}

	InlineInitializationProcessing("CGameStartup::Init FrameworkCompleteInit");

	// should be after init game (should be executed even if there is no game)
	if(startupParams.bExecuteCommandLine)
		pSystem->ExecuteCommandLine();

	pSystem->GetISystemEventDispatcher()->RegisterListener(this);

	// Creates and starts the realtime update system listener.
	if (pSystem->IsDevMode())
	{
		CGameRealtimeRemoteUpdateListener::GetGameRealtimeRemoteUpdateListener().Enable(true);
	}


	GCOV_FLUSH;

	if (ISystem *pSystem = gEnv ? GetISystem() : NULL)
	{
		pSystem->RegisterErrorObserver(&m_errorObsever);
		pSystem->RegisterWindowMessageHandler(this);
	}
	else
	{
		CryLogAlways("failed to find ISystem to register error observer");
		assert(0);
	}

	
	InlineInitializationProcessing("CGameStartup::Init End");

#if defined(CRY_UNIT_TESTING)
	// Register All unit tests of this module.
#if defined(_LIB)
	if(gEnv->pSystem)
	{
		CryUnitTest::Test *pTest = CryUnitTest::Test::m_pFirst; 
		for (; pTest != 0; pTest = pTest->m_pNext)
		{
			CryUnitTest::IUnitTestManager *pTestManager = gEnv->pSystem->GetITestSystem()->GetIUnitTestManager();
			if (pTestManager)
			{
				pTest->m_unitTestInfo.module = "StaticBinary";
				pTestManager->CreateTest( pTest->m_unitTestInfo );
			}
		}
	}
#endif

	// run unit tests
	CryUnitTest::IUnitTestManager *pTestManager =  (gEnv && gEnv->pSystem) ? gEnv->pSystem->GetITestSystem()->GetIUnitTestManager() : NULL;
	if (pTestManager)
	{
		const ICmdLineArg* pSkipUnitTest = gEnv->pSystem->GetICmdLine()->FindArg(eCLAT_Pre, "skip_unit_tests"); 
		if(pSkipUnitTest == NULL)
		{
			const ICmdLineArg* pUseUnitTestExcelReporter = gEnv->pSystem->GetICmdLine()->FindArg(eCLAT_Pre, "use_unit_test_excel_reporter"); 
			if(pUseUnitTestExcelReporter)
			{
				gEnv->pSystem->GetITestSystem()->GetIUnitTestManager()->RunAllTests(CryUnitTest::ExcelReporter);
			}
			else // default is the minimal reporter
			{
				gEnv->pSystem->GetITestSystem()->GetIUnitTestManager()->RunAllTests(CryUnitTest::MinimalReporter);
			}
		}
	}
#endif // CRY_UNIT_TESTING
	
	assert(gEnv);
	PREFAST_ASSUME(gEnv);
	
	GetISystem()->GetISystemEventDispatcher()->OnSystemEvent(ESYSTEM_EVENT_RANDOM_SEED, (UINT_PTR)gEnv->pTimer->GetAsyncTime().GetMicroSecondsAsInt64(), 0);
	return pOut;
}
Exemple #12
0
void CScriptProxy::Serialize( TSerialize ser )
{
	CHECK_SCRIPT_STACK;

	if (ser.GetSerializationTarget() != eST_Network)
	{
		MEMSTAT_CONTEXT(EMemStatContextTypes::MSC_Other, 0, "Script proxy serialization");

		if (NeedSerialize())
		{
			if (ser.BeginOptionalGroup("ScriptProxy", true))
			{
				ser.Value("scriptUpdateRate", m_fScriptUpdateRate);
				int currStateId = m_nCurrStateId;
				ser.Value("currStateId", currStateId);

				// Simulate state change
				if (m_nCurrStateId != currStateId)
				{
					// If state changed kill all old timers.
					m_pEntity->KillTimer(-1);
					m_nCurrStateId = currStateId;
				}
				if (ser.IsReading())
				{
					// Repeat check if update script function is implemented.
					m_bUpdateScript = CurrentState()->IsStateFunctionImplemented(ScriptState_OnUpdate);
				}

				if (CVar::pEnableFullScriptSave && CVar::pEnableFullScriptSave->GetIVal())
				{
					ser.Value( "FullScriptData", m_pThis );
				}
				else if (m_pThis->HaveValue("OnSave") && m_pThis->HaveValue("OnLoad"))
				{
					//SerializeTable( ser, "Properties" );
					//SerializeTable( ser, "PropertiesInstance" );
					//SerializeTable( ser, "Events" );

					SmartScriptTable persistTable(m_pThis->GetScriptSystem());
					if (ser.IsWriting())
						Script::CallMethod(m_pThis, "OnSave", persistTable);
					ser.Value( "ScriptData", persistTable.GetPtr());
					if (ser.IsReading())
						Script::CallMethod(m_pThis, "OnLoad", persistTable);
				}

				ser.EndGroup(); //ScriptProxy
			}
			else
			{
				// If we haven't already serialized the script proxy then reset it back to the default state.

				CRY_ASSERT(m_pScript);

				m_pScript->Call_OnReset(m_pThis, true);
			}
		}
	}
	else
	{
		int stateId = m_nCurrStateId;
		ser.Value("currStateId", stateId, 'sSts');
		if (ser.IsReading())
			GotoState(stateId);
	}
}