diff --git a/README.md b/README.md index cbc732f..ede598f 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,20 @@ Project Maat is the codename of my C++ course "mini-project" based on the quote This game is aimed to be a puzzle game in which the player sets different laws for the world and the people within it as to control what happens after hitting "play" and achieve the level's goal. I was inspired both by [The Incredible Machine](https://en.wikipedia.org/wiki/The_Incredible_Machine_(video_game)) and its successors and by a much more recent game : [Baba is you](https://en.wikipedia.org/wiki/Baba_Is_You). +## Dependencies + +The following libraries must be installed on your system or findable by CMake to be able to build: + - SFML + - TGui + - PugiXML + - GTest + ## Structure ![UML Diagram](UML_Class_Diagram.png) +The class diagram omits most constructors and getters. + ## TODO - [x] Level @@ -25,6 +35,7 @@ This game is aimed to be a puzzle game in which the player sets different laws f - [x] Interaction with entities - [ ] Parsing of rules and creation of subsequent decorators - [x] Find optimal target for pathfinding + - [ ] Other rules (Waiting...) - [ ] Graphics - [x] Scene rendering - [ ] UI @@ -33,6 +44,7 @@ This game is aimed to be a puzzle game in which the player sets different laws f - [ ] Transition from starting to running state and vice-versa - [ ] Entity behaviour evolution - [x] Rule application - - [ ] Saving state through serialization ? + - [ ] Win condition + - [ ] ~~Saving state through serialization ?~~ - [ ] UML - [ ] Unit tests \ No newline at end of file diff --git a/UML_Class_Diagram.png b/UML_Class_Diagram.png index e5faeff..640b843 100644 Binary files a/UML_Class_Diagram.png and b/UML_Class_Diagram.png differ diff --git a/src/Level.cpp b/src/Level.cpp index 65633b4..046ac13 100644 --- a/src/Level.cpp +++ b/src/Level.cpp @@ -14,7 +14,7 @@ Level::Level(const pugi::xml_document& xmlDoc, const pro_maat::TextureStore& tex { if(!strncmp(child.name(),"Entity",6)) { - entities.emplace_back(std::make_unique(child,textures.at(child.attribute("textureId").as_int(0)).get())); + entities.emplace_back(std::make_shared(child,textures.at(child.attribute("textureId").as_int(0)).get())); // Initialize the occupied squares vector with the new entity's squares std::vector entitySquares = entities.rbegin()->get()->getOccupiedSquares(); @@ -23,7 +23,8 @@ Level::Level(const pugi::xml_document& xmlDoc, const pro_maat::TextureStore& tex } // FIXME : For testing purposes - addRule(EntityType::Significant,State::Moving,EntityType::Citizen); + addRule(EntityType::Significant,State::Fleeing,EntityType::Citizen); + addRule(EntityType::Citizen,State::Moving,EntityType::Significant); } void Level::addRule(EntityType affectedEntities, const State targetState, EntityType targetEntities) @@ -32,7 +33,7 @@ void Level::addRule(EntityType affectedEntities, const State targetState, Entity { if(entity->getType() == affectedEntities) { - entity = std::make_unique(entity.release(),targetState,targetEntities,entities,occupiedSquares,size); + entity = std::make_shared(entity,targetState,targetEntities,entities,occupiedSquares,size); } } } @@ -189,7 +190,7 @@ Orientation Level::findPath(pro_maat::GridPos start, pro_maat::GridPos goal, int } pathCosts.insert_or_assign(neighbour,newPathCost); - estimatedCosts.insert_or_assign(neighbour,newPathCost + pro_maat::manhattanDistance(neighbour,goal)); + estimatedCosts.insert_or_assign(neighbour,newPathCost + pro_maat::manhattanDistance(neighbour,goal)*sign); paths.insert_or_assign(neighbour,currentNode); } } diff --git a/src/Level.h b/src/Level.h index 0171da9..a19aede 100644 --- a/src/Level.h +++ b/src/Level.h @@ -11,6 +11,7 @@ #include #include #include +#include #include "Utils.h" #include "Entity.h" @@ -34,7 +35,7 @@ public: private: const pro_maat::GridPos size; - std::vector> entities; + std::vector> entities; const pro_maat::TextureStore& textures; diff --git a/src/Rule.cpp b/src/Rule.cpp index b875d8f..87f97c7 100644 --- a/src/Rule.cpp +++ b/src/Rule.cpp @@ -5,10 +5,10 @@ #include "Rule.h" -Rule::Rule(Entity* entity, State targetState, EntityType targetType, - std::vector>& entities, +Rule::Rule(std::shared_ptr entity, State targetState, EntityType targetType, + const std::vector>& entities, const std::vector& occupiedSquares, const pro_maat::GridPos& mapSize) - : entity(entity), + : entity(std::move(entity)), targetState(targetState), targetType(targetType), entities(entities), @@ -47,12 +47,11 @@ void Rule::update() pro_maat::GridPos Rule::findTarget() { - // TODO : Sorting in place, consider using shared_ptr ? -// std::vector sortedEntities{}; -// sortedEntities.insert(sortedEntities.end(),entities.begin(),entities.end()); + std::vector> sortedEntities{}; + sortedEntities.insert(sortedEntities.end(),entities.begin(),entities.end()); // Compares entities via their distance to the current entity - auto distanceSortEntities = [this](const std::unique_ptr& leftHandSide, const std::unique_ptr& rightHandSide){ + auto distanceSortEntities = [this](const std::shared_ptr& leftHandSide, const std::shared_ptr& rightHandSide){ return (pro_maat::manhattanDistance(entity->getPosition(),leftHandSide->getPosition()) < pro_maat::manhattanDistance(entity->getPosition(),rightHandSide->getPosition())); }; @@ -90,9 +89,9 @@ pro_maat::GridPos Rule::findTarget() // Sort in order to minimize entities to process - std::sort(entities.begin(),entities.end(),distanceSortEntities); + std::sort(sortedEntities.begin(),sortedEntities.end(),distanceSortEntities); - for(const auto& processingEntity : entities) + for(const auto& processingEntity : sortedEntities) { if(processingEntity->getType() != targetType) continue; @@ -128,7 +127,6 @@ pro_maat::GridPos Rule::findTarget() if(target != potentialTargets.end()) { - std::cout << "Target : (" << (*target).first << ","<< (*target).second << ")" << std::endl; return (*target); } } diff --git a/src/Rule.h b/src/Rule.h index 55edf72..97e0228 100644 --- a/src/Rule.h +++ b/src/Rule.h @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include "Entity.h" @@ -18,7 +18,8 @@ class Rule : public Entity { public: // The Rule object takes ownership of the Entity* - Rule(Entity* entity, State targetState, EntityType targetType, std::vector>& entities, + Rule(std::shared_ptr entity, State targetState, EntityType targetType, + const std::vector>& entities, const std::vector& occupiedSquares, const pro_maat::GridPos& mapSize); /// Update according to the targetState and targetType @@ -40,13 +41,12 @@ private: /// \return Suitable target square or current position if none was found. pro_maat::GridPos findTarget(); - std::unique_ptr entity; + std::shared_ptr entity; State targetState; EntityType targetType; - // TOOD : dropped const-qualifier. Consider using shared_ptr ? - std::vector>& entities; + const std::vector>& entities; const std::vector& occupiedSquares; const pro_maat::GridPos& mapSize;