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())
scheduleEvent(updateFunc, 250)
end
updateFunc()
addEvent(updateFunc)

@ -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());
}

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

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

@ -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)

@ -92,6 +92,7 @@ public:
bool isRemoved() { return m_removed; }
CreaturePtr asCreature() { return std::static_pointer_cast<Creature>(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<Npc>(shared_from_this()); }
bool isNpc() { return true; }
};
class Monster : public Creature {
public:
MonsterPtr asMonster() { return std::static_pointer_cast<Monster>(shared_from_this()); }
bool isMonster() { return true; }
};
#endif

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

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

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

@ -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);
}

@ -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;

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

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

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

@ -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); }

@ -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);
}

@ -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;

@ -228,6 +228,14 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassMemberFunction<Thing>("asLocalPlayer", &Thing::asLocalPlayer);
g_lua.bindClassMemberFunction<Thing>("asAnimatedText", &Thing::asAnimatedText);
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>("isGroundBorder", &Thing::isGroundBorder);
g_lua.bindClassMemberFunction<Thing>("isOnBottom", &Thing::isOnBottom);

@ -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);
}
}

Loading…
Cancel
Save