Changed the logging system to be more flexible and to support world synch logging
This commit is contained in:
parent
024f86ce7c
commit
6d4838f470
|
@ -922,6 +922,8 @@ void Game::render2d(){
|
||||||
if(difftime(time(NULL),lastRenderLog2d) >= 1) {
|
if(difftime(time(NULL),lastRenderLog2d) >= 1) {
|
||||||
lastRenderLog2d = time(NULL);
|
lastRenderLog2d = time(NULL);
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d Statistics: %s\n",__FILE__,__FUNCTION__,__LINE__,str.c_str());
|
SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d Statistics: %s\n",__FILE__,__FUNCTION__,__LINE__,str.c_str());
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugWorldSynch,"In [%s::%s] Line: %d Statistics: %s\n",__FILE__,__FUNCTION__,__LINE__,str.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,12 +62,13 @@ public:
|
||||||
CardinalDir() : value(NORTH) {}
|
CardinalDir() : value(NORTH) {}
|
||||||
CardinalDir(Enum v) : value(v) {}
|
CardinalDir(Enum v) : value(v) {}
|
||||||
explicit CardinalDir(int v) {
|
explicit CardinalDir(int v) {
|
||||||
assert(v >= 0 && v < 4);
|
assertDirValid(v);
|
||||||
value = static_cast<Enum>(v);
|
value = static_cast<Enum>(v);
|
||||||
}
|
}
|
||||||
operator Enum() { return value; }
|
operator Enum() { return value; }
|
||||||
//int asInt() { return (int)value; }
|
//int asInt() { return (int)value; }
|
||||||
|
|
||||||
|
static void assertDirValid(int v) { assert(v >= 0 && v < 4); }
|
||||||
void operator++() {
|
void operator++() {
|
||||||
//printf("In [%s::%s] Line: %d BEFORE +: value = %d\n",__FILE__,__FUNCTION__,__LINE__,asInt());
|
//printf("In [%s::%s] Line: %d BEFORE +: value = %d\n",__FILE__,__FUNCTION__,__LINE__,asInt());
|
||||||
value = static_cast<Enum>((value + 1) % 4);
|
value = static_cast<Enum>((value + 1) % 4);
|
||||||
|
|
|
@ -38,7 +38,6 @@ using namespace Shared::Util;
|
||||||
|
|
||||||
namespace Glest{ namespace Game{
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
string debugLogFile = "";
|
|
||||||
bool gameInitialized = false;
|
bool gameInitialized = false;
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
@ -271,9 +270,9 @@ int glestMain(int argc, char** argv){
|
||||||
printf("%s, STREFLOP disabled.\n",getNetworkVersionString().c_str());
|
printf("%s, STREFLOP disabled.\n",getNetworkVersionString().c_str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SystemFlags::enableNetworkDebugInfo = true;
|
SystemFlags::init();
|
||||||
SystemFlags::enableDebugText = true;
|
SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled = true;
|
||||||
SystemFlags::enablePerformanceDebugInfo = false;
|
SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled = true;
|
||||||
|
|
||||||
MainWindow *mainWindow= NULL;
|
MainWindow *mainWindow= NULL;
|
||||||
Program *program= NULL;
|
Program *program= NULL;
|
||||||
|
@ -285,14 +284,24 @@ int glestMain(int argc, char** argv){
|
||||||
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
SystemFlags::enableNetworkDebugInfo = config.getBool("DebugNetwork","false");
|
SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled = config.getBool("DebugMode","false");
|
||||||
SystemFlags::enableDebugText = config.getBool("DebugMode","false");
|
SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled = config.getBool("DebugNetwork","false");
|
||||||
debugLogFile = config.getString("DebugLogFile","");
|
SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled = config.getBool("DebugPerformance","false");
|
||||||
|
SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled = config.getBool("DebugWorldSynch","false");
|
||||||
|
|
||||||
|
string debugWorldSynchLogFile = config.getString("DebugLogFileWorldSynch","");
|
||||||
|
string debugLogFile = config.getString("DebugLogFile","");
|
||||||
if(getGameReadWritePath() != "") {
|
if(getGameReadWritePath() != "") {
|
||||||
debugLogFile = getGameReadWritePath() + debugLogFile;
|
debugLogFile = getGameReadWritePath() + debugLogFile;
|
||||||
}
|
}
|
||||||
SystemFlags::debugLogFile = debugLogFile.c_str();
|
if(debugWorldSynchLogFile == "") {
|
||||||
SystemFlags::enablePerformanceDebugInfo = config.getBool("DebugPerformance","false");
|
debugWorldSynchLogFile = debugLogFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
SystemFlags::getSystemSettingType(SystemFlags::debugSystem).debugLogFileName = debugLogFile;
|
||||||
|
SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).debugLogFileName = debugLogFile;
|
||||||
|
SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).debugLogFileName = debugLogFile;
|
||||||
|
SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).debugLogFileName = debugWorldSynchLogFile;
|
||||||
|
|
||||||
NetworkInterface::setDisplayMessageFunction(ExceptionHandler::DisplayMessage);
|
NetworkInterface::setDisplayMessageFunction(ExceptionHandler::DisplayMessage);
|
||||||
|
|
||||||
|
|
|
@ -256,7 +256,7 @@ bool NetworkMessageCommandList::receive(Socket* socket){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bool result = NetworkMessage::receive(socket, &data, totalMsgSize);
|
bool result = NetworkMessage::receive(socket, &data, totalMsgSize);
|
||||||
if(SystemFlags::enableNetworkDebugInfo) {
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled == true) {
|
||||||
for(int idx = 0 ; idx < data.commandCount; ++idx) {
|
for(int idx = 0 ; idx < data.commandCount; ++idx) {
|
||||||
const NetworkCommand &cmd = data.commands[idx];
|
const NetworkCommand &cmd = data.commands[idx];
|
||||||
|
|
||||||
|
@ -272,7 +272,7 @@ void NetworkMessageCommandList::send(Socket* socket) const{
|
||||||
assert(data.messageType==nmtCommandList);
|
assert(data.messageType==nmtCommandList);
|
||||||
NetworkMessage::send(socket, &data, commandListHeaderSize + sizeof(NetworkCommand) * data.commandCount);
|
NetworkMessage::send(socket, &data, commandListHeaderSize + sizeof(NetworkCommand) * data.commandCount);
|
||||||
|
|
||||||
if(SystemFlags::enableNetworkDebugInfo) {
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled == true) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s %d] messageType = %d, frameCount = %d, data.commandCount = %d\n",
|
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s %d] messageType = %d, frameCount = %d, data.commandCount = %d\n",
|
||||||
__FILE__,__FUNCTION__,__LINE__,data.messageType,data.frameCount,data.commandCount);
|
__FILE__,__FUNCTION__,__LINE__,data.messageType,data.frameCount,data.commandCount);
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// ==============================================================
|
// ==============================================================
|
||||||
// This file is part of Glest (www.glest.org)
|
// This file is part of Glest (www.glest.org)
|
||||||
//
|
//
|
||||||
// Copyright (C) 2001-2008 Martiño Figueroa
|
// Copyright (C) 2001-2008 Martio Figueroa
|
||||||
//
|
//
|
||||||
// You can redistribute this code and/or modify it under
|
// You can redistribute this code and/or modify it under
|
||||||
// the terms of the GNU General Public License as published
|
// the terms of the GNU General Public License as published
|
||||||
|
@ -47,7 +47,8 @@ NetworkCommand::NetworkCommand(World *world, int networkCommandType, int unitId,
|
||||||
const CommandType *ct = unit->getType()->findCommandTypeById(this->commandTypeId);
|
const CommandType *ct = unit->getType()->findCommandTypeById(this->commandTypeId);
|
||||||
if(ct != NULL && ct->getClass() == ccBuild) {
|
if(ct != NULL && ct->getClass() == ccBuild) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,toString().c_str());
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] %s\n",__FILE__,__FUNCTION__,__LINE__,toString().c_str());
|
||||||
assert(facing >= 0 && facing < 4 && targetId == -1);
|
CardinalDir::assertDirValid(facing);
|
||||||
|
assert(targetId == -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +63,7 @@ void NetworkCommand::preprocessNetworkCommand(World *world) {
|
||||||
const UnitType *unitType= world->findUnitTypeById(unit->getFaction()->getType(), unitTypeId);
|
const UnitType *unitType= world->findUnitTypeById(unit->getFaction()->getType(), unitTypeId);
|
||||||
const CommandType *ct = unit->getType()->findCommandTypeById(commandTypeId);
|
const CommandType *ct = unit->getType()->findCommandTypeById(commandTypeId);
|
||||||
if(ct != NULL && ct->getClass() == ccBuild && targetId >= 0) {
|
if(ct != NULL && ct->getClass() == ccBuild && targetId >= 0) {
|
||||||
assert(targetId < 4);
|
CardinalDir::assertDirValid(targetId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -171,6 +171,8 @@ Unit::Unit(int id, const Vec2i &pos, const UnitType *type, Faction *faction, Map
|
||||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__);
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__);
|
||||||
livingUnits.insert(id);
|
livingUnits.insert(id);
|
||||||
livingUnitsp.insert(this);
|
livingUnitsp.insert(this);
|
||||||
|
|
||||||
|
logSynchData(string(__FILE__) + string("::") + string(__FUNCTION__) + string(" Line: ") + intToStr(__LINE__));
|
||||||
}
|
}
|
||||||
|
|
||||||
Unit::~Unit(){
|
Unit::~Unit(){
|
||||||
|
@ -403,6 +405,8 @@ void Unit::setPos(const Vec2i &pos){
|
||||||
this->lastPos= this->pos;
|
this->lastPos= this->pos;
|
||||||
this->pos= pos;
|
this->pos= pos;
|
||||||
this->meetingPos= pos - Vec2i(1);
|
this->meetingPos= pos - Vec2i(1);
|
||||||
|
|
||||||
|
logSynchData(string(__FILE__) + string("::") + string(__FUNCTION__) + string(" Line: ") + intToStr(__LINE__));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::setTargetPos(const Vec2i &targetPos){
|
void Unit::setTargetPos(const Vec2i &targetPos){
|
||||||
|
@ -413,6 +417,8 @@ void Unit::setTargetPos(const Vec2i &targetPos){
|
||||||
targetRef= NULL;
|
targetRef= NULL;
|
||||||
|
|
||||||
this->targetPos= targetPos;
|
this->targetPos= targetPos;
|
||||||
|
|
||||||
|
logSynchData(string(__FILE__) + string("::") + string(__FUNCTION__) + string(" Line: ") + intToStr(__LINE__));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::setVisible(const bool visible){
|
void Unit::setVisible(const bool visible){
|
||||||
|
@ -989,6 +995,8 @@ void Unit::updateTarget(){
|
||||||
|
|
||||||
//update target vec
|
//update target vec
|
||||||
targetVec= target->getCurrVector();
|
targetVec= target->getCurrVector();
|
||||||
|
|
||||||
|
//logSynchData(string(__FILE__) + string("::") + string(__FUNCTION__) + string(" Line: ") + intToStr(__LINE__));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1151,4 +1159,46 @@ void Unit::startDamageParticles(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Unit::setTargetVec(const Vec3f &targetVec) {
|
||||||
|
this->targetVec= targetVec;
|
||||||
|
logSynchData(string(__FILE__) + string("::") + string(__FUNCTION__) + string(" Line: ") + intToStr(__LINE__));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Unit::setMeetingPos(const Vec2i &meetingPos) {
|
||||||
|
this->meetingPos= meetingPos;
|
||||||
|
logSynchData(string(__FILE__) + string("::") + string(__FUNCTION__) + string(" Line: ") + intToStr(__LINE__));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Unit::logSynchData(string source) {
|
||||||
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled == true) {
|
||||||
|
|
||||||
|
char szBuf[1024]="";
|
||||||
|
sprintf(szBuf,
|
||||||
|
//"Unit = %d [%s] [%s] pos = %s, lastPos = %s, targetPos = %s, targetVec = %s, meetingPos = %s, lastRotation [%f], targetRotation [%f], rotation [%f], progress [%f], progress2 [%f]\n",
|
||||||
|
"Unit = %d [%s] pos = %s, lastPos = %s, targetPos = %s, targetVec = %s, meetingPos = %s, lastRotation [%f], targetRotation [%f], rotation [%f], progress [%f], progress2 [%d]\n",
|
||||||
|
id,
|
||||||
|
getFullName().c_str(),
|
||||||
|
//getDesc().c_str(),
|
||||||
|
pos.getString().c_str(),
|
||||||
|
lastPos.getString().c_str(),
|
||||||
|
targetPos.getString().c_str(),
|
||||||
|
targetVec.getString().c_str(),
|
||||||
|
meetingPos.getString().c_str(),
|
||||||
|
lastRotation,
|
||||||
|
targetRotation,
|
||||||
|
rotation,
|
||||||
|
progress,
|
||||||
|
progress2);
|
||||||
|
|
||||||
|
if(lastSynchDataString != string(szBuf)) {
|
||||||
|
lastSynchDataString = string(szBuf);
|
||||||
|
|
||||||
|
SystemFlags::OutputDebug(SystemFlags::debugWorldSynch,
|
||||||
|
"%s %s\n",
|
||||||
|
source.c_str(),
|
||||||
|
szBuf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
|
|
@ -190,6 +190,8 @@ private:
|
||||||
bool allowRotateUnits;
|
bool allowRotateUnits;
|
||||||
CardinalDir modelFacing;
|
CardinalDir modelFacing;
|
||||||
|
|
||||||
|
std::string lastSynchDataString;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Unit(int id, const Vec2i &pos, const UnitType *type, Faction *faction, Map *map, CardinalDir placeFacing);
|
Unit(int id, const Vec2i &pos, const UnitType *type, Faction *faction, Map *map, CardinalDir placeFacing);
|
||||||
~Unit();
|
~Unit();
|
||||||
|
@ -259,8 +261,8 @@ public:
|
||||||
void setPos(const Vec2i &pos);
|
void setPos(const Vec2i &pos);
|
||||||
void setTargetPos(const Vec2i &targetPos);
|
void setTargetPos(const Vec2i &targetPos);
|
||||||
void setTarget(const Unit *unit);
|
void setTarget(const Unit *unit);
|
||||||
void setTargetVec(const Vec3f &targetVec) {this->targetVec= targetVec;}
|
void setTargetVec(const Vec3f &targetVec);
|
||||||
void setMeetingPos(const Vec2i &meetingPos) {this->meetingPos= meetingPos;}
|
void setMeetingPos(const Vec2i &meetingPos);
|
||||||
void setVisible(const bool visible);
|
void setVisible(const bool visible);
|
||||||
|
|
||||||
//render related
|
//render related
|
||||||
|
@ -314,6 +316,7 @@ private:
|
||||||
CommandResult undoCommand(Command *command);
|
CommandResult undoCommand(Command *command);
|
||||||
void stopDamageParticles();
|
void stopDamageParticles();
|
||||||
void startDamageParticles();
|
void startDamageParticles();
|
||||||
|
void logSynchData(string source="");
|
||||||
};
|
};
|
||||||
|
|
||||||
}}// end namespace
|
}}// end namespace
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
|
|
||||||
#include "streflop_cond.h"
|
#include "streflop_cond.h"
|
||||||
//#include <cmath>
|
//#include <cmath>
|
||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
namespace Shared{ namespace Graphics{
|
namespace Shared{ namespace Graphics{
|
||||||
|
|
||||||
|
@ -133,6 +135,12 @@ public:
|
||||||
x/= m;
|
x/= m;
|
||||||
y/= m;
|
y/= m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string getString() {
|
||||||
|
std::ostringstream streamOut;
|
||||||
|
streamOut << "x [" << x << "] y [" << y << "]";
|
||||||
|
return streamOut.str();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef Vec2<int> Vec2i;
|
typedef Vec2<int> Vec2i;
|
||||||
|
@ -298,6 +306,12 @@ public:
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string getString() {
|
||||||
|
std::ostringstream streamOut;
|
||||||
|
streamOut << "x [" << x << "] y [" << y << "] z [" << z << "]";
|
||||||
|
return streamOut.str();
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef Vec3<int> Vec3i;
|
typedef Vec3<int> Vec3i;
|
||||||
|
@ -431,6 +445,13 @@ public:
|
||||||
T dot(const Vec4<T> &v) const{
|
T dot(const Vec4<T> &v) const{
|
||||||
return x*v.x + y*v.y + z*v.z + w*v.w;
|
return x*v.x + y*v.y + z*v.z + w*v.w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string getString() {
|
||||||
|
std::ostringstream streamOut;
|
||||||
|
streamOut << "x [" << x << "] y [" << y << "] z [" << z << "] w [" << w << "]";
|
||||||
|
return streamOut.str();
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef Vec4<int> Vec4i;
|
typedef Vec4<int> Vec4i;
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
|
@ -21,28 +22,60 @@ namespace Shared{ namespace Util{
|
||||||
|
|
||||||
class SystemFlags
|
class SystemFlags
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
enum DebugType {
|
||||||
|
debugSystem,
|
||||||
|
debugNetwork,
|
||||||
|
debugPerformance,
|
||||||
|
debugWorldSynch
|
||||||
|
};
|
||||||
|
|
||||||
|
class SystemFlagsType
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
DebugType debugType;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SystemFlagsType() {
|
||||||
|
this->debugType = debugSystem;
|
||||||
|
this->enabled = false;
|
||||||
|
this->fileStream = NULL;
|
||||||
|
this->debugLogFileName = "";
|
||||||
|
}
|
||||||
|
SystemFlagsType(DebugType debugType) {
|
||||||
|
this->debugType = debugType;
|
||||||
|
this->enabled = false;
|
||||||
|
this->fileStream = NULL;
|
||||||
|
this->debugLogFileName = "";
|
||||||
|
}
|
||||||
|
SystemFlagsType(DebugType debugType,bool enabled,
|
||||||
|
std::ofstream *fileStream,std::string debugLogFileName) {
|
||||||
|
this->debugType = debugType;
|
||||||
|
this->enabled = enabled;
|
||||||
|
this->fileStream = fileStream;
|
||||||
|
this->debugLogFileName = debugLogFileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool enabled;
|
||||||
|
std::ofstream *fileStream;
|
||||||
|
std::string debugLogFileName;
|
||||||
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
static int lockFile;
|
static int lockFile;
|
||||||
static string lockfilename;
|
static string lockfilename;
|
||||||
|
|
||||||
static std::ofstream fileStream;
|
static std::map<DebugType,SystemFlagsType> debugLogFileList;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
SystemFlags();
|
SystemFlags();
|
||||||
~SystemFlags();
|
~SystemFlags();
|
||||||
|
|
||||||
enum DebugType {
|
static void init();
|
||||||
debugSystem,
|
static SystemFlagsType & getSystemSettingType(DebugType type) { return debugLogFileList[type]; }
|
||||||
debugNetwork,
|
|
||||||
debugPerformance
|
|
||||||
};
|
|
||||||
|
|
||||||
static bool enableDebugText;
|
|
||||||
static bool enableNetworkDebugInfo;
|
|
||||||
static bool enablePerformanceDebugInfo;
|
|
||||||
static const char *debugLogFile;
|
|
||||||
|
|
||||||
static void OutputDebug(DebugType type, const char *fmt, ...);
|
static void OutputDebug(DebugType type, const char *fmt, ...);
|
||||||
static void Close();
|
static void Close();
|
||||||
};
|
};
|
||||||
|
|
|
@ -35,12 +35,22 @@ using namespace Shared::Platform;
|
||||||
|
|
||||||
namespace Shared{ namespace Util{
|
namespace Shared{ namespace Util{
|
||||||
|
|
||||||
bool SystemFlags::enableDebugText = false;
|
std::map<SystemFlags::DebugType,SystemFlags::SystemFlagsType> SystemFlags::debugLogFileList;
|
||||||
bool SystemFlags::enableNetworkDebugInfo = false;
|
|
||||||
bool SystemFlags::enablePerformanceDebugInfo = false;
|
|
||||||
|
|
||||||
const char * SystemFlags::debugLogFile = NULL;
|
void SystemFlags::init() {
|
||||||
ofstream SystemFlags::fileStream;
|
SystemFlags::debugLogFileList[SystemFlags::debugSystem] = SystemFlags::SystemFlagsType(SystemFlags::debugSystem);
|
||||||
|
SystemFlags::debugLogFileList[SystemFlags::debugNetwork] = SystemFlags::SystemFlagsType(SystemFlags::debugNetwork);
|
||||||
|
SystemFlags::debugLogFileList[SystemFlags::debugPerformance] = SystemFlags::SystemFlagsType(SystemFlags::debugPerformance);
|
||||||
|
SystemFlags::debugLogFileList[SystemFlags::debugWorldSynch] = SystemFlags::SystemFlagsType(SystemFlags::debugWorldSynch);
|
||||||
|
}
|
||||||
|
|
||||||
|
//bool SystemFlags::enableDebugText = false;
|
||||||
|
//bool SystemFlags::enableNetworkDebugInfo = false;
|
||||||
|
//bool SystemFlags::enablePerformanceDebugInfo = false;
|
||||||
|
//bool SystemFlags::enableWorldSynchDebugInfo = false;
|
||||||
|
|
||||||
|
//const char * SystemFlags::debugLogFile = NULL;
|
||||||
|
//ofstream SystemFlags::fileStream;
|
||||||
int SystemFlags::lockFile = -1;
|
int SystemFlags::lockFile = -1;
|
||||||
string SystemFlags::lockfilename = "";
|
string SystemFlags::lockfilename = "";
|
||||||
|
|
||||||
|
@ -69,9 +79,17 @@ SystemFlags::~SystemFlags() {
|
||||||
void SystemFlags::Close() {
|
void SystemFlags::Close() {
|
||||||
printf("Closing logfile\n");
|
printf("Closing logfile\n");
|
||||||
|
|
||||||
if(fileStream.is_open() == true) {
|
for(std::map<SystemFlags::DebugType,SystemFlags::SystemFlagsType>::iterator iterMap = SystemFlags::debugLogFileList.begin();
|
||||||
SystemFlags::fileStream.close();
|
iterMap != SystemFlags::debugLogFileList.end(); iterMap++) {
|
||||||
|
SystemFlags::SystemFlagsType ¤tDebugLog = iterMap->second;
|
||||||
|
if( currentDebugLog.fileStream != NULL &&
|
||||||
|
currentDebugLog.fileStream->is_open() == true) {
|
||||||
|
currentDebugLog.fileStream->close();
|
||||||
|
}
|
||||||
|
delete currentDebugLog.fileStream;
|
||||||
|
currentDebugLog.fileStream = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(SystemFlags::lockfilename != "") {
|
if(SystemFlags::lockfilename != "") {
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
close(SystemFlags::lockFile);
|
close(SystemFlags::lockFile);
|
||||||
|
@ -84,9 +102,8 @@ void SystemFlags::Close() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) {
|
void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) {
|
||||||
if((type == debugSystem && SystemFlags::enableDebugText == false) ||
|
SystemFlags::SystemFlagsType ¤tDebugLog = SystemFlags::debugLogFileList[type];
|
||||||
(type == debugNetwork && SystemFlags::enableNetworkDebugInfo == false ||
|
if(currentDebugLog.enabled == false) {
|
||||||
type == debugPerformance && SystemFlags::enablePerformanceDebugInfo == false)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,10 +121,27 @@ void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) {
|
||||||
vsprintf(szBuf,fmt, argList);
|
vsprintf(szBuf,fmt, argList);
|
||||||
|
|
||||||
// Either output to a logfile or
|
// Either output to a logfile or
|
||||||
if(SystemFlags::debugLogFile != NULL && SystemFlags::debugLogFile[0] != 0) {
|
if(currentDebugLog.debugLogFileName != "") {
|
||||||
if(fileStream.is_open() == false) {
|
if( currentDebugLog.fileStream == NULL ||
|
||||||
string debugLog = SystemFlags::debugLogFile;
|
currentDebugLog.fileStream->is_open() == false) {
|
||||||
printf("Opening logfile [%s]\n",debugLog.c_str());
|
|
||||||
|
// If the file is already open (shared) by another debug type
|
||||||
|
// do not over-write the file but append
|
||||||
|
bool appendToFileOnly = false;
|
||||||
|
for(std::map<SystemFlags::DebugType,SystemFlags::SystemFlagsType>::iterator iterMap = SystemFlags::debugLogFileList.begin();
|
||||||
|
iterMap != SystemFlags::debugLogFileList.end(); iterMap++) {
|
||||||
|
SystemFlags::SystemFlagsType ¤tDebugLog2 = iterMap->second;
|
||||||
|
|
||||||
|
if( iterMap->first != type &&
|
||||||
|
currentDebugLog.debugLogFileName == currentDebugLog2.debugLogFileName &&
|
||||||
|
currentDebugLog2.fileStream != NULL) {
|
||||||
|
appendToFileOnly = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string debugLog = currentDebugLog.debugLogFileName;
|
||||||
|
printf("Opening logfile [%s] type = %d, appendToFileOnly = %d\n",debugLog.c_str(),type, appendToFileOnly);
|
||||||
|
|
||||||
const string lock_file_name = "debug.lck";
|
const string lock_file_name = "debug.lck";
|
||||||
string lockfile = extractDirectoryPathFromFile(debugLog);
|
string lockfile = extractDirectoryPathFromFile(debugLog);
|
||||||
|
@ -142,14 +176,28 @@ void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) {
|
||||||
printf("Opening additional logfile [%s]\n",debugLog.c_str());
|
printf("Opening additional logfile [%s]\n",debugLog.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
fileStream.open(debugLog.c_str(), ios_base::out | ios_base::trunc);
|
if(currentDebugLog.fileStream == NULL) {
|
||||||
|
currentDebugLog.fileStream = new std::ofstream();
|
||||||
|
}
|
||||||
|
if(appendToFileOnly == false) {
|
||||||
|
currentDebugLog.fileStream->open(debugLog.c_str(), ios_base::out | ios_base::trunc);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
currentDebugLog.fileStream->open(debugLog.c_str(), ios_base::out | ios_base::app);
|
||||||
|
}
|
||||||
|
|
||||||
|
(*currentDebugLog.fileStream) << "Starting Mega-Glest logging for type: " << type << "\n";
|
||||||
|
(*currentDebugLog.fileStream).flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf("Logfile is open [%s]\n",SystemFlags::debugLogFile);
|
//printf("Logfile is open [%s]\n",SystemFlags::debugLogFile);
|
||||||
|
|
||||||
//printf("writing to logfile [%s]\n",szBuf);
|
//printf("writing to logfile [%s]\n",szBuf);
|
||||||
fileStream << "[" << szBuf2 << "] " << szBuf;
|
|
||||||
fileStream.flush();
|
assert(currentDebugLog.fileStream != NULL);
|
||||||
|
|
||||||
|
(*currentDebugLog.fileStream) << "[" << szBuf2 << "] " << szBuf;
|
||||||
|
(*currentDebugLog.fileStream).flush();
|
||||||
}
|
}
|
||||||
// output to console
|
// output to console
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Reference in New Issue