Skip to content

Commit

Permalink
+ validation and tooltip of parameters for external energy source
Browse files Browse the repository at this point in the history
+ support for infinite energy sources
  • Loading branch information
chrxh committed Nov 25, 2023
1 parent 435f5f7 commit 44b2140
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
15 changes: 10 additions & 5 deletions source/EngineGpuKernels/ConstructorProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -723,12 +723,17 @@ __inline__ __device__ bool ConstructorProcessor::checkAndReduceHostEnergy(Simula
auto externalEnergyPortion = constructionData.energy * cudaSimulationParameters.cellFunctionConstructorExternalEnergySupplyRate[hostCell->color];

auto externalEnergyPtr = &((*data.externalEnergy)[hostCell->color]);
externalEnergyPortion = max(0.0f, min(alienAtomicRead(externalEnergyPtr), externalEnergyPortion));
auto origEnergy = atomicAdd(externalEnergyPtr, -externalEnergyPortion);
if (origEnergy >= externalEnergyPortion) {
hostCell->energy += externalEnergyPortion;
auto origExternalEnergy = alienAtomicRead(externalEnergyPtr);
if (origExternalEnergy == Infinity<float>::value) {
hostCell->energy += constructionData.energy;
} else {
atomicAdd(externalEnergyPtr, externalEnergyPortion);
externalEnergyPortion = max(0.0f, min(origExternalEnergy, externalEnergyPortion));
auto origExternalEnergy_tickLater = atomicAdd(externalEnergyPtr, -externalEnergyPortion);
if (origExternalEnergy_tickLater >= externalEnergyPortion) {
hostCell->energy += externalEnergyPortion;
} else {
atomicAdd(externalEnergyPtr, externalEnergyPortion);
}
}
}

Expand Down
12 changes: 9 additions & 3 deletions source/Gui/SimulationParametersWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ void _SimulationParametersWindow::processBase(
/**
* Danger zone
*/
if (ImGui::TreeNodeEx("External energy supply", treeNodeOpenFlags)) {
if (ImGui::TreeNodeEx("External energy source", treeNodeOpenFlags)) {
AlienImGui::SliderFloat(
AlienImGui::SliderFloatParameters()
.name("External energy for constructors")
Expand All @@ -1189,7 +1189,9 @@ void _SimulationParametersWindow::processBase(
.logarithmic(true)
.infinity(true)
.defaultValue(origSimParameters.cellFunctionConstructorExternalEnergy)
.tooltip(""),
.tooltip("This parameter can be used to set the amount of energy (per color) of an external energy source. This type of energy is "
"transferred to all constructor cells at a certain rate.\n\nTip: You can explicitly enter a numerical value by selecting the "
"slider and pressing TAB."),
simParameters.cellFunctionConstructorExternalEnergy);
AlienImGui::SliderFloat(
AlienImGui::SliderFloatParameters()
Expand All @@ -1199,7 +1201,8 @@ void _SimulationParametersWindow::processBase(
.min(0.0f)
.max(1.0f)
.defaultValue(origSimParameters.cellFunctionConstructorExternalEnergySupplyRate)
.tooltip(""),
.tooltip("The energy from the external source is transferred to all constructor cells at a rate defined here: 0 = no energy transfer, 1 = "
"constructor cells receive all the required energy"),
simParameters.cellFunctionConstructorExternalEnergySupplyRate);
ImGui::TreePop();
}
Expand Down Expand Up @@ -1880,6 +1883,9 @@ void _SimulationParametersWindow::validationAndCorrection(SimulationParameters&
parameters.cellFunctionAttackerSensorDetectionFactor[i] = std::max(0.0f, std::min(1.0f, parameters.cellFunctionAttackerSensorDetectionFactor[i]));
parameters.cellFunctionDetonatorChainExplosionProbability[i] =
std::max(0.0f, std::min(1.0f, parameters.cellFunctionDetonatorChainExplosionProbability[i]));
parameters.cellFunctionConstructorExternalEnergy[i] = std::max(0.0f, parameters.cellFunctionConstructorExternalEnergy[i]);
parameters.cellFunctionConstructorExternalEnergySupplyRate[i] =
std::max(0.0f, std::min(1.0f, parameters.cellFunctionConstructorExternalEnergySupplyRate[i]));
}
parameters.baseValues.cellMaxBindingEnergy = std::max(10.0f, parameters.baseValues.cellMaxBindingEnergy);
parameters.timestepSize = std::max(0.0f, parameters.timestepSize);
Expand Down

0 comments on commit 44b2140

Please sign in to comment.