Skip to content

Commit

Permalink
Merge branch 'release/1.2.15'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bam4d committed Nov 18, 2021
2 parents f0f3ef4 + b974939 commit b8409a6
Show file tree
Hide file tree
Showing 20 changed files with 176 additions and 58 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.14]
- Version [e.g. 1.2.15]

**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.14)
project(Griddly VERSION 1.2.15)

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.14";
m.attr("version") = "1.2.15";

#ifndef NDEBUG
spdlog::set_level(spdlog::level::debug);
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.14'
release = '1.2.15'


# -- 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.14",
version="1.2.15",
author_email="[email protected]",
description="Griddly Python Libraries",
long_description=long_description,
Expand Down
17 changes: 12 additions & 5 deletions src/Griddly/Core/GDY/Actions/Direction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class DiscreteOrientation {
}
}

float getAngleRadians() {
float getAngleRadians() const {
switch (direction_) {
case Direction::NONE:
case Direction::UP:
Expand All @@ -78,7 +78,7 @@ class DiscreteOrientation {
}
}

glm::ivec2 getUnitVector() {
glm::ivec2 getUnitVector() const {
return unitVector_;
}

Expand All @@ -100,11 +100,11 @@ class DiscreteOrientation {
}

// If the current direction is DOWN and the input vector is "right" we return "left" etc..
glm::ivec2 getRelativeUnitVector(glm::ivec2 vector) {
glm::ivec2 getRelativeUnitVector(glm::ivec2 vector) const {
return vector * getRotationMatrix();
}

glm::imat2x2 getRotationMatrix() {
glm::imat2x2 getRotationMatrix() const {
switch (direction_) {
default:
case Direction::NONE:
Expand All @@ -119,10 +119,17 @@ class DiscreteOrientation {
}
}

Direction getDirection() {
Direction getDirection() const {
return direction_;
}

inline bool operator==(const DiscreteOrientation& other) const {
bool equal = direction_ == other.getDirection() &&
unitVector_ == other.getUnitVector();

return equal;
}

private:
glm::ivec2 unitVector_ = {0, 0};
Direction direction_ = Direction::NONE;
Expand Down
4 changes: 4 additions & 0 deletions src/Griddly/Core/GDY/Objects/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,10 @@ void Object::setRenderTileId(uint32_t renderTileId) {
renderTileId_ = renderTileId;
}

uint32_t Object::getRenderTileId() const {
return renderTileId_;
}

void Object::removeObject() {
grid_->removeObject(shared_from_this());
}
Expand Down
6 changes: 4 additions & 2 deletions src/Griddly/Core/GDY/Objects/Object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ class Object : public std::enable_shared_from_this<Object> {

virtual bool isPlayerAvatar() const;

virtual void setRenderTileId(uint32_t renderTileId);

virtual uint32_t getRenderTileId() const;

virtual void markAsPlayerAvatar(); // Set this object as a player avatar

virtual bool isValidAction(std::shared_ptr<Action> action) const;
Expand Down Expand Up @@ -158,8 +162,6 @@ class Object : public std::enable_shared_from_this<Object> {

virtual bool moveObject(glm::ivec2 newLocation);

virtual void setRenderTileId(uint32_t renderTileId);

virtual void removeObject();

SingleInputMapping getInputMapping(std::string actionName, uint32_t actionId, bool randomize, InputMapping fallback);
Expand Down
4 changes: 4 additions & 0 deletions src/Griddly/Core/GDY/Objects/ObjectGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ std::shared_ptr<Object> ObjectGenerator::cloneInstance(std::shared_ptr<Object> t
}
}


auto objectZIdx = objectDefinition->zIdx;
auto mapCharacter = objectDefinition->mapCharacter;
auto initializedObject = std::shared_ptr<Object>(new Object(objectName, mapCharacter, playerId, objectZIdx, availableVariables, shared_from_this(), grid));
Expand All @@ -100,6 +101,9 @@ std::shared_ptr<Object> ObjectGenerator::cloneInstance(std::shared_ptr<Object> t
initializedObject->markAsPlayerAvatar();
}

initializedObject->setRenderTileId(toClone->getRenderTileId());


for (auto &actionBehaviourDefinition : objectDefinition->actionBehaviourDefinitions) {
switch (actionBehaviourDefinition.behaviourType) {
case ActionBehaviourType::SOURCE:
Expand Down
4 changes: 2 additions & 2 deletions src/Griddly/Core/Grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ std::shared_ptr<Object> Grid::getPlayerDefaultObject(uint32_t playerId) const {
return defaultObject_.at(playerId);
}

void Grid::addObject(glm::ivec2 location, std::shared_ptr<Object> object, bool applyInitialActions, std::shared_ptr<Action> originatingAction) {
void Grid::addObject(glm::ivec2 location, std::shared_ptr<Object> object, bool applyInitialActions, std::shared_ptr<Action> originatingAction, DiscreteOrientation orientation) {
auto objectName = object->getObjectName();
auto playerId = object->getPlayerId();

Expand All @@ -540,7 +540,7 @@ void Grid::addObject(glm::ivec2 location, std::shared_ptr<Object> object, bool a

auto canAddObject = objects_.insert(object).second;
if (canAddObject) {
object->init(location);
object->init(location, orientation);

auto objectZIdx = object->getZIdx();
auto& objectsAtLocation = occupiedLocations_[location];
Expand Down
2 changes: 1 addition & 1 deletion src/Griddly/Core/Grid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class Grid : public std::enable_shared_from_this<Grid> {

virtual void initObject(std::string objectName, std::vector<std::string> objectVariableNames);

virtual void addObject(glm::ivec2 location, std::shared_ptr<Object> object, bool applyInitialActions = true, std::shared_ptr<Action> originatingAction = nullptr);
virtual void addObject(glm::ivec2 location, std::shared_ptr<Object> object, bool applyInitialActions = true, std::shared_ptr<Action> originatingAction = nullptr, DiscreteOrientation orientation=DiscreteOrientation());

virtual bool removeObject(std::shared_ptr<Object> object);

Expand Down
2 changes: 1 addition & 1 deletion src/Griddly/Core/TurnBasedGameProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ std::shared_ptr<TurnBasedGameProcess> TurnBasedGameProcess::clone() {
auto& objectsToCopy = grid_->getObjects();
for (const auto& toCopy : objectsToCopy) {
auto clonedObject = objectGenerator->cloneInstance(toCopy, clonedGrid);
clonedGrid->addObject(toCopy->getLocation(), clonedObject, false);
clonedGrid->addObject(toCopy->getLocation(), clonedObject, false, nullptr, toCopy->getObjectOrientation());

// We need to know which objects are equivalent in the grid so we can
// map delayed actions later
Expand Down
27 changes: 1 addition & 26 deletions tests/src/Griddly/Core/GDY/GDYFactoryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <iostream>
#include <memory>

#include "Griddly/Core/TestUtils/common.hpp"
#include "Griddly/Core/GDY/Actions/Action.hpp"
#include "Griddly/Core/GDY/GDYFactory.hpp"
#include "Mocks//Griddly/Core/LevelGenerators/MockLevelGenerator.hpp"
Expand Down Expand Up @@ -537,32 +538,6 @@ TEST(GDYFactoryTest, load_object_initial_actions) {
EXPECT_TRUE(Mock::VerifyAndClearExpectations(mockObjectGeneratorPtr.get()));
}

bool commandArgumentsEqual(BehaviourCommandArguments a, BehaviourCommandArguments b) {
for (auto it = a.begin(); it != a.end(); ++it) {
auto key = it->first;
auto node = it->second;

if (node.Type() != b[key].Type()) {
return false;
}
}
return true;
}

//! the comparison here is not comparing the values of the YAML but just the types. Its not perfect.
MATCHER_P(ActionBehaviourDefinitionEqMatcher, behaviour, "") {
auto isEqual = behaviour.behaviourType == arg.behaviourType &&
behaviour.sourceObjectName == arg.sourceObjectName &&
behaviour.destinationObjectName == arg.destinationObjectName &&
behaviour.actionName == arg.actionName &&
behaviour.commandName == arg.commandName &&
commandArgumentsEqual(behaviour.commandArguments, arg.commandArguments);
//behaviour.actionPreconditions == arg.actionPreconditions &&
//behaviour.conditionalCommands == arg.conditionalCommands;

return isEqual;
}

void expectOpposingDefinitionNOP(ActionBehaviourType behaviourType, std::string sourceObjectName, std::string destinationObjectName, std::shared_ptr<MockObjectGenerator> mockObjectGeneratorPtr) {
ActionBehaviourDefinition expectedNOPDefinition = GDYFactory::makeBehaviourDefinition(
behaviourType == ActionBehaviourType::DESTINATION ? ActionBehaviourType::SOURCE : ActionBehaviourType::DESTINATION,
Expand Down
75 changes: 75 additions & 0 deletions tests/src/Griddly/Core/GDY/Objects/ObjectGeneratorTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include <unordered_map>

#include "Griddly/Core/TestUtils/common.hpp"
#include "Griddly/Core/GDY/Objects/Object.hpp"
#include "Griddly/Core/GDY/Objects/ObjectGenerator.hpp"
#include "Mocks/Griddly/Core/GDY/Actions/MockAction.hpp"
#include "Mocks/Griddly/Core/MockGrid.hpp"
#include "gmock/gmock.h"
#include "gtest/gtest.h"

using ::testing::_;
using ::testing::ElementsAre;
using ::testing::Eq;
using ::testing::Invoke;
using ::testing::Mock;
using ::testing::Return;
using ::testing::ReturnRef;
using ::testing::UnorderedElementsAre;

#define _V(X) std::make_shared<int32_t>(X)
#define _Y(X) YAML::Node(X)

namespace griddly {
TEST(ObjectGeneratorTest, cloneInstance) {
std::string objectAName = "objectA";
std::string objectBName = "objectB";
DiscreteOrientation orientation = DiscreteOrientation(Direction::RIGHT);
glm::ivec2 location = {4, 5};
char mapCharacter = 'A';
uint32_t zIdx = 1;

ActionBehaviourDefinition mockBehaviourDefinition;

mockBehaviourDefinition.behaviourType = ActionBehaviourType::SOURCE;
mockBehaviourDefinition.sourceObjectName = objectAName;
mockBehaviourDefinition.destinationObjectName = objectBName;
mockBehaviourDefinition.actionName = "actionA";
mockBehaviourDefinition.commandName = "eq";
mockBehaviourDefinition.commandArguments = {{"0", _Y("0")}, {"1", _Y("10")}};
mockBehaviourDefinition.actionPreconditions = {{"eq", {{"0", _Y("0")}, {"1", _Y("1")}}}, {"eq", {{"0", _Y("1")}, {"1", _Y("0")}}}};
mockBehaviourDefinition.conditionalCommands = {{"reward", {{"0", _Y("1")}}}};
mockBehaviourDefinition.executionProbability = 0.4;

auto mockObjectPtr = mockObject(objectAName, mapCharacter, 1, zIdx, location, orientation, {"actionA"}, {{"variable1", _V(10)}, {"variable2", _V(20)}});

EXPECT_CALL(*mockObjectPtr, getRenderTileId).WillOnce(Return(4));

auto mockGridPtr = std::shared_ptr<MockGrid>(new MockGrid());

std::unordered_map<std::string, std::unordered_map<uint32_t, std::shared_ptr<int32_t>>> globalVariables = {
{"globalVariable1", {{0, _V(1)}}},
{"globalVariable2", {{0, _V(1)},{1, _V(2)}}},
};

EXPECT_CALL(*mockGridPtr, getGlobalVariables()).WillOnce(ReturnRef(globalVariables));

auto objectGenerator = std::shared_ptr<ObjectGenerator>(new ObjectGenerator());

objectGenerator->setAvatarObject(objectAName);
objectGenerator->defineNewObject(objectAName, mapCharacter, zIdx, {{"variable1", 0}, {"variable2", 0}});
objectGenerator->defineActionBehaviour(objectAName, mockBehaviourDefinition);

auto clonedObject = objectGenerator->cloneInstance(mockObjectPtr, mockGridPtr);

ASSERT_EQ(clonedObject->getObjectName(), objectAName);
//ASSERT_EQ(clonedObject->getLocation(), location); // At this point the object has not been added to the grid, so it does not have a location or orientation
//ASSERT_EQ(clonedObject->getObjectOrientation().getDirection(), orientation.getDirection());
ASSERT_EQ(clonedObject->getZIdx(), zIdx);
ASSERT_EQ(clonedObject->getMapCharacter(), mapCharacter);
ASSERT_EQ(clonedObject->getObjectRenderTileName(), objectAName+"4");
ASSERT_EQ(clonedObject->isPlayerAvatar(), true);
ASSERT_THAT(clonedObject->getAvailableActionNames(), UnorderedElementsAre("actionA"));

}
} // namespace griddly
6 changes: 3 additions & 3 deletions tests/src/Griddly/Core/GDY/Objects/ObjectTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1158,13 +1158,13 @@ TEST(ObjectTest, command_change_to) {
EXPECT_CALL(*mockGridPtr, removeObject(Eq(srcObjectPtr)))
.Times(1)
.WillOnce(Return(true));
EXPECT_CALL(*mockGridPtr, addObject(Eq(glm::ivec2(0, 0)), Eq(newObjectPtr), Eq(true), Eq(mockActionPtr)))
EXPECT_CALL(*mockGridPtr, addObject(Eq(glm::ivec2(0, 0)), Eq(newObjectPtr), Eq(true), Eq(mockActionPtr), Eq(DiscreteOrientation())))
.Times(1);

EXPECT_CALL(*mockGridPtr, removeObject(Eq(dstObjectPtr)))
.Times(1)
.WillOnce(Return(true));
EXPECT_CALL(*mockGridPtr, addObject(Eq(glm::ivec2(1, 0)), Eq(newObjectPtr), Eq(true), Eq(mockActionPtr)))
EXPECT_CALL(*mockGridPtr, addObject(Eq(glm::ivec2(1, 0)), Eq(newObjectPtr), Eq(true), Eq(mockActionPtr), Eq(DiscreteOrientation())))
.Times(1);

auto srcResult = addCommandsAndExecute(ActionBehaviourType::SOURCE, mockActionPtr, "change_to", {{"0", _Y("newObject")}}, srcObjectPtr, dstObjectPtr);
Expand Down Expand Up @@ -1229,7 +1229,7 @@ TEST(ObjectTest, command_spawn) {
EXPECT_CALL(*mockObjectGenerator, newInstance(Eq("newObject"), Eq(1), Eq(mockGridPtr)))
.WillOnce(Return(newObjectPtr));

EXPECT_CALL(*mockGridPtr, addObject(Eq(glm::ivec2(1, 0)), Eq(newObjectPtr), Eq(true), Eq(mockActionPtr)))
EXPECT_CALL(*mockGridPtr, addObject(Eq(glm::ivec2(1, 0)), Eq(newObjectPtr), Eq(true), Eq(mockActionPtr), Eq(DiscreteOrientation())))
.Times(1);

auto srcResult = addCommandsAndExecute(ActionBehaviourType::SOURCE, mockActionPtr, "spawn", {{"0", _Y("newObject")}}, srcObjectPtr, nullptr);
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Griddly/Core/GridTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ TEST(GridTest, objectCounters) {
auto mockObject = std::shared_ptr<MockObject>(new MockObject());

glm::ivec2 location = {(int32_t)p, (int32_t)o};
EXPECT_CALL(*mockObject, init).Times(1);
EXPECT_CALL(*mockObject, init(Eq(location), _)).Times(1);
EXPECT_CALL(*mockObject, getZIdx).WillRepeatedly(Return(0));
EXPECT_CALL(*mockObject, getLocation).WillRepeatedly(Return(location));

Expand Down
22 changes: 11 additions & 11 deletions tests/src/Griddly/Core/LevelGenerator/MapReaderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ TEST(MapGeneratorTest, testLoadStringWithPlayerObjects) {
EXPECT_CALL(*mockGridPtr, resetMap(Eq(3), Eq(3)))
.Times(1);

EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockWallObject), Eq(true), Eq(nullptr)))
EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockWallObject), Eq(true), Eq(nullptr), Eq(DiscreteOrientation())))
.Times(8);

EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockAvatarObject), Eq(true), Eq(nullptr)))
EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockAvatarObject), Eq(true), Eq(nullptr), Eq(DiscreteOrientation())))
.Times(1);

std::string levelString = "W W W\nW P1 W\nW W W";
Expand Down Expand Up @@ -150,10 +150,10 @@ TEST(MapGeneratorTest, testLoadStringWithPlayerObjectsRandomWhitespace) {
EXPECT_CALL(*mockGridPtr, resetMap(Eq(3), Eq(3)))
.Times(1);

EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockWallObject), Eq(true), Eq(nullptr)))
EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockWallObject), Eq(true), Eq(nullptr), Eq(DiscreteOrientation())))
.Times(8);

EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockAvatarObject), Eq(true), Eq(nullptr)))
EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockAvatarObject), Eq(true), Eq(nullptr), Eq(DiscreteOrientation())))
.Times(1);

