Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Apr 22, 2024
2 parents bb32bc9 + 7996a0c commit 5184183
Show file tree
Hide file tree
Showing 39 changed files with 366 additions and 143 deletions.
18 changes: 18 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Release notes

## [4.9.0] - 2024-04-22
### Added
- engine, gui/simulation parameters: conditional and unconditional energy inflow from external energy source
- engine, gui/simulation parameters: energy backflow to the external energy source
- gui/simulation view: combined mutation and cell function coloring
- gui/temporal control window: real-time counter

### Changed
- gui/simulation view: cells are rendered smoother
- engine, gui/simulation parameters: external energy becomes a scalar value (no color dependence)

### Deleted
- engine, gui/simulation parameters: energy pump from constructors (substituted by conditional energy inflow)

### Fixed
- serialization: activation of necessary add-ons for old simulation parameter files fixed
- gui/browser: preserve subfolders when renaming folders

## [4.8.2] - 2024-04-05
### Changed
- engine, genome editor: multiple construction flag is replaced by number of constructions
Expand Down
6 changes: 3 additions & 3 deletions imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ Size=32,1042
Collapsed=0

[Window][Temporal control]
Pos=1511,622
Size=330,319
Pos=1517,578
Size=341,393
Collapsed=0

[Window][###SimulationSaveDialog]
Expand Down Expand Up @@ -104,7 +104,7 @@ Size=594,788
Collapsed=0

[Window][Spatial control]
Pos=1511,209
Pos=1517,162
Size=330,397
Collapsed=0

Expand Down
34 changes: 18 additions & 16 deletions resources/autosave.settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"general": {
"time step": "85540",
"real time": "0",
"zoom": "1.16543949",
"center": {
"x": "918.00494385",
Expand Down Expand Up @@ -86,13 +87,28 @@
},
"function": {
"constructor": {
"external energy": "0.00000000",
"external energy supply rate[0]": "0.00000000",
"external energy supply rate[1]": "0.00000000",
"external energy supply rate[2]": "0.00000000",
"external energy supply rate[3]": "0.00000000",
"external energy supply rate[4]": "0.00000000",
"external energy supply rate[5]": "0.00000000",
"external energy supply rate[6]": "0.00000000",
"pump energy factor[0]": "0.71799999",
"pump energy factor[1]": "0.00000000",
"pump energy factor[2]": "0.71799999",
"pump energy factor[3]": "0.71799999",
"pump energy factor[4]": "0.71799999",
"pump energy factor[5]": "0.71799999",
"pump energy factor[6]": "0.71799999",
"external energy backflow[0]": "0.14360000",
"external energy backflow[1]": "0.00000000",
"external energy backflow[2]": "0.14360000",
"external energy backflow[3]": "0.14360000",
"external energy backflow[4]": "0.14360000",
"external energy backflow[5]": "0.14360000",
"external energy backflow[6]": "0.14360000",
"offspring distance[0]": "2.00000000",
"offspring distance[1]": "2.00000000",
"offspring distance[2]": "2.00000000",
Expand Down Expand Up @@ -251,21 +267,7 @@
"mutation color transition[6, 6]": "true",
"mutation self replication": "false",
"mutation prevent depth increase": "false",
"completeness check for self-replication": "false",
"external energy[0]": "0.00000000",
"external energy[1]": "0.00000000",
"external energy[2]": "0.00000000",
"external energy[3]": "0.00000000",
"external energy[4]": "0.00000000",
"external energy[5]": "0.00000000",
"external energy[6]": "0.00000000",
"external energy supply rate[0]": "0.00000000",
"external energy supply rate[1]": "0.00000000",
"external energy supply rate[2]": "0.00000000",
"external energy supply rate[3]": "0.00000000",
"external energy supply rate[4]": "0.00000000",
"external energy supply rate[5]": "0.00000000",
"external energy supply rate[6]": "0.00000000"
"completeness check for self-replication": "false"
},
"injector": {
"radius[0]": "2.00000000",
Expand Down Expand Up @@ -1920,7 +1922,7 @@
"genome complexity measurement": "false",
"additional absorption control": "false",
"additional attacker control": "true",
"external energy": "false",
"external energy": "true",
"cell color transition rules": "false"
}
}
Expand Down
13 changes: 12 additions & 1 deletion source/Base/JsonParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ bool JsonParser::encodeDecode(
} else {
value = tree.get<T>(node, defaultValue);
}
return tree.find(node) == tree.not_found();
size_t lastDotIndex = node.find_last_of('.');
if (lastDotIndex == std::string::npos) {
return true;
}
std::string path = node.substr(0, lastDotIndex);
std::string property = node.substr(lastDotIndex + 1);
auto subtree = tree.get_child_optional(path);
if (!subtree) {
return true;
}

return subtree->find(property) == subtree->not_found();
}
}
2 changes: 1 addition & 1 deletion source/Base/Resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Const
{
std::string const ProgramVersion = "4.8.2";
std::string const ProgramVersion = "4.9.0";
std::string const DiscordLink = "https://discord.gg/7bjyZdXXQ2";

std::string const BasePath = "resources/";
Expand Down
39 changes: 39 additions & 0 deletions source/Base/StringHelper.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "StringHelper.h"

#include <algorithm>
#include <sstream>
#include <iomanip>

std::string StringHelper::format(uint64_t n)
{
Expand Down Expand Up @@ -38,6 +40,43 @@ std::string StringHelper::format(float v, int fracPartDecimals)
return result;
}

std::string StringHelper::format(std::chrono::milliseconds duration)
{
if (duration.count() == 0) {
return "0";
}
auto months = std::chrono::duration_cast<std::chrono::months>(duration);
duration -= months;
auto days = std::chrono::duration_cast<std::chrono::days>(duration);
duration -= days;
auto hours = std::chrono::duration_cast<std::chrono::hours>(duration);
duration -= hours;
auto minutes = std::chrono::duration_cast<std::chrono::minutes>(duration);
duration -= minutes;
auto seconds = std::chrono::duration_cast<std::chrono::seconds>(duration);
duration -= seconds;

std::ostringstream oss;
if (months.count() > 0) {
oss << std::setw(2) << std::setfill('0') << months.count() << ":";
}
if (days.count() > 0 || months.count() > 0) {
oss << std::setw(2) << std::setfill('0') << days.count() << ":";
}
if (hours.count() > 0 || days.count() > 0 || months.count() > 0) {
oss << std::setw(2) << std::setfill('0') << hours.count() << ":";
}
if (minutes.count() > 0 || hours.count() > 0 || days.count() > 0 || months.count() > 0) {
oss << std::setw(2) << std::setfill('0') << minutes.count() << ":";
}
if (seconds.count() > 0 || minutes.count() > 0 || hours.count() > 0 || days.count() > 0 || months.count() > 0) {
oss << std::setw(2) << std::setfill('0') << seconds.count() << ":";
}
oss << std::setw(3) << std::setfill('0') << duration.count();

return oss.str();
}

void StringHelper::copy(char* target, int targetSize, std::string const& source)
{
auto sourceSize = source.size();
Expand Down
2 changes: 2 additions & 0 deletions source/Base/StringHelper.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <chrono>
#include <string>

#include "Base/Definitions.h"
Expand All @@ -9,6 +10,7 @@ class StringHelper
public:
static std::string format(uint64_t n);
static std::string format(float v, int decimalsAfterPoint);
static std::string format(std::chrono::milliseconds duration);

static void copy(char* target, int targetSize, std::string const& source);
};
2 changes: 1 addition & 1 deletion source/EngineGpuKernels/AttackerProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ __device__ __inline__ void AttackerProcessor::processCell(SimulationData& data,
energyToTransfer /=
(1.0f + cellFunctionAttackerGenomeComplexityBonus * static_cast<float>(otherCell->genomeComplexity - cell->genomeComplexity));
}
if (cudaSimulationParameters.features.advancedAttackerControl && otherCell->mutationId == cell->mutationId) {
if (cudaSimulationParameters.features.advancedAttackerControl && otherCell->mutationId == cell->mutationId && cell->mutationId != 0) {
auto sameMutantPenalty = cudaSimulationParameters.cellFunctionAttackerSameMutantPenalty[color][otherColor];
energyToTransfer *= (1.0f - sameMutantPenalty);
}
Expand Down
19 changes: 9 additions & 10 deletions source/EngineGpuKernels/ConstructorProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -720,27 +720,26 @@ ConstructorProcessor::constructCellIntern(
__inline__ __device__ bool ConstructorProcessor::checkAndReduceHostEnergy(SimulationData& data, Cell* hostCell, ConstructionData const& constructionData)
{
if (cudaSimulationParameters.features.externalEnergyControl && hostCell->energy < constructionData.energy + cudaSimulationParameters.cellNormalEnergy[hostCell->color]
&& cudaSimulationParameters.cellFunctionConstructorExternalEnergySupplyRate[hostCell->color] > 0) {
auto externalEnergyPortion = constructionData.energy * cudaSimulationParameters.cellFunctionConstructorExternalEnergySupplyRate[hostCell->color];
&& cudaSimulationParameters.externalEnergyInflowFactor[hostCell->color] > 0) {
auto externalEnergyPortion = constructionData.energy * cudaSimulationParameters.externalEnergyInflowFactor[hostCell->color];

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

auto cellFunctionConstructorPumpEnergyFactor = cudaSimulationParameters.cellFunctionConstructorPumpEnergyFactor[hostCell->color];
auto cellFunctionConstructorPumpEnergyFactor = cudaSimulationParameters.externalEnergyConditionalInflowFactor[hostCell->color];
//if (isSelfReplicator(hostCell)) {
// cellFunctionConstructorPumpEnergyFactor = 0;
// externalEnergyConditionalInflowFactor = 0;
//}

auto energyNeededFromHost = max(0.0f, constructionData.energy - cudaSimulationParameters.cellNormalEnergy[hostCell->color])
Expand All @@ -750,9 +749,9 @@ __inline__ __device__ bool ConstructorProcessor::checkAndReduceHostEnergy(Simula
return false;
}
auto energyNeededFromRadiation = constructionData.energy - energyNeededFromHost;
auto orig = atomicAdd(data.residualEnergy, -energyNeededFromRadiation);
auto orig = atomicAdd(data.externalEnergy, -energyNeededFromRadiation);
if (orig < energyNeededFromRadiation) {
atomicAdd(data.residualEnergy, energyNeededFromRadiation);
atomicAdd(data.externalEnergy, energyNeededFromRadiation);
if (hostCell->energy < cudaSimulationParameters.cellNormalEnergy[hostCell->color] + constructionData.energy) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion source/EngineGpuKernels/Macros.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void checkAndThrowError(T result, char const *const func, const char *const file
}
break;
}
stream << " Location: " << file << ":" << line << " code=" << static_cast<unsigned int>(result) << "(" << _cudaGetErrorEnum(result) << ") \"" << func
stream << std::endl << "Location: " << file << ":" << line << " code=" << static_cast<unsigned int>(result) << "(" << _cudaGetErrorEnum(result) << ") \"" << func
<< "\"";
auto text = stream.str();
log(Priority::Important, text);
Expand Down
7 changes: 7 additions & 0 deletions source/EngineGpuKernels/Math.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ __inline__ __device__ __host__ void operator+=(float2& p, float2 const& q)
p.y += q.y;
}

__inline__ __device__ __host__ void operator*=(float3& p, float const& q)
{
p.x *= q;
p.y *= q;
p.z *= q;
}

__inline__ __device__ __host__ void operator+=(float3& p, float3 const& q)
{
p.x += q.x;
Expand Down
4 changes: 2 additions & 2 deletions source/EngineGpuKernels/MutationProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public:
__inline__ __device__ static void genomeColorMutation(SimulationData& data, Cell* cell);

private:
__inline__ __device__ static bool adaptMutationId(SimulationData& data, ConstructorFunction& constructor);
__inline__ __device__ static void adaptMutationId(SimulationData& data, ConstructorFunction& constructor);
__inline__ __device__ static bool isRandomEvent(SimulationData& data, float probability);
__inline__ __device__ static int getNewColorFromTransition(SimulationData& data, int origColor);
};
Expand Down Expand Up @@ -822,7 +822,7 @@ __inline__ __device__ void MutationProcessor::genomeColorMutation(SimulationData
genome, genomeSize, true, [&](int depth, int nodeAddress, int repetition) { GenomeDecoder::setNextCellColor(genome, nodeAddress, newColor); });
}

__inline__ __device__ bool MutationProcessor::adaptMutationId(SimulationData& data, ConstructorFunction& constructor)
__inline__ __device__ void MutationProcessor::adaptMutationId(SimulationData& data, ConstructorFunction& constructor)
{
if (GenomeDecoder::containsSelfReplication(constructor)) {
constructor.offspringMutationId = abs(toInt(data.numberGen1.createNewSmalllId()));
Expand Down
9 changes: 4 additions & 5 deletions source/EngineGpuKernels/ParticleProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,14 @@ __inline__ __device__ void ParticleProcessor::radiate(SimulationData& data, floa

data.cellMap.correctPosition(pos);

auto residualEnergyPerCell = *data.residualEnergy / max(static_cast<uint64_t>(1), data.objects.cells.getNumOrigEntries());
auto cellFunctionConstructorEnergyFromRadiationFactor = residualEnergyPerCell < 0.2 ? cudaSimulationParameters.cellFunctionConstructorPumpEnergyFactor[color] / 3 : 0;
auto particleEnergy = energy * (1.0f - cellFunctionConstructorEnergyFromRadiationFactor);
auto externalEnergyBackflowFactor = cudaSimulationParameters.externalEnergyBackflowFactor[color];
auto particleEnergy =
energy * (1.0f - externalEnergyBackflowFactor);
if (particleEnergy > NEAR_ZERO) {
ObjectFactory factory;
factory.init(&data);
data.cellMap.correctPosition(pos);
factory.createParticle(particleEnergy, pos, vel, color);
}

atomicAdd(data.residualEnergy, energy * cellFunctionConstructorEnergyFromRadiationFactor);
atomicAdd(data.externalEnergy, toDouble(energy * externalEnergyBackflowFactor));
}
Loading

0 comments on commit 5184183

Please sign in to comment.