Sources/CryGame C++/Solution1/CryGame/Game.cpp
//////////////////////////////////////////////////////////////////////
//! Initialize the game. This must be called before calling other functions of this class.

Initialize the game. This must be called before calling other functions of this class.
Initialize the game . This must be called before calling other functions of this class .
bool CXGame::Init(struct ISystem *pSystem,bool bDedicatedSrv,bool bInEditor,const char *szGameMod)
{	
	m_pSystem	= pSystem;
	m_pGameMods = new CGameMods(this);
	gISystem = pSystem;
	m_bDedicatedServer=bDedicatedSrv;
	m_XAreaMgr.Init( pSystem );
	m_bEditor=bInEditor;
	m_bRelaunch=false;
	m_bMovieSystemPaused = false;
	m_bIsLoadingLevelFromFile=false;
	m_bOK = false;
	m_bUpdateRet = true;
	m_pClient	= NULL;
	m_pServer	= NULL;
  m_pSystem->GetILog()->Log("Game Initialization");
#if !defined(LINUX)	
	IMovieSystem *pMovieSystem=m_pSystem->GetIMovieSystem();
	if (pMovieSystem)
		pMovieSystem->SetUser(m_pMovieUser);
#endif
	if (!m_pTimeDemoRecorder)
		m_pTimeDemoRecorder = new CTimeDemoRecorder(pSystem);
	m_pUIHud = NULL;
	m_pNetwork= m_pSystem->GetINetwork();
	m_pLog= m_pSystem->GetILog();
	m_p3DEngine	= m_pSystem->GetI3DEngine();
	m_pRenderer = m_pSystem->GetIRenderer();
	m_pScriptSystem=pSystem->GetIScriptSystem();
	m_pEntitySystem=m_pSystem->GetIEntitySystem();
#ifndef _XBOX
	m_pServerSnooper=m_pNetwork->CreateServerSnooper(this);
	m_pNETServerSnooper=m_pNetwork->CreateNETServerSnooper(this);
	m_pRConSystem=m_pNetwork->CreateRConSystem();
#endif
	m_pWeaponSystemEx = new CWeaponSystemEx();
	m_pVehicleSystem = new CVehicleSystem();
	m_pPlayerSystem = new CPlayerSystem();
	m_pFlockManager = new CFlockManager(m_pSystem);
	CScriptObjectUI::InitializeTemplate(m_pScriptSystem);
	m_pScriptObjectGame=new CScriptObjectGame;
	CScriptObjectGame::InitializeTemplate(m_pScriptSystem);
	m_pScriptObjectInput=new CScriptObjectInput;
	CScriptObjectInput::InitializeTemplate(m_pScriptSystem);
	m_pScriptObjectLanguage=new CScriptObjectLanguage;
	CScriptObjectLanguage::InitializeTemplate(m_pScriptSystem);
	m_pScriptObjectBoids = new CScriptObjectBoids;
	CScriptObjectBoids::InitializeTemplate(m_pScriptSystem);
	m_pScriptObjectAI = new CScriptObjectAI;
	CScriptObjectAI::InitializeTemplate(m_pScriptSystem);
	CScriptObjectServer::InitializeTemplate(m_pScriptSystem);
	CScriptObjectPlayer::InitializeTemplate(m_pScriptSystem);
	CScriptObjectFireParam::InitializeTemplate(m_pScriptSystem);
	CScriptObjectWeaponClass::InitializeTemplate(m_pScriptSystem);
	CScriptObjectVehicle::InitializeTemplate(m_pScriptSystem);
	CScriptObjectSpectator::InitializeTemplate(m_pScriptSystem);
	CScriptObjectAdvCamSystem::InitializeTemplate(m_pScriptSystem);
	CScriptObjectSynched2DTable::InitializeTemplate(m_pScriptSystem);
	CScriptObjectRenderer::InitializeTemplate(m_pScriptSystem);
	m_pScriptObjectGame->Init(m_pScriptSystem, this);
	m_pScriptObjectInput->Init(m_pScriptSystem,this,m_pSystem);
	m_pScriptObjectBoids->Init(m_pScriptSystem,m_pSystem,m_pFlockManager);
	m_pScriptObjectLanguage->Init(m_pScriptSystem,&m_StringTableMgr);
	m_pScriptObjectAI->Init(m_pScriptSystem,m_pSystem,this);
	CScriptObjectServerSlot::InitializeTemplate(m_pScriptSystem);
	CScriptObjectClient::InitializeTemplate(m_pScriptSystem);
	CScriptObjectStream::InitializeTemplate(m_pScriptSystem);
	m_pScriptTimerMgr=new CScriptTimerMgr(m_pScriptSystem,m_pSystem->GetIEntitySystem(),this);
	m_pScriptSystem->SetGlobalValue("FireActivation_OnPress",ePressing);
	m_pScriptSystem->SetGlobalValue("FireActivation_OnRelease",eReleasing);
	m_pScriptSystem->SetGlobalValue("FireActivation_OnHold",eHolding);
	m_pScriptSystem->SetGlobalValue("ENTITYTYPE_PLAYER", ENTITYTYPE_PLAYER);
	m_pScriptSystem->SetGlobalValue("ENTITYTYPE_WAYPOINT", ENTITYTYPE_WAYPOINT);
	m_pScriptSystem->SetGlobalValue("ENTITYTYPE_OWNTEAM", ENTITYTYPE_OWNTEAM);
	InitConsoleVars();
	if (szGameMod && szGameMod[0])
	{
		GetModsInterface()->SetCurrentMod(szGameMod,false);
	}
	InitClassRegistry();
	m_pScriptSystem->ExecuteFile("scripts/main.lua");
	m_pScriptSystem->BeginCall("Init");
	m_pScriptSystem->PushFuncParam(0);
	m_pScriptSystem->EndCall();
	m_XSurfaceMgr.Init(m_pScriptSystem,m_p3DEngine,GetSystem()->GetIPhysicalWorld());
	if(!m_bDedicatedServer)
		InitInputMap();
	InitConsoleCommands();
	if (!m_StringTableMgr.Load(GetSystem(),*m_pScriptObjectLanguage,g_language->GetString()))
		m_pLog->Log("cannot load language file [%s]",g_language->GetString());
	m_pLog->Log("Initializing UI");
	m_pUIHud = new CUIHud(this,m_pSystem);
	LoadConfiguration("","game.cfg");
	m_XSurfaceMgr.LoadMaterials("scripts/materials");
	if(!m_bDedicatedServer)
	{
		m_pSystem->GetIConsole()->ShowConsole(0);
		if (!bInEditor)
		{
			m_pUISystem = new CUISystem;
			if (m_pUISystem)
			{
				m_pUISystem->Create(this, m_pSystem, m_pScriptSystem, "Scripts/MenuScreens/UISystem.lua", 1);
			}
			else
			{
				m_pLog->Log("Failed to create UI System!");
			}
		}
		if (m_pUISystem)
		{
			m_bMenuOverlay = 1;
		}
	}
	else
		m_pSystem->GetIConsole()->ShowConsole(true);
	if (m_pRenderer)
	{
		ITexPic *pPic;
		pPic=m_pRenderer->EF_LoadTexture("gui/map_player", FT_NOREMOVE, 0, eTT_Base);
		if (pPic && pPic->IsTextureLoaded())
			m_nPlayerIconTexId=pPic->GetTextureID();
		pPic=m_pRenderer->EF_LoadTexture("gui/map_vehicle", FT_NOREMOVE, 0, eTT_Base);
		if (pPic && pPic->IsTextureLoaded())
			m_nVehicleIconTexId=pPic->GetTextureID();
		pPic=m_pRenderer->EF_LoadTexture("gui/map_building", FT_NOREMOVE, 0, eTT_Base);
		if (pPic && pPic->IsTextureLoaded())
			m_nBuildingIconTexId=pPic->GetTextureID();
		pPic=m_pRenderer->EF_LoadTexture("gui/map_unknown", FT_NOREMOVE, 0, eTT_Base);
		if (pPic && pPic->IsTextureLoaded())
			m_nUnknownIconTexId=pPic->GetTextureID();
	}
	if(!bInEditor)
		m_pEntitySystem->SetDynamicEntityIdMode(true);	
#if !defined(_XBOX) && !defined(PS2) && !defined(LINUX)
	SetCursor(NULL);
#endif
	DevModeInit();
	m_bOK = true;	
	e_deformable_terrain = NULL;
	return (true);
}
bool CXGame :: Init ( struct ISystem * pSystem , bool bDedicatedSrv , bool bInEditor , const char * szGameMod ) { m_pSystem = pSystem ; m_pGameMods = new CGameMods ( this ) ; gISystem = pSystem ; m_bDedicatedServer = bDedicatedSrv ; m_XAreaMgr . Init ( pSystem ) ; m_bEditor = bInEditor ; m_bRelaunch = false ; m_bMovieSystemPaused = false ; m_bIsLoadingLevelFromFile = false ; m_bOK = false ; m_bUpdateRet = true ; m_pClient = NULL ; m_pServer = NULL ; m_pSystem -> GetILog ( ) -> Log ( " " ) ; #if ! defined ( LINUX ) IMovieSystem * pMovieSystem = m_pSystem -> GetIMovieSystem ( ) ; if ( pMovieSystem ) pMovieSystem -> SetUser ( m_pMovieUser ) ; #endif if ( ! m_pTimeDemoRecorder ) m_pTimeDemoRecorder = new CTimeDemoRecorder ( pSystem ) ; m_pUIHud = NULL ; m_pNetwork = m_pSystem -> GetINetwork ( ) ; m_pLog = m_pSystem -> GetILog ( ) ; m_p3DEngine = m_pSystem -> GetI3DEngine ( ) ; m_pRenderer = m_pSystem -> GetIRenderer ( ) ; m_pScriptSystem = pSystem -> GetIScriptSystem ( ) ; m_pEntitySystem = m_pSystem -> GetIEntitySystem ( ) ; #ifndef _XBOX m_pServerSnooper = m_pNetwork -> CreateServerSnooper ( this ) ; m_pNETServerSnooper = m_pNetwork -> CreateNETServerSnooper ( this ) ; m_pRConSystem = m_pNetwork -> CreateRConSystem ( ) ; #endif m_pWeaponSystemEx = new CWeaponSystemEx ( ) ; m_pVehicleSystem = new CVehicleSystem ( ) ; m_pPlayerSystem = new CPlayerSystem ( ) ; m_pFlockManager = new CFlockManager ( m_pSystem ) ; CScriptObjectUI :: InitializeTemplate ( m_pScriptSystem ) ; m_pScriptObjectGame = new CScriptObjectGame ; CScriptObjectGame :: InitializeTemplate ( m_pScriptSystem ) ; m_pScriptObjectInput = new CScriptObjectInput ; CScriptObjectInput :: InitializeTemplate ( m_pScriptSystem ) ; m_pScriptObjectLanguage = new CScriptObjectLanguage ; CScriptObjectLanguage :: InitializeTemplate ( m_pScriptSystem ) ; m_pScriptObjectBoids = new CScriptObjectBoids ; CScriptObjectBoids :: InitializeTemplate ( m_pScriptSystem ) ; m_pScriptObjectAI = new CScriptObjectAI ; CScriptObjectAI :: InitializeTemplate ( m_pScriptSystem ) ; CScriptObjectServer :: InitializeTemplate ( m_pScriptSystem ) ; CScriptObjectPlayer :: InitializeTemplate ( m_pScriptSystem ) ; CScriptObjectFireParam :: InitializeTemplate ( m_pScriptSystem ) ; CScriptObjectWeaponClass :: InitializeTemplate ( m_pScriptSystem ) ; CScriptObjectVehicle :: InitializeTemplate ( m_pScriptSystem ) ; CScriptObjectSpectator :: InitializeTemplate ( m_pScriptSystem ) ; CScriptObjectAdvCamSystem :: InitializeTemplate ( m_pScriptSystem ) ; CScriptObjectSynched2DTable :: InitializeTemplate ( m_pScriptSystem ) ; CScriptObjectRenderer :: InitializeTemplate ( m_pScriptSystem ) ; m_pScriptObjectGame -> Init ( m_pScriptSystem , this ) ; m_pScriptObjectInput -> Init ( m_pScriptSystem , this , m_pSystem ) ; m_pScriptObjectBoids -> Init ( m_pScriptSystem , m_pSystem , m_pFlockManager ) ; m_pScriptObjectLanguage -> Init ( m_pScriptSystem , & m_StringTableMgr ) ; m_pScriptObjectAI -> Init ( m_pScriptSystem , m_pSystem , this ) ; CScriptObjectServerSlot :: InitializeTemplate ( m_pScriptSystem ) ; CScriptObjectClient :: InitializeTemplate ( m_pScriptSystem ) ; CScriptObjectStream :: InitializeTemplate ( m_pScriptSystem ) ; m_pScriptTimerMgr = new CScriptTimerMgr ( m_pScriptSystem , m_pSystem -> GetIEntitySystem ( ) , this ) ; m_pScriptSystem -> SetGlobalValue ( " " , ePressing ) ; m_pScriptSystem -> SetGlobalValue ( " " , eReleasing ) ; m_pScriptSystem -> SetGlobalValue ( " " , eHolding ) ; m_pScriptSystem -> SetGlobalValue ( " " , ENTITYTYPE_PLAYER ) ; m_pScriptSystem -> SetGlobalValue ( " " , ENTITYTYPE_WAYPOINT ) ; m_pScriptSystem -> SetGlobalValue ( " " , ENTITYTYPE_OWNTEAM ) ; InitConsoleVars ( ) ; if ( szGameMod && szGameMod [ 0 ] ) { GetModsInterface ( ) -> SetCurrentMod ( szGameMod , false ) ; } InitClassRegistry ( ) ; m_pScriptSystem -> ExecuteFile ( " " ) ; m_pScriptSystem -> BeginCall ( " " ) ; m_pScriptSystem -> PushFuncParam ( 0 ) ; m_pScriptSystem -> EndCall ( ) ; m_XSurfaceMgr . Init ( m_pScriptSystem , m_p3DEngine , GetSystem ( ) -> GetIPhysicalWorld ( ) ) ; if ( ! m_bDedicatedServer ) InitInputMap ( ) ; InitConsoleCommands ( ) ; if ( ! m_StringTableMgr . Load ( GetSystem ( ) , * m_pScriptObjectLanguage , g_language -> GetString ( ) ) ) m_pLog -> Log ( " " , g_language -> GetString ( ) ) ; m_pLog -> Log ( " " ) ; m_pUIHud = new CUIHud ( this , m_pSystem ) ; LoadConfiguration ( " " , " " ) ; m_XSurfaceMgr . LoadMaterials ( " " ) ; if ( ! m_bDedicatedServer ) { m_pSystem -> GetIConsole ( ) -> ShowConsole ( 0 ) ; if ( ! bInEditor ) { m_pUISystem = new CUISystem ; if ( m_pUISystem ) { m_pUISystem -> Create ( this , m_pSystem , m_pScriptSystem , " " , 1 ) ; } else { m_pLog -> Log ( " " ) ; } } if ( m_pUISystem ) { m_bMenuOverlay = 1 ; } } else m_pSystem -> GetIConsole ( ) -> ShowConsole ( true ) ; if ( m_pRenderer ) { ITexPic * pPic ; pPic = m_pRenderer -> EF_LoadTexture ( " " , FT_NOREMOVE , 0 , eTT_Base ) ; if ( pPic && pPic -> IsTextureLoaded ( ) ) m_nPlayerIconTexId = pPic -> GetTextureID ( ) ; pPic = m_pRenderer -> EF_LoadTexture ( " " , FT_NOREMOVE , 0 , eTT_Base ) ; if ( pPic && pPic -> IsTextureLoaded ( ) ) m_nVehicleIconTexId = pPic -> GetTextureID ( ) ; pPic = m_pRenderer -> EF_LoadTexture ( " " , FT_NOREMOVE , 0 , eTT_Base ) ; if ( pPic && pPic -> IsTextureLoaded ( ) ) m_nBuildingIconTexId = pPic -> GetTextureID ( ) ; pPic = m_pRenderer -> EF_LoadTexture ( " " , FT_NOREMOVE , 0 , eTT_Base ) ; if ( pPic && pPic -> IsTextureLoaded ( ) ) m_nUnknownIconTexId = pPic -> GetTextureID ( ) ; } if ( ! bInEditor ) m_pEntitySystem -> SetDynamicEntityIdMode ( true ) ; #if ! defined ( _XBOX ) && ! defined ( PS2 ) && ! defined ( LINUX ) SetCursor ( NULL ) ; #endif DevModeInit ( ) ; m_bOK = true ; e_deformable_terrain = NULL ; return ( true ) ; }
Initialize the game.
Initialize the game .
// Setup the system and 3D Engine pointers
 // Register game rendering callback.
 //[Timur] m_p3DEngine->SetRenderCallback( OnRenderCallback,this );
 // init subsystems
 // init is not necessary for now, but add here if it later is
 // making some constants accessable to the script
 // apply the mod without restarting as the game just started!
 // execute the "main"-script (to pre-load other scripts, etc.)
 // initialize the surface-manager
 // init key-bindings
 // create various console-commands/variables
 // loading the main language-string-table
 // creating HUD interface
 //////////////////////////////////////////////////////////////////////////
 // Materials
 // load materials (once before all, this info stays till we quit the game - no need to load material later)
 // first load normal materials
 //////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////
 // load textures used as icons by the mini-map
