Fix filesystem game method
This commit is contained in:
parent
b532f1c9c8
commit
61c012370d
3 changed files with 7 additions and 7 deletions
|
@ -116,7 +116,7 @@ int runClient(int argc, char* argv[])
|
||||||
|
|
||||||
// Output the gamestate file for this game
|
// Output the gamestate file for this game
|
||||||
CTTRTSGame thisGame = GetGameFromString(gamestate);
|
CTTRTSGame thisGame = GetGameFromString(gamestate);
|
||||||
OutputGameStateFile(thisGame, getGamesDir());
|
OutputGameStateFile(thisGame);
|
||||||
|
|
||||||
// Get the order file for this turn
|
// Get the order file for this turn
|
||||||
std::string orders = GetOrdersFromPlayerFile(thisGame,myPlayer);
|
std::string orders = GetOrdersFromPlayerFile(thisGame,myPlayer);
|
||||||
|
|
|
@ -30,10 +30,10 @@ void WaitForFile( const std::string& name, const std::chrono::milliseconds& time
|
||||||
while( !FileExists(name) ) std::this_thread::sleep_for(time);
|
while( !FileExists(name) ) std::this_thread::sleep_for(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OutputGameStateFile(CTTRTSGame &game, const std::string &gameDir)
|
bool OutputGameStateFile(CTTRTSGame &game)
|
||||||
{
|
{
|
||||||
char turnFileName[128];
|
char turnFileName[128];
|
||||||
snprintf(turnFileName,128,"%s/%s/Turn_%i.txt",gameDir.c_str(),game.GetName().c_str(),game.GetTurn());
|
snprintf(turnFileName,128,"%s%s/Turn_%i.txt", getGamesDir().c_str(),game.GetName().c_str(),game.GetTurn());
|
||||||
std::ofstream turnFile(turnFileName, std::ios_base::trunc); // truncate to overwrite if a file exists
|
std::ofstream turnFile(turnFileName, std::ios_base::trunc); // truncate to overwrite if a file exists
|
||||||
|
|
||||||
if ( turnFile.bad() )
|
if ( turnFile.bad() )
|
||||||
|
@ -127,7 +127,7 @@ std::string GetOrdersFromPlayerFile(const CTTRTSGame &game, player_t &player)
|
||||||
std::string gameDir = getGamesDir();
|
std::string gameDir = getGamesDir();
|
||||||
|
|
||||||
char playerOrderFileName[128];
|
char playerOrderFileName[128];
|
||||||
snprintf(playerOrderFileName, 128, "%s/%s/Player_%i_Turn_%i.txt", gameDir.c_str(),game.GetName().c_str(),(int) player, game.GetTurn());
|
snprintf(playerOrderFileName, 128, "%s%s/Player_%i_Turn_%i.txt", gameDir.c_str(),game.GetName().c_str(),(int) player, game.GetTurn());
|
||||||
|
|
||||||
// Wait for the player order file to be created
|
// Wait for the player order file to be created
|
||||||
std::cout<<"Waiting for "<< playerOrderFileName << std::endl;
|
std::cout<<"Waiting for "<< playerOrderFileName << std::endl;
|
||||||
|
@ -249,7 +249,7 @@ int runFromFilesystem(int argc, char* argv[])
|
||||||
std::cout<<"Starting turn "<<game.GetTurn()<<std::endl;
|
std::cout<<"Starting turn "<<game.GetTurn()<<std::endl;
|
||||||
|
|
||||||
// Create a turn file
|
// Create a turn file
|
||||||
if( !OutputGameStateFile(game, gameDir))
|
if( !OutputGameStateFile(game))
|
||||||
{
|
{
|
||||||
std::cerr<<"Error: Failed to output new turn file" << std::endl;
|
std::cerr<<"Error: Failed to output new turn file" << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -277,7 +277,7 @@ int runFromFilesystem(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output final gamestate
|
// Output final gamestate
|
||||||
OutputGameStateFile(game, gameDir);
|
OutputGameStateFile(game);
|
||||||
|
|
||||||
// Get the winning player
|
// Get the winning player
|
||||||
player_t winningPlayer = game.GetWinningPlayer();
|
player_t winningPlayer = game.GetWinningPlayer();
|
||||||
|
|
|
@ -13,7 +13,7 @@ bool FileExists( const std::string& name );
|
||||||
|
|
||||||
void WaitForFile( const std::string& name, const std::chrono::milliseconds& time );
|
void WaitForFile( const std::string& name, const std::chrono::milliseconds& time );
|
||||||
|
|
||||||
bool OutputGameStateFile(CTTRTSGame &game, const std::string &gameDir);
|
bool OutputGameStateFile(CTTRTSGame &game);
|
||||||
|
|
||||||
std::string GetOrdersFromPlayerFile(const CTTRTSGame &game, player_t &player);
|
std::string GetOrdersFromPlayerFile(const CTTRTSGame &game, player_t &player);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue