mirror of
https://github.com/glest/glest-source.git
synced 2025-08-29 19:00:07 +02:00
- fixed two nasty AI bugs which would cause out of synch and memory corruption problems
- added new glest.ini setting to log commands for each client
This commit is contained in:
@@ -38,7 +38,8 @@ public:
|
||||
debugSystem,
|
||||
debugNetwork,
|
||||
debugPerformance,
|
||||
debugWorldSynch
|
||||
debugWorldSynch,
|
||||
debugUnitCommands
|
||||
};
|
||||
|
||||
class SystemFlagsType
|
||||
@@ -101,6 +102,7 @@ protected:
|
||||
|
||||
static int lockFile;
|
||||
static string lockfilename;
|
||||
static int lockFileCountIndex;
|
||||
|
||||
static std::map<DebugType,SystemFlagsType> debugLogFileList;
|
||||
|
||||
|
@@ -1,8 +1,10 @@
|
||||
#include "randomgen.h"
|
||||
#include <cassert>
|
||||
#include "util.h"
|
||||
#include <stdexcept>
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace std;
|
||||
namespace Shared { namespace Util {
|
||||
|
||||
// =====================================================
|
||||
@@ -37,7 +39,7 @@ void RandomGen::init(int seed){
|
||||
int RandomGen::rand() {
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] lastNumber = %d\n",__FILE__,__FUNCTION__,__LINE__,lastNumber);
|
||||
|
||||
lastNumber= ((a*lastNumber) + b) % m;
|
||||
lastNumber= (a*lastNumber + b) % m;
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] lastNumber = %d\n",__FILE__,__FUNCTION__,__LINE__,lastNumber);
|
||||
|
||||
@@ -46,14 +48,24 @@ int RandomGen::rand() {
|
||||
|
||||
int RandomGen::randRange(int min, int max){
|
||||
assert(min<=max);
|
||||
if(min > max) {
|
||||
char szBuf[1024]="";
|
||||
sprintf(szBuf,"In [%s::%s Line: %d] min > max, min = %d, max = %d",__FILE__,__FUNCTION__,__LINE__,min,max);
|
||||
throw runtime_error(szBuf);
|
||||
}
|
||||
|
||||
//#ifdef USE_STREFLOP
|
||||
// int res = streflop::Random<true, false, float>(min, max); // streflop
|
||||
//#else
|
||||
int diff= max-min;
|
||||
int res= min + static_cast<int>((static_cast<float>(diff+1)*RandomGen::rand()) / m);
|
||||
int res= min + static_cast<int>(static_cast<float>(diff+1)*RandomGen::rand() / m);
|
||||
//#endif
|
||||
assert(res>=min && res<=max);
|
||||
if(res < min || res > max) {
|
||||
char szBuf[1024]="";
|
||||
sprintf(szBuf,"In [%s::%s Line: %d] res < min || res > max, min = %d, max = %d, res = %d",__FILE__,__FUNCTION__,__LINE__,min,max,res);
|
||||
throw runtime_error(szBuf);
|
||||
}
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] min = %d, max = %d, res = %d\n",__FILE__,__FUNCTION__,__LINE__,min,max,res);
|
||||
|
||||
@@ -62,15 +74,25 @@ int RandomGen::randRange(int min, int max){
|
||||
|
||||
float RandomGen::randRange(float min, float max){
|
||||
assert(min<=max);
|
||||
if(min > max) {
|
||||
char szBuf[1024]="";
|
||||
sprintf(szBuf,"In [%s::%s Line: %d] min > max, min = %f, max = %f",__FILE__,__FUNCTION__,__LINE__,min,max);
|
||||
throw runtime_error(szBuf);
|
||||
}
|
||||
|
||||
//#ifdef USE_STREFLOP
|
||||
// float res = streflop::Random<true, false, float>(min, max, randomState); // streflop
|
||||
//#else
|
||||
float rand01= static_cast<float>(RandomGen::rand())/(m-1);
|
||||
float res= min+((max-min)*rand01);
|
||||
float res= min+(max-min)*rand01;
|
||||
//#endif
|
||||
|
||||
assert(res>=min && res<=max);
|
||||
if(res < min || res > max) {
|
||||
char szBuf[1024]="";
|
||||
sprintf(szBuf,"In [%s::%s Line: %d] res < min || res > max, min = %f, max = %f, res = %f",__FILE__,__FUNCTION__,__LINE__,min,max,res);
|
||||
throw runtime_error(szBuf);
|
||||
}
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] min = %f, max = %f, res = %f\n",__FILE__,__FUNCTION__,__LINE__,min,max,res);
|
||||
|
||||
|
@@ -40,6 +40,7 @@ namespace Shared{ namespace Util{
|
||||
// Init statics
|
||||
std::map<SystemFlags::DebugType,SystemFlags::SystemFlagsType> SystemFlags::debugLogFileList;
|
||||
int SystemFlags::lockFile = -1;
|
||||
int SystemFlags::lockFileCountIndex = -1;
|
||||
string SystemFlags::lockfilename = "";
|
||||
CURL *SystemFlags::curl_handle = NULL;
|
||||
//
|
||||
@@ -113,6 +114,7 @@ void SystemFlags::init() {
|
||||
SystemFlags::debugLogFileList[SystemFlags::debugNetwork] = SystemFlags::SystemFlagsType(SystemFlags::debugNetwork);
|
||||
SystemFlags::debugLogFileList[SystemFlags::debugPerformance] = SystemFlags::SystemFlagsType(SystemFlags::debugPerformance);
|
||||
SystemFlags::debugLogFileList[SystemFlags::debugWorldSynch] = SystemFlags::SystemFlagsType(SystemFlags::debugWorldSynch);
|
||||
SystemFlags::debugLogFileList[SystemFlags::debugUnitCommands] = SystemFlags::SystemFlagsType(SystemFlags::debugUnitCommands);
|
||||
}
|
||||
|
||||
if(curl_handle == NULL) {
|
||||
@@ -166,6 +168,7 @@ void SystemFlags::Close() {
|
||||
_close(SystemFlags::lockFile);
|
||||
#endif
|
||||
SystemFlags::lockFile = -1;
|
||||
SystemFlags::lockFileCountIndex = -1;
|
||||
|
||||
if(SystemFlags::lockfilename != "") {
|
||||
remove(SystemFlags::lockfilename.c_str());
|
||||
@@ -230,17 +233,9 @@ void SystemFlags::handleDebug(DebugType type, const char *fmt, ...) {
|
||||
|
||||
#ifndef WIN32
|
||||
//SystemFlags::lockFile = open(lockfile.c_str(), O_WRONLY | O_CREAT | O_EXCL, S_IRUSR|S_IWUSR);
|
||||
#ifdef S_IREAD
|
||||
SystemFlags::lockFile = open(lockfile.c_str(), O_WRONLY | O_CREAT, S_IREAD | S_IWRITE);
|
||||
#else
|
||||
SystemFlags::lockFile = open(lockfile.c_str(), O_WRONLY | O_CREAT);
|
||||
#endif
|
||||
#else
|
||||
#ifdef S_IREAD
|
||||
SystemFlags::lockFile = _open(lockfile.c_str(), O_WRONLY | O_CREAT, S_IREAD | S_IWRITE);
|
||||
#else
|
||||
SystemFlags::lockFile = _open(lockfile.c_str(), O_WRONLY | O_CREAT);
|
||||
#endif
|
||||
#endif
|
||||
if (SystemFlags::lockFile < 0 || acquire_file_lock(SystemFlags::lockFile) == false) {
|
||||
string newlockfile = lockfile;
|
||||
@@ -249,17 +244,9 @@ void SystemFlags::handleDebug(DebugType type, const char *fmt, ...) {
|
||||
newlockfile = lockfile + intToStr(idx);
|
||||
//SystemFlags::lockFile = open(newlockfile.c_str(), O_WRONLY | O_CREAT | O_EXCL, S_IRUSR|S_IWUSR);
|
||||
#ifndef WIN32
|
||||
#ifdef S_IREAD
|
||||
SystemFlags::lockFile = open(newlockfile.c_str(), O_WRONLY | O_CREAT, S_IREAD | S_IWRITE);
|
||||
#else
|
||||
SystemFlags::lockFile = open(newlockfile.c_str(), O_WRONLY | O_CREAT);
|
||||
#endif
|
||||
#else
|
||||
#ifdef S_IREAD
|
||||
SystemFlags::lockFile = _open(newlockfile.c_str(), O_WRONLY | O_CREAT, S_IREAD | S_IWRITE);
|
||||
#else
|
||||
SystemFlags::lockFile = _open(newlockfile.c_str(), O_WRONLY | O_CREAT);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
if(SystemFlags::lockFile >= 0 && acquire_file_lock(SystemFlags::lockFile) == true) {
|
||||
@@ -267,12 +254,18 @@ void SystemFlags::handleDebug(DebugType type, const char *fmt, ...) {
|
||||
}
|
||||
}
|
||||
|
||||
SystemFlags::lockFileCountIndex = idx;
|
||||
SystemFlags::lockfilename = newlockfile;
|
||||
debugLog += intToStr(idx);
|
||||
|
||||
printf("Opening additional logfile [%s]\n",debugLog.c_str());
|
||||
}
|
||||
}
|
||||
else if(SystemFlags::lockFileCountIndex > 0) {
|
||||
debugLog += intToStr(SystemFlags::lockFileCountIndex);
|
||||
|
||||
printf("Opening additional logfile [%s]\n",debugLog.c_str());
|
||||
}
|
||||
|
||||
if(currentDebugLog.fileStream == NULL) {
|
||||
currentDebugLog.fileStream = new std::ofstream();
|
||||
|
Reference in New Issue
Block a user