effects working, map on higher levels too

This commit is contained in:
Henrique 2011-08-16 02:47:35 -03:00
parent 3d4cfb793e
commit 97d2c30a81
11 changed files with 118 additions and 50 deletions

View File

@ -38,7 +38,7 @@ function EnterGame_connectToLoginServer()
-- display motd -- display motd
local motdNumber = string.sub(motd, 0, string.find(motd, "\n")) local motdNumber = string.sub(motd, 0, string.find(motd, "\n"))
local motdText = string.sub(motd, string.find(motd, "\n") + 1, string.len(motd)) local motdText = string.sub(motd, string.find(motd, "\n") + 1, string.len(motd))
local motdBox = displayInfoBox("Message of the day", motdText) --local motdBox = displayInfoBox("Message of the day", motdText)
-- hide main menu -- hide main menu
mainMenu.visible = false mainMenu.visible = false

View File

@ -17,20 +17,20 @@ bool DatManager::load(const std::string& filename)
int numShots = fw::getu16(fin); int numShots = fw::getu16(fin);
m_itemsAttributes.resize(numItems); m_itemsAttributes.resize(numItems);
for(int id = 100; id <= numItems; ++id) for(int id = 100; id < numItems; ++id)
parseThingAttributes(fin, m_itemsAttributes[id - 100]); parseThingAttributes(fin, m_itemsAttributes[id - 100]);
m_creaturesAttributes.resize(numItems); m_creaturesAttributes.resize(numItems);
for(int id = 1; id < numCreatures; ++id) for(int id = 0; id < numCreatures; ++id)
parseThingAttributes(fin, m_creaturesAttributes[id - 1]); parseThingAttributes(fin, m_creaturesAttributes[id]);
m_effectsAttributes.resize(numItems); m_effectsAttributes.resize(numItems);
for(int id = 100; id < numEffects; ++id) for(int id = 0; id < numEffects; ++id)
parseThingAttributes(fin, m_effectsAttributes[id - 100]); parseThingAttributes(fin, m_effectsAttributes[id]);
m_shotsAttributes.resize(numItems); m_shotsAttributes.resize(numItems);
for(int id = 1; id < numShots; ++id) for(int id = 0; id < numShots; ++id)
parseThingAttributes(fin, m_shotsAttributes[id - 1]); parseThingAttributes(fin, m_shotsAttributes[id]);
return true; return true;
} catch(std::exception& e) { } catch(std::exception& e) {
@ -178,8 +178,9 @@ void DatManager::parseThingAttributesOpt(std::stringstream& fin, ThingAttributes
break; break;
case 0x19: // pixels characters height case 0x19: // pixels characters height
fin.read((char*)&thingAttributes.xOffset, 1); //fin.read((char*)&thingAttributes.xOffset, 1);
fin.read((char*)&thingAttributes.yOffset, 1); //fin.read((char*)&thingAttributes.yOffset, 1);
fin.read((char*)&read_short, 2);
//logDebug((int)thingAttributes.xOffset, " ", (int)thingAttributes.yOffset); //logDebug((int)thingAttributes.xOffset, " ", (int)thingAttributes.yOffset);
break; break;
case 0x1A: case 0x1A:

View File

@ -14,9 +14,9 @@ public:
void parseThingAttributesOpt(std::stringstream& fin, ThingAttributes& thingAttributes, uint8 opt); void parseThingAttributesOpt(std::stringstream& fin, ThingAttributes& thingAttributes, uint8 opt);
ThingAttributes& getItemAttributes(uint16 id) { return m_itemsAttributes[id - 100]; } ThingAttributes& getItemAttributes(uint16 id) { return m_itemsAttributes[id - 100]; }
ThingAttributes& getCreatureAttributes(uint16 id) { return m_creaturesAttributes[id - 1]; } ThingAttributes& getCreatureAttributes(uint16 id) { return m_creaturesAttributes[id]; }
ThingAttributes& getEffectAttributes(uint16 id) { return m_effectsAttributes[id - 100]; } ThingAttributes& getEffectAttributes(uint16 id) { return m_effectsAttributes[id]; }
ThingAttributes& getShotAttributes(uint16 id) { return m_shotsAttributes[id - 1]; } ThingAttributes& getShotAttributes(uint16 id) { return m_shotsAttributes[id]; }
uint32 getSignature() { return m_signature; } uint32 getSignature() { return m_signature; }

View File

@ -3,12 +3,32 @@
Effect::Effect() : Thing(THING_EFFECT) Effect::Effect() : Thing(THING_EFFECT)
{ {
m_timer = 0;
m_animation = 0;
m_finished = false;
} }
void Effect::draw(int x, int y) void Effect::draw(int x, int y)
{ {
int anim = 0; internalDraw(x, y, 0, 0, 0, 0, m_animation);
internalDraw(x, y, 0, 0, 0, 0, anim); }
void Effect::update(int elapsedTime)
{
if(m_finished)
return;
if(m_timer > 75) {
const ThingAttributes& attributes = getAttributes();
if(m_animation+1 == attributes.animcount) {
m_finished = true;
return;
}
m_animation++;
m_timer = 0;
}
m_timer += elapsedTime;
} }
const ThingAttributes& Effect::getAttributes() const ThingAttributes& Effect::getAttributes()

View File

@ -10,10 +10,18 @@ public:
Effect(); Effect();
void draw(int x, int y); void draw(int x, int y);
void update(int elapsedTime);
bool finished() { return m_finished; }
const ThingAttributes& getAttributes(); const ThingAttributes& getAttributes();
virtual EffectPtr asEffect() { return std::static_pointer_cast<Effect>(shared_from_this()); } EffectPtr asEffect() { return std::static_pointer_cast<Effect>(shared_from_this()); }
private:
int m_timer;
int m_animation;
bool m_finished;
}; };
#endif #endif

