some render improvements

master
Henrique 13 years ago
parent 65dca53c0f
commit 4bd701f94c

@ -32,7 +32,6 @@ Creature::Creature() : Thing(Otc::Creature)
{ {
m_healthPercent = 0; m_healthPercent = 0;
m_direction = Otc::South; m_direction = Otc::South;
m_animation = 0;
m_walking = false; m_walking = false;
m_walkOffsetX = 0; m_walkOffsetX = 0;
@ -106,14 +105,15 @@ void Creature::draw(int x, int y)
y += m_walkOffsetY; 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. // 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; continue;
// draw white item // draw white item
internalDraw(x, y, 0, m_direction, ydiv, 0, m_animation); internalDraw(x, y, 0);
// draw mask if exists // draw mask if exists
if(attributes.blendframes > 1) { if(attributes.blendframes > 1) {
@ -122,19 +122,19 @@ void Creature::draw(int x, int y)
// head // head
g_graphics.bindColor(Otc::OutfitColors[m_outfit.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 // body
g_graphics.bindColor(Otc::OutfitColors[m_outfit.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 // legs
g_graphics.bindColor(Otc::OutfitColors[m_outfit.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 // feet
g_graphics.bindColor(Otc::OutfitColors[m_outfit.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 // restore default blend func
g_graphics.bindBlendFunc(Fw::BlendDefault); g_graphics.bindBlendFunc(Fw::BlendDefault);

@ -90,7 +90,6 @@ private:
double m_walkTime; double m_walkTime;
Position m_walkingFromPosition; Position m_walkingFromPosition;
double m_walkOffsetX, m_walkOffsetY; double m_walkOffsetX, m_walkOffsetY;
int m_animation;
}; };
#endif #endif

@ -29,7 +29,6 @@
Effect::Effect() : Thing(Otc::Effect) Effect::Effect() : Thing(Otc::Effect)
{ {
m_lastTicks = g_platform.getTicks(); m_lastTicks = g_platform.getTicks();
m_animation = 0;
m_finished = false; m_finished = false;
} }
@ -47,7 +46,7 @@ void Effect::draw(int x, int y)
m_lastTicks = g_platform.getTicks(); m_lastTicks = g_platform.getTicks();
} }
internalDraw(x, y, 0, 0, 0, 0, m_animation); internalDraw(x, y, 0);
} }
} }

@ -41,7 +41,6 @@ public:
private: private:
int m_lastTicks; int m_lastTicks;
int m_animation;
bool m_finished; bool m_finished;
}; };

@ -30,61 +30,76 @@ Item::Item() : Thing(Otc::Item)
{ {
m_count = 0; m_count = 0;
m_lastTicks = g_platform.getTicks(); 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 oldCount = m_count;
int xdiv = 0, ydiv = 0, zdiv = 0; m_count = count;
onCountChange(oldCount);
}
if(attributes.animcount > 1) { void Item::onPositionChange(const Position&)
if(g_platform.getTicks() - m_lastTicks > 500) { {
if(m_animation+1 == attributes.animcount) const ThingAttributes& attributes = g_dat.getItemAttributes(m_id);
m_animation = 0;
else
m_animation++;
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) { void Item::onCountChange(int)
//xdiv = m_count % attributes.xdiv; {
//ydiv = m_count / attributes.ydiv; const ThingAttributes& attributes = g_dat.getItemAttributes(m_id);
} if(attributes.stackable) {
else if(attributes.stackable) {
if(m_count < 5) { if(m_count < 5) {
xdiv = m_count-1; m_xDiv = m_count-1;
ydiv = 0; m_yDiv = 0;
} }
else if(m_count < 10) { else if(m_count < 10) {
xdiv = 0; m_xDiv = 0;
ydiv = 1; m_yDiv = 1;
} }
else if(m_count < 25) { else if(m_count < 25) {
xdiv = 1; m_xDiv = 1;
ydiv = 1; m_yDiv = 1;
} }
else if(m_count < 50) { else if(m_count < 50) {
xdiv = 2; m_xDiv = 2;
ydiv = 1; m_yDiv = 1;
} }
else if(m_count <= 100) { else if(m_count <= 100) {
xdiv = 3; m_xDiv = 3;
ydiv = 1; m_yDiv = 1;
} }
} }
else if(!attributes.moveable) { }
xdiv = m_position.x % attributes.xdiv;
ydiv = m_position.y % attributes.ydiv; void Item::draw(int x, int y)
zdiv = m_position.z % attributes.zdiv; {
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++) 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() const ThingAttributes& Item::getAttributes()

@ -33,17 +33,19 @@ public:
void draw(int x, int y); void draw(int x, int y);
void setCount(int count) { m_count = count; } void setCount(int count);
int getCount() { return m_count; } int getCount() { return m_count; }
const ThingAttributes& getAttributes(); const ThingAttributes& getAttributes();
void onPositionChange(const Position&);
void onCountChange(int);
ItemPtr asItem() { return std::static_pointer_cast<Item>(shared_from_this()); } ItemPtr asItem() { return std::static_pointer_cast<Item>(shared_from_this()); }
private: private:
int m_count; int m_count;
int m_lastTicks; int m_lastTicks;
int m_animation;
}; };
#endif #endif

@ -26,9 +26,21 @@
Thing::Thing(Otc::ThingType type) : m_id(0), m_type(type) 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(); 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 + int sprIndex = xi +
yi * attributes.width + yi * attributes.width +
blendframes * attributes.width * attributes.height + blendframes * attributes.width * attributes.height +
xdiv * attributes.width * attributes.height * attributes.blendframes + m_xDiv * attributes.width * attributes.height * attributes.blendframes +
ydiv * attributes.width * attributes.height * attributes.blendframes * attributes.xdiv + m_yDiv * attributes.width * attributes.height * attributes.blendframes * attributes.xdiv +
zdiv * attributes.width * attributes.height * attributes.blendframes * attributes.xdiv * attributes.ydiv + m_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_animation * attributes.width * attributes.height * attributes.blendframes * attributes.xdiv * attributes.ydiv * attributes.zdiv;
int spriteId = attributes.sprites[sprIndex]; int spriteId = attributes.sprites[sprIndex];
if(!spriteId) if(!spriteId)

@ -42,13 +42,15 @@ public:
virtual void draw(int x, int y) = 0; virtual void draw(int x, int y) = 0;
void setId(uint32 id) { m_id = id; } 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; } uint32 getId() const { return m_id; }
Otc::ThingType getType() const { return m_type; } Otc::ThingType getType() const { return m_type; }
Position getPosition() const { return m_position; } Position getPosition() const { return m_position; }
virtual const ThingAttributes& getAttributes() = 0; virtual const ThingAttributes& getAttributes() = 0;
virtual void onPositionChange(const Position&) {}
ThingPtr asThing() { return std::static_pointer_cast<Thing>(shared_from_this()); } ThingPtr asThing() { return std::static_pointer_cast<Thing>(shared_from_this()); }
virtual ItemPtr asItem() { return nullptr; } virtual ItemPtr asItem() { return nullptr; }
virtual CreaturePtr asCreature() { return nullptr; } virtual CreaturePtr asCreature() { return nullptr; }
@ -57,11 +59,13 @@ public:
virtual LocalPlayerPtr asLocalPlayer() { return nullptr; } virtual LocalPlayerPtr asLocalPlayer() { return nullptr; }
protected: 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; uint32 m_id;
Otc::ThingType m_type; Otc::ThingType m_type;
Position m_position; Position m_position;
int m_xDiv, m_yDiv, m_zDiv, m_animation;
}; };
#endif #endif

Loading…
Cancel
Save