From 25ae2ab183f592b6da32d5bb2aaeef096fea0e6f Mon Sep 17 00:00:00 2001 From: Christian Heinemann Date: Mon, 11 Nov 2024 21:09:06 +0100 Subject: [PATCH] make cellDeathProbability spot-dependent --- source/EngineGpuKernels/CellProcessor.cuh | 8 +++++++- source/EngineInterface/SimulationParameters.cpp | 3 --- source/EngineInterface/SimulationParameters.h | 1 - .../SimulationParametersSpotActivatedValues.h | 5 +++-- .../SimulationParametersSpotValues.h | 5 +++++ source/EngineTests/CellConnectionTests.cpp | 2 +- source/Gui/SimulationParametersWindow.cpp | 16 ++++++++++++++-- .../AuxiliaryDataParserService.cpp | 13 ++++++++++++- .../LegacyAuxiliaryDataParserService.cpp | 4 ++-- 9 files changed, 44 insertions(+), 13 deletions(-) diff --git a/source/EngineGpuKernels/CellProcessor.cuh b/source/EngineGpuKernels/CellProcessor.cuh index a43fdc16b..007efcd91 100644 --- a/source/EngineGpuKernels/CellProcessor.cuh +++ b/source/EngineGpuKernels/CellProcessor.cuh @@ -766,7 +766,13 @@ __inline__ __device__ void CellProcessor::decay(SimulationData& data) &SimulationParametersSpotValues::cellMinEnergy, &SimulationParametersSpotActivatedValues::cellMinEnergy, data, cell->pos, cell->color); if (cell->livingState == LivingState_Dying || cell->livingState == LivingState_Detaching) { - if (data.numberGen1.random() < cudaSimulationParameters.cellDeathProbability[cell->color]) { + auto cellDeathProbability = SpotCalculator::calcParameter( + &SimulationParametersSpotValues::cellDeathProbability, + &SimulationParametersSpotActivatedValues::cellDeathProbability, + data, + cell->pos, + cell->color); + if (data.numberGen1.random() < cellDeathProbability) { CellConnectionProcessor::scheduleDeleteCell(data, index); } } diff --git a/source/EngineInterface/SimulationParameters.cpp b/source/EngineInterface/SimulationParameters.cpp index 7d489a578..297311a4f 100644 --- a/source/EngineInterface/SimulationParameters.cpp +++ b/source/EngineInterface/SimulationParameters.cpp @@ -110,9 +110,6 @@ bool SimulationParameters::operator==(SimulationParameters const& other) const if (cellFunctionConstructorConnectingCellMaxDistance[i] != other.cellFunctionConstructorConnectingCellMaxDistance[i]) { return false; } - if (cellDeathProbability[i] != other.cellDeathProbability[i]) { - return false; - } if (cellNormalEnergy[i] != other.cellNormalEnergy[i]) { return false; } diff --git a/source/EngineInterface/SimulationParameters.h b/source/EngineInterface/SimulationParameters.h index 06150310e..3c7b2eb64 100644 --- a/source/EngineInterface/SimulationParameters.h +++ b/source/EngineInterface/SimulationParameters.h @@ -104,7 +104,6 @@ struct SimulationParameters ColorVector highRadiationFactor = {0, 0, 0, 0, 0, 0, 0}; ColorVector highRadiationMinCellEnergy = {500.0f, 500.0f, 500.0f, 500.0f, 500.0f, 500.0f, 500.0f}; CellDeathConsquences cellDeathConsequences = CellDeathConsquences_DetachedPartsDie; - ColorVector cellDeathProbability = {0.001f, 0.001f, 0.001f, 0.001f, 0.001f, 0.001f, 0.001f}; ColorVector cellMaxAge = { Infinity::value, Infinity::value, diff --git a/source/EngineInterface/SimulationParametersSpotActivatedValues.h b/source/EngineInterface/SimulationParametersSpotActivatedValues.h index 819287a17..1c8d2daf0 100644 --- a/source/EngineInterface/SimulationParametersSpotActivatedValues.h +++ b/source/EngineInterface/SimulationParametersSpotActivatedValues.h @@ -13,6 +13,7 @@ struct SimulationParametersSpotActivatedValues bool radiationDisableSources = false; bool cellMaxForce = false; bool cellMinEnergy = false; + bool cellDeathProbability = false; bool cellFusionVelocity = false; bool cellMaxBindingEnergy = false; bool cellInactiveMaxAge = false; @@ -63,8 +64,8 @@ struct SimulationParametersSpotActivatedValues && cellFunctionAttackerGenomeComplexityBonus == other.cellFunctionAttackerGenomeComplexityBonus && radiationAbsorptionLowVelocityPenalty == other.radiationAbsorptionLowVelocityPenalty && cellFunctionAttackerNewComplexMutantPenalty == other.cellFunctionAttackerNewComplexMutantPenalty - && cellInactiveMaxAge == other.cellInactiveMaxAge - && radiationDisableSources == other.radiationDisableSources + && cellInactiveMaxAge == other.cellInactiveMaxAge && radiationDisableSources == other.radiationDisableSources + && cellDeathProbability == other.cellDeathProbability ; } }; diff --git a/source/EngineInterface/SimulationParametersSpotValues.h b/source/EngineInterface/SimulationParametersSpotValues.h index 76866e25a..b430531d0 100644 --- a/source/EngineInterface/SimulationParametersSpotValues.h +++ b/source/EngineInterface/SimulationParametersSpotValues.h @@ -18,6 +18,8 @@ struct SimulationParametersSpotValues bool radiationDisableSources = false; ColorVector cellMaxForce = {0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f, 0.8f}; ColorVector cellMinEnergy = {50.0f, 50.0f, 50.0f, 50.0f, 50.0f, 50.0f, 50.0f}; + ColorVector cellDeathProbability = {0.001f, 0.001f, 0.001f, 0.001f, 0.001f, 0.001f, 0.001f}; + float cellFusionVelocity = 0.6f; float cellMaxBindingEnergy = Infinity::value; ColorVector cellInactiveMaxAge = { @@ -95,6 +97,9 @@ struct SimulationParametersSpotValues } } for (int i = 0; i < MAX_COLORS; ++i) { + if (cellDeathProbability[i] != other.cellDeathProbability[i]) { + return false; + } if (cellMaxForce[i] != other.cellMaxForce[i]) { return false; } diff --git a/source/EngineTests/CellConnectionTests.cpp b/source/EngineTests/CellConnectionTests.cpp index 5898b367a..db2fcd250 100644 --- a/source/EngineTests/CellConnectionTests.cpp +++ b/source/EngineTests/CellConnectionTests.cpp @@ -20,7 +20,7 @@ TEST_F(CellConnectionTests, decay) { _parameters.baseValues.radiationAbsorption[0] = 0; _parameters.cellDeathConsequences = CellDeathConsquences_CreatureDies; - _parameters.cellDeathProbability[0] = 0.5f; + _parameters.baseValues.cellDeathProbability[0] = 0.5f; _simulationFacade->setSimulationParameters(_parameters); auto origData = diff --git a/source/Gui/SimulationParametersWindow.cpp b/source/Gui/SimulationParametersWindow.cpp index 6358b7f1d..6a4ea12c7 100644 --- a/source/Gui/SimulationParametersWindow.cpp +++ b/source/Gui/SimulationParametersWindow.cpp @@ -659,12 +659,12 @@ void SimulationParametersWindow::processBase() .max(0.1f) .format("%.6f") .logarithmic(true) - .defaultValue(origParameters.cellDeathProbability) + .defaultValue(origParameters.baseValues.cellDeathProbability) .tooltip("The probability per time step with which a cell will disintegrate (i.e. transform into an energy particle) when it is in the " "state 'Dying'. This can occur when one of the following conditions is satisfied:\n\n" ICON_FA_CHEVRON_RIGHT " The cell has too low energy.\n\n" ICON_FA_CHEVRON_RIGHT " The cell has exceeded its maximum age."), - parameters.cellDeathProbability); + parameters.baseValues.cellDeathProbability); AlienImGui::Switcher( AlienImGui::SwitcherParameters() .name("Cell death consequences") @@ -1969,6 +1969,18 @@ bool SimulationParametersWindow::processSpot(int index) .disabledValue(parameters.baseValues.cellMinEnergy), spot.values.cellMinEnergy, &spot.activatedValues.cellMinEnergy); + AlienImGui::SliderFloat( + AlienImGui::SliderFloatParameters() + .name("Decay rate of dying cells") + .colorDependence(true) + .textWidth(RightColumnWidth) + .min(1e-6f) + .max(0.1f) + .format("%.6f") + .logarithmic(true) + .defaultValue(origSpot.values.cellDeathProbability).disabledValue(parameters.baseValues.cellDeathProbability), + spot.values.cellDeathProbability, + &spot.activatedValues.cellDeathProbability); AlienImGui::EndTreeNode(); } diff --git a/source/PersisterInterface/AuxiliaryDataParserService.cpp b/source/PersisterInterface/AuxiliaryDataParserService.cpp index 04d2ce496..125209dc4 100644 --- a/source/PersisterInterface/AuxiliaryDataParserService.cpp +++ b/source/PersisterInterface/AuxiliaryDataParserService.cpp @@ -301,7 +301,11 @@ namespace missingParameters.cellDeathConsequences = ParameterParser::encodeDecode( tree, parameters.cellDeathConsequences, defaultParameters.cellDeathConsequences, "simulation parameters.cell.death consequences", parserTask); ParameterParser::encodeDecode( - tree, parameters.cellDeathProbability, defaultParameters.cellDeathProbability, "simulation parameters.cell.death probability", parserTask); + tree, + parameters.baseValues.cellDeathProbability, + defaultParameters.baseValues.cellDeathProbability, + "simulation parameters.cell.death probability", + parserTask); ParameterParser::encodeDecode( tree, @@ -789,6 +793,13 @@ namespace tree, spot.values.cellMaxForce, spot.activatedValues.cellMaxForce, defaultSpot.values.cellMaxForce, base + "cell.max force", parserTask); ParameterParser::encodeDecodeWithEnabled( tree, spot.values.cellMinEnergy, spot.activatedValues.cellMinEnergy, defaultSpot.values.cellMinEnergy, base + "cell.min energy", parserTask); + ParameterParser::encodeDecodeWithEnabled( + tree, + spot.values.cellDeathProbability, + spot.activatedValues.cellDeathProbability, + defaultSpot.values.cellDeathProbability, + base + "cell.death probability", + parserTask); ParameterParser::encodeDecodeWithEnabled( tree, diff --git a/source/PersisterInterface/LegacyAuxiliaryDataParserService.cpp b/source/PersisterInterface/LegacyAuxiliaryDataParserService.cpp index 57e9ee1bd..f4b896e98 100644 --- a/source/PersisterInterface/LegacyAuxiliaryDataParserService.cpp +++ b/source/PersisterInterface/LegacyAuxiliaryDataParserService.cpp @@ -300,11 +300,11 @@ void LegacyAuxiliaryDataParserService::activateParametersAndFeaturesForLegacyFil parameters.cellDeathConsequences = legacyParameters.base.clusterDecay.parameter ? CellDeathConsquences_CreatureDies : CellDeathConsquences_None; if (parameters.cellDeathConsequences == CellDeathConsquences_None) { for (int i = 0; i < MAX_COLORS; ++i) { - parameters.cellDeathProbability[i] = 0.01f; + parameters.baseValues.cellDeathProbability[i] = 0.01f; } } else { for (int i = 0; i < MAX_COLORS; ++i) { - parameters.cellDeathProbability[i] = legacyParameters.base.clusterDecayProb.parameter[i]; + parameters.baseValues.cellDeathProbability[i] = legacyParameters.base.clusterDecayProb.parameter[i]; } } }