Namespace ST for global vars

This commit is contained in:
Vladislav Khorev 2013-02-21 13:14:46 +00:00
parent 61ada33ee1
commit 7d8bcec025
14 changed files with 58 additions and 94 deletions

View File

@ -51,15 +51,6 @@ class TResourceManager
{ {
protected: protected:
public: public:
std::string PathToResources;
boost::thread::id MainThreadId;
//std::vector<boost::function<void()>> MainThreadAsyncFunctionArr;
//boost::mutex FuncListMutex;
//std::list<TFuncToPerform> MainThreadSyncFunctionList;
TTextureListClass TexList; TTextureListClass TexList;
TModelManager ModelManager; TModelManager ModelManager;
TFlexModelManager FlexModelManager; TFlexModelManager FlexModelManager;

View File

@ -26,6 +26,13 @@ WINDOWS AND ANDROID
namespace SE namespace SE
{ {
namespace ST
{
extern std::string PathToResources;
}
bool findString(char* in, char* list); bool findString(char* in, char* list);
//utility for opengl extensions parsing. Not safe //utility for opengl extensions parsing. Not safe
@ -243,7 +250,7 @@ std::string GetFilePath(const std::string& filename);
//Special for IOS, because Foundation.h conflicts with sq_plus.h //Special for IOS, because Foundation.h conflicts with sq_plus.h
// Obviously, this returns ResourceManager->PathToResources // Obviously, this returns ST::PathToResources
std::string GetPathToResources(); std::string GetPathToResources();
#endif #endif

View File

@ -9,7 +9,12 @@
namespace SE namespace SE
{ {
extern boost::asio::io_service MainThreadIoService; namespace ST
{
extern boost::asio::io_service MainThreadIoService;
extern boost::thread::id MainThreadId;
}
#ifndef UTILS_ENGINE #ifndef UTILS_ENGINE

View File

@ -10,34 +10,7 @@ namespace SE
template<typename RETURNTYPE> template<typename RETURNTYPE>
RETURNTYPE PerformInMainThread(boost::function<RETURNTYPE()> f) RETURNTYPE PerformInMainThread(boost::function<RETURNTYPE()> f)
{ {
/* if (boost::this_thread::get_id() == ST::MainThreadId)
if (boost::this_thread::get_id() == ResourceManager->MainThreadId)
{
return f();
}
else
{
RETURNTYPE result;
boost::mutex ServiceLock;
ServiceLock.lock();
boost::function<void()> cover_f = [&result, &ServiceLock, f]()
{
result = f();
ServiceLock.unlock();
};
MainThreadIoService.post(cover_f);
ServiceLock.lock();
ServiceLock.unlock();
return result;
}*/
if (boost::this_thread::get_id() == ResourceManager->MainThreadId)
{ {
return f(); return f();
} }
@ -56,7 +29,7 @@ namespace SE
serviceLock.lock(); serviceLock.lock();
MainThreadIoService.post(func); ST::MainThreadIoService.post(func);
serviceLock.lock(); serviceLock.lock();
serviceLock.unlock(); serviceLock.unlock();

View File

@ -155,7 +155,7 @@ bool TAnimList::LoadBoneSystemFromFileBn1(const std::string& fileName)
int i; int i;
cardinal fSize; cardinal fSize;
boost::shared_array<cardinal> fileData = CreateMemFromFile<cardinal>(ResourceManager->PathToResources+fileName,fSize); boost::shared_array<cardinal> fileData = CreateMemFromFile<cardinal>(ST::PathToResources+fileName,fSize);
@ -238,7 +238,7 @@ bool TAnimList::LoadBoneSystemFromFileBn2(const std::string& fileName)
int i; int i;
cardinal fSize; cardinal fSize;
boost::shared_array<cardinal> fileData = CreateMemFromFile<cardinal>(ResourceManager->PathToResources+fileName,fSize); boost::shared_array<cardinal> fileData = CreateMemFromFile<cardinal>(ST::PathToResources+fileName,fSize);
if (fileData == NULL) if (fileData == NULL)
throw ErrorFileNotLoaded(fileName); throw ErrorFileNotLoaded(fileName);
@ -330,7 +330,7 @@ bool TAnimList::LoadAnimSequenceFromFileAn1(const std::string& fileName)
if (AnimSequenceMap.count(shortFileName) == 0) if (AnimSequenceMap.count(shortFileName) == 0)
{ {
TAnimSequence animSeqience; TAnimSequence animSeqience;
if (animSeqience.LoadFromFileAn1(ResourceManager->PathToResources+fileName)) if (animSeqience.LoadFromFileAn1(ST::PathToResources+fileName))
{ {
AnimSequenceMap[shortFileName] = animSeqience; AnimSequenceMap[shortFileName] = animSeqience;
return true; return true;

View File

@ -52,7 +52,7 @@ void TFontManager::AddFont(const std::string& fontName, const std::string& bitma
cardinal byteCount; cardinal byteCount;
boost::shared_array<char> charmapFileArr = boost::shared_array<char>(CreateMemFromFile<char>(ResourceManager->PathToResources+charmapFile, byteCount)); boost::shared_array<char> charmapFileArr = boost::shared_array<char>(CreateMemFromFile<char>(ST::PathToResources+charmapFile, byteCount));
//Need to rewrite this code :( //Need to rewrite this code :(

View File

@ -333,13 +333,13 @@ bool TModelManager::AddLiteModel(const std::string& filename, const std::string&
if (LiteModelMap.count(modelName) != 0) if (LiteModelMap.count(modelName) != 0)
return true; return true;
boost::shared_array<byte> fileArr = CreateMemFromFile<byte>((ResourceManager->PathToResources + filename), fileSize); boost::shared_array<byte> fileArr = CreateMemFromFile<byte>((ST::PathToResources + filename), fileSize);
if (!(fileArr[0] == 'L' && fileArr[1] == 'M' && fileArr[2] == 0 && fileArr[3] == 1)) if (!(fileArr[0] == 'L' && fileArr[1] == 'M' && fileArr[2] == 0 && fileArr[3] == 1))
throw ErrorFileNotCorrect(filename); throw ErrorFileNotCorrect(filename);
LiteModelMap[modelName].SetPathToResource(GetFilePath(ResourceManager->PathToResources + filename)); LiteModelMap[modelName].SetPathToResource(GetFilePath(ST::PathToResources + filename));
bool result = LiteModelMap[modelName].LoadModel(fileArr, fileSize); bool result = LiteModelMap[modelName].LoadModel(fileArr, fileSize);

View File

@ -25,36 +25,13 @@ TResourceManager* ResourceManager;
void TResourceManager::Update(cardinal timer) void TResourceManager::Update(cardinal timer)
{ {
//FuncListMutex.lock();
SoundManager.Update(timer); SoundManager.Update(timer);
GUIManager.Update(timer); GUIManager.Update(timer);
/*
if (MainThreadAsyncFunctionArr.size() != 0)
{
MainThreadAsyncFunctionArr[0]();
MainThreadAsyncFunctionArr.erase(MainThreadAsyncFunctionArr.begin()); ST::MainThreadIoService.run();
}
auto itr = MainThreadSyncFunctionList.begin(); ST::MainThreadIoService.reset();
while (itr != MainThreadSyncFunctionList.end() && itr->Executed)
{
itr++;
}
if (itr != MainThreadSyncFunctionList.end())
{
itr->Func();
itr->Executed = true;
itr->LockerPtr->unlock();
}
FuncListMutex.unlock();*/
MainThreadIoService.run();
MainThreadIoService.reset();
} }
TResourceManager::~TResourceManager() TResourceManager::~TResourceManager()
@ -77,7 +54,7 @@ TApplicationAncestor::~TApplicationAncestor()
void TApplicationAncestor::OuterInit(int screenWidth, int screenHeight, float matrixWidth, float matrixHeight) void TApplicationAncestor::OuterInit(int screenWidth, int screenHeight, float matrixWidth, float matrixHeight)
{ {
ResourceManager->MainThreadId = boost::this_thread::get_id(); ST::MainThreadId = boost::this_thread::get_id();
ResourceManager->ScriptManager.BindBasicFunctions(); ResourceManager->ScriptManager.BindBasicFunctions();

View File

@ -202,7 +202,7 @@ void TShaderManager::Serialize(boost::property_tree::ptree& propertyTree)
bool TShaderManager::AddShader(const std::string& shaderName, const std::string& vertexFileName, const std::string& fragmentFileName) bool TShaderManager::AddShader(const std::string& shaderName, const std::string& vertexFileName, const std::string& fragmentFileName)
{ {
std::string pathToResources = ResourceManager->PathToResources; std::string pathToResources = ST::PathToResources;
if (ShaderList.count(shaderName) > 0) if (ShaderList.count(shaderName) > 0)
{ {

View File

@ -238,7 +238,7 @@ bool TSimpleLandClass::LoadFromFile(const std::string& filename)
{ {
cardinal dwordCount; cardinal dwordCount;
boost::shared_array<cardinal> fileArr = CreateMemFromFile<cardinal>((ResourceManager->PathToResources + filename).c_str(), dwordCount); boost::shared_array<cardinal> fileArr = CreateMemFromFile<cardinal>((ST::PathToResources + filename).c_str(), dwordCount);
if ((((char*)&fileArr[0])[0]!='L')|| if ((((char*)&fileArr[0])[0]!='L')||
(((char*)&fileArr[0])[1]!='S')|| (((char*)&fileArr[0])[1]!='S')||

View File

@ -735,7 +735,7 @@ cardinal TTextureListClass::AddTexture(const std::string& fileName)
cardinal TTextureListClass::AddTexture(const std::string& fileName, std::string texName) cardinal TTextureListClass::AddTexture(const std::string& fileName, std::string texName)
{ {
std::string fullFileName = ResourceManager->PathToResources + fileName; std::string fullFileName = ST::PathToResources + fileName;
return AddTextureDirectly(fullFileName, texName); return AddTextureDirectly(fullFileName, texName);
} }
@ -758,12 +758,12 @@ cardinal TTextureListClass::AddTextureFromUserdata(const std::string& fileName,
cardinal TTextureListClass::AddCubemapTexture(std::string filename[6]) cardinal TTextureListClass::AddCubemapTexture(std::string filename[6])
{ {
filename[0] = ResourceManager->PathToResources + filename[0]; filename[0] = ST::PathToResources + filename[0];
filename[1] = ResourceManager->PathToResources + filename[1]; filename[1] = ST::PathToResources + filename[1];
filename[2] = ResourceManager->PathToResources + filename[2]; filename[2] = ST::PathToResources + filename[2];
filename[3] = ResourceManager->PathToResources + filename[3]; filename[3] = ST::PathToResources + filename[3];
filename[4] = ResourceManager->PathToResources + filename[4]; filename[4] = ST::PathToResources + filename[4];
filename[5] = ResourceManager->PathToResources + filename[5]; filename[5] = ST::PathToResources + filename[5];
std::string texname = GetFileName(filename[0]); std::string texname = GetFileName(filename[0]);
std::string texext; std::string texext;

View File

@ -9,6 +9,13 @@
namespace SE namespace SE
{ {
namespace ST
{
std::string PathToResources;
}
bool findString(char* in, char* list) bool findString(char* in, char* list)
{ {
int thisLength = strlen(in); int thisLength = strlen(in);
@ -82,7 +89,7 @@ std::string GetFilePathUserData(const std::string& filename)
//Special for IOS -> Foundation.h conflicts with sq_plus.h //Special for IOS -> Foundation.h conflicts with sq_plus.h
std::string GetPathToResources() std::string GetPathToResources()
{ {
return ResourceManager->PathToResources; return ST::PathToResources;
} }
#endif #endif

View File

@ -56,7 +56,7 @@ boost::property_tree::ptree::iterator ReplaceIncludeFile(boost::property_tree::p
#ifdef UTILS_ENGINE #ifdef UTILS_ENGINE
xmlFileArr = CreateMemFromFile<char>(fileName, xmlFileSize); xmlFileArr = CreateMemFromFile<char>(fileName, xmlFileSize);
#else #else
xmlFileArr = CreateMemFromFile<char>(ResourceManager->PathToResources + fileName, xmlFileSize); xmlFileArr = CreateMemFromFile<char>(ST::PathToResources + fileName, xmlFileSize);
#endif #endif
std::string xmlString = std::string(&xmlFileArr[0], &xmlFileArr[xmlFileSize]); std::string xmlString = std::string(&xmlFileArr[0], &xmlFileArr[xmlFileSize]);
@ -150,7 +150,7 @@ std::shared_ptr<boost::property_tree::ptree> FileToPropertyTree(const std::strin
#ifdef UTILS_ENGINE #ifdef UTILS_ENGINE
boost::shared_array<char> file = CreateMemFromFile<char>(fileName, byteCount); boost::shared_array<char> file = CreateMemFromFile<char>(fileName, byteCount);
#else #else
boost::shared_array<char> file = CreateMemFromFile<char>(ResourceManager->PathToResources + fileName, byteCount); boost::shared_array<char> file = CreateMemFromFile<char>(ST::PathToResources + fileName, byteCount);
#endif #endif
return FileToPropertyTree(file, byteCount, replaceMap); return FileToPropertyTree(file, byteCount, replaceMap);

View File

@ -3,12 +3,16 @@
namespace SE namespace SE
{ {
boost::asio::io_service MainThreadIoService; namespace ST
{
boost::asio::io_service MainThreadIoService;
boost::thread::id MainThreadId;
}
#ifndef UTILS_ENGINE #ifndef UTILS_ENGINE
void AssertIfInMainThread() void AssertIfInMainThread()
{ {
if (boost::this_thread::get_id() != ResourceManager->MainThreadId) if (boost::this_thread::get_id() != ST::MainThreadId)
{ {
throw ErrorToLog("ERROR! AssertIfInMainThread - assert failed!"); throw ErrorToLog("ERROR! AssertIfInMainThread - assert failed!");
} }
@ -16,16 +20,16 @@ namespace SE
void TryUpdateMainThreadId() void TryUpdateMainThreadId()
{ {
if (boost::this_thread::get_id() != ResourceManager->MainThreadId) if (boost::this_thread::get_id() != ST::MainThreadId)
{ {
ResourceManager->MainThreadId = boost::this_thread::get_id(); ST::MainThreadId = boost::this_thread::get_id();
} }
} }
void PerformInMainThreadAsync(boost::function<void()> f) void PerformInMainThreadAsync(boost::function<void()> f)
{ {
if (boost::this_thread::get_id() == ResourceManager->MainThreadId) if (boost::this_thread::get_id() == ST::MainThreadId)
{ {
f(); f();
} }
@ -43,7 +47,7 @@ namespace SE
serviceLock.lock(); serviceLock.lock();
MainThreadIoService.post(func); ST::MainThreadIoService.post(func);
serviceLock.lock(); serviceLock.lock();
serviceLock.unlock(); serviceLock.unlock();