map tile render rework, not done yet

This commit is contained in:
Henrique 2011-08-19 23:08:27 -03:00
parent 033f14780d
commit 9b112b1daf
7 changed files with 144 additions and 32 deletions

View File

@ -29,9 +29,9 @@ void Creature::draw(int x, int y)
outfitColorId = m_outfit.head; outfitColorId = m_outfit.head;
else if(mask == SpriteMaskRed) else if(mask == SpriteMaskRed)
outfitColorId = m_outfit.body; outfitColorId = m_outfit.body;
else if(mask == SpriteMaskBlue)
outfitColorId = m_outfit.legs;
else if(mask == SpriteMaskGreen) else if(mask == SpriteMaskGreen)
outfitColorId = m_outfit.legs;
else if(mask == SpriteMaskBlue)
outfitColorId = m_outfit.feet; outfitColorId = m_outfit.feet;
g_graphics.bindColor(OutfitColors[outfitColorId]); g_graphics.bindColor(OutfitColors[outfitColorId]);

View File

@ -169,12 +169,13 @@ void DatManager::parseThingAttributesOpt(std::stringstream& fin, ThingAttributes
break; break;
case 0x18: // Thing must be drawed with offset case 0x18: // Thing must be drawed with offset
thingAttributes.hasHeight = true; thingAttributes.hasHeight = true;
thingAttributes.xOffset = fw::getu8(fin); thingAttributes.drawOffset = fw::getu8(fin);
thingAttributes.yOffset = fw::getu8(fin); fw::getu8(fin);
fw::getu16(fin); fw::getu16(fin);
break; break;
case 0x19: // pixels characters height case 0x19: // pixels characters height
fw::getu16(fin); thingAttributes.drawNextOffset = fw::getu8(fin);
fw::getu8(fin);
break; break;
case 0x1A: case 0x1A:
//thingAttributes.hasHeight = true; //thingAttributes.hasHeight = true;

View File

@ -17,10 +17,25 @@ void Map::draw(int x, int y)
Position playerPos = g_game.getLocalPlayer()->getPosition(); Position playerPos = g_game.getLocalPlayer()->getPosition();
// player is above 7 // player is above 7
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.
int drawFloorStop = 0; int drawFloorStop = 0;
// if there is a window on north, east, south or west
//Position direction[4] = {Position(0, -1, 0), Position(1, 0, 0), Position(0, 1, 0), Position(-1, 0, 0)};
for(int d = 0; d < 4; ++d) {
/*if(const TilePtr& tile = m_tiles[playerPos+direction[d]]) {
const ThingAttributes& thingAttributes = thing->getAttributes();
if(thingAttributes.lookThrough) {
drawFloorStop = playerPos.z - 1;
break;
}
}*/
}
// if we have something covering us, dont show floors above.
for(int jz = 6; jz >= 0; --jz) { for(int jz = 6; jz >= 0; --jz) {
Position coverPos = Position(playerPos.x+(7-jz)-1, playerPos.y+(7-jz)-1, jz); Position coverPos = Position(playerPos.x+(7-jz)-1, playerPos.y+(7-jz)-1, jz);
if(const TilePtr& tile = m_tiles[coverPos]) { if(const TilePtr& tile = m_tiles[coverPos]) {
@ -35,13 +50,17 @@ void Map::draw(int x, int y)
if(iz == drawFloorStop) if(iz == drawFloorStop)
break; break;
for(int step = 0; step < 4; ++step) {
// +1 in draws cause 64x64 items may affect view. // +1 in draws cause 64x64 items may affect view.
for(int ix = -7+(playerPos.z-iz); ix < + 8+7; ++ix) { for(int ix = -7+(playerPos.z-iz); ix < + 8+7; ++ix) {
for(int iy = -5+(playerPos.z-iz); iy < + 6+7; ++iy) { 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);
if(const TilePtr& tile = m_tiles[itemPos]) if(const TilePtr& tile = m_tiles[itemPos])
tile->draw((ix + 7 - (playerPos.z-iz))*32, (iy + 5 - (playerPos.z-iz))*32); tile->draw((ix + 7 - (playerPos.z-iz))*32, (iy + 5 - (playerPos.z-iz))*32, step);
}
} }
} }
} }

View File

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

View File

@ -37,13 +37,13 @@ struct ThingAttributes
ydiv = 0; ydiv = 0;
zdiv = 0; zdiv = 0;
animcount = 0; animcount = 0;
xOffset = 0; drawOffset = 0;
yOffset = 0; drawNextOffset = 0;
} }
bool stackable, alwaysOnTop, useable, readable, moveable, blockSolid, blockProjectile, blockPathFind, pickupable, bool stackable, alwaysOnTop, useable, readable, moveable, blockSolid, blockProjectile, blockPathFind, pickupable,
isHangable, isHorizontal, isVertical, rotable, hasHeight, lookThrough, hasMiniMapColor; isHangable, isHorizontal, isVertical, rotable, hasHeight, lookThrough, hasMiniMapColor;
uint8 alwaysOnTopOrder, width, height, blendframes, xdiv, ydiv, zdiv, animcount, xOffset, yOffset; uint8 alwaysOnTopOrder, width, height, blendframes, xdiv, ydiv, zdiv, animcount, drawOffset, drawNextOffset;
uint16 speed, subParam07, subParam08, lightLevel, lightColor, miniMapColor; uint16 speed, subParam07, subParam08, lightLevel, lightColor, miniMapColor;
std::vector<int> sprites; std::vector<int> sprites;

View File

