diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 2b2dd289b..ced069c97 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -24,7 +24,7 @@ If applicable, add screenshots to help explain your problem. **Desktop (please complete the following information):** - OS: [e.g. mac/linux/windows] - - Version [e.g. 1.2.17] + - Version [e.g. 1.2.18] **Additional context** Add any other context about the problem here. diff --git a/CMakeLists.txt b/CMakeLists.txt index fdd5fd5f4..1737c4064 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.10.0) -project(Griddly VERSION 1.2.17) +project(Griddly VERSION 1.2.18) set(BINARY ${CMAKE_PROJECT_NAME}) diff --git a/bindings/python.cpp b/bindings/python.cpp index 837c68bd3..f33dcf7c5 100644 --- a/bindings/python.cpp +++ b/bindings/python.cpp @@ -12,7 +12,7 @@ namespace griddly { PYBIND11_MODULE(python_griddly, m) { m.doc() = "Griddly python bindings"; - m.attr("version") = "1.2.17"; + m.attr("version") = "1.2.18"; #ifndef NDEBUG spdlog::set_level(spdlog::level::debug); diff --git a/bindings/wrapper/GDYWrapper.cpp b/bindings/wrapper/GDYWrapper.cpp index 83c15a860..c7670623a 100644 --- a/bindings/wrapper/GDYWrapper.cpp +++ b/bindings/wrapper/GDYWrapper.cpp @@ -80,7 +80,7 @@ class Py_GDYWrapper { } std::shared_ptr createGame(ObserverType globalObserverType) { - return std::shared_ptr(new Py_GameWrapper(globalObserverType, gdyFactory_)); + return std::make_shared(Py_GameWrapper(globalObserverType, gdyFactory_)); } private: diff --git a/bindings/wrapper/GameWrapper.cpp b/bindings/wrapper/GameWrapper.cpp index e6991b47a..41be3183a 100644 --- a/bindings/wrapper/GameWrapper.cpp +++ b/bindings/wrapper/GameWrapper.cpp @@ -1,11 +1,9 @@ -#pragma once - #include #include "../../src/Griddly/Core/TurnBasedGameProcess.hpp" +#include "EntityObserverWrapper.cpp" #include "NumpyWrapper.cpp" #include "StepPlayerWrapper.cpp" -#include "EntityObserverWrapper.cpp" namespace griddly { @@ -18,7 +16,7 @@ class ValidActionNode { } void add(uint32_t value) { - children[value] = std::shared_ptr(new ValidActionNode()); + children[value] = std::make_shared(ValidActionNode()); } static py::dict toPyDict(std::shared_ptr node) { @@ -33,13 +31,9 @@ class ValidActionNode { class Py_GameWrapper { public: - Py_GameWrapper(ObserverType globalObserverType, std::shared_ptr gdyFactory) - : gdyFactory_(gdyFactory), - gameProcess_(std::shared_ptr( - new TurnBasedGameProcess( - globalObserverType, - gdyFactory, - std::shared_ptr(new Grid())))) { + Py_GameWrapper(ObserverType globalObserverType, std::shared_ptr gdyFactory) : gdyFactory_(gdyFactory) { + std::shared_ptr grid = std::make_shared(Grid()); + gameProcess_ = std::make_shared(TurnBasedGameProcess(globalObserverType, gdyFactory, grid)); spdlog::debug("Created game process wrapper"); } @@ -57,7 +51,7 @@ class Py_GameWrapper { auto observer = gdyFactory_->createObserver(gameProcess_->getGrid(), observerType); auto nextPlayerId = ++playerCount_; - auto player = std::shared_ptr(new Py_StepPlayerWrapper(nextPlayerId, playerName, observer, gdyFactory_, gameProcess_)); + auto player = std::make_shared(Py_StepPlayerWrapper(nextPlayerId, playerName, observer, gdyFactory_, gameProcess_)); players_.push_back(player); gameProcess_->addPlayer(player->unwrapped()); return player; @@ -78,7 +72,7 @@ class Py_GameWrapper { auto externalActionNames = gdyFactory_->getExternalActionNames(); spdlog::debug("Building tree, {0} actions", externalActionNames.size()); for (int playerId = 1; playerId <= playerCount_; playerId++) { - std::shared_ptr node = std::shared_ptr(new ValidActionNode()); + std::shared_ptr node = std::make_shared(ValidActionNode()); for (auto actionNamesAtLocation : gameProcess_->getAvailableActionNames(playerId)) { auto location = actionNamesAtLocation.first; auto actionNames = actionNamesAtLocation.second; @@ -150,7 +144,6 @@ class Py_GameWrapper { } py::dict getAvailableActionIds(std::vector location, std::vector actionNames) { - spdlog::debug("Getting available action ids for location [{0},{1}]", location[0], location[1]); py::dict py_availableActionIds; @@ -205,7 +198,7 @@ class Py_GameWrapper { auto observationData = observer->update(); - return std::shared_ptr>(new NumpyWrapper(observer->getShape(), observer->getStrides(), observationData)); + return std::make_shared>(NumpyWrapper(observer->getShape(), observer->getStrides(), observationData)); } py::tuple stepParallel(py::buffer stepArray) { @@ -280,8 +273,8 @@ class Py_GameWrapper { } } - for(int p = 0; p < playerSize; p++) { - playerRewards.push_back(gameProcess_->getAccumulatedRewards(p+1)); + for (int p = 0; p < playerSize; p++) { + playerRewards.push_back(gameProcess_->getAccumulatedRewards(p + 1)); } return py::make_tuple(playerRewards, terminated, info); @@ -311,11 +304,7 @@ class Py_GameWrapper { std::shared_ptr clone() { auto clonedGameProcess = gameProcess_->clone(); - - auto clonedPyGameProcessWrapper = std::shared_ptr( - new Py_GameWrapper( - gdyFactory_, - clonedGameProcess)); + auto clonedPyGameProcessWrapper = std::make_shared(Py_GameWrapper(gdyFactory_, clonedGameProcess)); return clonedPyGameProcessWrapper; } @@ -442,7 +431,7 @@ class Py_GameWrapper { } private: - const std::shared_ptr gameProcess_; + std::shared_ptr gameProcess_; const std::shared_ptr gdyFactory_; uint32_t playerCount_ = 0; std::vector> players_; diff --git a/bindings/wrapper/GriddlyLoaderWrapper.cpp b/bindings/wrapper/GriddlyLoaderWrapper.cpp index 29d8b5032..717f785f8 100644 --- a/bindings/wrapper/GriddlyLoaderWrapper.cpp +++ b/bindings/wrapper/GriddlyLoaderWrapper.cpp @@ -17,20 +17,20 @@ class Py_GriddlyLoaderWrapper { } std::shared_ptr loadGDYFile(std::string filename) { - auto objectGenerator = std::shared_ptr(new ObjectGenerator()); - auto terminationGenerator = std::shared_ptr(new TerminationGenerator()); - auto gdyFactory = std::shared_ptr(new GDYFactory(objectGenerator, terminationGenerator, resourceConfig_)); + auto objectGenerator = std::make_shared(ObjectGenerator()); + auto terminationGenerator = std::make_shared(TerminationGenerator()); + auto gdyFactory = std::make_shared(GDYFactory(objectGenerator, terminationGenerator, resourceConfig_)); gdyFactory->initializeFromFile(filename); - return std::shared_ptr(new Py_GDYWrapper(gdyFactory)); + return std::make_shared(Py_GDYWrapper(gdyFactory)); } std::shared_ptr loadGDYString(std::string string) { - auto objectGenerator = std::shared_ptr(new ObjectGenerator()); - auto terminationGenerator = std::shared_ptr(new TerminationGenerator()); - auto gdyFactory = std::shared_ptr(new GDYFactory(objectGenerator, terminationGenerator, resourceConfig_)); + auto objectGenerator = std::make_shared(ObjectGenerator()); + auto terminationGenerator = std::make_shared(TerminationGenerator()); + auto gdyFactory = std::make_shared(GDYFactory(objectGenerator, terminationGenerator, resourceConfig_)); std::istringstream s(string); gdyFactory->parseFromStream(s); - return std::shared_ptr(new Py_GDYWrapper(gdyFactory)); + return std::make_shared(Py_GDYWrapper(gdyFactory)); } private: diff --git a/bindings/wrapper/StepPlayerWrapper.cpp b/bindings/wrapper/StepPlayerWrapper.cpp index fc30061cc..617b9fab6 100644 --- a/bindings/wrapper/StepPlayerWrapper.cpp +++ b/bindings/wrapper/StepPlayerWrapper.cpp @@ -13,7 +13,11 @@ namespace griddly { class Py_StepPlayerWrapper { public: Py_StepPlayerWrapper(int playerId, std::string playerName, std::shared_ptr observer, std::shared_ptr gdyFactory, std::shared_ptr gameProcess) - : player_(std::shared_ptr(new Player(playerId, playerName, observer))), gdyFactory_(gdyFactory), gameProcess_(gameProcess) { + : player_(std::make_shared(Player(playerId, playerName, observer))), gdyFactory_(gdyFactory), gameProcess_(gameProcess) { + } + + ~Py_StepPlayerWrapper() { + spdlog::trace("StepPlayerWrapper Destroyed"); } std::shared_ptr unwrapped() { @@ -37,7 +41,7 @@ class Py_StepPlayerWrapper { auto observationData = observer->update(); - return std::shared_ptr>(new NumpyWrapper(observer->getShape(), observer->getStrides(), observationData)); + return std::make_shared>(NumpyWrapper(observer->getShape(), observer->getStrides(), observationData)); } py::tuple stepMulti(py::buffer stepArray, bool updateTicks) { @@ -185,7 +189,7 @@ class Py_StepPlayerWrapper { auto vectorToDest = mapping.vectorToDest; auto orientationVector = mapping.orientationVector; auto metaData = mapping.metaData; - auto action = std::shared_ptr(new Action(gameProcess_->getGrid(), actionName, playerId, 0, metaData)); + auto action = std::make_shared(Action(gameProcess_->getGrid(), actionName, playerId, 0, metaData)); action->init(playerAvatar, vectorToDest, orientationVector, actionInputsDefinition.relative); return action; @@ -204,7 +208,7 @@ class Py_StepPlayerWrapper { auto metaData = mapping.metaData; glm::ivec2 destinationLocation = sourceLocation + vector; - auto action = std::shared_ptr(new Action(gameProcess_->getGrid(), actionName, playerId, 0, metaData)); + auto action = std::make_shared(Action(gameProcess_->getGrid(), actionName, playerId, 0, metaData)); action->init(sourceLocation, destinationLocation); return action; diff --git a/docs/conf.py b/docs/conf.py index 9ac97daa5..26818efec 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -22,7 +22,7 @@ author = 'Chris Bamford' # The full version, including alpha/beta/rc tags -release = '1.2.17' +release = '1.2.18' # -- General configuration --------------------------------------------------- diff --git a/python/setup.py b/python/setup.py index fe46e0d52..7b8c9ce6b 100644 --- a/python/setup.py +++ b/python/setup.py @@ -71,7 +71,7 @@ def griddly_package_data(config='Debug'): setup( name='griddly', - version="1.2.17", + version="1.2.18", author_email="chrisbam4d@gmail.com", description="Griddly Python Libraries", long_description=long_description, diff --git a/src/Griddly/Core/CollisionDetectorFactory.cpp b/src/Griddly/Core/CollisionDetectorFactory.cpp index 0b0cc7e47..6660a6654 100644 --- a/src/Griddly/Core/CollisionDetectorFactory.cpp +++ b/src/Griddly/Core/CollisionDetectorFactory.cpp @@ -13,6 +13,6 @@ std::shared_ptr CollisionDetectorFactory::newCollisionDetecto cellSize = (uint32_t)std::floor(std::sqrt((double)minDim)); } - return std::shared_ptr(new SpatialHashCollisionDetector(gridWidth, gridHeight, cellSize, actionTriggerDefinition.range, actionTriggerDefinition.triggerType)); + return std::make_shared(SpatialHashCollisionDetector(gridWidth, gridHeight, cellSize, actionTriggerDefinition.range, actionTriggerDefinition.triggerType)); } } // namespace griddly \ No newline at end of file diff --git a/src/Griddly/Core/DelayedActionQueueItem.cpp b/src/Griddly/Core/DelayedActionQueueItem.cpp new file mode 100644 index 000000000..1efddcad4 --- /dev/null +++ b/src/Griddly/Core/DelayedActionQueueItem.cpp @@ -0,0 +1,9 @@ +#include "DelayedActionQueueItem.hpp" + +namespace griddly { + +DelayedActionQueueItem::DelayedActionQueueItem(uint32_t _playerId, uint32_t _priority, std::shared_ptr _action) + : playerId(_playerId), priority(_priority), action(_action) { +} + +} // namespace griddly \ No newline at end of file diff --git a/src/Griddly/Core/DelayedActionQueueItem.hpp b/src/Griddly/Core/DelayedActionQueueItem.hpp index a5ed07447..0a0f97611 100644 --- a/src/Griddly/Core/DelayedActionQueueItem.hpp +++ b/src/Griddly/Core/DelayedActionQueueItem.hpp @@ -1,30 +1,27 @@ #pragma once #include - -#include "GDY/Actions/Action.hpp" +#include +#include "Util/util.hpp" namespace griddly { +class Action; + class DelayedActionQueueItem { public: - DelayedActionQueueItem(uint32_t _playerId, uint32_t _priority, std::shared_ptr _action) - : playerId(_playerId), priority(_priority), action(_action) { - } - bool operator==(const DelayedActionQueueItem& other) const { - return priority == other.priority; - } - - bool operator>(const DelayedActionQueueItem& other) const { - return priority < other.priority; - } - - bool operator<(const DelayedActionQueueItem& other) const { - return priority > other.priority; - } + DelayedActionQueueItem(uint32_t _playerId, uint32_t _priority, std::shared_ptr _action); uint32_t playerId; uint32_t priority; std::shared_ptr action; }; +struct SortDelayedActionQueue { + bool operator()(std::shared_ptr a, std::shared_ptr b) { + return a->priority > b->priority; + }; +}; + +typedef VectorPriorityQueue, std::vector>, SortDelayedActionQueue> DelayedActionQueue; + } // namespace griddly \ No newline at end of file diff --git a/src/Griddly/Core/GDY/Actions/Action.cpp b/src/Griddly/Core/GDY/Actions/Action.cpp index 10c5a707d..8bc073ae8 100644 --- a/src/Griddly/Core/GDY/Actions/Action.cpp +++ b/src/Griddly/Core/GDY/Actions/Action.cpp @@ -37,7 +37,7 @@ void Action::init(std::shared_ptr sourceObject, std::shared_ptr sourceObject_ = sourceObject; destinationObject_ = destinationObject; - vectorToDest_ = destinationObject_->getLocation() - sourceObject_->getLocation(); + vectorToDest_ = destObj()->getLocation() - sourceObj()->getLocation(); actionMode_ = ActionMode::SRC_OBJ_DST_OBJ; } @@ -46,7 +46,7 @@ void Action::init(std::shared_ptr sourceObject, glm::ivec2 vectorToDest, sourceObject_ = sourceObject; spdlog::debug("Getting rotation matrix from source"); - auto rotationMatrix = sourceObject_->getObjectOrientation().getRotationMatrix(); + auto rotationMatrix = sourceObj()->getObjectOrientation().getRotationMatrix(); vectorToDest_ = relativeToSource ? vectorToDest * rotationMatrix : vectorToDest; orientationVector_ = relativeToSource ? orientationVector * rotationMatrix : orientationVector; @@ -56,17 +56,17 @@ void Action::init(std::shared_ptr sourceObject, glm::ivec2 vectorToDest, } std::shared_ptr Action::getSourceObject() const { - if (sourceObject_ != nullptr) { - return sourceObject_; + if (sourceObj() != nullptr) { + return sourceObj(); } else { - auto srcObject = grid_->getObject(sourceLocation_); + auto srcObject = grid()->getObject(sourceLocation_); if (srcObject != nullptr) { return srcObject; } spdlog::debug("getting default object"); - return grid_->getPlayerDefaultObject(playerId_); + return grid()->getPlayerDefaultObject(playerId_); } } @@ -74,21 +74,21 @@ std::shared_ptr Action::getDestinationObject() const { switch (actionMode_) { case ActionMode::SRC_LOC_DST_LOC: case ActionMode::SRC_OBJ_DST_LOC: { - auto dstObject = grid_->getObject(destinationLocation_); + auto dstObject = grid()->getObject(destinationLocation_); if (dstObject != nullptr) { return dstObject; } - return grid_->getPlayerDefaultObject(playerId_); + return grid()->getPlayerDefaultObject(playerId_); } case ActionMode::SRC_OBJ_DST_OBJ: - return destinationObject_; + return destinationObject_.lock(); case ActionMode::SRC_OBJ_DST_VEC: { auto destinationLocation = (getSourceLocation() + vectorToDest_); - auto dstObject = grid_->getObject(destinationLocation); + auto dstObject = grid()->getObject(destinationLocation); if (dstObject != nullptr) { return dstObject; } - return grid_->getPlayerDefaultObject(playerId_); + return grid()->getPlayerDefaultObject(playerId_); } } @@ -102,7 +102,7 @@ glm::ivec2 Action::getSourceLocation() const { case ActionMode::SRC_OBJ_DST_LOC: case ActionMode::SRC_OBJ_DST_OBJ: case ActionMode::SRC_OBJ_DST_VEC: - return sourceObject_->getLocation(); + return sourceObj()->getLocation(); } return {}; @@ -114,9 +114,9 @@ glm::ivec2 Action::getDestinationLocation() const { case ActionMode::SRC_OBJ_DST_LOC: return destinationLocation_; case ActionMode::SRC_OBJ_DST_OBJ: - return destinationObject_->getLocation(); + return destObj()->getLocation(); case ActionMode::SRC_OBJ_DST_VEC: - return sourceObject_->getLocation() + vectorToDest_; + return sourceObj()->getLocation() + vectorToDest_; } return {}; @@ -148,4 +148,16 @@ std::unordered_map Action::getMetaData() const { return metaData_; } +std::shared_ptr Action::sourceObj() const { + return sourceObject_.expired() ? nullptr : sourceObject_.lock(); +} + +std::shared_ptr Action::destObj() const { + return destinationObject_.expired() ? nullptr : destinationObject_.lock(); +} + +std::shared_ptr Action::grid() const { + return grid_.lock(); +} + } // namespace griddly \ No newline at end of file diff --git a/src/Griddly/Core/GDY/Actions/Action.hpp b/src/Griddly/Core/GDY/Actions/Action.hpp index 41cbde96f..cf9de7e3d 100644 --- a/src/Griddly/Core/GDY/Actions/Action.hpp +++ b/src/Griddly/Core/GDY/Actions/Action.hpp @@ -76,8 +76,8 @@ class Action { virtual ~Action() = default; protected: - std::shared_ptr sourceObject_ = nullptr; - std::shared_ptr destinationObject_ = nullptr; + std::weak_ptr sourceObject_ ; + std::weak_ptr destinationObject_; glm::ivec2 destinationLocation_ = {0, 0}; glm::ivec2 sourceLocation_ = {0, 0}; glm::ivec2 vectorToDest_ = {0, 0}; @@ -86,7 +86,7 @@ class Action { const std::string actionName_; const uint32_t delay_; - const std::shared_ptr grid_; + const std::weak_ptr grid_; const uint32_t playerId_ = 0; // Some variables that we can set in the input mapping @@ -94,5 +94,10 @@ class Action { private: ActionMode actionMode_; + + std::shared_ptr sourceObj() const; + std::shared_ptr destObj() const; + std::shared_ptr grid() const; + }; } // namespace griddly \ No newline at end of file diff --git a/src/Griddly/Core/GDY/GDYFactory.cpp b/src/Griddly/Core/GDY/GDYFactory.cpp index 9e94edec2..c73e8e390 100644 --- a/src/Griddly/Core/GDY/GDYFactory.cpp +++ b/src/Griddly/Core/GDY/GDYFactory.cpp @@ -85,7 +85,7 @@ void GDYFactory::loadEnvironment(YAML::Node environment) { for (std::size_t l = 0; l < levels.size(); l++) { auto levelStringStream = std::stringstream(levels[l].as()); - auto mapGenerator = std::shared_ptr(new MapGenerator(playerCount_, objectGenerator_)); + auto mapGenerator = std::make_shared(MapGenerator(playerCount_, objectGenerator_)); mapGenerator->parseFromStream(levelStringStream); mapLevelGenerators_.push_back(mapGenerator); } @@ -833,7 +833,7 @@ std::shared_ptr GDYFactory::createObserver(std::shared_ptr grid, throw std::invalid_argument("Environment does not suport Isometric rendering."); } - return std::shared_ptr(new IsometricSpriteObserver(grid, resourceConfig_, getIsometricSpriteObserverDefinitions(), shaderVariableConfig_)); + return std::make_shared(IsometricSpriteObserver(grid, resourceConfig_, getIsometricSpriteObserverDefinitions(), shaderVariableConfig_)); break; case ObserverType::SPRITE_2D: spdlog::debug("Creating SPRITE observer"); @@ -841,7 +841,7 @@ std::shared_ptr GDYFactory::createObserver(std::shared_ptr grid, throw std::invalid_argument("Environment does not suport Sprite2D rendering."); } - return std::shared_ptr(new SpriteObserver(grid, resourceConfig_, getSpriteObserverDefinitions(), shaderVariableConfig_)); + return std::make_shared(SpriteObserver(grid, resourceConfig_, getSpriteObserverDefinitions(), shaderVariableConfig_)); break; case ObserverType::BLOCK_2D: spdlog::debug("Creating BLOCK observer"); @@ -849,15 +849,15 @@ std::shared_ptr GDYFactory::createObserver(std::shared_ptr grid, throw std::invalid_argument("Environment does not suport Block2D rendering."); } - return std::shared_ptr(new BlockObserver(grid, resourceConfig_, getBlockObserverDefinitions(), shaderVariableConfig_)); + return std::make_shared(BlockObserver(grid, resourceConfig_, getBlockObserverDefinitions(), shaderVariableConfig_)); break; case ObserverType::VECTOR: spdlog::debug("Creating VECTOR observer"); - return std::shared_ptr(new VectorObserver(grid)); + return std::make_shared(VectorObserver(grid)); break; case ObserverType::ASCII: spdlog::debug("Creating ASCII observer"); - return std::shared_ptr(new ASCIIObserver(grid)); + return std::make_shared(ASCIIObserver(grid)); break; case ObserverType::NONE: return nullptr; @@ -894,7 +894,7 @@ std::shared_ptr GDYFactory::getLevelGenerator(uint32_t level) co std::shared_ptr GDYFactory::getLevelGenerator(std::string levelString) const { auto levelStringStream = std::stringstream(levelString); - auto mapGenerator = std::shared_ptr(new MapGenerator(playerCount_, objectGenerator_)); + auto mapGenerator = std::make_shared(MapGenerator(playerCount_, objectGenerator_)); mapGenerator->parseFromStream(levelStringStream); return mapGenerator; diff --git a/src/Griddly/Core/GDY/Objects/Object.cpp b/src/Griddly/Core/GDY/Objects/Object.cpp index f7577acf5..1c3d6935a 100644 --- a/src/Griddly/Core/GDY/Objects/Object.cpp +++ b/src/Griddly/Core/GDY/Objects/Object.cpp @@ -11,7 +11,7 @@ namespace griddly { -Object::Object(std::string objectName, char mapCharacter, uint32_t playerId, uint32_t zIdx, std::unordered_map> availableVariables, std::shared_ptr objectGenerator, std::shared_ptr grid) +Object::Object(std::string objectName, char mapCharacter, uint32_t playerId, uint32_t zIdx, std::unordered_map> availableVariables, std::shared_ptr objectGenerator, std::weak_ptr grid) : objectName_(objectName), mapCharacter_(mapCharacter), zIdx_(zIdx), objectGenerator_(objectGenerator), grid_(grid) { availableVariables.insert({"_x", x_}); availableVariables.insert({"_y", y_}); @@ -23,6 +23,10 @@ Object::Object(std::string objectName, char mapCharacter, uint32_t playerId, uin availableVariables_ = availableVariables; } +Object::~Object() { + spdlog::trace("Object Destroyed"); +} + void Object::init(glm::ivec2 location) { init(location, DiscreteOrientation(Direction::NONE)); } @@ -110,7 +114,7 @@ BehaviourResult Object::onActionDst(std::shared_ptr action) { std::unordered_map> Object::resolveVariables(BehaviourCommandArguments commandArguments) { std::unordered_map> resolvedVariables; for (auto commandArgument : commandArguments) { - resolvedVariables[commandArgument.first] = std::shared_ptr(new ObjectVariable(commandArgument.second, availableVariables_)); + resolvedVariables[commandArgument.first] = std::make_shared(ObjectVariable(commandArgument.second, availableVariables_)); } return resolvedVariables; @@ -231,9 +235,9 @@ BehaviourFunction Object::instantiateBehaviour(std::string commandName, Behaviou spdlog::debug("Changing object={0} to {1}", getObjectName(), objectName); auto playerId = getPlayerId(); auto location = getLocation(); - auto newObject = objectGenerator_->newInstance(objectName, playerId, grid_); + auto newObject = objectGenerator_->newInstance(objectName, playerId, grid()); removeObject(); - grid_->addObject(location, newObject, true, action); + grid()->addObject(location, newObject, true, action); return {}; }; } @@ -244,7 +248,7 @@ BehaviourFunction Object::instantiateBehaviour(std::string commandName, Behaviou auto b = variablePointers["1"]; return [this, a, b](std::shared_ptr action) -> BehaviourResult { *a->resolve_ptr(action) += b->resolve(action); - grid_->invalidateLocation(getLocation()); + grid()->invalidateLocation(getLocation()); return {}; }; } @@ -255,7 +259,7 @@ BehaviourFunction Object::instantiateBehaviour(std::string commandName, Behaviou auto b = variablePointers["1"]; return [this, a, b](std::shared_ptr action) -> BehaviourResult { *a->resolve_ptr(action) -= b->resolve(action); - grid_->invalidateLocation(getLocation()); + grid()->invalidateLocation(getLocation()); return {}; }; } @@ -267,7 +271,7 @@ BehaviourFunction Object::instantiateBehaviour(std::string commandName, Behaviou return [this, a, b](std::shared_ptr action) -> BehaviourResult { spdlog::debug("set"); *a->resolve_ptr(action) = b->resolve(action); - grid_->invalidateLocation(getLocation()); + grid()->invalidateLocation(getLocation()); return {}; }; } @@ -278,7 +282,7 @@ BehaviourFunction Object::instantiateBehaviour(std::string commandName, Behaviou return [this, a](std::shared_ptr action) -> BehaviourResult { spdlog::debug("incr"); (*a->resolve_ptr(action)) += 1; - grid_->invalidateLocation(getLocation()); + grid()->invalidateLocation(getLocation()); return {}; }; } @@ -289,7 +293,7 @@ BehaviourFunction Object::instantiateBehaviour(std::string commandName, Behaviou return [this, a](std::shared_ptr action) -> BehaviourResult { spdlog::debug("decr"); (*a->resolve_ptr(action)) -= 1; - grid_->invalidateLocation(getLocation()); + grid()->invalidateLocation(getLocation()); return {}; }; } @@ -300,7 +304,7 @@ BehaviourFunction Object::instantiateBehaviour(std::string commandName, Behaviou orientation_ = DiscreteOrientation(action->getOrientationVector()); // redraw the current location - grid_->invalidateLocation(getLocation()); + grid()->invalidateLocation(getLocation()); return {}; }; } @@ -343,7 +347,7 @@ BehaviourFunction Object::instantiateBehaviour(std::string commandName, Behaviou auto a = commandArguments["0"].as(); return [this, a](std::shared_ptr action) -> BehaviourResult { if (a == "_dest") { - std::shared_ptr cascadedAction = std::shared_ptr(new Action(grid_, action->getActionName(), action->getOriginatingPlayerId(), action->getDelay(), action->getMetaData())); + std::shared_ptr cascadedAction = std::make_shared(Action(grid(), action->getActionName(), action->getOriginatingPlayerId(), action->getDelay(), action->getMetaData())); cascadedAction->init(action->getDestinationObject(), action->getVectorToDest(), action->getOrientationVector(), false); @@ -353,7 +357,7 @@ BehaviourFunction Object::instantiateBehaviour(std::string commandName, Behaviou spdlog::debug("Cascade vector [{0},{1}]", vectorToDest.x, vectorToDest.y); spdlog::debug("Cascading action to [{0},{1}], dst: [{2}, {3}]", sourceLocation.x, sourceLocation.y, destinationLocation.x, destinationLocation.y); - auto actionRewards = grid_->performActions(0, {cascadedAction}); + auto actionRewards = grid()->performActions(0, {cascadedAction}); return {false, actionRewards}; } @@ -421,10 +425,10 @@ BehaviourFunction Object::instantiateBehaviour(std::string commandName, Behaviou break; } - std::shared_ptr newAction = std::shared_ptr(new Action(grid_, actionName, execAsPlayerId, delay, inputMapping.metaData)); + std::shared_ptr newAction = std::make_shared(Action(grid(), actionName, execAsPlayerId, delay, inputMapping.metaData)); newAction->init(shared_from_this(), inputMapping.vectorToDest, inputMapping.orientationVector, inputMapping.relative); - auto rewards = grid_->performActions(0, {newAction}); + auto rewards = grid()->performActions(0, {newAction}); return {false, rewards}; }; @@ -446,7 +450,7 @@ BehaviourFunction Object::instantiateBehaviour(std::string commandName, Behaviou return [this, tileId](std::shared_ptr action) -> BehaviourResult { spdlog::debug("set_tile"); setRenderTileId(tileId->resolve(action)); - grid_->invalidateLocation({*x_, *y_}); + grid()->invalidateLocation({*x_, *y_}); return {}; }; } @@ -458,8 +462,8 @@ BehaviourFunction Object::instantiateBehaviour(std::string commandName, Behaviou spdlog::debug("Spawning object={0} in location [{1},{2}]", objectName, destinationLocation.x, destinationLocation.y); auto playerId = getPlayerId(); - auto newObject = objectGenerator_->newInstance(objectName, playerId, grid_); - grid_->addObject(destinationLocation, newObject, true, action); + auto newObject = objectGenerator_->newInstance(objectName, playerId, grid()); + grid()->addObject(destinationLocation, newObject, true, action); return {}; }; } @@ -506,8 +510,8 @@ bool Object::isValidAction(std::shared_ptr action) const { std::string destinationObjectName = destinationObject->getObjectName(); if (destinationObjectName == "_empty") { - auto width = grid_->getWidth(); - auto height = grid_->getHeight(); + auto width = grid()->getWidth(); + auto height = grid()->getHeight(); // Check that the destination of the action is not outside the grid auto destinationLocation = action->getDestinationLocation(); @@ -594,8 +598,8 @@ SingleInputMapping Object::getInputMapping(std::string actionName, uint32_t acti // TODO: Can this be cleaned up a bit maybe static variables or someting? std::random_device rd; std::mt19937 random_generator_(rd()); - std::uniform_int_distribution grid_location_width_distribution(0, grid_->getWidth() - 1); - std::uniform_int_distribution grid_location_height_distribution(0, grid_->getHeight() - 1); + std::uniform_int_distribution grid_location_width_distribution(0, grid()->getWidth() - 1); + std::uniform_int_distribution grid_location_height_distribution(0, grid()->getHeight() - 1); auto rand_x = grid_location_width_distribution(random_generator_); auto rand_y = grid_location_height_distribution(random_generator_); @@ -646,7 +650,7 @@ std::vector> Object::getInitialActions(std::shared_ptr(new Action(grid_, actionDefinition.actionName, 0, actionDefinition.delay, inputMapping.metaData)); + auto action = std::make_shared(Action(grid(), actionDefinition.actionName, 0, actionDefinition.delay, inputMapping.metaData)); if (inputMapping.mappedToGrid) { inputMapping.vectorToDest = inputMapping.destinationLocation - getLocation(); } @@ -681,15 +685,15 @@ PathFinderConfig Object::configurePathFinder(YAML::Node searchNode, std::string spdlog::debug("Path finder target object: {0}", targetObjectName); - spdlog::debug("Grid height: {0}", grid_->getHeight()); + spdlog::debug("Grid height: {0}", grid()->getHeight()); // Just make the range really large so we always look in all cells - auto range = std::max(grid_->getWidth(), grid_->getHeight()); + auto range = std::max(grid()->getWidth(), grid()->getHeight()); - config.collisionDetector = std::shared_ptr(new SpatialHashCollisionDetector(grid_->getWidth(), grid_->getHeight(), 10, range, TriggerType::RANGE_BOX_AREA)); + config.collisionDetector = std::make_shared(SpatialHashCollisionDetector(grid()->getWidth(), grid()->getHeight(), 10, range, TriggerType::RANGE_BOX_AREA)); if (config.collisionDetector != nullptr) { - grid_->addCollisionDetector({targetObjectName}, actionName + generateRandomString(5), config.collisionDetector); + grid()->addCollisionDetector({targetObjectName}, actionName + generateRandomString(5), config.collisionDetector); } } @@ -700,7 +704,7 @@ PathFinderConfig Object::configurePathFinder(YAML::Node searchNode, std::string auto actionInputDefinitionIt = actionInputDefinitions.find(actionName); config.maxSearchDepth = searchNode["MaxDepth"].as(100); - config.pathFinder = std::shared_ptr(new AStarPathFinder(grid_, impassableObjectsSet, actionInputDefinitionIt->second)); + config.pathFinder = std::make_shared(AStarPathFinder(grid(), impassableObjectsSet, actionInputDefinitionIt->second)); if (searchNode["TargetLocation"].IsDefined()) { auto targetEndLocation = singleOrListNodeToList(searchNode["TargetLocation"]); @@ -716,7 +720,7 @@ uint32_t Object::getPlayerId() const { } bool Object::moveObject(glm::ivec2 newLocation) { - if (grid_->updateLocation(shared_from_this(), {*x_, *y_}, newLocation)) { + if (grid()->updateLocation(shared_from_this(), {*x_, *y_}, newLocation)) { *x_ = newLocation.x; *y_ = newLocation.y; return true; @@ -734,7 +738,7 @@ uint32_t Object::getRenderTileId() const { } void Object::removeObject() { - grid_->removeObject(shared_from_this()); + grid()->removeObject(shared_from_this()); } uint32_t Object::getZIdx() const { @@ -769,6 +773,10 @@ std::unordered_set Object::getAvailableActionNames() const { return availableActionNames_; } +std::shared_ptr Object::grid() const { + return grid_.lock(); +} + ActionExecutor Object::getActionExecutorFromString(std::string executorString) const { if (executorString == "action") { return ActionExecutor::ACTION_PLAYER_ID; diff --git a/src/Griddly/Core/GDY/Objects/Object.hpp b/src/Griddly/Core/GDY/Objects/Object.hpp index 7c7e252bd..e0255cc70 100644 --- a/src/Griddly/Core/GDY/Objects/Object.hpp +++ b/src/Griddly/Core/GDY/Objects/Object.hpp @@ -122,9 +122,9 @@ class Object : public std::enable_shared_from_this { virtual std::vector> getInitialActions(std::shared_ptr originatingAction); virtual void setInitialActionDefinitions(std::vector actionDefinitions); - Object(std::string objectName, char mapCharacter, uint32_t playerId, uint32_t zIdx, std::unordered_map> availableVariables, std::shared_ptr objectGenerator, std::shared_ptr grid); + Object(std::string objectName, char mapCharacter, uint32_t playerId, uint32_t zIdx, std::unordered_map> availableVariables, std::shared_ptr objectGenerator, std::weak_ptr grid); - virtual ~Object() = default; + virtual ~Object(); private: // Have to be shared pointers because they are used as variables @@ -154,7 +154,8 @@ class Object : public std::enable_shared_from_this { // The variables that are available in the object for behaviour commands to interact with std::unordered_map> availableVariables_; - const std::shared_ptr grid_; + std::shared_ptr grid() const; + const std::weak_ptr grid_; std::unordered_set availableActionNames_; diff --git a/src/Griddly/Core/GDY/Objects/ObjectGenerator.cpp b/src/Griddly/Core/GDY/Objects/ObjectGenerator.cpp index 280b08660..94a6ad26c 100644 --- a/src/Griddly/Core/GDY/Objects/ObjectGenerator.cpp +++ b/src/Griddly/Core/GDY/Objects/ObjectGenerator.cpp @@ -95,7 +95,7 @@ std::shared_ptr ObjectGenerator::cloneInstance(std::shared_ptr t auto objectZIdx = objectDefinition->zIdx; auto mapCharacter = objectDefinition->mapCharacter; - auto initializedObject = std::shared_ptr(new Object(objectName, mapCharacter, playerId, objectZIdx, availableVariables, shared_from_this(), grid)); + auto initializedObject = std::make_shared(Object(objectName, mapCharacter, playerId, objectZIdx, availableVariables, shared_from_this(), grid)); if (objectName == avatarObject_) { initializedObject->markAsPlayerAvatar(); @@ -180,7 +180,7 @@ std::shared_ptr ObjectGenerator::newInstance(std::string objectName, uin auto objectZIdx = objectDefinition->zIdx; auto mapCharacter = objectDefinition->mapCharacter; - auto initializedObject = std::shared_ptr(new Object(objectName, mapCharacter, playerId, objectZIdx, availableVariables, shared_from_this(), grid)); + auto initializedObject = std::make_shared(Object(objectName, mapCharacter, playerId, objectZIdx, availableVariables, shared_from_this(), grid)); if (isAvatar) { initializedObject->markAsPlayerAvatar(); diff --git a/src/Griddly/Core/GDY/TerminationGenerator.cpp b/src/Griddly/Core/GDY/TerminationGenerator.cpp index 08213c607..ed444b1b4 100644 --- a/src/Griddly/Core/GDY/TerminationGenerator.cpp +++ b/src/Griddly/Core/GDY/TerminationGenerator.cpp @@ -19,7 +19,7 @@ void TerminationGenerator::defineTerminationCondition(TerminationState state, st } std::shared_ptr TerminationGenerator::newInstance(std::shared_ptr grid, std::vector> players) { - auto terminationHandler = std::shared_ptr(new TerminationHandler(grid, players)); + auto terminationHandler = std::make_shared(TerminationHandler(grid, players)); for (auto terminationConditionDefinition : terminationConditionDefinitions_) { terminationHandler->addTerminationCondition(terminationConditionDefinition); diff --git a/src/Griddly/Core/GDY/TerminationHandler.hpp b/src/Griddly/Core/GDY/TerminationHandler.hpp index 7d08ffc91..3d8e5c43d 100644 --- a/src/Griddly/Core/GDY/TerminationHandler.hpp +++ b/src/Griddly/Core/GDY/TerminationHandler.hpp @@ -20,16 +20,16 @@ enum class TerminationState { struct TerminationResult { bool terminated = false; - std::unordered_map rewards; - std::unordered_map playerStates; + std::unordered_map rewards{}; + std::unordered_map playerStates{}; }; struct TerminationConditionDefinition { TerminationState state = TerminationState::NONE; std::string commandName; - int32_t reward; - int32_t opposingReward; - std::vector commandArguments; + int32_t reward = 0; + int32_t opposingReward = 0; + std::vector commandArguments{}; }; class TerminationHandler { diff --git a/src/Griddly/Core/GameProcess.cpp b/src/Griddly/Core/GameProcess.cpp index 7aefffede..fbec24028 100644 --- a/src/Griddly/Core/GameProcess.cpp +++ b/src/Griddly/Core/GameProcess.cpp @@ -14,7 +14,9 @@ GameProcess::GameProcess( : grid_(grid), globalObserverType_(globalObserverType), gdyFactory_(gdyFactory) { } -GameProcess::~GameProcess() {} +GameProcess::~GameProcess() { + spdlog::debug("GameProcess Destroyed"); +} void GameProcess::addPlayer(std::shared_ptr player) { spdlog::debug("Adding player Name={0}, Id={1}", player->getName(), player->getId()); @@ -189,11 +191,14 @@ ObserverConfig GameProcess::getObserverConfig(ObserverType observerType) const { } void GameProcess::release() { - spdlog::debug("Forcing release of vulkan"); observer_->release(); for (auto& p : players_) { p->getObserver()->release(); } + + players_.clear(); + + grid_->reset(); } bool GameProcess::isInitialized() { @@ -281,7 +286,7 @@ std::vector GameProcess::getAvailableActionIdsAtLocation(glm::ivec2 lo auto metaData = mapping.metaData; // Create an fake action to test for availability (and not duplicate a bunch of code) - auto potentialAction = std::shared_ptr(new Action(grid_, actionName, 0, 0, metaData)); + auto potentialAction = std::make_shared(Action(grid_, actionName, 0, 0, metaData)); potentialAction->init(srcObject, mapping.vectorToDest, mapping.orientationVector, relativeToSource); if (srcObject->isValidAction(potentialAction)) { diff --git a/src/Griddly/Core/Grid.cpp b/src/Griddly/Core/Grid.cpp index 1ef36e24b..c949ded51 100644 --- a/src/Griddly/Core/Grid.cpp +++ b/src/Griddly/Core/Grid.cpp @@ -13,16 +13,16 @@ namespace griddly { -Grid::Grid() { +Grid::Grid() : gameTicks_(std::make_shared(0)) { #ifndef NDEBUG spdlog::set_level(spdlog::level::debug); #else spdlog::set_level(spdlog::level::info); #endif - collisionDetectorFactory_ = std::shared_ptr(new CollisionDetectorFactory()); + collisionDetectorFactory_ = std::make_shared(CollisionDetectorFactory()); } -Grid::Grid(std::shared_ptr collisionDetectorFactory) { +Grid::Grid(std::shared_ptr collisionDetectorFactory) : gameTicks_(std::make_shared(0)){ #ifndef NDEBUG spdlog::set_level(spdlog::level::debug); #else @@ -32,6 +32,11 @@ Grid::Grid(std::shared_ptr collisionDetectorFactory) { collisionDetectorFactory_ = collisionDetectorFactory; } +Grid::~Grid() { + spdlog::debug("Grid Destroyed"); + reset(); +} + void Grid::setPlayerCount(uint32_t playerCount) { playerCount_ = playerCount; } @@ -45,26 +50,30 @@ void Grid::resetMap(uint32_t width, uint32_t height) { height_ = height; width_ = width; + reset(); + + + globalVariables_["_steps"].insert({0, gameTicks_}); + + if (updatedLocations_.size() == 0) { + for (auto p = 0; p < playerCount_ + 1; p++) { + updatedLocations_.push_back(std::unordered_set{}); + } + } +} + +void Grid::reset() { occupiedLocations_.clear(); objects_.clear(); objectCounters_.clear(); objectIds_.clear(); objectVariableIds_.clear(); delayedActions_ = {}; - defaultObject_ = {}; + defaultObject_.clear(); collisionObjectActionNames_.clear(); collisionSourceObjectActionNames_.clear(); collisionDetectors_.clear(); - - gameTicks_ = std::make_shared(0); - globalVariables_["_steps"].insert({0, gameTicks_}); - - if (updatedLocations_.size() == 0) { - for (auto p = 0; p < playerCount_ + 1; p++) { - updatedLocations_.push_back(std::unordered_set{}); - } - } } void Grid::setGlobalVariables(std::unordered_map> globalVariableDefinitions) { @@ -73,10 +82,10 @@ void Grid::setGlobalVariables(std::unordered_map(variableValue); - globalVariables_[ "_steps"].insert({0, gameTicks_}); + *gameTicks_ = variableValue; + globalVariables_["_steps"].insert({0, gameTicks_}); } else { for (auto playerVariable : playerVariables) { auto playerId = playerVariable.first; @@ -316,7 +325,7 @@ std::unordered_map Grid::performActions(uint32_t playerId, st void Grid::delayAction(uint32_t playerId, std::shared_ptr action) { auto executionTarget = *(gameTicks_) + action->getDelay(); spdlog::debug("Delaying action={0} to execution target time {1}", action->getDescription(), executionTarget); - delayedActions_.push(DelayedActionQueueItem{playerId, executionTarget, action}); + delayedActions_.push(std::make_shared(DelayedActionQueueItem{playerId, executionTarget, action})); } std::unordered_map Grid::processDelayedActions() { @@ -325,16 +334,16 @@ std::unordered_map Grid::processDelayedActions() { spdlog::debug("{0} Delayed actions at game tick {1}", delayedActions_.size(), *gameTicks_); // Perform any delayed actions - std::vector actionsToExecute; - while (delayedActions_.size() > 0 && delayedActions_.top().priority <= *(gameTicks_)) { + std::vector> actionsToExecute; + while (delayedActions_.size() > 0 && delayedActions_.top()->priority <= *(gameTicks_)) { // Get the top element and remove it actionsToExecute.push_back(delayedActions_.top()); delayedActions_.pop(); } for (auto delayedAction : actionsToExecute) { - auto action = delayedAction.action; - auto playerId = delayedAction.playerId; + auto action = delayedAction->action; + auto playerId = delayedAction->playerId; spdlog::debug("Popped delayed action {0} at game tick {1}", action->getDescription(), *gameTicks_); @@ -374,7 +383,7 @@ std::unordered_map Grid::processCollisions() { spdlog::debug("Collision detected for action {0} {1}->{2}", actionName, collisionObject->getObjectName(), objectName); - std::shared_ptr collisionAction = std::shared_ptr(new Action(shared_from_this(), actionName, playerId, 0)); + std::shared_ptr collisionAction = std::make_shared(Action(shared_from_this(), actionName, playerId, 0)); collisionAction->init(object, collisionObject); auto rewards = executeAndRecord(0, collisionAction); @@ -403,7 +412,7 @@ std::unordered_map Grid::update() { return rewards; } -VectorPriorityQueue Grid::getDelayedActions() { +DelayedActionQueue Grid::getDelayedActions() { return delayedActions_; } @@ -687,5 +696,4 @@ const std::unordered_map>& Grid::ge return collisionObjectActionNames_; } -Grid::~Grid() {} } // namespace griddly \ No newline at end of file diff --git a/src/Griddly/Core/Grid.hpp b/src/Griddly/Core/Grid.hpp index eaaefb8aa..82a9fe70a 100644 --- a/src/Griddly/Core/Grid.hpp +++ b/src/Griddly/Core/Grid.hpp @@ -9,6 +9,7 @@ #include #include "CollisionDetectorFactory.hpp" +#include "DelayedActionQueueItem.hpp" #include "GDY/Actions/Action.hpp" #include "GDY/Objects/Object.hpp" #include "LevelGenerators/LevelGenerator.hpp" @@ -58,8 +59,6 @@ struct GlobalVariableDefinition { bool perPlayer = false; }; -class DelayedActionQueueItem; - class Grid : public std::enable_shared_from_this { public: Grid(); @@ -83,7 +82,7 @@ class Grid : public std::enable_shared_from_this { virtual void addActionTrigger(std::string actionName, ActionTriggerDefinition actionTriggerDefinition); virtual void addActionProbability(std::string actionName, float probability); - virtual VectorPriorityQueue getDelayedActions(); + virtual DelayedActionQueue getDelayedActions(); virtual bool updateLocation(std::shared_ptr object, glm::ivec2 previousLocation, glm::ivec2 newLocation); @@ -101,7 +100,7 @@ class Grid : public std::enable_shared_from_this { virtual void initObject(std::string objectName, std::vector objectVariableNames); - virtual void addObject(glm::ivec2 location, std::shared_ptr object, bool applyInitialActions = true, std::shared_ptr originatingAction = nullptr, DiscreteOrientation orientation=DiscreteOrientation()); + virtual void addObject(glm::ivec2 location, std::shared_ptr object, bool applyInitialActions = true, std::shared_ptr originatingAction = nullptr, DiscreteOrientation orientation = DiscreteOrientation()); virtual bool removeObject(std::shared_ptr object); @@ -138,7 +137,7 @@ class Grid : public std::enable_shared_from_this { /** * Get a mapping of objects to their defined variables */ - virtual const std::unordered_map> getObjectVariableMap() const; + virtual const std::unordered_map> getObjectVariableMap() const; /** * Gets an ordered list of objectNames @@ -166,6 +165,8 @@ class Grid : public std::enable_shared_from_this { virtual void addCollisionDetector(std::vector objectNames, std::string actionName, std::shared_ptr collisionDetector); + virtual void reset(); + private: GridEvent buildGridEvent(std::shared_ptr action, uint32_t playerId, uint32_t tick); void recordGridEvent(GridEvent event, std::unordered_map rewards); @@ -177,7 +178,7 @@ class Grid : public std::enable_shared_from_this { uint32_t height_; uint32_t width_; - std::shared_ptr gameTicks_; + const std::shared_ptr gameTicks_; // For every game tick record a list of locations that should be updated. // This is so we can highly optimize observers to only re-render changed grid locations @@ -197,7 +198,7 @@ class Grid : public std::enable_shared_from_this { const std::unordered_set EMPTY_LOCATIONS = {}; // A priority queue of actions that are delayed in time (time is measured in game ticks) - VectorPriorityQueue delayedActions_; + DelayedActionQueue delayedActions_; std::unordered_map actionProbabilities_; // There is at least 1 player diff --git a/src/Griddly/Core/Observers/Observer.cpp b/src/Griddly/Core/Observers/Observer.cpp index d3690de70..86d3202a2 100644 --- a/src/Griddly/Core/Observers/Observer.cpp +++ b/src/Griddly/Core/Observers/Observer.cpp @@ -88,6 +88,7 @@ PartialObservableGrid Observer::getAvatarObservableGrid(glm::ivec2 avatarLocatio } Observer::~Observer() { + spdlog::debug("Observer Destroyed"); } } // namespace griddly \ No newline at end of file diff --git a/src/Griddly/Core/Observers/Vulkan/VulkanObserver.cpp b/src/Griddly/Core/Observers/Vulkan/VulkanObserver.cpp index a98e6251a..6d4cbc6f8 100644 --- a/src/Griddly/Core/Observers/Vulkan/VulkanObserver.cpp +++ b/src/Griddly/Core/Observers/Vulkan/VulkanObserver.cpp @@ -18,6 +18,7 @@ VulkanObserver::VulkanObserver(std::shared_ptr grid, ResourceConfig resour } VulkanObserver::~VulkanObserver() { + spdlog::debug("VulkanObserver Destroyed"); } void VulkanObserver::init(ObserverConfig observerConfig) { @@ -57,9 +58,7 @@ void VulkanObserver::lazyInit() { instance_ = std::shared_ptr(new vk::VulkanInstance(configuration)); } - std::unique_ptr vulkanDevice(new vk::VulkanDevice(instance_, observerConfig_.tileSize, shaderPath)); - - device_ = std::move(vulkanDevice); + device_ = std::make_shared(vk::VulkanDevice(instance_, observerConfig_.tileSize, shaderPath)); device_->initDevice(false); // This is probably far too big for most circumstances, but not sure how to work this one out in a smarter way, diff --git a/src/Griddly/Core/Observers/Vulkan/VulkanObserver.hpp b/src/Griddly/Core/Observers/Vulkan/VulkanObserver.hpp index f28924a89..5f28f54c1 100644 --- a/src/Griddly/Core/Observers/Vulkan/VulkanObserver.hpp +++ b/src/Griddly/Core/Observers/Vulkan/VulkanObserver.hpp @@ -52,7 +52,7 @@ class VulkanObserver : public Observer { void resetRenderSurface(); - std::unique_ptr device_; + std::shared_ptr device_; const ResourceConfig resourceConfig_; const ShaderVariableConfig shaderVariableConfig_; diff --git a/src/Griddly/Core/Players/Player.cpp b/src/Griddly/Core/Players/Player.cpp index a34654879..6a3db34a5 100644 --- a/src/Griddly/Core/Players/Player.cpp +++ b/src/Griddly/Core/Players/Player.cpp @@ -1,8 +1,7 @@ -#include "Player.hpp" - #include #include "../GameProcess.hpp" +#include "Player.hpp" namespace griddly { @@ -11,7 +10,9 @@ Player::Player(uint32_t id, std::string name, std::shared_ptr observer score_ = std::make_shared(0); } -Player::~Player() {} +Player::~Player() { + spdlog::debug("Player Destroyed"); +} std::string Player::getName() const { return name_; @@ -57,7 +58,7 @@ std::shared_ptr Player::getAvatar() { } std::shared_ptr Player::getGameProcess() const { - return gameProcess_; + return gameProcess_.lock(); } std::shared_ptr Player::getObserver() const { @@ -65,7 +66,7 @@ std::shared_ptr Player::getObserver() const { } ActionResult Player::performActions(std::vector> actions, bool updateTicks) { - return gameProcess_->performActions(id_, actions, updateTicks); + return gameProcess_.lock()->performActions(id_, actions, updateTicks); } uint8_t* Player::observe() { diff --git a/src/Griddly/Core/Players/Player.hpp b/src/Griddly/Core/Players/Player.hpp index 18c426621..4d8be78e2 100644 --- a/src/Griddly/Core/Players/Player.hpp +++ b/src/Griddly/Core/Players/Player.hpp @@ -20,7 +20,7 @@ struct PlayerObserverDefinition { int32_t gridYOffset = 0; bool trackAvatar = false; bool rotateWithAvatar = false; - uint32_t playerCount; + uint32_t playerCount = 0; bool highlightPlayers = true; }; @@ -56,7 +56,9 @@ class Player { std::shared_ptr avatarObject_; const std::shared_ptr observer_; - std::shared_ptr gameProcess_; + + // Using a weak ptr here because game process points to the player objects and vice versa + std::weak_ptr gameProcess_; std::shared_ptr score_; }; } // namespace griddly \ No newline at end of file diff --git a/src/Griddly/Core/TurnBasedGameProcess.cpp b/src/Griddly/Core/TurnBasedGameProcess.cpp index 75e3cdc0c..df63cf891 100644 --- a/src/Griddly/Core/TurnBasedGameProcess.cpp +++ b/src/Griddly/Core/TurnBasedGameProcess.cpp @@ -17,6 +17,7 @@ TurnBasedGameProcess::TurnBasedGameProcess( } TurnBasedGameProcess::~TurnBasedGameProcess() { + spdlog::debug("TurnBasedGameProcess Destroyed"); } ActionResult TurnBasedGameProcess::performActions(uint32_t playerId, std::vector> actions, bool updateTicks) { @@ -74,7 +75,7 @@ std::string TurnBasedGameProcess::getProcessName() const { std::shared_ptr TurnBasedGameProcess::clone() { // Firstly create a new grid - std::shared_ptr clonedGrid = std::shared_ptr(new Grid()); + std::shared_ptr clonedGrid = std::make_shared(Grid()); clonedGrid->setPlayerCount(static_cast(players_.size())); @@ -150,9 +151,9 @@ std::shared_ptr TurnBasedGameProcess::clone() { spdlog::debug("Cloning delayed actions..."); for (auto delayedActionToCopy : delayedActions) { - auto remainingTicks = delayedActionToCopy.priority - tickCountToCopy; - auto actionToCopy = delayedActionToCopy.action; - auto playerId = delayedActionToCopy.playerId; + auto remainingTicks = delayedActionToCopy->priority - tickCountToCopy; + auto actionToCopy = delayedActionToCopy->action; + auto playerId = delayedActionToCopy->playerId; auto actionName = actionToCopy->getActionName(); auto vectorToDest = actionToCopy->getVectorToDest(); @@ -165,7 +166,7 @@ std::shared_ptr TurnBasedGameProcess::clone() { if (clonedActionSourceObjectIt != clonedObjectMapping.end()) { // Clone the action - auto clonedAction = std::shared_ptr(new Action(clonedGrid, actionName, originatingPlayerId, remainingTicks)); + auto clonedAction = std::make_shared(Action(clonedGrid, actionName, originatingPlayerId, remainingTicks)); // The orientation and vector to dest are already modified from the first action in respect // to if this is a relative action, so relative is set to false here @@ -180,7 +181,7 @@ std::shared_ptr TurnBasedGameProcess::clone() { spdlog::debug("Cloning game process..."); - auto clonedGameProcess = std::shared_ptr(new TurnBasedGameProcess(globalObserverType_, gdyFactory_, clonedGrid)); + auto clonedGameProcess = std::make_shared(TurnBasedGameProcess(globalObserverType_, gdyFactory_, clonedGrid)); clonedGameProcess->setLevelGenerator(levelGenerator_); return clonedGameProcess; diff --git a/src/Griddly/Core/Util/util.hpp b/src/Griddly/Core/Util/util.hpp index 658642765..b567d5350 100644 --- a/src/Griddly/Core/Util/util.hpp +++ b/src/Griddly/Core/Util/util.hpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include template inline void hash_combine(std::size_t& seed, const T& val) { diff --git a/tests/src/Griddly/Core/GDY/Objects/ObjectTest.cpp b/tests/src/Griddly/Core/GDY/Objects/ObjectTest.cpp index 5e52f2437..39c756f17 100644 --- a/tests/src/Griddly/Core/GDY/Objects/ObjectTest.cpp +++ b/tests/src/Griddly/Core/GDY/Objects/ObjectTest.cpp @@ -126,7 +126,7 @@ std::shared_ptr setupAction(std::string actionName, std::shared_ptr< TEST(ObjectTest, getLocation) { auto mockGridPtr = std::shared_ptr(new MockGrid()); - auto object = std::shared_ptr(new Object("object", 'o', 0, 0, {}, nullptr, mockGridPtr)); + auto object = std::make_shared(Object("object", 'o', 0, 0, {}, nullptr, mockGridPtr)); object->init({5, 5}); @@ -137,7 +137,7 @@ TEST(ObjectTest, getLocation) { TEST(ObjectTest, getObjectName) { auto mockGridPtr = std::shared_ptr(new MockGrid()); - auto object = std::shared_ptr(new Object("object", 'o', 0, 0, {}, nullptr, mockGridPtr)); + auto object = std::make_shared(Object("object", 'o', 0, 0, {}, nullptr, mockGridPtr)); ASSERT_EQ(object->getObjectName(), "object"); @@ -146,7 +146,7 @@ TEST(ObjectTest, getObjectName) { TEST(ObjectTest, getDescription) { auto mockGridPtr = std::shared_ptr(new MockGrid()); - auto object = std::shared_ptr(new Object("object", 'o', 0, 0, {}, nullptr, mockGridPtr)); + auto object = std::make_shared(Object("object", 'o', 0, 0, {}, nullptr, mockGridPtr)); object->init({9, 6}); @@ -157,7 +157,7 @@ TEST(ObjectTest, getDescription) { TEST(ObjectTest, getPlayerId) { auto mockGridPtr = std::shared_ptr(new MockGrid()); - auto object = std::shared_ptr(new Object("object", 'o', 2, 0, {}, nullptr, mockGridPtr)); + auto object = std::make_shared(Object("object", 'o', 2, 0, {}, nullptr, mockGridPtr)); object->init({5, 5}); @@ -168,7 +168,7 @@ TEST(ObjectTest, getPlayerId) { TEST(ObjectTest, getVariables) { auto mockGridPtr = std::shared_ptr(new MockGrid()); - auto object = std::shared_ptr(new Object("object", 'o', 2, 0, {{"test_param", _V(20)}}, nullptr, mockGridPtr)); + auto object = std::make_shared(Object("object", 'o', 2, 0, {{"test_param", _V(20)}}, nullptr, mockGridPtr)); ASSERT_EQ(*object->getVariableValue("test_param"), 20); @@ -185,8 +185,8 @@ TEST(ObjectTest, getVariables) { TEST(ObjectTest, actionBoundToSrc) { auto srcObjectName = "srcObject"; auto dstObjectName = "dstObject"; - auto srcObject = std::shared_ptr(new Object(srcObjectName, 'S', 0, 0, {}, nullptr, nullptr)); - auto dstObject = std::shared_ptr(new Object(dstObjectName, 'D', 0, 0, {}, nullptr, nullptr)); + auto srcObject = std::make_shared(Object(srcObjectName, 'S', 0, 0, {}, nullptr, std::weak_ptr())); + auto dstObject = std::make_shared(Object(dstObjectName, 'D', 0, 0, {}, nullptr, std::weak_ptr())); auto mockActionPtr = setupAction("action", srcObject, dstObject); @@ -202,8 +202,8 @@ TEST(ObjectTest, actionBoundToSrc) { TEST(ObjectTest, actionBoundToDst) { auto srcObjectName = "srcObject"; auto dstObjectName = "dstObject"; - auto srcObject = std::shared_ptr(new Object(srcObjectName, 'S', 0, 0, {}, nullptr, nullptr)); - auto dstObject = std::shared_ptr(new Object(dstObjectName, 'D', 0, 0, {}, nullptr, nullptr)); + auto srcObject = std::make_shared(Object(srcObjectName, 'S', 0, 0, {}, nullptr, std::weak_ptr())); + auto dstObject = std::make_shared(Object(dstObjectName, 'D', 0, 0, {}, nullptr, std::weak_ptr())); auto mockActionPtr = setupAction("action", srcObject, dstObject); @@ -221,7 +221,7 @@ TEST(ObjectTest, actionBoundToDst) { TEST(ObjectTest, actionDestinationObjectDifferentFromOriginalObject) { auto srcObjectName = "srcObject"; auto dstObjectName = "dstObject"; - auto srcObject = std::shared_ptr(new Object(srcObjectName, 'S', 0, 0, {}, nullptr, nullptr)); + auto srcObject = std::make_shared(Object(srcObjectName, 'S', 0, 0, {}, nullptr, std::weak_ptr())); auto mockActionPtr = setupAction("action", srcObject, glm::ivec2{1, 1}); @@ -238,8 +238,8 @@ TEST(ObjectTest, actionDestinationObjectDifferentFromOriginalObject) { TEST(ObjectTest, srcActionNoBehaviourForDstObject) { auto srcObjectName = "srcObject"; auto dstObjectName = "dstObject"; - auto srcObject = std::shared_ptr(new Object(srcObjectName, 'S', 0, 0, {}, nullptr, nullptr)); - auto dstObject = std::shared_ptr(new Object(dstObjectName, 'D', 0, 0, {}, nullptr, nullptr)); + auto srcObject = std::make_shared(Object(srcObjectName, 'S', 0, 0, {}, nullptr, std::weak_ptr())); + auto dstObject = std::make_shared(Object(dstObjectName, 'D', 0, 0, {}, nullptr, std::weak_ptr())); auto mockActionPtr = setupAction("action", srcObject, dstObject); @@ -256,8 +256,8 @@ TEST(ObjectTest, srcActionNoBehaviourForDstObject) { TEST(ObjectTest, srcActionNoBehaviourForAction) { auto srcObjectName = "srcObject"; auto dstObjectName = "dstObject"; - auto srcObject = std::shared_ptr(new Object(srcObjectName, 'S', 0, 0, {}, nullptr, nullptr)); - auto dstObject = std::shared_ptr(new Object(dstObjectName, 'D', 0, 0, {}, nullptr, nullptr)); + auto srcObject = std::make_shared(Object(srcObjectName, 'S', 0, 0, {}, nullptr, std::weak_ptr())); + auto dstObject = std::make_shared(Object(dstObjectName, 'D', 0, 0, {}, nullptr, std::weak_ptr())); auto mockActionPtr = setupAction("action", srcObject, dstObject); @@ -271,8 +271,8 @@ TEST(ObjectTest, srcActionNoBehaviourForAction) { TEST(ObjectTest, dstActionNoBehaviourForDstObject) { auto srcObjectName = "srcObject"; auto dstObjectName = "dstObject"; - auto srcObject = std::shared_ptr(new Object(srcObjectName, 'S', 0, 0, {}, nullptr, nullptr)); - auto dstObject = std::shared_ptr(new Object(dstObjectName, 'D', 0, 0, {}, nullptr, nullptr)); + auto srcObject = std::make_shared(Object(srcObjectName, 'S', 0, 0, {}, nullptr, std::weak_ptr())); + auto dstObject = std::make_shared(Object(dstObjectName, 'D', 0, 0, {}, nullptr, std::weak_ptr())); auto mockActionPtr = setupAction("action", srcObject, dstObject); @@ -289,8 +289,8 @@ TEST(ObjectTest, dstActionNoBehaviourForDstObject) { TEST(ObjectTest, dstActionNoBehaviourForAction) { auto srcObjectName = "srcObject"; auto dstObjectName = "dstObject"; - auto srcObject = std::shared_ptr(new Object(srcObjectName, 'S', 0, 0, {}, nullptr, nullptr)); - auto dstObject = std::shared_ptr(new Object(dstObjectName, 'D', 0, 0, {}, nullptr, nullptr)); + auto srcObject = std::make_shared(Object(srcObjectName, 'S', 0, 0, {}, nullptr, std::weak_ptr())); + auto dstObject = std::make_shared(Object(dstObjectName, 'D', 0, 0, {}, nullptr, std::weak_ptr())); auto mockActionPtr = setupAction("action", srcObject, dstObject); @@ -308,7 +308,7 @@ struct CommandTestResult { }; std::shared_ptr setupObject(uint32_t playerId, std::string objectname, glm::ivec2 location, DiscreteOrientation orientation, std::unordered_map> initialVariables, std::shared_ptr mockGridPtr, std::shared_ptr objectGenerator) { - auto object = std::shared_ptr(new Object(objectname, 'o', playerId, 0, initialVariables, objectGenerator, mockGridPtr)); + auto object = std::make_shared(Object(objectname, 'o', playerId, 0, initialVariables, objectGenerator, mockGridPtr)); if (mockGridPtr != nullptr) { object->init(location, orientation); @@ -1453,8 +1453,8 @@ TEST(ObjectTest, isValidAction) { auto srcObjectName = "srcObject"; auto dstObjectName = "dstObject"; auto actionName = "action"; - auto srcObject = std::shared_ptr(new Object(srcObjectName, 'S', 0, 0, {{"counter", _V(5)}}, nullptr, nullptr)); - auto dstObject = std::shared_ptr(new Object(dstObjectName, 'D', 0, 0, {}, nullptr, nullptr)); + auto srcObject = std::make_shared(Object(srcObjectName, 'S', 0, 0, {{"counter", _V(5)}}, nullptr, std::weak_ptr())); + auto dstObject = std::make_shared(Object(dstObjectName, 'D', 0, 0, {}, nullptr, std::weak_ptr())); auto mockActionPtr = setupAction(actionName, srcObject, dstObject); // auto mockActionPtr = std::shared_ptr(new MockAction()); @@ -1476,8 +1476,8 @@ TEST(ObjectTest, isValidActionNotDefinedForAction) { auto srcObjectName = "srcObject"; auto dstObjectName = "dstObject"; auto actionName = "action"; - auto srcObject = std::shared_ptr(new Object(srcObjectName, 'S', 0, 0, {{"counter", _V(5)}}, nullptr, nullptr)); - auto dstObject = std::shared_ptr(new Object(dstObjectName, 'D', 0, 0, {}, nullptr, nullptr)); + auto srcObject = std::make_shared(Object(srcObjectName, 'S', 0, 0, {{"counter", _V(5)}}, nullptr, std::weak_ptr())); + auto dstObject = std::make_shared(Object(dstObjectName, 'D', 0, 0, {}, nullptr, std::weak_ptr())); auto mockActionPtr = setupAction(actionName, srcObject, dstObject); @@ -1496,8 +1496,8 @@ TEST(ObjectTest, isValidActionNotDefinedForDestination) { auto srcObjectName = "srcObject"; auto dstObjectName = "dstObject"; auto actionName = "action"; - auto srcObject = std::shared_ptr(new Object(srcObjectName, 'S', 0, 0, {{"counter", _V(5)}}, nullptr, nullptr)); - auto dstObject = std::shared_ptr(new Object(dstObjectName, 'D', 0, 0, {}, nullptr, nullptr)); + auto srcObject = std::make_shared(Object(srcObjectName, 'S', 0, 0, {{"counter", _V(5)}}, nullptr, std::weak_ptr())); + auto dstObject = std::make_shared(Object(dstObjectName, 'D', 0, 0, {}, nullptr, std::weak_ptr())); auto mockActionPtr = setupAction(actionName, srcObject, dstObject); @@ -1524,10 +1524,10 @@ TEST(ObjectTest, isValidActionDestinationLocationOutsideGrid) { EXPECT_CALL(*mockGridPtr, getWidth).WillRepeatedly(Return(10)); EXPECT_CALL(*mockGridPtr, getHeight).WillRepeatedly(Return(10)); - auto srcObject = std::shared_ptr(new Object(srcObjectName, 'S', 0, 0, {{"counter", _V(5)}}, nullptr, mockGridPtr)); + auto srcObject = std::make_shared(Object(srcObjectName, 'S', 0, 0, {{"counter", _V(5)}}, nullptr, mockGridPtr)); - auto dstObjectOutside = std::shared_ptr(new Object(dstBoundaryObjectName, 'S', 0, 0, {}, nullptr, mockGridPtr)); - auto dstObjectInside = std::shared_ptr(new Object(dstEmptyObjectName, 'D', 0, 0, {}, nullptr, mockGridPtr)); + auto dstObjectOutside = std::make_shared(Object(dstBoundaryObjectName, 'S', 0, 0, {}, nullptr, mockGridPtr)); + auto dstObjectInside = std::make_shared(Object(dstEmptyObjectName, 'D', 0, 0, {}, nullptr, mockGridPtr)); srcObject->init({5, 4}, DiscreteOrientation()); @@ -1579,7 +1579,7 @@ TEST(ObjectTest, getInitialActions) { EXPECT_CALL(*mockObjectGenerator, getActionInputDefinitions()).WillRepeatedly(Return(mockActionInputDefinitions)); - auto object = std::shared_ptr(new Object(objectName, 'S', 0, 0, {}, mockObjectGenerator, nullptr)); + auto object = std::make_shared(Object(objectName, 'S', 0, 0, {}, mockObjectGenerator, std::weak_ptr())); object->setInitialActionDefinitions(initialActionDefinitions); @@ -1643,7 +1643,7 @@ TEST(ObjectTest, getInitialActionsWithOriginatingAction) { EXPECT_CALL(*mockObjectGenerator, getActionInputDefinitions()).WillRepeatedly(Return(mockActionInputDefinitions)); - auto object = std::shared_ptr(new Object(objectName, 'S', 0, 0, {}, mockObjectGenerator, nullptr)); + auto object = std::make_shared(Object(objectName, 'S', 0, 0, {}, mockObjectGenerator, std::weak_ptr())); object->setInitialActionDefinitions(initialActionDefinitions); diff --git a/tests/src/Griddly/Core/GameProcessTest.cpp b/tests/src/Griddly/Core/GameProcessTest.cpp index 0da22d1cd..2c10acf67 100644 --- a/tests/src/Griddly/Core/GameProcessTest.cpp +++ b/tests/src/Griddly/Core/GameProcessTest.cpp @@ -1,6 +1,5 @@ #include -#include "Griddly/Core/TestUtils/common.hpp" #include "Griddly/Core/TurnBasedGameProcess.cpp" #include "Mocks/Griddly/Core/GDY/MockGDYFactory.hpp" #include "Mocks/Griddly/Core/GDY/MockTerminationHandler.hpp" @@ -9,6 +8,7 @@ #include "Mocks/Griddly/Core/MockGrid.hpp" #include "Mocks/Griddly/Core/Observers/MockObserver.hpp" #include "Mocks/Griddly/Core/Players/MockPlayer.hpp" +#include "TestUtils/common.hpp" #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -387,8 +387,6 @@ TEST(GameProcessTest, reset) { EXPECT_CALL(*mockObserverPtr, getObserverType()) .WillRepeatedly(Return(ObserverType::VECTOR)); - auto mockObservationPtr = new uint8_t[3]{0, 1, 2}; - EXPECT_CALL(*mockGDYFactoryPtr, getPlayerObserverDefinition()) .WillOnce(Return(PlayerObserverDefinition{4, 8, 0, 0, false, false})); diff --git a/tests/src/Griddly/Core/GridTest.cpp b/tests/src/Griddly/Core/GridTest.cpp index 62fc6c63e..89aebcc28 100644 --- a/tests/src/Griddly/Core/GridTest.cpp +++ b/tests/src/Griddly/Core/GridTest.cpp @@ -877,7 +877,7 @@ TEST(GridTest, performActionTriggeredByCollision) { EXPECT_CALL(*mockCollisionDetectorFactoryPtr, newCollisionDetector) .WillOnce(Return(mockCollisionDetectorPtr1)); - auto grid = std::shared_ptr(new Grid(mockCollisionDetectorFactoryPtr)); + auto grid = std::make_shared(Grid(mockCollisionDetectorFactoryPtr)); grid->resetMap(123, 456); std::string actionName1 = "collision_trigger_action"; diff --git a/tests/src/Mocks/Griddly/Core/GDY/Actions/MockAction.hpp b/tests/src/Mocks/Griddly/Core/GDY/Actions/MockAction.hpp index 45d40a4d3..c06750b25 100644 --- a/tests/src/Mocks/Griddly/Core/GDY/Actions/MockAction.hpp +++ b/tests/src/Mocks/Griddly/Core/GDY/Actions/MockAction.hpp @@ -8,7 +8,7 @@ namespace griddly { class MockAction : public Action { public: MockAction() - : Action(nullptr, "mockAction", 0, {}) {} + : Action(std::shared_ptr(), "mockAction", 0, {}) {} MOCK_METHOD(void, init, (std::shared_ptr sourceObject, std::shared_ptr destinationObject), ()); diff --git a/tests/src/Mocks/Griddly/Core/GDY/Objects/MockObject.hpp b/tests/src/Mocks/Griddly/Core/GDY/Objects/MockObject.hpp index ebf02f0cd..c9a5168cf 100644 --- a/tests/src/Mocks/Griddly/Core/GDY/Objects/MockObject.hpp +++ b/tests/src/Mocks/Griddly/Core/GDY/Objects/MockObject.hpp @@ -8,7 +8,7 @@ namespace griddly { class MockObject : public Object { public: MockObject() - : Object("mockObject", 'o', 0, 0, {}, nullptr, nullptr) { + : Object("mockObject", 'o', 0, 0, {}, nullptr, std::weak_ptr()) { }