From 1b7b3395820ac5ba784e2e0207c4994d19f8cc9f Mon Sep 17 00:00:00 2001 From: Christian Heinemann Date: Tue, 20 Aug 2024 18:04:43 +0200 Subject: [PATCH] + rendering optimized + legacy parameter serialization fixed, part 1 --- source/EngineGpuKernels/RenderingKernels.cu | 241 ++++++++++-------- source/EngineGpuKernels/RenderingKernels.cuh | 15 ++ .../RenderingKernelsLauncher.cu | 9 +- .../AuxiliaryDataParserService.cpp | 67 +++-- .../LegacySimulationParametersService.cpp | 21 +- .../LegacySimulationParametersService.h | 23 +- 6 files changed, 252 insertions(+), 124 deletions(-) diff --git a/source/EngineGpuKernels/RenderingKernels.cu b/source/EngineGpuKernels/RenderingKernels.cu index a55fc5ca6..619200d78 100644 --- a/source/EngineGpuKernels/RenderingKernels.cu +++ b/source/EngineGpuKernels/RenderingKernels.cu @@ -400,7 +400,63 @@ __global__ void cudaDrawBackground(uint64_t* imageData, int2 imageSize, int2 wor } } -__global__ void cudaDrawCells(uint64_t timestep, int2 worldSize, float2 rectUpperLeft, float2 rectLowerRight, Array cells, uint64_t* imageData, int2 imageSize, float zoom) +__global__ void cudaPrepareFilteringForRendering(Array filteredCells, Array filteredParticles) +{ + filteredCells.reset(); + filteredParticles.reset(); +} + +__global__ void cudaFilterCellsForRendering(int2 worldSize, float2 rectUpperLeft, Array cells, Array filteredCells, int2 imageSize, float zoom) +{ + auto const partition = calcAllThreadsPartition(cells.getNumEntries()); + auto universeImageSize = toFloat2(worldSize) * zoom; + + BaseMap map; + map.init(worldSize); + + for (int index = partition.startIndex; index <= partition.endIndex; ++index) { + auto const& cell = cells.at(index); + auto imagePos = mapWorldPosToImagePos(rectUpperLeft, cell->pos, universeImageSize, zoom); + if (isContainedInRect({0, 0}, toFloat2(imageSize), imagePos)) { + auto cellPtr = filteredCells.getNewElement(); + *cellPtr = cell; + } + } +} + +__global__ void cudaFilterParticlesForRendering( + int2 worldSize, + float2 rectUpperLeft, + Array particles, + Array filteredParticles, + int2 imageSize, + float zoom) +{ + auto const partition = calcAllThreadsPartition(particles.getNumEntries()); + auto universeImageSize = toFloat2(worldSize) * zoom; + + BaseMap map; + map.init(worldSize); + + for (int index = partition.startIndex; index <= partition.endIndex; ++index) { + auto const& particle = particles.at(index); + auto imagePos = mapWorldPosToImagePos(rectUpperLeft, particle->absPos, universeImageSize, zoom); + if (isContainedInRect({0, 0}, toFloat2(imageSize), imagePos)) { + auto cellPtr = filteredParticles.getNewElement(); + *cellPtr = particle; + } + } +} + +__global__ void cudaDrawCells( + uint64_t timestep, + int2 worldSize, + float2 rectUpperLeft, + float2 rectLowerRight, + Array cells, + uint64_t* imageData, + int2 imageSize, + float zoom) { auto const partition = calcAllThreadsPartition(cells.getNumEntries()); @@ -415,110 +471,101 @@ __global__ void cudaDrawCells(uint64_t timestep, int2 worldSize, float2 rectUppe auto cellPos = cell->pos; auto cellImagePos = mapWorldPosToImagePos(rectUpperLeft, cellPos, universeImageSize, zoom); - if (isContainedInRect({0, 0}, toFloat2(imageSize), cellImagePos)) { - auto cellRadius = zoom * cudaSimulationParameters.cellRadius; + auto cellRadius = zoom * cudaSimulationParameters.cellRadius; - //draw primary color for cell - auto primaryColor = calcColor(cell, cell->selected, coloring, true) * 0.85f; - drawCircle(imageData, imageSize, cellImagePos, primaryColor * 0.45f, cellRadius * 8 / 5, false, false); + //draw primary color for cell + auto primaryColor = calcColor(cell, cell->selected, coloring, true) * 0.85f; + drawCircle(imageData, imageSize, cellImagePos, primaryColor * 0.45f, cellRadius * 8 / 5, false, false); - //draw secondary color for cell - auto secondaryColor = - coloring == CellColoring_MutationId_AllCellFunctions ? calcColor(cell, cell->selected, coloring, false) * 0.5f : primaryColor * 0.6f; - drawCircle(imageData, imageSize, cellImagePos, secondaryColor, cellRadius, shadedCells, true); + //draw secondary color for cell + auto secondaryColor = + coloring == CellColoring_MutationId_AllCellFunctions ? calcColor(cell, cell->selected, coloring, false) * 0.5f : primaryColor * 0.6f; + drawCircle(imageData, imageSize, cellImagePos, secondaryColor, cellRadius, shadedCells, true); - //draw activity - if (cell->isActive() && zoom >= cudaSimulationParameters.zoomLevelNeuronalActivity) { - drawCircle(imageData, imageSize, cellImagePos, float3{0.3f, 0.3f, 0.3f}, cellRadius, shadedCells); - } + //draw activity + if (cell->isActive() && zoom >= cudaSimulationParameters.zoomLevelNeuronalActivity) { + drawCircle(imageData, imageSize, cellImagePos, float3{0.3f, 0.3f, 0.3f}, cellRadius, shadedCells); + } - //draw events - if (cell->eventCounter > 0) { - if (cudaSimulationParameters.attackVisualization && cell->event == CellEvent_Attacking) { - drawDisc(imageData, imageSize, cellImagePos, {0.0f, 0.5f, 0.0f}, cellRadius * 1.4f, cellRadius * 2.0f); - } - if (cudaSimulationParameters.attackVisualization && cell->event == CellEvent_Attacked) { - float3 color{0.5f, 0.0f, 0.0f}; - drawDisc(imageData, imageSize, cellImagePos, color, cellRadius * 1.4f, cellRadius * 2.0f); + //draw events + if (cell->eventCounter > 0) { + if (cudaSimulationParameters.attackVisualization && cell->event == CellEvent_Attacking) { + drawDisc(imageData, imageSize, cellImagePos, {0.0f, 0.5f, 0.0f}, cellRadius * 1.4f, cellRadius * 2.0f); + } + if (cudaSimulationParameters.attackVisualization && cell->event == CellEvent_Attacked) { + float3 color{0.5f, 0.0f, 0.0f}; + drawDisc(imageData, imageSize, cellImagePos, color, cellRadius * 1.4f, cellRadius * 2.0f); - auto const endImagePos = mapWorldPosToImagePos(rectUpperLeft, cell->eventPos, universeImageSize, zoom); - if (isLineVisible(cellImagePos, endImagePos, universeImageSize) && Math::length(cell->eventPos - cell->pos) < 10.0f) { - drawLine(cellImagePos, endImagePos, color, imageData, imageSize); - } + auto const endImagePos = mapWorldPosToImagePos(rectUpperLeft, cell->eventPos, universeImageSize, zoom); + if (isLineVisible(cellImagePos, endImagePos, universeImageSize) && Math::length(cell->eventPos - cell->pos) < 10.0f) { + drawLine(cellImagePos, endImagePos, color, imageData, imageSize); } } + } - //draw detonation - if (cell->cellFunction == CellFunction_Detonator) { - auto const& detonator = cell->cellFunctionData.detonator; - if (detonator.state == DetonatorState_Activated && detonator.countdown < 2) { - auto radius = toFloat((timestep - cell->executionOrderNumber + 5) % 6 + (6 - detonator.countdown * 6)); - radius *= radius; - radius *= cudaSimulationParameters.cellFunctionDetonatorRadius[cell->color] * zoom / 36; - drawCircle( - imageData, - imageSize, - cellImagePos, - float3{0.3f, 0.3f, 0.0f}, - radius, - shadedCells); - } + //draw detonation + if (cell->cellFunction == CellFunction_Detonator) { + auto const& detonator = cell->cellFunctionData.detonator; + if (detonator.state == DetonatorState_Activated && detonator.countdown < 2) { + auto radius = toFloat((timestep - cell->executionOrderNumber + 5) % 6 + (6 - detonator.countdown * 6)); + radius *= radius; + radius *= cudaSimulationParameters.cellFunctionDetonatorRadius[cell->color] * zoom / 36; + drawCircle(imageData, imageSize, cellImagePos, float3{0.3f, 0.3f, 0.0f}, radius, shadedCells); } + } - //draw connections - auto lineColor = primaryColor * min((zoom - 1.0f) / 3, 1.0f) * 2 * 0.7f; - if (zoom >= ZoomLevelForConnections) { - for (int i = 0; i < cell->numConnections; ++i) { - auto const otherCell = cell->connections[i].cell; - auto otherCellPos = otherCell->pos; - auto topologyCorrection = map.getCorrectionIncrement(cellPos, otherCellPos); - otherCellPos += topologyCorrection; - - auto distFromCellCenter = Math::normalized(otherCellPos - cellPos) / 4; - auto const startImagePos = mapWorldPosToImagePos(rectUpperLeft, cellPos + distFromCellCenter, universeImageSize, zoom); - auto const endImagePos = - mapWorldPosToImagePos(rectUpperLeft, otherCellPos - distFromCellCenter, universeImageSize, zoom); - if (isLineVisible(startImagePos, endImagePos, universeImageSize)) { - drawLine(startImagePos, endImagePos, lineColor, imageData, imageSize); - } + //draw connections + auto lineColor = primaryColor * min((zoom - 1.0f) / 3, 1.0f) * 2 * 0.7f; + if (zoom >= ZoomLevelForConnections) { + for (int i = 0; i < cell->numConnections; ++i) { + auto const otherCell = cell->connections[i].cell; + auto otherCellPos = otherCell->pos; + auto topologyCorrection = map.getCorrectionIncrement(cellPos, otherCellPos); + otherCellPos += topologyCorrection; + + auto distFromCellCenter = Math::normalized(otherCellPos - cellPos) / 4; + auto const startImagePos = mapWorldPosToImagePos(rectUpperLeft, cellPos + distFromCellCenter, universeImageSize, zoom); + auto const endImagePos = mapWorldPosToImagePos(rectUpperLeft, otherCellPos - distFromCellCenter, universeImageSize, zoom); + if (isLineVisible(startImagePos, endImagePos, universeImageSize)) { + drawLine(startImagePos, endImagePos, lineColor, imageData, imageSize); } } + } - //draw arrows - if (zoom >= ZoomLevelForArrows) { - auto inputExecutionOrderNumber = cell->inputExecutionOrderNumber; - if (inputExecutionOrderNumber != -1 && inputExecutionOrderNumber != cell->executionOrderNumber) { - for (int i = 0; i < cell->numConnections; ++i) { - auto const& otherCell = cell->connections[i].cell; - if (otherCell->executionOrderNumber == inputExecutionOrderNumber && !otherCell->outputBlocked) { - auto otherCellPos = otherCell->pos; - auto topologyCorrection = map.getCorrectionIncrement(cellPos, otherCellPos); - otherCellPos += topologyCorrection; - - auto const otherCellImagePos = mapWorldPosToImagePos(rectUpperLeft, otherCellPos, universeImageSize, zoom); - if (!isContainedInRect({0, 0}, toFloat2(imageSize), otherCellImagePos)) { - continue; - } - auto const arrowEnd = mapWorldPosToImagePos( - rectUpperLeft, cellPos + Math::normalized(otherCellPos - cellPos) / 4, universeImageSize, zoom); - if (!isContainedInRect({0, 0}, toFloat2(imageSize), arrowEnd)) { - continue; - } - auto direction = Math::normalized(arrowEnd - otherCellImagePos); - { - float2 arrowPartStart = {-direction.x + direction.y, -direction.x - direction.y}; - arrowPartStart = arrowPartStart * zoom / 8 + arrowEnd; - if (isLineVisible(arrowPartStart, arrowEnd, universeImageSize)) { - drawLine(arrowPartStart, arrowEnd, lineColor, imageData, imageSize, 0.5f); - } + //draw arrows + if (zoom >= ZoomLevelForArrows) { + auto inputExecutionOrderNumber = cell->inputExecutionOrderNumber; + if (inputExecutionOrderNumber != -1 && inputExecutionOrderNumber != cell->executionOrderNumber) { + for (int i = 0; i < cell->numConnections; ++i) { + auto const& otherCell = cell->connections[i].cell; + if (otherCell->executionOrderNumber == inputExecutionOrderNumber && !otherCell->outputBlocked) { + auto otherCellPos = otherCell->pos; + auto topologyCorrection = map.getCorrectionIncrement(cellPos, otherCellPos); + otherCellPos += topologyCorrection; + + auto const otherCellImagePos = mapWorldPosToImagePos(rectUpperLeft, otherCellPos, universeImageSize, zoom); + if (!isContainedInRect({0, 0}, toFloat2(imageSize), otherCellImagePos)) { + continue; + } + auto const arrowEnd = + mapWorldPosToImagePos(rectUpperLeft, cellPos + Math::normalized(otherCellPos - cellPos) / 4, universeImageSize, zoom); + if (!isContainedInRect({0, 0}, toFloat2(imageSize), arrowEnd)) { + continue; + } + auto direction = Math::normalized(arrowEnd - otherCellImagePos); + { + float2 arrowPartStart = {-direction.x + direction.y, -direction.x - direction.y}; + arrowPartStart = arrowPartStart * zoom / 8 + arrowEnd; + if (isLineVisible(arrowPartStart, arrowEnd, universeImageSize)) { + drawLine(arrowPartStart, arrowEnd, lineColor, imageData, imageSize, 0.5f); } - { - float2 arrowPartStart = {-direction.x - direction.y, direction.x - direction.y}; - arrowPartStart = arrowPartStart * zoom / 8 + arrowEnd; - if (isLineVisible(arrowPartStart, arrowEnd, universeImageSize)) { - drawLine(arrowPartStart, arrowEnd, lineColor, imageData, imageSize, 0.5f); - } + } + { + float2 arrowPartStart = {-direction.x - direction.y, direction.x - direction.y}; + arrowPartStart = arrowPartStart * zoom / 8 + arrowEnd; + if (isLineVisible(arrowPartStart, arrowEnd, universeImageSize)) { + drawLine(arrowPartStart, arrowEnd, lineColor, imageData, imageSize, 0.5f); } } } @@ -563,11 +610,7 @@ __global__ void cudaDrawCellGlow(int2 worldSize, float2 rectUpperLeft, Arrayselected); - auto radius = zoom / 3; - drawCircle(imageData, imageSize, particleImagePos, color, radius); - } + auto const color = calcColor(particle, 0 != particle->selected); + auto radius = zoom / 3; + drawCircle(imageData, imageSize, particleImagePos, color, radius); } } diff --git a/source/EngineGpuKernels/RenderingKernels.cuh b/source/EngineGpuKernels/RenderingKernels.cuh index 33f1013f8..c01144951 100644 --- a/source/EngineGpuKernels/RenderingKernels.cuh +++ b/source/EngineGpuKernels/RenderingKernels.cuh @@ -15,6 +15,21 @@ #include __global__ void cudaDrawBackground(uint64_t* imageData, int2 imageSize, int2 worldSize, float zoom, float2 rectUpperLeft, float2 rectLowerRight); +__global__ void cudaPrepareFilteringForRendering(Array filteredCells, Array filteredParticles); +__global__ void cudaFilterCellsForRendering( + int2 worldSize, + float2 rectUpperLeft, + Array cells, + Array filteredCells, + int2 imageSize, + float zoom); +__global__ void cudaFilterParticlesForRendering( + int2 worldSize, + float2 rectUpperLeft, + Array particles, + Array filteredParticles, + int2 imageSize, + float zoom); __global__ void cudaDrawCells( uint64_t timestep, int2 worldSize, diff --git a/source/EngineGpuKernels/RenderingKernelsLauncher.cu b/source/EngineGpuKernels/RenderingKernelsLauncher.cu index e0016a550..01f5712cd 100644 --- a/source/EngineGpuKernels/RenderingKernelsLauncher.cu +++ b/source/EngineGpuKernels/RenderingKernelsLauncher.cu @@ -16,12 +16,15 @@ void _RenderingKernelsLauncher::drawImage( auto const& gpuSettings = settings.gpuSettings; KERNEL_CALL(cudaDrawBackground, targetImage, imageSize, data.worldSize, zoom, rectUpperLeft, rectLowerRight); - KERNEL_CALL(cudaDrawCells, data.timestep, data.worldSize, rectUpperLeft, rectLowerRight, data.objects.cellPointers, targetImage, imageSize, zoom); - KERNEL_CALL(cudaDrawParticles, data.worldSize, rectUpperLeft, rectLowerRight, data.objects.particlePointers, targetImage, imageSize, zoom); + KERNEL_CALL_1_1(cudaPrepareFilteringForRendering, data.tempObjects.cellPointers, data.tempObjects.particlePointers); + KERNEL_CALL(cudaFilterCellsForRendering, data.worldSize, rectUpperLeft, data.objects.cellPointers, data.tempObjects.cellPointers, imageSize, zoom); + KERNEL_CALL(cudaFilterParticlesForRendering, data.worldSize, rectUpperLeft, data.objects.particlePointers, data.tempObjects.particlePointers, imageSize, zoom); + KERNEL_CALL(cudaDrawCells, data.timestep, data.worldSize, rectUpperLeft, rectLowerRight, data.tempObjects.cellPointers, targetImage, imageSize, zoom); + KERNEL_CALL(cudaDrawParticles, data.worldSize, rectUpperLeft, rectLowerRight, data.tempObjects.particlePointers, targetImage, imageSize, zoom); KERNEL_CALL_1_1(cudaDrawRadiationSources, targetImage, rectUpperLeft, data.worldSize, imageSize, zoom); if (settings.simulationParameters.features.cellGlow) { - cudaDrawCellGlow<<<512, 128>>>(data.worldSize, rectUpperLeft, data.objects.cellPointers, targetImage, imageSize, zoom); + cudaDrawCellGlow<<<512, 128>>>(data.worldSize, rectUpperLeft, data.tempObjects.cellPointers, targetImage, imageSize, zoom); } if (settings.simulationParameters.borderlessRendering) { diff --git a/source/EngineInterface/AuxiliaryDataParserService.cpp b/source/EngineInterface/AuxiliaryDataParserService.cpp index 577b88aa9..febeceb29 100644 --- a/source/EngineInterface/AuxiliaryDataParserService.cpp +++ b/source/EngineInterface/AuxiliaryDataParserService.cpp @@ -169,38 +169,74 @@ namespace encodeDecodeProperty(tree, parameter, defaultValue, node, task); } - void readLegacyParameter(ColorVector& result, boost::property_tree::ptree& tree, std::string const& node) + void readLegacyParameterForBase(ColorVector& result, boost::property_tree::ptree& tree, std::string const& node) { ColorVector defaultDummy; encodeDecodeProperty(tree, result, defaultDummy, node, ParserTask::Decode); } + void readLegacyParameterForSpot(LegacySpotParameter>& result, boost::property_tree::ptree& tree, std::string const& node) + { + ColorVector defaultDummy; + encodeDecodeSpotProperty(tree, result.parameter, result.active, defaultDummy, node, ParserTask::Decode); + } + + LegacyParametersForBase readLegacyParametersForBase(boost::property_tree::ptree& tree, std::string const& nodeBase) + { + LegacyParametersForBase result; + readLegacyParameterForBase( + result.cellFunctionConstructorMutationNeuronDataProbability, tree, nodeBase + "cell.function.constructor.mutation probability.neuron data"); + readLegacyParameterForBase( + result.cellFunctionConstructorMutationPropertiesProbability, tree, nodeBase + "cell.function.constructor.mutation probability.data"); + readLegacyParameterForBase( + result.cellFunctionConstructorMutationCellFunctionProbability, tree, nodeBase + "cell.function.constructor.mutation probability.cell function"); + readLegacyParameterForBase( + result.cellFunctionConstructorMutationGeometryProbability, tree, nodeBase + "cell.function.constructor.mutation probability.geometry"); + readLegacyParameterForBase( + result.cellFunctionConstructorMutationCustomGeometryProbability, tree, nodeBase + "cell.function.constructor.mutation probability.custom geometry"); + readLegacyParameterForBase( + result.cellFunctionConstructorMutationInsertionProbability, tree, nodeBase + "cell.function.constructor.mutation probability.insertion"); + readLegacyParameterForBase( + result.cellFunctionConstructorMutationDeletionProbability, tree, nodeBase + "cell.function.constructor.mutation probability.deletion"); + readLegacyParameterForBase( + result.cellFunctionConstructorMutationTranslationProbability, tree, nodeBase + "cell.function.constructor.mutation probability.translation"); + readLegacyParameterForBase( + result.cellFunctionConstructorMutationDuplicationProbability, tree, nodeBase + "cell.function.constructor.mutation probability.duplication"); + readLegacyParameterForBase( + result.cellFunctionConstructorMutationCellColorProbability, tree, nodeBase + "cell.function.constructor.mutation probability.cell color"); + readLegacyParameterForBase( + result.cellFunctionConstructorMutationSubgenomeColorProbability, tree, nodeBase + "cell.function.constructor.mutation probability.color"); + readLegacyParameterForBase( + result.cellFunctionConstructorMutationGenomeColorProbability, tree, nodeBase + "cell.function.constructor.mutation probability.uniform color"); + return result; + } + LegacyParametersForSpot readLegacyParametersForSpot(boost::property_tree::ptree& tree, std::string const& nodeBase) { LegacyParametersForSpot result; - readLegacyParameter( + readLegacyParameterForSpot( result.cellFunctionConstructorMutationNeuronDataProbability, tree, nodeBase + "cell.function.constructor.mutation probability.neuron data"); - readLegacyParameter( - result.cellFunctionConstructorMutationPropertiesProbability, tree, nodeBase + "cell.function.constructor.mutation probability.data"); - readLegacyParameter( + readLegacyParameterForSpot( + result.cellFunctionConstructorMutationPropertiesProbability, tree, nodeBase + "cell.function.constructor.mutation probability.data "); + readLegacyParameterForSpot( result.cellFunctionConstructorMutationCellFunctionProbability, tree, nodeBase + "cell.function.constructor.mutation probability.cell function"); - readLegacyParameter( + readLegacyParameterForSpot( result.cellFunctionConstructorMutationGeometryProbability, tree, nodeBase + "cell.function.constructor.mutation probability.geometry"); - readLegacyParameter( + readLegacyParameterForSpot( result.cellFunctionConstructorMutationCustomGeometryProbability, tree, nodeBase + "cell.function.constructor.mutation probability.custom geometry"); - readLegacyParameter( + readLegacyParameterForSpot( result.cellFunctionConstructorMutationInsertionProbability, tree, nodeBase + "cell.function.constructor.mutation probability.insertion"); - readLegacyParameter( + readLegacyParameterForSpot( result.cellFunctionConstructorMutationDeletionProbability, tree, nodeBase + "cell.function.constructor.mutation probability.deletion"); - readLegacyParameter( + readLegacyParameterForSpot( result.cellFunctionConstructorMutationTranslationProbability, tree, nodeBase + "cell.function.constructor.mutation probability.translation"); - readLegacyParameter( + readLegacyParameterForSpot( result.cellFunctionConstructorMutationDuplicationProbability, tree, nodeBase + "cell.function.constructor.mutation probability.duplication"); - readLegacyParameter( + readLegacyParameterForSpot( result.cellFunctionConstructorMutationCellColorProbability, tree, nodeBase + "cell.function.constructor.mutation probability.cell color"); - readLegacyParameter( + readLegacyParameterForSpot( result.cellFunctionConstructorMutationSubgenomeColorProbability, tree, nodeBase + "cell.function.constructor.mutation probability.color"); - readLegacyParameter( + readLegacyParameterForSpot( result.cellFunctionConstructorMutationGenomeColorProbability, tree, nodeBase + "cell.function.constructor.mutation probability.uniform color"); return result; } @@ -214,14 +250,13 @@ namespace LegacySimulationParametersService::activateFeaturesForLegacyFiles(missingFeatures, parameters); LegacyParameters legacyParameters; - legacyParameters.base = readLegacyParametersForSpot(tree, "simulation parameters."); + legacyParameters.base = readLegacyParametersForBase(tree, "simulation parameters."); for (int i = 0; i < parameters.numSpots; ++i) { legacyParameters.spots[i] = readLegacyParametersForSpot(tree, "simulation parameters.spots." + std::to_string(i) + "."); } LegacySimulationParametersService::activateParametersForLegacyFiles(missingParameters, legacyParameters, parameters); } - void encodeDecode( boost::property_tree::ptree& tree, SimulationParameters& parameters, diff --git a/source/EngineInterface/LegacySimulationParametersService.cpp b/source/EngineInterface/LegacySimulationParametersService.cpp index abf62a764..13898b9db 100644 --- a/source/EngineInterface/LegacySimulationParametersService.cpp +++ b/source/EngineInterface/LegacySimulationParametersService.cpp @@ -133,7 +133,7 @@ void LegacySimulationParametersService::activateParametersForLegacyFiles( } if (missingParameters.copyMutations) { - auto setParametersForSpot = [](SimulationParametersSpotValues& target, LegacyParametersForSpot const& source) { + auto setParametersForBase = [](SimulationParametersSpotValues& target, LegacyParametersForBase const& source) { for (int i = 0; i < MAX_COLORS; ++i) { target.cellCopyMutationNeuronData[i] = source.cellFunctionConstructorMutationNeuronDataProbability[i] * 250; target.cellCopyMutationCellProperties[i] = source.cellFunctionConstructorMutationPropertiesProbability[i] * 250; @@ -149,7 +149,24 @@ void LegacySimulationParametersService::activateParametersForLegacyFiles( target.cellCopyMutationGenomeColor[i] = source.cellFunctionConstructorMutationGenomeColorProbability[i] * 5000; } }; - setParametersForSpot(parameters.baseValues, legacyParameters.base); + auto setParametersForSpot = [](SimulationParametersSpotValues& target, LegacyParametersForSpot const& source) { + for (int i = 0; i < MAX_COLORS; ++i) { + target.cellCopyMutationNeuronData[i] = source.cellFunctionConstructorMutationNeuronDataProbability.parameter[i] * 250; + target.cellCopyMutationCellProperties[i] = source.cellFunctionConstructorMutationPropertiesProbability.parameter[i] * 250; + target.cellCopyMutationCellFunction[i] = source.cellFunctionConstructorMutationCellFunctionProbability.parameter[i] * 250; + target.cellCopyMutationGeometry[i] = source.cellFunctionConstructorMutationGeometryProbability.parameter[i] * 250; + target.cellCopyMutationCustomGeometry[i] = source.cellFunctionConstructorMutationCustomGeometryProbability.parameter[i] * 250; + target.cellCopyMutationInsertion[i] = source.cellFunctionConstructorMutationInsertionProbability.parameter[i] * 250; + target.cellCopyMutationDeletion[i] = source.cellFunctionConstructorMutationDeletionProbability.parameter[i] * 250; + target.cellCopyMutationCellColor[i] = source.cellFunctionConstructorMutationCellColorProbability.parameter[i] * 250; + target.cellCopyMutationTranslation[i] = source.cellFunctionConstructorMutationTranslationProbability.parameter[i] * 5000; + target.cellCopyMutationDuplication[i] = source.cellFunctionConstructorMutationDuplicationProbability.parameter[i] * 5000; + target.cellCopyMutationSubgenomeColor[i] = source.cellFunctionConstructorMutationSubgenomeColorProbability.parameter[i] * 5000; + target.cellCopyMutationGenomeColor[i] = source.cellFunctionConstructorMutationGenomeColorProbability.parameter[i] * 5000; + } + }; + + setParametersForBase(parameters.baseValues, legacyParameters.base); for (int i = 0; i < MAX_SPOTS; ++i) { setParametersForSpot(parameters.spots->values, legacyParameters.spots[i]); } diff --git a/source/EngineInterface/LegacySimulationParametersService.h b/source/EngineInterface/LegacySimulationParametersService.h index 26321de54..41dedf21b 100644 --- a/source/EngineInterface/LegacySimulationParametersService.h +++ b/source/EngineInterface/LegacySimulationParametersService.h @@ -10,13 +10,13 @@ struct MissingParameters }; template -struct LegacyParameter +struct LegacySpotParameter { bool active = false; T parameter; }; -struct LegacyParametersForSpot +struct LegacyParametersForBase { ColorVector cellFunctionConstructorMutationNeuronDataProbability; ColorVector cellFunctionConstructorMutationPropertiesProbability; @@ -31,9 +31,26 @@ struct LegacyParametersForSpot ColorVector cellFunctionConstructorMutationSubgenomeColorProbability; ColorVector cellFunctionConstructorMutationGenomeColorProbability; }; + +struct LegacyParametersForSpot +{ + LegacySpotParameter> cellFunctionConstructorMutationNeuronDataProbability; + LegacySpotParameter> cellFunctionConstructorMutationPropertiesProbability; + LegacySpotParameter> cellFunctionConstructorMutationCellFunctionProbability; + LegacySpotParameter> cellFunctionConstructorMutationGeometryProbability; + LegacySpotParameter> cellFunctionConstructorMutationCustomGeometryProbability; + LegacySpotParameter> cellFunctionConstructorMutationInsertionProbability; + LegacySpotParameter> cellFunctionConstructorMutationDeletionProbability; + LegacySpotParameter> cellFunctionConstructorMutationTranslationProbability; + LegacySpotParameter> cellFunctionConstructorMutationDuplicationProbability; + LegacySpotParameter> cellFunctionConstructorMutationCellColorProbability; + LegacySpotParameter> cellFunctionConstructorMutationSubgenomeColorProbability; + LegacySpotParameter> cellFunctionConstructorMutationGenomeColorProbability; +}; + struct LegacyParameters { - LegacyParametersForSpot base; + LegacyParametersForBase base; LegacyParametersForSpot spots[MAX_SPOTS]; };