From 1cba665ba383def62eb80718b981dc569a14aec3 Mon Sep 17 00:00:00 2001 From: Christian Heinemann Date: Sat, 31 Aug 2024 23:12:00 +0200 Subject: [PATCH 1/2] parameter 'Movement toward target' introduced + RELEASE-NOTES.md corrected --- RELEASE-NOTES.md | 4 +- source/EngineGpuKernels/MuscleProcessor.cuh | 19 ++++--- source/EngineGpuKernels/SensorProcessor.cuh | 3 +- .../AuxiliaryDataParserService.cpp | 15 ++++-- .../LegacyAuxiliaryDataParserService.cpp | 10 ++-- .../EngineInterface/SimulationParameters.cpp | 4 +- source/EngineInterface/SimulationParameters.h | 4 +- source/EngineTests/MuscleTests.cpp | 9 ++-- source/EngineTests/SensorTests.cpp | 12 ++--- source/Gui/SimulationParametersWindow.cpp | 49 ++++++++++--------- 10 files changed, 64 insertions(+), 65 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 359bab515..9b079b18e 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -3,14 +3,14 @@ ## [4.10.2] - 2024-08-31 ### Added - engine, gui/simulation parameters: number of neurons can be taken into account for the genome complexity calculation -- engine, gui/simulation parameters: add-on 'Legacy features' containing parameter for older muscle movement modes +- engine, gui/simulation parameters: add-on 'Legacy features' containing parameter for older muscle movement mode ### Changed - engine: cell property mutations prefer to set fitting input execution numbers (leads in better communicating cell networks) - engine: muscle cells in movement mode will only move if they receive signals which originate from sensors that have targeted an object ### Deleted -- gui/simulation parameters: add-on 'Advanced muscle control' (incorporated in add-on 'Legacy features') +- gui/simulation parameters: add-on 'Advanced muscle control' ### Fixed - gui: prevent exception in case of too small window size diff --git a/source/EngineGpuKernels/MuscleProcessor.cuh b/source/EngineGpuKernels/MuscleProcessor.cuh index 89ff93635..30d19e740 100644 --- a/source/EngineGpuKernels/MuscleProcessor.cuh +++ b/source/EngineGpuKernels/MuscleProcessor.cuh @@ -91,12 +91,8 @@ __device__ __inline__ void MuscleProcessor::movement(SimulationData& data, Simul auto direction = float2{0, 0}; auto acceleration = 0.0f; - if (cudaSimulationParameters.features.legacyModes && cudaSimulationParameters.legacyCellFunctionMuscleMovementModeActivated) { - if (cudaSimulationParameters.legacyCellFunctionMuscleMovementMode == 0) { - direction = CellFunctionProcessor::calcSignalDirection(data, cell); - acceleration = cudaSimulationParameters.cellFunctionMuscleMovementAcceleration[cell->color]; - } - if (cudaSimulationParameters.legacyCellFunctionMuscleMovementMode == 1) { + if (cudaSimulationParameters.cellFunctionMuscleMovementTowardTargetedObject) { + if (cudaSimulationParameters.features.legacyModes && cudaSimulationParameters.legacyCellFunctionMuscleMovementAngleFromSensor) { if (auto sensorCell = findNearbySensor(cell)) { auto const& sensorData = sensorCell->cellFunctionData.sensor; if (sensorData.targetX != 0 || sensorData.targetY != 0) { @@ -104,12 +100,15 @@ __device__ __inline__ void MuscleProcessor::movement(SimulationData& data, Simul acceleration = cudaSimulationParameters.cellFunctionMuscleMovementAcceleration[cell->color]; } } + } else { + if (activity.origin == ActivityOrigin_Sensor && (activity.targetX != 0 || activity.targetY != 0)) { + direction = {activity.targetX, activity.targetY}; + acceleration = cudaSimulationParameters.cellFunctionMuscleMovementAcceleration[cell->color]; + } } } else { - if (activity.origin == ActivityOrigin_Sensor && (activity.targetX != 0 || activity.targetY != 0)) { - direction = {activity.targetX, activity.targetY}; - acceleration = cudaSimulationParameters.cellFunctionMuscleMovementAcceleration[cell->color]; - } + direction = CellFunctionProcessor::calcSignalDirection(data, cell); + acceleration = cudaSimulationParameters.cellFunctionMuscleMovementAcceleration[cell->color]; } float angle = max(-0.5f, min(0.5f, activity.channels[3])) * 360.0f; direction = Math::rotateClockwise(direction, angle); diff --git a/source/EngineGpuKernels/SensorProcessor.cuh b/source/EngineGpuKernels/SensorProcessor.cuh index 47cb07954..ce91de3fa 100644 --- a/source/EngineGpuKernels/SensorProcessor.cuh +++ b/source/EngineGpuKernels/SensorProcessor.cuh @@ -196,8 +196,7 @@ SensorProcessor::searchNeighborhood(SimulationData& data, SimulationStatistics& activity.channels[1] = toFloat((lookupResult >> 40) & 0xff) / 256; //density activity.channels[2] = 1.0f - min(1.0f, distance / 256); //distance: 1 = close, 0 = far away - auto legacyMode_unrestrictedMovements = cudaSimulationParameters.features.legacyModes && cudaSimulationParameters.legacyCellFunctionMuscleMovementModeActivated - && cudaSimulationParameters.legacyCellFunctionMuscleMovementMode == 0; + auto legacyMode_unrestrictedMovements = !cudaSimulationParameters.cellFunctionMuscleMovementTowardTargetedObject; activity.channels[3] = legacyMode_unrestrictedMovements ? angle / 360.0f : 0; //angle: between -0.5 and 0.5 cell->cellFunctionData.sensor.memoryChannel1 = activity.channels[1]; cell->cellFunctionData.sensor.memoryChannel2 = activity.channels[2]; diff --git a/source/EngineInterface/AuxiliaryDataParserService.cpp b/source/EngineInterface/AuxiliaryDataParserService.cpp index ef1072252..22e20ef47 100644 --- a/source/EngineInterface/AuxiliaryDataParserService.cpp +++ b/source/EngineInterface/AuxiliaryDataParserService.cpp @@ -565,12 +565,17 @@ namespace defaultParameters.cellFunctionMuscleBendingAccelerationThreshold, "simulation parameters.cell.function.muscle.bending acceleration threshold", parserTask); - PropertyParser::encodeDecodeWithEnabled( + PropertyParser::encodeDecode( + tree, + parameters.cellFunctionMuscleMovementTowardTargetedObject, + defaultParameters.cellFunctionMuscleMovementTowardTargetedObject, + "simulation parameters.cell.function.muscle.movement toward targeted object", + parserTask); + PropertyParser::encodeDecode( tree, - parameters.legacyCellFunctionMuscleMovementMode, - parameters.legacyCellFunctionMuscleMovementModeActivated, - defaultParameters.legacyCellFunctionMuscleMovementMode, - "simulation parameters.legacy.cell.function.muscle.movement mode", + parameters.legacyCellFunctionMuscleMovementAngleFromSensor, + defaultParameters.legacyCellFunctionMuscleMovementAngleFromSensor, + "simulation parameters.legacy.cell.function.muscle.movement angle from sensor", parserTask); PropertyParser::encodeDecode( diff --git a/source/EngineInterface/LegacyAuxiliaryDataParserService.cpp b/source/EngineInterface/LegacyAuxiliaryDataParserService.cpp index 2b9e46a04..539378f48 100644 --- a/source/EngineInterface/LegacyAuxiliaryDataParserService.cpp +++ b/source/EngineInterface/LegacyAuxiliaryDataParserService.cpp @@ -167,17 +167,15 @@ void LegacyAuxiliaryDataParserService::activateParametersAndFeaturesForLegacyFil { //check activation of legacyCellFunctionMuscleMovementAngleFromChannel before v4.10.0 if (missingFeatures.legacyMode && !legacyFeatures.advancedMuscleControl.existent) { - parameters.features.legacyModes = true; - parameters.legacyCellFunctionMuscleMovementModeActivated = true; - parameters.legacyCellFunctionMuscleMovementMode = 0; + parameters.cellFunctionMuscleMovementTowardTargetedObject = false; } //check activation of legacyCellFunctionMuscleMovementAngleFromChannel between v4.10.0 and v4.10.1 if (legacyFeatures.advancedMuscleControl.existent && legacyParameters.base.cellFunctionMuscleMovementAngleFromSensor.existent) { parameters.features.legacyModes = true; - parameters.legacyCellFunctionMuscleMovementModeActivated = true; - parameters.legacyCellFunctionMuscleMovementMode = - legacyFeatures.advancedMuscleControl.parameter && legacyParameters.base.cellFunctionMuscleMovementAngleFromSensor.parameter ? 1 : 0; + parameters.cellFunctionMuscleMovementTowardTargetedObject = + legacyFeatures.advancedMuscleControl.parameter && legacyParameters.base.cellFunctionMuscleMovementAngleFromSensor.parameter; + parameters.legacyCellFunctionMuscleMovementAngleFromSensor = true; } //check activation of other features diff --git a/source/EngineInterface/SimulationParameters.cpp b/source/EngineInterface/SimulationParameters.cpp index bbc5652dc..7dbd6be94 100644 --- a/source/EngineInterface/SimulationParameters.cpp +++ b/source/EngineInterface/SimulationParameters.cpp @@ -200,7 +200,7 @@ bool SimulationParameters::operator==(SimulationParameters const& other) const && cellGlowStrength == other.cellGlowStrength && cellGlowRadius == other.cellGlowRadius && cellResetAgeAfterActivation == other.cellResetAgeAfterActivation && cellRadius == other.cellRadius && cellEmergentMaxAgeActivated == other.cellEmergentMaxAgeActivated - && legacyCellFunctionMuscleMovementModeActivated == other.legacyCellFunctionMuscleMovementModeActivated - && legacyCellFunctionMuscleMovementMode == other.legacyCellFunctionMuscleMovementMode + && cellFunctionMuscleMovementTowardTargetedObject == other.cellFunctionMuscleMovementTowardTargetedObject + && legacyCellFunctionMuscleMovementAngleFromSensor == other.legacyCellFunctionMuscleMovementAngleFromSensor ; } \ No newline at end of file diff --git a/source/EngineInterface/SimulationParameters.h b/source/EngineInterface/SimulationParameters.h index be2f8fd0c..728add92b 100644 --- a/source/EngineInterface/SimulationParameters.h +++ b/source/EngineInterface/SimulationParameters.h @@ -181,8 +181,8 @@ struct SimulationParameters ColorVector cellFunctionMuscleBendingAngle = {5.0f, 5.0f, 5.0f, 5.0f, 5.0f, 5.0f, 5.0f}; ColorVector cellFunctionMuscleBendingAcceleration = {0.15f, 0.15f, 0.15f, 0.15f, 0.15f, 0.15f, 0.15f}; float cellFunctionMuscleBendingAccelerationThreshold = 0.1f; - bool legacyCellFunctionMuscleMovementModeActivated = false; - int legacyCellFunctionMuscleMovementMode = 0; //0 = unrestricted, 1 = get angle from sensor + bool cellFunctionMuscleMovementTowardTargetedObject = true; + bool legacyCellFunctionMuscleMovementAngleFromSensor = false; ColorVector cellFunctionSensorRange = {255.0f, 255.0f, 255.0f, 255.0f, 255.0f, 255.0f, 255.0f}; float cellFunctionSensorActivityThreshold = 0.1f; diff --git a/source/EngineTests/MuscleTests.cpp b/source/EngineTests/MuscleTests.cpp index c05ae4a81..0fb0cdbcc 100644 --- a/source/EngineTests/MuscleTests.cpp +++ b/source/EngineTests/MuscleTests.cpp @@ -66,8 +66,7 @@ TEST_F(MuscleTests, doNothing) TEST_F(MuscleTests, moveForward) { - _parameters.features.legacyModes = true; - _parameters.legacyCellFunctionMuscleMovementModeActivated = true; + _parameters.cellFunctionMuscleMovementTowardTargetedObject = false; _simController->setSimulationParameters(_parameters); DataDescription data; @@ -106,8 +105,7 @@ TEST_F(MuscleTests, moveForward) TEST_F(MuscleTests, moveBackward) { - _parameters.features.legacyModes = true; - _parameters.legacyCellFunctionMuscleMovementModeActivated = true; + _parameters.cellFunctionMuscleMovementTowardTargetedObject = false; _simController->setSimulationParameters(_parameters); DataDescription data; @@ -145,8 +143,7 @@ TEST_F(MuscleTests, moveBackward) TEST_F(MuscleTests, multipleMovementDirections) { - _parameters.features.legacyModes = true; - _parameters.legacyCellFunctionMuscleMovementModeActivated = true; + _parameters.cellFunctionMuscleMovementTowardTargetedObject = false; _simController->setSimulationParameters(_parameters); DataDescription data; diff --git a/source/EngineTests/SensorTests.cpp b/source/EngineTests/SensorTests.cpp index a2cd071f5..75a3a57f1 100644 --- a/source/EngineTests/SensorTests.cpp +++ b/source/EngineTests/SensorTests.cpp @@ -184,8 +184,7 @@ TEST_F(SensorTests, scanNeighborhood_foundAtFront) TEST_F(SensorTests, scanNeighborhood_foundAtRightHandSide) { - _parameters.features.legacyModes = true; - _parameters.legacyCellFunctionMuscleMovementModeActivated = true; + _parameters.cellFunctionMuscleMovementTowardTargetedObject = false; _simController->setSimulationParameters(_parameters); DataDescription data; @@ -224,8 +223,7 @@ TEST_F(SensorTests, scanNeighborhood_foundAtRightHandSide) TEST_F(SensorTests, scanNeighborhood_foundAtLeftHandSide) { - _parameters.features.legacyModes = true; - _parameters.legacyCellFunctionMuscleMovementModeActivated = true; + _parameters.cellFunctionMuscleMovementTowardTargetedObject = false; _simController->setSimulationParameters(_parameters); DataDescription data; @@ -264,8 +262,7 @@ TEST_F(SensorTests, scanNeighborhood_foundAtLeftHandSide) TEST_F(SensorTests, scanNeighborhood_foundAtBack) { - _parameters.features.legacyModes = true; - _parameters.legacyCellFunctionMuscleMovementModeActivated = true; + _parameters.cellFunctionMuscleMovementTowardTargetedObject = false; _simController->setSimulationParameters(_parameters); DataDescription data; @@ -304,8 +301,7 @@ TEST_F(SensorTests, scanNeighborhood_foundAtBack) TEST_F(SensorTests, scanNeighborhood_twoMasses) { - _parameters.features.legacyModes = true; - _parameters.legacyCellFunctionMuscleMovementModeActivated = true; + _parameters.cellFunctionMuscleMovementTowardTargetedObject = false; _simController->setSimulationParameters(_parameters); DataDescription data; diff --git a/source/Gui/SimulationParametersWindow.cpp b/source/Gui/SimulationParametersWindow.cpp index 262ff4a95..f82500e83 100644 --- a/source/Gui/SimulationParametersWindow.cpp +++ b/source/Gui/SimulationParametersWindow.cpp @@ -998,20 +998,17 @@ void _SimulationParametersWindow::processBase() * Muscle */ if (AlienImGui::BeginTreeNode(AlienImGui::TreeNodeParameters().text("Cell function: Muscle"))) { - AlienImGui::SliderFloat( - AlienImGui::SliderFloatParameters() - .name("Contraction and expansion delta") + AlienImGui::Checkbox( + AlienImGui::CheckboxParameters() + .name("Movement toward target") .textWidth(RightColumnWidth) - .colorDependence(true) - .min(0) - .max(0.1f) - .defaultValue(origParameters.cellFunctionMuscleContractionExpansionDelta) - .tooltip("The maximum length that a muscle cell can shorten or lengthen a cell connection. This parameter applies only to muscle cells " - "which are in contraction/expansion mode."), - parameters.cellFunctionMuscleContractionExpansionDelta); + .defaultValue(origParameters.cellFunctionMuscleMovementTowardTargetedObject) + .tooltip("If activated, a muscle cell in movement mode will only move if the triggering signal originates from a sensor cell that has " + "targeted an object. The specified angle in the input is interpreted relative to the target."), + parameters.cellFunctionMuscleMovementTowardTargetedObject); AlienImGui::SliderFloat( AlienImGui::SliderFloatParameters() - .name("Forward/backward acceleration") + .name("Movement acceleration") .textWidth(RightColumnWidth) .colorDependence(true) .min(0) @@ -1021,6 +1018,17 @@ void _SimulationParametersWindow::processBase() .tooltip("The maximum value by which a muscle cell can modify its velocity during activation. This parameter applies only to muscle cells " "which are in movement mode."), parameters.cellFunctionMuscleMovementAcceleration); + AlienImGui::SliderFloat( + AlienImGui::SliderFloatParameters() + .name("Contraction and expansion delta") + .textWidth(RightColumnWidth) + .colorDependence(true) + .min(0) + .max(0.1f) + .defaultValue(origParameters.cellFunctionMuscleContractionExpansionDelta) + .tooltip("The maximum length that a muscle cell can shorten or lengthen a cell connection. This parameter applies only to muscle cells " + "which are in contraction/expansion mode."), + parameters.cellFunctionMuscleContractionExpansionDelta); AlienImGui::SliderFloat( AlienImGui::SliderFloatParameters() .name("Bending angle") @@ -1556,18 +1564,15 @@ void _SimulationParametersWindow::processBase() */ if (parameters.features.legacyModes) { if (AlienImGui::BeginTreeNode(AlienImGui::TreeNodeParameters().text("Addon: Legacy features"))) { - AlienImGui::Switcher( - AlienImGui::SwitcherParameters() - .name("Muscle movement modes") + AlienImGui::Checkbox( + AlienImGui::CheckboxParameters() + .name("Fetch angle from adjacent sensor") .textWidth(RightColumnWidth) - .defaultValue(origParameters.legacyCellFunctionMuscleMovementMode) - .values({"Unrestricted", "Fetch angle from sensor"}) - .tooltip(ICON_FA_CHEVRON_RIGHT " Unrestricted: Muscle cells can move in all directions when set in 'Movement' mode. The relative " - "angle is provided in channel #3.\n\n" ICON_FA_CHEVRON_RIGHT - " Fetch angle from sensor: Muscle cells can move only if an adjacent sensor cell has previously " - "detected a target. The relative angle in relation to the target is provided in channel #3."), - parameters.legacyCellFunctionMuscleMovementMode, - ¶meters.legacyCellFunctionMuscleMovementModeActivated); + .defaultValue(origParameters.legacyCellFunctionMuscleMovementAngleFromSensor) + .tooltip("This parameter changes the behavior of the parameter 'Movement angle from sensor'. If activated, the fetches the angle " + "directly from an connected (or connected-connected) sensor cell has previously detected a target (legacy behavior). If " + "deactivated, the signal must only originate from a sensor cell and must not be adjacent (new behavior)."), + parameters.legacyCellFunctionMuscleMovementAngleFromSensor); AlienImGui::EndTreeNode(); } } From ba738084d548a17f55ce6a22c117dc9b3f82088d Mon Sep 17 00:00:00 2001 From: Christian Heinemann Date: Sat, 31 Aug 2024 23:34:43 +0200 Subject: [PATCH 2/2] tooltips corrected --- source/Gui/HelpStrings.h | 12 +++++++----- source/Gui/SimulationParametersWindow.cpp | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/source/Gui/HelpStrings.h b/source/Gui/HelpStrings.h index a67e4c0e0..4f1e1e7aa 100644 --- a/source/Gui/HelpStrings.h +++ b/source/Gui/HelpStrings.h @@ -73,9 +73,10 @@ namespace Const "#0: The strength of the movement, bending or expansion/contraction. A negative sign corresponds to the opposite " "action.\n\n" ICON_FA_CHEVRON_RIGHT " Input channel #1: This channel is solely utilized for acceleration due to bending. If the sign of channel #1 " "differs from the sign of channel #0, no acceleration will be obtained during the bending process.\n\n " ICON_FA_CHEVRON_RIGHT - " Input channel #3: This channel is used for muscles in movement mode. It contains the relative angle of the movement with respect to a " - "detected object. The object must have been targeted from a sensor cell from which the input signal originates (it does not have to be an adjacent cell). A value of -0.5 " - "correspond to -180 deg and +0.5 to +180 deg."; + " Input channel #3: This channel is used for muscles in movement mode. It encodes the relative angle for the movement with respect to a " + "detected object (if the parameter 'Movement toward target' is activated) or to the direction of the adjacent cell where the input signal comes from " + "(if the parameter 'Movement toward target' is deactivated). In the first case, the object must have been targeted by a sensor cell from which the " + "input signal originates (it does not have to be an adjacent cell). A value of -0.5 correspond to -180 deg and +0.5 to +180 deg."; std::string const DefenderTooltip = "A defender cell does not need to be activated. Its presence reduces the strength of an enemy attack involving attacker " @@ -454,8 +455,9 @@ namespace Const "during the bending process.", "The following cell functions obtain their input from channel #2:\n\n" ICON_FA_CHEVRON_RIGHT " Neuron", "The following cell functions obtain their input from channel #3:\n\n" ICON_FA_CHEVRON_RIGHT " Neuron\n\n" ICON_FA_CHEVRON_RIGHT - " Muscle: This channel is used for muscles in movement mode. It allows to determine the relative angle of the movement with respect to a previously " - "detected target from a sensor cell. A value of -0.5 correspond to -180 deg and +0.5 to +180 deg.", + " Muscle: This channel is used for muscles in movement mode. It encodes the relative angle for the movement with respect to a previously " + "detected target by a sensor cell (if the parameter 'Movement toward target' is activated) or to the direction of the adjacent cell where the input " + "signal comes from (if the parameter 'Movement toward target' is deactivated). A value of -0.5 correspond to -180 deg and +0.5 to +180 deg.", "The following cell functions obtain their input from channel #4:\n\n" ICON_FA_CHEVRON_RIGHT " Neuron", "The following cell functions obtain their input from channel #5:\n\n" ICON_FA_CHEVRON_RIGHT " Neuron", "The following cell functions obtain their input from channel #6:\n\n" ICON_FA_CHEVRON_RIGHT " Neuron", diff --git a/source/Gui/SimulationParametersWindow.cpp b/source/Gui/SimulationParametersWindow.cpp index f82500e83..5a0717e8c 100644 --- a/source/Gui/SimulationParametersWindow.cpp +++ b/source/Gui/SimulationParametersWindow.cpp @@ -1569,9 +1569,9 @@ void _SimulationParametersWindow::processBase() .name("Fetch angle from adjacent sensor") .textWidth(RightColumnWidth) .defaultValue(origParameters.legacyCellFunctionMuscleMovementAngleFromSensor) - .tooltip("This parameter changes the behavior of the parameter 'Movement angle from sensor'. If activated, the fetches the angle " - "directly from an connected (or connected-connected) sensor cell has previously detected a target (legacy behavior). If " - "deactivated, the signal must only originate from a sensor cell and must not be adjacent (new behavior)."), + .tooltip("This parameter changes the behavior of the parameter 'Movement toward target'. If activated, the muscle cell fetches the " + "movement angle directly from a connected (or connected-connected) sensor cell that has previously detected a target " + "(legacy behavior). If deactivated, the input signal must only originate from a sensor cell and must not be adjacent (new behavior)."), parameters.legacyCellFunctionMuscleMovementAngleFromSensor); AlienImGui::EndTreeNode(); }