SB_API void S_CALLTYPE GameServer_RunCallbacks() { return SteamGameServer_RunCallbacks(); }
//----------------------------------------------------------------------------- // Purpose: Main frame function, updates the state of the world and performs rendering //----------------------------------------------------------------------------- void CSpaceWarServer::RunFrame() { // Run any Steam Game Server API callbacks SteamGameServer_RunCallbacks(); // Update our server details SendUpdatedServerDetailsToSteam(); // Timeout stale player connections, also update player count data uint32 uPlayerCount = 0; for( uint32 i=0; i < MAX_PLAYERS_PER_SERVER; ++i ) { // If there is no ship, skip if ( !m_rgClientData[i].m_bActive ) continue; if ( m_pGameEngine->GetGameTickCount() - m_rgClientData[i].m_ulTickCountLastData > SERVER_TIMEOUT_MILLISECONDS ) { OutputDebugString( "Timing out player connection\n" ); RemovePlayerFromServer( i ); } else { ++uPlayerCount; } } m_uPlayerCount = uPlayerCount; switch ( m_eGameState ) { case k_EServerWaitingForPlayers: // Wait a few seconds (so everyone can join if a lobby just started this server) if ( m_pGameEngine->GetGameTickCount() - m_ulStateTransitionTime >= MILLISECONDS_BETWEEN_ROUNDS ) { // Just keep waiting until at least one ship is active for( uint32 i = 0; i < MAX_PLAYERS_PER_SERVER; ++i ) { if ( m_rgClientData[i].m_bActive ) { // Transition to active OutputDebugString( "Server going active after waiting for players\n" ); SetGameState( k_EServerActive ); } } } break; case k_EServerDraw: case k_EServerWinner: // Update all the entities... m_pSun->RunFrame(); for( uint32 i=0; i<MAX_PLAYERS_PER_SERVER; ++i ) { if ( m_rgpShips[i] ) m_rgpShips[i]->RunFrame(); } // NOTE: no collision detection, because the round is really over, objects are now invulnerable // After 5 seconds start the next round if ( m_pGameEngine->GetGameTickCount() - m_ulStateTransitionTime >= MILLISECONDS_BETWEEN_ROUNDS ) { ResetPlayerShips(); SetGameState( k_EServerActive ); } break; case k_EServerActive: // Update all the entities... m_pSun->RunFrame(); for( uint32 i=0; i<MAX_PLAYERS_PER_SERVER; ++i ) { if ( m_rgpShips[i] ) m_rgpShips[i]->RunFrame(); } // Check for collisions which could lead to a winner this round CheckForCollisions(); break; case k_EServerExiting: break; default: OutputDebugString( "Unhandled game state in CSpaceWarServer::RunFrame\n" ); } // Send client updates (will internal limit itself to the tick rate desired) SendUpdateDataToAllClients(); }