performance improvements

master
Eduardo Bart 12 years ago
parent 4de9787198
commit 023a4ebef6

@ -85,4 +85,4 @@ TopPanel
rootWidget:recursiveGetChildById('frameCounter'):setText('FPS: ' .. g_app.getBackgroundPaneFps()) rootWidget:recursiveGetChildById('frameCounter'):setText('FPS: ' .. g_app.getBackgroundPaneFps())
scheduleEvent(updateFunc, 250) scheduleEvent(updateFunc, 250)
end end
updateFunc() addEvent(updateFunc)

@ -68,7 +68,7 @@ public:
int getUseCount(); int getUseCount();
/// Returns the derived class name, its the same name used in Lua /// 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 // TODO: this could be cached for more performance
return stdext::demangle_name(typeid(*this).name()); return stdext::demangle_name(typeid(*this).name());
} }

@ -170,11 +170,7 @@ bool Matrix<N,M,T>::operator==(const Matrix<N,M,T>& other) const
template<int N, int M, typename T> template<int N, int M, typename T>
bool Matrix<N,M,T>::operator!=(const Matrix<N,M,T>& other) const bool Matrix<N,M,T>::operator!=(const Matrix<N,M,T>& other) const
{ {
for(int i=0;i<N;++i) return !(*this == other);
for(int j=0;j<M;++j)
if(m[i][j] != other.m[i][j])
return true;
return false;
} }
template<int N, int M, typename T> template<int N, int M, typename T>
@ -200,6 +196,17 @@ std::istream& operator>>(std::istream& in, Matrix<N,M,T>& mat)
return in; 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<4,4> Matrix4x4;
typedef Matrix<3,3> Matrix3x3; typedef Matrix<3,3> Matrix3x3;
typedef Matrix<2,2> Matrix2x2; typedef Matrix<2,2> Matrix2x2;

@ -39,6 +39,7 @@ public:
void setText(const std::string& text); void setText(const std::string& text);
AnimatedTextPtr asAnimatedText() { return std::static_pointer_cast<AnimatedText>(shared_from_this()); } AnimatedTextPtr asAnimatedText() { return std::static_pointer_cast<AnimatedText>(shared_from_this()); }
bool isAnimatedText() { return true; }
private: private:
FontPtr m_font; FontPtr m_font;

@ -201,12 +201,10 @@ void Creature::drawOutfit(const Rect& destRect, bool resize)
if(!outfitBuffer) if(!outfitBuffer)
outfitBuffer = FrameBufferPtr(new FrameBuffer(Size(2*Otc::TILE_PIXELS, 2*Otc::TILE_PIXELS))); outfitBuffer = FrameBufferPtr(new FrameBuffer(Size(2*Otc::TILE_PIXELS, 2*Otc::TILE_PIXELS)));
g_painter->saveAndResetState();
outfitBuffer->bind(); outfitBuffer->bind();
outfitBuffer->clear(Color::alpha); outfitBuffer->clear(Color::alpha);
internalDrawOutfit(Point(Otc::TILE_PIXELS,Otc::TILE_PIXELS) + getDisplacement(), 1, false, true, Otc::South); internalDrawOutfit(Point(Otc::TILE_PIXELS,Otc::TILE_PIXELS) + getDisplacement(), 1, false, true, Otc::South);
outfitBuffer->release(); outfitBuffer->release();
g_painter->restoreSavedState();
Rect srcRect; Rect srcRect;
if(resize) if(resize)

