formatting

This commit is contained in:
jacob 2026-01-22 03:47:58 -06:00
parent 0c9dd684af
commit 5ad14b2dfd
15 changed files with 199 additions and 203 deletions

View File

@ -1,25 +1,5 @@
// Project-wide configurable constants
#define WRITE_DIR "power_play"
// Window title
#if IsRtcEnabled
#if IsDeveloperModeEnabled
#define WINDOW_TITLE "Debug (Developer Build)"
#else
#define WINDOW_TITLE "Debug"
#endif
#else
#if IsDeveloperModeEnabled
#define WINDOW_TITLE "Power Play (Developer Build)"
#else
#define WINDOW_TITLE "Power Play"
#endif
#endif
#define DEFAULT_CAMERA_WIDTH (16)
#define DEFAULT_CAMERA_HEIGHT ((f64)DEFAULT_CAMERA_WIDTH / (16.0 / 9.0))
// Rendered texture size + extra room for off-screen light falloff
#define RENDER_WIDTH (640 + 250)
#define RENDER_HEIGHT (360 + 250)
@ -32,13 +12,6 @@
#define USER_INTERP_RATIO 1.2
#define USER_INTERP_ENABLED 1
// 64^2 = 4096 bins
#define SPACE_CELL_BINS_SQRT (64)
#define SPACE_CELL_SIZE (1)
#define SIM_TILES_PER_UNIT_SQRT (4)
#define SIM_TILES_PER_CHUNK_SQRT (16)
#define SIM_MAX_PING 5.0
#define SIM_TICKS_PER_SECOND 64
#define SIM_TICK_INTERVAL_NS (NsFromSeconds(1) / SIM_TICKS_PER_SECOND)

View File

@ -594,7 +594,6 @@ G_ResourceHandle G_PushResource(G_ArenaHandle arena, G_CommandListHandle cl, G_R
} \
)
//- Index buffer helpers
#define G_IdxBuff16(_res) ((G_IndexBufferDesc) { .resource = (_res), .index_size = 2, .index_count = (G_CountBuffer((_res), i16)) })

View File

