From: Daniel Karbach Date: Sat, 6 Oct 2012 20:08:11 +0000 (+0200) Subject: added debug mode for maps X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=07cdc452aeaad73ca9f8f9a3cf9868d2b6c9d5b3;p=l2e.git added debug mode for maps currently shows tile blocking flags as little red lines --- diff --git a/src/map/Area.cpp b/src/map/Area.cpp index 292b895..0b25a04 100644 --- a/src/map/Area.cpp +++ b/src/map/Area.cpp @@ -44,4 +44,49 @@ void Area::Render(SDL_Surface *dest, const graphics::Sprite *tileset, const Vect } } +void Area::RenderDebug(SDL_Surface *dest, const graphics::Sprite *tileset, const Vector &inOffset) const { + for (int i(0); i < numTiles; ++i) { + Vector offset( + inOffset.X() + (i % width) * tileset->Width(), + inOffset.Y() + (i / width) * tileset->Height()); + const Tile &tile(tiles[i]); + + if (tile.BlocksNorth()) { + SDL_Rect destRect; + destRect.x = offset.X(); + destRect.y = offset.Y(); + destRect.w = tileset->Width(); + destRect.h = 1; + SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00)); + } + + if (tile.BlocksEast()) { + SDL_Rect destRect; + destRect.x = offset.X() + tileset->Width() - 1; + destRect.y = offset.Y(); + destRect.w = 1; + destRect.h = tileset->Height(); + SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00)); + } + + if (tile.BlocksSouth()) { + SDL_Rect destRect; + destRect.x = offset.X(); + destRect.y = offset.Y() + tileset->Height() - 1; + destRect.w = tileset->Width(); + destRect.h = 1; + SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00)); + } + + if (tile.BlocksWest()) { + SDL_Rect destRect; + destRect.x = offset.X(); + destRect.y = offset.Y(); + destRect.w = 1; + destRect.h = tileset->Height(); + SDL_FillRect(dest, &destRect, SDL_MapRGB(dest->format, 0xFF, 0x00, 0x00)); + } + } +} + } diff --git a/src/map/Area.h b/src/map/Area.h index e2b6a1e..0a56339 100644 --- a/src/map/Area.h +++ b/src/map/Area.h @@ -29,6 +29,7 @@ public: const Tile &TileAt(const geometry::Vector &) const; void Render(SDL_Surface *dest, const graphics::Sprite *tileset, const geometry::Vector &offset) const; + void RenderDebug(SDL_Surface *dest, const graphics::Sprite *tileset, const geometry::Vector &offset) const; // temporary setters public: diff --git a/src/map/Map.cpp b/src/map/Map.cpp index 20f2fa5..c7d75f1 100644 --- a/src/map/Map.cpp +++ b/src/map/Map.cpp @@ -71,4 +71,13 @@ void Map::Render(SDL_Surface *dest, const Vector &inOffset) const { } } +void Map::RenderDebug(SDL_Surface *dest, const Vector &inOffset) const { + // TODO: skip invisible areas + for (int i(0); i < numAreas; ++i) { + const Area &area(areas[i]); + Vector offset(inOffset + Vector::FromIndex(i, width) * area.Size() * tileset->Size()); + area.RenderDebug(dest, tileset, offset); + } +} + } diff --git a/src/map/Map.h b/src/map/Map.h index bda62bd..a1b9ceb 100644 --- a/src/map/Map.h +++ b/src/map/Map.h @@ -30,6 +30,7 @@ public: geometry::Vector TileCoordinates(const geometry::Vector &) const; void Render(SDL_Surface *dest, const geometry::Vector &offset) const; + void RenderDebug(SDL_Surface *dest, const geometry::Vector &offset) const; // temporary setters public: diff --git a/src/map/MapState.cpp b/src/map/MapState.cpp index 108d97c..350a1f4 100644 --- a/src/map/MapState.cpp +++ b/src/map/MapState.cpp @@ -27,7 +27,8 @@ MapState::MapState(Map *map) , camera(100, 100, &tempTarget) , walkingSpeed(64) , nextDirection(-1) -, afterLock(false) { +, afterLock(false) +, debug(false) { } @@ -67,6 +68,10 @@ void MapState::HandleEvents(const Input &input) { } else { nextDirection = -1; } + + if (input.JustPressed(Input::DEBUG_1)) { + debug = !debug; + } } void MapState::UpdateWorld(float deltaT) { @@ -278,6 +283,10 @@ void MapState::Render(SDL_Surface *screen) { Vector offset(camera.CalculateOffset()); map->Render(screen, offset); + if (debug) { + map->RenderDebug(screen, offset); + } + std::sort(entities.begin(), entities.end(), ZCompare); for (std::vector::iterator i(entities.begin()), end(entities.end()); i != end; ++i) { (*i)->Render(screen, offset); diff --git a/src/map/MapState.h b/src/map/MapState.h index e7a75b6..4ba149d 100644 --- a/src/map/MapState.h +++ b/src/map/MapState.h @@ -69,6 +69,7 @@ private: float walkingSpeed; int nextDirection; bool afterLock; + bool debug; };