aboutsummaryrefslogtreecommitdiff
path: root/src/utility.h
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2010-12-13 03:19:12 +0200
committerPerttu Ahola <celeron55@gmail.com>2010-12-13 03:19:12 +0200
commit571fb14f9480a0fd70d7cfeb0484c9513153c33a (patch)
tree64601662d351d986fbadaef2c410c90a38241634 /src/utility.h
parent47a593b5197393d8f8cdfe18b1aa46b8bc1f3fb6 (diff)
downloadminetest-571fb14f9480a0fd70d7cfeb0484c9513153c33a.tar.gz
minetest-571fb14f9480a0fd70d7cfeb0484c9513153c33a.tar.bz2
minetest-571fb14f9480a0fd70d7cfeb0484c9513153c33a.zip
working nicely
Diffstat (limited to 'src/utility.h')
-rw-r--r--src/utility.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/utility.h b/src/utility.h
index c9b13546c..d22e1d651 100644
--- a/src/utility.h
+++ b/src/utility.h
@@ -32,6 +32,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <fstream>
#include <string>
#include <sstream>
+#include <jmutex.h>
+#include <jmutexautolock.h>
extern const v3s16 g_26dirs[26];
@@ -808,5 +810,45 @@ private:
core::map<std::string, std::string> m_settings;
};
+/*
+ A thread-safe texture cache.
+
+ This is used so that irrlicht doesn't get called from many threads
+*/
+
+class TextureCache
+{
+public:
+ TextureCache()
+ {
+ m_mutex.Init();
+ assert(m_mutex.IsInitialized());
+ }
+
+ void set(std::string name, video::ITexture *texture)
+ {
+ JMutexAutoLock lock(m_mutex);
+
+ m_textures[name] = texture;
+ }
+
+ video::ITexture* get(std::string name)
+ {
+ JMutexAutoLock lock(m_mutex);
+
+ core::map<std::string, video::ITexture*>::Node *n;
+ n = m_textures.find(name);
+
+ if(n != NULL)
+ return n->getValue();
+
+ return NULL;
+ }
+
+private:
+ core::map<std::string, video::ITexture*> m_textures;
+ JMutex m_mutex;
+};
+
#endif