mirror of
https://github.com/glest/glest-source.git
synced 2025-08-17 21:51:17 +02:00
- added stats on console for headless server when game exits
This commit is contained in:
@@ -1457,6 +1457,8 @@ void Game::render() {
|
|||||||
renderFps++;
|
renderFps++;
|
||||||
totalRenderFps++;
|
totalRenderFps++;
|
||||||
|
|
||||||
|
updateWorldStats();
|
||||||
|
|
||||||
//NetworkManager &networkManager= NetworkManager::getInstance();
|
//NetworkManager &networkManager= NetworkManager::getInstance();
|
||||||
if(this->masterserverMode == false) {
|
if(this->masterserverMode == false) {
|
||||||
renderWorker();
|
renderWorker();
|
||||||
@@ -2601,6 +2603,16 @@ void Game::exitGameState(Program *program, Stats &endStats) {
|
|||||||
game->endGame();
|
game->endGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(game->isMasterserverMode() == true) {
|
||||||
|
printf("Game ending with stats:\n");
|
||||||
|
printf("-----------------------\n");
|
||||||
|
|
||||||
|
string gameStats = endStats.getStats();
|
||||||
|
printf("%s",gameStats.c_str());
|
||||||
|
|
||||||
|
printf("-----------------------\n");
|
||||||
|
}
|
||||||
|
|
||||||
ProgramState *newState = new BattleEnd(program, &endStats, game);
|
ProgramState *newState = new BattleEnd(program, &endStats, game);
|
||||||
|
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
@@ -2701,7 +2713,27 @@ void Game::render3d(){
|
|||||||
renderer.setLastRenderFps(lastRenderFps);
|
renderer.setLastRenderFps(lastRenderFps);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::render2d(){
|
void Game::updateWorldStats() {
|
||||||
|
world.getStats()->setWorldTimeElapsed(world.getTimeFlow()->getTime());
|
||||||
|
|
||||||
|
if(difftime(time(NULL),lastMaxUnitCalcTime) >= 1) {
|
||||||
|
lastMaxUnitCalcTime = time(NULL);
|
||||||
|
|
||||||
|
int totalUnitcount = 0;
|
||||||
|
for(int i = 0; i < world.getFactionCount(); ++i) {
|
||||||
|
Faction *faction= world.getFaction(i);
|
||||||
|
totalUnitcount += faction->getUnitCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(world.getStats()->getMaxConcurrentUnitCount() < totalUnitcount) {
|
||||||
|
world.getStats()->setMaxConcurrentUnitCount(totalUnitcount);
|
||||||
|
}
|
||||||
|
world.getStats()->setTotalEndGameConcurrentUnitCount(totalUnitcount);
|
||||||
|
world.getStats()->setFramesPlayed(world.getFrameCount());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Game::render2d() {
|
||||||
Renderer &renderer= Renderer::getInstance();
|
Renderer &renderer= Renderer::getInstance();
|
||||||
//Config &config= Config::getInstance();
|
//Config &config= Config::getInstance();
|
||||||
CoreData &coreData= CoreData::getInstance();
|
CoreData &coreData= CoreData::getInstance();
|
||||||
@@ -2776,24 +2808,6 @@ void Game::render2d(){
|
|||||||
string str="";
|
string str="";
|
||||||
std::map<int,string> factionDebugInfo;
|
std::map<int,string> factionDebugInfo;
|
||||||
|
|
||||||
world.getStats()->setWorldTimeElapsed(world.getTimeFlow()->getTime());
|
|
||||||
|
|
||||||
if(difftime(time(NULL),lastMaxUnitCalcTime) >= 1) {
|
|
||||||
lastMaxUnitCalcTime = time(NULL);
|
|
||||||
|
|
||||||
int totalUnitcount = 0;
|
|
||||||
for(int i = 0; i < world.getFactionCount(); ++i) {
|
|
||||||
Faction *faction= world.getFaction(i);
|
|
||||||
totalUnitcount += faction->getUnitCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(world.getStats()->getMaxConcurrentUnitCount() < totalUnitcount) {
|
|
||||||
world.getStats()->setMaxConcurrentUnitCount(totalUnitcount);
|
|
||||||
}
|
|
||||||
world.getStats()->setTotalEndGameConcurrentUnitCount(totalUnitcount);
|
|
||||||
world.getStats()->setFramesPlayed(world.getFrameCount());
|
|
||||||
}
|
|
||||||
|
|
||||||
if( renderer.getShowDebugUI() == true ||
|
if( renderer.getShowDebugUI() == true ||
|
||||||
(perfLogging == true && difftime(time(NULL),lastRenderLog2d) >= 1)) {
|
(perfLogging == true && difftime(time(NULL),lastRenderLog2d) >= 1)) {
|
||||||
str+= "MouseXY: " + intToStr(mouseX) + "," + intToStr(mouseY)+"\n";
|
str+= "MouseXY: " + intToStr(mouseX) + "," + intToStr(mouseY)+"\n";
|
||||||
|
@@ -252,6 +252,7 @@ private:
|
|||||||
void calcCameraMoveZ();
|
void calcCameraMoveZ();
|
||||||
|
|
||||||
int getFirstUnusedTeamNumber();
|
int getFirstUnusedTeamNumber();
|
||||||
|
void updateWorldStats();
|
||||||
};
|
};
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
@@ -10,11 +10,93 @@
|
|||||||
// ==============================================================
|
// ==============================================================
|
||||||
|
|
||||||
#include "stats.h"
|
#include "stats.h"
|
||||||
|
#include "lang.h"
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
namespace Glest{ namespace Game{
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
|
PlayerStats::PlayerStats() {
|
||||||
|
control = ctClosed;
|
||||||
|
resourceMultiplier=1.0f;
|
||||||
|
factionTypeName = "";
|
||||||
|
personalityType = fpt_Normal;
|
||||||
|
teamIndex = 0;
|
||||||
|
victory = false;
|
||||||
|
kills = 0;
|
||||||
|
enemykills = 0;
|
||||||
|
deaths = 0;
|
||||||
|
unitsProduced = 0;
|
||||||
|
resourcesHarvested = 0;
|
||||||
|
playerName = "";
|
||||||
|
playerColor = Vec3f(0,0,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
string PlayerStats::getStats() const {
|
||||||
|
string result = "";
|
||||||
|
|
||||||
|
Lang &lang= Lang::getInstance();
|
||||||
|
string controlString = "";
|
||||||
|
|
||||||
|
if(personalityType == fpt_Observer) {
|
||||||
|
controlString= GameConstants::OBSERVER_SLOTNAME;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
switch(control) {
|
||||||
|
case ctCpuEasy:
|
||||||
|
controlString= lang.get("CpuEasy");
|
||||||
|
break;
|
||||||
|
case ctCpu:
|
||||||
|
controlString= lang.get("Cpu");
|
||||||
|
break;
|
||||||
|
case ctCpuUltra:
|
||||||
|
controlString= lang.get("CpuUltra");
|
||||||
|
break;
|
||||||
|
case ctCpuMega:
|
||||||
|
controlString= lang.get("CpuMega");
|
||||||
|
break;
|
||||||
|
case ctNetwork:
|
||||||
|
controlString= lang.get("Network");
|
||||||
|
break;
|
||||||
|
case ctHuman:
|
||||||
|
controlString= lang.get("Human");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ctNetworkCpuEasy:
|
||||||
|
controlString= lang.get("NetworkCpuEasy");
|
||||||
|
break;
|
||||||
|
case ctNetworkCpu:
|
||||||
|
controlString= lang.get("NetworkCpu");
|
||||||
|
break;
|
||||||
|
case ctNetworkCpuUltra:
|
||||||
|
controlString= lang.get("NetworkCpuUltra");
|
||||||
|
break;
|
||||||
|
case ctNetworkCpuMega:
|
||||||
|
controlString= lang.get("NetworkCpuMega");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
printf("Error control = %d\n",control);
|
||||||
|
assert(false);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if(control != ctHuman && control != ctNetwork ) {
|
||||||
|
controlString += " x " + floatToStr(resourceMultiplier,1);
|
||||||
|
}
|
||||||
|
|
||||||
|
result += playerName + " (" + controlString + ") ";
|
||||||
|
result += "faction: " + factionTypeName + " ";
|
||||||
|
result += "Team: " + intToStr(teamIndex) + " ";
|
||||||
|
result += "victory: " + boolToStr(victory) + " ";
|
||||||
|
result += "# kills: " + intToStr(kills) + " ";
|
||||||
|
result += "# enemy kills: " + intToStr(enemykills) + " ";
|
||||||
|
result += "# deaths: " + intToStr(deaths) + "\n";
|
||||||
|
result += "# units produced: " + intToStr(unitsProduced) + " ";
|
||||||
|
result += "# resources harvested: " + intToStr(resourcesHarvested);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class Stats
|
// class Stats
|
||||||
// =====================================================
|
// =====================================================
|
||||||
@@ -49,4 +131,23 @@ void Stats::harvest(int harvesterFactionIndex, int amount){
|
|||||||
playerStats[harvesterFactionIndex].resourcesHarvested+= amount;
|
playerStats[harvesterFactionIndex].resourcesHarvested+= amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string Stats::getStats() const {
|
||||||
|
string result = "";
|
||||||
|
|
||||||
|
result += "Description: " + description + "\n";
|
||||||
|
result += "Faction count: " + intToStr(factionCount) + "\n";
|
||||||
|
|
||||||
|
result += "Game duration (mins): " + intToStr(getFramesToCalculatePlaytime()/GameConstants::updateFps/60) + "\n";
|
||||||
|
result += "Max Concurrent Units: " + intToStr(maxConcurrentUnitCount) + "\n";
|
||||||
|
result += "Total EndGame Concurrent Unit Count: " + intToStr(totalEndGameConcurrentUnitCount) + "\n";
|
||||||
|
|
||||||
|
for(unsigned int i = 0; i < factionCount; ++i) {
|
||||||
|
const PlayerStats &player = playerStats[i];
|
||||||
|
|
||||||
|
result += "player #" + intToStr(i) + " " + player.getStats() + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
@@ -27,21 +27,7 @@ namespace Glest{ namespace Game{
|
|||||||
|
|
||||||
class PlayerStats {
|
class PlayerStats {
|
||||||
public:
|
public:
|
||||||
PlayerStats() {
|
PlayerStats();
|
||||||
control = ctClosed;
|
|
||||||
resourceMultiplier=1.0f;
|
|
||||||
factionTypeName = "";
|
|
||||||
personalityType = fpt_Normal;
|
|
||||||
teamIndex = 0;
|
|
||||||
victory = false;
|
|
||||||
kills = 0;
|
|
||||||
enemykills = 0;
|
|
||||||
deaths = 0;
|
|
||||||
unitsProduced = 0;
|
|
||||||
resourcesHarvested = 0;
|
|
||||||
playerName = "";
|
|
||||||
playerColor = Vec3f(0,0,0);
|
|
||||||
}
|
|
||||||
|
|
||||||
ControlType control;
|
ControlType control;
|
||||||
float resourceMultiplier;
|
float resourceMultiplier;
|
||||||
@@ -56,6 +42,8 @@ public:
|
|||||||
int resourcesHarvested;
|
int resourcesHarvested;
|
||||||
string playerName;
|
string playerName;
|
||||||
Vec3f playerColor;
|
Vec3f playerColor;
|
||||||
|
|
||||||
|
string getStats() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
@@ -145,6 +133,7 @@ public:
|
|||||||
|
|
||||||
void addFramesToCalculatePlaytime() {this->framesToCalculatePlaytime++; }
|
void addFramesToCalculatePlaytime() {this->framesToCalculatePlaytime++; }
|
||||||
|
|
||||||
|
string getStats() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
@@ -284,6 +284,7 @@ void BattleEnd::render() {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
printf("Error control = %d for i\n",stats.getControl(i),i);
|
||||||
assert(false);
|
assert(false);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user