Skip to content

Commit

Permalink
renaming: acitivity -> signal
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Nov 13, 2024
1 parent 2bcfc3f commit 7845c89
Show file tree
Hide file tree
Showing 39 changed files with 602 additions and 603 deletions.
12 changes: 6 additions & 6 deletions source/EngineGpuKernels/AttackerProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ __device__ __inline__ void AttackerProcessor::process(SimulationData& data, Simu

__device__ __inline__ void AttackerProcessor::processCell(SimulationData& data, SimulationStatistics& statistics, Cell* cell)
{
auto activity = CellFunctionProcessor::calcInputActivity(cell);
CellFunctionProcessor::updateInvocationState(cell, activity);
auto signal = CellFunctionProcessor::calcInputSignal(cell);
CellFunctionProcessor::updateInvocationState(cell, signal);

if (abs(activity.channels[0]) >= cudaSimulationParameters.cellFunctionAttackerActivityThreshold) {
if (abs(signal.channels[0]) >= cudaSimulationParameters.cellFunctionAttackerSignalThreshold) {
float energyDelta = 0;
auto cellMinEnergy = SpotCalculator::calcParameter(
&SimulationParametersSpotValues::cellMinEnergy, &SimulationParametersSpotActivatedValues::cellMinEnergy, data, cell->pos, cell->color);
Expand Down Expand Up @@ -161,7 +161,7 @@ __device__ __inline__ void AttackerProcessor::processCell(SimulationData& data,
if (energyToTransfer > NEAR_ZERO) {

//notify attacked cell
atomicAdd(&otherCell->activity.channels[7], 1.0f);
atomicAdd(&otherCell->signal.channels[7], 1.0f);
otherCell->event = CellEvent_Attacked;
otherCell->eventCounter = 6;
otherCell->eventPos = cell->pos;
Expand Down Expand Up @@ -194,7 +194,7 @@ __device__ __inline__ void AttackerProcessor::processCell(SimulationData& data,
radiate(data, cell);

//output
activity.channels[0] = energyDelta / 10;
signal.channels[0] = energyDelta / 10;

if (energyDelta > NEAR_ZERO) {
cell->event = CellEvent_Attacking;
Expand All @@ -203,7 +203,7 @@ __device__ __inline__ void AttackerProcessor::processCell(SimulationData& data,
}
}

CellFunctionProcessor::setActivity(cell, activity);
CellFunctionProcessor::setSignal(cell, signal);
}

__device__ __inline__ void AttackerProcessor::radiate(SimulationData& data, Cell* cell)
Expand Down
54 changes: 27 additions & 27 deletions source/EngineGpuKernels/CellFunctionProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class CellFunctionProcessor
public:
__inline__ __device__ static void collectCellFunctionOperations(SimulationData& data);
__inline__ __device__ static void updateRenderingData(SimulationData& data);
__inline__ __device__ static void resetFetchedActivities(SimulationData& data);
__inline__ __device__ static void resetFetchedSignals(SimulationData& data);

__inline__ __device__ static Activity calcInputActivity(Cell* cell);
__inline__ __device__ static void setActivity(Cell* cell, Activity const& newActivity);
__inline__ __device__ static void updateInvocationState(Cell* cell, Activity const& activity);
__inline__ __device__ static Signal calcInputSignal(Cell* cell);
__inline__ __device__ static void setSignal(Cell* cell, Signal const& newSignal);
__inline__ __device__ static void updateInvocationState(Cell* cell, Signal const& signal);

struct ReferenceAndActualAngle
{
Expand Down Expand Up @@ -66,7 +66,7 @@ __inline__ __device__ void CellFunctionProcessor::updateRenderingData(Simulation
}
}

__inline__ __device__ void CellFunctionProcessor::resetFetchedActivities(SimulationData& data)
__inline__ __device__ void CellFunctionProcessor::resetFetchedSignals(SimulationData& data)
{
auto& cells = data.objects.cellPointers;
auto partition = calcAllThreadsPartition(cells.getNumEntries());
Expand All @@ -75,7 +75,7 @@ __inline__ __device__ void CellFunctionProcessor::resetFetchedActivities(Simulat
auto& cell = cells.at(index);
if (cell->cellFunction == CellFunction_None) {
for (int i = 0; i < MAX_CHANNELS; ++i) {
cell->activity.channels[i] = 0;
cell->signal.channels[i] = 0;
}
continue;
}
Expand Down Expand Up @@ -104,16 +104,16 @@ __inline__ __device__ void CellFunctionProcessor::resetFetchedActivities(Simulat
&& executionOrderNumber == (cell->executionOrderNumber + 1) % cudaSimulationParameters.cellNumExecutionOrderNumbers)
|| (maxOtherExecutionOrderNumber != -1 && maxOtherExecutionOrderNumber == executionOrderNumber)) {
for (int i = 0; i < MAX_CHANNELS; ++i) {
cell->activity.channels[i] = 0;
cell->signal.channels[i] = 0;
}
}
}
}

__inline__ __device__ Activity CellFunctionProcessor::calcInputActivity(Cell* cell)
__inline__ __device__ Signal CellFunctionProcessor::calcInputSignal(Cell* cell)
{
Activity result;
result.origin = ActivityOrigin_Unknown;
Signal result;
result.origin = SignalOrigin_Unknown;
result.targetX = 0;
result.targetY = 0;

Expand All @@ -125,47 +125,47 @@ __inline__ __device__ Activity CellFunctionProcessor::calcInputActivity(Cell* ce
return result;
}

int numSensorActivities = 0;
int numSensorSignals = 0;
for (int i = 0, j = cell->numConnections; i < j; ++i) {
auto connectedCell = cell->connections[i].cell;
if (connectedCell->outputBlocked || connectedCell->livingState != LivingState_Ready ) {
continue;
}
if (connectedCell->executionOrderNumber == cell->inputExecutionOrderNumber) {
for (int i = 0; i < MAX_CHANNELS; ++i) {
result.channels[i] += connectedCell->activity.channels[i];
result.channels[i] += connectedCell->signal.channels[i];
result.channels[i] = max(-10.0f, min(10.0f, result.channels[i])); //truncate value to avoid overflow
}
if (connectedCell->activity.origin == ActivityOrigin_Sensor) {
result.origin = ActivityOrigin_Sensor;
result.targetX += connectedCell->activity.targetX;
result.targetY += connectedCell->activity.targetY;
++numSensorActivities;
if (connectedCell->signal.origin == SignalOrigin_Sensor) {
result.origin = SignalOrigin_Sensor;
result.targetX += connectedCell->signal.targetX;
result.targetY += connectedCell->signal.targetY;
++numSensorSignals;
}
}
}
if (numSensorActivities > 0) {
result.targetX /= numSensorActivities;
result.targetY /= numSensorActivities;
if (numSensorSignals > 0) {
result.targetX /= numSensorSignals;
result.targetY /= numSensorSignals;
}
return result;
}

__inline__ __device__ void CellFunctionProcessor::setActivity(Cell* cell, Activity const& newActivity)
__inline__ __device__ void CellFunctionProcessor::setSignal(Cell* cell, Signal const& newSignal)
{
for (int i = 0; i < MAX_CHANNELS; ++i) {
cell->activity.channels[i] = newActivity.channels[i];
cell->signal.channels[i] = newSignal.channels[i];
}
cell->activity.origin = newActivity.origin;
cell->activity.targetX = newActivity.targetX;
cell->activity.targetY = newActivity.targetY;
cell->signal.origin = newSignal.origin;
cell->signal.targetX = newSignal.targetX;
cell->signal.targetY = newSignal.targetY;
}

__inline__ __device__ void CellFunctionProcessor::updateInvocationState(Cell* cell, Activity const& activity)
__inline__ __device__ void CellFunctionProcessor::updateInvocationState(Cell* cell, Signal const& signal)
{
if (cell->cellFunctionUsed == CellFunctionUsed_No) {
for (int i = 0; i < MAX_CHANNELS - 1; ++i) {
if (activity.channels[i] != 0) {
if (signal.channels[i] != 0) {
cell->cellFunctionUsed = CellFunctionUsed_Yes;
break;
}
Expand Down
22 changes: 11 additions & 11 deletions source/EngineGpuKernels/ConstructorProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private:

__inline__ __device__ static void processCell(SimulationData& data, SimulationStatistics& statistics, Cell* cell);
__inline__ __device__ static ConstructionData readConstructionData(Cell* cell);
__inline__ __device__ static bool isConstructionTriggered(SimulationData const& data, Cell* cell, Activity const& activity);
__inline__ __device__ static bool isConstructionTriggered(SimulationData const& data, Cell* cell, Signal const& signal);

__inline__ __device__ static Cell* tryConstructCell(SimulationData& data, SimulationStatistics& statistics, Cell* hostCell, ConstructionData const& constructionData);

Expand Down Expand Up @@ -102,8 +102,8 @@ __inline__ __device__ void ConstructorProcessor::completenessCheck(SimulationDat
if (!GenomeDecoder::isFirstNode(constructor)) {
return;
}
auto activity = CellFunctionProcessor::calcInputActivity(cell);
if (!isConstructionTriggered(data, cell, activity)) {
auto signal = CellFunctionProcessor::calcInputSignal(cell);
if (!isConstructionTriggered(data, cell, signal)) {
return;
}

Expand Down Expand Up @@ -149,20 +149,20 @@ __inline__ __device__ void ConstructorProcessor::completenessCheck(SimulationDat
__inline__ __device__ void ConstructorProcessor::processCell(SimulationData& data, SimulationStatistics& statistics, Cell* cell)
{
auto& constructor = cell->cellFunctionData.constructor;
auto activity = CellFunctionProcessor::calcInputActivity(cell);
CellFunctionProcessor::updateInvocationState(cell, activity);
auto signal = CellFunctionProcessor::calcInputSignal(cell);
CellFunctionProcessor::updateInvocationState(cell, signal);
if (!GenomeDecoder::isFinished(constructor)) {
auto constructionData = readConstructionData(cell);
auto cellBuilt = false;
if (isConstructionTriggered(data, cell, activity)) {
if (isConstructionTriggered(data, cell, signal)) {
if (tryConstructCell(data, statistics, cell, constructionData)) {
cellBuilt = true;
cell->cellFunctionUsed = CellFunctionUsed_Yes;
}
}

if (cellBuilt) {
activity.channels[0] = 1;
signal.channels[0] = 1;
if (GenomeDecoder::isLastNode(constructor)) {
constructor.genomeCurrentNodeIndex = 0;
if (!constructionData.genomeHeader.hasInfiniteRepetitions()) {
Expand All @@ -178,10 +178,10 @@ __inline__ __device__ void ConstructorProcessor::processCell(SimulationData& dat
++constructor.genomeCurrentNodeIndex;
}
} else {
activity.channels[0] = 0;
signal.channels[0] = 0;
}
}
CellFunctionProcessor::setActivity(cell, activity);
CellFunctionProcessor::setSignal(cell, signal);
}

__inline__ __device__ ConstructorProcessor::ConstructionData ConstructorProcessor::readConstructionData(Cell* cell)
Expand Down Expand Up @@ -269,10 +269,10 @@ __inline__ __device__ ConstructorProcessor::ConstructionData ConstructorProcesso
}

__inline__ __device__ bool
ConstructorProcessor::isConstructionTriggered(SimulationData const& data, Cell* cell, Activity const& activity)
ConstructorProcessor::isConstructionTriggered(SimulationData const& data, Cell* cell, Signal const& signal)
{
if (cell->cellFunctionData.constructor.activationMode == 0
&& abs(activity.channels[0]) < cudaSimulationParameters.cellFunctionConstructorActivityThreshold[cell->color]) {
&& abs(signal.channels[0]) < cudaSimulationParameters.cellFunctionConstructorSignalThreshold[cell->color]) {
return false;
}
if (cell->cellFunctionData.constructor.activationMode > 0
Expand Down
8 changes: 4 additions & 4 deletions source/EngineGpuKernels/DataAccessKernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ namespace
cellTO.color = cell->color;
cellTO.age = cell->age;
for (int i = 0; i < MAX_CHANNELS; ++i) {
cellTO.activity.channels[i] = cell->activity.channels[i];
cellTO.signal.channels[i] = cell->signal.channels[i];
}
cellTO.activity.origin = cell->activity.origin;
cellTO.activity.targetX = cell->activity.targetX;
cellTO.activity.targetY = cell->activity.targetY;
cellTO.signal.origin = cell->signal.origin;
cellTO.signal.targetX = cell->signal.targetX;
cellTO.signal.targetY = cell->signal.targetY;
cellTO.activationTime = cell->activationTime;
cellTO.detectedByCreatureId = cell->detectedByCreatureId;
cellTO.cellFunctionUsed = cell->cellFunctionUsed;
Expand Down
8 changes: 4 additions & 4 deletions source/EngineGpuKernels/DetonatorProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ __device__ __inline__ void DetonatorProcessor::process(SimulationData& data, Sim

__device__ __inline__ void DetonatorProcessor::processCell(SimulationData& data, SimulationStatistics& statistics, Cell* cell)
{
auto activity = CellFunctionProcessor::calcInputActivity(cell);
CellFunctionProcessor::updateInvocationState(cell, activity);
auto signal = CellFunctionProcessor::calcInputSignal(cell);
CellFunctionProcessor::updateInvocationState(cell, signal);

auto& detonator = cell->cellFunctionData.detonator;
if (activity.channels[0] >= abs(cudaSimulationParameters.cellFunctionDetonatorActivityThreshold) && detonator.state == DetonatorState_Ready) {
if (signal.channels[0] >= abs(cudaSimulationParameters.cellFunctionDetonatorSignalThreshold) && detonator.state == DetonatorState_Ready) {
detonator.state = DetonatorState_Activated;
}
if (detonator.state == DetonatorState_Activated) {
Expand Down Expand Up @@ -72,5 +72,5 @@ __device__ __inline__ void DetonatorProcessor::processCell(SimulationData& data,
detonator.state = DetonatorState_Exploded;
}
}
CellFunctionProcessor::setActivity(cell, activity);
CellFunctionProcessor::setSignal(cell, signal);
}
12 changes: 6 additions & 6 deletions source/EngineGpuKernels/InjectorProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ __device__ __inline__ void InjectorProcessor::process(SimulationData& data, Simu

__inline__ __device__ void InjectorProcessor::processCell(SimulationData& data, SimulationStatistics& statistics, Cell* cell)
{
auto activity = CellFunctionProcessor::calcInputActivity(cell);
CellFunctionProcessor::updateInvocationState(cell, activity);
auto signal = CellFunctionProcessor::calcInputSignal(cell);
CellFunctionProcessor::updateInvocationState(cell, signal);

if (abs(activity.channels[0]) >= cudaSimulationParameters.cellFunctionInjectorActivityThreshold) {
if (abs(signal.channels[0]) >= cudaSimulationParameters.cellFunctionInjectorSignalThreshold) {

auto& injector = cell->cellFunctionData.injector;

Expand Down Expand Up @@ -133,13 +133,13 @@ __inline__ __device__ void InjectorProcessor::processCell(SimulationData& data,
} else {
++injector.counter;
}
activity.channels[0] = 1;
signal.channels[0] = 1;
} else {
injector.counter = 0;
activity.channels[0] = 0;
signal.channels[0] = 0;
}
}
CellFunctionProcessor::setActivity(cell, activity);
CellFunctionProcessor::setSignal(cell, signal);
}

__inline__ __device__ int InjectorProcessor::countAndTrackDefenderCells(SimulationStatistics& statistics, Cell* cell)
Expand Down
Loading

0 comments on commit 7845c89

Please sign in to comment.