From 9bff1aa6eae5fa72d89020e882b414c6cfe3467c Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Wed, 8 Feb 2012 03:13:52 -0200 Subject: [PATCH] changes in creature drawing for battle list --- src/otclient/core/creature.cpp | 49 +++++++++++++++++++++++++++------- src/otclient/core/creature.h | 2 ++ src/otclient/ui/uicreature.cpp | 12 +-------- 3 files changed, 43 insertions(+), 20 deletions(-) diff --git a/src/otclient/core/creature.cpp b/src/otclient/core/creature.cpp index 18cb00b2..64992331 100644 --- a/src/otclient/core/creature.cpp +++ b/src/otclient/core/creature.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include "spritemanager.h" Creature::Creature() : Thing() @@ -78,6 +79,12 @@ void Creature::draw(const Point& dest, float scaleFactor, bool animate) g_painter.drawBoundingRect(Rect(dest + (animationOffset - getDisplacement() + 1)*scaleFactor, Size(Otc::TILE_PIXELS, Otc::TILE_PIXELS)*scaleFactor), std::max((int)(2*scaleFactor), 1)); } + internalDrawOutfit(dest + animationOffset * scaleFactor, scaleFactor, animate, animate, m_direction); + +} + +void Creature::internalDrawOutfit(const Point& dest, float scaleFactor, bool animateWalk, bool animateIdle, Otc::Direction direction) +{ g_painter.setColor(Fw::white); if(!outfitProgram) { outfitProgram = PainterShaderProgramPtr(new PainterShaderProgram); @@ -95,19 +102,20 @@ void Creature::draw(const Point& dest, float scaleFactor, bool animate) // outfit is a real creature if(m_outfit.getCategory() == ThingsType::Creature) { - int animationPhase = animate ? m_walkAnimationPhase : 0; - if(isAnimateAlways()) { + int animationPhase = animateWalk ? m_walkAnimationPhase : 0; + + if(isAnimateAlways() && animateIdle) { int ticksPerFrame = 1000 / getAnimationPhases(); animationPhase = (g_clock.ticks() % (ticksPerFrame * getAnimationPhases())) / ticksPerFrame; } // xPattern => creature direction - if(m_direction == Otc::NorthEast || m_direction == Otc::SouthEast) + if(direction == Otc::NorthEast || direction == Otc::SouthEast) xPattern = Otc::East; - else if(m_direction == Otc::NorthWest || m_direction == Otc::SouthWest) + else if(direction == Otc::NorthWest || direction == Otc::SouthWest) xPattern = Otc::West; else - xPattern = m_direction; + xPattern = direction; // yPattern => creature addon for(yPattern = 0; yPattern < getNumPatternsY(); yPattern++) { @@ -129,12 +137,12 @@ void Creature::draw(const Point& dest, float scaleFactor, bool animate) // setup texture outfit mask TexturePtr maskTex; if(getLayers() > 1) { - int maskId = getSpriteId(w, h, 1, xPattern, yPattern, zPattern, m_walkAnimationPhase); + int maskId = getSpriteId(w, h, 1, xPattern, yPattern, zPattern, animationPhase); maskTex = g_sprites.getSpriteTexture(maskId); } outfitProgram->setUniformTexture(MASK_TEXTURE_UNIFORM, maskTex, 1); - internalDraw(dest + (animationOffset - Point(w,h)*Otc::TILE_PIXELS)*scaleFactor, + internalDraw(dest + (-Point(w,h)*Otc::TILE_PIXELS)*scaleFactor, scaleFactor, w, h, xPattern, yPattern, zPattern, 0, animationPhase); } } @@ -155,7 +163,7 @@ void Creature::draw(const Point& dest, float scaleFactor, bool animate) } if(animationPhases > 1) { - if(animate) + if(animateIdle) animationPhase = (g_clock.ticks() % (animateTicks * animationPhases)) / animateTicks; else animationPhase = animationPhases-1; @@ -164,7 +172,30 @@ void Creature::draw(const Point& dest, float scaleFactor, bool animate) if(m_outfit.getCategory() == ThingsType::Effect) animationPhase = std::min(animationPhase+1, getAnimationPhases()); - internalDraw(dest + animationOffset*scaleFactor, scaleFactor, 0, 0, 0, animationPhase); + internalDraw(dest, scaleFactor, 0, 0, 0, animationPhase); + } +} + +void Creature::drawOutfit(const Rect& destRect, bool resize) +{ + static FrameBufferPtr outfitBuffer; + if(!outfitBuffer) + outfitBuffer = FrameBufferPtr(new FrameBuffer(Size(2*Otc::TILE_PIXELS, 2*Otc::TILE_PIXELS))); + + outfitBuffer->bind(); + internalDrawOutfit(Point(Otc::TILE_PIXELS,Otc::TILE_PIXELS) + getDisplacement(), 1, false, true, Otc::South); + outfitBuffer->release(); + + if(resize) { + Rect srcRect; + srcRect.resize(getExactSize(), getExactSize()); + srcRect.moveBottomRight(Point(2*Otc::TILE_PIXELS, 2*Otc::TILE_PIXELS)); + outfitBuffer->draw(destRect, srcRect); + } else { + Rect dest = destRect; + dest.expandTop(Otc::TILE_PIXELS); + dest.expandLeft(Otc::TILE_PIXELS); + outfitBuffer->draw(dest); } } diff --git a/src/otclient/core/creature.h b/src/otclient/core/creature.h index 12cb5327..fd461c5f 100644 --- a/src/otclient/core/creature.h +++ b/src/otclient/core/creature.h @@ -41,6 +41,8 @@ public: virtual ~Creature() { } virtual void draw(const Point& dest, float scaleFactor, bool animate); + void internalDrawOutfit(const Point& dest, float scaleFactor, bool animateWalk, bool animateIdle, Otc::Direction direction); + void drawOutfit(const Rect& destRect, bool resize); void drawInformation(const Point& point, bool useGray, const Rect& parentRect); void setId(uint32 id) { m_id = id; } diff --git a/src/otclient/ui/uicreature.cpp b/src/otclient/ui/uicreature.cpp index 8edad2d0..543586d0 100644 --- a/src/otclient/ui/uicreature.cpp +++ b/src/otclient/ui/uicreature.cpp @@ -28,20 +28,10 @@ void UICreature::draw() { drawSelf(); - //TODO: cache with framebuffer if(m_creature) { g_painter.setColor(Fw::white); - Rect drawRect = getChildrenRect(); - - float scaleFactor = drawRect.width(); - if(m_fixedCreatureSize) - scaleFactor /= Otc::TILE_PIXELS; - else - scaleFactor /= m_creature->getExactSize(); - - Point dest = drawRect.bottomRight() - (Point(1,1)*Otc::TILE_PIXELS - m_creature->getDisplacement()) * scaleFactor; - m_creature->draw(dest, scaleFactor, false); + m_creature->drawOutfit(drawRect, !m_fixedCreatureSize); } drawChildren();