Skip to content

Commit

Permalink
Merge branch 'release/1.2.18'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bam4d committed Dec 7, 2021
2 parents 5dbfded + 82b299f commit f0ec38a
Show file tree
Hide file tree
Showing 35 changed files with 252 additions and 209 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})

Expand Down
2 changes: 1 addition & 1 deletion bindings/python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion bindings/wrapper/GDYWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Py_GDYWrapper {
}

std::shared_ptr<Py_GameWrapper> createGame(ObserverType globalObserverType) {
return std::shared_ptr<Py_GameWrapper>(new Py_GameWrapper(globalObserverType, gdyFactory_));
return std::make_shared<Py_GameWrapper>(Py_GameWrapper(globalObserverType, gdyFactory_));
}

private:
Expand Down
35 changes: 12 additions & 23 deletions bindings/wrapper/GameWrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#pragma once

#include <spdlog/spdlog.h>

#include "../../src/Griddly/Core/TurnBasedGameProcess.hpp"
#include "EntityObserverWrapper.cpp"
#include "NumpyWrapper.cpp"
#include "StepPlayerWrapper.cpp"
#include "EntityObserverWrapper.cpp"

namespace griddly {

Expand All @@ -18,7 +16,7 @@ class ValidActionNode {
}

void add(uint32_t value) {
children[value] = std::shared_ptr<ValidActionNode>(new ValidActionNode());
children[value] = std::make_shared<ValidActionNode>(ValidActionNode());
}

static py::dict toPyDict(std::shared_ptr<ValidActionNode> node) {
Expand All @@ -33,13 +31,9 @@ class ValidActionNode {

class Py_GameWrapper {
public:
Py_GameWrapper(ObserverType globalObserverType, std::shared_ptr<GDYFactory> gdyFactory)
: gdyFactory_(gdyFactory),
gameProcess_(std::shared_ptr<TurnBasedGameProcess>(
new TurnBasedGameProcess(
globalObserverType,
gdyFactory,
std::shared_ptr<Grid>(new Grid())))) {
Py_GameWrapper(ObserverType globalObserverType, std::shared_ptr<GDYFactory> gdyFactory) : gdyFactory_(gdyFactory) {
std::shared_ptr<Grid> grid = std::make_shared<Grid>(Grid());
gameProcess_ = std::make_shared<TurnBasedGameProcess>(TurnBasedGameProcess(globalObserverType, gdyFactory, grid));
spdlog::debug("Created game process wrapper");
}

Expand All @@ -57,7 +51,7 @@ class Py_GameWrapper {
auto observer = gdyFactory_->createObserver(gameProcess_->getGrid(), observerType);

auto nextPlayerId = ++playerCount_;
auto player = std::shared_ptr<Py_StepPlayerWrapper>(new Py_StepPlayerWrapper(nextPlayerId, playerName, observer, gdyFactory_, gameProcess_));
auto player = std::make_shared<Py_StepPlayerWrapper>(Py_StepPlayerWrapper(nextPlayerId, playerName, observer, gdyFactory_, gameProcess_));
players_.push_back(player);
gameProcess_->addPlayer(player->unwrapped());
return player;
Expand All @@ -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<ValidActionNode> node = std::shared_ptr<ValidActionNode>(new ValidActionNode());
std::shared_ptr<ValidActionNode> node = std::make_shared<ValidActionNode>(ValidActionNode());
for (auto actionNamesAtLocation : gameProcess_->getAvailableActionNames(playerId)) {
auto location = actionNamesAtLocation.first;
auto actionNames = actionNamesAtLocation.second;
Expand Down Expand Up @@ -150,7 +144,6 @@ class Py_GameWrapper {
}

py::dict getAvailableActionIds(std::vector<int32_t> location, std::vector<std::string> actionNames) {

spdlog::debug("Getting available action ids for location [{0},{1}]", location[0], location[1]);

py::dict py_availableActionIds;
Expand Down Expand Up @@ -205,7 +198,7 @@ class Py_GameWrapper {

auto observationData = observer->update();

return std::shared_ptr<NumpyWrapper<uint8_t>>(new NumpyWrapper<uint8_t>(observer->getShape(), observer->getStrides(), observationData));
return std::make_shared<NumpyWrapper<uint8_t>>(NumpyWrapper<uint8_t>(observer->getShape(), observer->getStrides(), observationData));
}

py::tuple stepParallel(py::buffer stepArray) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -311,11 +304,7 @@ class Py_GameWrapper {

std::shared_ptr<Py_GameWrapper> clone() {
auto clonedGameProcess = gameProcess_->clone();

auto clonedPyGameProcessWrapper = std::shared_ptr<Py_GameWrapper>(
new Py_GameWrapper(
gdyFactory_,
clonedGameProcess));
auto clonedPyGameProcessWrapper = std::make_shared<Py_GameWrapper>(Py_GameWrapper(gdyFactory_, clonedGameProcess));

return clonedPyGameProcessWrapper;
}
Expand Down Expand Up @@ -442,7 +431,7 @@ class Py_GameWrapper {
}

private:
const std::shared_ptr<TurnBasedGameProcess> gameProcess_;
std::shared_ptr<TurnBasedGameProcess> gameProcess_;
const std::shared_ptr<GDYFactory> gdyFactory_;
uint32_t playerCount_ = 0;
std::vector<std::shared_ptr<Py_StepPlayerWrapper>> players_;
Expand Down
16 changes: 8 additions & 8 deletions bindings/wrapper/GriddlyLoaderWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ class Py_GriddlyLoaderWrapper {
}

std::shared_ptr<Py_GDYWrapper> loadGDYFile(std::string filename) {
auto objectGenerator = std::shared_ptr<ObjectGenerator>(new ObjectGenerator());
auto terminationGenerator = std::shared_ptr<TerminationGenerator>(new TerminationGenerator());
auto gdyFactory = std::shared_ptr<GDYFactory>(new GDYFactory(objectGenerator, terminationGenerator, resourceConfig_));
auto objectGenerator = std::make_shared<ObjectGenerator>(ObjectGenerator());
auto terminationGenerator = std::make_shared<TerminationGenerator>(TerminationGenerator());
auto gdyFactory = std::make_shared<GDYFactory>(GDYFactory(objectGenerator, terminationGenerator, resourceConfig_));
gdyFactory->initializeFromFile(filename);
return std::shared_ptr<Py_GDYWrapper>(new Py_GDYWrapper(gdyFactory));
return std::make_shared<Py_GDYWrapper>(Py_GDYWrapper(gdyFactory));
}

std::shared_ptr<Py_GDYWrapper> loadGDYString(std::string string) {
auto objectGenerator = std::shared_ptr<ObjectGenerator>(new ObjectGenerator());
auto terminationGenerator = std::shared_ptr<TerminationGenerator>(new TerminationGenerator());
auto gdyFactory = std::shared_ptr<GDYFactory>(new GDYFactory(objectGenerator, terminationGenerator, resourceConfig_));
auto objectGenerator = std::make_shared<ObjectGenerator>(ObjectGenerator());
auto terminationGenerator = std::make_shared<TerminationGenerator>(TerminationGenerator());
auto gdyFactory = std::make_shared<GDYFactory>(GDYFactory(objectGenerator, terminationGenerator, resourceConfig_));
std::istringstream s(string);
gdyFactory->parseFromStream(s);
return std::shared_ptr<Py_GDYWrapper>(new Py_GDYWrapper(gdyFactory));
return std::make_shared<Py_GDYWrapper>(Py_GDYWrapper(gdyFactory));
}

private:
Expand Down
12 changes: 8 additions & 4 deletions bindings/wrapper/StepPlayerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ namespace griddly {
class Py_StepPlayerWrapper {
public:
Py_StepPlayerWrapper(int playerId, std::string playerName, std::shared_ptr<Observer> observer, std::shared_ptr<GDYFactory> gdyFactory, std::shared_ptr<GameProcess> gameProcess)
: player_(std::shared_ptr<Player>(new Player(playerId, playerName, observer))), gdyFactory_(gdyFactory), gameProcess_(gameProcess) {
: player_(std::make_shared<Player>(Player(playerId, playerName, observer))), gdyFactory_(gdyFactory), gameProcess_(gameProcess) {
}

~Py_StepPlayerWrapper() {
spdlog::trace("StepPlayerWrapper Destroyed");
}

std::shared_ptr<Player> unwrapped() {
Expand All @@ -37,7 +41,7 @@ class Py_StepPlayerWrapper {

auto observationData = observer->update();

return std::shared_ptr<NumpyWrapper<uint8_t>>(new NumpyWrapper<uint8_t>(observer->getShape(), observer->getStrides(), observationData));
return std::make_shared<NumpyWrapper<uint8_t>>(NumpyWrapper<uint8_t>(observer->getShape(), observer->getStrides(), observationData));
}

py::tuple stepMulti(py::buffer stepArray, bool updateTicks) {
Expand Down Expand Up @@ -185,7 +189,7 @@ class Py_StepPlayerWrapper {
auto vectorToDest = mapping.vectorToDest;
auto orientationVector = mapping.orientationVector;
auto metaData = mapping.metaData;
auto action = std::shared_ptr<Action>(new Action(gameProcess_->getGrid(), actionName, playerId, 0, metaData));
auto action = std::make_shared<Action>(Action(gameProcess_->getGrid(), actionName, playerId, 0, metaData));
action->init(playerAvatar, vectorToDest, orientationVector, actionInputsDefinition.relative);

return action;
Expand All @@ -204,7 +208,7 @@ class Py_StepPlayerWrapper {
auto metaData = mapping.metaData;
glm::ivec2 destinationLocation = sourceLocation + vector;

auto action = std::shared_ptr<Action>(new Action(gameProcess_->getGrid(), actionName, playerId, 0, metaData));
auto action = std::make_shared<Action>(Action(gameProcess_->getGrid(), actionName, playerId, 0, metaData));
action->init(sourceLocation, destinationLocation);

return action;
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def griddly_package_data(config='Debug'):

setup(
name='griddly',
version="1.2.17",
version="1.2.18",
author_email="[email protected]",
description="Griddly Python Libraries",
long_description=long_description,
Expand Down
2 changes: 1 addition & 1 deletion src/Griddly/Core/CollisionDetectorFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ std::shared_ptr<CollisionDetector> CollisionDetectorFactory::newCollisionDetecto
cellSize = (uint32_t)std::floor(std::sqrt((double)minDim));
}

return std::shared_ptr<CollisionDetector>(new SpatialHashCollisionDetector(gridWidth, gridHeight, cellSize, actionTriggerDefinition.range, actionTriggerDefinition.triggerType));
return std::make_shared<SpatialHashCollisionDetector>(SpatialHashCollisionDetector(gridWidth, gridHeight, cellSize, actionTriggerDefinition.range, actionTriggerDefinition.triggerType));
}
} // namespace griddly
9 changes: 9 additions & 0 deletions src/Griddly/Core/DelayedActionQueueItem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "DelayedActionQueueItem.hpp"

namespace griddly {

DelayedActionQueueItem::DelayedActionQueueItem(uint32_t _playerId, uint32_t _priority, std::shared_ptr<Action> _action)
: playerId(_playerId), priority(_priority), action(_action) {
}

} // namespace griddly
29 changes: 13 additions & 16 deletions src/Griddly/Core/DelayedActionQueueItem.hpp
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
#pragma once
#include <memory>

#include "GDY/Actions/Action.hpp"
#include <queue>
#include "Util/util.hpp"

namespace griddly {

class Action;

class DelayedActionQueueItem {
public:
DelayedActionQueueItem(uint32_t _playerId, uint32_t _priority, std::shared_ptr<Action> _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> _action);

uint32_t playerId;
uint32_t priority;
std::shared_ptr<Action> action;
};

struct SortDelayedActionQueue {
bool operator()(std::shared_ptr<DelayedActionQueueItem> a, std::shared_ptr<DelayedActionQueueItem> b) {
return a->priority > b->priority;
};
};

typedef VectorPriorityQueue<std::shared_ptr<DelayedActionQueueItem>, std::vector<std::shared_ptr<DelayedActionQueueItem>>, SortDelayedActionQueue> DelayedActionQueue;

} // namespace griddly
40 changes: 26 additions & 14 deletions src/Griddly/Core/GDY/Actions/Action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void Action::init(std::shared_ptr<Object> sourceObject, std::shared_ptr<Object>
sourceObject_ = sourceObject;
destinationObject_ = destinationObject;

vectorToDest_ = destinationObject_->getLocation() - sourceObject_->getLocation();
vectorToDest_ = destObj()->getLocation() - sourceObj()->getLocation();

actionMode_ = ActionMode::SRC_OBJ_DST_OBJ;
}
Expand All @@ -46,7 +46,7 @@ void Action::init(std::shared_ptr<Object> 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;
Expand All @@ -56,39 +56,39 @@ void Action::init(std::shared_ptr<Object> sourceObject, glm::ivec2 vectorToDest,
}

std::shared_ptr<Object> 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_);
}
}

std::shared_ptr<Object> 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_);
}
}

Expand All @@ -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 {};
Expand All @@ -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 {};
Expand Down Expand Up @@ -148,4 +148,16 @@ std::unordered_map<std::string, int32_t> Action::getMetaData() const {
return metaData_;
}

std::shared_ptr<Object> Action::sourceObj() const {
return sourceObject_.expired() ? nullptr : sourceObject_.lock();
}

std::shared_ptr<Object> Action::destObj() const {
return destinationObject_.expired() ? nullptr : destinationObject_.lock();
}

std::shared_ptr<Grid> Action::grid() const {
return grid_.lock();
}

} // namespace griddly
Loading

0 comments on commit f0ec38a

Please sign in to comment.