Skip to content

Commit

Permalink
use 16 bits for detectedByCreatureId
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Sep 16, 2024
1 parent 73db528 commit 60461aa
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions source/EngineGpuKernels/AttackerProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ __device__ __inline__ void AttackerProcessor::processCell(SimulationData& data,
auto color = calcMod(cell->color, MAX_COLORS);
auto otherColor = calcMod(otherCell->color, MAX_COLORS);

if (cudaSimulationParameters.features.advancedAttackerControl && otherCell->detectedByCreatureId != (cell->creatureId & 0xff)) {
if (cudaSimulationParameters.features.advancedAttackerControl && otherCell->detectedByCreatureId != (cell->creatureId & 0xffff)) {
energyToTransfer *= (1.0f - cudaSimulationParameters.cellFunctionAttackerSensorDetectionFactor[color]);
}

Expand All @@ -87,7 +87,7 @@ __device__ __inline__ void AttackerProcessor::processCell(SimulationData& data,
(1.0f + cellFunctionAttackerGenomeComplexityBonus * (otherCell->genomeComplexity - cell->genomeComplexity));
}
if (cudaSimulationParameters.features.advancedAttackerControl
&& ((otherCell->mutationId == cell->mutationId) || (otherCell->ancestorMutationId == static_cast<uint16_t>(cell->mutationId & 0xffff)))
&& ((otherCell->mutationId == cell->mutationId) || (otherCell->ancestorMutationId == static_cast<uint8_t>(cell->mutationId & 0xff)))
&& cell->mutationId != 0) {
energyToTransfer *= (1.0f - cudaSimulationParameters.cellFunctionAttackerSameMutantPenalty[color][otherColor]);
}
Expand Down
2 changes: 1 addition & 1 deletion source/EngineGpuKernels/ConstructorProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ ConstructorProcessor::constructCellIntern(
result->livingState = LivingState_UnderConstruction;
result->creatureId = constructor.offspringCreatureId;
result->mutationId = constructor.offspringMutationId;
result->ancestorMutationId = static_cast<uint16_t>(hostCell->mutationId & 0xffff);
result->ancestorMutationId = static_cast<uint8_t>(hostCell->mutationId & 0xff);
result->cellFunction = constructionData.cellFunction;
result->color = constructionData.color;
result->inputExecutionOrderNumber = constructionData.inputExecutionOrderNumber;
Expand Down
4 changes: 2 additions & 2 deletions source/EngineGpuKernels/Object.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ struct Cell
LivingState livingState;
uint32_t creatureId;
uint32_t mutationId;
uint16_t ancestorMutationId; //only the first 16 bits from host mutation id
uint8_t ancestorMutationId; //only the first 8 bits from ancestor mutation id
float genomeComplexity;

//cell function
Expand All @@ -234,7 +234,7 @@ struct Cell
CellFunctionUsed cellFunctionUsed;

//process data
uint8_t detectedByCreatureId; //only the first 8 bits from the creature id
uint16_t detectedByCreatureId; //only the first 16 bits from the creature id

//annotations
CellMetadataDescription metadata;
Expand Down
4 changes: 2 additions & 2 deletions source/EngineGpuKernels/SensorProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ __inline__ __device__ void SensorProcessor::flagDetectedCells(SimulationData& da
}
if (restrictToMutants == SensorRestrictToMutants_RestrictToOtherMutants
&& (cell->mutationId == otherCell->mutationId || otherCell->mutationId == 0 || otherCell->mutationId == 1
|| static_cast<uint16_t>(cell->mutationId & 0xffff) == otherCell->ancestorMutationId)) {
|| static_cast<uint8_t>(cell->mutationId & 0xff) == otherCell->ancestorMutationId)) {
continue;
}
if (restrictToMutants == SensorRestrictToMutants_RestrictToFreeCells && otherCell->mutationId != 1) {
Expand All @@ -343,7 +343,7 @@ __inline__ __device__ void SensorProcessor::flagDetectedCells(SimulationData& da
// continue;
//}

otherCell->detectedByCreatureId = static_cast<uint8_t>(cell->creatureId & 0xff);
otherCell->detectedByCreatureId = static_cast<uint16_t>(cell->creatureId & 0xffff);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions source/EngineGpuKernels/TOs.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ struct CellTO
LivingState livingState;
uint32_t creatureId;
uint32_t mutationId;
uint16_t ancestorMutationId; //only the first 16 bits from host mutation id
uint8_t ancestorMutationId; //only the first 8 bits from ancestor mutation id
float genomeComplexity;

//cell function
Expand All @@ -185,7 +185,7 @@ struct CellTO
CellFunctionTO cellFunctionData;
ActivityTO activity;
uint32_t activationTime;
uint8_t detectedByCreatureId; //only the first 8 bits from the creature id
uint16_t detectedByCreatureId; //only the first 16 bits from the creature id
CellFunctionUsed cellFunctionUsed;

CellMetadataTO metadata;
Expand Down
4 changes: 2 additions & 2 deletions source/EngineInterface/Descriptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ struct CellDescription
LivingState livingState = LivingState_Ready;
int creatureId = 0;
int mutationId = 0;
int ancestorMutationId = 0;
uint8_t ancestorMutationId = 0;
float genomeComplexity = 0;

//cell function
Expand All @@ -394,7 +394,7 @@ struct CellDescription
CellFunctionDescription cellFunction;
ActivityDescription activity;
int activationTime = 0;
uint8_t detectedByCreatureId = 0; //only the first 8 bits from the creature id
int detectedByCreatureId = 0; //only the first 16 bits from the creature id
CellFunctionUsed cellFunctionUsed = CellFunctionUsed_No;

CellMetadataDescription metadata;
Expand Down
11 changes: 6 additions & 5 deletions source/EngineInterface/SerializerService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,12 @@ namespace
auto constexpr Id_Cell_CreatureId = 11;
auto constexpr Id_Cell_MutationId = 12;
auto constexpr Id_Cell_GenomeComplexity_Deprecated = 13;
auto constexpr Id_Cell_DetectedByCreatureId = 14;
//auto constexpr Id_Cell_DetectedByCreatureId = 14;
auto constexpr Id_Cell_CellFunctionUsed = 15;
// auto constexpr Id_Cell_AncestorMutationId = 16;
auto constexpr Id_Cell_AncestorMutationId = 16;
auto constexpr Id_Cell_GenomeComplexity = 17;
auto constexpr Id_Cell_AncestorMutationId = 18;
//auto constexpr Id_Cell_AncestorMutationId = 18;
auto constexpr Id_Cell_DetectedByCreatureId = 19;

auto constexpr Id_Activity_Origin = 0;
auto constexpr Id_Activity_TargetX = 1;
Expand Down Expand Up @@ -793,13 +794,13 @@ namespace cereal
loadSave<int>(task, auxiliaries, Id_Cell_LivingState, data.livingState, defaultObject.livingState);
loadSave<int>(task, auxiliaries, Id_Cell_CreatureId, data.creatureId, defaultObject.creatureId);
loadSave<int>(task, auxiliaries, Id_Cell_MutationId, data.mutationId, defaultObject.mutationId);
loadSave<int>(task, auxiliaries, Id_Cell_AncestorMutationId, data.ancestorMutationId, defaultObject.ancestorMutationId);
loadSave<uint8_t>(task, auxiliaries, Id_Cell_AncestorMutationId, data.ancestorMutationId, defaultObject.ancestorMutationId);
loadSave<std::optional<int>>(
task, auxiliaries, Id_Cell_InputExecutionOrderNumber, data.inputExecutionOrderNumber, defaultObject.inputExecutionOrderNumber);
loadSave<bool>(task, auxiliaries, Id_Cell_OutputBlocked, data.outputBlocked, defaultObject.outputBlocked);
loadSave<int>(task, auxiliaries, Id_Cell_ActivationTime, data.activationTime, defaultObject.activationTime);
loadSave<float>(task, auxiliaries, Id_Cell_GenomeComplexity, data.genomeComplexity, defaultObject.genomeComplexity);
loadSave<uint8_t>(task, auxiliaries, Id_Cell_DetectedByCreatureId, data.detectedByCreatureId, defaultObject.detectedByCreatureId);
loadSave(task, auxiliaries, Id_Cell_DetectedByCreatureId, data.detectedByCreatureId, defaultObject.detectedByCreatureId);
loadSave<uint8_t>(task, auxiliaries, Id_Cell_CellFunctionUsed, data.cellFunctionUsed, defaultObject.cellFunctionUsed);
processLoadSaveMap(task, ar, auxiliaries);

Expand Down

0 comments on commit 60461aa

Please sign in to comment.