@ -92,6 +92,7 @@ public:
bool isRemoved() { return m_removed; } bool isRemoved() { return m_removed; }
CreaturePtr asCreature() { return std::static_pointer_cast<Creature>(shared_from_this()); } CreaturePtr asCreature() { return std::static_pointer_cast<Creature>(shared_from_this()); }
bool isCreature() { return true; }
protected: protected:
virtual void updateWalkAnimation(int totalPixelsWalked); virtual void updateWalkAnimation(int totalPixelsWalked);
@ -142,11 +143,13 @@ protected:
class Npc : public Creature { class Npc : public Creature {
public: public:
NpcPtr asNpc() { return std::static_pointer_cast<Npc>(shared_from_this()); } NpcPtr asNpc() { return std::static_pointer_cast<Npc>(shared_from_this()); }
bool isNpc() { return true; }
}; };
class Monster : public Creature { class Monster : public Creature {
public: public:
MonsterPtr asMonster() { return std::static_pointer_cast<Monster>(shared_from_this()); } MonsterPtr asMonster() { return std::static_pointer_cast<Monster>(shared_from_this()); }
bool isMonster() { return true; }
}; };
#endif #endif

@ -36,7 +36,9 @@ public:
void startAnimation(); void startAnimation();
uint32 getId() { return m_id; } uint32 getId() { return m_id; }
EffectPtr asEffect() { return std::static_pointer_cast<Effect>(shared_from_this()); } EffectPtr asEffect() { return std::static_pointer_cast<Effect>(shared_from_this()); }
bool isEffect() { return true; }
private: private:
Timer m_animationTimer; Timer m_animationTimer;

@ -46,6 +46,7 @@ public:
uint32 getId() { return m_id; } uint32 getId() { return m_id; }
ItemPtr asItem() { return std::static_pointer_cast<Item>(shared_from_this()); } ItemPtr asItem() { return std::static_pointer_cast<Item>(shared_from_this()); }
bool isItem() { return true; }
private: private:
uint16 m_id; uint16 m_id;

@ -74,6 +74,7 @@ public:
bool isAutoWalking() { return m_autoWalking; } bool isAutoWalking() { return m_autoWalking; }
LocalPlayerPtr asLocalPlayer() { return std::static_pointer_cast<LocalPlayer>(shared_from_this()); } LocalPlayerPtr asLocalPlayer() { return std::static_pointer_cast<LocalPlayer>(shared_from_this()); }
bool isLocalPlayer() { return true; }
protected: protected:
void walk(const Position& oldPos, const Position& newPos); void walk(const Position& oldPos, const Position& newPos);

