1 #include "irrlichtwrapper.h"
3 IrrlichtWrapper::IrrlichtWrapper(IrrlichtDevice *device)
5 m_main_thread = get_current_thread_id();
10 void IrrlichtWrapper::Run()
15 if(m_get_texture_queue.size() > 0)
17 GetRequest<TextureSpec, video::ITexture*, u8, u8>
18 request = m_get_texture_queue.pop();
20 dstream<<"got request with key.name="<<request.key.name<<std::endl;
22 GetResult<TextureSpec, video::ITexture*, u8, u8>
24 result.key = request.key;
25 result.callers = request.callers;
26 result.item = getTextureDirect(request.key);
28 request.dest->push_back(result);
32 video::ITexture* IrrlichtWrapper::getTexture(TextureSpec spec)
34 video::ITexture *t = m_texturecache.get(spec.name);
38 if(get_current_thread_id() == m_main_thread)
40 dstream<<"Loading texture directly: "<<spec.name<<std::endl;
41 t = getTextureDirect(spec);
45 // We're gonna ask the result to be put into here
46 ResultQueue<TextureSpec, video::ITexture*, u8, u8> result_queue;
49 m_get_texture_queue.add(spec, 0, 0, &result_queue);
51 dstream<<"Waiting for texture "<<spec.name<<std::endl;
54 GetResult<TextureSpec, video::ITexture*, u8, u8>
55 result = result_queue.pop_front(true);
57 // Check that at least something worked OK
58 assert(result.key.name == spec.name);
63 // Add to cache and return
64 m_texturecache.set(spec.name, t);
68 video::ITexture* IrrlichtWrapper::getTexture(const std::string &path)
73 return getTexture(spec);*/
74 return getTexture(TextureSpec(path, path, NULL));
78 Non-thread-safe functions
81 video::ITexture* IrrlichtWrapper::getTextureDirect(TextureSpec spec)
83 video::IVideoDriver* driver = m_device->getVideoDriver();
87 dstream<<"IrrlichtWrapper::getTextureDirect: Modified textures"
88 " not supported"<<std::endl;
90 return driver->getTexture(spec.path.c_str());
93 video::ITexture * CrackTextureMod::make(video::ITexture *original,
94 video::IVideoDriver* driver)
97 dstream<<__FUNCTION_NAME<<std::endl;
102 video::ITexture * createAlphaBlitTexture(const char *name, video::ITexture *base,
103 video::ITexture *other, v2u32 size, v2s32 pos_base, v2s32 pos_other)
107 video::IVideoDriver* driver = g_device->getVideoDriver();
109 core::dimension2d<u32> dim(size.X, size.Y);
111 video::IImage *baseimage = driver->createImage(
113 core::position2d<s32>(pos_base.X, pos_base.Y),
117 video::IImage *otherimage = driver->createImage(
119 core::position2d<s32>(pos_other.X, pos_other.Y),
123 otherimage->copyToWithAlpha(baseimage, v2s32(0,0),
124 core::rect<s32>(v2s32(0,0), dim),
125 video::SColor(255,255,255,255),
126 core::rect<s32>(v2s32(0,0), dim));
129 video::ITexture *newtexture = driver->addTexture(name, baseimage);