From d5a78c12530df800f8182f7012cd16237a7ebafe Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Mon, 20 Dec 2010 22:23:24 +0200 Subject: added some missing files --- src/irrlichtwrapper.cpp | 136 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 src/irrlichtwrapper.cpp (limited to 'src/irrlichtwrapper.cpp') diff --git a/src/irrlichtwrapper.cpp b/src/irrlichtwrapper.cpp new file mode 100644 index 000000000..69b08a6d8 --- /dev/null +++ b/src/irrlichtwrapper.cpp @@ -0,0 +1,136 @@ +#include "irrlichtwrapper.h" + +IrrlichtWrapper::IrrlichtWrapper(IrrlichtDevice *device) +{ + m_main_thread = get_current_thread_id(); + m_device_mutex.Init(); + m_device = device; +} + +void IrrlichtWrapper::Run() +{ + /* + Fetch textures + */ + if(m_get_texture_queue.size() > 0) + { + GetRequest + request = m_get_texture_queue.pop(); + + dstream<<"got request with key.name="< + result; + result.key = request.key; + result.callers = request.callers; + result.item = getTextureDirect(request.key); + + request.dest->push_back(result); + } +} + +video::ITexture* IrrlichtWrapper::getTexture(TextureSpec spec) +{ + video::ITexture *t = m_texturecache.get(spec.name); + if(t != NULL) + return t; + + if(get_current_thread_id() == m_main_thread) + { + dstream<<"Loading texture directly: "< result_queue; + + // Throw a request in + m_get_texture_queue.add(spec, 0, 0, &result_queue); + + dstream<<"Waiting for texture "< + result = result_queue.pop_front(true); + + // Check that at least something worked OK + assert(result.key.name == spec.name); + + t = result.item; + } + + // Add to cache and return + m_texturecache.set(spec.name, t); + return t; +} + +video::ITexture* IrrlichtWrapper::getTexture(const std::string &path) +{ + /*TextureSpec spec; + spec.name = path; + spec.path = path; + return getTexture(spec);*/ + return getTexture(TextureSpec(path, path, NULL)); +} + +/* + Non-thread-safe functions +*/ + +video::ITexture* IrrlichtWrapper::getTextureDirect(TextureSpec spec) +{ + video::IVideoDriver* driver = m_device->getVideoDriver(); + //TODO + if(spec.mod != NULL) + { + dstream<<"IrrlichtWrapper::getTextureDirect: Modified textures" + " not supported"<getTexture(spec.path.c_str()); +} + +video::ITexture * CrackTextureMod::make(video::ITexture *original, + video::IVideoDriver* driver) +{ + //TODO + dstream<<__FUNCTION_NAME<getVideoDriver(); + + core::dimension2d dim(size.X, size.Y); + + video::IImage *baseimage = driver->createImage( + base, + core::position2d(pos_base.X, pos_base.Y), + dim); + assert(baseimage); + + video::IImage *otherimage = driver->createImage( + other, + core::position2d(pos_other.X, pos_other.Y), + dim); + assert(sourceimage); + + otherimage->copyToWithAlpha(baseimage, v2s32(0,0), + core::rect(v2s32(0,0), dim), + video::SColor(255,255,255,255), + core::rect(v2s32(0,0), dim)); + otherimage->drop(); + + video::ITexture *newtexture = driver->addTexture(name, baseimage); + + baseimage->drop(); + + return newtexture; +} +#endif + -- cgit v1.2.3