3 Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef IRRLICHTWRAPPER_HEADER
21 #define IRRLICHTWRAPPER_HEADER
24 #include "common_irrlicht.h"
29 #include <jmutexautolock.h>
33 A thread-safe texture pointer cache.
35 This is used so that irrlicht doesn't get called from many
36 threads, because texture pointers have to be handled in
46 assert(m_mutex.IsInitialized());
49 void set(std::string name, video::ITexture *texture)
54 JMutexAutoLock lock(m_mutex);
56 m_textures[name] = texture;
59 video::ITexture* get(std::string name)
61 JMutexAutoLock lock(m_mutex);
63 core::map<std::string, video::ITexture*>::Node *n;
64 n = m_textures.find(name);
73 core::map<std::string, video::ITexture*> m_textures;
80 Returns a new texture which can be based on the original.
81 Shall not modify or delete the original texture.
83 virtual video::ITexture * make(video::ITexture *original,
84 const char *newname, video::IVideoDriver* driver) = 0;
87 struct CrackTextureMod: public TextureMod
89 CrackTextureMod(u16 a_progression)
91 progression = a_progression;
94 virtual video::ITexture * make(video::ITexture *original,
95 const char *newname, video::IVideoDriver* driver);
100 struct ProgressBarTextureMod: public TextureMod
102 // value is from 0.0 to 1.0
103 ProgressBarTextureMod(float a_value)
108 virtual video::ITexture * make(video::ITexture *original,
109 const char *newname, video::IVideoDriver* driver);
115 A class for specifying a requested texture
123 TextureSpec(const std::string &a_name, const std::string &a_path,
133 bool operator==(const TextureSpec &other)
135 return name == other.name;
137 // An unique name for the texture. Usually the same as the path.
138 // Note that names and paths reside the same namespace.
140 // This is the path of the base texture
142 // Modification to do to the base texture
143 // NOTE: This is deleted by the one who processes the request
148 A thread-safe wrapper for irrlicht, to be accessed from
149 background worker threads.
151 Queues tasks to be done in the main thread.
154 class IrrlichtWrapper
158 These are called from the main thread
160 IrrlichtWrapper(IrrlichtDevice *device);
166 These are called from other threads
169 // Not exactly thread-safe but this needs to be fast.
170 // getTimer()->getRealTime() only reads one variable anyway.
173 return m_device->getTimer()->getRealTime();
176 video::ITexture* getTexture(TextureSpec spec);
177 video::ITexture* getTexture(const std::string &path);
181 Non-thread-safe variants of stuff, for internal use
183 video::ITexture* getTextureDirect(TextureSpec spec);
189 threadid_t m_main_thread;
191 JMutex m_device_mutex;
192 IrrlichtDevice *m_device;
194 TextureCache m_texturecache;
196 RequestQueue<TextureSpec, video::ITexture*, u8, u8> m_get_texture_queue;