@ -2,28 +2,97 @@
#include "item.h" #include "item.h"
#include "datmanager.h" #include "datmanager.h"
#include "map.h" #include "map.h"
#include "game.h"
#include "localplayer.h" #include "localplayer.h"
#include <framework/graphics/fontmanager.h>
Tile::Tile() Tile::Tile()
{ {
m_drawNextOffset = 0;
} }
void Tile::draw(int x, int y) void Tile::draw(int x, int y, int step)
{ {
// STEP 0 = draw ground, top 1
// STEP 1 = top 2
// STEP 2 = top 3
// STEP 3 = bottom, creatures, names, etc
FontPtr font = g_fonts.getDefaultFont();
if(step == 0 && m_drawNextOffset != 0) {
logDebug("error with tile offset.");
return;
}
if(step == 0) {
if(m_ground) if(m_ground)
m_ground->draw(x, y); m_ground->draw(x, y);
for(const ThingPtr& thing : m_itemsTop) for(const ThingPtr& thing : m_itemsTop) {
thing->draw(x, y); const ThingAttributes& thingAttributes = thing->getAttributes();
for(const ThingPtr& thing : m_itemsBottom) if(thingAttributes.alwaysOnTopOrder == 1) {
thing->draw(x, y); thing->draw(x - m_drawNextOffset, y - m_drawNextOffset);
//font->renderText("T1", Rect(x + 5, y+5, 100, 100));
for(const ThingPtr& thing : m_creatures) m_drawNextOffset += thingAttributes.drawNextOffset;
thing->draw(x, y); }
}
for(const ThingPtr& thing : m_effects) for(const ThingPtr& thing : m_itemsTop) {
thing->draw(x, y); const ThingAttributes& thingAttributes = thing->getAttributes();
if(thingAttributes.alwaysOnTopOrder == 2) {
thing->draw(x - m_drawNextOffset, y - m_drawNextOffset);
//font->renderText("T2", Rect(x + 5, y+5, 100, 100));
m_drawNextOffset += thingAttributes.drawNextOffset;
}
}
for(const ThingPtr& thing : m_itemsBottom) {
const ThingAttributes& thingAttributes = thing->getAttributes();
thing->draw(x - m_drawNextOffset, y - m_drawNextOffset);
//font->renderText("B0", Rect(x + 5, y+5, 100, 100));
m_drawNextOffset += thingAttributes.drawNextOffset;
}
for(const ThingPtr& thing : m_creatures) {
const ThingAttributes& thingAttributes = thing->getAttributes();
thing->draw(x - m_drawNextOffset, y - m_drawNextOffset);
m_drawNextOffset += thingAttributes.drawNextOffset;
}
for(const ThingPtr& thing : m_itemsTop) {
const ThingAttributes& thingAttributes = thing->getAttributes();
if(thingAttributes.alwaysOnTopOrder == 3) {
thing->draw(x - m_drawNextOffset, y - m_drawNextOffset);
//font->renderText("T3", Rect(x + 5, y+5, 100, 100));
m_drawNextOffset += thingAttributes.drawNextOffset;
}
}
for(const ThingPtr& thing : m_effects) {
thing->draw(x - m_drawNextOffset, y - m_drawNextOffset);
}
m_drawNextOffset = 0;
}
else if(step == 1) {
}
else if(step == 2) {
}
else if(step == 3) {
}
} }
void Tile::addThing(ThingPtr thing, uint8 stackpos) void Tile::addThing(ThingPtr thing, uint8 stackpos)
@ -31,6 +100,22 @@ void Tile::addThing(ThingPtr thing, uint8 stackpos)
if(!thing) if(!thing)
return; return;
//8308
//2526
//5296
const ThingAttributes& item1 = g_dat.getItemAttributes(8308);
const ThingAttributes& item2 = g_dat.getItemAttributes(2526);
const ThingAttributes& item3 = g_dat.getItemAttributes(5296);
int j = item1.alwaysOnTopOrder + item2.alwaysOnTopOrder + item3.alwaysOnTopOrder;
j++;
if(thing->getPosition() == g_game.getLocalPlayer()->getPosition() + Position(-1, 0, 0) && thing->getAttributes().alwaysOnTop) {
logDebug((int)thing->getId());
}
const ThingAttributes& thingAttributes = thing->getAttributes(); const ThingAttributes& thingAttributes = thing->getAttributes();
if(thing->asItem()) { if(thing->asItem()) {
@ -38,16 +123,16 @@ void Tile::addThing(ThingPtr thing, uint8 stackpos)
m_ground = thing; m_ground = thing;
else { else {
if(thingAttributes.alwaysOnTop) if(thingAttributes.alwaysOnTop)
m_itemsTop.push_back(thing); m_itemsTop.push_front(thing);
else else
m_itemsBottom.push_back(thing); m_itemsBottom.push_front(thing);
} }
} }
else if(thing->asCreature()) { else if(thing->asCreature()) {
m_creatures.push_back(thing); m_creatures.push_front(thing);
} }
else if(thing->asEffect()) { else if(thing->asEffect()) {
m_effects.push_back(thing); m_effects.push_front(thing);
} }
} }

View File

@ -4,12 +4,17 @@
#include "declarations.h" #include "declarations.h"
#include <framework/luascript/luaobject.h> #include <framework/luascript/luaobject.h>
enum RenderStep
{
};
class Tile : public LuaObject class Tile : public LuaObject
{ {
public: public:
Tile(); Tile();
void draw(int x, int y); void draw(int x, int y, int step);
void addThing(ThingPtr thing, uint8 stackpos); void addThing(ThingPtr thing, uint8 stackpos);
ThingPtr getThing(uint8 stackpos); ThingPtr getThing(uint8 stackpos);
@ -28,6 +33,8 @@ private:
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; std::deque<ThingPtr> m_effects;
int m_drawNextOffset;
}; };
#endif #endif