diff --git a/source/EngineGpuKernels/AttackerProcessor.cuh b/source/EngineGpuKernels/AttackerProcessor.cuh index b787e798f..dea82fc30 100644 --- a/source/EngineGpuKernels/AttackerProcessor.cuh +++ b/source/EngineGpuKernels/AttackerProcessor.cuh @@ -59,15 +59,33 @@ __device__ __inline__ void AttackerProcessor::processCell(SimulationData& data, if (cell->creatureId == 0 && CellConnectionProcessor::isConnectedConnected(cell, otherCell)) { return; } - if (otherCell->barrier /*&& otherCell->livingState != LivingState_UnderConstruction*/) { + if (otherCell->barrier) { return; } + //if (otherCell->livingState == LivingState_UnderConstruction) { + // return; + //} auto energyToTransfer = (atomicAdd(&otherCell->energy, 0) - baseValue) * cudaSimulationParameters.cellFunctionAttackerStrength[cell->color]; if (energyToTransfer < 0) { return; } + if (otherCell->livingState == LivingState_UnderConstruction) { + for (int i = 0; i < otherCell->numConnections; ++i) { + auto connectedCell = otherCell->connections[i].cell; + if (connectedCell->creatureId != 0 && connectedCell->creatureId == cell->creatureId) { + return; + } + for (int j = 0; j < connectedCell->numConnections; ++j) { + auto otherConnectedCell = connectedCell->connections[j].cell; + if (otherConnectedCell->creatureId != 0 && otherConnectedCell->creatureId == cell->creatureId) { + return; + } + } + } + } + auto color = calcMod(cell->color, MAX_COLORS); auto otherColor = calcMod(otherCell->color, MAX_COLORS); diff --git a/source/EngineGpuKernels/CellProcessor.cuh b/source/EngineGpuKernels/CellProcessor.cuh index 178032de4..04de2de34 100644 --- a/source/EngineGpuKernels/CellProcessor.cuh +++ b/source/EngineGpuKernels/CellProcessor.cuh @@ -514,6 +514,7 @@ __inline__ __device__ void CellProcessor::checkConnections(SimulationData& data) } if (scheduleForDestruction) { CellConnectionProcessor::scheduleDeleteAllConnections(data, cell); + atomicCAS(&cell->livingState, LivingState_UnderConstruction, LivingState_Dying); } } } @@ -733,6 +734,10 @@ __inline__ __device__ void CellProcessor::decay(SimulationData& data) if (cell->livingState == LivingState_Dying) { if (data.numberGen1.random() < cudaSimulationParameters.clusterDecayProb[cell->color]) { CellConnectionProcessor::scheduleDeleteCell(data, index); + + //for (int i = 0; i < cell->numConnections; ++i) { + // atomicCAS(&cell->connections[i].cell->livingState, LivingState_UnderConstruction, LivingState_Dying); + //} } } @@ -741,10 +746,11 @@ __inline__ __device__ void CellProcessor::decay(SimulationData& data) cellDestruction = true; } else if (cell->energy > cellMaxBindingEnergy) { CellConnectionProcessor::scheduleDeleteAllConnections(data, cell); + atomicCAS(&cell->livingState, LivingState_UnderConstruction, LivingState_Dying); } auto cellMaxAge = cudaSimulationParameters.cellMaxAge[cell->color]; - if (cudaSimulationParameters.features.cellAgeLimiter && cudaSimulationParameters.cellInactiveMaxAgeActivated + if (cudaSimulationParameters.features.cellAgeLimiter && cudaSimulationParameters.cellInactiveMaxAgeActivated && cell->mutationId != 0 && cell->cellFunctionUsed == CellFunctionUsed_No && cell->livingState == LivingState_Ready && cell->activationTime == 0) { bool adjacentCellsUsed = false; for (int i = 0; i < cell->numConnections; ++i) { diff --git a/source/EngineGpuKernels/ConstructorProcessor.cuh b/source/EngineGpuKernels/ConstructorProcessor.cuh index 35804b8a7..537b52b85 100644 --- a/source/EngineGpuKernels/ConstructorProcessor.cuh +++ b/source/EngineGpuKernels/ConstructorProcessor.cuh @@ -479,7 +479,7 @@ __inline__ __device__ bool ConstructorProcessor::continueConstruction( bool adaptReferenceAngle = false; if (!constructionData.isLastNodeOfLastRepetition || !constructionData.genomeHeader.separateConstruction) { - //move connection + //move connection between lastConstructionCell and hostCell to a connection between newCell and hostCell auto distance = constructionData.isLastNodeOfLastRepetition && !constructionData.genomeHeader.separateConstruction ? 1.0f : cudaSimulationParameters.cellFunctionConstructorOffspringDistance[hostCell->color]; @@ -515,6 +515,7 @@ __inline__ __device__ bool ConstructorProcessor::continueConstruction( adaptReferenceAngle = false; CellConnectionProcessor::scheduleDeleteCell(data, cellPointerIndex); hostCell->livingState = LivingState_Dying; + constructionData.lastConstructionCell->livingState = LivingState_Dying; } Math::normalize(posDelta); diff --git a/source/EngineGpuKernels/RenderingKernels.cu b/source/EngineGpuKernels/RenderingKernels.cu index 44762b443..967ccbd30 100644 --- a/source/EngineGpuKernels/RenderingKernels.cu +++ b/source/EngineGpuKernels/RenderingKernels.cu @@ -84,7 +84,7 @@ namespace return {toInt((r_ + m) * 255), toInt((g_ + m) * 255), toInt((b_ + m) * 255)}; } - __device__ __inline__ float3 calcColor(Cell* cell, int selected, CellColoring cellColoring) + __device__ __inline__ float3 calcColor(Cell* cell, int selected, CellColoring cellColoring, bool primary) { float factor = max(20.0f, min(300.0f, cell->energy)) / 320.0f; if (1 == selected) { @@ -130,7 +130,7 @@ namespace } } } - if (cellColoring == CellColoring_MutationId) { + if (cellColoring == CellColoring_MutationId || (cellColoring == CellColoring_MutationId_AllCellFunctions && primary)) { auto h = abs(toInt((cell->mutationId * 12107) % 360)); auto s = 0.6f + toFloat(abs(toInt(cell->mutationId * 12107)) % 400) / 1000; auto rgb = convertHSVtoRGB(toFloat(h), s, 1.0f); @@ -139,16 +139,16 @@ namespace if (cellColoring == CellColoring_LivingState) { switch (cell->livingState) { case LivingState_Ready: - cellColor = 0x0000ff; + cellColor = 0x1010ff; break; case LivingState_UnderConstruction: - cellColor = 0x00ff00; + cellColor = 0x10ff10; break; case LivingState_Activating: cellColor = 0xffffff; break; case LivingState_Dying: - cellColor = 0xff0000; + cellColor = 0xff1010; break; default: cellColor = 0x000000; @@ -172,7 +172,7 @@ namespace } } - if (cellColoring == CellColoring_AllCellFunction) { + if (cellColoring == CellColoring_AllCellFunctions || (cellColoring == CellColoring_MutationId_AllCellFunctions && !primary)) { auto h = (toFloat(cell->cellFunction) / toFloat(CellFunction_Count - 1)) * 360.0f; auto rgb = convertHSVtoRGB(toFloat(h), 0.7f, 1.0f); cellColor = (rgb.x << 16) | (rgb.y << 8) | rgb.z; @@ -421,12 +421,13 @@ __global__ void cudaDrawCells(uint64_t timestep, int2 worldSize, float2 rectUppe if (isContainedInRect({0, 0}, toFloat2(imageSize), cellImagePos)) { //draw primary color for cell - auto primaryColor = calcColor(cell, cell->selected, coloring) * 0.85f; + auto primaryColor = calcColor(cell, cell->selected, coloring, true) * 0.85f; drawCircle(imageData, imageSize, cellImagePos, primaryColor * 0.45f, zoom / 2.5f, false, false); //draw secondary color for cell auto radius = zoom / 4; - drawCircle(imageData, imageSize, cellImagePos, primaryColor * 0.6f, radius, shadedCells, true); + auto secondaryColor = calcColor(cell, cell->selected, coloring, false) * 0.5f; + drawCircle(imageData, imageSize, cellImagePos, secondaryColor, radius, shadedCells, true); //draw activity if (cell->isActive() && zoom >= cudaSimulationParameters.zoomLevelNeuronalActivity) { @@ -558,7 +559,7 @@ __global__ void cudaDrawCellGlow(int2 worldSize, float2 rectUpperLeft, Arrayselected, coloring); + color = calcColor(cell, cell->selected, coloring, true); } __syncthreads(); diff --git a/source/EngineGpuKernels/SimulationKernels.cu b/source/EngineGpuKernels/SimulationKernels.cu index 445d768a1..41384db7e 100644 --- a/source/EngineGpuKernels/SimulationKernels.cu +++ b/source/EngineGpuKernels/SimulationKernels.cu @@ -142,12 +142,12 @@ __global__ void cudaNextTimestep_cellFunction_detonator(SimulationData data, Sim DetonatorProcessor::process(data, statistics); } -__global__ void cudaNextTimestep_physics_substep7_innerFriction(SimulationData data) +__global__ void cudaNextTimestep_physics_applyInnerFriction(SimulationData data) { CellProcessor::applyInnerFriction(data); } -__global__ void cudaNextTimestep_physics_substep8(SimulationData data) +__global__ void cudaNextTimestep_physics_applyFriction(SimulationData data) { CellFunctionProcessor::resetFetchedActivities(data); CellProcessor::applyFriction(data); diff --git a/source/EngineGpuKernels/SimulationKernels.cuh b/source/EngineGpuKernels/SimulationKernels.cuh index 8503beb6f..e06d49c70 100644 --- a/source/EngineGpuKernels/SimulationKernels.cuh +++ b/source/EngineGpuKernels/SimulationKernels.cuh @@ -25,8 +25,8 @@ __global__ void cudaNextTimestep_cellFunction_muscle(SimulationData data, Simula __global__ void cudaNextTimestep_cellFunction_sensor(SimulationData data, SimulationStatistics statistics); __global__ void cudaNextTimestep_cellFunction_reconnector(SimulationData data, SimulationStatistics statistics); __global__ void cudaNextTimestep_cellFunction_detonator(SimulationData data, SimulationStatistics statistics); -__global__ void cudaNextTimestep_physics_substep7_innerFriction(SimulationData data); -__global__ void cudaNextTimestep_physics_substep8(SimulationData data); +__global__ void cudaNextTimestep_physics_applyInnerFriction(SimulationData data); +__global__ void cudaNextTimestep_physics_applyFriction(SimulationData data); __global__ void cudaNextTimestep_structuralOperations_substep1(SimulationData data); __global__ void cudaNextTimestep_structuralOperations_substep2(SimulationData data); __global__ void cudaNextTimestep_structuralOperations_substep3(SimulationData data); diff --git a/source/EngineGpuKernels/SimulationKernelsLauncher.cu b/source/EngineGpuKernels/SimulationKernelsLauncher.cu index 5ef2915ac..ec1b69969 100644 --- a/source/EngineGpuKernels/SimulationKernelsLauncher.cu +++ b/source/EngineGpuKernels/SimulationKernelsLauncher.cu @@ -35,7 +35,7 @@ void _SimulationKernelsLauncher::calcTimestep(Settings const& settings, Simulati bool considerRigidityUpdate = (data.timestep % 3 == 0); KERNEL_CALL(cudaNextTimestep_physics_init, data); - KERNEL_CALL(cudaNextTimestep_physics_fillMaps, data); + cudaNextTimestep_physics_fillMaps<<>>(data); if (settings.simulationParameters.motionType == MotionType_Fluid) { auto threads = calcOptimalThreadsForFluidKernel(settings.simulationParameters); cudaNextTimestep_physics_calcFluidForces<<>>(data); @@ -69,9 +69,9 @@ void _SimulationKernelsLauncher::calcTimestep(Settings const& settings, Simulati KERNEL_CALL(cudaNextTimestep_cellFunction_detonator, data, statistics); if (considerInnerFriction) { - KERNEL_CALL(cudaNextTimestep_physics_substep7_innerFriction, data); + KERNEL_CALL(cudaNextTimestep_physics_applyInnerFriction, data); } - KERNEL_CALL(cudaNextTimestep_physics_substep8, data); + KERNEL_CALL(cudaNextTimestep_physics_applyFriction, data); if (considerRigidityUpdate && isRigidityUpdateEnabled(settings)) { KERNEL_CALL(cudaInitClusterData, data); diff --git a/source/EngineInterface/SimulationParameters.h b/source/EngineInterface/SimulationParameters.h index 8818cc6f3..ecacf142b 100644 --- a/source/EngineInterface/SimulationParameters.h +++ b/source/EngineInterface/SimulationParameters.h @@ -19,10 +19,11 @@ enum CellColoring_ CellColoring_None, CellColoring_CellColor, CellColoring_MutationId, + CellColoring_MutationId_AllCellFunctions, CellColoring_LivingState, CellColoring_GenomeSize, CellColoring_CellFunction, - CellColoring_AllCellFunction + CellColoring_AllCellFunctions }; struct SimulationParameters diff --git a/source/EngineInterface/StatisticsHistory.cpp b/source/EngineInterface/StatisticsHistory.cpp index 86a163acc..10a0f4248 100644 --- a/source/EngineInterface/StatisticsHistory.cpp +++ b/source/EngineInterface/StatisticsHistory.cpp @@ -4,7 +4,8 @@ StatisticsHistoryData StatisticsHistory::getCopiedData() const { std::lock_guard lock(_mutex); - return _data; + auto copy = _data; + return copy; } std::mutex& StatisticsHistory::getMutex() const diff --git a/source/Gui/SimulationParametersWindow.cpp b/source/Gui/SimulationParametersWindow.cpp index ec708c7cf..2b0f5d854 100644 --- a/source/Gui/SimulationParametersWindow.cpp +++ b/source/Gui/SimulationParametersWindow.cpp @@ -251,6 +251,7 @@ void _SimulationParametersWindow::processBase( {"None", "Standard cell colors", "Mutants", + "Mutants and cell functions", "Cell states", "Genome complexities", "Single cell function", @@ -258,6 +259,7 @@ void _SimulationParametersWindow::processBase( .tooltip("Here, one can set how the cells are to be colored during rendering. \n\n" ICON_FA_CHEVRON_RIGHT " Standard cell colors: Each cell is assigned one of 7 default colors, which is displayed with this option. \n\n" ICON_FA_CHEVRON_RIGHT " Mutants: Different mutants are represented by different colors (only larger structural mutations such as translations or duplications are taken into account).\n\n" + ICON_FA_CHEVRON_RIGHT " Mutants and cell functions: Combination of mutants and cell function coloring.\n\n" ICON_FA_CHEVRON_RIGHT " Cell states: green = under construction, blue = ready, red = dying\n\n" ICON_FA_CHEVRON_RIGHT " Genome complexities: This property can be utilized by attacker cells when the parameter 'Complex genome protection' is " "activated (see tooltip there). The coloring is as follows: blue = creature with low bonus (usually small or simple genome structure), red = large bonus\n\n" @@ -1479,7 +1481,15 @@ void _SimulationParametersWindow::processBase( .name("Coloring") .textWidth(RightColumnWidth) .defaultValue(origParameters.cellGlowColoring) - .values({"None", "Standard cell colors", "Mutants", "Cell states", "Genome complexities", "Single cell function", "All cell functions"}) + .values( + {"None", + "Standard cell colors", + "Mutants", + "Mutants and cell functions", + "Cell states", + "Genome complexities", + "Single cell function", + "All cell functions"}) .tooltip(""), parameters.cellGlowColoring); AlienImGui::SliderFloat( @@ -2187,6 +2197,9 @@ void _SimulationParametersWindow::processAddonList( .defaultValue(origParameters.features.cellColorTransitionRules) .tooltip("This can be used to define color transitions for cells depending on their age."), parameters.features.cellColorTransitionRules); + AlienImGui::Checkbox( + AlienImGui::CheckboxParameters().name("Cell glow").textWidth(0).defaultValue(origParameters.features.cellGlow).tooltip(""), + parameters.features.cellGlow); AlienImGui::Checkbox( AlienImGui::CheckboxParameters() .name("External energy control") @@ -2205,9 +2218,6 @@ void _SimulationParametersWindow::processAddonList( "and 'Advanced attacker control' to favor more complex genomes in natural selection. If it is deactivated, default values are " "used that simply take the genome size into account."), parameters.features.genomeComplexityMeasurement); - AlienImGui::Checkbox( - AlienImGui::CheckboxParameters().name("Secondary cell rendering").textWidth(0).defaultValue(origParameters.features.cellGlow).tooltip(""), - parameters.features.cellGlow); } ImGui::EndChild(); AlienImGui::EndTreeNode();