diff --git a/modules/mainmenu/entergame.lua b/modules/mainmenu/entergame.lua index 0ef57768..3c01a1b7 100644 --- a/modules/mainmenu/entergame.lua +++ b/modules/mainmenu/entergame.lua @@ -38,7 +38,7 @@ function EnterGame_connectToLoginServer() -- display motd local motdNumber = string.sub(motd, 0, string.find(motd, "\n")) local motdText = string.sub(motd, string.find(motd, "\n") + 1, string.len(motd)) - local motdBox = displayInfoBox("Message of the day", motdText) + --local motdBox = displayInfoBox("Message of the day", motdText) -- hide main menu mainMenu.visible = false diff --git a/src/otclient/core/datmanager.cpp b/src/otclient/core/datmanager.cpp index 16386967..2b45e29c 100644 --- a/src/otclient/core/datmanager.cpp +++ b/src/otclient/core/datmanager.cpp @@ -17,20 +17,20 @@ bool DatManager::load(const std::string& filename) int numShots = fw::getu16(fin); m_itemsAttributes.resize(numItems); - for(int id = 100; id <= numItems; ++id) + for(int id = 100; id < numItems; ++id) parseThingAttributes(fin, m_itemsAttributes[id - 100]); m_creaturesAttributes.resize(numItems); - for(int id = 1; id < numCreatures; ++id) - parseThingAttributes(fin, m_creaturesAttributes[id - 1]); + for(int id = 0; id < numCreatures; ++id) + parseThingAttributes(fin, m_creaturesAttributes[id]); m_effectsAttributes.resize(numItems); - for(int id = 100; id < numEffects; ++id) - parseThingAttributes(fin, m_effectsAttributes[id - 100]); + for(int id = 0; id < numEffects; ++id) + parseThingAttributes(fin, m_effectsAttributes[id]); m_shotsAttributes.resize(numItems); - for(int id = 1; id < numShots; ++id) - parseThingAttributes(fin, m_shotsAttributes[id - 1]); + for(int id = 0; id < numShots; ++id) + parseThingAttributes(fin, m_shotsAttributes[id]); return true; } catch(std::exception& e) { @@ -178,8 +178,9 @@ void DatManager::parseThingAttributesOpt(std::stringstream& fin, ThingAttributes break; case 0x19: // pixels characters height - fin.read((char*)&thingAttributes.xOffset, 1); - fin.read((char*)&thingAttributes.yOffset, 1); + //fin.read((char*)&thingAttributes.xOffset, 1); + //fin.read((char*)&thingAttributes.yOffset, 1); + fin.read((char*)&read_short, 2); //logDebug((int)thingAttributes.xOffset, " ", (int)thingAttributes.yOffset); break; case 0x1A: diff --git a/src/otclient/core/datmanager.h b/src/otclient/core/datmanager.h index 2a0bac5e..672cc141 100644 --- a/src/otclient/core/datmanager.h +++ b/src/otclient/core/datmanager.h @@ -14,9 +14,9 @@ public: void parseThingAttributesOpt(std::stringstream& fin, ThingAttributes& thingAttributes, uint8 opt); ThingAttributes& getItemAttributes(uint16 id) { return m_itemsAttributes[id - 100]; } - ThingAttributes& getCreatureAttributes(uint16 id) { return m_creaturesAttributes[id - 1]; } - ThingAttributes& getEffectAttributes(uint16 id) { return m_effectsAttributes[id - 100]; } - ThingAttributes& getShotAttributes(uint16 id) { return m_shotsAttributes[id - 1]; } + ThingAttributes& getCreatureAttributes(uint16 id) { return m_creaturesAttributes[id]; } + ThingAttributes& getEffectAttributes(uint16 id) { return m_effectsAttributes[id]; } + ThingAttributes& getShotAttributes(uint16 id) { return m_shotsAttributes[id]; } uint32 getSignature() { return m_signature; } diff --git a/src/otclient/core/effect.cpp b/src/otclient/core/effect.cpp index 6ce97939..71d84d74 100644 --- a/src/otclient/core/effect.cpp +++ b/src/otclient/core/effect.cpp @@ -3,12 +3,32 @@ Effect::Effect() : Thing(THING_EFFECT) { + m_timer = 0; + m_animation = 0; + m_finished = false; } void Effect::draw(int x, int y) { - int anim = 0; - internalDraw(x, y, 0, 0, 0, 0, anim); + internalDraw(x, y, 0, 0, 0, 0, m_animation); +} + +void Effect::update(int elapsedTime) +{ + if(m_finished) + return; + + if(m_timer > 75) { + const ThingAttributes& attributes = getAttributes(); + + if(m_animation+1 == attributes.animcount) { + m_finished = true; + return; + } + m_animation++; + m_timer = 0; + } + m_timer += elapsedTime; } const ThingAttributes& Effect::getAttributes() diff --git a/src/otclient/core/effect.h b/src/otclient/core/effect.h index 4b2a6fbb..85630b15 100644 --- a/src/otclient/core/effect.h +++ b/src/otclient/core/effect.h @@ -10,10 +10,18 @@ public: Effect(); void draw(int x, int y); + void update(int elapsedTime); + + bool finished() { return m_finished; } const ThingAttributes& getAttributes(); - virtual EffectPtr asEffect() { return std::static_pointer_cast(shared_from_this()); } + EffectPtr asEffect() { return std::static_pointer_cast(shared_from_this()); } + +private: + int m_timer; + int m_animation; + bool m_finished; }; #endif diff --git a/src/otclient/core/map.cpp b/src/otclient/core/map.cpp index a2cde7fa..47573cf7 100644 --- a/src/otclient/core/map.cpp +++ b/src/otclient/core/map.cpp @@ -20,39 +20,31 @@ void Map::draw(int x, int y) if(playerPos.z <= 7) { // player pos it 8-6. check if we can draw upper floors. - bool draw = true; + int drawFloorStop = 0; for(int jz = 6; jz >= 0; --jz) { - Position coverPos = Position(playerPos.x-(6-jz), playerPos.y-(6-jz), jz); + Position coverPos = Position(playerPos.x+(7-jz)-1, playerPos.y+(7-jz)-1, jz); if(m_tiles[coverPos]) { if(m_tiles[coverPos]->getStackSize() > 0 && jz < playerPos.z) { - draw = false; + drawFloorStop = jz; + break; } } } for(int iz = 7; iz > 0; --iz) { + if(iz == drawFloorStop) + break; // +1 in draws cause 64x64 items may affect view. - for(int ix = -7; ix < + 8+7; ++ix) { - for(int iy = -5; iy < + 6+7; ++iy) { + + for(int ix = -7+(playerPos.z-iz); ix < + 8+7; ++ix) { + for(int iy = -5+(playerPos.z-iz); iy < + 6+7; ++iy) { Position itemPos = Position(playerPos.x + ix, playerPos.y + iy, iz); - //Position drawPos = Position(ix + 8, iy - playerPos.y + 6, iz); - //logDebug("x: ", relativePos.x, " y: ", relativePos.y, " z: ", (int)relativePos.z); if(m_tiles[itemPos]) - m_tiles[itemPos]->draw((ix + 7 - (7-iz))*32, (iy + 5 - (7-iz))*32); + m_tiles[itemPos]->draw((ix + 7 - (playerPos.z-iz))*32, (iy + 5 - (playerPos.z-iz))*32); } } - - if(!draw) - break; } - - } - - // draw effects - for(auto it = m_effects.begin(), end = m_effects.end(); it != end; ++it) { - Position effectPos = (*it)->getPosition(); - (*it)->draw((effectPos.x - playerPos.x + 7) * 32, (effectPos.y - playerPos.y + 5) * 32); } // debug draws @@ -62,16 +54,33 @@ void Map::draw(int x, int y) m_framebuffer->draw(Rect(x, y, g_graphics.getScreenSize())); } -void Map::addThing(ThingPtr thing, uint8 stackpos) +void Map::update(int elapsedTime) { - if(thing->asItem() || thing->asCreature()) { - if(!m_tiles[thing->getPosition()]) { - m_tiles[thing->getPosition()] = TilePtr(new Tile()); + // Items + + // Effects + for(auto it = m_effects.begin(), end = m_effects.end(); it != end;) { + if((*it)->finished()) { + m_tiles[(*it)->getPosition()]->removeThing(*it, 0); + it = m_effects.erase(it); + } + else { + (*it)->update(elapsedTime); + ++it; } + } +} - m_tiles[thing->getPosition()]->addThing(thing, stackpos); +void Map::addThing(ThingPtr thing, uint8 stackpos) +{ + if(!m_tiles[thing->getPosition()]) { + m_tiles[thing->getPosition()] = TilePtr(new Tile()); } - else if(thing->asEffect()) { - m_effects.push_back(thing); + + m_tiles[thing->getPosition()]->addThing(thing, stackpos); + + // List with effects and shots to update them. + if(thing->asEffect()) { + m_effects.push_back(thing->asEffect()); } } diff --git a/src/otclient/core/map.h b/src/otclient/core/map.h index ebd6a953..e2ed1f0b 100644 --- a/src/otclient/core/map.h +++ b/src/otclient/core/map.h @@ -8,13 +8,14 @@ class Map { public: - void addThing(ThingPtr thing, uint8 stackpos = 0); - void draw(int x, int y); + void update(int elapsedTime); + + void addThing(ThingPtr thing, uint8 stackpos = 0); private: std::unordered_map m_tiles; - std::list m_effects; + std::list m_effects; FrameBufferPtr m_framebuffer; }; diff --git a/src/otclient/core/thing.cpp b/src/otclient/core/thing.cpp index ac03d069..2204987f 100644 --- a/src/otclient/core/thing.cpp +++ b/src/otclient/core/thing.cpp @@ -26,7 +26,7 @@ void Thing::internalDraw(int x, int y, int blendframes, int xdiv, int ydiv, int TexturePtr spriteTex = g_sprites.getSpriteTexture(spriteId); Rect drawRect((x - xi*32) - attributes.xOffset, - (y - yi*32) - attributes.yOffset, + (y - yi*32) - attributes.xOffset, 32, 32); g_graphics.drawTexturedRect(drawRect, spriteTex); diff --git a/src/otclient/core/tile.cpp b/src/otclient/core/tile.cpp index f03ded52..683e9e4e 100644 --- a/src/otclient/core/tile.cpp +++ b/src/otclient/core/tile.cpp @@ -21,9 +21,26 @@ void Tile::addThing(ThingPtr thing, uint8 stackpos) else m_itemsBottom.push_back(thing); } - } else if(thing->asCreature()) { + } + else if(thing->asCreature()) { m_creatures.push_back(thing); } + else if(thing->asEffect()) { + m_effects.push_back(thing); + } +} + +void Tile::removeThing(ThingPtr thing, uint8 stackpos) +{ + if(thing->asEffect()) { + for(auto it = m_effects.begin(), end = m_effects.end(); it != end; ++it) { + if(thing == *it) { + (*it).reset(); + m_effects.erase(it); + break; + } + } + } } void Tile::draw(int x, int y) @@ -31,13 +48,16 @@ void Tile::draw(int x, int y) if(m_ground) m_ground->draw(x, y); - for(const ThingPtr& thing : m_itemsBottom) + for(const ThingPtr& thing : m_itemsTop) thing->draw(x, y); for(const ThingPtr& thing : m_creatures) thing->draw(x, y); - for(const ThingPtr& thing : m_itemsTop) + for(const ThingPtr& thing : m_itemsBottom) + thing->draw(x, y); + + for(const ThingPtr& thing : m_effects) thing->draw(x, y); } diff --git a/src/otclient/core/tile.h b/src/otclient/core/tile.h index 2d632aa2..df9fcbfb 100644 --- a/src/otclient/core/tile.h +++ b/src/otclient/core/tile.h @@ -10,6 +10,7 @@ public: Tile(); void addThing(ThingPtr thing, uint8 stackpos); + void removeThing(ThingPtr thing, uint8 stackpos); void draw(int x, int y); @@ -22,6 +23,7 @@ private: std::deque m_itemsBottom; std::deque m_creatures; std::deque m_itemsTop; + std::deque m_effects; }; #endif diff --git a/src/otclient/otclient.cpp b/src/otclient/otclient.cpp index 6f342813..36345b98 100644 --- a/src/otclient/otclient.cpp +++ b/src/otclient/otclient.cpp @@ -82,6 +82,7 @@ void OTClient::run() int frameTicks = g_platform.getTicks(); int lastFpsTicks = frameTicks; int lastPollTicks = frameTicks; + int lastUpdateTicks = frameTicks; int frameCount = 0; m_stopping = false; @@ -114,6 +115,12 @@ void OTClient::run() lastPollTicks = frameTicks; } + // only update to a maximum of 60 fps + if(frameTicks - lastUpdateTicks >= 1) { + g_map.update(frameTicks - lastUpdateTicks); + lastUpdateTicks = frameTicks; + } + // only render when the windows is visible if(g_platform.isWindowVisible()) { // render begin