示例#1
0
void GamePair::initialize(GameSettingsPtr settings, const Vector<string> &levelCode, S32 clientCount)
{
   settings->resolveDirs();

   // Need to start Lua before we add any clients.  Might as well do it now.
   LuaScriptRunner::startLua(settings->getFolderManager()->getLuaDir());

   LevelSourcePtr levelSource = LevelSourcePtr(new StringLevelSource(levelCode));
   initHosting(settings, levelSource, true, false);      // Creates a game and adds it to GameManager

   server = GameManager::getServerGame();                // Get the game created in initHosting

   // Give the host name something meaningful... in this case the name of the test
   if(::testing::UnitTest::GetInstance()->current_test_case())
   {
      const char *name = ::testing::UnitTest::GetInstance()->current_test_case()->name();
      const char *name2 = ::testing::UnitTest::GetInstance()->current_test_info()->name();
      server->getSettings()->setHostName(string(name) + "_" + name2, false);
   }

   server->startHosting();          // This will load levels and wipe out any teams

   for(S32 i = 0; i < clientCount; i++)
      addClient("TestPlayer" + itos(i));

   idle(1, 5);    // Give GameType and game objects time to propagate to client(s)
}
示例#2
0
// Note that clientLevelSource could be NULL
void GamePair::initialize(GameSettingsPtr serverSettings, GameSettingsPtr clientSettings, 
                          LevelSourcePtr serverLevelSource, S32 clientCount, bool skipInitialIdle)
{
   GameManager::reset();      // Still needed?

   serverSettings->resolveDirs();
   clientSettings->resolveDirs();

   // Need to start Lua before we add any clients.  Might as well do it now.
   LuaScriptRunner::startLua(serverSettings->getFolderManager()->getLuaDir());

   initHosting(serverSettings, serverLevelSource, true, false);   // Creates a ServerGame and adds it to GameManager

   server = GameManager::getServerGame();                         // Get the game created in initHosting

   // Give the host name something meaningful... in this case the name of the test
   if(::testing::UnitTest::GetInstance()->current_test_case())
   {
      const char *name = ::testing::UnitTest::GetInstance()->current_test_case()->name();
      const char *name2 = ::testing::UnitTest::GetInstance()->current_test_info()->name();
      server->getSettings()->setHostName(string(name) + "_" + name2, false);
   }

   bool ok = server->startHosting();   // This will load levels and wipe out any teams
   ASSERT_TRUE(ok) << "Ooops!";          

   for(S32 i = 0; i < clientCount; i++)
      addClient("TestPlayer" + itos(i), clientSettings);


   // SPECIAL CASE ALERT -- IF YOU PROVIDE A CLIENT AND SERVER PLAYLIST, WE WILL SKIP THE IDLE BELOW TO THAT WE 
   // CAN TEST THE INITIAL STATE OF CLIENT GAME BEFORE THERE IS ANY MEANINGFUL INTERACTION WITH THE SERVER.  BE
   // SURE TO RUN IDLE YOURSELF!
   if(skipInitialIdle)
      return;

   idle(1, 5);    // Give GameType and game objects time to propagate to client(s)
}