diff --git a/modules/client_topmenu/topmenu.otui b/modules/client_topmenu/topmenu.otui index 0f881d44..67e3190f 100644 --- a/modules/client_topmenu/topmenu.otui +++ b/modules/client_topmenu/topmenu.otui @@ -85,4 +85,4 @@ TopPanel rootWidget:recursiveGetChildById('frameCounter'):setText('FPS: ' .. g_app.getBackgroundPaneFps()) scheduleEvent(updateFunc, 250) end - updateFunc() + addEvent(updateFunc) diff --git a/src/framework/luascript/luaobject.h b/src/framework/luascript/luaobject.h index a12318b2..8d6abcbb 100644 --- a/src/framework/luascript/luaobject.h +++ b/src/framework/luascript/luaobject.h @@ -68,7 +68,7 @@ public: int getUseCount(); /// Returns the derived class name, its the same name used in Lua - virtual std::string getClassName() const { + std::string getClassName() const { // TODO: this could be cached for more performance return stdext::demangle_name(typeid(*this).name()); } diff --git a/src/framework/util/matrix.h b/src/framework/util/matrix.h index 4e83aa32..dd27d217 100644 --- a/src/framework/util/matrix.h +++ b/src/framework/util/matrix.h @@ -170,11 +170,7 @@ bool Matrix::operator==(const Matrix& other) const template bool Matrix::operator!=(const Matrix& other) const { - for(int i=0;i @@ -200,6 +196,17 @@ std::istream& operator>>(std::istream& in, Matrix& mat) return in; } +// faster comparing for 3x3 matrixes +template<> +inline bool Matrix<3,3,float>::operator==(const Matrix<3,3,float>& other) const +{ + return m[0][0] == other.m[0][0] && m[1][1] == other.m[1][1] && + m[2][1] == other.m[2][1] && m[2][0] == other.m[2][0] && + m[1][2] == other.m[1][2] && m[0][2] == other.m[0][2] && + m[1][0] == other.m[1][0] && m[0][1] == other.m[0][1] && + m[2][2] == other.m[2][2]; +} + typedef Matrix<4,4> Matrix4x4; typedef Matrix<3,3> Matrix3x3; typedef Matrix<2,2> Matrix2x2; diff --git a/src/otclient/core/animatedtext.h b/src/otclient/core/animatedtext.h index cb32d3a8..66cf42a2 100644 --- a/src/otclient/core/animatedtext.h +++ b/src/otclient/core/animatedtext.h @@ -39,6 +39,7 @@ public: void setText(const std::string& text); AnimatedTextPtr asAnimatedText() { return std::static_pointer_cast(shared_from_this()); } + bool isAnimatedText() { return true; } private: FontPtr m_font; diff --git a/src/otclient/core/creature.cpp b/src/otclient/core/creature.cpp index 08efb89c..bd39db22 100644 --- a/src/otclient/core/creature.cpp +++ b/src/otclient/core/creature.cpp @@ -201,12 +201,10 @@ void Creature::drawOutfit(const Rect& destRect, bool resize) if(!outfitBuffer) outfitBuffer = FrameBufferPtr(new FrameBuffer(Size(2*Otc::TILE_PIXELS, 2*Otc::TILE_PIXELS))); - g_painter->saveAndResetState(); outfitBuffer->bind(); outfitBuffer->clear(Color::alpha); internalDrawOutfit(Point(Otc::TILE_PIXELS,Otc::TILE_PIXELS) + getDisplacement(), 1, false, true, Otc::South); outfitBuffer->release(); - g_painter->restoreSavedState(); Rect srcRect; if(resize) diff --git a/src/otclient/core/creature.h b/src/otclient/core/creature.h index bddfd328..8a3a0b35 100644 --- a/src/otclient/core/creature.h +++ b/src/otclient/core/creature.h @@ -92,6 +92,7 @@ public: bool isRemoved() { return m_removed; } CreaturePtr asCreature() { return std::static_pointer_cast(shared_from_this()); } + bool isCreature() { return true; } protected: virtual void updateWalkAnimation(int totalPixelsWalked); @@ -142,11 +143,13 @@ protected: class Npc : public Creature { public: NpcPtr asNpc() { return std::static_pointer_cast(shared_from_this()); } + bool isNpc() { return true; } }; class Monster : public Creature { public: MonsterPtr asMonster() { return std::static_pointer_cast(shared_from_this()); } + bool isMonster() { return true; } }; #endif diff --git a/src/otclient/core/effect.h b/src/otclient/core/effect.h index fb1794b5..1e46c63b 100644 --- a/src/otclient/core/effect.h +++ b/src/otclient/core/effect.h @@ -36,7 +36,9 @@ public: void startAnimation(); uint32 getId() { return m_id; } + EffectPtr asEffect() { return std::static_pointer_cast(shared_from_this()); } + bool isEffect() { return true; } private: Timer m_animationTimer; diff --git a/src/otclient/core/item.h b/src/otclient/core/item.h index 8a06aa0c..be2998c5 100644 --- a/src/otclient/core/item.h +++ b/src/otclient/core/item.h @@ -46,6 +46,7 @@ public: uint32 getId() { return m_id; } ItemPtr asItem() { return std::static_pointer_cast(shared_from_this()); } + bool isItem() { return true; } private: uint16 m_id; diff --git a/src/otclient/core/localplayer.h b/src/otclient/core/localplayer.h index 03087d96..19c8a138 100644 --- a/src/otclient/core/localplayer.h +++ b/src/otclient/core/localplayer.h @@ -74,6 +74,7 @@ public: bool isAutoWalking() { return m_autoWalking; } LocalPlayerPtr asLocalPlayer() { return std::static_pointer_cast(shared_from_this()); } + bool isLocalPlayer() { return true; } protected: void walk(const Position& oldPos, const Position& newPos); diff --git a/src/otclient/core/mapview.cpp b/src/otclient/core/mapview.cpp index 25234251..c4f5728b 100644 --- a/src/otclient/core/mapview.cpp +++ b/src/otclient/core/mapview.cpp @@ -90,16 +90,16 @@ void MapView::draw(const Rect& rect) ++it; if(!m_drawMinimapColors) - tile->draw(transformPositionTo2D(tilePos), scaleFactor, drawFlags); + tile->draw(transformPositionTo2D(tilePos, cameraPosition), scaleFactor, drawFlags); else { g_painter->setColor(tile->getMinimapColor()); - g_painter->drawFilledRect(Rect(transformPositionTo2D(tilePos), tileSize)); + g_painter->drawFilledRect(Rect(transformPositionTo2D(tilePos, cameraPosition), tileSize)); } } if(drawFlags & Otc::DrawMissiles && !m_drawMinimapColors) { for(const MissilePtr& missile : g_map.getFloorMissiles(z)) { - missile->draw(transformPositionTo2D(missile->getPosition()), scaleFactor, drawFlags & Otc::DrawAnimations); + missile->draw(transformPositionTo2D(missile->getPosition(), cameraPosition), scaleFactor, drawFlags & Otc::DrawAnimations); } } } @@ -156,7 +156,7 @@ void MapView::draw(const Rect& rect) for(const CreaturePtr& creature : m_cachedFloorVisibleCreatures) { Point creatureOffset = Point(16 - creature->getDisplacementX(), -3 - creature->getDisplacementY()); Position pos = creature->getPosition(); - Point p = transformPositionTo2D(pos) - drawOffset; + Point p = transformPositionTo2D(pos, cameraPosition) - drawOffset; p += (creature->getDrawOffset() + creatureOffset) * scaleFactor; p.x = p.x * horizontalStretchFactor; p.y = p.y * verticalStretchFactor; @@ -169,10 +169,10 @@ void MapView::draw(const Rect& rect) Position pos = staticText->getPosition(); // ony draw static texts from current camera floor, unless yells - if(pos.z != getCameraPosition().z && !staticText->isYell()) + if(pos.z != cameraPosition.z && !staticText->isYell()) continue; - Point p = transformPositionTo2D(pos) - drawOffset; + Point p = transformPositionTo2D(pos, cameraPosition) - drawOffset; p.x = p.x * horizontalStretchFactor; p.y = p.y * verticalStretchFactor; p += rect.topLeft(); @@ -190,7 +190,7 @@ void MapView::draw(const Rect& rect) if(pos.z != cameraPosition.z && g_map.isCovered(pos, m_cachedFirstVisibleFloor)) continue; - Point p = transformPositionTo2D(pos) - drawOffset; + Point p = transformPositionTo2D(pos, cameraPosition) - drawOffset; p.x = p.x * horizontalStretchFactor; p.y = p.y * verticalStretchFactor; p += rect.topLeft(); @@ -648,10 +648,3 @@ TilePtr MapView::getTile(const Point& mousePos, const Rect& mapRect) return tile; } - -Point MapView::transformPositionTo2D(const Position& position) -{ - Position cameraPosition = getCameraPosition(); - return Point((m_virtualCenterOffset.x + (position.x - cameraPosition.x) - (cameraPosition.z - position.z)) * m_tileSize, - (m_virtualCenterOffset.y + (position.y - cameraPosition.y) - (cameraPosition.z - position.z)) * m_tileSize); -} diff --git a/src/otclient/core/mapview.h b/src/otclient/core/mapview.h index 6da8265b..0c9d7153 100644 --- a/src/otclient/core/mapview.h +++ b/src/otclient/core/mapview.h @@ -111,7 +111,10 @@ public: private: int calcFirstVisibleFloor(); int calcLastVisibleFloor(); - Point transformPositionTo2D(const Position& position); + Point transformPositionTo2D(const Position& position, const Position& relativePosition) { + return Point((m_virtualCenterOffset.x + (position.x - relativePosition.x) - (relativePosition.z - position.z)) * m_tileSize, + (m_virtualCenterOffset.y + (position.y - relativePosition.y) - (relativePosition.z - position.z)) * m_tileSize); + } int m_lockedFirstVisibleFloor; int m_cachedFirstVisibleFloor; diff --git a/src/otclient/core/missile.h b/src/otclient/core/missile.h index 4b3a48fc..858768f2 100644 --- a/src/otclient/core/missile.h +++ b/src/otclient/core/missile.h @@ -44,6 +44,7 @@ public: uint32 getId() { return m_id; } MissilePtr asMissile() { return std::static_pointer_cast(shared_from_this()); } + bool isMissile() { return true; } private: Timer m_animationTimer; diff --git a/src/otclient/core/player.h b/src/otclient/core/player.h index 461c4069..8c7c50ef 100644 --- a/src/otclient/core/player.h +++ b/src/otclient/core/player.h @@ -32,6 +32,7 @@ public: virtual ~Player() { } PlayerPtr asPlayer() { return std::static_pointer_cast(shared_from_this()); } + bool isPlayer() { return true; } }; #endif diff --git a/src/otclient/core/statictext.h b/src/otclient/core/statictext.h index 626af781..bfccfda1 100644 --- a/src/otclient/core/statictext.h +++ b/src/otclient/core/statictext.h @@ -43,6 +43,7 @@ public: void removeMessage(); StaticTextPtr asStaticText() { return std::static_pointer_cast(shared_from_this()); } + bool isStaticText() { return true; } private: void compose(); diff --git a/src/otclient/core/thing.h b/src/otclient/core/thing.h index 78daada6..d7022cc7 100644 --- a/src/otclient/core/thing.h +++ b/src/otclient/core/thing.h @@ -64,6 +64,17 @@ public: virtual AnimatedTextPtr asAnimatedText() { return nullptr; } virtual StaticTextPtr asStaticText() { return nullptr; } + virtual bool isItem() { return false; } + virtual bool isEffect() { return false; } + virtual bool isMissile() { return false; } + virtual bool isCreature() { return false; } + virtual bool isNpc() { return false; } + virtual bool isMonster() { return false; } + virtual bool isPlayer() { return false; } + virtual bool isLocalPlayer() { return false; } + virtual bool isAnimatedText() { return false; } + virtual bool isStaticText() { return false; } + // type related bool isGround() { return m_type->getProperty(ThingType::IsGround); } bool isFullGround() { return m_type->getProperty(ThingType::IsFullGround); } diff --git a/src/otclient/core/thingtype.cpp b/src/otclient/core/thingtype.cpp index 556f8965..a26b3455 100644 --- a/src/otclient/core/thingtype.cpp +++ b/src/otclient/core/thingtype.cpp @@ -30,6 +30,7 @@ ThingType::ThingType() { + m_category = 0; m_dimensions.fill(0); m_parameters.fill(0); m_properties.fill(false); @@ -47,7 +48,6 @@ void ThingType::draw(const Point& dest, float scaleFactor, int layer, int xPatte Rect screenRect(dest + (-displacement + textureOffset - Point(m_dimensions[Width] - 1, m_dimensions[Height] - 1) * Otc::TILE_PIXELS) * scaleFactor, textureRect.size() * scaleFactor); - g_painter->setColor(Color::white); g_painter->drawTexturedRect(screenRect, texture, textureRect); } diff --git a/src/otclient/core/tile.cpp b/src/otclient/core/tile.cpp index cd358617..b6472c9b 100644 --- a/src/otclient/core/tile.cpp +++ b/src/otclient/core/tile.cpp @@ -65,7 +65,7 @@ void Tile::draw(const Point& dest, float scaleFactor, int drawFlags) // now common items in reverse order for(auto it = m_things.rbegin(); it != m_things.rend(); ++it) { const ThingPtr& thing = *it; - if(thing->isOnTop() || thing->isOnBottom() || thing->isGroundBorder() || thing->isGround() || thing->asCreature()) + if(thing->isOnTop() || thing->isOnBottom() || thing->isGroundBorder() || thing->isGround() || thing->isCreature()) break; thing->draw(dest - m_drawElevation*scaleFactor, scaleFactor, animate); @@ -109,7 +109,10 @@ void Tile::draw(const Point& dest, float scaleFactor, int drawFlags) } for(auto it = m_things.rbegin(); it != m_things.rend(); ++it) { - CreaturePtr creature = (*it)->asCreature(); + const ThingPtr& thing = *it; + if(!thing->isCreature()) + continue; + CreaturePtr creature = thing->asCreature(); if(creature && (!creature->isWalking() || !animate)) creature->draw(dest - m_drawElevation*scaleFactor, scaleFactor, animate); } @@ -312,7 +315,7 @@ ThingPtr Tile::getTopUseThing() for(uint i = 0; i < m_things.size(); ++i) { ThingPtr thing = m_things[i]; - if(thing->isForceUse() || (!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop() && !thing->asCreature())) + if(thing->isForceUse() || (!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop() && !thing->isCreature())) return thing; } @@ -326,7 +329,7 @@ CreaturePtr Tile::getTopCreature() ThingPtr thing = m_things[i]; if(thing->asLocalPlayer()) // return local player if there is no other creature creature = thing->asCreature(); - else if(thing->asCreature() && !thing->asLocalPlayer()) + else if(thing->isCreature() && !thing->isLocalPlayer()) return thing->asCreature(); } if(!creature && !m_walkingCreatures.empty()) @@ -341,7 +344,7 @@ ThingPtr Tile::getTopMoveThing() for(uint i = 0; i < m_things.size(); ++i) { ThingPtr thing = m_things[i]; - if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop() && !thing->asCreature()) { + if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop() && !thing->isCreature()) { if(i > 0 && thing->isNotMoveable()) return m_things[i-1]; return thing; diff --git a/src/otclient/luafunctions.cpp b/src/otclient/luafunctions.cpp index a56de2fc..8a9e034f 100644 --- a/src/otclient/luafunctions.cpp +++ b/src/otclient/luafunctions.cpp @@ -228,6 +228,14 @@ void OTClient::registerLuaFunctions() g_lua.bindClassMemberFunction("asLocalPlayer", &Thing::asLocalPlayer); g_lua.bindClassMemberFunction("asAnimatedText", &Thing::asAnimatedText); g_lua.bindClassMemberFunction("asStaticText", &Thing::asStaticText); + g_lua.bindClassMemberFunction("isItem", &Thing::isItem); + g_lua.bindClassMemberFunction("isCreature", &Thing::isCreature); + g_lua.bindClassMemberFunction("isEffect", &Thing::isEffect); + g_lua.bindClassMemberFunction("isMissile", &Thing::isMissile); + g_lua.bindClassMemberFunction("isPlayer", &Thing::isPlayer); + g_lua.bindClassMemberFunction("isLocalPlayer", &Thing::isLocalPlayer); + g_lua.bindClassMemberFunction("isAnimatedText", &Thing::isAnimatedText); + g_lua.bindClassMemberFunction("isStaticText", &Thing::isStaticText); g_lua.bindClassMemberFunction("isGround", &Thing::isGround); g_lua.bindClassMemberFunction("isGroundBorder", &Thing::isGroundBorder); g_lua.bindClassMemberFunction("isOnBottom", &Thing::isOnBottom); diff --git a/src/otclient/ui/uicreature.cpp b/src/otclient/ui/uicreature.cpp index 99581fdb..d0ce16ca 100644 --- a/src/otclient/ui/uicreature.cpp +++ b/src/otclient/ui/uicreature.cpp @@ -32,8 +32,8 @@ void UICreature::drawSelf(bool foregroundPane) UIWidget::drawSelf(foregroundPane); if(m_creature) { - g_painter->setColor(Color::white); Rect drawRect = getPaddingRect(); + g_painter->setColor(Color::white); m_creature->drawOutfit(drawRect, !m_fixedCreatureSize); } }