From e16fb5be90c889c371cbb0ca2444735c2e12073c Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 18 Feb 2018 12:35:45 -0500 Subject: Implemented map adjacency This brings along with it the ability to move to different maps, for which the PlayingSystem and PlayableComponent were introduced. The PlayingSystem is a general overseer system that handles big picture stuff like initializing the player and changing maps. The PlayableComponent represents the player. While the ControllableComponent is also likely to always only be on the player entity, the two are distinct by separation of concerns. This also required a refactoring of how collisions are processed, because of a bug where the player can move to a new map when horizontal collisions are checked, and vertical collisions are skipped, causing the player to clip through the ground because the normal force was never handled. --- CMakeLists.txt | 2 + src/collision.cpp | 97 +++++++++++++ src/collision.h | 81 +++++++++++ src/components/mappable.h | 10 +- src/components/playable.h | 15 ++ src/consts.h | 2 +- src/entity_manager.h | 10 ++ src/game.cpp | 27 +--- src/map.h | 70 +++++++++- src/systems/mapping.cpp | 28 ++++ src/systems/playing.cpp | 98 +++++++++++++ src/systems/playing.h | 21 +++ src/systems/pondering.cpp | 347 +++++++++++++++++++++++++++++++--------------- src/systems/pondering.h | 11 -- src/world.cpp | 58 +++++++- 15 files changed, 717 insertions(+), 160 deletions(-) create mode 100644 src/collision.cpp create mode 100644 src/collision.h create mode 100644 src/components/playable.h create mode 100644 src/systems/playing.cpp create mode 100644 src/systems/playing.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e7bcb8..155063e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,7 @@ add_executable(Aromatherapy src/animation.cpp src/world.cpp src/util.cpp + src/collision.cpp src/renderer/renderer.cpp src/renderer/mesh.cpp src/renderer/shader.cpp @@ -64,6 +65,7 @@ add_executable(Aromatherapy src/systems/animating.cpp src/systems/mapping.cpp src/systems/orienting.cpp + src/systems/playing.cpp ) set_property(TARGET Aromatherapy PROPERTY CXX_STANDARD 11) diff --git a/src/collision.cpp b/src/collision.cpp new file mode 100644 index 0000000..b747a90 --- /dev/null +++ b/src/collision.cpp @@ -0,0 +1,97 @@ +#include "collision.h" + +bool Collision::operator<(const Collision& other) const +{ + // Most important is the type of collision + if (type_ != other.type_) + { + return (static_cast(type_) > static_cast(other.type_)); + } + + // Next, categorize the collisions arbitrarily based on direction + if (dir_ != other.dir_) + { + return (static_cast(dir_) < static_cast(other.dir_)); + } + + // We want to process closer collisions first + if (axis_ != other.axis_) + { + switch (dir_) + { + case Direction::left: + case Direction::up: + { + return (axis_ < other.axis_); + } + + case Direction::right: + case Direction::down: + { + return (axis_ > other.axis_); + } + } + } + + // Order the remaining attributes arbitrarily + return std::tie(collider_, lower_, upper_) < + std::tie(other.collider_, other.lower_, other.upper_); +} + +bool Collision::isColliding( + double x, + double y, + int w, + int h) const +{ + int right = x + w; + int bottom = y + h; + + switch (dir_) + { + case Direction::left: + case Direction::right: + { + if (!((bottom > lower_) && (y < upper_))) + { + return false; + } + + break; + } + + case Direction::up: + case Direction::down: + { + if (!((right > lower_) && (x < upper_))) + { + return false; + } + + break; + } + } + + switch (dir_) + { + case Direction::left: + { + return (axis_ >= x); + } + + case Direction::right: + { + return (axis_ <= right); + } + + case Direction::up: + { + return (axis_ >= y); + } + + case Direction::down: + { + return (axis_ <= bottom); + } + } +} diff --git a/src/collision.h b/src/collision.h new file mode 100644 index 0000000..e5371f8 --- /dev/null +++ b/src/collision.h @@ -0,0 +1,81 @@ +#ifndef COLLISION_H_53D84877 +#define COLLISION_H_53D84877 + +#include "entity_manager.h" +#include "direction.h" + +class Collision { +public: + + using id_type = EntityManager::id_type; + + // Types are defined in descending priority order + enum class Type { + wall, + platform, + adjacency, + warp, + danger + }; + + Collision( + id_type collider, + Direction dir, + Type type, + int axis, + double lower, + double upper) : + collider_(collider), + dir_(dir), + type_(type), + axis_(axis), + lower_(lower), + upper_(upper) + { + } + + inline id_type getCollider() const + { + return collider_; + } + + inline Direction getDirection() const + { + return dir_; + } + + inline Type getType() const + { + return type_; + } + + inline int getAxis() const + { + return axis_; + } + + inline double getLower() const + { + return lower_; + } + + inline double getUpper() const + { + return upper_; + } + + bool operator<(const Collision& other) const; + + bool isColliding(double x, double y, int w, int h) const; + +private: + + id_type collider_; + Direction dir_; + Type type_; + int axis_; + double lower_; + double upper_; +}; + +#endif /* end of include guard: COLLISION_H_53D84877 */ diff --git a/src/components/mappable.h b/src/components/mappable.h index 2dbab77..633cdf4 100644 --- a/src/components/mappable.h +++ b/src/components/mappable.h @@ -4,6 +4,7 @@ #include #include "component.h" #include "renderer/texture.h" +#include "collision.h" #include "map.h" class MappableComponent : public Component { @@ -12,14 +13,7 @@ public: class Boundary { public: - enum class Type { - wall, - wrap, - teleport, - reverse, - platform, - danger - }; + using Type = Collision::Type; Boundary( double axis, diff --git a/src/components/playable.h b/src/components/playable.h new file mode 100644 index 0000000..a6e71b0 --- /dev/null +++ b/src/components/playable.h @@ -0,0 +1,15 @@ +#ifndef PLAYABLE_H_DDC566C3 +#define PLAYABLE_H_DDC566C3 + +#include "component.h" + +class PlayableComponent : public Component { +public: + + bool changingMap = false; + int newMapId = -1; + double newMapX = 0; + double newMapY = 0; +}; + +#endif /* end of include guard: PLAYABLE_H_DDC566C3 */ diff --git a/src/consts.h b/src/consts.h index 581018d..a065159 100644 --- a/src/consts.h +++ b/src/consts.h @@ -7,7 +7,7 @@ const int GAME_WIDTH = 320; const int GAME_HEIGHT = 200; const int MAP_WIDTH = GAME_WIDTH/TILE_WIDTH; const int MAP_HEIGHT = GAME_HEIGHT/TILE_HEIGHT - 1; -const int WALL_GAP = 6; +const int WALL_GAP = 5; const int TILESET_COLS = 8; const int FONT_COLS = 16; diff --git a/src/entity_manager.h b/src/entity_manager.h index 65fa6ca..1e8d31c 100644 --- a/src/entity_manager.h +++ b/src/entity_manager.h @@ -26,6 +26,7 @@ private: database_type entities; std::vector slotAvailable; + std::set allEntities; std::map, std::set> cachedComponents; id_type nextEntityID = 0; @@ -59,12 +60,14 @@ public: // If the database is saturated, add a new element for the new entity. entities.emplace_back(); slotAvailable.push_back(false); + allEntities.insert(nextEntityID); return nextEntityID++; } else { // If there is an available slot in the database, use it. id_type id = nextEntityID++; slotAvailable[id] = false; + allEntities.insert(id); // Fast forward the next available slot pointer to an available slot. while ((nextEntityID < entities.size()) && !slotAvailable[nextEntityID]) @@ -89,6 +92,8 @@ public: cache.second.erase(entity); } + allEntities.erase(entity); + // Destroy the data entities[entity].components.clear(); @@ -202,6 +207,11 @@ public: return getEntitiesWithComponentsHelper(componentTypes); } + + const std::set& getEntities() const + { + return allEntities; + } }; template <> diff --git a/src/game.cpp b/src/game.cpp index 228ff23..f245e7c 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -9,6 +9,7 @@ #include "systems/animating.h" #include "systems/mapping.h" #include "systems/orienting.h" +#include "systems/playing.h" #include "animation.h" #include "consts.h" @@ -28,36 +29,14 @@ void key_callback(GLFWwindow* window, int key, int, int action, int) Game::Game() : world_("res/maps.xml") { + systemManager_.emplaceSystem(*this); systemManager_.emplaceSystem(*this); systemManager_.emplaceSystem(*this); systemManager_.emplaceSystem(*this); systemManager_.emplaceSystem(*this); systemManager_.emplaceSystem(*this); - int player = entityManager_.emplaceEntity(); - - AnimationSet playerGraphics {"res/Starla.png", 10, 12, 6}; - playerGraphics.emplaceAnimation("stillLeft", 3, 1, 1); - playerGraphics.emplaceAnimation("stillRight", 0, 1, 1); - playerGraphics.emplaceAnimation("walkingLeft", 4, 2, 10); - playerGraphics.emplaceAnimation("walkingRight", 1, 2, 10); - - entityManager_.emplaceComponent( - player, - std::move(playerGraphics), - "stillLeft"); - - entityManager_.emplaceComponent( - player, - 203, 44, 10, 12); - - systemManager_.getSystem().initializeBody( - player, - PonderableComponent::Type::freefalling); - - entityManager_.emplaceComponent(player); - entityManager_.emplaceComponent(player); - + systemManager_.getSystem().initPlayer(); systemManager_.getSystem().loadMap(world_.getStartingMapId()); glfwSwapInterval(1); diff --git a/src/map.h b/src/map.h index 9177870..6fe1e62 100644 --- a/src/map.h +++ b/src/map.h @@ -10,13 +10,55 @@ class Map { public: + class Adjacent { + public: + + enum class Type { + wall, + wrap, + warp, + reverse + }; + + Adjacent( + Type type = Type::wall, + int mapId = -1) : + type_(type), + mapId_(mapId) + { + } + + inline Type getType() const + { + return type_; + } + + inline int getMapId() const + { + return mapId_; + } + + private: + + Type type_; + int mapId_; + }; + Map( int id, std::vector tiles, - std::string title) : + std::string title, + Adjacent leftAdjacent, + Adjacent rightAdjacent, + Adjacent upAdjacent, + Adjacent downAdjacent) : id_(id), tiles_(std::move(tiles)), - title_(std::move(title)) + title_(std::move(title)), + leftAdjacent_(std::move(leftAdjacent)), + rightAdjacent_(std::move(rightAdjacent)), + upAdjacent_(std::move(upAdjacent)), + downAdjacent_(std::move(downAdjacent)) { } @@ -35,11 +77,35 @@ public: return title_; } + inline const Adjacent& getLeftAdjacent() const + { + return leftAdjacent_; + } + + inline const Adjacent& getRightAdjacent() const + { + return rightAdjacent_; + } + + inline const Adjacent& getUpAdjacent() const + { + return upAdjacent_; + } + + inline const Adjacent& getDownAdjacent() const + { + return downAdjacent_; + } + private: int id_; std::vector tiles_; std::string title_; + Adjacent leftAdjacent_; + Adjacent rightAdjacent_; + Adjacent upAdjacent_; + Adjacent downAdjacent_; }; #endif /* end of include guard: MAP_H_74055FC0 */ diff --git a/src/systems/mapping.cpp b/src/systems/mapping.cpp index 120a27a..05167c1 100644 --- a/src/systems/mapping.cpp +++ b/src/systems/mapping.cpp @@ -93,6 +93,34 @@ void MappingSystem::loadMap(size_t mapId) const Map& map = game_.getWorld().getMap(mappable.getMapId()); + addBoundary( + mappable.getLeftBoundaries(), + -WALL_GAP, + 0, + MAP_HEIGHT * TILE_HEIGHT, + MappableComponent::Boundary::Type::adjacency); + + addBoundary( + mappable.getRightBoundaries(), + GAME_WIDTH + WALL_GAP, + 0, + MAP_HEIGHT * TILE_HEIGHT, + MappableComponent::Boundary::Type::adjacency); + + addBoundary( + mappable.getUpBoundaries(), + -WALL_GAP, + 0, + GAME_WIDTH, + MappableComponent::Boundary::Type::adjacency); + + addBoundary( + mappable.getDownBoundaries(), + MAP_HEIGHT * TILE_HEIGHT + WALL_GAP, + 0, + GAME_WIDTH, + MappableComponent::Boundary::Type::adjacency); + for (size_t i = 0; i < MAP_WIDTH * MAP_HEIGHT; i++) { size_t x = i % MAP_WIDTH; diff --git a/src/systems/playing.cpp b/src/systems/playing.cpp new file mode 100644 index 0000000..2c6a419 --- /dev/null +++ b/src/systems/playing.cpp @@ -0,0 +1,98 @@ +#include "playing.h" +#include "game.h" +#include "components/transformable.h" +#include "components/animatable.h" +#include "components/playable.h" +#include "components/controllable.h" +#include "components/orientable.h" +#include "systems/mapping.h" +#include "systems/pondering.h" +#include "animation.h" + +void PlayingSystem::tick(double) +{ + // Check if we need to change the map + auto players = game_.getEntityManager().getEntitiesWithComponents< + PlayableComponent>(); + + for (id_type player : players) + { + auto& playable = game_.getEntityManager(). + getComponent(player); + + if (playable.changingMap) + { + // Change the map! + auto entities = game_.getEntityManager().getEntities(); + + for (id_type entity : entities) + { + if (entity != player) + { + game_.getEntityManager().deleteEntity(entity); + } + } + + game_.getSystemManager().getSystem(). + loadMap(playable.newMapId); + + auto& transformable = game_.getEntityManager(). + getComponent(player); + + transformable.setX(playable.newMapX); + transformable.setY(playable.newMapY); + + playable.changingMap = false; + + break; + } + } +} + +void PlayingSystem::initPlayer() +{ + id_type player = game_.getEntityManager().emplaceEntity(); + + AnimationSet playerGraphics {"res/Starla.png", 10, 12, 6}; + playerGraphics.emplaceAnimation("stillLeft", 3, 1, 1); + playerGraphics.emplaceAnimation("stillRight", 0, 1, 1); + playerGraphics.emplaceAnimation("walkingLeft", 4, 2, 10); + playerGraphics.emplaceAnimation("walkingRight", 1, 2, 10); + + game_.getEntityManager().emplaceComponent( + player, + std::move(playerGraphics), + "stillLeft"); + + game_.getEntityManager().emplaceComponent( + player, + 203, 44, 10, 12); + + game_.getSystemManager().getSystem().initializeBody( + player, + PonderableComponent::Type::freefalling); + + game_.getEntityManager().emplaceComponent(player); + game_.getEntityManager().emplaceComponent(player); + game_.getEntityManager().emplaceComponent(player); +} + +void PlayingSystem::changeMap( + size_t mapId, + double x, + double y) +{ + auto players = game_.getEntityManager().getEntitiesWithComponents< + PlayableComponent>(); + + for (id_type player : players) + { + auto& playable = game_.getEntityManager(). + getComponent(player); + + playable.changingMap = true; + playable.newMapId = mapId; + playable.newMapX = x; + playable.newMapY = y; + } +} diff --git a/src/systems/playing.h b/src/systems/playing.h new file mode 100644 index 0000000..c98a464 --- /dev/null +++ b/src/systems/playing.h @@ -0,0 +1,21 @@ +#ifndef PLAYING_H_70A54F7D +#define PLAYING_H_70A54F7D + +#include "system.h" + +class PlayingSystem : public System { +public: + + PlayingSystem(Game& game) : System(game) + { + } + + void tick(double dt); + + void initPlayer(); + + void changeMap(size_t mapId, double x, double y); + +}; + +#endif /* end of include guard: PLAYING_H_70A54F7D */ diff --git a/src/systems/pondering.cpp b/src/systems/pondering.cpp index 4a165b1..2490dc9 100644 --- a/src/systems/pondering.cpp +++ b/src/systems/pondering.cpp @@ -1,11 +1,14 @@ #include "pondering.h" +#include #include "game.h" #include "components/ponderable.h" #include "components/transformable.h" #include "components/orientable.h" #include "components/mappable.h" #include "systems/orienting.h" +#include "systems/playing.h" #include "consts.h" +#include "collision.h" void PonderingSystem::tick(double dt) { @@ -42,6 +45,9 @@ void PonderingSystem::tick(double dt) bool oldGrounded = ponderable.isGrounded(); ponderable.setGrounded(false); + std::priority_queue collisions; + + // Find collisions for (id_type mapEntity : maps) { auto& mappable = game_.getEntityManager(). @@ -57,13 +63,13 @@ void PonderingSystem::tick(double dt) && (oldY < it->second.getUpper())) { // We have a collision! - processCollision( - entity, + collisions.emplace( + mapEntity, Direction::left, - newX, - newY, + it->second.getType(), it->first, - it->second.getType()); + it->second.getLower(), + it->second.getUpper()); } } } else if (newX > oldX) @@ -77,13 +83,13 @@ void PonderingSystem::tick(double dt) && (oldY < it->second.getUpper())) { // We have a collision! - processCollision( - entity, + collisions.emplace( + mapEntity, Direction::right, - newX, - newY, + it->second.getType(), it->first, - it->second.getType()); + it->second.getLower(), + it->second.getUpper()); } } } @@ -98,13 +104,13 @@ void PonderingSystem::tick(double dt) && (oldX < it->second.getUpper())) { // We have a collision! - processCollision( - entity, + collisions.emplace( + mapEntity, Direction::up, - newX, - newY, + it->second.getType(), it->first, - it->second.getType()); + it->second.getLower(), + it->second.getUpper()); } } } else if (newY > oldY) @@ -118,13 +124,221 @@ void PonderingSystem::tick(double dt) && (oldX < it->second.getUpper())) { // We have a collision! - processCollision( - entity, + collisions.emplace( + mapEntity, Direction::down, - newX, - newY, + it->second.getType(), it->first, - it->second.getType()); + it->second.getLower(), + it->second.getUpper()); + } + } + } + } + + // Process collisions in order of priority + while (!collisions.empty()) + { + Collision collision = collisions.top(); + collisions.pop(); + + // Make sure that they are still colliding + if (!collision.isColliding( + newX, + newY, + transformable.getW(), + transformable.getH())) + { + continue; + } + + bool touchedWall = false; + bool stopProcessing = false; + + switch (collision.getType()) + { + case Collision::Type::wall: + { + touchedWall = true; + + break; + } + + case Collision::Type::platform: + { + if (game_.getEntityManager(). + hasComponent(entity)) + { + auto& orientable = game_.getEntityManager(). + getComponent(entity); + + if (orientable.getDropState() != + OrientableComponent::DropState::none) + { + orientable.setDropState(OrientableComponent::DropState::active); + } else { + touchedWall = true; + } + } else { + touchedWall = true; + } + + break; + } + + case Collision::Type::adjacency: + { + auto& mappable = game_.getEntityManager(). + getComponent(collision.getCollider()); + const Map& map = game_.getWorld().getMap(mappable.getMapId()); + auto& adj = [&] () -> const Map::Adjacent& { + switch (collision.getDirection()) + { + case Direction::left: return map.getLeftAdjacent(); + case Direction::right: return map.getRightAdjacent(); + case Direction::up: return map.getUpAdjacent(); + case Direction::down: return map.getDownAdjacent(); + } + }(); + + switch (adj.getType()) + { + case Map::Adjacent::Type::wall: + { + touchedWall = true; + + break; + } + + case Map::Adjacent::Type::wrap: + { + switch (collision.getDirection()) + { + case Direction::left: + { + newX = GAME_WIDTH + WALL_GAP - transformable.getW(); + + break; + } + + case Direction::right: + { + newX = -WALL_GAP; + + break; + } + + case Direction::up: + { + newY = MAP_HEIGHT * TILE_HEIGHT + WALL_GAP - + transformable.getH(); + + break; + } + + case Direction::down: + { + newY = -WALL_GAP; + + break; + } + } + } + + case Map::Adjacent::Type::warp: + { + double warpX = newX; + double warpY = newY; + + switch (collision.getDirection()) + { + case Direction::left: + { + warpX = GAME_WIDTH + WALL_GAP - transformable.getW(); + + break; + } + + case Direction::right: + { + warpX = -WALL_GAP; + + break; + } + + case Direction::up: + { + warpY = MAP_HEIGHT * TILE_HEIGHT - transformable.getH(); + + break; + } + + case Direction::down: + { + warpY = -WALL_GAP; + + break; + } + } + + game_.getSystemManager().getSystem(). + changeMap(adj.getMapId(), warpX, warpY); + + stopProcessing = true; + + break; + } + } + } + + default: + { + // Not yet implemented. + + break; + } + } + + if (stopProcessing) + { + break; + } + + if (touchedWall) + { + switch (collision.getDirection()) + { + case Direction::left: + { + newX = collision.getAxis(); + ponderable.setVelocityX(0.0); + + break; + } + + case Direction::right: + { + newX = collision.getAxis() - transformable.getW(); + ponderable.setVelocityX(0.0); + + break; + } + + case Direction::up: + { + newY = collision.getAxis(); + ponderable.setVelocityY(0.0); + + break; + } + + case Direction::down: + { + newY = collision.getAxis() - transformable.getH(); + ponderable.setVelocityY(0.0); + ponderable.setGrounded(true); + + break; } } } @@ -173,96 +387,3 @@ void PonderingSystem::initializeBody( ponderable.setAccelY(NORMAL_GRAVITY); } } - -void PonderingSystem::processCollision( - id_type entity, - Direction dir, - double& newX, - double& newY, - int axis, - MappableComponent::Boundary::Type type) -{ - auto& ponderable = game_.getEntityManager(). - getComponent(entity); - - auto& transformable = game_.getEntityManager(). - getComponent(entity); - - bool touchedGround = false; - - switch (type) - { - case MappableComponent::Boundary::Type::wall: - { - switch (dir) - { - case Direction::left: - { - newX = axis; - ponderable.setVelocityX(0.0); - - break; - } - - case Direction::right: - { - newX = axis - transformable.getW(); - ponderable.setVelocityX(0.0); - - break; - } - - case Direction::up: - { - newY = axis; - ponderable.setVelocityY(0.0); - - break; - } - - case Direction::down: - { - touchedGround = true; - - break; - } - } - - break; - } - - case MappableComponent::Boundary::Type::platform: - { - if (game_.getEntityManager().hasComponent(entity)) - { - auto& orientable = game_.getEntityManager(). - getComponent(entity); - - if (orientable.getDropState() != OrientableComponent::DropState::none) - { - orientable.setDropState(OrientableComponent::DropState::active); - } else { - touchedGround = true; - } - } else { - touchedGround = true; - } - - break; - } - - default: - { - // Not yet implemented. - - break; - } - } - - if (touchedGround) - { - newY = axis - transformable.getH(); - ponderable.setVelocityY(0.0); - ponderable.setGrounded(true); - } -} diff --git a/src/systems/pondering.h b/src/systems/pondering.h index a16622b..d70525b 100644 --- a/src/systems/pondering.h +++ b/src/systems/pondering.h @@ -2,7 +2,6 @@ #define PONDERING_H_F2530E0E #include "system.h" -#include "components/mappable.h" #include "components/ponderable.h" #include "direction.h" @@ -17,16 +16,6 @@ public: void initializeBody(id_type entity, PonderableComponent::Type type); -private: - - void processCollision( - id_type entity, - Direction dir, - double& newX, - double& newY, - int axis, - MappableComponent::Boundary::Type type); - }; #endif /* end of include guard: PONDERING_H_F2530E0E */ diff --git a/src/world.cpp b/src/world.cpp index 9b1e4f6..3b6bd41 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -63,6 +63,10 @@ World::World(std::string filename) xmlFree(key); std::vector mapTiles; + Map::Adjacent leftAdj; + Map::Adjacent rightAdj; + Map::Adjacent upAdj; + Map::Adjacent downAdj; for (xmlNodePtr mapNode = node->xmlChildrenNode; mapNode != nullptr; @@ -82,6 +86,54 @@ World::World(std::string filename) } xmlFree(key); + } else if (!xmlStrcmp( + mapNode->name, + reinterpret_cast("adjacent"))) + { + key = getProp(mapNode, "type"); + std::string adjTypeStr(reinterpret_cast(key)); + xmlFree(key); + + Map::Adjacent::Type adjType; + if (adjTypeStr == "wall") + { + adjType = Map::Adjacent::Type::wall; + } else if (adjTypeStr == "wrap") + { + adjType = Map::Adjacent::Type::wrap; + } else if (adjTypeStr == "warp") + { + adjType = Map::Adjacent::Type::warp; + } else if (adjTypeStr == "reverseWarp") + { + adjType = Map::Adjacent::Type::reverse; + } else { + throw std::logic_error("Invalid adjacency type"); + } + + key = getProp(mapNode, "map"); + int adjMapId = atoi(reinterpret_cast(key)); + xmlFree(key); + + key = getProp(mapNode, "dir"); + std::string adjDir(reinterpret_cast(key)); + xmlFree(key); + + if (adjDir == "left") + { + leftAdj = {adjType, adjMapId}; + } else if (adjDir == "right") + { + rightAdj = {adjType, adjMapId}; + } else if (adjDir == "up") + { + upAdj = {adjType, adjMapId}; + } else if (adjDir == "down") + { + downAdj = {adjType, adjMapId}; + } else { + throw std::logic_error("Invalid adjacency direction"); + } } } @@ -91,7 +143,11 @@ World::World(std::string filename) std::forward_as_tuple( mapId, std::move(mapTiles), - std::move(mapTitle))); + std::move(mapTitle), + leftAdj, + rightAdj, + upAdj, + downAdj)); } } -- cgit 1.4.1