Fixed the god-awful indentation

This commit is contained in:
mathusummut
2018-05-06 00:01:36 +02:00
parent 643e3820f5
commit 35b7b1f1a6
459 changed files with 204893 additions and 217545 deletions

View File

@@ -20,147 +20,152 @@
using namespace Shared::Platform;
using namespace std;
namespace Shared { namespace PlatformCommon {
namespace Shared {
namespace PlatformCommon {
// =====================================================
// class BaseThread
// =====================================================
// =====================================================
// class BaseThread
// =====================================================
class BaseThread : public Thread
{
protected:
Mutex *mutexRunning;
Mutex *mutexQuit;
Mutex *mutexBeginExecution;
Mutex *mutexDeleteSelfOnExecutionDone;
class BaseThread : public Thread {
protected:
Mutex *mutexRunning;
Mutex *mutexQuit;
Mutex *mutexBeginExecution;
Mutex *mutexDeleteSelfOnExecutionDone;
Mutex *mutexThreadObjectAccessor;
Mutex *mutexThreadObjectAccessor;
bool threadOwnerValid;
Mutex *mutexThreadOwnerValid;
bool threadOwnerValid;
Mutex *mutexThreadOwnerValid;
Mutex *mutexExecutingTask;
bool executingTask;
Mutex *mutexExecutingTask;
bool executingTask;
void *ptr;
static Mutex mutexMasterThreadList;
static std::map<void *,int> masterThreadList;
void *ptr;
static Mutex mutexMasterThreadList;
static std::map<void *, int> masterThreadList;
bool quit;
bool running;
string uniqueID;
bool hasBeginExecution;
bool deleteSelfOnExecutionDone;
bool quit;
bool running;
string uniqueID;
bool hasBeginExecution;
bool deleteSelfOnExecutionDone;
Mutex *mutexStarted;
bool started;
Mutex *mutexStarted;
bool started;
virtual void setQuitStatus(bool value);
void deleteSelfIfRequired();
virtual void setQuitStatus(bool value);
void deleteSelfIfRequired();
void *genericData;
void *genericData;
public:
BaseThread();
virtual ~BaseThread();
virtual void execute()=0;
public:
BaseThread();
virtual ~BaseThread();
virtual void execute() = 0;
virtual void signalQuit();
virtual bool getQuitStatus();
virtual bool getRunningStatus();
virtual void signalQuit();
virtual bool getQuitStatus();
virtual bool getRunningStatus();
virtual bool getStarted();
virtual void setStarted(bool value);
virtual bool getStarted();
virtual void setStarted(bool value);
virtual bool getHasBeginExecution();
virtual void setHasBeginExecution(bool value);
virtual bool getHasBeginExecution();
virtual void setHasBeginExecution(bool value);
static bool shutdownAndWait(BaseThread *ppThread);
virtual bool shutdownAndWait();
virtual bool canShutdown(bool deleteSelfIfShutdownDelayed=false);
static bool shutdownAndWait(BaseThread *ppThread);
virtual bool shutdownAndWait();
virtual bool canShutdown(bool deleteSelfIfShutdownDelayed = false);
virtual bool getDeleteSelfOnExecutionDone();
virtual void setDeleteSelfOnExecutionDone(bool value);
virtual bool getDeleteSelfOnExecutionDone();
virtual void setDeleteSelfOnExecutionDone(bool value);
void setUniqueID(string value) { uniqueID = value; }
string getUniqueID() { return uniqueID; }
void setUniqueID(string value) {
uniqueID = value;
}
string getUniqueID() {
return uniqueID;
}
virtual void setRunningStatus(bool value);
virtual void setRunningStatus(bool value);
void setExecutingTask(bool value);
bool getExecutingTask();
void setExecutingTask(bool value);
bool getExecutingTask();
void setThreadOwnerValid(bool value);
bool getThreadOwnerValid();
Mutex * getMutexThreadOwnerValid();
void setThreadOwnerValid(bool value);
bool getThreadOwnerValid();
Mutex * getMutexThreadOwnerValid();
Mutex * getMutexThreadObjectAccessor();
template <typename T>
T * getGenericData() {
return genericData;
}
template <typename T>
void setGenericData(T *value) {
genericData = value;
}
static bool isThreadDeleted(void *ptr);
};
class RunningStatusSafeWrapper {
protected:
BaseThread *thread;
public:
RunningStatusSafeWrapper(BaseThread *thread) {
this->thread = thread;
Enable();
}
~RunningStatusSafeWrapper() {
Disable();
}
void Enable() {
if (this->thread != NULL) {
this->thread->setRunningStatus(true);
}
}
void Disable() {
if (this->thread != NULL) {
this->thread->setRunningStatus(false);
}
}
};
class ExecutingTaskSafeWrapper {
protected:
BaseThread *thread;
public:
ExecutingTaskSafeWrapper(BaseThread *thread) {
this->thread = thread;
Enable();
}
~ExecutingTaskSafeWrapper() {
Disable();
}
void Enable() {
if (this->thread != NULL) {
this->thread->setExecutingTask(true);
}
}
void Disable() {
if (this->thread != NULL) {
this->thread->setExecutingTask(false);
}
}
};
Mutex * getMutexThreadObjectAccessor();
template <typename T>
T * getGenericData() {
return genericData;
}
template <typename T>
void setGenericData(T *value) {
genericData = value;
}
static bool isThreadDeleted(void *ptr);
};
class RunningStatusSafeWrapper {
protected:
BaseThread *thread;
public:
RunningStatusSafeWrapper(BaseThread *thread) {
this->thread = thread;
Enable();
}
~RunningStatusSafeWrapper() {
Disable();
}
void Enable() {
if(this->thread != NULL) {
this->thread->setRunningStatus(true);
}
}
void Disable() {
if(this->thread != NULL) {
this->thread->setRunningStatus(false);
}
}
};
class ExecutingTaskSafeWrapper {
protected:
BaseThread *thread;
public:
ExecutingTaskSafeWrapper(BaseThread *thread) {
this->thread = thread;
Enable();
}
~ExecutingTaskSafeWrapper() {
Disable();
}
void Enable() {
if(this->thread != NULL) {
this->thread->setExecutingTask(true);
}
}
void Disable() {
if(this->thread != NULL) {
this->thread->setExecutingTask(false);
}
}
};
}}//end namespace
}//end namespace
#endif

View File

@@ -15,65 +15,67 @@
#include <algorithm>
#include "leak_dumper.h"
namespace Shared{ namespace PlatformByteOrder {
namespace Shared {
namespace PlatformByteOrder {
template<class T> T EndianReverse(T t) {
// unsigned char uc[sizeof t];
// memcpy(uc, &t, sizeof t);
//
// for (unsigned char *b = uc, *e = uc + sizeof(T) - 1; b < e; ++b, --e) {
// std::swap(*b, *e);
// }
// memcpy(&t, uc, sizeof t);
// return t;
template<class T> T EndianReverse(T t) {
// unsigned char uc[sizeof t];
// memcpy(uc, &t, sizeof t);
//
// for (unsigned char *b = uc, *e = uc + sizeof(T) - 1; b < e; ++b, --e) {
// std::swap(*b, *e);
// }
// memcpy(&t, uc, sizeof t);
// return t;
char& raw = reinterpret_cast<char&>(t);
std::reverse(&raw, &raw + sizeof(T));
return t;
}
inline static bool isBigEndian() {
short n = 0x1;
return (*(char*)(&n) == 0x0);
}
template<class T> T toCommonEndian(T t) {
static bool bigEndianSystem = isBigEndian();
if(bigEndianSystem == true) {
t = EndianReverse(t);
}
return t;
}
template<class T> T fromCommonEndian(T t) {
static bool bigEndianSystem = isBigEndian();
if(bigEndianSystem == true) {
t = EndianReverse(t);
}
return t;
}
template<class T>
void toEndianTypeArray(T *data, size_t size) {
static bool bigEndianSystem = isBigEndian();
if(bigEndianSystem == true) {
for(size_t i = 0; i < size; ++i) {
data[i] = toCommonEndian(data[i]);
char& raw = reinterpret_cast<char&>(t);
std::reverse(&raw, &raw + sizeof(T));
return t;
}
}
}
template<class T>
void fromEndianTypeArray(T *data, size_t size) {
static bool bigEndianSystem = isBigEndian();
if(bigEndianSystem == true) {
for(size_t i = 0; i < size; ++i) {
data[i] = fromCommonEndian(data[i]);
inline static bool isBigEndian() {
short n = 0x1;
return (*(char*) (&n) == 0x0);
}
template<class T> T toCommonEndian(T t) {
static bool bigEndianSystem = isBigEndian();
if (bigEndianSystem == true) {
t = EndianReverse(t);
}
return t;
}
template<class T> T fromCommonEndian(T t) {
static bool bigEndianSystem = isBigEndian();
if (bigEndianSystem == true) {
t = EndianReverse(t);
}
return t;
}
template<class T>
void toEndianTypeArray(T *data, size_t size) {
static bool bigEndianSystem = isBigEndian();
if (bigEndianSystem == true) {
for (size_t i = 0; i < size; ++i) {
data[i] = toCommonEndian(data[i]);
}
}
}
template<class T>
void fromEndianTypeArray(T *data, size_t size) {
static bool bigEndianSystem = isBigEndian();
if (bigEndianSystem == true) {
for (size_t i = 0; i < size; ++i) {
data[i] = fromCommonEndian(data[i]);
}
}
}
}
}
}}
#endif

View File

@@ -23,116 +23,116 @@
using namespace std;
using namespace Shared::Platform;
namespace Shared { namespace PlatformCommon {
namespace Shared {
namespace PlatformCommon {
// =====================================================
// class BaseThread
// =====================================================
// =====================================================
// class BaseThread
// =====================================================
class CacheManager
{
public:
class CacheManager {
public:
static const char *getFolderTreeContentsCheckSumRecursivelyCacheLookupKey1;
static const char *getFolderTreeContentsCheckSumRecursivelyCacheLookupKey2;
static const char *getFolderTreeContentsCheckSumListRecursivelyCacheLookupKey1;
static const char *getFolderTreeContentsCheckSumListRecursivelyCacheLookupKey2;
static const char *getFolderTreeContentsCheckSumRecursivelyCacheLookupKey1;
static const char *getFolderTreeContentsCheckSumRecursivelyCacheLookupKey2;
static const char *getFolderTreeContentsCheckSumListRecursivelyCacheLookupKey1;
static const char *getFolderTreeContentsCheckSumListRecursivelyCacheLookupKey2;
protected:
static std::map<string, Mutex *> itemCacheMutexList;
static Mutex mutexMap;
typedef enum {
cacheItemGet,
cacheItemSet
} CacheAccessorType;
protected:
static std::map<string, Mutex *> itemCacheMutexList;
static Mutex mutexMap;
typedef enum {
cacheItemGet,
cacheItemSet
} CacheAccessorType;
static Mutex & manageCachedItemMutex(string cacheKey) {
if(itemCacheMutexList.find(cacheKey) == itemCacheMutexList.end()) {
MutexSafeWrapper safeMutex(&mutexMap);
if(itemCacheMutexList.find(cacheKey) == itemCacheMutexList.end()) {
itemCacheMutexList[cacheKey] = new Mutex(CODE_AT_LINE);
}
safeMutex.ReleaseLock();
}
Mutex *mutex = itemCacheMutexList[cacheKey];
return *mutex;
}
template <typename T>
static T & manageCachedItem(string cacheKey, T *value,CacheAccessorType accessor) {
// Here is the actual type-safe instantiation
static std::map<string, T > itemCache;
if(accessor == cacheItemSet) {
if(value == NULL) {
try {
Mutex &mutexCache = manageCachedItemMutex(cacheKey);
MutexSafeWrapper safeMutex(&mutexCache);
if(itemCache.find(cacheKey) != itemCache.end()) {
itemCache.erase(cacheKey);
static Mutex & manageCachedItemMutex(string cacheKey) {
if (itemCacheMutexList.find(cacheKey) == itemCacheMutexList.end()) {
MutexSafeWrapper safeMutex(&mutexMap);
if (itemCacheMutexList.find(cacheKey) == itemCacheMutexList.end()) {
itemCacheMutexList[cacheKey] = new Mutex(CODE_AT_LINE);
}
safeMutex.ReleaseLock();
}
catch(const std::exception &ex) {
throw megaglest_runtime_error(ex.what());
}
Mutex *mutex = itemCacheMutexList[cacheKey];
return *mutex;
}
if(value != NULL) {
try {
Mutex &mutexCache = manageCachedItemMutex(cacheKey);
MutexSafeWrapper safeMutex(&mutexCache);
itemCache[cacheKey] = *value;
safeMutex.ReleaseLock();
}
catch(const std::exception &ex) {
throw megaglest_runtime_error(ex.what());
template <typename T>
static T & manageCachedItem(string cacheKey, T *value, CacheAccessorType accessor) {
// Here is the actual type-safe instantiation
static std::map<string, T > itemCache;
if (accessor == cacheItemSet) {
if (value == NULL) {
try {
Mutex &mutexCache = manageCachedItemMutex(cacheKey);
MutexSafeWrapper safeMutex(&mutexCache);
if (itemCache.find(cacheKey) != itemCache.end()) {
itemCache.erase(cacheKey);
}
safeMutex.ReleaseLock();
} catch (const std::exception &ex) {
throw megaglest_runtime_error(ex.what());
}
}
if (value != NULL) {
try {
Mutex &mutexCache = manageCachedItemMutex(cacheKey);
MutexSafeWrapper safeMutex(&mutexCache);
itemCache[cacheKey] = *value;
safeMutex.ReleaseLock();
} catch (const std::exception &ex) {
throw megaglest_runtime_error(ex.what());
}
}
}
// If this is the first access we return a default object of the type
Mutex &mutexCache = manageCachedItemMutex(cacheKey);
MutexSafeWrapper safeMutex(&mutexCache);
return itemCache[cacheKey];
}
}
// If this is the first access we return a default object of the type
Mutex &mutexCache = manageCachedItemMutex(cacheKey);
MutexSafeWrapper safeMutex(&mutexCache);
return itemCache[cacheKey];
}
public:
public:
CacheManager() {
}
static void cleanupMutexes() {
MutexSafeWrapper safeMutex(&mutexMap);
for (std::map<string, Mutex *>::iterator iterMap = itemCacheMutexList.begin();
iterMap != itemCacheMutexList.end(); iterMap++) {
delete iterMap->second;
iterMap->second = NULL;
}
itemCacheMutexList.clear();
safeMutex.ReleaseLock();
}
~CacheManager() {
CacheManager::cleanupMutexes();
}
CacheManager() { }
static void cleanupMutexes() {
MutexSafeWrapper safeMutex(&mutexMap);
for(std::map<string, Mutex *>::iterator iterMap = itemCacheMutexList.begin();
iterMap != itemCacheMutexList.end(); iterMap++) {
delete iterMap->second;
iterMap->second = NULL;
}
itemCacheMutexList.clear();
safeMutex.ReleaseLock();
}
~CacheManager() {
CacheManager::cleanupMutexes();
}
template <typename T>
static void setCachedItem(string cacheKey, const T value) {
manageCachedItem<T>(cacheKey, value, cacheItemSet);
}
template <typename T>
static T & getCachedItem(string cacheKey) {
return manageCachedItem<T>(cacheKey, NULL, cacheItemGet);
}
template <typename T>
static void clearCachedItem(string cacheKey) {
return manageCachedItem<T>(cacheKey, NULL, cacheItemSet);
}
template <typename T>
static void setCachedItem(string cacheKey, const T value) {
manageCachedItem<T>(cacheKey,value,cacheItemSet);
}
template <typename T>
static T & getCachedItem(string cacheKey) {
return manageCachedItem<T>(cacheKey,NULL,cacheItemGet);
}
template <typename T>
static void clearCachedItem(string cacheKey) {
return manageCachedItem<T>(cacheKey,NULL,cacheItemSet);
}
template <typename T>
static Mutex & getMutexForItem(string cacheKey) {
return manageCachedItemMutex(cacheKey);
}
};
template <typename T>
static Mutex & getMutexForItem(string cacheKey) {
return manageCachedItemMutex(cacheKey);
}
};
}}//end namespace
}//end namespace
#endif

View File

@@ -25,7 +25,7 @@
#if defined(WIN32)
#define auto_ptr unique_ptr
#else
#define auto_ptr std::unique_ptr
#define auto_ptr std::unique_ptr
#endif
#endif

View File

@@ -40,295 +40,297 @@ using std::exception;
using Shared::Platform::int64;
using Shared::Util::Checksum;
namespace Shared { namespace PlatformCommon {
namespace Shared {
namespace PlatformCommon {
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#define CODE_AT_LINE __FILE__ ":" TOSTRING(__LINE__)
#define CODE_AT_LINE_X(x) __FILE__ ":" TOSTRING(__LINE__) ":" TOSTRING(x)
static const int IGNORE_CMD_RESULT_VALUE = -999999;
static const int IGNORE_CMD_RESULT_VALUE = -999999;
// keycode constants (unfortunately designed after DirectInput and therefore not
// very specific)
// They also have to fit into a char. The positive numbers seem to be equal
// to ascii, for the rest we have to find sensefull mappings from SDL (which is
// alot more fine grained like left/right control instead of just control...)
const char vkAdd = -1;
const char vkSubtract = -2;
const char vkAlt = -3;
const char vkControl = -4;
const char vkShift = -5;
const char vkEscape = -6;
const char vkUp = -7;
const char vkLeft = -8;
const char vkRight = -9;
const char vkDown = -10;
const char vkReturn = -11;
const char vkBack = -12;
const char vkTab = -13;
const char vkF1 = -14;
const char vkF2 = -15;
const char vkF3 = -16;
const char vkF4 = -17;
const char vkF5 = -18;
const char vkF6 = -19;
const char vkF7 = -20;
const char vkF8 = -21;
const char vkF9 = -22;
const char vkF10 = -23;
const char vkF11 = -24;
const char vkF12 = -25;
const char vkDelete = -26;
const char vkPrint = -27;
const char vkPause = -29;
// keycode constants (unfortunately designed after DirectInput and therefore not
// very specific)
// They also have to fit into a char. The positive numbers seem to be equal
// to ascii, for the rest we have to find sensefull mappings from SDL (which is
// alot more fine grained like left/right control instead of just control...)
const char vkAdd = -1;
const char vkSubtract = -2;
const char vkAlt = -3;
const char vkControl = -4;
const char vkShift = -5;
const char vkEscape = -6;
const char vkUp = -7;
const char vkLeft = -8;
const char vkRight = -9;
const char vkDown = -10;
const char vkReturn = -11;
const char vkBack = -12;
const char vkTab = -13;
const char vkF1 = -14;
const char vkF2 = -15;
const char vkF3 = -16;
const char vkF4 = -17;
const char vkF5 = -18;
const char vkF6 = -19;
const char vkF7 = -20;
const char vkF8 = -21;
const char vkF9 = -22;
const char vkF10 = -23;
const char vkF11 = -24;
const char vkF12 = -25;
const char vkDelete = -26;
const char vkPrint = -27;
const char vkPause = -29;
class ShellCommandOutputCallbackInterface {
public:
virtual ~ShellCommandOutputCallbackInterface() {}
class ShellCommandOutputCallbackInterface {
public:
virtual ~ShellCommandOutputCallbackInterface() {
}
virtual void * getShellCommandOutput_UserData(string cmd) = 0;
virtual void ShellCommandOutput_CallbackEvent(string cmd,char *output,void *userdata) = 0;
};
virtual void * getShellCommandOutput_UserData(string cmd) = 0;
virtual void ShellCommandOutput_CallbackEvent(string cmd, char *output, void *userdata) = 0;
};
//typedef std::chrono::time_point<std::chrono::system_clock> system_time_point;
tm threadsafe_localtime(const time_t &time);
// extracting std::time_t from std:chrono for "now"
time_t systemtime_now();
//typedef std::chrono::time_point<std::chrono::system_clock> system_time_point;
tm threadsafe_localtime(const time_t &time);
// extracting std::time_t from std:chrono for "now"
time_t systemtime_now();
// =====================================================
// class PerformanceTimer
// =====================================================
// =====================================================
// class PerformanceTimer
// =====================================================
class PerformanceTimer {
private:
Uint32 lastTicks;
Uint32 updateTicks;
class PerformanceTimer {
private:
Uint32 lastTicks;
Uint32 updateTicks;
int times; // number of consecutive times
int maxTimes; // maximum number consecutive times
int times; // number of consecutive times
int maxTimes; // maximum number consecutive times
public:
void init(float fps, int maxTimes= -1);
public:
void init(float fps, int maxTimes = -1);
bool isTime();
void reset();
};
bool isTime();
void reset();
};
// =====================================================
// class Chrono
// =====================================================
// =====================================================
// class Chrono
// =====================================================
class Chrono {
private:
Uint32 startCount;
Uint32 accumCount;
Uint32 freq;
bool stopped;
class Chrono {
private:
Uint32 startCount;
Uint32 accumCount;
Uint32 freq;
bool stopped;
Uint32 lastStartCount;
Uint32 lastTickCount;
int64 lastResult;
int64 lastMultiplier;
bool lastStopped;
Uint32 lastStartCount;
Uint32 lastTickCount;
int64 lastResult;
int64 lastMultiplier;
bool lastStopped;
public:
Chrono(bool autoStart=false);
void start();
void stop();
void reset();
int64 getMicros();
int64 getMillis();
int64 getSeconds();
public:
Chrono(bool autoStart = false);
void start();
void stop();
void reset();
int64 getMicros();
int64 getMillis();
int64 getSeconds();
bool isStarted() const;
static int64 getCurTicks();
static int64 getCurMillis();
bool isStarted() const;
static int64 getCurTicks();
static int64 getCurMillis();
private:
int64 queryCounter(int64 multiplier);
};
private:
int64 queryCounter(int64 multiplier);
};
// =====================================================
// class ModeInfo
// =====================================================
class ModeInfo {
public:
int width;
int height;
int depth;
// =====================================================
// class ModeInfo
// =====================================================
class ModeInfo {
public:
int width;
int height;
int depth;
ModeInfo(int width, int height, int depth);
ModeInfo(int width, int height, int depth);
bool operator< (const ModeInfo &j) const {
if(this->width < j.width) {
return true;
}
else if(this->width == j.width && this->height < j.height) {
return true;
}
else if(this->width == j.width &&
this->height == j.height &&
this->depth < j.depth) {
return true;
bool operator< (const ModeInfo &j) const {
if (this->width < j.width) {
return true;
} else if (this->width == j.width && this->height < j.height) {
return true;
} else if (this->width == j.width &&
this->height == j.height &&
this->depth < j.depth) {
return true;
}
return false;
}
string getString() const;
};
// =====================================================
// Misc
// =====================================================
void Tokenize(const string& str, vector<string>& tokens, const string& delimiters = " ");
bool isdir(const char *path);
bool fileExists(const string &path);
inline bool folderExists(const string &path) {
return isdir(path.c_str());
}
return false;
}
string getString() const;
};
void findDirs(const string &path, vector<string> &results, bool errorOnNotFound, bool keepDuplicates);
void findDirs(const vector<string> &paths, vector<string> &results, bool errorOnNotFound = false, bool keepDuplicates = false);
void findAll(const vector<string> &paths, const string &fileFilter, vector<string> &results, bool cutExtension = false, bool errorOnNotFound = true, bool keepDuplicates = false);
void findAll(const string &path, vector<string> &results, bool cutExtension = false, bool errorOnNotFound = true);
vector<string> getFolderTreeContentsListRecursively(const string &path, const string &filterFileExt, bool includeFolders = false, vector<string> *recursiveMap = NULL);
// =====================================================
// Misc
// =====================================================
void Tokenize(const string& str,vector<string>& tokens,const string& delimiters = " ");
bool isdir(const char *path);
bool fileExists(const string &path);
inline bool folderExists(const string &path) { return isdir(path.c_str()); }
//string getGameVersion();
//string getGameGITVersion();
void setGameVersion(const string &version);
void setGameGITVersion(const string &git);
void findDirs(const string &path, vector<string> &results, bool errorOnNotFound,bool keepDuplicates);
void findDirs(const vector<string> &paths, vector<string> &results, bool errorOnNotFound=false,bool keepDuplicates=false);
void findAll(const vector<string> &paths, const string &fileFilter, vector<string> &results, bool cutExtension=false, bool errorOnNotFound=true,bool keepDuplicates=false);
void findAll(const string &path, vector<string> &results, bool cutExtension=false, bool errorOnNotFound=true);
vector<string> getFolderTreeContentsListRecursively(const string &path, const string &filterFileExt, bool includeFolders=false, vector<string> *recursiveMap=NULL);
string getCRCCacheFilePath();
void setCRCCacheFilePath(const string &path);
//string getGameVersion();
//string getGameGITVersion();
void setGameVersion(const string &version);
void setGameGITVersion(const string &git);
std::pair<string, string> getFolderTreeContentsCheckSumCacheKey(vector<string> paths, const string &pathSearchString, const string &filterFileExt);
void clearFolderTreeContentsCheckSum(vector<string> paths, const string &pathSearchString, const string &filterFileExt);
uint32 getFolderTreeContentsCheckSumRecursively(vector<string> paths, string pathSearchString, const string &filterFileExt, Checksum *recursiveChecksum, bool forceNoCache = false);
time_t getFolderTreeContentsCheckSumRecursivelyLastGenerated(const vector<string> &paths, string pathSearchString, const string &filterFileExt);
string getCRCCacheFilePath();
void setCRCCacheFilePath(const string &path);
std::pair<string, string> getFolderTreeContentsCheckSumCacheKey(const string &path, const string &filterFileExt);
void clearFolderTreeContentsCheckSum(const string &path, const string &filterFileExt);
uint32 getFolderTreeContentsCheckSumRecursively(const string &path, const string &filterFileExt, Checksum *recursiveChecksum, bool forceNoCache = false);
std::pair<string,string> getFolderTreeContentsCheckSumCacheKey(vector<string> paths, const string &pathSearchString, const string &filterFileExt);
void clearFolderTreeContentsCheckSum(vector<string> paths, const string &pathSearchString, const string &filterFileExt);
uint32 getFolderTreeContentsCheckSumRecursively(vector<string> paths, string pathSearchString, const string &filterFileExt, Checksum *recursiveChecksum,bool forceNoCache=false);
time_t getFolderTreeContentsCheckSumRecursivelyLastGenerated(const vector<string> &paths, string pathSearchString, const string &filterFileExt);
std::pair<string, string> getFolderTreeContentsCheckSumListCacheKey(vector<string> paths, const string &pathSearchString, const string &filterFileExt);
void clearFolderTreeContentsCheckSumList(vector<string> paths, const string &pathSearchString, const string &filterFileExt);
vector<std::pair<string, uint32> > getFolderTreeContentsCheckSumListRecursively(vector<string> paths, const string &pathSearchString, const string &filterFileExt, vector<std::pair<string, uint32> > *recursiveMap);
std::pair<string,string> getFolderTreeContentsCheckSumCacheKey(const string &path, const string &filterFileExt);
void clearFolderTreeContentsCheckSum(const string &path, const string &filterFileExt);
uint32 getFolderTreeContentsCheckSumRecursively(const string &path, const string &filterFileExt, Checksum *recursiveChecksum,bool forceNoCache=false);
std::pair<string, string> getFolderTreeContentsCheckSumListCacheKey(const string &path, const string &filterFileExt);
void clearFolderTreeContentsCheckSumList(const string &path, const string &filterFileExt);
vector<std::pair<string, uint32> > getFolderTreeContentsCheckSumListRecursively(const string &path, const string &filterFileExt, vector<std::pair<string, uint32> > *recursiveMap);
std::pair<string,string> getFolderTreeContentsCheckSumListCacheKey(vector<string> paths, const string &pathSearchString, const string &filterFileExt);
void clearFolderTreeContentsCheckSumList(vector<string> paths, const string &pathSearchString, const string &filterFileExt);
vector<std::pair<string,uint32> > getFolderTreeContentsCheckSumListRecursively(vector<string> paths, const string &pathSearchString, const string &filterFileExt, vector<std::pair<string,uint32> > *recursiveMap);
void createDirectoryPaths(string Path);
string extractFileFromDirectoryPath(string filename);
string extractDirectoryPathFromFile(string filename);
string extractLastDirectoryFromPath(string Path);
string extractExtension(const string& filename);
std::pair<string,string> getFolderTreeContentsCheckSumListCacheKey(const string &path, const string &filterFileExt);
void clearFolderTreeContentsCheckSumList(const string &path, const string &filterFileExt);
vector<std::pair<string,uint32> > getFolderTreeContentsCheckSumListRecursively(const string &path, const string &filterFileExt, vector<std::pair<string,uint32> > *recursiveMap);
void getFullscreenVideoModes(vector<ModeInfo> *modeinfos, bool isFullscreen);
void getFullscreenVideoInfo(int &colorBits, int &screenWidth, int &screenHeight, bool isFullscreen);
void changeVideoModeFullScreen(bool value);
void restoreVideoMode(SDL_Window *sdlWindow, bool exitingApp = false);
void createDirectoryPaths(string Path);
string extractFileFromDirectoryPath(string filename);
string extractDirectoryPathFromFile(string filename);
string extractLastDirectoryFromPath(string Path);
string extractExtension(const string& filename);
bool StartsWith(const std::string &str, const std::string &key);
bool EndsWith(const string &str, const string& key);
void getFullscreenVideoModes(vector<ModeInfo> *modeinfos,bool isFullscreen);
void getFullscreenVideoInfo(int &colorBits,int &screenWidth,int &screenHeight,bool isFullscreen);
void changeVideoModeFullScreen(bool value);
void restoreVideoMode(SDL_Window *sdlWindow,bool exitingApp=false);
void endPathWithSlash(string &path, bool requireOSSlash = false);
void trimPathWithStartingSlash(string &path);
void updatePathClimbingParts(string &path, bool processPreviousDirTokenCheck = true);
string formatPath(string path);
bool StartsWith(const std::string &str, const std::string &key);
bool EndsWith(const string &str, const string& key);
string replaceAllHTMLEntities(string& context);
string replaceAll(string& context, const string& from, const string& to);
vector<char> replaceAllBetweenTokens(vector<char>& context, const string &startToken, const string &endToken, const string &newText, bool removeTokens = true);
string replaceAllBetweenTokens(string& context, const string &startToken, const string &endToken, const string &newText, bool removeTokens = true);
bool removeFile(string file);
bool renameFile(string oldFile, string newFile);
void removeFolder(const string &path);
off_t getFileSize(string filename);
bool searchAndReplaceTextInFile(string fileName, string findText, string replaceText, bool simulateOnly);
void copyFileTo(string fromFileName, string toFileName);
void endPathWithSlash(string &path, bool requireOSSlash=false);
void trimPathWithStartingSlash(string &path);
void updatePathClimbingParts(string &path,bool processPreviousDirTokenCheck=true);
string formatPath(string path);
//int getScreenW();
//int getScreenH();
string replaceAllHTMLEntities(string& context);
string replaceAll(string& context, const string& from, const string& to);
vector<char> replaceAllBetweenTokens(vector<char>& context, const string &startToken, const string &endToken, const string &newText, bool removeTokens=true);
string replaceAllBetweenTokens(string& context, const string &startToken, const string &endToken, const string &newText, bool removeTokens=true);
bool removeFile(string file);
bool renameFile(string oldFile, string newFile);
void removeFolder(const string &path);
off_t getFileSize(string filename);
bool searchAndReplaceTextInFile(string fileName, string findText, string replaceText, bool simulateOnly);
void copyFileTo(string fromFileName, string toFileName);
void sleep(int millis);
//int getScreenW();
//int getScreenH();
bool isCursorShowing();
void showCursor(bool b);
bool isKeyDown(int virtualKey);
//bool isKeyDown(SDLKey key);
string getCommandLine();
void sleep(int millis);
bool isCursorShowing();
void showCursor(bool b);
bool isKeyDown(int virtualKey);
//bool isKeyDown(SDLKey key);
string getCommandLine();
string getUserHome();
string getUserHome();
#define SPACES " "
inline string trim_at_delim (const string & s, const string &t) {
string d (s);
string::size_type i(d.find(t));
//printf("Searching for [%s] in [%s] got " MG_SIZE_T_SPECIFIER "\n",t.c_str(),d.c_str(),i);
inline string trim_at_delim(const string & s, const string &t) {
string d(s);
string::size_type i(d.find(t));
//printf("Searching for [%s] in [%s] got " MG_SIZE_T_SPECIFIER "\n",t.c_str(),d.c_str(),i);
if (i == string::npos) {
return d;
}
else {
d = d.erase (i) ;
//printf("returning [%s]\n",d.c_str());
return d;
}
}
if (i == string::npos) {
return d;
} else {
d = d.erase(i);
//printf("returning [%s]\n",d.c_str());
return d;
}
}
inline string trim_right (const string & s, const string & t = SPACES) {
string d (s);
string::size_type i (d.find_last_not_of (t));
if (i == string::npos)
return "";
else
return d.erase (d.find_last_not_of (t) + 1) ;
} // end of trim_right
inline string trim_right(const string & s, const string & t = SPACES) {
string d(s);
string::size_type i(d.find_last_not_of(t));
if (i == string::npos)
return "";
else
return d.erase(d.find_last_not_of(t) + 1);
} // end of trim_right
inline string trim_left (const string & s, const string & t = SPACES) {
string d (s);
return d.erase (0, s.find_first_not_of (t)) ;
} // end of trim_left
inline string trim_left(const string & s, const string & t = SPACES) {
string d(s);
return d.erase(0, s.find_first_not_of(t));
} // end of trim_left
inline string trim (const string & s, const string & t = SPACES) {
string d (s);
return trim_left (trim_right (d, t), t) ;
} // end of trim
inline string trim(const string & s, const string & t = SPACES) {
string d(s);
return trim_left(trim_right(d, t), t);
} // end of trim
string getFullFileArchiveExtractCommand(const string &fileArchiveExtractCommand,
string fileArchiveExtractCommandParameters, const string &outputpath, const string &archivename);
string getFullFileArchiveCompressCommand(const string &fileArchiveCompressCommand,
string fileArchiveCompressCommandParameters, const string &archivename, const string &archivefiles);
string getFullFileArchiveExtractCommand(const string &fileArchiveExtractCommand,
string fileArchiveExtractCommandParameters, const string &outputpath, const string &archivename);
string getFullFileArchiveCompressCommand(const string &fileArchiveCompressCommand,
string fileArchiveCompressCommandParameters, const string &archivename, const string &archivefiles);
bool executeShellCommand(string cmd,int expectedResult=IGNORE_CMD_RESULT_VALUE,ShellCommandOutputCallbackInterface *cb=NULL);
string executable_path(const string &exeName,bool includeExeNameInPath=false);
bool executeShellCommand(string cmd, int expectedResult = IGNORE_CMD_RESULT_VALUE, ShellCommandOutputCallbackInterface *cb = NULL);
string executable_path(const string &exeName, bool includeExeNameInPath = false);
void saveDataToFile(string filename, const string &data);
void saveDataToFile(string filename, const string &data);
bool valid_utf8_file(const char* file_name);
bool valid_utf8_file(const char* file_name);
//string getFileTextContents(string path);
//string getFileTextContents(string path);
string safeCharPtrCopy(const char *ptr, int maxLength=-1);
string safeCharPtrCopy(const char *ptr, int maxLength = -1);
class ValueCheckerVault {
class ValueCheckerVault {
protected:
std::map<const void *,uint32> vaultList;
protected:
std::map<const void *, uint32> vaultList;
void addItemToVault(const void *ptr,int value);
void checkItemInVault(const void *ptr,int value) const;
void addItemToVault(const void *ptr, int value);
void checkItemInVault(const void *ptr, int value) const;
public:
ValueCheckerVault() {
vaultList.clear();
}
};
public:
ValueCheckerVault() {
vaultList.clear();
}
};
}}//end namespace
}//end namespace
#endif

View File

@@ -22,153 +22,166 @@ using namespace std;
using namespace Shared::Util;
using namespace Shared::Graphics;
namespace Shared { namespace PlatformCommon {
namespace Shared {
namespace PlatformCommon {
//
// This interface describes the methods a callback object must implement
//
class FileCRCPreCacheThreadCallbackInterface {
public:
virtual vector<Texture2D *> processTech(string techName) = 0;
virtual ~FileCRCPreCacheThreadCallbackInterface() {}
};
//
// This interface describes the methods a callback object must implement
//
class FileCRCPreCacheThreadCallbackInterface {
public:
virtual vector<Texture2D *> processTech(string techName) = 0;
virtual ~FileCRCPreCacheThreadCallbackInterface() {
}
};
// =====================================================
// class FileCRCPreCacheThread
// =====================================================
// =====================================================
// class FileCRCPreCacheThread
// =====================================================
class FileCRCPreCacheThread : public BaseThread
{
protected:
vector<string> techDataPaths;
vector<string> workerThreadTechPaths;
FileCRCPreCacheThreadCallbackInterface *processTechCB;
class FileCRCPreCacheThread : public BaseThread {
protected:
vector<string> techDataPaths;
vector<string> workerThreadTechPaths;
FileCRCPreCacheThreadCallbackInterface *processTechCB;
static string preCacheThreadCacheLookupKey;
Mutex *mutexPauseForGame;
bool pauseForGame;
std::vector<FileCRCPreCacheThread *> preCacheWorkerThreadList;
static string preCacheThreadCacheLookupKey;
Mutex *mutexPauseForGame;
bool pauseForGame;
std::vector<FileCRCPreCacheThread *> preCacheWorkerThreadList;
public:
FileCRCPreCacheThread();
FileCRCPreCacheThread(vector<string> techDataPaths,vector<string> workerThreadTechPaths,FileCRCPreCacheThreadCallbackInterface *processTechCB);
virtual ~FileCRCPreCacheThread();
public:
FileCRCPreCacheThread();
FileCRCPreCacheThread(vector<string> techDataPaths, vector<string> workerThreadTechPaths, FileCRCPreCacheThreadCallbackInterface *processTechCB);
virtual ~FileCRCPreCacheThread();
static void setPreCacheThreadCacheLookupKey(string value) { preCacheThreadCacheLookupKey = value; }
static void setPreCacheThreadCacheLookupKey(string value) {
preCacheThreadCacheLookupKey = value;
}
virtual void execute();
void setTechDataPaths(vector<string> value) { this->techDataPaths = value; }
void setWorkerThreadTechPaths(vector<string> value) { this->workerThreadTechPaths = value; }
void setFileCRCPreCacheThreadCallbackInterface(FileCRCPreCacheThreadCallbackInterface *value) { processTechCB = value; }
virtual void execute();
void setTechDataPaths(vector<string> value) {
this->techDataPaths = value;
}
void setWorkerThreadTechPaths(vector<string> value) {
this->workerThreadTechPaths = value;
}
void setFileCRCPreCacheThreadCallbackInterface(FileCRCPreCacheThreadCallbackInterface *value) {
processTechCB = value;
}
virtual bool canShutdown(bool deleteSelfIfShutdownDelayed);
virtual bool canShutdown(bool deleteSelfIfShutdownDelayed);
void setPauseForGame(bool pauseForGame);
bool getPauseForGame();
};
void setPauseForGame(bool pauseForGame);
bool getPauseForGame();
};
// =====================================================
// class SimpleTaskThread
// =====================================================
typedef void taskFunctionCallback(BaseThread *callingThread);
//
// This interface describes the methods a callback object must implement
//
class SimpleTaskCallbackInterface {
public:
virtual void simpleTask(BaseThread *callingThread,void *userdata) = 0;
// =====================================================
// class SimpleTaskThread
// =====================================================
typedef void taskFunctionCallback(BaseThread *callingThread);
//
// This interface describes the methods a callback object must implement
//
class SimpleTaskCallbackInterface {
public:
virtual void simpleTask(BaseThread *callingThread, void *userdata) = 0;
virtual void setupTask(BaseThread *callingThread,void *userdata) { }
virtual void shutdownTask(BaseThread *callingThread,void *userdata) { }
virtual void setupTask(BaseThread *callingThread, void *userdata) {
}
virtual void shutdownTask(BaseThread *callingThread, void *userdata) {
}
virtual ~SimpleTaskCallbackInterface() {}
};
virtual ~SimpleTaskCallbackInterface() {
}
};
class SimpleTaskThread : public BaseThread
{
protected:
class SimpleTaskThread : public BaseThread {
protected:
Mutex *mutexSimpleTaskInterfaceValid;
bool simpleTaskInterfaceValid;
SimpleTaskCallbackInterface *simpleTaskInterface;
unsigned int executionCount;
unsigned int millisecsBetweenExecutions;
Mutex *mutexSimpleTaskInterfaceValid;
bool simpleTaskInterfaceValid;
SimpleTaskCallbackInterface *simpleTaskInterface;
unsigned int executionCount;
unsigned int millisecsBetweenExecutions;
Mutex *mutexTaskSignaller;
bool taskSignalled;
bool needTaskSignal;
Mutex *mutexTaskSignaller;
bool taskSignalled;
bool needTaskSignal;
Mutex *mutexLastExecuteTimestamp;
time_t lastExecuteTimestamp;
Mutex *mutexLastExecuteTimestamp;
time_t lastExecuteTimestamp;
taskFunctionCallback *overrideShutdownTask;
void *userdata;
bool wantSetupAndShutdown;
taskFunctionCallback *overrideShutdownTask;
void *userdata;
bool wantSetupAndShutdown;
public:
SimpleTaskThread(SimpleTaskCallbackInterface *simpleTaskInterface,
unsigned int executionCount=0,
unsigned int millisecsBetweenExecutions=0,
bool needTaskSignal = false,
void *userdata=NULL,
bool wantSetupAndShutdown=true);
virtual ~SimpleTaskThread();
public:
SimpleTaskThread(SimpleTaskCallbackInterface *simpleTaskInterface,
unsigned int executionCount = 0,
unsigned int millisecsBetweenExecutions = 0,
bool needTaskSignal = false,
void *userdata = NULL,
bool wantSetupAndShutdown = true);
virtual ~SimpleTaskThread();
virtual void * getUserdata() {
return userdata;
}
virtual int getUserdataAsInt() {
int value = 0;
if (userdata) {
value = *((int*) &userdata);
}
return value;
}
virtual void execute();
virtual bool canShutdown(bool deleteSelfIfShutdownDelayed = false);
void setTaskSignalled(bool value);
bool getTaskSignalled();
bool isThreadExecutionLagging();
void cleanup();
void setOverrideShutdownTask(taskFunctionCallback *ptr);
bool getSimpleTaskInterfaceValid();
void setSimpleTaskInterfaceValid(bool value);
};
// =====================================================
// class LogFileThread
// =====================================================
class LogFileEntry {
public:
SystemFlags::DebugType type;
string entry;
time_t entryDateTime;
};
class LogFileThread : public BaseThread {
protected:
Mutex *mutexLogList;
vector<LogFileEntry> logList;
time_t lastSaveToDisk;
void saveToDisk(bool forceSaveAll, bool logListAlreadyLocked);
bool checkSaveCurrentLogBufferToDisk();
public:
LogFileThread();
virtual ~LogFileThread();
virtual void execute();
void addLogEntry(SystemFlags::DebugType type, string logEntry);
std::size_t getLogEntryBufferCount();
virtual bool canShutdown(bool deleteSelfIfShutdownDelayed = false);
};
virtual void * getUserdata() { return userdata; }
virtual int getUserdataAsInt() {
int value = 0;
if(userdata) {
value = *((int*)&userdata);
}
return value;
}
virtual void execute();
virtual bool canShutdown(bool deleteSelfIfShutdownDelayed=false);
void setTaskSignalled(bool value);
bool getTaskSignalled();
bool isThreadExecutionLagging();
void cleanup();
void setOverrideShutdownTask(taskFunctionCallback *ptr);
bool getSimpleTaskInterfaceValid();
void setSimpleTaskInterfaceValid(bool value);
};
// =====================================================
// class LogFileThread
// =====================================================
class LogFileEntry {
public:
SystemFlags::DebugType type;
string entry;
time_t entryDateTime;
};
class LogFileThread : public BaseThread
{
protected:
Mutex *mutexLogList;
vector<LogFileEntry> logList;
time_t lastSaveToDisk;
void saveToDisk(bool forceSaveAll,bool logListAlreadyLocked);
bool checkSaveCurrentLogBufferToDisk();
public:
LogFileThread();
virtual ~LogFileThread();
virtual void execute();
void addLogEntry(SystemFlags::DebugType type, string logEntry);
std::size_t getLogEntryBufferCount();
virtual bool canShutdown(bool deleteSelfIfShutdownDelayed=false);
};
}}//end namespace
}//end namespace
#endif

View File

@@ -49,7 +49,7 @@ namespace math {
using std::exp;
using std::frexp;
using std::ldexp;
// the following are C99 functions -> not supported by VS C
// the following are C99 functions -> not supported by VS C
#if !defined(_MSC_VER) || _MSC_VER < 1500
using std::isnan;
using std::isinf;