Skip to content

Commit

Permalink
Merge branch 'release/1.2.26'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bam4d committed Jan 28, 2022
2 parents c17ad8d + 2df79c7 commit 4107bbc
Show file tree
Hide file tree
Showing 22 changed files with 252 additions and 21 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.25]
- Version [e.g. 1.2.26]

**Additional context**
Add any other context about the problem here.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 3.10.0)
project(Griddly VERSION 1.2.25)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum OS X deployment version")
project(Griddly VERSION 1.2.26)

set(BINARY ${CMAKE_PROJECT_NAME})

Expand All @@ -21,6 +22,8 @@ elseif(MINGW)
add_compile_options("-Wa,-mbig-obj")
endif()



set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${BIN_OUTPUT_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${BIN_OUTPUT_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BIN_OUTPUT_DIR})
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.25";
m.attr("version") = "1.2.26";

#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.25'
release = '1.2.26'


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/Custom Shaders/Global Lighting/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ In this tutorial we modify the :ref:`Bufferflies <doc_butterflies_and_spiders>`
<div class="figure align-center" id="vid1">
<video onloadeddata="this.play();" playsinline loop muted height="10%">

<source src="../../../../../_static/video/tutorials/custom_shaders/global_lighting/global_video_test.mp4"
<source src="../../../_static/video/tutorials/custom_shaders/global_lighting/global_video_test.mp4"
type="video/mp4">

Sorry, your browser doesn't support embedded videos.
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/Projectiles/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The agent receives a reward of 1 for every time a projectile hits a box, and a r
<div class="figure align-center" id="vid1">
<video onloadeddata="this.play();" playsinline loop muted height="10%">

<source src="../../../../../_static/video/tutorials/projectiles/global_video_test.mp4"
<source src="../../_static/video/tutorials/projectiles/global_video_test.mp4"
type="video/mp4">

Sorry, your browser doesn't support embedded videos.
Expand Down
Binary file added python/examples/Stochasticity/assets/cow-left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added python/examples/Stochasticity/assets/dirt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added python/examples/Stochasticity/assets/grass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added python/examples/Stochasticity/assets/player.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions python/examples/Stochasticity/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import os

from griddly import GymWrapperFactory, gd, GymWrapper
from griddly.RenderTools import VideoRecorder

if __name__ == '__main__':
wrapper = GymWrapperFactory()

name = 'stochasticity_env'

current_path = os.path.dirname(os.path.realpath(__file__))

env = GymWrapper('stochasticity.yaml',
player_observer_type=gd.ObserverType.SPRITE_2D,
global_observer_type=gd.ObserverType.SPRITE_2D,
image_path='./assets/',
level=0)

env.reset()

global_recorder = VideoRecorder()
global_visualization = env.render(observer='global', mode='rgb_array')
global_recorder.start("global_video_test.mp4", global_visualization.shape)

for i in range(10000):

obs, reward, done, info = env.step(env.action_space.sample())

env.render(observer='global')
env.render()
frame = env.render(observer='global', mode='rgb_array')

global_recorder.add_frame(frame)

if done:
break

global_recorder.close()
141 changes: 141 additions & 0 deletions python/examples/Stochasticity/stochasticity.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
Version: 1
Environment:
Name: Look After the Cows
Description: asdf
Player:
Observer:
Height: 5
Width: 5
TrackAvatar: true
#RotateWithAvatar: true
AvatarObject: player
Observers:
Sprite2D:
TileSize: 48
BackgroundTile: dirt.png
Levels:
- |
G G G G G G G G
G G G G G G c/G G
G G G G G G G G
G G G G G G G G
G G G p/G G G G G
G G G G G G G G
G G G G G G G G
G c/G G G G G G G
G G G G G G G G
Actions:
- Name: move
InputMapping:
Inputs:
1:
VectorToDest: [0, -1]
OrientationVector: [0, -1]
2:
VectorToDest: [ 1, 0 ]
OrientationVector: [ 1, 0 ]
3:
VectorToDest: [ 0, 1 ]
OrientationVector: [ 0, 1 ]
4:
VectorToDest: [-1, 0 ]
OrientationVector: [-1, 0 ]
Relative: true
Behaviours:
- Src:
Object: player
Commands:
- mov: _dest
- rot: _dir
Dst:
Object: [ grass, dirt ]

