From 4bd701f94c959d7e4af307ab1f1bf8ac10c24396 Mon Sep 17 00:00:00 2001 From: Henrique Date: Sun, 28 Aug 2011 16:47:23 -0300 Subject: [PATCH] some render improvements --- src/otclient/core/creature.cpp | 16 +++---- src/otclient/core/creature.h | 1 - src/otclient/core/effect.cpp | 3 +- src/otclient/core/effect.h | 1 - src/otclient/core/item.cpp | 81 ++++++++++++++++++++-------------- src/otclient/core/item.h | 6 ++- src/otclient/core/thing.cpp | 22 ++++++--- src/otclient/core/thing.h | 8 +++- 8 files changed, 84 insertions(+), 54 deletions(-) diff --git a/src/otclient/core/creature.cpp b/src/otclient/core/creature.cpp index 573cb784..c40ff5bd 100644 --- a/src/otclient/core/creature.cpp +++ b/src/otclient/core/creature.cpp @@ -32,7 +32,6 @@ Creature::Creature() : Thing(Otc::Creature) { m_healthPercent = 0; m_direction = Otc::South; - m_animation = 0; m_walking = false; m_walkOffsetX = 0; @@ -106,14 +105,15 @@ void Creature::draw(int x, int y) y += m_walkOffsetY; - for(int ydiv = 0; ydiv < attributes.ydiv; ydiv++) { + m_xDiv = m_direction; + for(m_yDiv = 0; m_yDiv < attributes.ydiv; m_yDiv++) { // continue if we dont have this addon. - if(ydiv > 0 && !(m_outfit.addons & (1 << (ydiv-1)))) + if(m_yDiv > 0 && !(m_outfit.addons & (1 << (m_yDiv-1)))) continue; // draw white item - internalDraw(x, y, 0, m_direction, ydiv, 0, m_animation); + internalDraw(x, y, 0); // draw mask if exists if(attributes.blendframes > 1) { @@ -122,19 +122,19 @@ void Creature::draw(int x, int y) // head g_graphics.bindColor(Otc::OutfitColors[m_outfit.head]); - internalDraw(x, y, 1, m_direction, ydiv, 0, m_animation, Otc::SpriteYellowMask); + internalDraw(x, y, 1, Otc::SpriteYellowMask); // body g_graphics.bindColor(Otc::OutfitColors[m_outfit.body]); - internalDraw(x, y, 1, m_direction, ydiv, 0, m_animation, Otc::SpriteRedMask); + internalDraw(x, y, 1, Otc::SpriteRedMask); // legs g_graphics.bindColor(Otc::OutfitColors[m_outfit.legs]); - internalDraw(x, y, 1, m_direction, ydiv, 0, m_animation, Otc::SpriteGreenMask); + internalDraw(x, y, 1, Otc::SpriteGreenMask); // feet g_graphics.bindColor(Otc::OutfitColors[m_outfit.feet]); - internalDraw(x, y, 1, m_direction, ydiv, 0, m_animation, Otc::SpriteBlueMask); + internalDraw(x, y, 1, Otc::SpriteBlueMask); // restore default blend func g_graphics.bindBlendFunc(Fw::BlendDefault); diff --git a/src/otclient/core/creature.h b/src/otclient/core/creature.h index 3fe686d5..8fe6a8ed 100644 --- a/src/otclient/core/creature.h +++ b/src/otclient/core/creature.h @@ -90,7 +90,6 @@ private: double m_walkTime; Position m_walkingFromPosition; double m_walkOffsetX, m_walkOffsetY; - int m_animation; }; #endif diff --git a/src/otclient/core/effect.cpp b/src/otclient/core/effect.cpp index 75163786..af6d3b8b 100644 --- a/src/otclient/core/effect.cpp +++ b/src/otclient/core/effect.cpp @@ -29,7 +29,6 @@ Effect::Effect() : Thing(Otc::Effect) { m_lastTicks = g_platform.getTicks(); - m_animation = 0; m_finished = false; } @@ -47,7 +46,7 @@ void Effect::draw(int x, int y) m_lastTicks = g_platform.getTicks(); } - internalDraw(x, y, 0, 0, 0, 0, m_animation); + internalDraw(x, y, 0); } } diff --git a/src/otclient/core/effect.h b/src/otclient/core/effect.h index e92f4e6d..28dc38cc 100644 --- a/src/otclient/core/effect.h +++ b/src/otclient/core/effect.h @@ -41,7 +41,6 @@ public: private: int m_lastTicks; - int m_animation; bool m_finished; }; diff --git a/src/otclient/core/item.cpp b/src/otclient/core/item.cpp index b5697588..c5a25464 100644 --- a/src/otclient/core/item.cpp +++ b/src/otclient/core/item.cpp @@ -30,61 +30,76 @@ Item::Item() : Thing(Otc::Item) { m_count = 0; m_lastTicks = g_platform.getTicks(); - m_animation = 0; } -void Item::draw(int x, int y) +void Item::setCount(int count) { - const ThingAttributes& attributes = g_dat.getItemAttributes(m_id); - int xdiv = 0, ydiv = 0, zdiv = 0; - + int oldCount = m_count; + m_count = count; + onCountChange(oldCount); +} - if(attributes.animcount > 1) { - if(g_platform.getTicks() - m_lastTicks > 500) { - if(m_animation+1 == attributes.animcount) - m_animation = 0; - else - m_animation++; +void Item::onPositionChange(const Position&) +{ + const ThingAttributes& attributes = g_dat.getItemAttributes(m_id); - m_lastTicks = g_platform.getTicks(); - } + if(!attributes.moveable) { + m_xDiv = m_position.x % attributes.xdiv; + m_yDiv = m_position.y % attributes.ydiv; + m_zDiv = m_position.z % attributes.zdiv; } +} - if(attributes.group == Otc::ThingSplashGroup || attributes.group == Otc::ThingFluidGroup) { - //xdiv = m_count % attributes.xdiv; - //ydiv = m_count / attributes.ydiv; +void Item::onCountChange(int) +{ + const ThingAttributes& attributes = g_dat.getItemAttributes(m_id); - } - else if(attributes.stackable) { + if(attributes.stackable) { if(m_count < 5) { - xdiv = m_count-1; - ydiv = 0; + m_xDiv = m_count-1; + m_yDiv = 0; } else if(m_count < 10) { - xdiv = 0; - ydiv = 1; + m_xDiv = 0; + m_yDiv = 1; } else if(m_count < 25) { - xdiv = 1; - ydiv = 1; + m_xDiv = 1; + m_yDiv = 1; } else if(m_count < 50) { - xdiv = 2; - ydiv = 1; + m_xDiv = 2; + m_yDiv = 1; } else if(m_count <= 100) { - xdiv = 3; - ydiv = 1; + m_xDiv = 3; + m_yDiv = 1; } } - else if(!attributes.moveable) { - xdiv = m_position.x % attributes.xdiv; - ydiv = m_position.y % attributes.ydiv; - zdiv = m_position.z % attributes.zdiv; +} + +void Item::draw(int x, int y) +{ + const ThingAttributes& attributes = g_dat.getItemAttributes(m_id); + + if(attributes.animcount > 1) { + if(g_platform.getTicks() - m_lastTicks > 500) { + if(m_animation+1 == attributes.animcount) + m_animation = 0; + else + m_animation++; + + m_lastTicks = g_platform.getTicks(); + } } + /*if(attributes.group == Otc::ThingSplashGroup || attributes.group == Otc::ThingFluidGroup) { + //xdiv = m_count % attributes.xdiv; + //ydiv = m_count / attributes.ydiv; + }*/ + for(int b = 0; b < attributes.blendframes; b++) - internalDraw(x, y, b, xdiv, ydiv, zdiv, m_animation); + internalDraw(x, y, b); } const ThingAttributes& Item::getAttributes() diff --git a/src/otclient/core/item.h b/src/otclient/core/item.h index 71ecdae6..e7f805c3 100644 --- a/src/otclient/core/item.h +++ b/src/otclient/core/item.h @@ -33,17 +33,19 @@ public: void draw(int x, int y); - void setCount(int count) { m_count = count; } + void setCount(int count); int getCount() { return m_count; } const ThingAttributes& getAttributes(); + void onPositionChange(const Position&); + void onCountChange(int); + ItemPtr asItem() { return std::static_pointer_cast(shared_from_this()); } private: int m_count; int m_lastTicks; - int m_animation; }; #endif diff --git a/src/otclient/core/thing.cpp b/src/otclient/core/thing.cpp index 3eaa4800..6a9baf16 100644 --- a/src/otclient/core/thing.cpp +++ b/src/otclient/core/thing.cpp @@ -26,9 +26,21 @@ Thing::Thing(Otc::ThingType type) : m_id(0), m_type(type) { + m_xDiv = 0; + m_yDiv = 0; + m_zDiv = 0; + m_animation = 0; } -void Thing::internalDraw(int x, int y, int blendframes, int xdiv, int ydiv, int zdiv, int anim, Otc::SpriteMask mask) +void Thing::setPosition(const Position& position) +{ + Position oldPosition = m_position; + m_position = position; + + onPositionChange(oldPosition); +} + +void Thing::internalDraw(int x, int y, int blendframes, Otc::SpriteMask mask) { const ThingAttributes& attributes = getAttributes(); @@ -37,10 +49,10 @@ void Thing::internalDraw(int x, int y, int blendframes, int xdiv, int ydiv, int int sprIndex = xi + yi * attributes.width + blendframes * attributes.width * attributes.height + - xdiv * attributes.width * attributes.height * attributes.blendframes + - ydiv * attributes.width * attributes.height * attributes.blendframes * attributes.xdiv + - zdiv * attributes.width * attributes.height * attributes.blendframes * attributes.xdiv * attributes.ydiv + - anim * attributes.width * attributes.height * attributes.blendframes * attributes.xdiv * attributes.ydiv * attributes.zdiv; + m_xDiv * attributes.width * attributes.height * attributes.blendframes + + m_yDiv * attributes.width * attributes.height * attributes.blendframes * attributes.xdiv + + m_zDiv * attributes.width * attributes.height * attributes.blendframes * attributes.xdiv * attributes.ydiv + + m_animation * attributes.width * attributes.height * attributes.blendframes * attributes.xdiv * attributes.ydiv * attributes.zdiv; int spriteId = attributes.sprites[sprIndex]; if(!spriteId) diff --git a/src/otclient/core/thing.h b/src/otclient/core/thing.h index a9a0991e..b5cdd808 100644 --- a/src/otclient/core/thing.h +++ b/src/otclient/core/thing.h @@ -42,13 +42,15 @@ public: virtual void draw(int x, int y) = 0; void setId(uint32 id) { m_id = id; } - void setPosition(const Position& position) { m_position = position; } + void setPosition(const Position& position); uint32 getId() const { return m_id; } Otc::ThingType getType() const { return m_type; } Position getPosition() const { return m_position; } virtual const ThingAttributes& getAttributes() = 0; + virtual void onPositionChange(const Position&) {} + ThingPtr asThing() { return std::static_pointer_cast(shared_from_this()); } virtual ItemPtr asItem() { return nullptr; } virtual CreaturePtr asCreature() { return nullptr; } @@ -57,11 +59,13 @@ public: virtual LocalPlayerPtr asLocalPlayer() { return nullptr; } protected: - void internalDraw(int x, int y, int blendframes, int xdiv, int ydiv, int zdiv, int anim, Otc::SpriteMask mask = Otc::SpriteNoMask); + void internalDraw(int x, int y, int blendframes, Otc::SpriteMask mask = Otc::SpriteNoMask); uint32 m_id; Otc::ThingType m_type; Position m_position; + + int m_xDiv, m_yDiv, m_zDiv, m_animation; }; #endif