@ -90,16 +90,16 @@ void MapView::draw(const Rect& rect)
++it; ++it;
if(!m_drawMinimapColors) if(!m_drawMinimapColors)
tile->draw(transformPositionTo2D(tilePos), scaleFactor, drawFlags); tile->draw(transformPositionTo2D(tilePos, cameraPosition), scaleFactor, drawFlags);
else { else {
g_painter->setColor(tile->getMinimapColor()); 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) { if(drawFlags & Otc::DrawMissiles && !m_drawMinimapColors) {
for(const MissilePtr& missile : g_map.getFloorMissiles(z)) { 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) { for(const CreaturePtr& creature : m_cachedFloorVisibleCreatures) {
Point creatureOffset = Point(16 - creature->getDisplacementX(), -3 - creature->getDisplacementY()); Point creatureOffset = Point(16 - creature->getDisplacementX(), -3 - creature->getDisplacementY());
Position pos = creature->getPosition(); Position pos = creature->getPosition();
Point p = transformPositionTo2D(pos) - drawOffset; Point p = transformPositionTo2D(pos, cameraPosition) - drawOffset;
p += (creature->getDrawOffset() + creatureOffset) * scaleFactor; p += (creature->getDrawOffset() + creatureOffset) * scaleFactor;
p.x = p.x * horizontalStretchFactor; p.x = p.x * horizontalStretchFactor;
p.y = p.y * verticalStretchFactor; p.y = p.y * verticalStretchFactor;
@ -169,10 +169,10 @@ void MapView::draw(const Rect& rect)
Position pos = staticText->getPosition(); Position pos = staticText->getPosition();
// ony draw static texts from current camera floor, unless yells // 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; continue;
Point p = transformPositionTo2D(pos) - drawOffset; Point p = transformPositionTo2D(pos, cameraPosition) - drawOffset;
p.x = p.x * horizontalStretchFactor; p.x = p.x * horizontalStretchFactor;
p.y = p.y * verticalStretchFactor; p.y = p.y * verticalStretchFactor;
p += rect.topLeft(); p += rect.topLeft();
@ -190,7 +190,7 @@ void MapView::draw(const Rect& rect)
if(pos.z != cameraPosition.z && g_map.isCovered(pos, m_cachedFirstVisibleFloor)) if(pos.z != cameraPosition.z && g_map.isCovered(pos, m_cachedFirstVisibleFloor))
continue; continue;
Point p = transformPositionTo2D(pos) - drawOffset; Point p = transformPositionTo2D(pos, cameraPosition) - drawOffset;
p.x = p.x * horizontalStretchFactor; p.x = p.x * horizontalStretchFactor;
p.y = p.y * verticalStretchFactor; p.y = p.y * verticalStretchFactor;
p += rect.topLeft(); p += rect.topLeft();
@ -648,10 +648,3 @@ TilePtr MapView::getTile(const Point& mousePos, const Rect& mapRect)
return tile; 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);
}

@ -111,7 +111,10 @@ public:
private: private:
int calcFirstVisibleFloor(); int calcFirstVisibleFloor();
int calcLastVisibleFloor(); 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_lockedFirstVisibleFloor;
int m_cachedFirstVisibleFloor; int m_cachedFirstVisibleFloor;

@ -44,6 +44,7 @@ public:
uint32 getId() { return m_id; } uint32 getId() { return m_id; }
MissilePtr asMissile() { return std::static_pointer_cast<Missile>(shared_from_this()); } MissilePtr asMissile() { return std::static_pointer_cast<Missile>(shared_from_this()); }
bool isMissile() { return true; }
private: private:
Timer m_animationTimer; Timer m_animationTimer;

@ -32,6 +32,7 @@ public:
virtual ~Player() { } virtual ~Player() { }
PlayerPtr asPlayer() { return std::static_pointer_cast<Player>(shared_from_this()); } PlayerPtr asPlayer() { return std::static_pointer_cast<Player>(shared_from_this()); }
bool isPlayer() { return true; }
}; };
#endif #endif

@ -43,6 +43,7 @@ public:
void removeMessage(); void removeMessage();
StaticTextPtr asStaticText() { return std::static_pointer_cast<StaticText>(shared_from_this()); } StaticTextPtr asStaticText() { return std::static_pointer_cast<StaticText>(shared_from_this()); }
bool isStaticText() { return true; }
private: private:
void compose(); void compose();

@ -64,6 +64,17 @@ public:
virtual AnimatedTextPtr asAnimatedText() { return nullptr; } virtual AnimatedTextPtr asAnimatedText() { return nullptr; }
virtual StaticTextPtr asStaticText() { 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 // type related
bool isGround() { return m_type->getProperty(ThingType::IsGround); } bool isGround() { return m_type->getProperty(ThingType::IsGround); }
bool isFullGround() { return m_type->getProperty(ThingType::IsFullGround); } bool isFullGround() { return m_type->getProperty(ThingType::IsFullGround); }

@ -30,6 +30,7 @@
ThingType::ThingType() ThingType::ThingType()
{ {
m_category = 0;
m_dimensions.fill(0); m_dimensions.fill(0);
m_parameters.fill(0); m_parameters.fill(0);
m_properties.fill(false); 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, Rect screenRect(dest + (-displacement + textureOffset - Point(m_dimensions[Width] - 1, m_dimensions[Height] - 1) * Otc::TILE_PIXELS) * scaleFactor,
textureRect.size() * scaleFactor); textureRect.size() * scaleFactor);
g_painter->setColor(Color::white);
g_painter->drawTexturedRect(screenRect, texture, textureRect); g_painter->drawTexturedRect(screenRect, texture, textureRect);
} }

@ -65,7 +65,7 @@ void Tile::draw(const Point& dest, float scaleFactor, int drawFlags)
// now common items in reverse order // now common items in reverse order
for(auto it = m_things.rbegin(); it != m_things.rend(); ++it) { for(auto it = m_things.rbegin(); it != m_things.rend(); ++it) {
const ThingPtr& thing = *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; break;
thing->draw(dest - m_drawElevation*scaleFactor, scaleFactor, animate); 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) { 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)) if(creature && (!creature->isWalking() || !animate))
creature->draw(dest - m_drawElevation*scaleFactor, scaleFactor, 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) { for(uint i = 0; i < m_things.size(); ++i) {
ThingPtr thing = m_things[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; return thing;
} }
@ -326,7 +329,7 @@ CreaturePtr Tile::getTopCreature()
ThingPtr thing = m_things[i]; ThingPtr thing = m_things[i];
if(thing->asLocalPlayer()) // return local player if there is no other creature if(thing->asLocalPlayer()) // return local player if there is no other creature
creature = thing->asCreature(); creature = thing->asCreature();
else if(thing->asCreature() && !thing->asLocalPlayer()) else if(thing->isCreature() && !thing->isLocalPlayer())
return thing->asCreature(); return thing->asCreature();
} }
if(!creature && !m_walkingCreatures.empty()) if(!creature && !m_walkingCreatures.empty())
@ -341,7 +344,7 @@ ThingPtr Tile::getTopMoveThing()
for(uint i = 0; i < m_things.size(); ++i) { for(uint i = 0; i < m_things.size(); ++i) {
ThingPtr thing = m_things[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()) if(i > 0 && thing->isNotMoveable())
return m_things[i-1]; return m_things[i-1];
return thing; return thing;

@ -228,6 +228,14 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassMemberFunction<Thing>("asLocalPlayer", &Thing::asLocalPlayer); g_lua.bindClassMemberFunction<Thing>("asLocalPlayer", &Thing::asLocalPlayer);
g_lua.bindClassMemberFunction<Thing>("asAnimatedText", &Thing::asAnimatedText); g_lua.bindClassMemberFunction<Thing>("asAnimatedText", &Thing::asAnimatedText);
g_lua.bindClassMemberFunction<Thing>("asStaticText", &Thing::asStaticText); g_lua.bindClassMemberFunction<Thing>("asStaticText", &Thing::asStaticText);
g_lua.bindClassMemberFunction<Thing>("isItem", &Thing::isItem);
g_lua.bindClassMemberFunction<Thing>("isCreature", &Thing::isCreature);
g_lua.bindClassMemberFunction<Thing>("isEffect", &Thing::isEffect);
g_lua.bindClassMemberFunction<Thing>("isMissile", &Thing::isMissile);
g_lua.bindClassMemberFunction<Thing>("isPlayer", &Thing::isPlayer);
g_lua.bindClassMemberFunction<Thing>("isLocalPlayer", &Thing::isLocalPlayer);
g_lua.bindClassMemberFunction<Thing>("isAnimatedText", &Thing::isAnimatedText);
g_lua.bindClassMemberFunction<Thing>("isStaticText", &Thing::isStaticText);
g_lua.bindClassMemberFunction<Thing>("isGround", &Thing::isGround); g_lua.bindClassMemberFunction<Thing>("isGround", &Thing::isGround);
g_lua.bindClassMemberFunction<Thing>("isGroundBorder", &Thing::isGroundBorder); g_lua.bindClassMemberFunction<Thing>("isGroundBorder", &Thing::isGroundBorder);
g_lua.bindClassMemberFunction<Thing>("isOnBottom", &Thing::isOnBottom); g_lua.bindClassMemberFunction<Thing>("isOnBottom", &Thing::isOnBottom);

@ -32,8 +32,8 @@ void UICreature::drawSelf(bool foregroundPane)
UIWidget::drawSelf(foregroundPane); UIWidget::drawSelf(foregroundPane);
if(m_creature) { if(m_creature) {
g_painter->setColor(Color::white);
Rect drawRect = getPaddingRect(); Rect drawRect = getPaddingRect();
g_painter->setColor(Color::white);
m_creature->drawOutfit(drawRect, !m_fixedCreatureSize); m_creature->drawOutfit(drawRect, !m_fixedCreatureSize);
} }
} }

Loading…
Cancel
Save