Skip to content

Commit

Permalink
Merge branch 'release/1.3.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bam4d committed May 31, 2022
2 parents 631f31a + dc94157 commit 01c6d97
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 6 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.3.8]
- Version [e.g. 1.3.9]

**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,6 +1,6 @@
cmake_minimum_required(VERSION 3.10.0)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum OS X deployment version")
project(Griddly VERSION 1.3.8)
project(Griddly VERSION 1.3.9)

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

#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.3.8'
release = '1.3.9'


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion js/jiddly-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jiddly-app",
"version": "1.3.8",
"version": "1.3.9",
"private": true,
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.1.1",
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.3.8",
version="1.3.9",
author_email="[email protected]",
description="Griddly Python Libraries",
long_description=long_description,
Expand Down
16 changes: 16 additions & 0 deletions src/Griddly/Core/GDY/GDYFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,22 @@ VectorObserverConfig GDYFactory::parseNamedVectorObserverConfig(std::string obse
config.includeRotation = resolveObserverConfigValue<bool>("IncludeRotation", observerConfigNode, config.includeRotation, !isGlobalObserver);
config.includeVariables = resolveObserverConfigValue<bool>("IncludeVariables", observerConfigNode, config.includeVariables, !isGlobalObserver);

auto globalVariableMappingNode = observerConfigNode["GlobalVariableMapping"];

if (globalVariableMappingNode.IsDefined()) {
const auto& globalEntityVariables = singleOrListNodeToList(globalVariableMappingNode);

for (const auto& globalEntityVariable : globalEntityVariables) {
if (globalVariableDefinitions_.find(globalEntityVariable) == globalVariableDefinitions_.end()) {
std::string error = fmt::format("No global variable with name {0} in GlobalVariableMapping feature configuration.", globalEntityVariable);
spdlog::error(error);
throw std::invalid_argument(error);
}
}

config.globalVariableMapping = globalEntityVariables;
}

return config;
}

Expand Down
27 changes: 27 additions & 0 deletions src/Griddly/Core/Observers/VectorObserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ void VectorObserver::resetShape() {
spdlog::debug("Adding {0} variable channels at: {1}", observationChannels_ - channelsBeforeVariables_, channelsBeforeVariables_);
}

if (config_.globalVariableMapping.size() > 0) {
channelsBeforeGlobalVariables_ = observationChannels_;
observationChannels_ += static_cast<uint32_t>(config_.globalVariableMapping.size());
spdlog::debug("Adding {0} global variable channels at: {1}", observationChannels_ - channelsBeforeGlobalVariables_, channelsBeforeGlobalVariables_);
}

observationShape_ = {observationChannels_, gridWidth_, gridHeight_};
observationStrides_ = {1, observationChannels_, observationChannels_ * gridWidth_};

Expand Down Expand Up @@ -237,6 +243,27 @@ uint8_t& VectorObserver::update() {
}
}
}

// Sellotape the chosen global variables onto the obs
if (config_.globalVariableMapping.size() > 0) {
const auto& globalVariables = grid_->getGlobalVariables();
uint32_t globalVariableIdx = 0;
for (const auto& variableName : config_.globalVariableMapping) {
const auto& variable = globalVariables.at(variableName);

auto value = variable.size() > 1 ? variable.at(config_.playerId) : variable.at(0);

for (auto x = 0; x < gridWidth_; x++) {
for (auto y = 0; y < gridHeight_; y++) {
auto memPtr = observation_.get() + observationChannels_ * (gridWidth_ * y + x);
auto globalVariableMemPtr = memPtr + channelsBeforeGlobalVariables_ + globalVariableIdx;
*globalVariableMemPtr = *value;
}
}
globalVariableIdx++;
}
}

}

spdlog::debug("Purging update locations.");
Expand Down
2 changes: 2 additions & 0 deletions src/Griddly/Core/Observers/VectorObserver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ struct VectorObserverConfig : public ObserverConfig {
bool includeVariables = false;
bool includeRotation = false;
bool includePlayerId = false;
std::vector<std::string> globalVariableMapping{};
};

class VectorObserver : public Observer, public TensorObservationInterface, public ObserverConfigInterface<VectorObserverConfig> {
Expand All @@ -34,6 +35,7 @@ class VectorObserver : public Observer, public TensorObservationInterface, publi
uint32_t channelsBeforePlayerCount_;
uint32_t channelsBeforeRotation_;
uint32_t channelsBeforeVariables_;
uint32_t channelsBeforeGlobalVariables_;

VectorObserverConfig config_;
};
Expand Down
20 changes: 20 additions & 0 deletions tests/src/Griddly/Core/Observers/VectorObserverTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,26 @@ TEST(VectorObserverTest, partialObserver_withOffset_trackAvatar_rotateWithAvatar
runVectorObserverTest(config, Direction::LEFT, {4, 5, 3}, {1, 4, 20}, expectedData[0][0]);
}

TEST(VectorObserverTest, defaultObserver_global_variables) {
VectorObserverConfig config = {
5,
5,
0,
0,
false, false};

config.globalVariableMapping = {"lightingR", "lightingB"};

uint8_t expectedData[5][5][6] = {
{{1, 0, 0, 0, 50, 100}, {1, 0, 0, 0, 50, 100}, {1, 0, 0, 0, 50, 100}, {1, 0, 0, 0, 50, 100}, {1, 0, 0, 0, 50, 100}},
{{1, 0, 0, 0, 50, 100}, {0, 1, 0, 0, 50, 100}, {0, 0, 0, 0, 50, 100}, {0, 0, 1, 0, 50, 100}, {1, 0, 0, 0, 50, 100}},
{{1, 0, 0, 0, 50, 100}, {0, 1, 0, 0, 50, 100}, {0, 0, 0, 1, 50, 100}, {0, 0, 1, 0, 50, 100}, {1, 0, 0, 0, 50, 100}},
{{1, 0, 0, 0, 50, 100}, {0, 0, 1, 0, 50, 100}, {0, 0, 0, 0, 50, 100}, {0, 1, 0, 0, 50, 100}, {1, 0, 0, 0, 50, 100}},
{{1, 0, 0, 0, 50, 100}, {1, 0, 0, 0, 50, 100}, {1, 0, 0, 0, 50, 100}, {1, 0, 0, 0, 50, 100}, {1, 0, 0, 0, 50, 100}}};

runVectorObserverTest(config, Direction::NONE, {6, 5, 5}, {1, 6, 30}, expectedData[0][0]);
}

TEST(VectorObserverTest, multiPlayer_Outline_Player1) {
VectorObserverConfig config = {5, 5, 0, 0};
config.playerId = 1;
Expand Down

0 comments on commit 01c6d97

Please sign in to comment.