From d593520b100b2b288bbf4bc05452de3abb3c3b07 Mon Sep 17 00:00:00 2001 From: David Bloomin Date: Tue, 13 Feb 2024 13:57:29 -0800 Subject: [PATCH] sort variableNames to provide consistent observations --- src/Griddly/Core/Grid.cpp | 7 ++++++- src/Griddly/Core/Grid.hpp | 5 +++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Griddly/Core/Grid.cpp b/src/Griddly/Core/Grid.cpp index c15b26fd..ce157645 100644 --- a/src/Griddly/Core/Grid.cpp +++ b/src/Griddly/Core/Grid.cpp @@ -446,6 +446,7 @@ std::shared_ptr Grid::getObject(glm::ivec2 location) const { const auto& objectsAtLocation = occupiedLocations_.at(location); if (!objectsAtLocation.empty()) { // Get the highest index object + return objectsAtLocation.rbegin()->second; } } @@ -497,6 +498,10 @@ void Grid::initObject(std::string objectName, std::vector variableN objectCounters_.insert({objectName, {{0, std::make_shared(0)}}}); for (auto& variableName : variableNames) { + objectVariables_.insert(variableName); + } + objectVariableMap_.clear(); + for (auto& variableName : objectVariables_) { objectVariableIds_.insert({variableName, objectVariableIds_.size()}); } @@ -739,4 +744,4 @@ const std::unordered_map>& Grid::ge return collisionObjectActionNames_; } -} // namespace griddly \ No newline at end of file +} // namespace griddly diff --git a/src/Griddly/Core/Grid.hpp b/src/Griddly/Core/Grid.hpp index c3ad8b3f..21b996e2 100644 --- a/src/Griddly/Core/Grid.hpp +++ b/src/Griddly/Core/Grid.hpp @@ -110,7 +110,7 @@ class Grid : public std::enable_shared_from_this { virtual const std::unordered_set>& getObjects(); virtual void addPlayerDefaultEmptyObject(std::shared_ptr emptyObject); - + virtual void addPlayerDefaultBoundaryObject(std::shared_ptr boundaryObject); virtual std::shared_ptr getPlayerDefaultEmptyObject(uint32_t playerId) const; @@ -199,6 +199,7 @@ class Grid : public std::enable_shared_from_this { std::vector> updatedLocations_; std::unordered_map objectIds_; + std::set objectVariables_; std::unordered_map objectVariableIds_; std::unordered_map> objectVariableMap_; std::unordered_set> objects_; @@ -248,4 +249,4 @@ class Grid : public std::enable_shared_from_this { std::shared_ptr randomGenerator_ = std::make_shared(RandomGenerator()); }; -} // namespace griddly \ No newline at end of file +} // namespace griddly