Skip to content

Commit 0c494b5

Browse files
committed
fix static wall hitbox when bursting off of them, allow multiple debug points to be rendered
1 parent a4d396f commit 0c494b5

File tree

4 files changed

+64
-34
lines changed

4 files changed

+64
-34
lines changed

pufferlib/ocean/impulse_wars/env.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,10 @@ iwEnv *initEnv(iwEnv *e, uint8_t numDrones, uint8_t numAgents, int8_t mapIdx, ui
596596
e->humanDroneInput = 0;
597597
e->connectedControllers = 0;
598598

599+
#ifndef NDEBUG
600+
create_array(&e->debugPoints, 4);
601+
#endif
602+
599603
return e;
600604
}
601605

@@ -701,6 +705,10 @@ void destroyEnv(iwEnv *e) {
701705
cc_array_destroy(e->dronePieces);
702706

703707
b2DestroyWorld(e->worldID);
708+
709+
#ifndef NDEBUG
710+
cc_array_destroy(e->debugPoints);
711+
#endif
704712
}
705713

706714
void resetEnv(iwEnv *e) {
@@ -1027,6 +1035,7 @@ void addLog(iwEnv *e, Log *log) {
10271035
e->log.n += 1.0f;
10281036
}
10291037

1038+
// TODO: 2nd agent doesn't seem to work right
10301039
void stepEnv(iwEnv *e) {
10311040
if (e->needsReset) {
10321041
DEBUG_LOG("Resetting environment");
@@ -1038,6 +1047,14 @@ void stepEnv(iwEnv *e) {
10381047
#endif
10391048
}
10401049

1050+
#ifndef NDEBUG
1051+
for (uint8_t i = 0; i < cc_array_size(e->debugPoints); i++) {
1052+
debugPoint *point = safe_array_get_at(e->debugPoints, i);
1053+
fastFree(point);
1054+
}
1055+
cc_array_remove_all(e->debugPoints);
1056+
#endif
1057+
10411058
agentActions stepActions[e->numDrones];
10421059
memset(stepActions, 0x0, e->numDrones * sizeof(agentActions));
10431060

pufferlib/ocean/impulse_wars/game.h

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,12 @@ bool isOverlappingAABB(const iwEnv *e, const b2Vec2 pos, const float distance, c
102102
return ctx.overlaps;
103103
}
104104

105-
// TODO: store a shape proxy in entities?
106-
b2ShapeProxy makeDistanceProxyFromType(const enum entityType type, bool *isCircle) {
105+
b2ShapeProxy makeDistanceProxy(const entity *ent, bool *isCircle) {
107106
b2ShapeProxy proxy = {0};
108-
switch (type) {
107+
float extent = 0.0f;
108+
wallEntity *wall = NULL;
109+
110+
switch (ent->type) {
109111
case DRONE_ENTITY:
110112
*isCircle = true;
111113
proxy.count = 1;
@@ -116,42 +118,44 @@ b2ShapeProxy makeDistanceProxyFromType(const enum entityType type, bool *isCircl
116118
proxy.count = 1;
117119
proxy.radius = DRONE_SHIELD_RADIUS;
118120
break;
121+
case PROJECTILE_ENTITY:
122+
*isCircle = true;
123+
const projectileEntity *proj = ent->entity;
124+
proxy.count = 1;
125+
proxy.radius = proj->weaponInfo->radius;
126+
break;
119127
case WEAPON_PICKUP_ENTITY:
128+
extent = PICKUP_THICKNESS / 2.0f;
129+
120130
proxy.count = 4;
121-
proxy.points[0] = (b2Vec2){.x = -PICKUP_THICKNESS / 2.0f, .y = -PICKUP_THICKNESS / 2.0f};
122-
proxy.points[1] = (b2Vec2){.x = -PICKUP_THICKNESS / 2.0f, .y = +PICKUP_THICKNESS / 2.0f};
123-
proxy.points[2] = (b2Vec2){.x = +PICKUP_THICKNESS / 2.0f, .y = -PICKUP_THICKNESS / 2.0f};
124-
proxy.points[3] = (b2Vec2){.x = +PICKUP_THICKNESS / 2.0f, .y = +PICKUP_THICKNESS / 2.0f};
131+
proxy.points[0] = (b2Vec2){.x = -extent, .y = -extent};
132+
proxy.points[1] = (b2Vec2){.x = -extent, .y = +extent};
133+
proxy.points[2] = (b2Vec2){.x = +extent, .y = -extent};
134+
proxy.points[3] = (b2Vec2){.x = +extent, .y = +extent};
125135
break;
126136
case STANDARD_WALL_ENTITY:
127137
case BOUNCY_WALL_ENTITY:
128138
case DEATH_WALL_ENTITY:
139+
extent = WALL_THICKNESS;
140+
wall = ent->entity;
141+
if (wall->isFloating) {
142+
extent = FLOATING_WALL_THICKNESS;
143+
}
144+
extent /= 2.0f;
145+
129146
proxy.count = 4;
130-
proxy.points[0] = (b2Vec2){.x = -FLOATING_WALL_THICKNESS / 2.0f, .y = -FLOATING_WALL_THICKNESS / 2.0f};
131-
proxy.points[1] = (b2Vec2){.x = -FLOATING_WALL_THICKNESS / 2.0f, .y = +FLOATING_WALL_THICKNESS / 2.0f};
132-
proxy.points[2] = (b2Vec2){.x = +FLOATING_WALL_THICKNESS / 2.0f, .y = -FLOATING_WALL_THICKNESS / 2.0f};
133-
proxy.points[3] = (b2Vec2){.x = +FLOATING_WALL_THICKNESS / 2.0f, .y = +FLOATING_WALL_THICKNESS / 2.0f};
147+
proxy.points[0] = (b2Vec2){.x = -extent, .y = -extent};
148+
proxy.points[1] = (b2Vec2){.x = -extent, .y = +extent};
149+
proxy.points[2] = (b2Vec2){.x = +extent, .y = -extent};
150+
proxy.points[3] = (b2Vec2){.x = +extent, .y = +extent};
134151
break;
135152
default:
136-
ERRORF("unknown entity type for shape distance: %d", type);
153+
ERRORF("unknown entity type for shape distance: %d", ent->type);
137154
}
138155

139156
return proxy;
140157
}
141158

142-
b2ShapeProxy makeDistanceProxy(const entity *ent, bool *isCircle) {
143-
if (ent->type == PROJECTILE_ENTITY) {
144-
*isCircle = true;
145-
b2ShapeProxy proxy = {0};
146-
const projectileEntity *proj = ent->entity;
147-
proxy.count = 1;
148-
proxy.radius = proj->weaponInfo->radius;
149-
return proxy;
150-
}
151-
152-
return makeDistanceProxyFromType(ent->type, isCircle);
153-
}
154-
155159
b2Transform entityTransform(const entity *ent) {
156160
b2Transform transform;
157161
wallEntity *wall;
@@ -1357,6 +1361,7 @@ bool explodeCallback(b2ShapeId shapeID, void *context) {
13571361

13581362
b2SimplexCache cache = {0};
13591363
const b2DistanceOutput output = b2ShapeDistance(&input, &cache, NULL, 0);
1364+
13601365
if (output.distance > ctx->def->radius) {
13611366
return true;
13621367
}
@@ -1981,6 +1986,7 @@ void droneBurst(iwEnv *e, droneEntity *drone) {
19811986
b2ExplosionDef explosion = {
19821987
.position = drone->pos,
19831988
.radius = radius,
1989+
.falloff = 0.0f,
19841990
.impulsePerLength = (DRONE_BURST_IMPACT_BASE * drone->burstCharge) + DRONE_BURST_IMPACT_MIN,
19851991
.maskBits = WALL_SHAPE | FLOATING_WALL_SHAPE | PROJECTILE_SHAPE | DRONE_SHAPE,
19861992
};

pufferlib/ocean/impulse_wars/render.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,7 @@ void renderUI(const iwEnv *e, const bool starting) {
856856
renderTimer(e, timerStr, PUFF_WHITE);
857857
}
858858

859+
// TODO: track when trails begine and end (ie when respawning)
859860
void renderBrakeTrails(iwEnv *e, const droneEntity *drone) {
860861
const float maxLifetime = 3.0f * e->frameRate;
861862
const float maxAlpha = 0.33f;
@@ -923,7 +924,7 @@ void renderBrakeTrails(iwEnv *e, const droneEntity *drone) {
923924
}
924925
}
925926

926-
// TODO: improve
927+
// TODO: make 2D circles
927928
void renderExplosions(const iwEnv *e) {
928929
const uint16_t maxRenderSteps = EXPLOSION_TIME * e->frameRate;
929930

@@ -940,7 +941,7 @@ void renderExplosions(const iwEnv *e) {
940941
continue;
941942
}
942943

943-
// color bursts with a bit of the parent drone's color'
944+
// color bursts with a bit of the parent drone's color
944945
const float alpha = (float)explosion->renderSteps / maxRenderSteps;
945946
BeginBlendMode(BLEND_ALPHA);
946947
if (false && explosion->isBurst) {
@@ -1658,9 +1659,6 @@ void _renderEnv(iwEnv *e, const bool starting, const bool ending, const int8_t w
16581659
BeginBlendMode(BLEND_ALPHA);
16591660
for (uint8_t i = 0; i < cc_array_size(e->drones); i++) {
16601661
const droneEntity *drone = safe_array_get_at(e->drones, i);
1661-
if (drone->dead) {
1662-
continue;
1663-
}
16641662
renderBrakeTrails(e, drone);
16651663
}
16661664
EndBlendMode();
@@ -1726,10 +1724,13 @@ void _renderEnv(iwEnv *e, const bool starting, const bool ending, const int8_t w
17261724
renderDroneUI(drone);
17271725
}
17281726

1729-
if (!b2VecEqual(e->debugPoint, b2Vec2_zero)) {
1730-
const Vector2 pos = {.x = e->debugPoint.x, .y = e->debugPoint.y};
1731-
DrawCircleV(pos, DRONE_RADIUS * 0.5f, WHITE);
1727+
#ifndef NDEBUG
1728+
for (uint8_t i = 0; i < cc_array_size(e->debugPoints); i++) {
1729+
debugPoint *point = safe_array_get_at(e->debugPoints, i);
1730+
const Vector2 pos = {.x = point->pos.x, .y = point->pos.y};
1731+
DrawCircleV(pos, point->size, point->color);
17321732
}
1733+
#endif
17331734

17341735
EndMode2D();
17351736

pufferlib/ocean/impulse_wars/types.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,12 @@ typedef struct pathingInfo {
405405
int8_t *pathBuffer;
406406
} pathingInfo;
407407

408+
typedef struct debugPoint {
409+
b2Vec2 pos;
410+
float size;
411+
Color color;
412+
} debugPoint;
413+
408414
typedef struct iwEnv {
409415
uint8_t numDrones;
410416
uint8_t numAgents;
@@ -486,7 +492,7 @@ typedef struct iwEnv {
486492
rayClient *client;
487493
float renderScale;
488494
CC_Array *explosions;
489-
b2Vec2 debugPoint;
495+
CC_Array *debugPoints;
490496
} iwEnv;
491497

492498
#endif

0 commit comments

Comments
 (0)