From 45fc45a49e61c61646b9997840e92f25bb8ccde9 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Tue, 15 Nov 2011 11:02:47 +0200 Subject: Sending of textures WIP --- src/tile.cpp | 105 +++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 74 insertions(+), 31 deletions(-) (limited to 'src/tile.cpp') diff --git a/src/tile.cpp b/src/tile.cpp index eb3616f02..8ab92d105 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -242,20 +242,23 @@ public: */ void updateAP(AtlasPointer &ap); + /* + Processes queued texture requests from other threads. + + Shall be called from the main thread. + */ + void processQueue(); + /* Build the main texture atlas which contains most of the textures. - - This is called by the constructor. */ void buildMainAtlas(class IGameDef *gamedef); /* - Processes queued texture requests from other threads. - - Shall be called from the main thread. + Insert an image into the cache without touching the filesystem. */ - void processQueue(); + void insertImage(const std::string &name, video::IImage *img); private: @@ -305,31 +308,6 @@ TextureSource::~TextureSource() { } -void TextureSource::processQueue() -{ - /* - Fetch textures - */ - if(m_get_texture_queue.size() > 0) - { - GetRequest - request = m_get_texture_queue.pop(); - - infostream<<"TextureSource::processQueue(): " - <<"got texture request with " - <<"name=\""< - result; - result.key = request.key; - result.callers = request.callers; - result.item = getTextureIdDirect(request.key); - - request.dest->push_back(result); - } -} - u32 TextureSource::getTextureId(const std::string &name) { //infostream<<"getTextureId(): \""< 0) + { + GetRequest + request = m_get_texture_queue.pop(); + + infostream<<"TextureSource::processQueue(): " + <<"got texture request with " + <<"name=\""< + result; + result.key = request.key; + result.callers = request.callers; + result.item = getTextureIdDirect(request.key); + + request.dest->push_back(result); + } +} + void TextureSource::buildMainAtlas(class IGameDef *gamedef) { assert(gamedef->tsrc() == this); @@ -864,6 +867,46 @@ void TextureSource::buildMainAtlas(class IGameDef *gamedef) driver->writeImageToFile(atlas_img, atlaspath.c_str());*/ } +void TextureSource::insertImage(const std::string &name, video::IImage *img) +{ + infostream<<"TextureSource::insertImage(): name="<getVideoDriver(); + assert(driver); + + // Create texture + video::ITexture *t = driver->addTexture(name.c_str(), img); + + bool reuse_old_id = false; + u32 id = m_atlaspointer_cache.size(); + // Check old id without fetching a texture + core::map::Node *n; + n = m_name_to_id.find(name); + // If it exists, we will replace the old definition + if(n){ + id = n->getValue(); + reuse_old_id = true; + } + + // Create AtlasPointer + AtlasPointer ap(id); + ap.atlas = t; + ap.pos = v2f(0,0); + ap.size = v2f(1,1); + ap.tiled = 0; + core::dimension2d dim = img->getDimension(); + + // Create SourceAtlasPointer and add to containers + SourceAtlasPointer nap(name, ap, img, v2s32(0,0), dim); + if(reuse_old_id) + m_atlaspointer_cache[id] = nap; + else + m_atlaspointer_cache.push_back(nap); + m_name_to_id[name] = id; +} + video::IImage* generate_image_from_scratch(std::string name, IrrlichtDevice *device) { -- cgit v1.2.3