View File

@ -20,39 +20,31 @@ void Map::draw(int x, int y)
if(playerPos.z <= 7) { if(playerPos.z <= 7) {
// player pos it 8-6. check if we can draw upper floors. // player pos it 8-6. check if we can draw upper floors.
bool draw = true; int drawFloorStop = 0;
for(int jz = 6; jz >= 0; --jz) { for(int jz = 6; jz >= 0; --jz) {
Position coverPos = Position(playerPos.x-(6-jz), playerPos.y-(6-jz), jz); Position coverPos = Position(playerPos.x+(7-jz)-1, playerPos.y+(7-jz)-1, jz);
if(m_tiles[coverPos]) { if(m_tiles[coverPos]) {
if(m_tiles[coverPos]->getStackSize() > 0 && jz < playerPos.z) { if(m_tiles[coverPos]->getStackSize() > 0 && jz < playerPos.z) {
draw = false; drawFloorStop = jz;
break;
} }
} }
} }
for(int iz = 7; iz > 0; --iz) { for(int iz = 7; iz > 0; --iz) {
if(iz == drawFloorStop)
break;
// +1 in draws cause 64x64 items may affect view. // +1 in draws cause 64x64 items may affect view.
for(int ix = -7; ix < + 8+7; ++ix) {
for(int iy = -5; iy < + 6+7; ++iy) { for(int ix = -7+(playerPos.z-iz); ix < + 8+7; ++ix) {
for(int iy = -5+(playerPos.z-iz); iy < + 6+7; ++iy) {
Position itemPos = Position(playerPos.x + ix, playerPos.y + iy, iz); Position itemPos = Position(playerPos.x + ix, playerPos.y + iy, iz);
//Position drawPos = Position(ix + 8, iy - playerPos.y + 6, iz);
//logDebug("x: ", relativePos.x, " y: ", relativePos.y, " z: ", (int)relativePos.z);
if(m_tiles[itemPos]) if(m_tiles[itemPos])
m_tiles[itemPos]->draw((ix + 7 - (7-iz))*32, (iy + 5 - (7-iz))*32); m_tiles[itemPos]->draw((ix + 7 - (playerPos.z-iz))*32, (iy + 5 - (playerPos.z-iz))*32);
} }
} }
if(!draw)
break;
} }
}
// draw effects
for(auto it = m_effects.begin(), end = m_effects.end(); it != end; ++it) {
Position effectPos = (*it)->getPosition();
(*it)->draw((effectPos.x - playerPos.x + 7) * 32, (effectPos.y - playerPos.y + 5) * 32);
} }
// debug draws // debug draws
@ -62,16 +54,33 @@ void Map::draw(int x, int y)
m_framebuffer->draw(Rect(x, y, g_graphics.getScreenSize())); m_framebuffer->draw(Rect(x, y, g_graphics.getScreenSize()));
} }
void Map::update(int elapsedTime)
{
// Items
// Effects
for(auto it = m_effects.begin(), end = m_effects.end(); it != end;) {
if((*it)->finished()) {
m_tiles[(*it)->getPosition()]->removeThing(*it, 0);
it = m_effects.erase(it);
}
else {
(*it)->update(elapsedTime);
++it;
}
}
}
void Map::addThing(ThingPtr thing, uint8 stackpos) void Map::addThing(ThingPtr thing, uint8 stackpos)
{ {
if(thing->asItem() || thing->asCreature()) {
if(!m_tiles[thing->getPosition()]) { if(!m_tiles[thing->getPosition()]) {
m_tiles[thing->getPosition()] = TilePtr(new Tile()); m_tiles[thing->getPosition()] = TilePtr(new Tile());
} }
m_tiles[thing->getPosition()]->addThing(thing, stackpos); m_tiles[thing->getPosition()]->addThing(thing, stackpos);
}
else if(thing->asEffect()) { // List with effects and shots to update them.
m_effects.push_back(thing); if(thing->asEffect()) {
m_effects.push_back(thing->asEffect());
} }
} }

