Skip to content

Commit

Permalink
sort variableNames to provide consistent observations
Browse files Browse the repository at this point in the history
  • Loading branch information
daveey committed Feb 13, 2024
1 parent 9623461 commit d593520
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/Griddly/Core/Grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ std::shared_ptr<Object> Grid::getObject(glm::ivec2 location) const {
const auto& objectsAtLocation = occupiedLocations_.at(location);
if (!objectsAtLocation.empty()) {
// Get the highest index object

return objectsAtLocation.rbegin()->second;
}
}
Expand Down Expand Up @@ -497,6 +498,10 @@ void Grid::initObject(std::string objectName, std::vector<std::string> variableN
objectCounters_.insert({objectName, {{0, std::make_shared<int32_t>(0)}}});

for (auto& variableName : variableNames) {
objectVariables_.insert(variableName);
}
objectVariableMap_.clear();
for (auto& variableName : objectVariables_) {
objectVariableIds_.insert({variableName, objectVariableIds_.size()});
}

Expand Down Expand Up @@ -739,4 +744,4 @@ const std::unordered_map<std::string, std::unordered_set<std::string>>& Grid::ge
return collisionObjectActionNames_;
}

} // namespace griddly
} // namespace griddly
5 changes: 3 additions & 2 deletions src/Griddly/Core/Grid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Grid : public std::enable_shared_from_this<Grid> {
virtual const std::unordered_set<std::shared_ptr<Object>>& getObjects();

virtual void addPlayerDefaultEmptyObject(std::shared_ptr<Object> emptyObject);

virtual void addPlayerDefaultBoundaryObject(std::shared_ptr<Object> boundaryObject);

virtual std::shared_ptr<Object> getPlayerDefaultEmptyObject(uint32_t playerId) const;
Expand Down Expand Up @@ -199,6 +199,7 @@ class Grid : public std::enable_shared_from_this<Grid> {
std::vector<std::unordered_set<glm::ivec2>> updatedLocations_;

std::unordered_map<std::string, uint32_t> objectIds_;
std::set<std::string> objectVariables_;
std::unordered_map<std::string, uint32_t> objectVariableIds_;
std::unordered_map<std::string, std::vector<std::string>> objectVariableMap_;
std::unordered_set<std::shared_ptr<Object>> objects_;
Expand Down Expand Up @@ -248,4 +249,4 @@ class Grid : public std::enable_shared_from_this<Grid> {
std::shared_ptr<RandomGenerator> randomGenerator_ = std::make_shared<RandomGenerator>(RandomGenerator());
};

} // namespace griddly
} // namespace griddly

0 comments on commit d593520

Please sign in to comment.