Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions source/EngineImpl/DescConverterService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,6 @@ ObjectDesc DescConverterService::createObjectDesc(TOs const& to, int objectIndex
if (communicatorTO.mode == CommunicatorMode_Sender) {
SenderDesc sender;
sender._range = communicatorTO.modeData.sender.range;
sender._maxTimesSent = communicatorTO.modeData.sender.maxTimesSent;
communicator._mode = sender;
} else if (communicatorTO.mode == CommunicatorMode_Receiver) {
ReceiverDesc receiver;
Expand Down Expand Up @@ -612,7 +611,6 @@ ObjectDesc DescConverterService::createObjectDesc(TOs const& to, int objectIndex
for (int i = 0; i < NEURONS_PER_CELL; ++i) {
cellDesc._signal._channels[i] = objectTO.typeData.cell.signal.channels[i];
}
cellDesc._signal._numTimesSent = objectTO.typeData.cell.signal.numTimesSent;
cellDesc._activationTime = objectTO.typeData.cell.activationTime;
result._type = cellDesc;

Expand Down Expand Up @@ -823,7 +821,6 @@ NodeDesc DescConverterService::createNodeDesc(TOs const& to, NodeTO const* nodeT
if (communicatorTO.mode == CommunicatorMode_Sender) {
SenderGenomeDesc sender;
sender._range = communicatorTO.modeData.sender.range;
sender._maxTimesSent = communicatorTO.modeData.sender.maxTimesSent;
communicatorDesc._mode = sender;
} else if (communicatorTO.mode == CommunicatorMode_Receiver) {
ReceiverGenomeDesc receiver;
Expand Down Expand Up @@ -1201,7 +1198,6 @@ void DescConverterService::convertGenomeToTO(
if (communicatorTO.mode == CommunicatorMode_Sender) {
auto const& senderDesc = std::get<SenderGenomeDesc>(communicatorDesc._mode);
communicatorTO.modeData.sender.range = static_cast<uint8_t>(senderDesc._range);
communicatorTO.modeData.sender.maxTimesSent = senderDesc._maxTimesSent;
} else if (communicatorTO.mode == CommunicatorMode_Receiver) {
auto const& receiverDesc = std::get<ReceiverGenomeDesc>(communicatorDesc._mode);
communicatorTO.modeData.receiver.restrictToColors = static_cast<uint16_t>(receiverDesc._restrictToColors);
Expand Down Expand Up @@ -1528,7 +1524,6 @@ void DescConverterService::convertObjectToTO(
if (communicatorTO.mode == CommunicatorMode_Sender) {
auto const& senderDesc = std::get<SenderDesc>(communicatorDesc._mode);
communicatorTO.modeData.sender.range = static_cast<uint8_t>(senderDesc._range);
communicatorTO.modeData.sender.maxTimesSent = senderDesc._maxTimesSent;
} else if (communicatorTO.mode == CommunicatorMode_Receiver) {
auto const& receiverDesc = std::get<ReceiverDesc>(communicatorDesc._mode);
communicatorTO.modeData.receiver.restrictToColors = static_cast<uint16_t>(receiverDesc._restrictToColors);
Expand Down Expand Up @@ -1561,7 +1556,6 @@ void DescConverterService::convertObjectToTO(
for (int i = 0; i < NEURONS_PER_CELL && i < numChannels; ++i) {
objectTO.typeData.cell.signal.channels[i] = cellDesc._signal._channels[i];
}
objectTO.typeData.cell.signal.numTimesSent = cellDesc._signal._numTimesSent;
} else {
CHECK(false);
}
Expand Down
2 changes: 0 additions & 2 deletions source/EngineInterface/CellTypeConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,6 @@ namespace Const
auto constexpr CommunicatorRange_Min = 0;
auto constexpr CommunicatorRange_Max = 20;
auto constexpr CommunicatorRange_Default = 15;
auto constexpr CommunicatorMaxTimesSent_Min = 0;
auto constexpr CommunicatorMaxTimesSent_Default = 4;
}

using CommunicatorMode = int;
Expand Down
3 changes: 0 additions & 3 deletions source/EngineInterface/Desc.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@ struct SenderDesc
auto operator<=>(SenderDesc const&) const = default;

MEMBER(SenderDesc, int, range, Const::CommunicatorRange_Default);
MEMBER(SenderDesc, int, maxTimesSent, Const::CommunicatorMaxTimesSent_Default);
};

struct ReceiverDesc
Expand Down Expand Up @@ -459,8 +458,6 @@ struct SignalDesc

SignalDesc& channels(std::vector<float> const& value);
std::vector<float> _channels;

MEMBER(SignalDesc, int, numTimesSent, 0);
};

struct SolidDesc
Expand Down
2 changes: 0 additions & 2 deletions source/EngineInterface/DescValidationService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ void DescValidationService::validateAndCorrect(GenomeDesc& genome)
if (communicatorMode == CommunicatorMode_Sender) {
auto& sender = std::get<SenderGenomeDesc>(communicator._mode);
sender._range = std::clamp(sender._range, Const::CommunicatorRange_Min, Const::CommunicatorRange_Max);
sender._maxTimesSent = std::clamp(sender._maxTimesSent, Const::CommunicatorMaxTimesSent_Min, 10);
} else if (communicatorMode == CommunicatorMode_Receiver) {
auto& receiver = std::get<ReceiverGenomeDesc>(communicator._mode);
receiver._restrictToColors =
Expand Down Expand Up @@ -482,7 +481,6 @@ void DescValidationService::validateAndCorrect(ExtendedObjectDesc& extendedObjec
if (communicatorMode == CommunicatorMode_Sender) {
auto& sender = std::get<SenderDesc>(communicator._mode);
sender._range = std::clamp(sender._range, 0, 20);
sender._maxTimesSent = std::max(sender._maxTimesSent, 0);
} else if (communicatorMode == CommunicatorMode_Receiver) {
auto& receiver = std::get<ReceiverDesc>(communicator._mode);
receiver._restrictToColors &= (1 << MAX_COLORS) - 1;
Expand Down
1 change: 0 additions & 1 deletion source/EngineInterface/GenomeDesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ struct SenderGenomeDesc
auto operator<=>(SenderGenomeDesc const&) const = default;

MEMBER(SenderGenomeDesc, int, range, Const::CommunicatorRange_Default);
MEMBER(SenderGenomeDesc, int, maxTimesSent, Const::CommunicatorMaxTimesSent_Default);
};

struct ReceiverGenomeDesc
Expand Down
1 change: 0 additions & 1 deletion source/EngineInterface/GenomeDescHash.h
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,6 @@ struct std::hash<SenderGenomeDesc>
{
std::size_t seed = 0;
hash_combine(seed, desc._range);
hash_combine(seed, desc._maxTimesSent);
return seed;
}
};
Expand Down
49 changes: 29 additions & 20 deletions source/EngineKernels/CommunicatorProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ private:
__inline__ __device__ static void processCell(SimulationData& data, SimulationStatistics& statistics, Object* object);
__inline__ __device__ static void processSender(SimulationData& data, SimulationStatistics& statistics, Object* object);

__inline__ __device__ static void tryTransmitSignal(SimulationData& data, Object* senderObject, Object* receiverObject, int newNumTimesSent);
__inline__ __device__ static void tryTransmitSignal(SimulationData& data, Object* senderObject, Object* receiverObject);
};

/************************************************************************/
Expand Down Expand Up @@ -52,26 +52,29 @@ __device__ __inline__ void CommunicatorProcessor::processCell(SimulationData& da
__device__ __inline__ void CommunicatorProcessor::processSender(SimulationData& data, SimulationStatistics& statistics, Object* object)
{
__shared__ int range;
__shared__ int maxTimesSent;
__shared__ int currentNumTimesSent;
__shared__ float2 senderPos;
__shared__ bool senderFrontValid;
__shared__ float2 senderFacing; // Absolute direction encoded by the signal angle relative to the front direction

if (threadIdx.x == 0) {
auto& sender = object->typeData.cell.cellTypeData.communicator.modeData.sender;
auto& cell = object->typeData.cell;
auto& sender = cell.cellTypeData.communicator.modeData.sender;
range = sender.range;
maxTimesSent = sender.maxTimesSent;
currentNumTimesSent = object->typeData.cell.signal.numTimesSent;
senderPos = object->pos;
senderFrontValid = cell.frontAngle != VALUE_NOT_SET_FLOAT;
if (senderFrontValid) {
auto refAngle = Math::angleOfVector(ObjectConnectionProcessor::calcReferenceDirection(data, object));
auto encodedAngle = cell.signal.channels[Channels::CommunicatorAngle];
senderFacing = Math::unitVectorOfAngle(refAngle + cell.frontAngle + encodedAngle * 180.0f);
}
}
__syncthreads();

// Check if signal can still be forwarded
if (currentNumTimesSent >= maxTimesSent) {
// The sender must have an initialized front direction
if (!senderFrontValid) {
return;
}

auto const newNumTimesSent = currentNumTimesSent + 1;

// Matching lambda to check if a cell is a valid receiver
auto isMatch = [&object](Object* otherObject) {
// Must be a communicator in receiver mode
Expand Down Expand Up @@ -136,29 +139,35 @@ __device__ __inline__ void CommunicatorProcessor::processSender(SimulationData&
auto const& otherRecord = records[otherIndex];
auto otherObject = otherRecord.self;
if (isMatch(otherObject)) {
tryTransmitSignal(data, object, otherObject, newNumTimesSent);
// The receiver must have an initialized front direction
if (otherObject->typeData.cell.frontAngle != VALUE_NOT_SET_FLOAT) {
// Direction gating: only send if the receiver lies in the half-plane opposite to the encoded facing direction
auto toReceiver = data.objectMap.getCorrectedDirection(otherObject->pos - senderPos);
if (Math::dot(toReceiver, senderFacing) <= 0) {
tryTransmitSignal(data, object, otherObject);
}
}
}
otherIndex = otherRecord.nextObjectIndex;
}
}
}

__inline__ __device__ void CommunicatorProcessor::tryTransmitSignal(SimulationData& data, Object* senderObject, Object* receiverObject, int newNumTimesSent)
__inline__ __device__ void CommunicatorProcessor::tryTransmitSignal(SimulationData& data, Object* senderObject, Object* receiverObject)
{
receiverObject->getLock();

// Copy signal to receiver with incremented numTimesSent
// Copy signal to receiver
copyChannels(receiverObject->typeData.cell.signal.channels, senderObject->typeData.cell.signal.channels);
receiverObject->typeData.cell.signal.numTimesSent = newNumTimesSent;

// Translate angle in channel[1] from sender's reference direction to receiver's reference direction
// The angle is encoded as value/180 degrees, where 1.0 = 180 deg and -1.0 = -180 deg
// We need to maintain the absolute direction: senderRefDir rotated by senderAngle = receiverRefDir rotated by receiverAngle
// Therefore: receiverAngle = senderAngle + (senderRefAngle - receiverRefAngle)
// Translate angle in channel[1] from the sender's absolute front direction to the receiver's absolute front direction
// The angle is encoded as value/180 degrees relative to the front direction, where 1.0 = 180 deg and -1.0 = -180 deg
// We need to maintain the absolute direction: senderFront rotated by senderAngle = receiverFront rotated by receiverAngle
// Therefore: receiverAngle = senderAngle + (senderFrontAngle - receiverFrontAngle)
auto senderRefDir = ObjectConnectionProcessor::calcReferenceDirection(data, senderObject);
auto receiverRefDir = ObjectConnectionProcessor::calcReferenceDirection(data, receiverObject);
auto senderRefAngle = Math::angleOfVector(senderRefDir);
auto receiverRefAngle = Math::angleOfVector(receiverRefDir);
auto senderRefAngle = Math::angleOfVector(senderRefDir) + senderObject->typeData.cell.frontAngle;
auto receiverRefAngle = Math::angleOfVector(receiverRefDir) + receiverObject->typeData.cell.frontAngle;
auto angleDiff = senderRefAngle - receiverRefAngle;

// The signal angle is encoded as angle/180, so the diff must also be scaled
Expand Down
3 changes: 0 additions & 3 deletions source/EngineKernels/DataAccessKernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ namespace
nodeTO.cellTypeData.communicator.mode = node.cellTypeData.communicator.mode;
if (node.cellTypeData.communicator.mode == CommunicatorMode_Sender) {
nodeTO.cellTypeData.communicator.modeData.sender.range = node.cellTypeData.communicator.modeData.sender.range;
nodeTO.cellTypeData.communicator.modeData.sender.maxTimesSent = node.cellTypeData.communicator.modeData.sender.maxTimesSent;
} else if (node.cellTypeData.communicator.mode == CommunicatorMode_Receiver) {
nodeTO.cellTypeData.communicator.modeData.receiver.restrictToColors =
node.cellTypeData.communicator.modeData.receiver.restrictToColors;
Expand Down Expand Up @@ -354,7 +353,6 @@ namespace
for (int i = 0; i < NEURONS_PER_CELL; ++i) {
cellTO.signal.channels[i] = cell.signal.channels[i];
}
cellTO.signal.numTimesSent = cell.signal.numTimesSent;
cellTO.activationTime = cell.activationTime;
cellTO.lastUpdate = cell.lastUpdate;
cellTO.concatenationIndex = cell.concatenationIndex;
Expand Down Expand Up @@ -540,7 +538,6 @@ namespace
cellTO.cellTypeData.communicator.mode = cell.cellTypeData.communicator.mode;
if (cell.cellTypeData.communicator.mode == CommunicatorMode_Sender) {
cellTO.cellTypeData.communicator.modeData.sender.range = cell.cellTypeData.communicator.modeData.sender.range;
cellTO.cellTypeData.communicator.modeData.sender.maxTimesSent = cell.cellTypeData.communicator.modeData.sender.maxTimesSent;
} else if (cell.cellTypeData.communicator.mode == CommunicatorMode_Receiver) {
cellTO.cellTypeData.communicator.modeData.receiver.restrictToColors = cell.cellTypeData.communicator.modeData.receiver.restrictToColors;
cellTO.cellTypeData.communicator.modeData.receiver.restrictToLineage = cell.cellTypeData.communicator.modeData.receiver.restrictToLineage;
Expand Down
2 changes: 0 additions & 2 deletions source/EngineKernels/Entities.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ struct Memory
struct Sender
{
uint8_t range;
int maxTimesSent;
};

struct Receiver
Expand Down Expand Up @@ -424,7 +423,6 @@ union CellTypeData
struct __align__(16) Signal
{
float channels[NEURONS_PER_CELL];
int numTimesSent;
};

struct uint32_float
Expand Down
5 changes: 0 additions & 5 deletions source/EngineKernels/EntityFactory.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ __inline__ __device__ Genome* EntityFactory::createGenomeFromTO(TOs const& to, i
node.cellTypeData.communicator.mode = nodeTO.cellTypeData.communicator.mode;
if (nodeTO.cellTypeData.communicator.mode == CommunicatorMode_Sender) {
node.cellTypeData.communicator.modeData.sender.range = nodeTO.cellTypeData.communicator.modeData.sender.range;
node.cellTypeData.communicator.modeData.sender.maxTimesSent = nodeTO.cellTypeData.communicator.modeData.sender.maxTimesSent;
} else if (nodeTO.cellTypeData.communicator.mode == CommunicatorMode_Receiver) {
node.cellTypeData.communicator.modeData.receiver.restrictToColors = nodeTO.cellTypeData.communicator.modeData.receiver.restrictToColors;
node.cellTypeData.communicator.modeData.receiver.restrictToLineage = nodeTO.cellTypeData.communicator.modeData.receiver.restrictToLineage;
Expand Down Expand Up @@ -412,7 +411,6 @@ __inline__ __device__ void EntityFactory::changeObjectFromTO(TOs const& to, Obje
for (int i = 0; i < NEURONS_PER_CELL; ++i) {
cell->signal.channels[i] = cellTO.signal.channels[i];
}
cell->signal.numTimesSent = cellTO.signal.numTimesSent;
cell->signalChanges = cellTO.signalChanges;

cell->cellType = cellTO.cellType;
Expand Down Expand Up @@ -577,7 +575,6 @@ __inline__ __device__ void EntityFactory::changeObjectFromTO(TOs const& to, Obje
cell->cellTypeData.communicator.mode = cellTO.cellTypeData.communicator.mode;
if (cellTO.cellTypeData.communicator.mode == CommunicatorMode_Sender) {
cell->cellTypeData.communicator.modeData.sender.range = cellTO.cellTypeData.communicator.modeData.sender.range;
cell->cellTypeData.communicator.modeData.sender.maxTimesSent = cellTO.cellTypeData.communicator.modeData.sender.maxTimesSent;
} else if (cellTO.cellTypeData.communicator.mode == CommunicatorMode_Receiver) {
cell->cellTypeData.communicator.modeData.receiver.restrictToColors = cellTO.cellTypeData.communicator.modeData.receiver.restrictToColors;
cell->cellTypeData.communicator.modeData.receiver.restrictToLineage = cellTO.cellTypeData.communicator.modeData.receiver.restrictToLineage;
Expand Down Expand Up @@ -767,7 +764,6 @@ __inline__ __device__ Object* EntityFactory::createCellFromNode(
for (int i = 0; i < NEURONS_PER_CELL; ++i) {
cell.signal.channels[i] = 0.0f;
}
cell.signal.numTimesSent = 0;
cell.signalChanges = 0;

cell.neuralNetwork = _data->entities.heap.getTypedSubArray<NeuralNet>(1);
Expand Down Expand Up @@ -963,7 +959,6 @@ __inline__ __device__ Object* EntityFactory::createCellFromNode(
communicator.mode = nodeCommunicator.mode;
if (nodeCommunicator.mode == CommunicatorMode_Sender) {
communicator.modeData.sender.range = nodeCommunicator.modeData.sender.range;
communicator.modeData.sender.maxTimesSent = nodeCommunicator.modeData.sender.maxTimesSent;
} else if (nodeCommunicator.mode == CommunicatorMode_Receiver) {
communicator.modeData.receiver.restrictToColors = nodeCommunicator.modeData.receiver.restrictToColors;
communicator.modeData.receiver.restrictToLineage = nodeCommunicator.modeData.receiver.restrictToLineage;
Expand Down
1 change: 0 additions & 1 deletion source/EngineKernels/Genome.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ struct MemoryGenome
struct SenderGenome
{
uint8_t range;
int maxTimesSent;
};

struct ReceiverGenome
Expand Down
1 change: 0 additions & 1 deletion source/EngineKernels/GenomeTO.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ struct MemoryGenomeTO
struct SenderGenomeTO
{
uint8_t range;
int maxTimesSent;
};

struct ReceiverGenomeTO
Expand Down
3 changes: 1 addition & 2 deletions source/EngineKernels/MutationProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,6 @@ __inline__ __device__ void MutationProcessor::applyMutations_cellTypeProperties(
switch (node.cellTypeData.communicator.mode) {
case CommunicatorMode_Sender:
mutateNumber(node.cellTypeData.communicator.modeData.sender.range, Const::CommunicatorRange_Min, Const::CommunicatorRange_Max);
mutateNumber(node.cellTypeData.communicator.modeData.sender.maxTimesSent, Const::CommunicatorMaxTimesSent_Min, 10);
break;
case CommunicatorMode_Receiver:
mutateBitset(node.cellTypeData.communicator.modeData.receiver.restrictToColors, Const::RestrictToColors_Max);
Expand Down Expand Up @@ -583,7 +582,7 @@ __inline__ __device__ void MutationProcessor::resetCellTypeModeToDefault(Node& n
auto& communicator = node.cellTypeData.communicator;
switch (communicator.mode) {
case CommunicatorMode_Sender:
communicator.modeData.sender = {Const::CommunicatorRange_Default, Const::CommunicatorMaxTimesSent_Default};
communicator.modeData.sender = {Const::CommunicatorRange_Default};
break;
case CommunicatorMode_Receiver:
communicator.modeData.receiver = {Const::RestrictToColors_Default, LineageRestriction_No};
Expand Down
Loading
Loading