示例#1
0
void BaseGameLogic::VOnUpdate(float time, float elapsedTime)
{
	int deltaMilliseconds = int(elapsedTime * 1000.0f);

	switch(m_State)
	{
	case BGS_Initializing:
		// If we get to here we're ready to attach players
		//todo should be BGS_MainMenu but i dont have one!
		//VChangeState(BGS_WaitingForPlayers);
		VChangeState(BGS_MainMenu);
		break;

	case BGS_LoadingGameEnvironment:
		if (g_pApp->VLoadGame())
		{	
			VChangeState(BGS_Running);
		}
		else
		{
			assert(0 && _T("The game failed to load."));
			g_pApp->AbortGame();
		}
		break;

	case BGS_MainMenu:
		// do nothing
		break;

	case BGS_WaitingForPlayers:
		// do nothing - the game class should handle this one.
		break;

	case BGS_Running:
		m_pProcessManager->UpdateProcesses(deltaMilliseconds);
		break;

	default:
		assert(0 && _T("Unrecognized state."));
		// Not a bad idea to throw an exception here to 
		// catch this in a release build...
	}

	GameViewList::iterator i=m_gameViews.begin();
	GameViewList::iterator end=m_gameViews.end();
	while (i != end)
	{
		(*i)->VOnUpdate( deltaMilliseconds );
		++i;
	}

	//Trigger an update event for anybody else (script functions, etc.).

}
示例#2
0
//
// TeapotWarsGame::VOnUpdate			- Chapter 19, page 709
//
void CometConquestGame::VOnUpdate(float time, float elapsedTime)
{
	int deltaMilliseconds = int(elapsedTime * 1000.0f);
	m_Lifetime += elapsedTime;
	unsigned int currentTime = timeGetTime();
	BaseGameLogic::VOnUpdate(time, elapsedTime);

	if (m_bProxy)
		return;

	switch(m_State)
	{
	case BGS_LoadingGameEnvironment:
		break;

	case BGS_MainMenu:
		break;

	case BGS_WaitingForPlayers:
		if (m_ExpectedPlayers + m_ExpectedRemotePlayers == m_HumanPlayersAttached ) 
		{
			VChangeState(BGS_LoadingGameEnvironment);
		}
		break;

	case BGS_Running:
		if(currentTime > (m_data.m_lastCometTime + 5000))
		{
			Vec4 at = -g_Right4 * 2.0f;
			Vec4 atWorld = Mat4x4::g_Identity.Xform(at);
			int randVertical = m_random.Random(115) + 1 - 60;
			Vec3 normalDir(atWorld);
			normalDir.Normalize();
			Mat4x4 temp = Mat4x4::g_Identity;
			temp.SetPosition(Vec3(110,10,randVertical));
			CometParams cp;
			cp.m_Pos = temp.GetPosition() + Vec3(atWorld);
			cp.m_Radius = 6.0f;
			cp.m_Color = g_Cyan;
			cp.m_NormalDir = normalDir;
			cp.m_Force = 40000.0f;

			const EvtData_Request_New_Actor cannonBallEvt( &cp );
			safeTriggerEvent( cannonBallEvt );
			m_data.m_lastCometTime = currentTime;
		}
		break;
	default:
		assert(0 && _T("Unrecognized state."));
	}

	// look in Chapter 15, page 563 for more on this bit of code
	if(m_pPhysics)
	{
		m_pPhysics->VOnUpdate(elapsedTime);
		m_pPhysics->VSyncVisibleScene();
	}
}
示例#3
0
void BaseGameLogic::VChangeState(BaseGameState newState)
{
	if (newState==BGS_WaitingForPlayers)
	{
		// Get rid of the Main Menu...
		m_gameViews.pop_front();
		//todo
		// Note: Split screen support would require this to change!
		m_ExpectedPlayers = 1;
		m_ExpectedRemotePlayers = g_pApp->m_pOptions->m_expectedPlayers;

		if (!g_pApp->m_pOptions->m_gameHost.empty())
		{
			VSetProxy();
			m_ExpectedRemotePlayers = 0;	// the server will create these
			ClientSocketManager *pClient = GCC_NEW ClientSocketManager(g_pApp->m_pOptions->m_gameHost, g_pApp->m_pOptions->m_listenPort);
			if (!pClient->Connect())
			{
				// Throw up a main menu
				VChangeState(BGS_MainMenu);
				return;
			}
			g_pApp->m_pBaseSocketManager = pClient;
		}
		else if (m_ExpectedRemotePlayers > 0)
		{
			BaseSocketManager *pServer = GCC_NEW BaseSocketManager();
			if (!pServer->Init())
			{
				// Throw up a main menu
				VChangeState(BGS_MainMenu);	
				return;
			}

			pServer->AddSocket(new GameServerListenSocket(g_pApp->m_pOptions->m_listenPort));
			g_pApp->m_pBaseSocketManager = pServer;
		}
	}

	m_State = newState;
	if (!m_bProxy)
	{
		safeQueEvent( IEventDataPtr(GCC_NEW EvtData_Game_State(m_State)) );
	}
}
示例#4
0
void nxBaseGameLogic::VOnUpdate(int deltaMilliseconds)
{
	switch(m_State)
	{
		case NX_GS_Initializing:
			// If we get to here we're ready to attach players
			VChangeState(NX_GS_MainMenu);
			break;
		case NX_GS_MainMenu:
			break;
		case NX_GS_LoadingGameEnvironment:
			break;
		case NX_GS_WaitingForPlayers:
			// do nothing - the game class should handle this one.
			break;
		case NX_GS_SpawnAI:
			if (m_ExpectedAI == 0)
			{
				VChangeState(NX_GS_Running);
			}
			break;
		case NX_GS_Running:
			m_pProcessManager->UpdateProcesses(deltaMilliseconds);
			break;
		default:
			assert(1 && "Unrecognized state.");
	}

	for(int i = 0 ; i < 10 ; i++)
	{
		float32 physicsStep = 1.0f / 60.0f;
		m_pPhysics->VOnUpdate(physicsStep);
	}

	nxGameViewList::iterator i=m_GameViews.begin();
	nxGameViewList::iterator end=m_GameViews.end();
	while (i != end)
	{
		(*i)->VOnUpdate( deltaMilliseconds );
		++i;
	}
}
示例#5
0
void TeapotWarsLogic::RequestStartGameDelegate(IEventDataPtr pEventData)
{
	VChangeState(BGS_WaitingForPlayers);
}