- Name: plant_grass
InputMapping:
Inputs:
1:
VectorToDest: [ 0, -1 ]
Relative: true
Behaviours:
- Src:
Object: player
Commands:
- reward: 1
Dst:
Object: dirt
Commands:
- change_to: grass

- Name: cow_eat_grass
Probability: 0.05
InputMapping:
Internal: true
Inputs:
1:
VectorToDest: [0, 0]
Behaviours:
- Src:
Object: cow
Dst:
Object: grass
Commands:
- change_to: dirt

- Name: cow_random_movement
InputMapping:
Internal: true
Behaviours:

- Src:
Object: cow
Commands:
- mov: _dest
- exec:
Action: cow_eat_grass
- exec:
Action: cow_random_movement
Delay: 1
Randomize: true
Dst:
Object: [ grass, dirt ]


- Src:
Object: cow
Commands:
- exec:
Action: cow_random_movement
Delay: 1
Randomize: true
Dst:
Object: [ _empty, _boundary, cow, player ]

Objects:
- Name: player
MapCharacter: p
Z: 2
Observers:
Sprite2D:
- Image: player.png
- Name: grass
MapCharacter: G
Z: 1
Observers:
Sprite2D:
- Image: grass.png
- Name: dirt
Z: 1
MapCharacter: D
Observers:
Sprite2D:
- Image: dirt.png
- Name: cow
InitialActions:
- Action: cow_random_movement
Randomize: true
Z: 2
MapCharacter: 'c'
Observers:
Sprite2D:
- Image: cow-left.png
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.25",
version="1.2.26",
author_email="[email protected]",
description="Griddly Python Libraries",
long_description=long_description,
Expand Down
2 changes: 2 additions & 0 deletions src/Griddly/Core/GDY/GDYFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ void GDYFactory::parsePlayerDefinition(YAML::Node playerNode) {
auto observerGridOffsetY = observerNode["OffsetY"].as<int32_t>(0);
auto trackAvatar = observerNode["TrackAvatar"].as<bool>(false);
auto rotateWithAvatar = observerNode["RotateWithAvatar"].as<bool>(false);
auto rotateAvatarImage = observerNode["RotateAvatarImage"].as<bool>(true);
auto highlightPlayers = observerNode["HighlightPlayers"].as<bool>(playerCount_ > 1);

if (highlightPlayers) {
Expand All @@ -266,6 +267,7 @@ void GDYFactory::parsePlayerDefinition(YAML::Node playerNode) {
playerObserverDefinition_.gridXOffset = observerGridOffsetX;
playerObserverDefinition_.gridYOffset = observerGridOffsetY;
playerObserverDefinition_.trackAvatar = trackAvatar;
playerObserverDefinition_.rotateAvatarImage = rotateAvatarImage;
playerObserverDefinition_.rotateWithAvatar = rotateWithAvatar;
playerObserverDefinition_.highlightPlayers = highlightPlayers;
}
Expand Down
1 change: 1 addition & 0 deletions src/Griddly/Core/GameProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ void GameProcess::init(bool isCloned) {
observerConfig.gridXOffset = playerObserverDefinition.gridXOffset;
observerConfig.gridYOffset = playerObserverDefinition.gridYOffset;
observerConfig.rotateWithAvatar = playerObserverDefinition.rotateWithAvatar;
observerConfig.rotateAvatarImage = playerObserverDefinition.rotateAvatarImage;
observerConfig.playerId = p->getId();
observerConfig.playerCount = playerObserverDefinition.playerCount;
observerConfig.highlightPlayers = playerObserverDefinition.highlightPlayers;
Expand Down
8 changes: 5 additions & 3 deletions src/Griddly/Core/Observers/BlockObserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ void BlockObserver::updateObjectSSBOData(PartialObservableGrid& observableGrid,
objectData.modelMatrix = glm::translate(objectData.modelMatrix, glm::vec3(0.5, 0.5, 0.0)); // Offset for the the vertexes as they are between (-0.5, 0.5) and we want them between (0, 1)

// Rotate the objects that should be rotated
if (!(object == avatarObject_ && observerConfig_.rotateWithAvatar)) {
auto objectAngleRadians = objectOrientation.getAngleRadians() - globalOrientation.getAngleRadians();
objectData.modelMatrix = glm::rotate(objectData.modelMatrix, objectAngleRadians, glm::vec3(0.0, 0.0, 1.0));
if(observerConfig_.rotateAvatarImage) {
if (!(object == avatarObject_ && observerConfig_.rotateWithAvatar)) {
auto objectAngleRadians = objectOrientation.getAngleRadians() - globalOrientation.getAngleRadians();
objectData.modelMatrix = glm::rotate(objectData.modelMatrix, objectAngleRadians, glm::vec3(0.0, 0.0, 1.0));
}
}

// Scale the objects based on their scales
Expand Down
1 change: 1 addition & 0 deletions src/Griddly/Core/Observers/Observer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct ObserverConfig {
int32_t gridXOffset = 0;
int32_t gridYOffset = 0;
bool rotateWithAvatar = false;
bool rotateAvatarImage = true;
uint32_t playerId = 0;
uint32_t playerCount = 1;
glm::ivec2 tileSize = {24, 24};
Expand Down
26 changes: 16 additions & 10 deletions src/Griddly/Core/Observers/SpriteObserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,17 @@ std::string SpriteObserver::getSpriteName(const std::string& objectName, const s
}

void SpriteObserver::updateObjectSSBOData(PartialObservableGrid& observableGrid, glm::mat4& globalModelMatrix, DiscreteOrientation globalOrientation) {
vk::ObjectDataSSBO backgroundTiling;
backgroundTiling.modelMatrix = glm::translate(backgroundTiling.modelMatrix, glm::vec3(gridWidth_ / 2.0 - observerConfig_.gridXOffset, gridHeight_ / 2.0 - observerConfig_.gridYOffset, 0.0));
backgroundTiling.modelMatrix = glm::scale(backgroundTiling.modelMatrix, glm::vec3(gridWidth_, gridHeight_, 1.0));
backgroundTiling.zIdx = -10;
backgroundTiling.textureMultiply = {gridWidth_, gridHeight_};
backgroundTiling.textureIndex = device_->getSpriteArrayLayer("_background_");
frameSSBOData_.objectSSBOData.push_back({backgroundTiling});

uint32_t backgroundTileIndex = device_->getSpriteArrayLayer("_background_");
if(backgroundTileIndex != -1) {
vk::ObjectDataSSBO backgroundTiling;
backgroundTiling.modelMatrix = glm::translate(backgroundTiling.modelMatrix, glm::vec3(gridWidth_ / 2.0 - observerConfig_.gridXOffset, gridHeight_ / 2.0 - observerConfig_.gridYOffset, 0.0));
backgroundTiling.modelMatrix = glm::scale(backgroundTiling.modelMatrix, glm::vec3(gridWidth_, gridHeight_, 1.0));
backgroundTiling.zIdx = -10;
backgroundTiling.textureMultiply = {gridWidth_, gridHeight_};
backgroundTiling.textureIndex = backgroundTileIndex;
frameSSBOData_.objectSSBOData.push_back({backgroundTiling});
}

const auto& objects = grid_->getObjects();
const auto& objectIds = grid_->getObjectIds();
Expand Down Expand Up @@ -216,9 +220,11 @@ void SpriteObserver::updateObjectSSBOData(PartialObservableGrid& observableGrid,
objectData.modelMatrix = glm::translate(objectData.modelMatrix, glm::vec3(0.5, 0.5, 0.0)); // Offset for the the vertexes as they are between (-0.5, 0.5) and we want them between (0, 1)

// Rotate the objects that should be rotated
if (!(object == avatarObject_ && observerConfig_.rotateWithAvatar) && !isWallTiles) {
auto objectAngleRadians = objectOrientation.getAngleRadians() - globalOrientation.getAngleRadians();
objectData.modelMatrix = glm::rotate(objectData.modelMatrix, objectAngleRadians, glm::vec3(0.0, 0.0, 1.0));
if(observerConfig_.rotateAvatarImage) {
if (!(object == avatarObject_ && observerConfig_.rotateWithAvatar) && !isWallTiles) {
auto objectAngleRadians = objectOrientation.getAngleRadians() - globalOrientation.getAngleRadians();
objectData.modelMatrix = glm::rotate(objectData.modelMatrix, objectAngleRadians, glm::vec3(0.0, 0.0, 1.0));
}
}

// Scale the objects based on their scales
Expand Down
6 changes: 5 additions & 1 deletion src/Griddly/Core/Observers/Vulkan/VulkanDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,11 @@ void VulkanDevice::startRecordingCommandBuffer() {
}

uint32_t VulkanDevice::getSpriteArrayLayer(std::string spriteName) {
return spriteIndices_.at(spriteName);
if (spriteIndices_.find(spriteName) == spriteIndices_.end()) {
return -1;
} else {
return spriteIndices_.at(spriteName);
}
}

void VulkanDevice::updateObjectPushConstants(uint32_t objectIndex) {
Expand Down
1 change: 1 addition & 0 deletions src/Griddly/Core/Players/Player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct PlayerObserverDefinition {
int32_t gridYOffset = 0;
bool trackAvatar = false;
bool rotateWithAvatar = false;
bool rotateAvatarImage = true;
uint32_t playerCount = 0;
bool highlightPlayers = true;
};
Expand Down
32 changes: 32 additions & 0 deletions tests/src/Griddly/Core/GDY/GDYFactoryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,38 @@ TEST(GDYFactoryTest, loadEnvironment_PlayerNoHighlight) {
ASSERT_EQ(observationDefinition.gridYOffset, 0);
ASSERT_FALSE(observationDefinition.highlightPlayers);
ASSERT_TRUE(observationDefinition.trackAvatar);
ASSERT_FALSE(observationDefinition.rotateWithAvatar);
ASSERT_TRUE(observationDefinition.rotateAvatarImage);
}

TEST(GDYFactoryTest, loadEnvironment_RotateAvatar) {
auto mockObjectGeneratorPtr = std::shared_ptr<MockObjectGenerator>(new MockObjectGenerator());
auto gdyFactory = std::shared_ptr<GDYFactory>(new GDYFactory(mockObjectGeneratorPtr, nullptr, {}));
auto yamlString = R"(
Environment:
Name: Test
Player:
AvatarObject: player
Observer:
RotateAvatarImage: false
Height: 9
Width: 9
)";

auto environmentNode = loadFromStringAndGetNode(std::string(yamlString), "Environment");

gdyFactory->loadEnvironment(environmentNode);

auto observationDefinition = gdyFactory->getPlayerObserverDefinition();

ASSERT_EQ(observationDefinition.gridHeight, 9);
ASSERT_EQ(observationDefinition.gridWidth, 9);
ASSERT_EQ(observationDefinition.gridXOffset, 0);
ASSERT_EQ(observationDefinition.gridYOffset, 0);
ASSERT_FALSE(observationDefinition.highlightPlayers);
ASSERT_FALSE(observationDefinition.trackAvatar);
ASSERT_FALSE(observationDefinition.rotateWithAvatar);
ASSERT_FALSE(observationDefinition.rotateAvatarImage);
}

TEST(GDYFactoryTest, loadEnvironment_MultiPlayerNoHighlight) {
Expand Down

0 comments on commit 4107bbc

Please sign in to comment.