diff --git a/source/EngineInterface/GenomeDescriptionConverter.cpp b/source/EngineInterface/GenomeDescriptionConverter.cpp index 8a6515aca..03dde128e 100644 --- a/source/EngineInterface/GenomeDescriptionConverter.cpp +++ b/source/EngineInterface/GenomeDescriptionConverter.cpp @@ -82,10 +82,15 @@ namespace auto value = static_cast(readByte(data, pos)); return value > 127 ? std::nullopt : std::make_optional(value % moduloValue); } - int readByteWithInfinity(std::vector const& data, int& pos) + + int convertByteToByteWithInfinity(uint8_t const& b) { - auto b = readByte(data, pos); return b == 255 ? std::numeric_limits::max() : b; + + } + int readByteWithInfinity(std::vector const& data, int& pos) + { + return convertByteToByteWithInfinity(readByte(data, pos)); } bool readBool(std::vector const& data, int& pos) { @@ -391,3 +396,8 @@ int GenomeDescriptionConverter::getNumNodesRecursively(std::vector cons auto numRepetitions = genome.header.numRepetitions == std::numeric_limits::max() ? 1 : genome.header.numRepetitions; return includeRepetitions ? result * numRepetitions : result; } + +int GenomeDescriptionConverter::getNumRepetitions(std::vector const& data) +{ + return convertByteToByteWithInfinity(data.at(Const::GenomeHeaderNumRepetitionsPos)); +} diff --git a/source/EngineInterface/GenomeDescriptionConverter.h b/source/EngineInterface/GenomeDescriptionConverter.h index c1a80c030..5aa8dbd9a 100644 --- a/source/EngineInterface/GenomeDescriptionConverter.h +++ b/source/EngineInterface/GenomeDescriptionConverter.h @@ -21,4 +21,5 @@ class GenomeDescriptionConverter static int convertNodeAddressToNodeIndex(std::vector const& data, int nodeAddress, GenomeEncodingSpecification const& spec = GenomeEncodingSpecification()); static int convertNodeIndexToNodeAddress(std::vector const& data, int nodeIndex, GenomeEncodingSpecification const& spec = GenomeEncodingSpecification()); static int getNumNodesRecursively(std::vector const& data, bool includeRepetitions, GenomeEncodingSpecification const& spec = GenomeEncodingSpecification()); + static int getNumRepetitions(std::vector const& data); }; diff --git a/source/Gui/InspectorWindow.cpp b/source/Gui/InspectorWindow.cpp index 4512dd7ac..03394c1bc 100644 --- a/source/Gui/InspectorWindow.cpp +++ b/source/Gui/InspectorWindow.cpp @@ -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); @@ -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); @@ -727,6 +724,13 @@ void _InspectorWindow::validationAndCorrection(CellDescription& cell) const constructor.genomeCurrentNodeIndex = 0; } + auto numRepetitions = GenomeDescriptionConverter::getNumRepetitions(constructor.genome); + if (numRepetitions != std::numeric_limits::max()) { + constructor.genomeCurrentRepetition = ((constructor.genomeCurrentRepetition % numRepetitions) + numRepetitions) % numRepetitions; + } else { + constructor.genomeCurrentRepetition = 0; + } + if (constructor.constructionActivationTime < 0) { constructor.constructionActivationTime = 0; }