diff --git a/include/SalmonEngineInterface.h b/include/SalmonEngineInterface.h index b77c955..1cecf15 100644 --- a/include/SalmonEngineInterface.h +++ b/include/SalmonEngineInterface.h @@ -51,15 +51,6 @@ class TResourceManager { protected: public: - std::string PathToResources; - - boost::thread::id MainThreadId; - - //std::vector> MainThreadAsyncFunctionArr; - - //boost::mutex FuncListMutex; - //std::list MainThreadSyncFunctionList; - TTextureListClass TexList; TModelManager ModelManager; TFlexModelManager FlexModelManager; diff --git a/include/Utils/FileUtils/FileUtils.h b/include/Utils/FileUtils/FileUtils.h index 0fb64eb..d607a0a 100644 --- a/include/Utils/FileUtils/FileUtils.h +++ b/include/Utils/FileUtils/FileUtils.h @@ -25,6 +25,13 @@ WINDOWS AND ANDROID namespace SE { + +namespace ST +{ + + extern std::string PathToResources; + +} bool findString(char* in, char* list); //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 -// Obviously, this returns ResourceManager->PathToResources +// Obviously, this returns ST::PathToResources std::string GetPathToResources(); #endif diff --git a/include/Utils/ThreadUtils.h b/include/Utils/ThreadUtils.h index 2013977..1048011 100644 --- a/include/Utils/ThreadUtils.h +++ b/include/Utils/ThreadUtils.h @@ -8,8 +8,13 @@ namespace SE { - - extern boost::asio::io_service MainThreadIoService; + + namespace ST + { + extern boost::asio::io_service MainThreadIoService; + + extern boost::thread::id MainThreadId; + } #ifndef UTILS_ENGINE diff --git a/include/Utils/ThreadUtilsImpl.h b/include/Utils/ThreadUtilsImpl.h index 45d1823..f2944a6 100644 --- a/include/Utils/ThreadUtilsImpl.h +++ b/include/Utils/ThreadUtilsImpl.h @@ -10,34 +10,7 @@ namespace SE template RETURNTYPE PerformInMainThread(boost::function f) { - /* - if (boost::this_thread::get_id() == ResourceManager->MainThreadId) - { - return f(); - } - else - { - RETURNTYPE result; - - boost::mutex ServiceLock; - - ServiceLock.lock(); - - boost::function 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) + if (boost::this_thread::get_id() == ST::MainThreadId) { return f(); } @@ -56,7 +29,7 @@ namespace SE serviceLock.lock(); - MainThreadIoService.post(func); + ST::MainThreadIoService.post(func); serviceLock.lock(); serviceLock.unlock(); diff --git a/src/Animation/SalmonAnimation.cpp b/src/Animation/SalmonAnimation.cpp index 92129a2..411cc4d 100644 --- a/src/Animation/SalmonAnimation.cpp +++ b/src/Animation/SalmonAnimation.cpp @@ -155,7 +155,7 @@ bool TAnimList::LoadBoneSystemFromFileBn1(const std::string& fileName) int i; cardinal fSize; - boost::shared_array fileData = CreateMemFromFile(ResourceManager->PathToResources+fileName,fSize); + boost::shared_array fileData = CreateMemFromFile(ST::PathToResources+fileName,fSize); @@ -238,7 +238,7 @@ bool TAnimList::LoadBoneSystemFromFileBn2(const std::string& fileName) int i; cardinal fSize; - boost::shared_array fileData = CreateMemFromFile(ResourceManager->PathToResources+fileName,fSize); + boost::shared_array fileData = CreateMemFromFile(ST::PathToResources+fileName,fSize); if (fileData == NULL) throw ErrorFileNotLoaded(fileName); @@ -330,7 +330,7 @@ bool TAnimList::LoadAnimSequenceFromFileAn1(const std::string& fileName) if (AnimSequenceMap.count(shortFileName) == 0) { TAnimSequence animSeqience; - if (animSeqience.LoadFromFileAn1(ResourceManager->PathToResources+fileName)) + if (animSeqience.LoadFromFileAn1(ST::PathToResources+fileName)) { AnimSequenceMap[shortFileName] = animSeqience; return true; diff --git a/src/FontManager/FontManager.cpp b/src/FontManager/FontManager.cpp index f4dad07..2d9efbc 100644 --- a/src/FontManager/FontManager.cpp +++ b/src/FontManager/FontManager.cpp @@ -52,7 +52,7 @@ void TFontManager::AddFont(const std::string& fontName, const std::string& bitma cardinal byteCount; - boost::shared_array charmapFileArr = boost::shared_array(CreateMemFromFile(ResourceManager->PathToResources+charmapFile, byteCount)); + boost::shared_array charmapFileArr = boost::shared_array(CreateMemFromFile(ST::PathToResources+charmapFile, byteCount)); //Need to rewrite this code :( diff --git a/src/ModelManager/ModelManager.cpp b/src/ModelManager/ModelManager.cpp index 6510a52..27dabaa 100644 --- a/src/ModelManager/ModelManager.cpp +++ b/src/ModelManager/ModelManager.cpp @@ -333,13 +333,13 @@ bool TModelManager::AddLiteModel(const std::string& filename, const std::string& if (LiteModelMap.count(modelName) != 0) return true; - boost::shared_array fileArr = CreateMemFromFile((ResourceManager->PathToResources + filename), fileSize); + boost::shared_array fileArr = CreateMemFromFile((ST::PathToResources + filename), fileSize); if (!(fileArr[0] == 'L' && fileArr[1] == 'M' && fileArr[2] == 0 && fileArr[3] == 1)) throw ErrorFileNotCorrect(filename); - LiteModelMap[modelName].SetPathToResource(GetFilePath(ResourceManager->PathToResources + filename)); + LiteModelMap[modelName].SetPathToResource(GetFilePath(ST::PathToResources + filename)); bool result = LiteModelMap[modelName].LoadModel(fileArr, fileSize); diff --git a/src/SalmonEngineInterface.cpp b/src/SalmonEngineInterface.cpp index 4fa88ea..5a6d16e 100644 --- a/src/SalmonEngineInterface.cpp +++ b/src/SalmonEngineInterface.cpp @@ -25,36 +25,13 @@ TResourceManager* ResourceManager; void TResourceManager::Update(cardinal timer) { - //FuncListMutex.lock(); - SoundManager.Update(timer); GUIManager.Update(timer); - /* - if (MainThreadAsyncFunctionArr.size() != 0) - { - MainThreadAsyncFunctionArr[0](); - - MainThreadAsyncFunctionArr.erase(MainThreadAsyncFunctionArr.begin()); - } - - auto itr = MainThreadSyncFunctionList.begin(); - - while (itr != MainThreadSyncFunctionList.end() && itr->Executed) - { - itr++; - } - - if (itr != MainThreadSyncFunctionList.end()) - { - itr->Func(); - itr->Executed = true; - itr->LockerPtr->unlock(); - } + + ST::MainThreadIoService.run(); - FuncListMutex.unlock();*/ - MainThreadIoService.run(); - MainThreadIoService.reset(); + ST::MainThreadIoService.reset(); } TResourceManager::~TResourceManager() @@ -77,7 +54,7 @@ TApplicationAncestor::~TApplicationAncestor() 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(); diff --git a/src/ShaderManager/ShaderManager.cpp b/src/ShaderManager/ShaderManager.cpp index 96ce1c2..3ee6930 100644 --- a/src/ShaderManager/ShaderManager.cpp +++ b/src/ShaderManager/ShaderManager.cpp @@ -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) { - std::string pathToResources = ResourceManager->PathToResources; + std::string pathToResources = ST::PathToResources; if (ShaderList.count(shaderName) > 0) { diff --git a/src/SimpleLand/SimpleLand.cpp b/src/SimpleLand/SimpleLand.cpp index 214aaa7..41a3954 100644 --- a/src/SimpleLand/SimpleLand.cpp +++ b/src/SimpleLand/SimpleLand.cpp @@ -238,7 +238,7 @@ bool TSimpleLandClass::LoadFromFile(const std::string& filename) { cardinal dwordCount; - boost::shared_array fileArr = CreateMemFromFile((ResourceManager->PathToResources + filename).c_str(), dwordCount); + boost::shared_array fileArr = CreateMemFromFile((ST::PathToResources + filename).c_str(), dwordCount); if ((((char*)&fileArr[0])[0]!='L')|| (((char*)&fileArr[0])[1]!='S')|| diff --git a/src/TextureManager/SalmonTexture.cpp b/src/TextureManager/SalmonTexture.cpp index 0026a26..1ac84fb 100644 --- a/src/TextureManager/SalmonTexture.cpp +++ b/src/TextureManager/SalmonTexture.cpp @@ -735,7 +735,7 @@ cardinal TTextureListClass::AddTexture(const std::string& fileName) 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); } @@ -758,12 +758,12 @@ cardinal TTextureListClass::AddTextureFromUserdata(const std::string& fileName, cardinal TTextureListClass::AddCubemapTexture(std::string filename[6]) { - filename[0] = ResourceManager->PathToResources + filename[0]; - filename[1] = ResourceManager->PathToResources + filename[1]; - filename[2] = ResourceManager->PathToResources + filename[2]; - filename[3] = ResourceManager->PathToResources + filename[3]; - filename[4] = ResourceManager->PathToResources + filename[4]; - filename[5] = ResourceManager->PathToResources + filename[5]; + filename[0] = ST::PathToResources + filename[0]; + filename[1] = ST::PathToResources + filename[1]; + filename[2] = ST::PathToResources + filename[2]; + filename[3] = ST::PathToResources + filename[3]; + filename[4] = ST::PathToResources + filename[4]; + filename[5] = ST::PathToResources + filename[5]; std::string texname = GetFileName(filename[0]); std::string texext; diff --git a/src/Utils/FileUtils/FileUtils.cpp b/src/Utils/FileUtils/FileUtils.cpp index 485ddbd..ede7022 100644 --- a/src/Utils/FileUtils/FileUtils.cpp +++ b/src/Utils/FileUtils/FileUtils.cpp @@ -8,6 +8,13 @@ namespace SE { + + namespace ST + { + + std::string PathToResources; + + } bool findString(char* in, char* list) { @@ -82,7 +89,7 @@ std::string GetFilePathUserData(const std::string& filename) //Special for IOS -> Foundation.h conflicts with sq_plus.h std::string GetPathToResources() { - return ResourceManager->PathToResources; + return ST::PathToResources; } #endif diff --git a/src/Utils/SerializeInterface/SerializeInterface.cpp b/src/Utils/SerializeInterface/SerializeInterface.cpp index 8927ad7..2786c44 100644 --- a/src/Utils/SerializeInterface/SerializeInterface.cpp +++ b/src/Utils/SerializeInterface/SerializeInterface.cpp @@ -56,7 +56,7 @@ boost::property_tree::ptree::iterator ReplaceIncludeFile(boost::property_tree::p #ifdef UTILS_ENGINE xmlFileArr = CreateMemFromFile(fileName, xmlFileSize); #else - xmlFileArr = CreateMemFromFile(ResourceManager->PathToResources + fileName, xmlFileSize); + xmlFileArr = CreateMemFromFile(ST::PathToResources + fileName, xmlFileSize); #endif std::string xmlString = std::string(&xmlFileArr[0], &xmlFileArr[xmlFileSize]); @@ -150,7 +150,7 @@ std::shared_ptr FileToPropertyTree(const std::strin #ifdef UTILS_ENGINE boost::shared_array file = CreateMemFromFile(fileName, byteCount); #else - boost::shared_array file = CreateMemFromFile(ResourceManager->PathToResources + fileName, byteCount); + boost::shared_array file = CreateMemFromFile(ST::PathToResources + fileName, byteCount); #endif return FileToPropertyTree(file, byteCount, replaceMap); diff --git a/src/Utils/ThreadUtils.cpp b/src/Utils/ThreadUtils.cpp index c1392e3..30a303b 100644 --- a/src/Utils/ThreadUtils.cpp +++ b/src/Utils/ThreadUtils.cpp @@ -2,13 +2,17 @@ namespace SE { - - boost::asio::io_service MainThreadIoService; - + + namespace ST + { + boost::asio::io_service MainThreadIoService; + + boost::thread::id MainThreadId; + } #ifndef UTILS_ENGINE void AssertIfInMainThread() { - if (boost::this_thread::get_id() != ResourceManager->MainThreadId) + if (boost::this_thread::get_id() != ST::MainThreadId) { throw ErrorToLog("ERROR! AssertIfInMainThread - assert failed!"); } @@ -16,16 +20,16 @@ namespace SE 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 f) { - if (boost::this_thread::get_id() == ResourceManager->MainThreadId) + if (boost::this_thread::get_id() == ST::MainThreadId) { f(); } @@ -43,7 +47,7 @@ namespace SE serviceLock.lock(); - MainThreadIoService.post(func); + ST::MainThreadIoService.post(func); serviceLock.lock(); serviceLock.unlock();