Skip to content

Commit

Permalink
+ correct num cells in inspection window
Browse files Browse the repository at this point in the history
+ replace workaround for widgets in inspection window by a proper solution
  • Loading branch information
chrxh committed Oct 15, 2023
1 parent cc31734 commit 1f944ec
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
14 changes: 12 additions & 2 deletions source/EngineInterface/GenomeDescriptionConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,15 @@ namespace
auto value = static_cast<int>(readByte(data, pos));
return value > 127 ? std::nullopt : std::make_optional(value % moduloValue);
}
int readByteWithInfinity(std::vector<uint8_t> const& data, int& pos)

int convertByteToByteWithInfinity(uint8_t const& b)
{
auto b = readByte(data, pos);
return b == 255 ? std::numeric_limits<int>::max() : b;

}
int readByteWithInfinity(std::vector<uint8_t> const& data, int& pos)
{
return convertByteToByteWithInfinity(readByte(data, pos));
}
bool readBool(std::vector<uint8_t> const& data, int& pos)
{
Expand Down Expand Up @@ -391,3 +396,8 @@ int GenomeDescriptionConverter::getNumNodesRecursively(std::vector<uint8_t> cons
auto numRepetitions = genome.header.numRepetitions == std::numeric_limits<int>::max() ? 1 : genome.header.numRepetitions;
return includeRepetitions ? result * numRepetitions : result;
}

int GenomeDescriptionConverter::getNumRepetitions(std::vector<uint8_t> const& data)
{
return convertByteToByteWithInfinity(data.at(Const::GenomeHeaderNumRepetitionsPos));
}
1 change: 1 addition & 0 deletions source/EngineInterface/GenomeDescriptionConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ class GenomeDescriptionConverter
static int convertNodeAddressToNodeIndex(std::vector<uint8_t> const& data, int nodeAddress, GenomeEncodingSpecification const& spec = GenomeEncodingSpecification());
static int convertNodeIndexToNodeAddress(std::vector<uint8_t> const& data, int nodeIndex, GenomeEncodingSpecification const& spec = GenomeEncodingSpecification());
static int getNumNodesRecursively(std::vector<uint8_t> const& data, bool includeRepetitions, GenomeEncodingSpecification const& spec = GenomeEncodingSpecification());
static int getNumRepetitions(std::vector<uint8_t> const& data);
};
28 changes: 16 additions & 12 deletions source/Gui/InspectorWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,22 +391,20 @@ void _InspectorWindow::processCellGenomeTab(Description& desc)
}

if (ImGui::TreeNodeEx("Properties (entire genome)", TreeNodeFlags)) {
auto numNodes = toFloat(GenomeDescriptionConverter::getNumNodesRecursively(desc.genome, true));
AlienImGui::InputFloat(
AlienImGui::InputFloatParameters()
auto numNodes = toInt(GenomeDescriptionConverter::getNumNodesRecursively(desc.genome, true));
AlienImGui::InputInt(
AlienImGui::InputIntParameters()
.name("Number of cells")
.textWidth(GenomeTabTextWidth)
.format("%.0f")
.readOnly(true)
.tooltip(Const::GenomeNumCellsRecursivelyTooltip),
numNodes);

auto numBytes = toFloat(desc.genome.size() + 0.5f);
AlienImGui::InputFloat(
AlienImGui::InputFloatParameters()
auto numBytes = toInt(desc.genome.size());
AlienImGui::InputInt(
AlienImGui::InputIntParameters()
.name("Bytes")
.textWidth(GenomeTabTextWidth)
.format("%.0f")
.readOnly(true)
.tooltip(Const::GenomeBytesTooltip),
numBytes);
Expand All @@ -420,12 +418,11 @@ void _InspectorWindow::processCellGenomeTab(Description& desc)
if (ImGui::TreeNodeEx("Properties (principal genome part)", TreeNodeFlags)) {

auto genomeDesc = GenomeDescriptionConverter::convertBytesToDescription(desc.genome);
auto numNodes = toFloat(genomeDesc.cells.size());
AlienImGui::InputFloat(
AlienImGui::InputFloatParameters()
auto numNodes = toInt(genomeDesc.cells.size());
AlienImGui::InputInt(
AlienImGui::InputIntParameters()
.name("Number of cells")
.textWidth(GenomeTabTextWidth)
.format("%.0f")
.readOnly(true)
.tooltip(Const::GenomeNumCellsTooltip),
numNodes);
Expand Down Expand Up @@ -727,6 +724,13 @@ void _InspectorWindow::validationAndCorrection(CellDescription& cell) const
constructor.genomeCurrentNodeIndex = 0;
}

auto numRepetitions = GenomeDescriptionConverter::getNumRepetitions(constructor.genome);
if (numRepetitions != std::numeric_limits<int>::max()) {
constructor.genomeCurrentRepetition = ((constructor.genomeCurrentRepetition % numRepetitions) + numRepetitions) % numRepetitions;
} else {
constructor.genomeCurrentRepetition = 0;
}

if (constructor.constructionActivationTime < 0) {
constructor.constructionActivationTime = 0;
}
Expand Down

0 comments on commit 1f944ec

Please sign in to comment.