From 9b112b1daf298a61f1ecafcf5cbe31558c992933 Mon Sep 17 00:00:00 2001 From: Henrique Date: Fri, 19 Aug 2011 23:08:27 -0300 Subject: [PATCH] map tile render rework, not done yet --- src/otclient/core/creature.cpp | 4 +- src/otclient/core/datmanager.cpp | 7 +- src/otclient/core/map.cpp | 31 ++++++-- src/otclient/core/thing.cpp | 4 +- src/otclient/core/thingattributes.h | 6 +- src/otclient/core/tile.cpp | 115 ++++++++++++++++++++++++---- src/otclient/core/tile.h | 9 ++- 7 files changed, 144 insertions(+), 32 deletions(-) diff --git a/src/otclient/core/creature.cpp b/src/otclient/core/creature.cpp index bfe5f2e9..809a2675 100644 --- a/src/otclient/core/creature.cpp +++ b/src/otclient/core/creature.cpp @@ -29,9 +29,9 @@ void Creature::draw(int x, int y) outfitColorId = m_outfit.head; else if(mask == SpriteMaskRed) outfitColorId = m_outfit.body; - else if(mask == SpriteMaskBlue) + else if(mask == SpriteMaskGreen) outfitColorId = m_outfit.legs; - else if(mask == SpriteMaskGreen) + else if(mask == SpriteMaskBlue) outfitColorId = m_outfit.feet; g_graphics.bindColor(OutfitColors[outfitColorId]); diff --git a/src/otclient/core/datmanager.cpp b/src/otclient/core/datmanager.cpp index 188a4be6..7a78ae62 100644 --- a/src/otclient/core/datmanager.cpp +++ b/src/otclient/core/datmanager.cpp @@ -169,12 +169,13 @@ void DatManager::parseThingAttributesOpt(std::stringstream& fin, ThingAttributes break; case 0x18: // Thing must be drawed with offset thingAttributes.hasHeight = true; - thingAttributes.xOffset = fw::getu8(fin); - thingAttributes.yOffset = fw::getu8(fin); + thingAttributes.drawOffset = fw::getu8(fin); + fw::getu8(fin); fw::getu16(fin); break; case 0x19: // pixels characters height - fw::getu16(fin); + thingAttributes.drawNextOffset = fw::getu8(fin); + fw::getu8(fin); break; case 0x1A: //thingAttributes.hasHeight = true; diff --git a/src/otclient/core/map.cpp b/src/otclient/core/map.cpp index c305c7ea..f638ff9e 100644 --- a/src/otclient/core/map.cpp +++ b/src/otclient/core/map.cpp @@ -17,10 +17,25 @@ void Map::draw(int x, int y) Position playerPos = g_game.getLocalPlayer()->getPosition(); // player is above 7 + if(playerPos.z <= 7) { // player pos it 8-6. check if we can draw upper floors. 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) { Position coverPos = Position(playerPos.x+(7-jz)-1, playerPos.y+(7-jz)-1, jz); if(const TilePtr& tile = m_tiles[coverPos]) { @@ -35,13 +50,17 @@ void Map::draw(int x, int y) if(iz == drawFloorStop) break; - // +1 in draws cause 64x64 items may affect view. + for(int step = 0; step < 4; ++step) { + + + // +1 in draws cause 64x64 items may affect view. - 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); - if(const TilePtr& tile = m_tiles[itemPos]) - tile->draw((ix + 7 - (playerPos.z-iz))*32, (iy + 5 - (playerPos.z-iz))*32); + 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); + if(const TilePtr& tile = m_tiles[itemPos]) + tile->draw((ix + 7 - (playerPos.z-iz))*32, (iy + 5 - (playerPos.z-iz))*32, step); + } } } } diff --git a/src/otclient/core/thing.cpp b/src/otclient/core/thing.cpp index 8b1c0d3f..9fa2ddbf 100644 --- a/src/otclient/core/thing.cpp +++ b/src/otclient/core/thing.cpp @@ -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); - Rect drawRect((x - xi*32) - attributes.xOffset, - (y - yi*32) - attributes.xOffset, + Rect drawRect((x - xi*32) - attributes.drawOffset, + (y - yi*32) - attributes.drawOffset, 32, 32); g_graphics.drawTexturedRect(drawRect, spriteTex); } diff --git a/src/otclient/core/thingattributes.h b/src/otclient/core/thingattributes.h index 1968f385..e6980162 100644 --- a/src/otclient/core/thingattributes.h +++ b/src/otclient/core/thingattributes.h @@ -37,13 +37,13 @@ struct ThingAttributes ydiv = 0; zdiv = 0; animcount = 0; - xOffset = 0; - yOffset = 0; + drawOffset = 0; + drawNextOffset = 0; } bool stackable, alwaysOnTop, useable, readable, moveable, blockSolid, blockProjectile, blockPathFind, pickupable, 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; std::vector sprites; diff --git a/src/otclient/core/tile.cpp b/src/otclient/core/tile.cpp index dee7afde..625bc060 100644 --- a/src/otclient/core/tile.cpp +++ b/src/otclient/core/tile.cpp @@ -2,28 +2,97 @@ #include "item.h" #include "datmanager.h" #include "map.h" +#include "game.h" #include "localplayer.h" +#include Tile::Tile() { + m_drawNextOffset = 0; } -void Tile::draw(int x, int y) +void Tile::draw(int x, int y, int step) { - if(m_ground) - m_ground->draw(x, y); + // 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; + } - for(const ThingPtr& thing : m_itemsTop) - thing->draw(x, y); + if(step == 0) { + if(m_ground) + m_ground->draw(x, y); - for(const ThingPtr& thing : m_itemsBottom) - thing->draw(x, y); + for(const ThingPtr& thing : m_itemsTop) { + const ThingAttributes& thingAttributes = thing->getAttributes(); - for(const ThingPtr& thing : m_creatures) - thing->draw(x, y); + if(thingAttributes.alwaysOnTopOrder == 1) { + thing->draw(x - m_drawNextOffset, y - m_drawNextOffset); + //font->renderText("T1", Rect(x + 5, y+5, 100, 100)); - for(const ThingPtr& thing : m_effects) - thing->draw(x, y); + m_drawNextOffset += thingAttributes.drawNextOffset; + } + } + + for(const ThingPtr& thing : m_itemsTop) { + 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) @@ -31,6 +100,22 @@ void Tile::addThing(ThingPtr thing, uint8 stackpos) if(!thing) 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(); if(thing->asItem()) { @@ -38,16 +123,16 @@ void Tile::addThing(ThingPtr thing, uint8 stackpos) m_ground = thing; else { if(thingAttributes.alwaysOnTop) - m_itemsTop.push_back(thing); + m_itemsTop.push_front(thing); else - m_itemsBottom.push_back(thing); + m_itemsBottom.push_front(thing); } } else if(thing->asCreature()) { - m_creatures.push_back(thing); + m_creatures.push_front(thing); } else if(thing->asEffect()) { - m_effects.push_back(thing); + m_effects.push_front(thing); } } diff --git a/src/otclient/core/tile.h b/src/otclient/core/tile.h index 0127cfda..8acdc31a 100644 --- a/src/otclient/core/tile.h +++ b/src/otclient/core/tile.h @@ -4,12 +4,17 @@ #include "declarations.h" #include +enum RenderStep +{ + +}; + class Tile : public LuaObject { public: Tile(); - void draw(int x, int y); + void draw(int x, int y, int step); void addThing(ThingPtr thing, uint8 stackpos); ThingPtr getThing(uint8 stackpos); @@ -28,6 +33,8 @@ private: std::deque m_creatures; std::deque m_itemsTop; std::deque m_effects; + + int m_drawNextOffset; }; #endif