some render improvements

This commit is contained in:
Henrique 2011-08-28 16:47:23 -03:00
parent 65dca53c0f
commit 4bd701f94c
8 changed files with 85 additions and 55 deletions

View File

@ -32,7 +32,6 @@ Creature::Creature() : Thing(Otc::Creature)
{
m_healthPercent = 0;
m_direction = Otc::South;
m_animation = 0;
m_walking = false;
m_walkOffsetX = 0;
@ -106,14 +105,15 @@ void Creature::draw(int x, int y)
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.
if(ydiv > 0 && !(m_outfit.addons & (1 << (ydiv-1))))
if(m_yDiv > 0 && !(m_outfit.addons & (1 << (m_yDiv-1))))
continue;
// draw white item
internalDraw(x, y, 0, m_direction, ydiv, 0, m_animation);
internalDraw(x, y, 0);
// draw mask if exists
if(attributes.blendframes > 1) {
@ -122,19 +122,19 @@ void Creature::draw(int x, int y)
// 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
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
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
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
g_graphics.bindBlendFunc(Fw::BlendDefault);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -26,9 +26,21 @@
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();
@ -37,10 +49,10 @@ void Thing::internalDraw(int x, int y, int blendframes, int xdiv, int ydiv, int
int sprIndex = xi +
yi * attributes.width +
blendframes * attributes.width * attributes.height +
xdiv * attributes.width * attributes.height * attributes.blendframes +
ydiv * attributes.width * attributes.height * attributes.blendframes * attributes.xdiv +
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_xDiv * attributes.width * attributes.height * attributes.blendframes +
m_yDiv * attributes.width * attributes.height * attributes.blendframes * attributes.xdiv +
m_zDiv * attributes.width * attributes.height * attributes.blendframes * attributes.xdiv * attributes.ydiv +
m_animation * attributes.width * attributes.height * attributes.blendframes * attributes.xdiv * attributes.ydiv * attributes.zdiv;
int spriteId = attributes.sprites[sprIndex];
if(!spriteId)

View File

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