std::string levelString = "W W W \nW P1 W\t\nW\tW\tW\n";
Expand Down Expand Up @@ -219,10 +219,10 @@ TEST(MapGeneratorTest, testLoadStringNoSpaces) {
EXPECT_CALL(*mockGridPtr, resetMap(Eq(3), Eq(3)))
.Times(1);

EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockWallObject), Eq(true), Eq(nullptr)))
EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockWallObject), Eq(true), Eq(nullptr), Eq(DiscreteOrientation())))
.Times(8);

EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockAvatarObject), Eq(true), Eq(nullptr)))
EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockAvatarObject), Eq(true), Eq(nullptr), Eq(DiscreteOrientation())))
.Times(1);
std::string levelString = "WWW\nWP1W\nWWW";
auto levelStringStream = std::stringstream(levelString);
Expand Down Expand Up @@ -287,10 +287,10 @@ TEST(MapGeneratorTest, testLoadStringNoSpacesWithDots) {
EXPECT_CALL(*mockGridPtr, resetMap(Eq(5), Eq(3)))
.Times(1);

EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockWallObject), Eq(true), Eq(nullptr)))
EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockWallObject), Eq(true), Eq(nullptr), Eq(DiscreteOrientation())))
.Times(12);

EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockAvatarObject), Eq(true), Eq(nullptr)))
EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockAvatarObject), Eq(true), Eq(nullptr), Eq(DiscreteOrientation())))
.Times(1);
std::string levelString = "WWWWW\nW.P1.W\nWWWWW";
auto levelStringStream = std::stringstream(levelString);
Expand Down Expand Up @@ -371,13 +371,13 @@ TEST(MapGeneratorTest, testLoadStringMultipleOccupants) {
EXPECT_CALL(*mockGridPtr, resetMap(Eq(5), Eq(3)))
.Times(1);

EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockWallObject), Eq(true), Eq(nullptr)))
EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockWallObject), Eq(true), Eq(nullptr), Eq(DiscreteOrientation())))
.Times(12);

EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockAvatarObject), Eq(true), Eq(nullptr)))
EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockAvatarObject), Eq(true), Eq(nullptr), Eq(DiscreteOrientation())))
.Times(1);

EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockFloorObject), Eq(true), Eq(nullptr)))
EXPECT_CALL(*mockGridPtr, addObject(_, Eq(mockFloorObject), Eq(true), Eq(nullptr), Eq(DiscreteOrientation())))
.Times(1);

std::string levelString = "W W W W W\nW . P1/F . W\n W W W W W";
Expand Down
Loading

0 comments on commit b8409a6

Please sign in to comment.