This commit is contained in:
vladislav.khorev committed 2013-02-03 13:11:16 +00:00
1 parent a8e01ed69d
commit c9b7f21be5
11 files changed
+228 -13

No files matched your search

+10 -1
View File
@@ -56,6 +56,13 @@ protected:
public:
std::string PathToResources;
boost::thread::id MainThreadId;
std::vector<boost::function<void()>> MainThreadAsyncFunctionArr;
boost::mutex FuncListMutex;
std::list<TFuncToPerform> MainThreadSyncFunctionList;
TTextureListClass TexList;
TModelManager ModelManager;
TFlexModelManager FlexModelManager;
@@ -79,7 +86,9 @@ public:
TSoundManagerIos SoundManager;
#endif
~TResourceManager() { }
void Update(cardinal timer);
~TResourceManager();
};
+2
View File
@@ -65,4 +65,6 @@ int MainLoop(TApplication& application);
//This file includes templates that call any of three singletones: Console, ResourceManager or Renderer
#include "include/GUIManager/WidgetTemplatesImpl.h"
#include "include/Utils/ThreadUtilsImpl.h"
+5 -2
View File
@@ -58,12 +58,14 @@ protected:
bool CreateTexDataFromBmp32(const std::string& filename, TTextureData& texData);
bool CreateTexDataFromTga(const std::string& filename, TTextureData& texData);
bool CreateTexDataFromPng(const std::string& filename, TTextureData& texData);
cardinal AddTextureBmp24Data(const TTextureData& texData);
cardinal AddTextureBmp32Data(const TTextureData& texData);
cardinal AddCubemapTextureBmp24Data(TTextureData* texData);
//cardinal AddCubemapTextureBmp32Data(TTextureData* texData); Not implemented yet
void InnerClear();
public:
TTextureListClass();
~TTextureListClass();
@@ -84,7 +86,8 @@ public:
cardinal GetTextureWidth(const std::string& texName);
cardinal AddTextureDirectly(const std::string& filename, std::string texName = ""); //Loads texture directly from this file or fails
cardinal AddTexture(const std::string& fileName, std::string texName = ""); //Adds path to resources to the filename then call previous one
cardinal AddTexture(const std::string& fileName);
cardinal AddTexture(const std::string& fileName, std::string texName); //Adds path to resources to the filename then call previous one
cardinal AddTextureFromUserdata(const std::string& fileName, std::string texName = ""); //Same as above but checks if file is created in user data
cardinal AddCubemapTexture(std::string filename[6]); // "posx.bmp","negx.bmp","posy.bmp","negy.bmp","posz.bmp","negz.bmp"
+36
View File
@@ -0,0 +1,36 @@
#ifndef THREAD_UTILS_H_INCLUDED
#define THREAD_UTILS_H_INCLUDED
#include "boost/signal.hpp"
#include "boost/thread.hpp"
namespace SE
{
struct TFuncToPerform
{
private:
public:
TFuncToPerform()
: LockerPtr(new boost::mutex)
{
}
bool Executed;
std::shared_ptr<boost::mutex> LockerPtr;
boost::function<void()> Func;
};
void AssertIfInMainThread();
void PerformInMainThreadAsync(boost::function<void()> f);
template<typename RETURNTYPE>
RETURNTYPE PerformInMainThread(boost::function<RETURNTYPE()> f);
} //namespace SE
#endif
+65
View File
@@ -0,0 +1,65 @@
#ifndef THREAD_UTILS_IMPL_H_INCLUDED
#define THREAD_UTILS_IMPL_H_INCLUDED
#include "include/Engine.h"
namespace SE
{
template<typename RETURNTYPE>
struct TCoverFunc
{
public:
typedef void result_type;
boost::function<RETURNTYPE()> Func;
void operator()(RETURNTYPE& rx)
{
rx = Func();
}
};
template<typename RETURNTYPE>
RETURNTYPE PerformInMainThread(boost::function<RETURNTYPE()> f)
{
if (boost::this_thread::get_id() == ResourceManager->MainThreadId)
{
return f();
}
else
{
RETURNTYPE result;
TCoverFunc<RETURNTYPE> cover_f;
cover_f.Func = f;
TFuncToPerform funcToPerform;
funcToPerform.Executed = false;
funcToPerform.Func = boost::bind(cover_f, boost::ref(result));
funcToPerform.LockerPtr->lock();
ResourceManager->FuncListMutex.lock();
auto itr = ResourceManager->MainThreadSyncFunctionList.insert(ResourceManager->MainThreadSyncFunctionList.end(), funcToPerform);
ResourceManager->FuncListMutex.unlock();
itr->LockerPtr->lock(); //wait until lock will be released
itr->LockerPtr->unlock();
ResourceManager->FuncListMutex.lock();
ResourceManager->MainThreadSyncFunctionList.erase(itr);
ResourceManager->FuncListMutex.unlock();
return result;
}
}
} //namespace SE
#endif
+1
View File
@@ -25,6 +25,7 @@ This code combines additional routines (such as console/log, exceptions, math ut
#include "include/Utils/BindableVar.h"
#include "include/Utils/SimpleTimer.h"
#include "include/Utils/ThreadUtils.h"
#ifdef TARGET_WIN32
#include "WinApi/WinApi.h"