Skip to content

Commit 8715022

Browse files
committed
introduce cell events for rendering of attackes
1 parent 3e61ef3 commit 8715022

9 files changed

+52
-11
lines changed

source/Base/Resources.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Const
44
{
5-
std::string const ProgramVersion = "4.9.1";
5+
std::string const ProgramVersion = "4.10.0";
66
std::string const DiscordURL = "https://discord.gg/7bjyZdXXQ2";
77

88
std::string const BasePath = "resources/";

source/EngineGpuKernels/AttackerProcessor.cuh

+5-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ __device__ __inline__ void AttackerProcessor::processCell(SimulationData& data,
147147
if (energyToTransfer > NEAR_ZERO) {
148148

149149
//notify attacked cell
150-
atomicExch(&otherCell->activity.channels[7], AttackNotificationActivity);
150+
atomicAdd(&otherCell->activity.channels[7], 1.0f);
151+
otherCell->event = CellEvent_Hit;
152+
otherCell->eventCounter = 6;
151153

152154
auto origEnergy = atomicAdd(&otherCell->energy, -energyToTransfer);
153155
if (origEnergy > baseValue + energyToTransfer) {
@@ -180,6 +182,8 @@ __device__ __inline__ void AttackerProcessor::processCell(SimulationData& data,
180182
activity.channels[0] = energyDelta / 10;
181183

182184
if (energyDelta > NEAR_ZERO) {
185+
cell->event = CellEvent_Attacking;
186+
cell->eventCounter = 6;
183187
statistics.incNumAttacks(cell->color);
184188
}
185189
}

source/EngineGpuKernels/CellFunctionProcessor.cuh

+14
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class CellFunctionProcessor
1010
{
1111
public:
1212
__inline__ __device__ static void collectCellFunctionOperations(SimulationData& data);
13+
__inline__ __device__ static void updateRenderingData(SimulationData& data);
1314
__inline__ __device__ static void resetFetchedActivities(SimulationData& data);
1415

1516
__inline__ __device__ static Activity calcInputActivity(Cell* cell);
@@ -47,6 +48,19 @@ __inline__ __device__ void CellFunctionProcessor::collectCellFunctionOperations(
4748
}
4849
}
4950

51+
__inline__ __device__ void CellFunctionProcessor::updateRenderingData(SimulationData& data)
52+
{
53+
auto& cells = data.objects.cellPointers;
54+
auto partition = calcAllThreadsPartition(cells.getNumEntries());
55+
56+
for (int index = partition.startIndex; index <= partition.endIndex; ++index) {
57+
auto& cell = cells.at(index);
58+
if (cell->eventCounter > 0) {
59+
--cell->eventCounter;
60+
}
61+
}
62+
}
63+
5064
__inline__ __device__ void CellFunctionProcessor::resetFetchedActivities(SimulationData& data)
5165
{
5266
auto& cells = data.objects.cellPointers;

source/EngineGpuKernels/Object.cuh

+4
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ struct Cell
225225
//annotations
226226
CellMetadataDescription metadata;
227227

228+
//additional rendering data
229+
CellEvent event;
230+
uint8_t eventCounter;
231+
228232
//editing data
229233
uint8_t selected; //0 = no, 1 = selected, 2 = cluster selected
230234
uint8_t detached; //0 = no, 1 = yes

source/EngineGpuKernels/ObjectFactory.cuh

+6
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ __inline__ __device__ Cell* ObjectFactory::createCellFromTO(DataTO const& dataTO
7474
cell->selected = 0;
7575
cell->scheduledOperationIndex = -1;
7676
cell->numConnections = cellTO.numConnections;
77+
cell->event = CellEvent_No;
78+
cell->eventCounter = 0;
7779
for (int i = 0; i < cell->numConnections; ++i) {
7880
auto& connectingCell = cell->connections[i];
7981
connectingCell.cell = cellTargetArray + cellTO.connections[i].cellIndex;
@@ -278,6 +280,8 @@ __inline__ __device__ Cell* ObjectFactory::createRandomCell(float energy, float2
278280
cell->creatureId = 0;
279281
cell->mutationId = 0;
280282
cell->detectedByCreatureId = 0;
283+
cell->event = CellEvent_No;
284+
cell->eventCounter = 0;
281285

282286
if (cudaSimulationParameters.particleTransformationRandomCellFunction) {
283287
cell->cellFunction = _data->numberGen1.random(CellFunction_Count - 1);
@@ -392,5 +396,7 @@ __inline__ __device__ Cell* ObjectFactory::createCell(uint64_t& cellPointerIndex
392396
}
393397
cell->density = 1.0f;
394398
cell->detectedByCreatureId = 0;
399+
cell->event = CellEvent_No;
400+
cell->eventCounter = 0;
395401
return cell;
396402
}

source/EngineGpuKernels/RenderingKernels.cu

+13-7
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,15 @@ namespace
261261
if (radius2 > 2.5 - NEAR_ZERO) {
262262
auto radiusSquared1 = radius1 * radius1;
263263
auto radiusSquared2 = radius2 * radius2;
264+
auto middleRadiusSquared = (radiusSquared1 + radiusSquared2) / 2;
265+
264266
for (float x = -radius2; x <= radius2; x += 1.0f) {
265267
for (float y = -radius2; y <= radius2; y += 1.0f) {
266268
auto rSquared = x * x + y * y;
267269
if (rSquared <= radiusSquared2 && rSquared >= radiusSquared1) {
268-
drawDot(imageData, imageSize, pos + float2{x, y}, color);
270+
auto weight = rSquared < middleRadiusSquared ? (rSquared - radiusSquared1) / (middleRadiusSquared - radiusSquared1)
271+
: (radiusSquared2 - rSquared) / (radiusSquared2 - middleRadiusSquared);
272+
drawDot(imageData, imageSize, pos + float2{x, y}, color * weight * 0.6f);
269273
}
270274
}
271275
}
@@ -402,12 +406,14 @@ __global__ void cudaDrawCells(uint64_t timestep, int2 worldSize, float2 rectUppe
402406
drawCircle(imageData, imageSize, cellImagePos, float3{0.3f, 0.3f, 0.3f}, radius, shadedCells);
403407
}
404408

405-
//draw attacks
406-
if (cell->cellFunction == CellFunction_Attacker && abs(cell->activity.channels[0]) > NEAR_ZERO) {
407-
drawDisc(imageData, imageSize, cellImagePos, {0.0f, 1.0f, 0.0f}, radius * 1.4f, radius * 2.0f);
408-
}
409-
if (abs(cell->activity.channels[7] - AttackNotificationActivity) < NEAR_ZERO) {
410-
drawDisc(imageData, imageSize, cellImagePos, {1.0f, 0.0f, 0.0f}, radius * 1.4f, radius * 2.0f);
409+
//draw events
410+
if (cell->eventCounter > 0) {
411+
if (cell->event == CellEvent_Attacking) {
412+
drawDisc(imageData, imageSize, cellImagePos, {0.0f, 1.0f, 0.0f}, radius * 1.4f, radius * 2.0f);
413+
}
414+
if (cell->event == CellEvent_Hit) {
415+
drawDisc(imageData, imageSize, cellImagePos, {1.0f, 0.0f, 0.0f}, radius * 1.4f, radius * 2.0f);
416+
}
411417
}
412418

413419
//draw detonation

source/EngineGpuKernels/SimulationKernels.cu

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ __global__ void cudaNextTimestep_cellFunction_prepare_substep2(SimulationData da
8484
{
8585
CellProcessor::livingStateTransition(data);
8686
CellFunctionProcessor::collectCellFunctionOperations(data);
87+
CellFunctionProcessor::updateRenderingData(data);
8788
}
8889

8990
__global__ void cudaNextTimestep_cellFunction_nerve(SimulationData data, SimulationStatistics statistics)

source/EngineInterface/CellFunctionConstants.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,10 @@ enum DetonatorState_
126126
DetonatorState_Exploded
127127
};
128128

129-
auto constexpr AttackNotificationActivity = 0.95f;
129+
using CellEvent = int;
130+
enum CellEvent_
131+
{
132+
CellEvent_No,
133+
CellEvent_Hit,
134+
CellEvent_Attacking
135+
};

vcpkg.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "alien",
3-
"version": "4.9.1",
3+
"version": "4.10.0",
44
"dependencies": [
55
{
66
"name": "glew",

0 commit comments

Comments
 (0)