diff --git a/src/framework/graphics/texture.cpp b/src/framework/graphics/texture.cpp index 89e42b3d..8b6d48a7 100644 --- a/src/framework/graphics/texture.cpp +++ b/src/framework/graphics/texture.cpp @@ -118,22 +118,27 @@ void Texture::setSmooth(bool smooth) std::vector Texture::getPixels() { - // hack to copy pixels from opengl memory - FrameBufferPtr fb(new FrameBuffer(m_size)); std::vector pixels(m_size.area()*4, 0); +#ifdef OPENGL_ES + // hack to copy pixels from opengl memory in opengl es + // NOTE: this can be slow, but its the only way to get pixels from a texture in OpenGL ES + FrameBufferPtr fb(new FrameBuffer(m_size)); fb->bind(); g_painter.saveAndResetState(); g_painter.drawTexturedRect(Rect(0,0,m_size), shared_from_this()); glReadPixels(0, 0, m_size.width(), m_size.height(), GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]); g_painter.restoreSavedState(); fb->release(); +#else + // copy pixels from opengl memory + glBindTexture(GL_TEXTURE_2D, m_textureId); + glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]); +#endif return pixels; } -void Texture::generateBilinearMipmaps() +void Texture::generateBilinearMipmaps(std::vector inPixels) { - std::vector inPixels = getPixels(); - bind(); if(!m_useMipmaps) { @@ -188,7 +193,7 @@ void Texture::generateBilinearMipmaps() if(inSize.width() == 1 || inSize.height() == 1) break; - inPixels = outPixels; + inPixels = std::move(outPixels); inSize /= 2; outSize /= 2; } diff --git a/src/framework/graphics/texture.h b/src/framework/graphics/texture.h index e410434b..5850db73 100644 --- a/src/framework/graphics/texture.h +++ b/src/framework/graphics/texture.h @@ -35,7 +35,10 @@ public: void bind() { glBindTexture(GL_TEXTURE_2D, m_textureId); } void generateMipmaps(); - void generateBilinearMipmaps(); + + // generate bilinear mipmaps optimized for alpha textures + void generateBilinearMipmaps(std::vector inPixels); + void setSmooth(bool smooth); GLuint getId() { return m_textureId; } diff --git a/src/otclient/core/item.cpp b/src/otclient/core/item.cpp index 4bc14852..b9d7e423 100644 --- a/src/otclient/core/item.cpp +++ b/src/otclient/core/item.cpp @@ -77,8 +77,10 @@ void Item::setPosition(const Position& position) Thing::setPosition(position); } -void Item::setCount(uint8 count) +void Item::setCount(int count) { + count = std::max(std::min(count, 255), 0); + if(isStackable() && getNumPatternsX() == 4 && getNumPatternsY() == 2) { if(count < 5) { m_xPattern = count-1; diff --git a/src/otclient/core/item.h b/src/otclient/core/item.h index f6bbfd3c..308a2446 100644 --- a/src/otclient/core/item.h +++ b/src/otclient/core/item.h @@ -36,9 +36,9 @@ public: void draw(const Point& dest, float scaleFactor); void setPosition(const Position &position); - void setCount(uint8 data); + void setCount(int count); - uint8 getCount() { return m_count; } + int getCount() { return m_count; } ItemPtr asItem() { return std::static_pointer_cast(shared_from_this()); } diff --git a/src/otclient/core/mapview.cpp b/src/otclient/core/mapview.cpp index af3688b0..1723e82f 100644 --- a/src/otclient/core/mapview.cpp +++ b/src/otclient/core/mapview.cpp @@ -153,9 +153,14 @@ void MapView::draw(const Rect& rect) animatedText->draw(p, rect); } } else { - // draw a arrow for position the center in non near views - g_painter.setColor(Fw::red); - g_painter.drawFilledRect(Rect(rect.center(), 4, 4)); + // draw a cross in the center instead of our creature + Rect vRect(0, 0, 2, 10); + Rect hRect(0, 0, 10, 2); + vRect.moveCenter(rect.center()); + hRect.moveCenter(rect.center()); + g_painter.setColor(Fw::white); + g_painter.drawFilledRect(vRect); + g_painter.drawFilledRect(hRect); } } @@ -405,18 +410,11 @@ void MapView::setVisibleDimension(const Size& visibleDimension) viewRange = NEAR_VIEW; else if(tileSize >= 16 && visibleDimension.area() <= MID_VIEW_AREA) viewRange = MID_VIEW; - else if(tileSize >= 8) + else if(tileSize >= 8 && visibleDimension.area() <= FAR_VIEW_AREA) viewRange = FAR_VIEW; else viewRange = HUGE_VIEW; - if(m_viewRange != viewRange) { - if(viewRange == NEAR_VIEW) dump << "near view"; - else if(viewRange == MID_VIEW) dump << "mid view"; - else if(viewRange == FAR_VIEW) dump << "far view"; - else if(viewRange == HUGE_VIEW) dump << "huge view"; - } - // draw actually more than what is needed to avoid massive recalculations on far views if(viewRange >= FAR_VIEW) { Size oldDimension = drawDimension; diff --git a/src/otclient/core/mapview.h b/src/otclient/core/mapview.h index 280fb306..982490b9 100644 --- a/src/otclient/core/mapview.h +++ b/src/otclient/core/mapview.h @@ -38,7 +38,8 @@ class MapView : public LuaObject DEFAULT_FRAMBUFFER_HEIGHT = 1440, NEAR_VIEW_AREA = 32*32, - MID_VIEW_AREA = 96*96, + MID_VIEW_AREA = 64*64, + FAR_VIEW_AREA = 128*128, MAX_TILE_UPDATES = NEAR_VIEW_AREA*7 }; diff --git a/src/otclient/core/spritemanager.cpp b/src/otclient/core/spritemanager.cpp index d317503d..cfbd684b 100644 --- a/src/otclient/core/spritemanager.cpp +++ b/src/otclient/core/spritemanager.cpp @@ -22,6 +22,7 @@ #include "spritemanager.h" #include +#include #include SpriteManager g_sprites; @@ -38,6 +39,7 @@ bool SpriteManager::load(const std::string& file) g_resources.loadFile(file, m_fin); m_signature = Fw::getU32(m_fin); m_spritesCount = Fw::getU16(m_fin); + dump << m_spritesCount; m_sprites.resize(m_spritesCount); m_loaded = true; return true; @@ -54,6 +56,21 @@ void SpriteManager::unload() m_signature = 0; } +void SpriteManager::preloadSprites() +{ + // preload every 100 sprites, periodically + const int burst = 50; + const int interval = 10; + auto preload = [this](int start) { + for(int i=start;i pixels(4096); int writePos = 0; int read = 0; @@ -116,9 +133,9 @@ TexturePtr SpriteManager::loadSpriteTexture(int id) writePos += 4; } - TexturePtr spriteTex(new Texture(32, 32, 4, pixels)); + TexturePtr spriteTex(new Texture(32, 32, 4, &pixels[0])); spriteTex->setSmooth(true); - spriteTex->generateBilinearMipmaps(); + spriteTex->generateBilinearMipmaps(pixels); return spriteTex; } diff --git a/src/otclient/core/spritemanager.h b/src/otclient/core/spritemanager.h index 130254de..63aca0a6 100644 --- a/src/otclient/core/spritemanager.h +++ b/src/otclient/core/spritemanager.h @@ -33,6 +33,7 @@ public: bool load(const std::string& file); void unload(); + void preloadSprites(); uint32 getSignature() { return m_signature; } int getSpritesCount() { return m_spritesCount; } @@ -45,7 +46,7 @@ private: Boolean m_loaded; uint32 m_signature; - uint16 m_spritesCount; + int m_spritesCount; std::stringstream m_fin; std::vector m_sprites; TexturePtr m_transparentSprite; diff --git a/src/otclient/luafunctions.cpp b/src/otclient/luafunctions.cpp index a792f775..0dc60b87 100644 --- a/src/otclient/luafunctions.cpp +++ b/src/otclient/luafunctions.cpp @@ -58,6 +58,7 @@ void OTClient::registerLuaFunctions() g_lua.bindClassStaticFunction("g_sprites", "load", std::bind(&SpriteManager::load, &g_sprites, _1)); g_lua.bindClassStaticFunction("g_sprites", "isLoaded", std::bind(&SpriteManager::isLoaded, &g_sprites)); g_lua.bindClassStaticFunction("g_sprites", "getSignature", std::bind(&SpriteManager::getSignature, &g_sprites)); + g_lua.bindClassStaticFunction("g_sprites", "preloadSprites", std::bind(&SpriteManager::preloadSprites, &g_sprites)); g_lua.registerStaticClass("g_map"); g_lua.bindClassStaticFunction("g_map", "isLookPossible", std::bind(&Map::isLookPossible, &g_map, _1));