#include "irrlichtwrapper.h" #include "constants.h" #include "string.h" #include "strfnd.h" IrrlichtWrapper::IrrlichtWrapper(IrrlichtDevice *device) { m_running = true; m_main_thread = get_current_thread_id(); m_device_mutex.Init(); m_device = device; } IrrlichtWrapper::~IrrlichtWrapper() { #if 0 // Clear image cache for(core::map::Iterator i = m_imagecache.getIterator(); i.atEnd() == false; i++) { i.getNode()->getValue()->drop(); } #endif } void IrrlichtWrapper::Run() { #if 0 /* Fetch textures */ if(m_get_texture_queue.size() > 0) { GetRequest request = m_get_texture_queue.pop(); dstream<<"got texture request with" <<" key.tids[0]="<getVideoDriver(); /* An image will be built from files and then converted into a texture. */ video::IImage *baseimg = NULL; /* Irrlicht requires a name for every texture, with which it will be stored internally in irrlicht. */ std::string texture_name; for(u32 i=0; i::Node *n; n = m_imagecache.find(texture_name); if(n != NULL) { video::IImage *image = n->getValue(); core::dimension2d dim = image->getDimension(); baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); image->copyTo(baseimg); dstream<<"INFO: getTextureDirect(): Loaded \"" <getTexture(path.c_str()); driver->renameTexture(t, texture_name.c_str()); return t; }*/ video::IImage *image = driver->createImageFromFile(path.c_str()); if(image == NULL) { dstream<<"WARNING: Could not load image \""<createImage(video::ECF_A8R8G8B8, image); core::dimension2d dim = image->getDimension(); baseimg = driver->createImage(video::ECF_A8R8G8B8, dim); image->copyTo(baseimg); image->drop(); //baseimg = image; } // Else blit on base. else { dstream<<"INFO: Blitting "< dim = image->getDimension(); //core::dimension2d dim(16,16); // Position to copy the blitted to in the base image core::position2d pos_to(0,0); // Position to copy the blitted from in the blitted image core::position2d pos_from(0,0); // Blit image->copyToWithAlpha(baseimg, pos_to, core::rect(pos_from, dim), video::SColor(255,255,255,255), NULL); // Drop image image->drop(); } } else { // A special texture modification dstream<<"INFO: getTextureDirect(): generating \""< dim_base = baseimg->getDimension(); // Crack will be drawn at this size u32 cracksize = 16; // Size of the crack image core::dimension2d dim_crack(cracksize,cracksize); // Position to copy the crack from in the crack image core::position2d pos_other(0, 16 * progression); video::IImage *crackimage = driver->createImageFromFile( porting::getDataPath("crack.png").c_str()); if(crackimage) { /*crackimage->copyToWithAlpha(baseimg, v2s32(0,0), core::rect(pos_other, dim_base), video::SColor(255,255,255,255), NULL);*/ for(u32 y0=0; y0 pos_base(x0*cracksize, y0*cracksize); crackimage->copyToWithAlpha(baseimg, pos_base, core::rect(pos_other, dim_crack), video::SColor(255,255,255,255), NULL); } crackimage->drop(); } } else if(name.substr(0,8) == "[combine") { // "[combine:16x128:0,0=stone.png:0,16=grass.png" Strfnd sf(name); sf.next(":"); u32 w0 = stoi(sf.next("x")); u32 h0 = stoi(sf.next(":")); dstream<<"INFO: combined w="<createImageFromFile( porting::getDataPath(filename.c_str()).c_str()); if(img) { core::dimension2d dim = img->getDimension(); dstream<<"INFO: Size "< pos_base(x, y); video::IImage *img2 = driver->createImage(video::ECF_A8R8G8B8, dim); img->copyTo(img2); img->drop(); img2->copyToWithAlpha(baseimg, pos_base, core::rect(v2s32(0,0), dim), video::SColor(255,255,255,255), NULL); img2->drop(); } else { dstream<<"WARNING: img==NULL"<::Node *n; n = m_imagecache.find(texture_name); if(n != NULL) { video::IImage *img = n->getValue(); if(img != baseimg) { img->drop(); } } m_imagecache[texture_name] = baseimg; } } // If no resulting image, return NULL if(baseimg == NULL) { dstream<<"WARNING: getTextureDirect(): baseimg is NULL (attempted to" " create texture \""<setPixel(1,1, c); baseimg->setPixel(1,14, c); baseimg->setPixel(14,1, c); baseimg->setPixel(14,14, c);*/ // Create texture from resulting image t = driver->addTexture(texture_name.c_str(), baseimg); dstream<<"INFO: getTextureDirect(): created texture \""< size = image->getDimension(); u32 barheight = 1; u32 barpad_x = 1; u32 barpad_y = 1; u32 barwidth = size.Width - barpad_x*2; v2u32 barpos(barpad_x, size.Height - barheight - barpad_y); u32 barvalue_i = (u32)(((float)barwidth * value) + 0.5); video::SColor active(255,255,0,0); video::SColor inactive(255,0,0,0); for(u32 x0=0; x0setPixel(x,y, *c); } } } #endif