fix covered issues

This commit is contained in:
Eduardo Bart 2012-02-01 01:47:00 -02:00
parent 7a12312220
commit 3e841cd7b6
6 changed files with 14 additions and 11 deletions

View File

@ -37,6 +37,10 @@ Item::Item() : Thing()
ItemPtr Item::create(int id) ItemPtr Item::create(int id)
{ {
if(id < g_thingsType.getFirstItemId() || id > g_thingsType.getMaxItemid()) {
logTraceError("invalid item id ", id);
return nullptr;
}
ItemPtr item = ItemPtr(new Item); ItemPtr item = ItemPtr(new Item);
item->setId(id); item->setId(id);
return item; return item;

View File

@ -337,9 +337,6 @@ bool Map::isCovered(const Position& pos, int firstFloor)
// the below tile is covered when the above tile has a full ground // the below tile is covered when the above tile has a full ground
if(tile && tile->isFullGround()) if(tile && tile->isFullGround())
return true; return true;
if(tilePos.z == 0)
break;
} }
return false; return false;
} }
@ -352,7 +349,7 @@ bool Map::isCompletelyCovered(const Position& pos, int firstFloor)
// check in 2x2 range tiles that has no transparent pixels // check in 2x2 range tiles that has no transparent pixels
for(int x=0;x<2;++x) { for(int x=0;x<2;++x) {
for(int y=0;y<2;++y) { for(int y=0;y<2;++y) {
TilePtr tile = m_tiles[tilePos + Position(-x, -y, 0)]; const TilePtr& tile = getTile(tilePos.translated(-x, -y));
if(!tile || !tile->isFullyOpaque()) { if(!tile || !tile->isFullyOpaque()) {
covered = false; covered = false;
break; break;

View File

@ -76,8 +76,6 @@ void MapView::draw(const Rect& rect)
if(m_mustDrawVisibleTilesCache || animate) { if(m_mustDrawVisibleTilesCache || animate) {
m_framebuffer->bind(m_mustCleanFramebuffer); m_framebuffer->bind(m_mustCleanFramebuffer);
if(m_mustCleanFramebuffer)
m_mustCleanFramebuffer = false;
for(const TilePtr& tile : m_cachedVisibleTiles) { for(const TilePtr& tile : m_cachedVisibleTiles) {
tile->draw(transformPositionTo2D(tile->getPosition()), scaleFactor, tileDrawFlags); tile->draw(transformPositionTo2D(tile->getPosition()), scaleFactor, tileDrawFlags);
@ -181,7 +179,8 @@ void MapView::updateVisibleTilesCache(int start)
m_mustCleanFramebuffer = true; m_mustCleanFramebuffer = true;
m_mustDrawVisibleTilesCache = true; m_mustDrawVisibleTilesCache = true;
m_mustUpdateVisibleTilesCache = false; m_mustUpdateVisibleTilesCache = false;
} } else
m_mustCleanFramebuffer = false;
// there is no tile to render on invalid positions // there is no tile to render on invalid positions
Position cameraPosition = getCameraPosition(); Position cameraPosition = getCameraPosition();
@ -227,7 +226,7 @@ void MapView::updateVisibleTilesCache(int start)
if(tile->isEmpty()) if(tile->isEmpty())
continue; continue;
// skip tiles that are completely behind another tile // skip tiles that are completely behind another tile
if(g_map.isCompletelyCovered(tilePos, m_cachedLastVisibleFloor)) if(g_map.isCompletelyCovered(tilePos, m_cachedFirstVisibleFloor))
continue; continue;
m_cachedVisibleTiles.push_back(tile); m_cachedVisibleTiles.push_back(tile);
} }
@ -323,9 +322,6 @@ void MapView::updateVisibleTilesCache(int start)
// skip tiles that have nothing // skip tiles that have nothing
if(tile->isEmpty()) if(tile->isEmpty())
continue; continue;
// skip tiles that are completely behind another tile
if(g_map.isCompletelyCovered(tilePos, m_cachedLastVisibleFloor))
continue;
m_cachedVisibleTiles.push_back(tile); m_cachedVisibleTiles.push_back(tile);
} }
} }

View File

@ -69,6 +69,7 @@ public:
// type related // type related
bool isGround() { return m_type->properties[ThingType::IsGround]; } bool isGround() { return m_type->properties[ThingType::IsGround]; }
bool isFullGround() { return m_type->properties[ThingType::IsFullGround]; } bool isFullGround() { return m_type->properties[ThingType::IsFullGround]; }
bool isTranslucent() { return m_type->properties[ThingType::IsTranslucent]; }
bool isGroundBorder() { return m_type->properties[ThingType::IsGroundBorder]; } bool isGroundBorder() { return m_type->properties[ThingType::IsGroundBorder]; }
bool isOnBottom() { return m_type->properties[ThingType::IsOnBottom]; } bool isOnBottom() { return m_type->properties[ThingType::IsOnBottom]; }
bool isOnTop() { return m_type->properties[ThingType::IsOnTop]; } bool isOnTop() { return m_type->properties[ThingType::IsOnTop]; }

View File

@ -49,6 +49,9 @@ public:
uint32 getSignature() { return m_signature; } uint32 getSignature() { return m_signature; }
bool isLoaded() { return m_loaded; } bool isLoaded() { return m_loaded; }
int getFirstItemId() { return 100; }
int getMaxItemid() { return m_things[Item].size() + 100 - 1; }
private: private:
uint32 m_signature; uint32 m_signature;
Boolean<false> m_loaded; Boolean<false> m_loaded;

View File

@ -114,6 +114,8 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassMemberFunction<Thing>("isPickupable", &Thing::isPickupable); g_lua.bindClassMemberFunction<Thing>("isPickupable", &Thing::isPickupable);
g_lua.bindClassMemberFunction<Thing>("isIgnoreLook", &Thing::isIgnoreLook); g_lua.bindClassMemberFunction<Thing>("isIgnoreLook", &Thing::isIgnoreLook);
g_lua.bindClassMemberFunction<Thing>("isStackable", &Thing::isStackable); g_lua.bindClassMemberFunction<Thing>("isStackable", &Thing::isStackable);
g_lua.bindClassMemberFunction<Thing>("isTranslucent", &Thing::isTranslucent);
g_lua.bindClassMemberFunction<Thing>("isFullGround", &Thing::isFullGround);
g_lua.registerClass<Creature, Thing>(); g_lua.registerClass<Creature, Thing>();
g_lua.bindClassMemberFunction<Creature>("getName", &Creature::getName); g_lua.bindClassMemberFunction<Creature>("getName", &Creature::getName);