View File

@ -8,13 +8,14 @@
class Map class Map
{ {
public: public:
void addThing(ThingPtr thing, uint8 stackpos = 0);
void draw(int x, int y); void draw(int x, int y);
void update(int elapsedTime);
void addThing(ThingPtr thing, uint8 stackpos = 0);
private: private:
std::unordered_map<Position, TilePtr, PositionHasher> m_tiles; std::unordered_map<Position, TilePtr, PositionHasher> m_tiles;
std::list<ThingPtr> m_effects; std::list<EffectPtr> m_effects;
FrameBufferPtr m_framebuffer; FrameBufferPtr m_framebuffer;
}; };

View File

@ -26,7 +26,7 @@ void Thing::internalDraw(int x, int y, int blendframes, int xdiv, int ydiv, int
TexturePtr spriteTex = g_sprites.getSpriteTexture(spriteId); TexturePtr spriteTex = g_sprites.getSpriteTexture(spriteId);
Rect drawRect((x - xi*32) - attributes.xOffset, Rect drawRect((x - xi*32) - attributes.xOffset,
(y - yi*32) - attributes.yOffset, (y - yi*32) - attributes.xOffset,
32, 32); 32, 32);
g_graphics.drawTexturedRect(drawRect, spriteTex); g_graphics.drawTexturedRect(drawRect, spriteTex);

View File

@ -21,9 +21,26 @@ void Tile::addThing(ThingPtr thing, uint8 stackpos)
else else
m_itemsBottom.push_back(thing); m_itemsBottom.push_back(thing);
} }
} else if(thing->asCreature()) { }
else if(thing->asCreature()) {
m_creatures.push_back(thing); m_creatures.push_back(thing);
} }
else if(thing->asEffect()) {
m_effects.push_back(thing);
}
}
void Tile::removeThing(ThingPtr thing, uint8 stackpos)
{
if(thing->asEffect()) {
for(auto it = m_effects.begin(), end = m_effects.end(); it != end; ++it) {
if(thing == *it) {
(*it).reset();
m_effects.erase(it);
break;
}
}
}
} }
void Tile::draw(int x, int y) void Tile::draw(int x, int y)
@ -31,13 +48,16 @@ void Tile::draw(int x, int y)
if(m_ground) if(m_ground)
m_ground->draw(x, y); m_ground->draw(x, y);
for(const ThingPtr& thing : m_itemsBottom) for(const ThingPtr& thing : m_itemsTop)
thing->draw(x, y); thing->draw(x, y);
for(const ThingPtr& thing : m_creatures) for(const ThingPtr& thing : m_creatures)
thing->draw(x, y); thing->draw(x, y);
for(const ThingPtr& thing : m_itemsTop) for(const ThingPtr& thing : m_itemsBottom)
thing->draw(x, y);
for(const ThingPtr& thing : m_effects)
thing->draw(x, y); thing->draw(x, y);
} }

View File

@ -10,6 +10,7 @@ public:
Tile(); Tile();
void addThing(ThingPtr thing, uint8 stackpos); void addThing(ThingPtr thing, uint8 stackpos);
void removeThing(ThingPtr thing, uint8 stackpos);
void draw(int x, int y); void draw(int x, int y);
@ -22,6 +23,7 @@ private:
std::deque<ThingPtr> m_itemsBottom; std::deque<ThingPtr> m_itemsBottom;
std::deque<ThingPtr> m_creatures; std::deque<ThingPtr> m_creatures;
std::deque<ThingPtr> m_itemsTop; std::deque<ThingPtr> m_itemsTop;
std::deque<ThingPtr> m_effects;
}; };
#endif #endif

View File

@ -82,6 +82,7 @@ void OTClient::run()
int frameTicks = g_platform.getTicks(); int frameTicks = g_platform.getTicks();
int lastFpsTicks = frameTicks; int lastFpsTicks = frameTicks;
int lastPollTicks = frameTicks; int lastPollTicks = frameTicks;
int lastUpdateTicks = frameTicks;
int frameCount = 0; int frameCount = 0;
m_stopping = false; m_stopping = false;
@ -114,6 +115,12 @@ void OTClient::run()
lastPollTicks = frameTicks; lastPollTicks = frameTicks;
} }
// only update to a maximum of 60 fps
if(frameTicks - lastUpdateTicks >= 1) {
g_map.update(frameTicks - lastUpdateTicks);
lastUpdateTicks = frameTicks;
}
// only render when the windows is visible // only render when the windows is visible
if(g_platform.isWindowVisible()) { if(g_platform.isWindowVisible()) {
// render begin // render begin