@ -2689,9 +2689,9 @@ void G_Rasterize(
cmd->rasterize.ps = ps;
cmd->rasterize.instances_count = instances_count;
cmd->rasterize.index_buffer_desc = index_buffer;
for (u32 i = 0; i < MinU32(render_targets_count, G_MaxRenderTargets); ++i)
for (u32 rt_idx = 0; rt_idx < MinU32(render_targets_count, G_MaxRenderTargets); ++rt_idx)
{
cmd->rasterize.render_target_descs[i] = render_targets[i];
cmd->rasterize.render_target_descs[rt_idx] = render_targets[rt_idx];
}
cmd->rasterize.viewport = viewport;
cmd->rasterize.scissor = scissor;

View File

@ -164,8 +164,8 @@ P_Shape P_LocalShapeFromEnt(P_Ent *ent)
.radius = 0.3,
);
// f32 guy_width = 0.6;
// f32 guy_height = 0.3;
// f32 guy_width = 0.75;
// f32 guy_height = 0.4;
// result = P_ShapeFromDesc(
// .mass = 10,
// .count = 2,
@ -1568,10 +1568,10 @@ void P_StepFrame(P_Frame *frame)
Vec2 new_velocity = guy->solved_v;
new_velocity = AddVec2(new_velocity, MulVec2(control.move, move_force * sim_dt));
// if (Vec2Len(new_velocity) > max_speed)
// {
// new_velocity = Vec2WithLen(new_velocity, max_speed);
// }
if (Vec2Len(new_velocity) > max_speed)
{
new_velocity = Vec2WithLen(new_velocity, max_speed);
}
guy->solved_v = new_velocity;
}
@ -1611,86 +1611,31 @@ void P_StepFrame(P_Frame *frame)
// TODO: Not like this
for (P_Ent *ent0 = P_FirstEnt(frame); !P_IsEntNil(ent0); ent0 = P_NextEnt(ent0))
if (!is_predicting)
{
if (ent0->is_guy)
for (P_Ent *ent0 = P_FirstEnt(frame); !P_IsEntNil(ent0); ent0 = P_NextEnt(ent0))
{
P_Shape shape0 = P_WorldShapeFromEnt(ent0);
for (P_Ent *ent1 = P_FirstEnt(frame); !P_IsEntNil(ent1); ent1 = P_NextEnt(ent1))
if (ent0->is_guy)
{
if (ent1->is_guy && ent1->key.v > ent0->key.v)
P_Shape shape0 = P_WorldShapeFromEnt(ent0);
for (P_Ent *ent1 = P_FirstEnt(frame); !P_IsEntNil(ent1); ent1 = P_NextEnt(ent1))
{
P_Shape shape1 = P_WorldShapeFromEnt(ent1);
// TODO: World query
P_CollisionResult collision = P_CollisionResultFromShapes(shape0, shape1);
if (collision.collision_points_count > 0)
if (ent1->is_guy && ent1->key.v > ent0->key.v)
{
// FIXME: Key lookup
P_Constraint *constraint = 0;
P_Shape shape1 = P_WorldShapeFromEnt(ent1);
// TODO: World query
P_CollisionResult collision = P_CollisionResultFromShapes(shape0, shape1);
if (collision.collision_points_count > 0)
{
b32 match = 0;
for (i64 constraint_idx = 0; constraint_idx < frame->constraints_count; ++constraint_idx)
// FIXME: Key lookup
P_Constraint *constraint = 0;
{
constraint = &frame->constraints[constraint_idx];
if (P_MatchKey(constraint->ent0, ent0->key) && P_MatchKey(constraint->ent1, ent1->key))
{
match = 1;
break;
}
}
if (!match)
{
if (frame->constraints_count < frame->constraints_cap)
{
constraint = &frame->constraints[frame->constraints_count];
frame->constraints_count += 1;
ZeroStruct(constraint);
}
}
}
if (constraint)
{
constraint->flags = P_ConstraintFlag_Gentle | P_ConstraintFlag_NoWarmStart;
constraint->last_touched_tick = frame->tick;
constraint->normal = collision.collision_normal;
// constraint->friction = SqrtF32(ent0->friction * ent1->friction);
constraint->friction = 0;
// TODO: Real masses
f32 inv_m0 = 10;
f32 inv_m1 = 10;
f32 inv_i0 = 0;
f32 inv_i1 = 0;
// Treat non-predicted guys as infinite-mass
if (is_predicting && ent0 != local_guy)
{
inv_m0 = 0;
}
if (is_predicting && ent1 != local_guy)
{
inv_m1 = 0;
}
constraint->ent0 = ent0->key;
constraint->ent1 = ent1->key;
// constraint->static_center1 = shape1.center_of_mass;
constraint->inv_m0 = inv_m0;
constraint->inv_m1 = inv_m1;
constraint->inv_i0 = inv_i0;
constraint->inv_i1 = inv_i1;
// Delete old contacts that are no longer present
for (i32 contact_point_idx = 0; contact_point_idx < constraint->points_count; ++contact_point_idx)
{
P_ContactPoint *contact = &constraint->points[contact_point_idx];
u32 id = contact->id;
b32 match = 0;
for (i32 collision_point_idx = 0; collision_point_idx < collision.collision_points_count; ++collision_point_idx)
for (i64 constraint_idx = 0; constraint_idx < frame->constraints_count; ++constraint_idx)
{
if (collision.collision_points[collision_point_idx].id == id)
constraint = &frame->constraints[constraint_idx];
if (P_MatchKey(constraint->ent0, ent0->key) && P_MatchKey(constraint->ent1, ent1->key))
{
match = 1;
break;
@ -1698,60 +1643,118 @@ void P_StepFrame(P_Frame *frame)
}
if (!match)
{
// Delete contact by replacing with last in array
*contact = constraint->points[constraint->points_count - 1];
constraint->points_count -= 1;
contact_point_idx -= 1;
if (frame->constraints_count < frame->constraints_cap)
{
constraint = &frame->constraints[frame->constraints_count];
frame->constraints_count += 1;
ZeroStruct(constraint);
}
}
}
// Create / update contacts from collision
for (i32 collision_point_idx = 0; collision_point_idx < collision.collision_points_count; ++collision_point_idx)
if (constraint)
{
P_CollisionPoint collision_point = collision.collision_points[collision_point_idx];
constraint->flags = P_ConstraintFlag_Gentle | P_ConstraintFlag_NoWarmStart;
constraint->last_touched_tick = frame->tick;
constraint->normal = collision.collision_normal;
// constraint->friction = SqrtF32(ent0->friction * ent1->friction);
constraint->friction = 0;
u32 id = collision_point.id;
P_ContactPoint *contact = 0;
// TODO: Real masses
f32 inv_m0 = 10;
f32 inv_m1 = 10;
f32 inv_i0 = 0;
f32 inv_i1 = 0;
// Treat non-predicted guys as infinite-mass
if (is_predicting && ent0 != local_guy)
{
for (i32 contact_point_idx = 0; contact_point_idx < constraint->points_count; ++contact_point_idx)
inv_m0 = 0;
}
if (is_predicting && ent1 != local_guy)
{
inv_m1 = 0;
}
constraint->ent0 = ent0->key;
constraint->ent1 = ent1->key;
// constraint->static_center1 = shape1.center_of_mass;
constraint->inv_m0 = inv_m0;
constraint->inv_m1 = inv_m1;
constraint->inv_i0 = inv_i0;
constraint->inv_i1 = inv_i1;
// Delete old contacts that are no longer present
for (i32 contact_point_idx = 0; contact_point_idx < constraint->points_count; ++contact_point_idx)
{
P_ContactPoint *contact = &constraint->points[contact_point_idx];
u32 id = contact->id;
b32 match = 0;
for (i32 collision_point_idx = 0; collision_point_idx < collision.collision_points_count; ++collision_point_idx)
{
P_ContactPoint *tmp = &constraint->points[contact_point_idx];
if (tmp->id == id)
if (collision.collision_points[collision_point_idx].id == id)
{
contact = tmp;
match = 1;
break;
}
}
if (!contact)
if (!match)
{
contact = &constraint->points[constraint->points_count];
constraint->points_count += 1;
ZeroStruct(contact);
// Delete contact by replacing with last in array
*contact = constraint->points[constraint->points_count - 1];
constraint->points_count -= 1;
contact_point_idx -= 1;
}
}
contact->id = id;
Vec2 vcp0 = SubVec2(collision_point.p, shape0.center_of_mass);
Vec2 vcp1 = SubVec2(collision_point.p, shape1.center_of_mass);
// Create / update contacts from collision
for (i32 collision_point_idx = 0; collision_point_idx < collision.collision_points_count; ++collision_point_idx)
{
P_CollisionPoint collision_point = collision.collision_points[collision_point_idx];
contact->vcp0 = vcp0;
contact->vcp1 = vcp1;
contact->starting_separation = collision_point.separation;
u32 id = collision_point.id;
P_ContactPoint *contact = 0;
{
for (i32 contact_point_idx = 0; contact_point_idx < constraint->points_count; ++contact_point_idx)
{
P_ContactPoint *tmp = &constraint->points[contact_point_idx];
if (tmp->id == id)
{
contact = tmp;
break;
}
}
if (!contact)
{
contact = &constraint->points[constraint->points_count];
constraint->points_count += 1;
ZeroStruct(contact);
}
}
contact->id = id;
// Debug draw
// {
// // P_Ent *ent0 = P_EntFromKey(frame, constraint->ent0);
// // P_Ent *ent1 = P_EntFromKey(frame, constraint->ent1);
// Vec2 normal = constraint->normal;
// Vec2 center0 = Zi;
// Vec2 center1 = Zi;
// if (!P_IsEntNil(ent0)) center0 = P_WorldShapeFromEnt(ent0).center_of_mass;
// if (!P_IsEntNil(ent1)) center1 = P_WorldShapeFromEnt(ent1).center_of_mass;
// Vec2 p0 = AddVec2(center0, vcp0);
// Vec2 p1 = AddVec2(center1, vcp1);
// P_DebugDrawPoint(p0, Color_Cyan);
// P_DebugDrawLine(p0, AddVec2(p0, normal), Color_White);
// }
Vec2 vcp0 = SubVec2(collision_point.p, shape0.center_of_mass);
Vec2 vcp1 = SubVec2(collision_point.p, shape1.center_of_mass);
contact->vcp0 = vcp0;
contact->vcp1 = vcp1;
contact->starting_separation = collision_point.separation;
// Debug draw
// {
// // P_Ent *ent0 = P_EntFromKey(frame, constraint->ent0);
// // P_Ent *ent1 = P_EntFromKey(frame, constraint->ent1);
// Vec2 normal = constraint->normal;
// Vec2 center0 = Zi;
// Vec2 center1 = Zi;
// if (!P_IsEntNil(ent0)) center0 = P_WorldShapeFromEnt(ent0).center_of_mass;
// if (!P_IsEntNil(ent1)) center1 = P_WorldShapeFromEnt(ent1).center_of_mass;
// Vec2 p0 = AddVec2(center0, vcp0);
// Vec2 p1 = AddVec2(center1, vcp1);
// P_DebugDrawPoint(p0, Color_Cyan);
// P_DebugDrawLine(p0, AddVec2(p0, normal), Color_White);
// }
}
}
}
}
@ -2276,8 +2279,8 @@ void P_StepFrame(P_Frame *frame)
f32 fire_rate = 50;
f32 bullets_per_fire = 1;
// f32 spread = Tau * 0.05;
f32 spread = Tau * 0.01;
f32 spread = Tau * 0.05;
// f32 spread = Tau * 0.01;
f32 tweak_speed = TweakFloat("Bullet speed", 100, 1, 100);
b32 can_fire = (firer->last_fire_ns + NsFromSeconds(1.0 / fire_rate)) <= frame->time_ns;

BIN
src/pp/pp_res/sprite/bla.ase (Stored with Git LFS) Normal file

Binary file not shown.

BIN
src/pp/pp_res/sprite/bla2.ase (Stored with Git LFS) Normal file

Binary file not shown.

BIN
src/pp/pp_res/sprite/bla3.ase (Stored with Git LFS) Normal file

Binary file not shown.

BIN
src/pp/pp_res/sprite/palette.ase (Stored with Git LFS) Normal file

Binary file not shown.

BIN
src/pp/pp_res/sprite/palette2.ase (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -88,7 +88,7 @@ void S_TickForever(WaveLaneCtx *lane)
while (!shutdown)
{
shutdown = Atomic32Fetch(&S.shutdown);
P_tl.debug_draw_enabled = TweakBool("Simulation debug draw", 1);
P_tl.debug_draw_enabled = TweakBool("Simulation debug draw", 0);
ResetArena(frame_arena);
//////////////////////////////

View File

@ -345,7 +345,7 @@ void V_TickForever(WaveLaneCtx *lane)
const f32 zoom_rate = 1.50;
const f32 min_zoom = 0.03;
const f32 max_zoom = 15.0;
const f32 meters_per_draw_width = 18;
const f32 meters_per_draw_width = 16;
NET_PipeHandle net_pipe = NET_AcquirePipe();
BB_Buff packer_bb = BB_AcquireDynamicBuff(Gibi(64));
@ -1306,8 +1306,8 @@ void V_TickForever(WaveLaneCtx *lane)
{
// How many buffered commands of ours we'd like the server to have
i64 target_buffered_controls_count = 1;
f64 rtt_bias_factor = 10.0;
f64 rtt_bias_factor = 5.0;
f64 dilation_factor = SmoothstepF64(
-(SIM_TICKS_PER_SECOND * smoothed_rtt * rtt_bias_factor),
(SIM_TICKS_PER_SECOND * smoothed_rtt * rtt_bias_factor),
@ -3615,7 +3615,7 @@ void V_TickForever(WaveLaneCtx *lane)
}
UI_BuildSpacer(UI_PIX(padding, 1), Axis_Y);
{
UI_BuildLabelF("Ping: %F", FmtFloat(smoothed_rtt * 1000, .p = 3));
UI_BuildLabelF("RTT: %Fms", FmtFloat(smoothed_rtt * 1000, .p = 3));
UI_BuildLabelF("Client send: %F MiB", FmtFloat(CeilF64((f64)vis_pipe_stats.total_bytes_sent / 1024) / 1024, .p = 3));
UI_BuildLabelF("Client recv: %F MiB", FmtFloat(CeilF64((f64)vis_pipe_stats.total_bytes_received / 1024) / 1024, .p = 3));
UI_BuildLabelF("Server send: %F MiB", FmtFloat(CeilF64((f64)sim_pipe_stats.total_bytes_sent / 1024) / 1024, .p = 3));
@ -3692,55 +3692,61 @@ void V_TickForever(WaveLaneCtx *lane)
UI_Key board_key = UI_KeyF("scoreboard");
Vec4 board_bg = VEC4(0, 0, 0, 0.50);
Vec4 board_bg = VEC4(0, 0, 0, 1);
f32 opacity = 0.75;
UI_Size board_width = UI_FNT(50, 0);
UI_Size board_height = UI_FNT(20, 0);
Vec2 pos = VEC2(frame->ui_dims.x / 2, 50);
UI_SetNext(Anchor, UI_Region_Top);
UI_SetNext(Width, board_width);
UI_SetNext(Height, board_height);
UI_SetNext(FloatingPos, pos);
UI_SetNext(BackgroundColor, board_bg);
UI_SetNext(Flags, UI_BoxFlag_Floating);
UI_PushCP(UI_BuildColumnEx(board_key));
UI_PushCP(UI_NilKey);
{
UI_BuildSpacer(spacing_sz, Axis_Y);
for (BoardRow *board_row = first_board_row; board_row; board_row = board_row->next)
UI_Push(Tint, VEC4(1, 1, 1, opacity));
UI_SetNext(Anchor, UI_Region_Top);
UI_SetNext(Width, board_width);
UI_SetNext(Height, board_height);
UI_SetNext(FloatingPos, pos);
UI_SetNext(BackgroundColor, board_bg);
UI_SetNext(Flags, UI_BoxFlag_Floating);
UI_PushCP(UI_BuildColumnEx(board_key));
{
UI_SetNext(Width, UI_GROW(1, 1));
UI_SetNext(Height, UI_FNT(2.5, 0));
UI_SetNext(Tint, 0);
UI_SetNext(ChildAlignment, UI_Region_Left);
UI_PushCP(UI_BuildRow()); // Scoreboard row
UI_BuildSpacer(spacing_sz, Axis_Y);
for (BoardRow *board_row = first_board_row; board_row; board_row = board_row->next)
{
UI_BuildSpacer(spacing_sz, Axis_X);
UI_SetNext(Width, name_sz);
UI_PushCP(UI_BuildColumn()); // Player name column
UI_SetNext(Width, UI_GROW(1, 1));
UI_SetNext(Height, UI_FNT(2.5, 0));
UI_SetNext(Tint, 0);
UI_SetNext(ChildAlignment, UI_Region_Left);
UI_PushCP(UI_BuildRow()); // Scoreboard row
{
UI_SetNext(FontSize, UI_Top(FontSize) * theme.h2);
UI_BuildLabelF("Player: \"%F\"", FmtString(board_row->name));
UI_BuildSpacer(spacing_sz, Axis_X);
UI_SetNext(Width, name_sz);
UI_PushCP(UI_BuildColumn()); // Player name column
{
UI_SetNext(FontSize, UI_Top(FontSize) * theme.h2);
UI_BuildLabelF("Player: \"%F\"", FmtString(board_row->name));
}
UI_PopCP(UI_TopCP());
UI_BuildSpacer(spacing_sz, Axis_X);
UI_SetNext(Width, ping_sz);
UI_PushCP(UI_BuildColumn()); // Ping column
{
UI_SetNext(FontSize, UI_Top(FontSize) * theme.h2);
UI_BuildLabelF("Ping: %F ", FmtFloat(board_row->ping, .p = 2));
}
UI_PopCP(UI_TopCP());
}
UI_PopCP(UI_TopCP());
UI_BuildSpacer(spacing_sz, Axis_X);
UI_SetNext(Width, ping_sz);
UI_PushCP(UI_BuildColumn()); // Ping column
if (board_row->next)
{
UI_SetNext(FontSize, UI_Top(FontSize) * theme.h2);
UI_BuildLabelF("Ping: %F ", FmtFloat(board_row->ping, .p = 2));
UI_BuildDivider(UI_PIX(1, 1), theme.col.divider, Axis_Y);
}
UI_PopCP(UI_TopCP());
}
UI_PopCP(UI_TopCP());
if (board_row->next)
{
UI_BuildDivider(UI_PIX(1, 1), theme.col.divider, Axis_Y);
}
UI_BuildSpacer(spacing_sz, Axis_Y);
}
UI_BuildSpacer(spacing_sz, Axis_Y);
UI_PopCP(UI_TopCP());
}
UI_PopCP(UI_TopCP());
}
@ -4315,12 +4321,12 @@ void V_TickForever(WaveLaneCtx *lane)
// FIXME: Remove this (testing)
if (frame->held_buttons[Button_R] && !prev_frame->held_buttons[Button_R])
{
LogDebugF("Sending test payload");
NET_Send(net_pipe, frame->sim_key, STRING(P_TilesCount, predict_world->tiles), NET_SendFlag_None);
// NET_Send(net_pipe, frame->sim_key, Lit("Hello there!"), NET_SendFlag_None);
}
// if (frame->held_buttons[Button_R] && !prev_frame->held_buttons[Button_R])
// {
// LogDebugF("Sending test payload");
// NET_Send(net_pipe, frame->sim_key, STRING(P_TilesCount, predict_world->tiles), NET_SendFlag_None);
// // NET_Send(net_pipe, frame->sim_key, Lit("Hello there!"), NET_SendFlag_None);
// }

View File

@ -63,7 +63,7 @@ ComputeShader(V_ClearParticlesCS, 64)
}
////////////////////////////////////////////////////////////
//~ Backdrop shaders
//~ Backdrop
ComputeShader2D(V_BackdropCS, 8, 8)
{
@ -270,7 +270,7 @@ ComputeShader2D(V_BackdropCS, 8, 8)
}
////////////////////////////////////////////////////////////
//~ Quad shaders
//~ Quads
//////////////////////////////
//- Vertex shader
@ -311,7 +311,7 @@ PixelShader(V_DQuadPS, V_DQuadPSOutput, V_DQuadPSInput input)
}
////////////////////////////////////////////////////////////
//~ Particle simulation shaders
//~ Particle simulation
//////////////////////////////
//- Particle emitter shader
@ -461,7 +461,7 @@ ComputeShader(V_SimParticlesCS, 64)
}
////////////////////////////////////////////////////////////
//~ Shape shaders
//~ Shapes
//////////////////////////////
//- Vertex shader
@ -493,7 +493,7 @@ PixelShader(V_DVertPS, V_DVertPSOutput, V_DVertPSInput input)
}
////////////////////////////////////////////////////////////
//~ Overlay shaders
//~ Overlay
//////////////////////////////
//- Vertex shader

View File

@ -53,21 +53,21 @@ Vec4 V_DryColor(Vec4 color, f32 dryness);
ComputeShader2D(V_ClearCellsCS, 8, 8);
ComputeShader(V_ClearParticlesCS, 64);
//- Backdrop shaders
//- Backdrop
ComputeShader2D(V_BackdropCS, 8, 8);
//- Quad shaders
//- Quads
VertexShader(V_DQuadVS, V_DQuadPSInput);
PixelShader(V_DQuadPS, V_DQuadPSOutput, V_DQuadPSInput input);
//- Particle simulation shaders
//- Particle simulation
ComputeShader(V_EmitParticlesCS, 64);
ComputeShader(V_SimParticlesCS, 64);
//- Shape shaders
//- Shapes
VertexShader(V_DVertVS, V_DVertPSInput);
PixelShader(V_DVertPS, V_DVertPSOutput, V_DVertPSInput input);
//- Overlay shaders
//- Overlay
VertexShader(V_OverlayVS, V_OverlayPSInput);
PixelShader(V_OverlayPS, V_OverlayPSOutput, V_OverlayPSInput input);

View File

@ -1,5 +1,5 @@
////////////////////////////////////////////////////////////
//~ Rect shaders
//~ Rects
//////////////////////////////
//- Vertex shader
@ -115,7 +115,7 @@ PixelShader(UI_DRectPS, UI_DRectPSOutput, UI_DRectPSInput input)
}
////////////////////////////////////////////////////////////
//~ Blit shaders
//~ Blit
//////////////////////////////
//- Vertex shader

View File

@ -35,7 +35,7 @@ Struct(UI_BlitPSOutput)
////////////////////////////////////////////////////////////
//~ Shaders
//- Rect
//- Rects
VertexShader(UI_DRectVS, UI_DRectPSInput);
PixelShader(UI_DRectPS, UI_DRectPSOutput, UI_DRectPSInput input);