Skip to content
Merged
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
2 changes: 1 addition & 1 deletion source/EngineGpuKernels/AttackerProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ __device__ __inline__ void AttackerProcessor::processCell(SimulationData& data,
auto sumEnergyToTransfer = 0.0f;
data.objectMap.executeForEach(
object->pos, cudaSimulationParameters.attackerRadius.value[object->color], object->detached, [&](auto const& otherObject) {
if (otherObject->type == ObjectType_Structure || otherObject->type == ObjectType_Fluid) {
if (otherObject->type == ObjectType_Solid || otherObject->type == ObjectType_Fluid) {
return;
}
if (otherObject->fixed) {
Expand Down
2 changes: 1 addition & 1 deletion source/EngineGpuKernels/CellProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ __inline__ __device__ void CellProcessor::aging(SimulationData& data)
auto const partition = calcSystemThreadPartition(data.entities.objects.getNumEntries());
for (int index = partition.startIndex; index <= partition.endIndex; index += partition.step) {
auto& object = data.entities.objects.at(index);
if (object->fixed || object->type == ObjectType_Structure || object->type == ObjectType_Fluid) {
if (object->fixed || object->type == ObjectType_Solid || object->type == ObjectType_Fluid) {
continue;
}
uint32_t* age = nullptr;
Expand Down
80 changes: 40 additions & 40 deletions source/EngineGpuKernels/ClusterProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ __device__ __inline__ void ClusterProcessor::initClusterData(SimulationData& dat

for (int index = partition.startIndex; index <= partition.endIndex; index += partition.step) {
auto& object = objects.at(index);
if (object->type != ObjectType_Structure) {
if (object->type != ObjectType_Solid) {
continue;
}
object->typeData.structure.clusterIndex = index;
object->typeData.structure.clusterBoundaries = 0;
object->typeData.structure.clusterPos = {0, 0};
object->typeData.structure.clusterVel = {0, 0};
object->typeData.structure.clusterAngularMass = 0;
object->typeData.structure.clusterAngularMomentum = 0;
object->typeData.structure.numCellsInCluster = 0;
object->typeData.solid.clusterIndex = index;
object->typeData.solid.clusterBoundaries = 0;
object->typeData.solid.clusterPos = {0, 0};
object->typeData.solid.clusterVel = {0, 0};
object->typeData.solid.clusterAngularMass = 0;
object->typeData.solid.clusterAngularMomentum = 0;
object->typeData.solid.numCellsInCluster = 0;
}
}

Expand All @@ -49,7 +49,7 @@ __device__ __inline__ void ClusterProcessor::findClusterIteration(SimulationData

for (int index = partition.startIndex; index <= partition.endIndex; index += partition.step) {
auto currentObject = objects.at(index);
if (currentObject->type != ObjectType_Structure) {
if (currentObject->type != ObjectType_Solid) {
continue;
}

Expand All @@ -58,11 +58,11 @@ __device__ __inline__ void ClusterProcessor::findClusterIteration(SimulationData
bool found = false;
for (int j = 0; j < currentObject->numConnections; ++j) {
auto candidateObject = currentObject->connections[j].object;
if (candidateObject->type != ObjectType_Structure) {
if (candidateObject->type != ObjectType_Solid) {
continue;
}
auto cellTag = currentObject->typeData.structure.clusterIndex;
auto origTag = atomicMin(&candidateObject->typeData.structure.clusterIndex, cellTag);
auto cellTag = currentObject->typeData.solid.clusterIndex;
auto origTag = atomicMin(&candidateObject->typeData.solid.clusterIndex, cellTag);
if (cellTag < origTag) {
currentObject = candidateObject;
found = true;
Expand All @@ -83,15 +83,15 @@ __device__ __inline__ void ClusterProcessor::findClusterBoundaries(SimulationDat

for (int index = partition.startIndex; index <= partition.endIndex; index += partition.step) {
auto object = objects.at(index);
if (object->type != ObjectType_Structure) {
if (object->type != ObjectType_Solid) {
continue;
}
auto cluster = objects.at(object->typeData.structure.clusterIndex);
auto cluster = objects.at(object->typeData.solid.clusterIndex);
if (object->pos.x < data.worldSize.x / 3) {
atomicOr(&cluster->typeData.structure.clusterBoundaries, 1);
atomicOr(&cluster->typeData.solid.clusterBoundaries, 1);
}
if (object->pos.y < data.worldSize.y / 3) {
atomicOr(&cluster->typeData.structure.clusterBoundaries, 2);
atomicOr(&cluster->typeData.solid.clusterBoundaries, 2);
}
}
}
Expand All @@ -103,26 +103,26 @@ __device__ __inline__ void ClusterProcessor::accumulateClusterPosAndVel(Simulati

for (int index = partition.startIndex; index <= partition.endIndex; index += partition.step) {
auto object = objects.at(index);
if (object->type != ObjectType_Structure) {
if (object->type != ObjectType_Solid) {
continue;
}
auto cluster = objects.at(object->typeData.structure.clusterIndex);
atomicAdd(&cluster->typeData.structure.clusterVel.x, object->vel.x);
atomicAdd(&cluster->typeData.structure.clusterVel.y, object->vel.y);
auto cluster = objects.at(object->typeData.solid.clusterIndex);
atomicAdd(&cluster->typeData.solid.clusterVel.x, object->vel.x);
atomicAdd(&cluster->typeData.solid.clusterVel.y, object->vel.y);

//topology correction
auto cellPos = object->pos;
if ((cluster->typeData.structure.clusterBoundaries & 1) == 1 && cellPos.x > data.worldSize.x * 2 / 3) {
if ((cluster->typeData.solid.clusterBoundaries & 1) == 1 && cellPos.x > data.worldSize.x * 2 / 3) {
cellPos.x -= data.worldSize.x;
}
if ((cluster->typeData.structure.clusterBoundaries & 2) == 2 && cellPos.y > data.worldSize.y * 2 / 3) {
if ((cluster->typeData.solid.clusterBoundaries & 2) == 2 && cellPos.y > data.worldSize.y * 2 / 3) {
cellPos.y -= data.worldSize.y;
}

atomicAdd(&cluster->typeData.structure.clusterPos.x, cellPos.x);
atomicAdd(&cluster->typeData.structure.clusterPos.y, cellPos.y);
atomicAdd(&cluster->typeData.solid.clusterPos.x, cellPos.x);
atomicAdd(&cluster->typeData.solid.clusterPos.y, cellPos.y);

atomicAdd(&cluster->typeData.structure.numCellsInCluster, 1);
atomicAdd(&cluster->typeData.solid.numCellsInCluster, 1);
}
}

Expand All @@ -133,27 +133,27 @@ __device__ __inline__ void ClusterProcessor::accumulateClusterAngularProp(Simula

for (int index = partition.startIndex; index <= partition.endIndex; index += partition.step) {
auto object = objects.at(index);
if (object->type != ObjectType_Structure) {
if (object->type != ObjectType_Solid) {
continue;
}
auto cluster = objects.at(object->typeData.structure.clusterIndex);
auto clusterVel = cluster->typeData.structure.clusterVel / cluster->typeData.structure.numCellsInCluster;
auto clusterPos = cluster->typeData.structure.clusterPos / cluster->typeData.structure.numCellsInCluster;
auto cluster = objects.at(object->typeData.solid.clusterIndex);
auto clusterVel = cluster->typeData.solid.clusterVel / cluster->typeData.solid.numCellsInCluster;
auto clusterPos = cluster->typeData.solid.clusterPos / cluster->typeData.solid.numCellsInCluster;

//topology correction
auto cellPos = object->pos;
if ((cluster->typeData.structure.clusterBoundaries & 1) == 1 && cellPos.x > data.worldSize.x * 2 / 3) {
if ((cluster->typeData.solid.clusterBoundaries & 1) == 1 && cellPos.x > data.worldSize.x * 2 / 3) {
cellPos.x -= data.worldSize.x;
}
if ((cluster->typeData.structure.clusterBoundaries & 2) == 2 && cellPos.y > data.worldSize.y * 2 / 3) {
if ((cluster->typeData.solid.clusterBoundaries & 2) == 2 && cellPos.y > data.worldSize.y * 2 / 3) {
cellPos.y -= data.worldSize.y;
}
auto r = cellPos - clusterPos;

auto angularMass = Math::lengthSquared(r);
auto angularMomentum = Physics::angularMomentum(r, object->vel - clusterVel);
atomicAdd(&cluster->typeData.structure.clusterAngularMass, angularMass);
atomicAdd(&cluster->typeData.structure.clusterAngularMomentum, angularMomentum);
atomicAdd(&cluster->typeData.solid.clusterAngularMass, angularMass);
atomicAdd(&cluster->typeData.solid.clusterAngularMomentum, angularMomentum);
}
}

Expand All @@ -164,23 +164,23 @@ __device__ __inline__ void ClusterProcessor::applyClusterData(SimulationData& da

for (int index = partition.startIndex; index <= partition.endIndex; index += partition.step) {
auto object = objects.at(index);
if (object->type != ObjectType_Structure) {
if (object->type != ObjectType_Solid) {
continue;
}
auto cluster = objects.at(object->typeData.structure.clusterIndex);
auto clusterPos = cluster->typeData.structure.clusterPos / cluster->typeData.structure.numCellsInCluster;
auto clusterVel = cluster->typeData.structure.clusterVel / cluster->typeData.structure.numCellsInCluster;
auto cluster = objects.at(object->typeData.solid.clusterIndex);
auto clusterPos = cluster->typeData.solid.clusterPos / cluster->typeData.solid.numCellsInCluster;
auto clusterVel = cluster->typeData.solid.clusterVel / cluster->typeData.solid.numCellsInCluster;

auto cellPos = object->pos;
if ((cluster->typeData.structure.clusterBoundaries & 1) == 1 && cellPos.x > data.worldSize.x * 2 / 3) {
if ((cluster->typeData.solid.clusterBoundaries & 1) == 1 && cellPos.x > data.worldSize.x * 2 / 3) {
cellPos.x -= data.worldSize.x;
}
if ((cluster->typeData.structure.clusterBoundaries & 2) == 2 && cellPos.y > data.worldSize.y * 2 / 3) {
if ((cluster->typeData.solid.clusterBoundaries & 2) == 2 && cellPos.y > data.worldSize.y * 2 / 3) {
cellPos.y -= data.worldSize.y;
}
auto r = cellPos - clusterPos;

auto angularVel = Physics::angularVelocity(cluster->typeData.structure.clusterAngularMomentum, cluster->typeData.structure.clusterAngularMass);
auto angularVel = Physics::angularVelocity(cluster->typeData.solid.clusterAngularMomentum, cluster->typeData.solid.clusterAngularMass);

auto rigidity = ParameterCalculator::calcParameter(cudaSimulationParameters.rigidity, data, object->pos) * object->stiffness * object->stiffness;
object->vel = object->vel * (1.0f - rigidity) + Physics::tangentialVelocity(r, clusterVel, angularVel) * rigidity;
Expand Down
12 changes: 6 additions & 6 deletions source/EngineGpuKernels/DataAccessKernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ namespace
if (nodeTO.cellTypeData.sensor.mode == SensorMode_Telemetry) {
} else if (nodeTO.cellTypeData.sensor.mode == SensorMode_DetectEnergy) {
nodeTO.cellTypeData.sensor.modeData.detectEnergy.minDensity = node.cellTypeData.sensor.modeData.detectEnergy.minDensity;
} else if (nodeTO.cellTypeData.sensor.mode == SensorMode_DetectStructure) {
} else if (nodeTO.cellTypeData.sensor.mode == SensorMode_DetectSolid) {
} else if (nodeTO.cellTypeData.sensor.mode == SensorMode_DetectFreeCell) {
nodeTO.cellTypeData.sensor.modeData.detectFreeCell.minDensity = node.cellTypeData.sensor.modeData.detectFreeCell.minDensity;
nodeTO.cellTypeData.sensor.modeData.detectFreeCell.restrictToColors =
Expand Down Expand Up @@ -177,7 +177,7 @@ namespace
break;
case CellType_Reconnector:
nodeTO.cellTypeData.reconnector.mode = node.cellTypeData.reconnector.mode;
if (node.cellTypeData.reconnector.mode == ReconnectorMode_Structure) {
if (node.cellTypeData.reconnector.mode == ReconnectorMode_Solid) {
} else if (node.cellTypeData.reconnector.mode == ReconnectorMode_FreeCell) {
nodeTO.cellTypeData.reconnector.modeData.reconnectFreeCell.restrictToColors =
node.cellTypeData.reconnector.modeData.reconnectFreeCell.restrictToColors;
Expand Down Expand Up @@ -312,8 +312,8 @@ namespace

object->tempValue1.as_uint64 = objectTOIndex;

if (object->type == ObjectType_Structure) {
objectTO.typeData.structure.energy = object->typeData.structure.energy;
if (object->type == ObjectType_Solid) {
objectTO.typeData.solid.energy = object->typeData.solid.energy;
} else if (object->type == ObjectType_Fluid) {
objectTO.typeData.fluid.energy = object->typeData.fluid.energy;
objectTO.typeData.fluid.glow = object->typeData.fluid.glow;
Expand Down Expand Up @@ -384,7 +384,7 @@ namespace
if (cellTO.cellTypeData.sensor.mode == SensorMode_Telemetry) {
} else if (cellTO.cellTypeData.sensor.mode == SensorMode_DetectEnergy) {
cellTO.cellTypeData.sensor.modeData.detectEnergy.minDensity = cell.cellTypeData.sensor.modeData.detectEnergy.minDensity;
} else if (cellTO.cellTypeData.sensor.mode == SensorMode_DetectStructure) {
} else if (cellTO.cellTypeData.sensor.mode == SensorMode_DetectSolid) {
} else if (cellTO.cellTypeData.sensor.mode == SensorMode_DetectFreeCell) {
cellTO.cellTypeData.sensor.modeData.detectFreeCell.minDensity = cell.cellTypeData.sensor.modeData.detectFreeCell.minDensity;
cellTO.cellTypeData.sensor.modeData.detectFreeCell.restrictToColors = cell.cellTypeData.sensor.modeData.detectFreeCell.restrictToColors;
Expand Down Expand Up @@ -463,7 +463,7 @@ namespace
} break;
case CellType_Reconnector: {
cellTO.cellTypeData.reconnector.mode = cell.cellTypeData.reconnector.mode;
if (cell.cellTypeData.reconnector.mode == ReconnectorMode_Structure) {
if (cell.cellTypeData.reconnector.mode == ReconnectorMode_Solid) {
} else if (cell.cellTypeData.reconnector.mode == ReconnectorMode_FreeCell) {
cellTO.cellTypeData.reconnector.modeData.reconnectFreeCell.restrictToColors =
cell.cellTypeData.reconnector.modeData.reconnectFreeCell.restrictToColors;
Expand Down
2 changes: 1 addition & 1 deletion source/EngineGpuKernels/EnergyProcessor.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ __inline__ __device__ void EnergyProcessor::collision(SimulationData& data)
}
} else {
if (auto object = data.objectMap.getFirst(particle->pos + particle->vel)) {
if (object->type == ObjectType_Structure || object->type == ObjectType_Fluid) {
if (object->type == ObjectType_Solid || object->type == ObjectType_Fluid) {
continue;
}
if (object->fixed) {
Expand Down
18 changes: 9 additions & 9 deletions source/EngineGpuKernels/Entities.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ struct DetectEnergy
float minDensity;
};

struct DetectStructure
struct DetectSolid
{};

struct DetectFreeCell
Expand All @@ -122,7 +122,7 @@ union SensorModeData
{
Telemetry telemetry;
DetectEnergy detectEnergy;
DetectStructure detectStructure;
DetectSolid detectSolid;
DetectFreeCell detectFreeCell;
DetectCreature detectCreature;
};
Expand Down Expand Up @@ -292,7 +292,7 @@ struct Defender
DefenderMode mode;
};

struct ReconnectStructure
struct ReconnectSolid
{};

struct ReconnectFreeCell
Expand All @@ -310,7 +310,7 @@ struct ReconnectCreature

union ReconnectorModeData
{
ReconnectStructure reconnectStructure;
ReconnectSolid reconnectSolid;
ReconnectFreeCell reconnectFreeCell;
ReconnectCreature reconnectCreature;
};
Expand Down Expand Up @@ -458,7 +458,7 @@ struct Creature
uint64_t creatureIndex; // May be invalid
};

struct Structure
struct Solid
{
float energy;

Expand Down Expand Up @@ -506,7 +506,7 @@ struct Cell
uint16_t geneIndex;

// Cell type data
NeuralNet* neuralNetwork; // Not used for structure and base cells
NeuralNet* neuralNetwork;
CellType cellType;
CellTypeData cellTypeData;
bool constructorAvailable; // If true, constructor holds valid data
Expand Down Expand Up @@ -541,7 +541,7 @@ struct Cell

union ObjectTypeData
{
Structure structure;
Solid solid;
Fluid fluid;
FreeCell freeCell;
Cell cell;
Expand Down Expand Up @@ -614,8 +614,8 @@ struct Object
return typeData.cell.getEnergy();
} else if (type == ObjectType_FreeCell) {
return typeData.freeCell.energy;
} else if (type == ObjectType_Structure) {
return typeData.structure.energy;
} else if (type == ObjectType_Solid) {
return typeData.solid.energy;
} else if (type == ObjectType_Fluid) {
return typeData.fluid.energy;
} else {
Expand Down
Loading
Loading