diff --git a/src/pp/pp.c b/src/pp/pp.c index 598ab4d3..733790aa 100644 --- a/src/pp/pp.c +++ b/src/pp/pp.c @@ -1,12 +1,12 @@ -SharedUserState shared_user_state = ZI; +PP_SharedUserState PP_shared_user_state = ZI; //////////////////////////////////////////////////////////// //~ Startup -void StartupUser(void) +void PP_StartupUser(void) { __prof; - SharedUserState *g = &shared_user_state; + PP_SharedUserState *g = &PP_shared_user_state; SetGstat(GSTAT_DEBUG_STEPS, U64Max); @@ -21,14 +21,14 @@ void StartupUser(void) g->average_local_to_user_snapshot_publish_dt_ns = NsFromSeconds(1) / SIM_TICKS_PER_SECOND; /* User blend clients */ - g->user_client_store = AcquireClientStore(); - g->user_unblended_client = AcquireClient(g->user_client_store); - g->user_blended_client = AcquireClient(g->user_client_store); - g->ss_blended = NilSnapshot(); + g->user_client_store = PP_AcquireClientStore(); + g->user_unblended_client = PP_AcquireClient(g->user_client_store); + g->user_blended_client = PP_AcquireClient(g->user_client_store); + g->ss_blended = PP_NilSnapshot(); /* Local to user client */ - g->local_to_user_client_store = AcquireClientStore(); - g->local_to_user_client = AcquireClient(g->local_to_user_client_store); + g->local_to_user_client_store = PP_AcquireClientStore(); + g->local_to_user_client = PP_AcquireClient(g->local_to_user_client_store); /* Init from swap */ if (IsSwappedIn()); @@ -42,11 +42,11 @@ void StartupUser(void) String swap_str = BB_ReadString(scratch.arena, &br); g->window_restore = BB_ReadString(perm, &br); - if (swap_str.len == sizeof(SwappedUserState)) + if (swap_str.len == sizeof(PP_SwappedUserState)) { - SwappedUserState *swap = PushStructNoZero(scratch.arena, SwappedUserState); + PP_SwappedUserState *swap = PushStructNoZero(scratch.arena, PP_SwappedUserState); CopyBytes(swap, swap_str.text, swap_str.len); - SharedUserState *old = &swap->s; + PP_SharedUserState *old = &swap->s; CopyStructRegion(g, old, AUTO_PERSIST_START, AUTO_PERSIST_END); } @@ -54,26 +54,26 @@ void StartupUser(void) } g->console_logs_arena = AcquireArena(Gibi(64)); - //P_RegisterLogCallback(ConsoleLogCallback, P_LogLevel_Success); - P_RegisterLogCallback(ConsoleLogCallback, P_LogLevel_Debug); + //P_RegisterLogCallback(PP_ConsoleLogCallback, P_LogLevel_Success); + P_RegisterLogCallback(PP_ConsoleLogCallback, P_LogLevel_Debug); /* Create job pools */ JobPoolId user_pool = InitJobPool(1, Lit("User"), JobPoolPriority_Graphics); JobPoolId sim_pool = InitJobPool(1, Lit("Simulation"), JobPoolPriority_Simulation); /* Start jobs */ - g->shutdown_jobs_count += RunJob(UpdateUserOrSleep, .pool = user_pool, .fence = &g->shutdown_jobs_fence); - g->shutdown_jobs_count += RunJob(UpdateSim, .pool = sim_pool, .fence = &g->shutdown_jobs_fence); - OnExit(&ShutdownUser); + g->shutdown_jobs_count += RunJob(PP_UpdateUserOrSleep, .pool = user_pool, .fence = &g->shutdown_jobs_fence); + g->shutdown_jobs_count += RunJob(PP_UpdateSim, .pool = sim_pool, .fence = &g->shutdown_jobs_fence); + OnExit(&PP_ShutdownUser); } //////////////////////////////////////////////////////////// //~ Shutdown -ExitFuncDef(ShutdownUser) +ExitFuncDef(PP_ShutdownUser) { __prof; - SharedUserState *g = &shared_user_state; + PP_SharedUserState *g = &PP_shared_user_state; Atomic32Set(&g->shutdown, 1); YieldOnFence(&g->shutdown_jobs_fence, g->shutdown_jobs_count); @@ -86,7 +86,7 @@ ExitFuncDef(ShutdownUser) BB_Buff bb = BB_BuffFromString(STRING(max_size, bytes)); { BB_Writer bw = BB_WriterFromBuff(&bb); - SwappedUserState *swap = PushStruct(scratch.arena, SwappedUserState); + PP_SwappedUserState *swap = PushStruct(scratch.arena, PP_SwappedUserState); swap->s = *g; BB_WriteString(&bw, StringFromStruct(swap)); BB_WriteString(&bw, g->window_restore); @@ -100,7 +100,7 @@ ExitFuncDef(ShutdownUser) //~ Ui helpers //- Ui style -void PushGameUiStyle(void) +void PP_PushGameUiStyle(void) { // UI_Push(FontSize, 48); // UI_Push(FontSize, 24); @@ -122,9 +122,9 @@ void PushGameUiStyle(void) } //- Draw xform -void DrawDebugXform(Xform xf, u32 color_x, u32 color_y) +void PP_DrawDebugXform(Xform xf, u32 color_x, u32 color_y) { - SharedUserState *g = &shared_user_state; + PP_SharedUserState *g = &PP_shared_user_state; f32 thickness = 2.f; f32 arrowhead_len = 15.f; @@ -157,15 +157,15 @@ void DrawDebugXform(Xform xf, u32 color_x, u32 color_y) } //- Draw movement -void DrawDebugMovement(Entity *ent) +void PP_DrawDebugMovement(PP_Ent *ent) { - SharedUserState *g = &shared_user_state; + PP_SharedUserState *g = &PP_shared_user_state; f32 thickness = 2.f; f32 arrow_len = 15.f; u32 color_vel = Color_Orange; - Xform xf = XformFromEntity(ent); + Xform xf = PP_XformFromEnt(ent); Vec2 velocity = ent->linear_velocity; Vec2 pos = MulXformV2(g->world_to_ui_xf, xf.og); @@ -188,11 +188,11 @@ void DrawDebugMovement(Entity *ent) } } -//- Entity debug string -String DebugStringFromEntity(Arena *arena, Entity *ent) +//- Ent debug string +String PP_DebugStringFromEnt(Arena *arena, PP_Ent *ent) { TempArena scratch = BeginScratch(arena); - Snapshot *ss = ent->ss; + PP_Snapshot *ss = ent->ss; const u8 hex[] = "0123456789abcdef"; @@ -201,8 +201,8 @@ String DebugStringFromEntity(Arena *arena, Entity *ent) //result.len += StringF(arena, "[%F]", FmtUid(ent->id.uid)).len; { - b32 transmitting = HasProp(ent, Prop_SyncSrc); - b32 receiving = HasProp(ent, Prop_SyncDst); + b32 transmitting = PP_HasProp(ent, PP_Prop_SyncSrc); + b32 receiving = PP_HasProp(ent, PP_Prop_SyncDst); if (transmitting & receiving) { result.len += StringF(arena, " networked (sending & receiving)").len; @@ -233,7 +233,7 @@ String DebugStringFromEntity(Arena *arena, Entity *ent) u64 chunk = ent->props[chunk_index]; for (u64 part_index = 8; part_index-- > 0;) { - if ((chunk_index != (countof(ent->props) - 1)) || ((chunk_index * 64) + (part_index * 8)) <= Prop_Count) + if ((chunk_index != (countof(ent->props) - 1)) || ((chunk_index * 64) + (part_index * 8)) <= PP_Prop_Count) { u8 part = (chunk >> (part_index * 8)) & 0xFF; StringFromChar(arena, hex[(part >> 4) & 0x0F]); @@ -245,12 +245,12 @@ String DebugStringFromEntity(Arena *arena, Entity *ent) result.len += StringF(arena, "\n").len; } - if (!EqId(ent->parent, RootEntityId)) + if (!PP_EqEntKey(ent->parent, PP_RootEntKey)) { result.len += StringF(arena, "parent: [%F]\n", FmtUid(ent->parent.uid)).len; } - if (!IsNilId(ent->next) || !IsNilId(ent->prev)) + if (!PP_IsNilEntKey(ent->next) || !PP_IsNilEntKey(ent->prev)) { result.len += StringF(arena, "prev: [%F]\n", FmtUid(ent->prev.uid)).len; result.len += StringF(arena, "next: [%F]\n", FmtUid(ent->next.uid)).len; @@ -259,7 +259,7 @@ String DebugStringFromEntity(Arena *arena, Entity *ent) result.len += StringF(arena, "\n").len; /* Pos */ - Xform xf = XformFromEntity(ent); + Xform xf = PP_XformFromEnt(ent); Vec2 linear_velocity = ent->linear_velocity; f32 angular_velocity = ent->angular_velocity; result.len += StringF(arena, "pos: (%F, %F)\n", FmtFloat(xf.og.x), FmtFloat(xf.og.y)).len; @@ -270,10 +270,10 @@ String DebugStringFromEntity(Arena *arena, Entity *ent) result.len += StringF(arena, "collision dir: (%F, %F)\n", FmtFloat(ent->collision_dir.x), FmtFloat(ent->collision_dir.y)).len; /* Children */ - if (!IsNilId(ent->first) || !IsNilId(ent->last)) + if (!PP_IsNilEntKey(ent->first) || !PP_IsNilEntKey(ent->last)) { - Entity *child = EntityFromId(ss, ent->first); - if (!EqId(ent->first, ent->last) || !child->valid) + PP_Ent *child = PP_EntFromKey(ss, ent->first); + if (!PP_EqEntKey(ent->first, ent->last) || !child->valid) { result.len += StringF(arena, "first child: [%F]\n", FmtUid(ent->first.uid)).len; result.len += StringF(arena, "last child: [%F]\n", FmtUid(ent->last.uid)).len; @@ -282,9 +282,9 @@ String DebugStringFromEntity(Arena *arena, Entity *ent) { result.len += StringF(arena, "\n---------------------------------\n").len; result.len += StringF(arena, "CHILD\n").len; - String child_text = DebugStringFromEntity(scratch.arena, child); + String child_text = PP_DebugStringFromEnt(scratch.arena, child); result.len += IndentString(arena, child_text, 4).len; - child = EntityFromId(ss, child->next); + child = PP_EntFromKey(ss, child->next); } } @@ -296,13 +296,13 @@ String DebugStringFromEntity(Arena *arena, Entity *ent) //~ Console //- Console log callback -P_LogEventCallbackFuncDef(ConsoleLogCallback, log) +P_LogEventCallbackFuncDef(PP_ConsoleLogCallback, log) { __prof; - SharedUserState *g = &shared_user_state; + PP_SharedUserState *g = &PP_shared_user_state; Lock lock = LockE(&g->console_logs_mutex); { - ConsoleLog *clog = PushStruct(g->console_logs_arena, ConsoleLog); + PP_ConsoleLog *clog = PushStruct(g->console_logs_arena, PP_ConsoleLog); clog->level = log.level; clog->msg = PushString(g->console_logs_arena, log.msg); clog->datetime = log.datetime; @@ -327,11 +327,11 @@ P_LogEventCallbackFuncDef(ConsoleLogCallback, log) } //- Draw console -void DrawDebugConsole(b32 minimized) +void PP_DrawDebugConsole(b32 minimized) { /* TODO: Remove this whole thing */ __prof; - SharedUserState *g = &shared_user_state; + PP_SharedUserState *g = &PP_shared_user_state; TempArena scratch = BeginScratchNoConflict(); // i32 console_level = minimized ? P_LogLevel_Success : P_LogLevel_Debug; @@ -392,14 +392,14 @@ void DrawDebugConsole(b32 minimized) /* Gather display logs */ u64 max = 20; u64 display_count = 0; - ConsoleLog **display_logs = PushStructs(scratch.arena, ConsoleLog *, max); + PP_ConsoleLog **display_logs = PushStructs(scratch.arena, PP_ConsoleLog *, max); { b32 done = 0; if (minimized) { max = 5; } - for (ConsoleLog *log = g->last_console_log; log && display_count < max && !done; log = log->prev) + for (PP_ConsoleLog *log = g->last_console_log; log && display_count < max && !done; log = log->prev) { if (log->time_ns > (now_ns - max_time_ns)) { @@ -419,7 +419,7 @@ void DrawDebugConsole(b32 minimized) /* Display logs in reverse */ for (u64 i = display_count; i-- > 0;) { - ConsoleLog *log = display_logs[i]; + PP_ConsoleLog *log = display_logs[i]; f32 opacity = 0.75; f32 lin = 1.0 - ClampF64((f64)(now_ns - log->time_ns) / (f64)fade_time_ns, 0, 1); opacity *= PowF32(lin, fade_curve); @@ -475,7 +475,7 @@ void DrawDebugConsole(b32 minimized) //- Gbuffer -GPU_Resource *AcquireGbuffer(GPU_Format format, Vec2I32 size) +GPU_Resource *PP_AcquireGbuffer(GPU_Format format, Vec2I32 size) { __prof; GPU_ResourceDesc desc = ZI; @@ -489,18 +489,18 @@ GPU_Resource *AcquireGbuffer(GPU_Format format, Vec2I32 size) //////////////////////////////////////////////////////////// //~ Sort entities -MergesortCompareFuncDef(EntitySortCmp, arg_a, arg_b, _) +MergesortCompareFuncDef(PP_EntSortCmp, arg_a, arg_b, _) { - Entity *a = *(Entity **)arg_a; - Entity *b = *(Entity **)arg_b; + PP_Ent *a = *(PP_Ent **)arg_a; + PP_Ent *b = *(PP_Ent **)arg_b; i32 result = 0; if (result == 0) { /* Sort by light */ - b32 a_cmp = HasProp(a, Prop_LightTest); - b32 b_cmp = HasProp(b, Prop_LightTest); + b32 a_cmp = PP_HasProp(a, PP_Prop_LightTest); + b32 b_cmp = PP_HasProp(b, PP_Prop_LightTest); result = (a_cmp > b_cmp) - (a_cmp < b_cmp); } if (result == 0) @@ -531,10 +531,10 @@ MergesortCompareFuncDef(EntitySortCmp, arg_a, arg_b, _) //////////////////////////////////////////////////////////// //~ User update -void UpdateUser(void) +void PP_UpdateUser(void) { __prof; - SharedUserState *g = &shared_user_state; + PP_SharedUserState *g = &PP_shared_user_state; TempArena scratch = BeginScratchNoConflict(); g->real_dt_ns = TimeNs() - g->real_time_ns; @@ -583,14 +583,14 @@ void UpdateUser(void) UI_SetNext(BorderColor, Rgba32F(1, 0, 0, 0.5)); } UI_Box *pp_root_box = UI_BuildBox(0, UI_NilKey); - PushGameUiStyle(); + PP_PushGameUiStyle(); UI_Push(Parent, pp_root_box); //- Init render data buffers if (!g->material_instances_arena) { - g->material_instances_tbuff = GPU_AcquireTransientBuffer(GPU_QueueKind_Direct, sizeof(MaterialInstance)); - g->grids_tbuff = GPU_AcquireTransientBuffer(GPU_QueueKind_Direct, sizeof(MaterialGrid)); + g->material_instances_tbuff = GPU_AcquireTransientBuffer(GPU_QueueKind_Direct, sizeof(PP_MaterialInstance)); + g->grids_tbuff = GPU_AcquireTransientBuffer(GPU_QueueKind_Direct, sizeof(PP_MaterialGrid)); g->material_instances_arena = AcquireArena(Gibi(64)); g->grids_arena = AcquireArena(Gibi(64)); } @@ -603,8 +603,8 @@ void UpdateUser(void) u64 last_tick = g->local_to_user_client->last_tick; if (last_tick > old_last_tick) { - Snapshot *src = SnapshotFromTick(g->local_to_user_client, last_tick); - AcquireSnapshot(g->user_unblended_client, src, src->tick); + PP_Snapshot *src = PP_SnapshotFromTick(g->local_to_user_client, last_tick); + PP_AcquireSnapshot(g->user_unblended_client, src, src->tick); g->last_local_to_user_snapshot_published_at_ns = g->local_to_user_client_publish_time_ns; g->average_local_to_user_snapshot_publish_dt_ns -= g->average_local_to_user_snapshot_publish_dt_ns / 50; g->average_local_to_user_snapshot_publish_dt_ns += g->local_to_user_client_publish_dt_ns / 50; @@ -624,7 +624,7 @@ void UpdateUser(void) } /* Predict local sim time based on average snapshot publish dt. */ - Snapshot *newest_snapshot = SnapshotFromTick(g->user_unblended_client, g->user_unblended_client->last_tick); + PP_Snapshot *newest_snapshot = PP_SnapshotFromTick(g->user_unblended_client, g->user_unblended_client->last_tick); g->local_sim_last_known_time_ns = newest_snapshot->sim_time_ns; g->local_sim_last_known_tick = newest_snapshot->tick; if (Atomic32Fetch(&g->user_paused)) @@ -654,10 +654,10 @@ void UpdateUser(void) } /* Get two snapshots nearest to render time */ - Snapshot *left_snapshot = NilSnapshot(); - Snapshot *right_snapshot = newest_snapshot; + PP_Snapshot *left_snapshot = PP_NilSnapshot(); + PP_Snapshot *right_snapshot = newest_snapshot; { - Snapshot *ss = SnapshotFromTick(g->user_unblended_client, g->user_unblended_client->first_tick); + PP_Snapshot *ss = PP_SnapshotFromTick(g->user_unblended_client, g->user_unblended_client->first_tick); while (ss->valid) { u64 next_tick = ss->next_tick; @@ -670,7 +670,7 @@ void UpdateUser(void) { right_snapshot = ss; } - ss = SnapshotFromTick(g->user_unblended_client, next_tick); + ss = PP_SnapshotFromTick(g->user_unblended_client, next_tick); } } @@ -678,21 +678,21 @@ void UpdateUser(void) if (left_snapshot->valid && right_snapshot->valid) { f64 blend = (f64)(g->render_time_ns - left_snapshot->sim_time_ns) / (f64)(right_snapshot->sim_time_ns - left_snapshot->sim_time_ns); - g->ss_blended = AcquireSnapshotFromLerp(g->user_blended_client, left_snapshot, right_snapshot, blend); + g->ss_blended = PP_AcquireSnapshotFromLerp(g->user_blended_client, left_snapshot, right_snapshot, blend); } else if (left_snapshot->valid) { - g->ss_blended = AcquireSnapshot(g->user_blended_client, left_snapshot, left_snapshot->tick); + g->ss_blended = PP_AcquireSnapshot(g->user_blended_client, left_snapshot, left_snapshot->tick); } else if (right_snapshot->valid) { - g->ss_blended = AcquireSnapshot(g->user_blended_client, right_snapshot, right_snapshot->tick); + g->ss_blended = PP_AcquireSnapshot(g->user_blended_client, right_snapshot, right_snapshot->tick); } /* Release unneeded unblended snapshots */ if (left_snapshot->tick > 0) { - ReleaseSnapshotsInRange(g->user_unblended_client, 0, left_snapshot->tick - 1); + PP_ReleaseSnapshotsInRange(g->user_unblended_client, 0, left_snapshot->tick - 1); } } else @@ -700,20 +700,20 @@ void UpdateUser(void) /* Interp disabled, just copy latest snapshot */ g->render_time_target_ns = newest_snapshot->sim_time_ns; g->render_time_ns = newest_snapshot->sim_time_ns; - g->ss_blended = AcquireSnapshot(g->user_blended_client, newest_snapshot, newest_snapshot->tick); + g->ss_blended = PP_AcquireSnapshot(g->user_blended_client, newest_snapshot, newest_snapshot->tick); /* Release unneeded unblended snapshots */ if (newest_snapshot->tick > 0) { - ReleaseSnapshotsInRange(g->user_unblended_client, 0, newest_snapshot->tick - 1); + PP_ReleaseSnapshotsInRange(g->user_unblended_client, 0, newest_snapshot->tick - 1); } } /* Release unneeded blended snapshots */ if (g->ss_blended->tick > 0) { - ReleaseSnapshotsInRange(g->user_blended_client, 0, g->ss_blended->tick - 1); - ReleaseSnapshotsInRange(g->user_blended_client, g->ss_blended->tick + 1, U64Max); + PP_ReleaseSnapshotsInRange(g->user_blended_client, 0, g->ss_blended->tick - 1); + PP_ReleaseSnapshotsInRange(g->user_blended_client, g->ss_blended->tick + 1, U64Max); } } @@ -724,7 +724,7 @@ void UpdateUser(void) /* Reset bind pressed / released states */ for (u32 i = 0; i < countof(g->bind_states); ++i) { - g->bind_states[i] = (BindState) { + g->bind_states[i] = (PP_BindState) { .is_held = g->bind_states[i].is_held }; } @@ -757,7 +757,7 @@ void UpdateUser(void) { Btn button = input->button; button = button >= Btn_Count ? Btn_None : button; - BindKind bind = g_binds[button]; + PP_BindKind bind = g_binds[button]; if (bind) { b32 pressed = input->kind == InputKind_ButtonDown; @@ -796,12 +796,12 @@ void UpdateUser(void) } //- Find local entities - Entity *local_player = EntityFromId(g->ss_blended, g->ss_blended->local_player); - Entity *local_control = EntityFromId(g->ss_blended, local_player->player_control_ent); - Entity *local_camera = EntityFromId(g->ss_blended, local_player->player_camera_ent); + PP_Ent *local_player = PP_EntFromKey(g->ss_blended, g->ss_blended->local_player); + PP_Ent *local_control = PP_EntFromKey(g->ss_blended, local_player->player_control_ent); + PP_Ent *local_camera = PP_EntFromKey(g->ss_blended, local_player->player_camera_ent); //- Find hovered entity - Entity *hovered_ent = NilEntity(); + PP_Ent *hovered_ent = PP_NilEnt(); { Xform mouse_xf = XformFromPos(g->world_cursor); CLD_Shape mouse_shape = ZI; @@ -810,18 +810,18 @@ void UpdateUser(void) mouse_shape.radius = 0.01f; for (u64 ent_index = 0; ent_index < g->ss_blended->num_ents_reserved; ++ent_index) { - Entity *ent = &g->ss_blended->ents[ent_index]; - if (!IsValidAndActive(ent)) continue; + PP_Ent *ent = &g->ss_blended->ents[ent_index]; + if (!PP_IsValidAndActive(ent)) continue; CLD_Shape ent_collider = ent->local_collider; if (ent_collider.count > 0) { /* TODO: Can just use boolean GJK */ - Xform ent_xf = XformFromEntity(ent); + Xform ent_xf = PP_XformFromEnt(ent); CLD_CollisionData collision_result = CLD_CollisionDataFromShapes(&ent_collider, &mouse_shape, ent_xf, mouse_xf); if (collision_result.num_points > 0) { - hovered_ent = EntityFromId(g->ss_blended, ent->top); + hovered_ent = PP_EntFromKey(g->ss_blended, ent->top); break; } } @@ -830,53 +830,53 @@ void UpdateUser(void) //- Update user state from binds { - if (g->bind_states[BindKind_Fullscreen].num_presses && g->bind_states[BindKind_FullscreenMod].is_held) + if (g->bind_states[PP_BindKind_Fullscreen].num_presses && g->bind_states[PP_BindKind_FullscreenMod].is_held) { WND_PushCmd(window_frame, .kind = WND_CmdKind_SetFullscreen, .v = !window_frame.fullscreen); } } - if (g->bind_states[BindKind_DebugDraw].num_presses > 0) + if (g->bind_states[PP_BindKind_DebugDraw].num_presses > 0) { g->debug_draw = !g->debug_draw; } - if (g->bind_states[BindKind_DebugToggleTopmost].num_presses > 0) + if (g->bind_states[PP_BindKind_DebugToggleTopmost].num_presses > 0) { WND_PushCmd(window_frame, .kind = WND_CmdKind_SetForcedTop, .v = !window_frame.forced_top); P_LogSuccessF("Toggle topmost"); } - if (g->bind_states[BindKind_DebugConsole].num_presses > 0) + if (g->bind_states[PP_BindKind_DebugConsole].num_presses > 0) { g->debug_console = !g->debug_console; } - if (g->bind_states[BindKind_DebugCamera].num_presses > 0) + if (g->bind_states[PP_BindKind_DebugCamera].num_presses > 0) { g->debug_camera = !g->debug_camera; } { - if (g->bind_states[BindKind_DebugFollow].num_presses > 0) + if (g->bind_states[PP_BindKind_DebugFollow].num_presses > 0) { - if (IsNilId(g->debug_following)) + if (PP_IsNilEntKey(g->debug_following)) { g->debug_following = hovered_ent->id; } else { - g->debug_following = NilEntityId; + g->debug_following = PP_NilEntKey; } } - if (!IsNilId(g->debug_following)) + if (!PP_IsNilEntKey(g->debug_following)) { - Entity *follow_ent = EntityFromId(g->ss_blended, g->debug_following); - Entity *follow_camera = NilEntity(); + PP_Ent *follow_ent = PP_EntFromKey(g->ss_blended, g->debug_following); + PP_Ent *follow_camera = PP_NilEnt(); for (u64 i = 0; i < g->ss_blended->num_ents_reserved; ++i) { - Entity *ent = &g->ss_blended->ents[i]; - Entity *ent_camera_follow = EntityFromId(g->ss_blended, ent->camera_follow); + PP_Ent *ent = &g->ss_blended->ents[i]; + PP_Ent *ent_camera_follow = PP_EntFromKey(g->ss_blended, ent->camera_follow); if (ent_camera_follow->valid && ent_camera_follow == follow_ent) { follow_camera = ent; @@ -889,7 +889,7 @@ void UpdateUser(void) } else { - g->debug_following = NilEntityId; + g->debug_following = PP_NilEntKey; } } } @@ -897,8 +897,8 @@ void UpdateUser(void) //- Apply shake for (u64 ent_index = 0; ent_index < g->ss_blended->num_ents_reserved; ++ent_index) { - Entity *ent = &g->ss_blended->ents[ent_index]; - if (!IsValidAndActive(ent)) continue; + PP_Ent *ent = &g->ss_blended->ents[ent_index]; + if (!PP_IsValidAndActive(ent)) continue; /* How much time between camera shakes */ i64 frequency_ns = NsFromSeconds(0.01f); @@ -918,9 +918,9 @@ void UpdateUser(void) f32 blend = (f32)(g->ss_blended->sim_time_ns % frequency_ns) / (f32)frequency_ns; Vec2 vec = LerpVec2(vec0, vec1, blend); - Xform xf = XformFromEntity(ent); + Xform xf = PP_XformFromEnt(ent); xf.og = AddVec2(xf.og, MulVec2(vec, shake)); - SetXform(ent, xf); + PP_SetXform(ent, xf); } } @@ -937,7 +937,7 @@ void UpdateUser(void) f32 aspect_ratio = (f32)(DEFAULT_CAMERA_WIDTH / DEFAULT_CAMERA_HEIGHT); if (local_camera->valid) { - Xform quad_xf = MulXform(XformFromEntity(local_camera), local_camera->camera_quad_xform); + Xform quad_xf = MulXform(PP_XformFromEnt(local_camera), local_camera->camera_quad_xform); Vec2 camera_size = ScaleFromXform(quad_xf); if (!IsVec2Zero(camera_size)) { @@ -973,7 +973,7 @@ void UpdateUser(void) Vec2 world_cursor = InvertXformMulV2(g->world_to_ui_xf, g->ui_cursor); /* Pan view */ - if (g->bind_states[BindKind_Pan].is_held) + if (g->bind_states[PP_BindKind_Pan].is_held) { if (!g->debug_camera_panning) { @@ -991,7 +991,7 @@ void UpdateUser(void) } /* Zoom view */ - i32 input_zooms = g->bind_states[BindKind_ZoomIn].num_presses - g->bind_states[BindKind_ZoomOut].num_presses; + i32 input_zooms = g->bind_states[PP_BindKind_ZoomIn].num_presses - g->bind_states[PP_BindKind_ZoomOut].num_presses; if (input_zooms != 0) { /* Zoom to cursor */ @@ -1005,7 +1005,7 @@ void UpdateUser(void) } else { - Xform xf = XformFromEntity(local_camera); + Xform xf = PP_XformFromEnt(local_camera); Vec2 world_center = xf.og; f32 rot = RotationFromXform(xf); @@ -1097,8 +1097,8 @@ void UpdateUser(void) u32 color0 = Rgba32F(0.17f, 0.17f, 0.17f, 1.f); u32 color1 = Rgba32F(0.15f, 0.15f, 0.15f, 1.f); - MaterialGrid *grid = PushStruct(g->grids_arena, MaterialGrid); - *grid = DefaultMaterialGrid; + PP_MaterialGrid *grid = PushStruct(g->grids_arena, PP_MaterialGrid); + *grid = PP_DefaultMaterialGrid; grid->line_thickness = thickness; grid->line_spacing = spacing; grid->offset = offset; @@ -1108,9 +1108,9 @@ void UpdateUser(void) grid->x_srgb = Color_Red; grid->y_srgb = Color_Green; - MaterialInstance *mat = PushStruct(g->material_instances_arena, MaterialInstance); - *mat = DefaultMaterialInstance; - mat->grid_id = grid - (MaterialGrid *)ArenaBase(g->grids_arena); + PP_MaterialInstance *mat = PushStruct(g->material_instances_arena, PP_MaterialInstance); + *mat = PP_DefaultMaterialInstance; + mat->grid_id = grid - (PP_MaterialGrid *)ArenaBase(g->grids_arena); mat->xf = XformFromRect(RectFromVec2(pos, size)); } @@ -1121,8 +1121,8 @@ void UpdateUser(void) for (u64 ent_index = 0; ent_index < g->ss_blended->num_ents_reserved; ++ent_index) { - Entity *chunk_ent = &g->ss_blended->ents[ent_index]; - if (IsValidAndActive(chunk_ent) && HasProp(chunk_ent, Prop_TileChunk)) + PP_Ent *chunk_ent = &g->ss_blended->ents[ent_index]; + if (PP_IsValidAndActive(chunk_ent) && PP_HasProp(chunk_ent, PP_Prop_TileChunk)) { struct user_tile_cache_entry *entry = user_tile_cache_entry_from_chunk_pos(chunk_ent->tile_chunk_pos); if (!entry->valid) @@ -1139,7 +1139,7 @@ void UpdateUser(void) struct tile_cache_entry *entry = &g->tile_cache.entries[entry_index]; if (entry->valid) { - Entity *chunk_ent = sim_ent_from_chunk_pos(entry->pos); + PP_Ent *chunk_ent = sim_ent_from_chunk_pos(entry->pos); if (!chunk_ent->valid) { user_tile_cache_entry_release(entry); @@ -1155,7 +1155,7 @@ void UpdateUser(void) if (entry->valid) { Vec2I32 chunk_pos = entry->pos; - Entity *chunk_ent = sim_ent_from_chunk_pos(chunk_pos); + PP_Ent *chunk_ent = sim_ent_from_chunk_pos(chunk_pos); if (entry->applied_dirty_gen != chunk_ent->dirty_gen) { entry->applied_dirty_gen = chunk_ent->dirty_gen; @@ -1187,7 +1187,7 @@ void UpdateUser(void) if (entry->valid) { Vec2I32 chunk_pos = entry->pos; - Entity *chunk_ent = sim_ent_from_chunk_pos(chunk_pos); + PP_Ent *chunk_ent = sim_ent_from_chunk_pos(chunk_pos); if (entry->applied_dirty_gen != chunk_ent->dirty_gen) { entry->applied_dirty_gen = chunk_ent->dirty_gen; @@ -1205,14 +1205,14 @@ void UpdateUser(void) Vec2I32 chunk_pos_bl = VEC2I32(chunk_pos.x - 1, chunk_pos.y + 1); Vec2I32 chunk_pos_b = VEC2I32(chunk_pos.x, chunk_pos.y + 1); Vec2I32 chunk_pos_br = VEC2I32(chunk_pos.x + 1, chunk_pos.y + 1); - Entity *chunk_ent_tl = sim_ent_from_chunk_pos(chunk_pos_tl); - Entity *chunk_ent_t = sim_ent_from_chunk_pos(chunk_pos_t); - Entity *chunk_ent_tr = sim_ent_from_chunk_pos(chunk_pos_tr); - Entity *chunk_ent_l = sim_ent_from_chunk_pos(chunk_pos_l); - Entity *chunk_ent_r = sim_ent_from_chunk_pos(chunk_pos_r); - Entity *chunk_ent_bl = sim_ent_from_chunk_pos(chunk_pos_bl); - Entity *chunk_ent_b = sim_ent_from_chunk_pos(chunk_pos_b); - Entity *chunk_ent_br = sim_ent_from_chunk_pos(chunk_pos_br); + PP_Ent *chunk_ent_tl = sim_ent_from_chunk_pos(chunk_pos_tl); + PP_Ent *chunk_ent_t = sim_ent_from_chunk_pos(chunk_pos_t); + PP_Ent *chunk_ent_tr = sim_ent_from_chunk_pos(chunk_pos_tr); + PP_Ent *chunk_ent_l = sim_ent_from_chunk_pos(chunk_pos_l); + PP_Ent *chunk_ent_r = sim_ent_from_chunk_pos(chunk_pos_r); + PP_Ent *chunk_ent_bl = sim_ent_from_chunk_pos(chunk_pos_bl); + PP_Ent *chunk_ent_b = sim_ent_from_chunk_pos(chunk_pos_b); + PP_Ent *chunk_ent_br = sim_ent_from_chunk_pos(chunk_pos_br); String data = sim_ent_get_chunk_tile_data(chunk_ent); } @@ -1222,7 +1222,7 @@ void UpdateUser(void) #endif //- Sort drawable entities - Entity **sorted = PushDry(scratch.arena, Entity *); + PP_Ent **sorted = PushDry(scratch.arena, PP_Ent *); u64 sorted_count = 0; { /* Copy valid entities */ @@ -1230,10 +1230,10 @@ void UpdateUser(void) __profn("Build ents list for sorting"); for (u64 ent_index = 0; ent_index < g->ss_blended->num_ents_reserved; ++ent_index) { - Entity *ent = &g->ss_blended->ents[ent_index]; - if (IsValidAndActive(ent)) + PP_Ent *ent = &g->ss_blended->ents[ent_index]; + if (PP_IsValidAndActive(ent)) { - *PushStructNoZero(scratch.arena, Entity *) = ent; + *PushStructNoZero(scratch.arena, PP_Ent *) = ent; ++sorted_count; } } @@ -1241,7 +1241,7 @@ void UpdateUser(void) /* Sort */ { __profn("Sort ents"); - Mergesort(sorted, sorted_count, sizeof(*sorted), EntitySortCmp, 0); + Mergesort(sorted, sorted_count, sizeof(*sorted), PP_EntSortCmp, 0); } } @@ -1250,21 +1250,21 @@ void UpdateUser(void) __profn("Draw entities"); for (u64 sorted_index = 0; sorted_index < sorted_count; ++sorted_index) { - Entity *ent = sorted[sorted_index]; - if (!IsValidAndActive(ent)) continue; + PP_Ent *ent = sorted[sorted_index]; + if (!PP_IsValidAndActive(ent)) continue; //if (S_IsNil(ent->sprite)) continue; ResourceKey sprite = ent->sprite; - Entity *parent = EntityFromId(g->ss_blended, ent->parent); + PP_Ent *parent = PP_EntFromKey(g->ss_blended, ent->parent); - Xform xf = XformFromEntity(ent); - UNUSED Xform parent_xf = XformFromEntity(parent); + Xform xf = PP_XformFromEnt(ent); + UNUSED Xform parent_xf = PP_XformFromEnt(parent); b32 skip_debug_draw = !g->debug_camera && ent == local_camera; - skip_debug_draw = skip_debug_draw || HasProp(ent, Prop_MotorJoint); + skip_debug_draw = skip_debug_draw || PP_HasProp(ent, PP_Prop_MotorJoint); - b32 skip_debug_draw_transform = HasProp(ent, Prop_Camera); + b32 skip_debug_draw_transform = PP_HasProp(ent, PP_Prop_Camera); skip_debug_draw_transform = 1; UNUSED Xform sprite_xform = MulXform(xf, ent->sprite_local_xform); @@ -1272,7 +1272,7 @@ void UpdateUser(void) /* Draw tracer */ /* TODO: Enable this */ #if 0 - if (HasProp(ent, Prop_Tracer)) + if (PP_HasProp(ent, PP_Prop_Tracer)) { Vec2 velocity = ent->tracer_start_velocity; @@ -1323,12 +1323,12 @@ void UpdateUser(void) /* TODO: Fade in placeholder if texture isn't loaded */ if (sheet->loaded && texture->loaded) { - b32 is_light = HasProp(ent, Prop_LightTest); + b32 is_light = PP_HasProp(ent, PP_Prop_LightTest); Vec3 emittance = ent->sprite_emittance; u32 tint = ent->sprite_tint; S_Frame frame = S_FrameFromIndex(sheet, ent->animation_frame); - MaterialInstance *mat = PushStruct(g->material_instances_arena, MaterialInstance); - *mat = DefaultMaterialInstance; + PP_MaterialInstance *mat = PushStruct(g->material_instances_arena, PP_MaterialInstance); + *mat = PP_DefaultMaterialInstance; mat->xf = sprite_xform; mat->tex = GPU_Texture2DRidFromResource(texture->gpu_texture); mat->tint_srgb = tint; @@ -1341,10 +1341,10 @@ void UpdateUser(void) /* Draw tiles */ /* TODO: Something better */ - if (HasProp(ent, Prop_TileChunk)) + if (PP_HasProp(ent, PP_Prop_TileChunk)) { Vec2I32 chunk_index = ent->tile_chunk_index; - ResourceKey tile_sprite = ResourceKeyFromStore(&GameResources, Lit("sprite/tile.ase")); + ResourceKey tile_sprite = ResourceKeyFromStore(&PP_Resources, Lit("sprite/tile.ase")); S_Texture *tile_texture = S_TextureFromResourceAsync(tile_sprite); if (tile_texture->loaded) { @@ -1354,16 +1354,16 @@ void UpdateUser(void) for (i32 tile_x = 0; tile_x < SIM_TILES_PER_CHUNK_SQRT; ++tile_x) { Vec2I32 local_tile_index = VEC2I32(tile_x, tile_y); - TileKind tile = ent->tile_chunk_tiles[local_tile_index.x + (local_tile_index.y * SIM_TILES_PER_CHUNK_SQRT)]; + PP_TileKind tile = ent->tile_chunk_tiles[local_tile_index.x + (local_tile_index.y * SIM_TILES_PER_CHUNK_SQRT)]; /* FIXME: Enable this */ //if (tile > -1) - if (tile == TileKind_Wall) + if (tile == PP_TileKind_Wall) { - Vec2I32 world_tile_index = WorldTileIndexFromLocalTileIndex(chunk_index, local_tile_index); - Vec2 pos = PosFromWorldTileIndex(world_tile_index); + Vec2I32 world_tile_index = PP_WorldTileIndexFromLocalTileIndex(chunk_index, local_tile_index); + Vec2 pos = PP_PosFromWorldTileIndex(world_tile_index); Xform tile_xf = XformFromRect(RectFromVec2(pos, VEC2(tile_size, tile_size))); - MaterialInstance *mat = PushStruct(g->material_instances_arena, MaterialInstance); - *mat = DefaultMaterialInstance; + PP_MaterialInstance *mat = PushStruct(g->material_instances_arena, PP_MaterialInstance); + *mat = PP_DefaultMaterialInstance; mat->xf = tile_xf; mat->tex = GPU_Texture2DRidFromResource(tile_texture->gpu_texture); mat->is_light = 1; @@ -1379,9 +1379,9 @@ void UpdateUser(void) { TempArena temp = BeginTempArena(scratch.arena); - if (HasProp(ent, Prop_Kinematic) || HasProp(ent, Prop_Dynamic)) + if (PP_HasProp(ent, PP_Prop_Kinematic) || PP_HasProp(ent, PP_Prop_Dynamic)) { - DrawDebugMovement(ent); + PP_DrawDebugMovement(ent); } /* Draw xform */ @@ -1389,7 +1389,7 @@ void UpdateUser(void) { u32 color_x = Rgba32F(1, 0, 0, 0.5); u32 color_y = Rgba32F(0, 1, 0, 0.5); - DrawDebugXform(xf, color_x, color_y); + PP_DrawDebugXform(xf, color_x, color_y); } /* Draw AABB */ @@ -1406,7 +1406,7 @@ void UpdateUser(void) } /* Draw focus arrow */ - if (ent == local_control || EqId(ent->id, g->debug_following)) + if (ent == local_control || PP_EqEntKey(ent->id, g->debug_following)) { S_Sheet *sheet = S_SheetFromResourceAsync(ent->sprite); S_Slice slice = S_SliceFromNameIndex(sheet, Lit("attach.wep"), ent->animation_frame); @@ -1464,10 +1464,10 @@ void UpdateUser(void) /* Draw weld joint */ #if 0 - if (HasProp(ent, Prop_WeldJoint)) + if (PP_HasProp(ent, PP_Prop_WeldJoint)) { - Entity *e1 = EntityFromId(g->ss_blended, ent->weld_joint_data.e1); - Xform e1_xf = XformFromEntity(e1); + PP_Ent *e1 = PP_EntFromKey(g->ss_blended, ent->weld_joint_data.e1); + Xform e1_xf = PP_XformFromEnt(e1); u32 color = Color_Yellow; f32 radius = 3; @@ -1482,10 +1482,10 @@ void UpdateUser(void) /* Draw mouse joint */ /* FIXME: Enable this */ #if 0 - if (HasProp(ent, Prop_MouseJoint)) + if (PP_HasProp(ent, PP_Prop_MouseJoint)) { - Entity *target = EntityFromId(g->ss_blended, ent->mouse_joint_data.target); - Xform target_xf = XformFromEntity(target); + PP_Ent *target = PP_EntFromKey(g->ss_blended, ent->mouse_joint_data.target); + Xform target_xf = PP_XformFromEnt(target); u32 color = Color_White; Vec2 point_start = MulXformV2(target_xf, ent->mouse_joint_data.point_local_start); Vec2 point_end = g->world_cursor; @@ -1541,11 +1541,11 @@ void UpdateUser(void) /* Draw contact constraint */ /* FIXME: Enable this */ #if 0 - if (HasProp(ent, Prop_ContactConstraint)) + if (PP_HasProp(ent, PP_Prop_ContactConstraint)) { ContactConstraint *data = &ent->contact_constraint_data; - Entity *e0 = EntityFromId(g->ss_blended, data->e0); - Entity *e1 = EntityFromId(g->ss_blended, data->e1); + PP_Ent *e0 = PP_EntFromKey(g->ss_blended, data->e0); + PP_Ent *e1 = PP_EntFromKey(g->ss_blended, data->e1); LAX e0; LAX e1; @@ -1576,7 +1576,7 @@ void UpdateUser(void) #if 0 /* Draw contact info */ { - F_Font *disp_font = F_LoadFontAsync(ResourceKeyFromStore(&GameResources, Lit("font/fixedsys.ttf")), 12.0f); + F_Font *disp_font = F_LoadFontAsync(ResourceKeyFromStore(&PP_Resources, Lit("font/fixedsys.ttf")), 12.0f); if (disp_font) { f32 offset_px = 10; @@ -1613,12 +1613,12 @@ void UpdateUser(void) /* Draw collision debug */ #if COLLIDER_DEBUG - if (HasProp(ent, Prop_CollisionDebug)) + if (PP_HasProp(ent, PP_Prop_CollisionDebug)) { ContactDebugData *data = &ent->collision_debug_data; CLD_CollisionData collision_reuslt = data->collision_result; - Entity *e0 = EntityFromId(g->ss_blended, data->e0); - Entity *e1 = EntityFromId(g->ss_blended, data->e1); + PP_Ent *e0 = PP_EntFromKey(g->ss_blended, data->e0); + PP_Ent *e1 = PP_EntFromKey(g->ss_blended, data->e1); CLD_Shape e0_collider = e0->local_collider; CLD_Shape e1_collider = e1->local_collider; LAX e0_collider; @@ -1698,7 +1698,7 @@ void UpdateUser(void) #if 0 /* Test info */ { - F_Font *disp_font = F_LoadFontAsync(ResourceKeyFromStore(&GameResources, Lit("font/fixedsys.ttf")), 12.0f); + F_Font *disp_font = F_LoadFontAsync(ResourceKeyFromStore(&PP_Resources, Lit("font/fixedsys.ttf")), 12.0f); if (disp_font) { f32 offset_px = 10; @@ -1814,7 +1814,7 @@ void UpdateUser(void) /* Draw hierarchy */ /* FIXME: Enable this */ #if 0 - if (HasProp(parent, Prop_Active) && !parent->is_root) + if (PP_HasProp(parent, PP_Prop_Active) && !parent->is_root) { u32 color = Rgba32F(0.6, 0.6, 1, 0.75); f32 thickness = 2; @@ -1826,7 +1826,7 @@ void UpdateUser(void) } /* Draw camera rect */ - if (HasProp(ent, Prop_Camera)) + if (PP_HasProp(ent, PP_Prop_Camera)) { u32 color = ent == local_camera ? Rgba32F(1, 1, 1, 0.5) : Rgba32F(0, 0.75, 0, 0.5); f32 thickness = 3; @@ -1851,7 +1851,7 @@ void UpdateUser(void) { __profn("Draw crosshair"); Vec2 crosshair_pos = g->ui_cursor; - ResourceKey crosshair = ResourceKeyFromStore(GameResources, Lit("sprite/crosshair.ase")); + ResourceKey crosshair = ResourceKeyFromStore(PP_Resources, Lit("sprite/crosshair.ase")); S_Texture *t = S_TextureFromResourceAsync(crosshair); Vec2 size = VEC2(t->width, t->height); Xform xf = XformFromTrs(TRS(.t = crosshair_pos, .s = size)); @@ -1870,7 +1870,7 @@ void UpdateUser(void) } else { - S_Texture *t = S_TextureFromResourceAsync(ResourceKeyFromStore(GameResources, Lit("sprite/crosshair.ase"))); + S_Texture *t = S_TextureFromResourceAsync(ResourceKeyFromStore(PP_Resources, Lit("sprite/crosshair.ase"))); Vec2 size = VEC2(t->width, t->height); Rect cursor_clip = RectFromVec2(g->ui_screen_offset, g->ui_size); cursor_clip.pos = AddVec2(cursor_clip.pos, MulVec2(size, 0.5f)); @@ -1887,8 +1887,8 @@ void UpdateUser(void) { /* Queue player move cmd */ f32 move_speed = 1.0f; - //if (g->bind_states[BindKind_Walk].is_held) - if (g->bind_states[BindKind_FullscreenMod].is_held) + //if (g->bind_states[PP_BindKind_Walk].is_held) + if (g->bind_states[PP_BindKind_FullscreenMod].is_held) { //const f32 walk_ratio = 0.25f; const f32 walk_ratio = 0.05f; @@ -1897,9 +1897,9 @@ void UpdateUser(void) Vec2 input_move_dir = ZI; { - for (BindKind bind = 0; bind < (i32)countof(g->bind_states); ++bind) + for (PP_BindKind bind = 0; bind < (i32)countof(g->bind_states); ++bind) { - BindState state = g->bind_states[bind]; + PP_BindState state = g->bind_states[bind]; if (!state.is_held && state.num_presses <= 0) { @@ -1911,22 +1911,22 @@ void UpdateUser(void) default: break; /* Movement */ - case BindKind_MoveUp: + case PP_BindKind_MoveUp: { input_move_dir.y -= 1; } break; - case BindKind_MoveDown: + case PP_BindKind_MoveDown: { input_move_dir.y += 1; } break; - case BindKind_MoveLeft: + case PP_BindKind_MoveLeft: { input_move_dir.x -= 1; } break; - case BindKind_MoveRight: + case PP_BindKind_MoveRight: { input_move_dir.x += 1; } break; @@ -1939,84 +1939,84 @@ void UpdateUser(void) if (!g->debug_camera) { - g->focus_send = SubVec2(g->world_cursor, XformFromEntity(local_control).og); + g->focus_send = SubVec2(g->world_cursor, PP_XformFromEnt(local_control).og); } Vec2 input_aim_dir = g->focus_send; /* Queue player control cmd */ { - ControlData control = ZI; + PP_ControlData control = ZI; control.move = input_move_dir; control.focus = input_aim_dir; control.dbg_cursor = g->world_cursor; - BindState fire_state = g->bind_states[BindKind_Fire]; - BindState fire_alt_state = g->bind_states[BindKind_AltFire]; - BindState drag_state = g->bind_states[BindKind_DebugDrag]; - BindState delete_state = g->bind_states[BindKind_DebugDelete]; - BindState clear_state = g->bind_states[BindKind_DebugClear]; - BindState spawn1_state = g->bind_states[BindKind_DebugSpawn1]; - BindState spawn2_state = g->bind_states[BindKind_DebugSpawn2]; - BindState spawn3_state = g->bind_states[BindKind_DebugSpawn3]; - BindState spawn4_state = g->bind_states[BindKind_DebugSpawn4]; - BindState walls_state = g->bind_states[BindKind_DebugWalls]; - BindState pause_state = g->bind_states[BindKind_DebugPause]; - BindState step_state = g->bind_states[BindKind_DebugStep]; - BindState tile_state = g->bind_states[BindKind_TestTile]; - BindState explode_state = g->bind_states[BindKind_DebugExplode]; - BindState teleport_state = g->bind_states[BindKind_DebugTeleport]; + PP_BindState fire_state = g->bind_states[PP_BindKind_Fire]; + PP_BindState fire_alt_state = g->bind_states[PP_BindKind_AltFire]; + PP_BindState drag_state = g->bind_states[PP_BindKind_DebugDrag]; + PP_BindState delete_state = g->bind_states[PP_BindKind_DebugDelete]; + PP_BindState clear_state = g->bind_states[PP_BindKind_DebugClear]; + PP_BindState spawn1_state = g->bind_states[PP_BindKind_DebugSpawn1]; + PP_BindState spawn2_state = g->bind_states[PP_BindKind_DebugSpawn2]; + PP_BindState spawn3_state = g->bind_states[PP_BindKind_DebugSpawn3]; + PP_BindState spawn4_state = g->bind_states[PP_BindKind_DebugSpawn4]; + PP_BindState walls_state = g->bind_states[PP_BindKind_DebugWalls]; + PP_BindState pause_state = g->bind_states[PP_BindKind_DebugPause]; + PP_BindState step_state = g->bind_states[PP_BindKind_DebugStep]; + PP_BindState tile_state = g->bind_states[PP_BindKind_TestTile]; + PP_BindState explode_state = g->bind_states[PP_BindKind_DebugExplode]; + PP_BindState teleport_state = g->bind_states[PP_BindKind_DebugTeleport]; if (fire_state.num_presses || fire_state.is_held) { - control.flags |= ControlFlag_Fire; + control.flags |= PP_ControlFlag_Fire; } if (fire_alt_state.num_presses || fire_alt_state.is_held) { - control.flags |= ControlFlag_AltFire; + control.flags |= PP_ControlFlag_AltFire; } if (drag_state.num_presses || drag_state.is_held) { - control.flags |= ControlFlag_Drag; + control.flags |= PP_ControlFlag_Drag; } if (delete_state.num_presses || delete_state.is_held) { - control.flags |= ControlFlag_Delete; + control.flags |= PP_ControlFlag_Delete; } if (clear_state.num_presses_and_repeats) { - control.flags |= ControlFlag_ClearAll; + control.flags |= PP_ControlFlag_ClearAll; } if (spawn1_state.num_presses_and_repeats) { - control.flags |= ControlFlag_SpawnTest1; + control.flags |= PP_ControlFlag_SpawnTest1; } if (spawn2_state.num_presses_and_repeats) { - control.flags |= ControlFlag_SpawnTest2; + control.flags |= PP_ControlFlag_SpawnTest2; } if (spawn3_state.num_presses_and_repeats) { - control.flags |= ControlFlag_SpawnTest3; + control.flags |= PP_ControlFlag_SpawnTest3; } if (spawn4_state.num_presses_and_repeats) { - control.flags |= ControlFlag_SpawnTest4; + control.flags |= PP_ControlFlag_SpawnTest4; } if (walls_state.num_presses_and_repeats) { - control.flags |= ControlFlag_TestWalls; + control.flags |= PP_ControlFlag_TestWalls; } if (tile_state.num_presses || tile_state.is_held) { - control.flags |= ControlFlag_TestTiles; + control.flags |= PP_ControlFlag_TestTiles; } if (explode_state.num_presses_and_repeats) { - control.flags |= ControlFlag_TestExplode; + control.flags |= PP_ControlFlag_TestExplode; } if (teleport_state.num_presses_and_repeats || (g->debug_camera && teleport_state.is_held)) { - control.flags |= ControlFlag_TestTeleport; + control.flags |= PP_ControlFlag_TestTeleport; } if (pause_state.num_presses) @@ -2047,13 +2047,13 @@ void UpdateUser(void) #if RtcIsEnabled /* Gjk steps */ { - if (g->bind_states[BindKind_ResetDebugSteps].num_presses_and_repeats > 0) + if (g->bind_states[PP_BindKind_ResetDebugSteps].num_presses_and_repeats > 0) { SetGstat(GSTAT_DEBUG_STEPS, 0); } i32 add_steps = 0; - add_steps += g->bind_states[BindKind_IncrementDebugSteps].num_presses_and_repeats; - add_steps -= g->bind_states[BindKind_DecrementDebugSteps].num_presses_and_repeats; + add_steps += g->bind_states[PP_BindKind_IncrementDebugSteps].num_presses_and_repeats; + add_steps -= g->bind_states[PP_BindKind_DecrementDebugSteps].num_presses_and_repeats; if (add_steps != 0) { AddGstat(GSTAT_DEBUG_STEPS, add_steps); @@ -2082,17 +2082,17 @@ void UpdateUser(void) #if 0 if (g->debug_draw && hovered_ent->valid) { - Entity *ent = hovered_ent; + PP_Ent *ent = hovered_ent; Vec2 pos = AddVec2(g->ui_cursor, VEC2(15, 15)); - F_Font *font = F_LoadFontAsync(ResourceKeyFromStore(&GameResources, Lit("font/fixedsys.ttf")), 12.0f); + F_Font *font = F_LoadFontAsync(ResourceKeyFromStore(&PP_Resources, Lit("font/fixedsys.ttf")), 12.0f); if (font) { TempArena temp = BeginTempArena(scratch.arena); String dbg_text = ZI; dbg_text.text = PushDry(temp.arena, u8); - dbg_text.len += DebugStringFromEntity(temp.arena, ent).len; + dbg_text.len += PP_DebugStringFromEnt(temp.arena, ent).len; draw_text(g->render_sig, D_TEXTPARAMS(.font = font, .pos = pos, .str = dbg_text)); EndTempArena(temp); @@ -2108,7 +2108,7 @@ void UpdateUser(void) /* Draw console */ { b32 console_minimized = !g->debug_console; - DrawDebugConsole(console_minimized); + PP_DrawDebugConsole(console_minimized); } /* Draw debug info */ @@ -2152,13 +2152,13 @@ void UpdateUser(void) Vec2 world_cursor = g->world_cursor; UI_BuildLabelF("cursor world: %F, %F", FmtFloat(world_cursor.x), FmtFloat(world_cursor.y)); - Vec2I32 world_tile_cursor = WorldTileIndexFromPos(world_cursor); + Vec2I32 world_tile_cursor = PP_WorldTileIndexFromPos(world_cursor); UI_BuildLabelF("cursor world tile: %F, %F", FmtSint(world_tile_cursor.x), FmtSint(world_tile_cursor.y)); - Vec2I32 local_tile_cursor = LocalTileIndexFromWorldTileIndex(world_tile_cursor); + Vec2I32 local_tile_cursor = PP_LocalTileIndexFromWorldTileIndex(world_tile_cursor); UI_BuildLabelF("cursor local tile: %F, %F", FmtSint(local_tile_cursor.x), FmtSint(local_tile_cursor.y)); - Vec2I32 tile_chunk_cursor = TileChunkIndexFromWorldTileIndex(world_tile_cursor); + Vec2I32 tile_chunk_cursor = PP_TileChunkIndexFromWorldTileIndex(world_tile_cursor); UI_BuildLabelF("cursor tile chunk: %F, %F", FmtSint(tile_chunk_cursor.x), FmtSint(tile_chunk_cursor.y)); UI_BuildSpacer(UI_EM(1.5, 0)); @@ -2223,12 +2223,12 @@ void UpdateUser(void) if (!g->shade_target) { __profn("Acquire sig resources"); - g->albedo = AcquireGbuffer(GPU_Format_R8G8B8A8_Unorm, g->render_size); - g->emittance = AcquireGbuffer(GPU_Format_R16G16B16A16_Float, g->render_size); - g->emittance_flood_read = AcquireGbuffer(GPU_Format_R16G16_Uint, g->render_size); - g->emittance_flood_target = AcquireGbuffer(GPU_Format_R16G16_Uint, g->render_size); - g->shade_read = AcquireGbuffer(GPU_Format_R16G16B16A16_Float, g->render_size); - g->shade_target = AcquireGbuffer(GPU_Format_R16G16B16A16_Float, g->render_size); + g->albedo = PP_AcquireGbuffer(GPU_Format_R8G8B8A8_Unorm, g->render_size); + g->emittance = PP_AcquireGbuffer(GPU_Format_R16G16B16A16_Float, g->render_size); + g->emittance_flood_read = PP_AcquireGbuffer(GPU_Format_R16G16_Uint, g->render_size); + g->emittance_flood_target = PP_AcquireGbuffer(GPU_Format_R16G16_Uint, g->render_size); + g->shade_read = PP_AcquireGbuffer(GPU_Format_R16G16B16A16_Float, g->render_size); + g->shade_target = PP_AcquireGbuffer(GPU_Format_R16G16B16A16_Float, g->render_size); } /* Acquire ui target */ @@ -2285,14 +2285,14 @@ void UpdateUser(void) GPU_Viewport viewport = GPU_ViewportFromRect(render_viewport); GPU_Scissor scissor = GPU_ScissorFromRect(render_viewport); - MaterialSig sig = ZI; + PP_MaterialSig sig = ZI; sig.projection = world_to_render_vp_matrix; sig.sampler = GPU_SamplerStateRidFromResource(GPU_GetCommonPointSampler()); sig.instances = GPU_StructuredBufferRidFromResource(material_instances_buffer); sig.grids = GPU_StructuredBufferRidFromResource(grids_buffer); GPU_Rasterize(cl, &sig, - MaterialVS, MaterialPS, + PP_MaterialVS, PP_MaterialPS, 2, viewport, scissor, @@ -2326,14 +2326,14 @@ void UpdateUser(void) GPU_FlushWritable(cl, g->emittance_flood_read); - FloodSig sig = ZI; + PP_FloodSig sig = ZI; sig.step_len = step_length; sig.emittance = GPU_Texture2DRidFromResource(g->emittance); sig.read = GPU_RWTexture2DRidFromResource(g->emittance_flood_read); sig.target = GPU_RWTexture2DRidFromResource(g->emittance_flood_target); sig.tex_width = g->render_size.x; sig.tex_height = g->render_size.y; - GPU_Compute(cl, &sig, FloodCS, (g->render_size.x + 7) / 8, (g->render_size.y + 7) / 8, 1); + GPU_Compute(cl, &sig, PP_FloodCS, (g->render_size.x + 7) / 8, (g->render_size.y + 7) / 8, 1); /* Swap buffers */ GPU_Resource *swp = g->emittance_flood_read; @@ -2370,13 +2370,13 @@ void UpdateUser(void) GPU_ProfN(cl, Lit("Shade pass")); Vec3I32 noise_size = GPU_GetTextureSize3D(GPU_GetCommonNoise()); - u32 shade_flags = ShadeFlag_None | ShadeFlag_ToneMap; + u32 shade_flags = PP_ShadeFlag_None | PP_ShadeFlag_ToneMap; if (effects_disabled) { - shade_flags |= ShadeFlag_DisableEffects; + shade_flags |= PP_ShadeFlag_DisableEffects; } - ShadeSig sig = ZI; + PP_ShadeSig sig = ZI; sig.flags = shade_flags; sig.tex_width = g->render_size.x; sig.tex_height = g->render_size.y; @@ -2396,7 +2396,7 @@ void UpdateUser(void) sig.noise_tex_width = noise_size.x; sig.noise_tex_height = noise_size.y; sig.noise_tex_depth = noise_size.z; - GPU_Compute(cl, &sig, ShadeCS, (g->render_size.x + 7) / 8, (g->render_size.y + 7) / 8, 1); + GPU_Compute(cl, &sig, PP_ShadeCS, (g->render_size.x + 7) / 8, (g->render_size.y + 7) / 8, 1); /* Swap */ GPU_Resource *swp = g->shade_read; @@ -2451,9 +2451,9 @@ void UpdateUser(void) //////////////////////////////////////////////////////////// //~ User update job -JobDef(UpdateUserOrSleep, UNUSED sig, UNUSED id) +JobDef(PP_UpdateUserOrSleep, UNUSED sig, UNUSED id) { - SharedUserState *g = &shared_user_state; + PP_SharedUserState *g = &PP_shared_user_state; i64 time_ns = TimeNs(); while (!Atomic32Fetch(&g->shutdown)) { @@ -2464,28 +2464,28 @@ JobDef(UpdateUserOrSleep, UNUSED sig, UNUSED id) P_SleepFrame(time_ns, 1000000000 / fps_limit); time_ns = TimeNs(); } - UpdateUser(); + PP_UpdateUser(); } } //////////////////////////////////////////////////////////// //~ Generate user input cmds -void GenerateuserInputCmds(Client *user_input_client, u64 tick) +void PP_GenerateuserInputCmds(PP_Client *user_input_client, u64 tick) { - SharedUserState *g = &shared_user_state; - Snapshot *prev_user_input_ss = SnapshotFromTick(user_input_client, user_input_client->last_tick); - Snapshot *user_input_ss = AcquireSnapshot(user_input_client, prev_user_input_ss, tick); - Entity *user_input_root = EntityFromId(user_input_ss, RootEntityId); + PP_SharedUserState *g = &PP_shared_user_state; + PP_Snapshot *prev_user_input_ss = PP_SnapshotFromTick(user_input_client, user_input_client->last_tick); + PP_Snapshot *user_input_ss = PP_AcquireSnapshot(user_input_client, prev_user_input_ss, tick); + PP_Ent *user_input_root = PP_EntFromKey(user_input_ss, PP_RootEntKey); /* Find / create local control cmd ent */ - Entity *control_cmd = FirstWithProp(user_input_ss, Prop_Cmd); + PP_Ent *control_cmd = PP_FirstWithProp(user_input_ss, PP_Prop_Cmd); if (!control_cmd->valid) { - control_cmd = AcquireSyncSrc(user_input_root); - control_cmd->cmd_kind = CmdKind_Control; + control_cmd = PP_AcquireSyncSrcEnt(user_input_root); + control_cmd->cmd_kind = PP_CmdKind_Control; control_cmd->predictor = user_input_client->player_id; - EnableProp(control_cmd, Prop_Cmd); - Activate(control_cmd, user_input_ss->tick); + PP_EnableProp(control_cmd, PP_Prop_Cmd); + PP_ActivateEnt(control_cmd, user_input_ss->tick); } { Lock lock = LockE(&g->user_sim_cmd_mutex); @@ -2498,8 +2498,8 @@ void GenerateuserInputCmds(Client *user_input_client, u64 tick) /* Create chat cmd */ if (g->user_sim_cmd_chat.len > 0) { - Entity *chat_cmd = AcquireSyncSrc(user_input_root); - chat_cmd->cmd_kind = CmdKind_Chat; + PP_Ent *chat_cmd = PP_AcquireSyncSrcEnt(user_input_root); + chat_cmd->cmd_kind = PP_CmdKind_Chat; //chat_cmd->chat_msg = ZI } #endif @@ -2511,9 +2511,9 @@ void GenerateuserInputCmds(Client *user_input_client, u64 tick) //////////////////////////////////////////////////////////// //~ Sim update -JobDef(UpdateSim, UNUSED sig, UNUSED id) +JobDef(PP_UpdateSim, UNUSED sig, UNUSED id) { - SharedUserState *g = &shared_user_state; + PP_SharedUserState *g = &PP_shared_user_state; #if 0 struct host_listen_address local_listen_addr = host_listen_address_from_local_name(Lit("LOCAL_SIM")); struct host_listen_address net_listen_addr = host_listen_address_from_net_port(12345); @@ -2539,15 +2539,15 @@ JobDef(UpdateSim, UNUSED sig, UNUSED id) BB_Buff msg_writer_bb = BB_AcquireBuff(Gibi(64)); BB_Buff snapshot_writer_bb = BB_AcquireBuff(Gibi(64)); - SimAccel accel = AcquireSimAccel(); + PP_Accel accel = PP_AcquireAccel(); - ClientStore *store = AcquireClientStore(); - Client *user_input_client = AcquireClient(store); /* Stores snapshots containing commands to be published to local client */ - Client *local_client = AcquireClient(store); /* Stores snapshots produced locally */ - Client *publish_client = AcquireClient(store); /* Stores versions of local snapshots that will be published to remote sims */ + PP_ClientStore *store = PP_AcquireClientStore(); + PP_Client *user_input_client = PP_AcquireClient(store); /* Stores snapshots containing commands to be published to local client */ + PP_Client *local_client = PP_AcquireClient(store); /* Stores snapshots produced locally */ + PP_Client *publish_client = PP_AcquireClient(store); /* Stores versions of local snapshots that will be published to remote sims */ - Client *master_client = NilClient(); /* Stores snapshots received from master */ - Client *master_blended_client = NilClient(); /* Stores interpolated master snapshots */ + PP_Client *master_client = PP_NilClient(); /* Stores snapshots received from master */ + PP_Client *master_blended_client = PP_NilClient(); /* Stores interpolated master snapshots */ b32 initialized_from_master = 0; @@ -2606,12 +2606,12 @@ JobDef(UpdateSim, UNUSED sig, UNUSED id) N_EventList host_events = N_BeginUpdate(scratch.arena, host); /* Read net messages */ - DecodeQueue queue = ZI; + PP_DecodeQueue queue = ZI; { for (N_Event *event = host_events.first; event; event = event->next) { N_ChannelId channel_id = event->channel_id; - Client *client = ClientFromChannelId(store, channel_id); + PP_Client *client = PP_ClientFromChannelId(store, channel_id); switch (event->kind) { case N_EventKind_ChannelOpened: @@ -2621,18 +2621,18 @@ JobDef(UpdateSim, UNUSED sig, UNUSED id) if (is_master) { /* Create remote client */ - client = AcquireClient(store); - SetClientChannelId(client, channel_id); + client = PP_AcquireClient(store); + PP_SetClientChannelId(client, channel_id); } else { /* Create master client */ if (!master_client->valid) { - client = AcquireClient(store); - SetClientChannelId(client, channel_id); + client = PP_AcquireClient(store); + PP_SetClientChannelId(client, channel_id); master_client = client; - master_blended_client = AcquireClient(store); + master_blended_client = PP_AcquireClient(store); } else { @@ -2678,7 +2678,7 @@ JobDef(UpdateSim, UNUSED sig, UNUSED id) tmp_encoded.text = BB_ReadBytesRaw(&decoder_br, tmp_encoded.len); if (!tmp_encoded.text) tmp_encoded.len = 0; - Snapshot *base_ss = SnapshotFromTick(client, base_tick); + PP_Snapshot *base_ss = PP_SnapshotFromTick(client, base_tick); if (base_ss->tick == base_tick) { if (is_master) @@ -2688,7 +2688,7 @@ JobDef(UpdateSim, UNUSED sig, UNUSED id) b32 should_decode = tick > client->highest_received_tick; if (should_decode) { - DecodeQueueNode *node = PushStruct(scratch.arena, DecodeQueueNode); + PP_DecodeQueueNode *node = PushStruct(scratch.arena, PP_DecodeQueueNode); node->client = client; node->tick = tick; node->base_tick = base_tick; @@ -2714,7 +2714,7 @@ JobDef(UpdateSim, UNUSED sig, UNUSED id) b32 should_decode = client == master_client && tick > client->highest_received_tick; if (should_decode) { - DecodeQueueNode *node = queue.first ? queue.first : PushStruct(scratch.arena, DecodeQueueNode); + PP_DecodeQueueNode *node = queue.first ? queue.first : PushStruct(scratch.arena, PP_DecodeQueueNode); node->client = client; node->tick = tick; node->base_tick = base_tick; @@ -2755,29 +2755,29 @@ JobDef(UpdateSim, UNUSED sig, UNUSED id) } /* Decode incoming snapshots */ - for (DecodeQueueNode *n = queue.first; n; n = n->next) + for (PP_DecodeQueueNode *n = queue.first; n; n = n->next) { - Client *client = n->client; + PP_Client *client = n->client; u64 base_tick = n->base_tick; u64 tick = n->tick; - Snapshot *base_ss = SnapshotFromTick(client, base_tick); + PP_Snapshot *base_ss = PP_SnapshotFromTick(client, base_tick); if (base_ss->tick == base_tick) { BB_Buff bb = BB_BuffFromString(n->tmp_encoded); BB_Reader br = BB_ReaderFromBuff(&bb); /* Acquire & decode snapshot */ - Snapshot *ss = AcquireSnapshot(client, base_ss, tick); - DecodeSnapshot(&br, ss); + PP_Snapshot *ss = PP_AcquireSnapshot(client, base_ss, tick); + PP_DecodeSnapshot(&br, ss); /* Assume all incoming ents want to be sync srcs */ for (u64 i = 0; i < ss->num_ents_reserved; ++i) { - Entity *ent = &ss->ents[i]; - if (ent->valid && HasProp(ent, Prop_SyncDst)) + PP_Ent *ent = &ss->ents[i]; + if (ent->valid && PP_HasProp(ent, PP_Prop_SyncDst)) { - DisableProp(ent, Prop_SyncDst); - EnableProp(ent, Prop_SyncSrc); + PP_DisableProp(ent, PP_Prop_SyncDst); + PP_EnableProp(ent, PP_Prop_SyncSrc); } } } @@ -2817,7 +2817,7 @@ JobDef(UpdateSim, UNUSED sig, UNUSED id) u64 oldest_client_ack = 0; for (u64 i = 0; i < store->num_clients_reserved; ++i) { - Client *client = &store->clients[i]; + PP_Client *client = &store->clients[i]; if (client->valid && client != local_client && client != publish_client && client != user_input_client && client != master_client) { client->last_rtt_ns = N_GetChannelLastRttNs(host, client->channel_id); @@ -2828,7 +2828,7 @@ JobDef(UpdateSim, UNUSED sig, UNUSED id) u64 keep_tick = MinU64(client->double_ack, local_client->last_tick); if (keep_tick > 0) { - ReleaseSnapshotsInRange(client, 0, keep_tick - 1); + PP_ReleaseSnapshotsInRange(client, 0, keep_tick - 1); } } if (client->ack < oldest_client_ack || oldest_client_ack == 0) @@ -2849,7 +2849,7 @@ JobDef(UpdateSim, UNUSED sig, UNUSED id) { --keep_tick; } - ReleaseSnapshotsInRange(publish_client, 0, keep_tick); + PP_ReleaseSnapshotsInRange(publish_client, 0, keep_tick); } /* Release old local snapshots */ @@ -2858,12 +2858,12 @@ JobDef(UpdateSim, UNUSED sig, UNUSED id) if (local_client->last_tick > keep_range) { u64 keep_tick = local_client->last_tick - keep_range; - ReleaseSnapshotsInRange(local_client, 0, keep_tick); + PP_ReleaseSnapshotsInRange(local_client, 0, keep_tick); } } /* Release unneeded user input snapshots */ - ReleaseSnapshotsInRange(user_input_client, 0, local_client->first_tick - 1); + PP_ReleaseSnapshotsInRange(user_input_client, 0, local_client->first_tick - 1); @@ -2878,17 +2878,17 @@ JobDef(UpdateSim, UNUSED sig, UNUSED id) /* Step master */ u64 prev_tick = local_client->last_tick; u64 next_tick = prev_tick + 1; - SimStepCtx ctx = ZI; + PP_SimStepCtx ctx = ZI; ctx.is_master = is_master; ctx.sim_dt_ns = step_dt_ns; ctx.accel = &accel; ctx.user_input_client = user_input_client; ctx.master_client = master_client; ctx.publish_client = publish_client; - Snapshot *prev_world = SnapshotFromTick(local_client, prev_tick); - ctx.world = AcquireSnapshot(local_client, prev_world, next_tick); - GenerateuserInputCmds(user_input_client, next_tick); - StepSim(&ctx); + PP_Snapshot *prev_world = PP_SnapshotFromTick(local_client, prev_tick); + ctx.world = PP_AcquireSnapshot(local_client, prev_world, next_tick); + PP_GenerateuserInputCmds(user_input_client, next_tick); + PP_StepSim(&ctx); } else if (master_client->valid) { @@ -2898,7 +2898,7 @@ JobDef(UpdateSim, UNUSED sig, UNUSED id) b32 master_ss_is_blended = 0; - Snapshot *master_ss = NilSnapshot(); + PP_Snapshot *master_ss = PP_NilSnapshot(); { /* How along are we between master sim ticks (0 = start of tick, 1 = end of tick) */ f64 tick_progress = 0; @@ -2909,7 +2909,7 @@ JobDef(UpdateSim, UNUSED sig, UNUSED id) } /* Predict master sim time based on average snapshot publish dt. */ - Snapshot *newest_snapshot = SnapshotFromTick(master_client, master_client->last_tick); + PP_Snapshot *newest_snapshot = PP_SnapshotFromTick(master_client, master_client->last_tick); i64 master_sim_predicted_time_ns = newest_snapshot->sim_time_ns + (newest_snapshot->sim_dt_ns * tick_progress); /* Determine blend time */ @@ -2929,10 +2929,10 @@ JobDef(UpdateSim, UNUSED sig, UNUSED id) /* Get snapshot nearest to master blend time */ /* TODO: Blend */ - Snapshot *left_snapshot = NilSnapshot(); - Snapshot *right_snapshot = newest_snapshot; + PP_Snapshot *left_snapshot = PP_NilSnapshot(); + PP_Snapshot *right_snapshot = newest_snapshot; { - Snapshot *ss = SnapshotFromTick(master_client, master_client->first_tick); + PP_Snapshot *ss = PP_SnapshotFromTick(master_client, master_client->first_tick); while (ss->valid) { u64 next_tick = ss->next_tick; @@ -2945,7 +2945,7 @@ JobDef(UpdateSim, UNUSED sig, UNUSED id) { right_snapshot = ss; } - ss = SnapshotFromTick(master_client, next_tick); + ss = PP_SnapshotFromTick(master_client, next_tick); } } @@ -2968,13 +2968,13 @@ JobDef(UpdateSim, UNUSED sig, UNUSED id) else { master_ss_is_blended = 1; - master_ss = AcquireSnapshotFromLerp(master_blended_client, left_snapshot, right_snapshot, blend); + master_ss = PP_AcquireSnapshotFromLerp(master_blended_client, left_snapshot, right_snapshot, blend); /* Release unneeded blended master snapshots */ if (master_ss->tick > 0) { - ReleaseSnapshotsInRange(master_blended_client, 0, master_ss->tick - 1); - ReleaseSnapshotsInRange(master_blended_client, master_ss->tick + 1, U64Max); + PP_ReleaseSnapshotsInRange(master_blended_client, 0, master_ss->tick - 1); + PP_ReleaseSnapshotsInRange(master_blended_client, master_ss->tick + 1, U64Max); } } } @@ -2988,7 +2988,7 @@ JobDef(UpdateSim, UNUSED sig, UNUSED id) u64 keep_master_tick = MinU64(left_snapshot->tick, master_client->double_ack); if (keep_master_tick > 0) { - ReleaseSnapshotsInRange(master_client, 0, keep_master_tick - 1); + PP_ReleaseSnapshotsInRange(master_client, 0, keep_master_tick - 1); } #if 0 @@ -3012,7 +3012,7 @@ JobDef(UpdateSim, UNUSED sig, UNUSED id) if (master_ss->valid) { - Entity *master_player = FirstWithProp(master_ss, Prop_IsMaster); + PP_Ent *master_player = PP_FirstWithProp(master_ss, PP_Prop_IsMaster); /* Update ent id from master */ { @@ -3078,26 +3078,26 @@ JobDef(UpdateSim, UNUSED sig, UNUSED id) } /* Sync master with local base tick */ - Snapshot *base_ss = SnapshotFromTick(local_client, step_base_tick); + PP_Snapshot *base_ss = PP_SnapshotFromTick(local_client, step_base_tick); if (mispredicted_tick) { if (base_ss->valid) { - SyncSnapshotEntities(base_ss, master_ss, master_player->id, 0); + PP_SyncSnapshotEnts(base_ss, master_ss, master_player->id, 0); } else { - base_ss = AcquireSnapshot(local_client, master_ss, step_base_tick); + base_ss = PP_AcquireSnapshot(local_client, master_ss, step_base_tick); } } /* Release any existing ticks that are about to be simulated */ - ReleaseSnapshotsInRange(local_client, step_base_tick + 1, U64Max); + PP_ReleaseSnapshotsInRange(local_client, step_base_tick + 1, U64Max); /* Step */ - GenerateuserInputCmds(user_input_client, step_end_tick); + PP_GenerateuserInputCmds(user_input_client, step_end_tick); { - SimStepCtx ctx = ZI; + PP_SimStepCtx ctx = ZI; ctx.is_master = is_master; ctx.sim_dt_ns = step_dt_ns; ctx.accel = &accel; @@ -3106,15 +3106,15 @@ JobDef(UpdateSim, UNUSED sig, UNUSED id) ctx.publish_client = publish_client; u64 step_tick = step_base_tick + 1; - Snapshot *prev_ss = base_ss; + PP_Snapshot *prev_ss = base_ss; while (step_tick <= step_end_tick) { - ctx.world = AcquireSnapshot(local_client, prev_ss, step_tick); + ctx.world = PP_AcquireSnapshot(local_client, prev_ss, step_tick); if (!mispredicted_tick && step_tick == step_end_tick) { - SyncSnapshotEntities(ctx.world, master_ss, master_player->id, SyncFlag_NoSyncPredictables); + PP_SyncSnapshotEnts(ctx.world, master_ss, master_player->id, PP_SyncFlag_NoSyncPredictables); } - StepSim(&ctx); + PP_StepSim(&ctx); prev_ss = ctx.world; ++step_tick; } @@ -3125,7 +3125,7 @@ JobDef(UpdateSim, UNUSED sig, UNUSED id) /* Publish snapshot to remote clients */ for (u64 i = 0; i < store->num_clients_reserved; ++i) { - Client *client = &store->clients[i]; + PP_Client *client = &store->clients[i]; if (client->valid && client != user_input_client && client != local_client && client != publish_client) { BB_Writer msg_bw = BB_WriterFromBuff(&msg_writer_bb); @@ -3133,17 +3133,17 @@ JobDef(UpdateSim, UNUSED sig, UNUSED id) BB_WriteUV(&msg_bw, client->highest_received_tick); /* ack */ BB_WriteUV(&msg_bw, client->ack); /* double ack */ - Snapshot *base_ss = SnapshotFromTick(publish_client, client->ack); - Snapshot *publish_ss; + PP_Snapshot *base_ss = PP_SnapshotFromTick(publish_client, client->ack); + PP_Snapshot *publish_ss; if (client == master_client) { /* If sending to master, start sending all snapshots since last ack */ - publish_ss = SnapshotFromClosestTickGte(publish_client, base_ss->tick + 1); + publish_ss = PP_SnapshotFromClosestTickGte(publish_client, base_ss->tick + 1); } else { /* If sending to slave, only send latest snapshot */ - publish_ss = SnapshotFromTick(publish_client, publish_client->last_tick); + publish_ss = PP_SnapshotFromTick(publish_client, publish_client->last_tick); } while (publish_ss->valid) @@ -3153,13 +3153,13 @@ JobDef(UpdateSim, UNUSED sig, UNUSED id) { BB_WriteUV(&snapshot_bw, base_ss->tick); BB_WriteUV(&snapshot_bw, publish_ss->tick); - EncodeSnapshot(&snapshot_bw, client, base_ss, publish_ss); + PP_EncodeSnapshot(&snapshot_bw, client, base_ss, publish_ss); tmp_snapshot_encoded.len = BB_GetNumBytesWritten(&snapshot_bw); tmp_snapshot_encoded.text = BB_GetWrittenRaw(&snapshot_bw); } BB_WriteUV(&msg_bw, tmp_snapshot_encoded.len); BB_WriteBytes(&msg_bw, tmp_snapshot_encoded); - publish_ss = SnapshotFromTick(publish_client, publish_ss->tick + 1); + publish_ss = PP_SnapshotFromTick(publish_client, publish_ss->tick + 1); } BB_WriteUV(&msg_bw, 0); @@ -3172,12 +3172,12 @@ JobDef(UpdateSim, UNUSED sig, UNUSED id) /* Copy local snapshot to user client */ { - Snapshot *local_ss = SnapshotFromTick(local_client, local_client->last_tick); + PP_Snapshot *local_ss = PP_SnapshotFromTick(local_client, local_client->last_tick); if (local_ss->valid) { /* TODO: Double buffer */ Lock lock = LockE(&g->local_to_user_client_mutex); - AcquireSnapshot(g->local_to_user_client, local_ss, local_ss->tick); + PP_AcquireSnapshot(g->local_to_user_client, local_ss, local_ss->tick); i64 publish_ns = TimeNs(); if (last_publish_to_user_ns == 0) { @@ -3186,7 +3186,7 @@ JobDef(UpdateSim, UNUSED sig, UNUSED id) g->local_to_user_client_publish_dt_ns = publish_ns - last_publish_to_user_ns; g->local_to_user_client_publish_time_ns = publish_ns; last_publish_to_user_ns = publish_ns; - ReleaseSnapshotsInRange(g->local_to_user_client, 0, local_ss->tick - 1); + PP_ReleaseSnapshotsInRange(g->local_to_user_client, 0, local_ss->tick - 1); Unlock(&lock); } } @@ -3202,8 +3202,8 @@ JobDef(UpdateSim, UNUSED sig, UNUSED id) } #if 0 - ReleaseClientStore(store); - ReleaseSimAccel(&accel); + PP_ReleaseClientStore(store); + PP_ReleaseAccel(&accel); BB_ReleaseBuff(&snapshot_writer_bb); BB_ReleaseBuff(&msg_writer_bb); N_ReleaseHost(host); diff --git a/src/pp/pp.h b/src/pp/pp.h index 357770d5..1ced15e7 100644 --- a/src/pp/pp.h +++ b/src/pp/pp.h @@ -2,103 +2,103 @@ //~ Binds //- Bind kinds -Enum(BindKind) +Enum(PP_BindKind) { - BindKind_None, + PP_BindKind_None, - BindKind_MoveUp, - BindKind_MoveDown, - BindKind_MoveLeft, - BindKind_MoveRight, - BindKind_Walk, - BindKind_Fire, - BindKind_AltFire, + PP_BindKind_MoveUp, + PP_BindKind_MoveDown, + PP_BindKind_MoveLeft, + PP_BindKind_MoveRight, + PP_BindKind_Walk, + PP_BindKind_Fire, + PP_BindKind_AltFire, - BindKind_TestTile, - BindKind_DebugClear, - BindKind_DebugSpawn1, - BindKind_DebugSpawn2, - BindKind_DebugSpawn3, - BindKind_DebugSpawn4, - BindKind_DebugWalls, - BindKind_DebugFollow, - BindKind_DebugDraw, - BindKind_DebugConsole, - BindKind_DebugCamera, - BindKind_DebugPause, - BindKind_DebugStep, - BindKind_DebugDrag, - BindKind_DebugDelete, - BindKind_DebugTeleport, - BindKind_DebugExplode, - BindKind_DebugToggleTopmost, - BindKind_FullscreenMod, - BindKind_Fullscreen, - BindKind_ZoomIn, - BindKind_ZoomOut, - BindKind_Pan, + PP_BindKind_TestTile, + PP_BindKind_DebugClear, + PP_BindKind_DebugSpawn1, + PP_BindKind_DebugSpawn2, + PP_BindKind_DebugSpawn3, + PP_BindKind_DebugSpawn4, + PP_BindKind_DebugWalls, + PP_BindKind_DebugFollow, + PP_BindKind_DebugDraw, + PP_BindKind_DebugConsole, + PP_BindKind_DebugCamera, + PP_BindKind_DebugPause, + PP_BindKind_DebugStep, + PP_BindKind_DebugDrag, + PP_BindKind_DebugDelete, + PP_BindKind_DebugTeleport, + PP_BindKind_DebugExplode, + PP_BindKind_DebugToggleTopmost, + PP_BindKind_FullscreenMod, + PP_BindKind_Fullscreen, + PP_BindKind_ZoomIn, + PP_BindKind_ZoomOut, + PP_BindKind_Pan, #if RtcIsEnabled /* Debug */ - BindKind_ResetDebugSteps, - BindKind_IncrementDebugSteps, - BindKind_DecrementDebugSteps, + PP_BindKind_ResetDebugSteps, + PP_BindKind_IncrementDebugSteps, + PP_BindKind_DecrementDebugSteps, #endif - BindKind_Count + PP_BindKind_Count }; //- Test bindings /* TODO: Remove this */ -Global Readonly BindKind g_binds[Btn_Count] = { - [Btn_W] = BindKind_MoveUp, - [Btn_S] = BindKind_MoveDown, - [Btn_A] = BindKind_MoveLeft, - [Btn_D] = BindKind_MoveRight, - [Btn_M1] = BindKind_Fire, - [Btn_M2] = BindKind_AltFire, +Global Readonly PP_BindKind g_binds[Btn_Count] = { + [Btn_W] = PP_BindKind_MoveUp, + [Btn_S] = PP_BindKind_MoveDown, + [Btn_A] = PP_BindKind_MoveLeft, + [Btn_D] = PP_BindKind_MoveRight, + [Btn_M1] = PP_BindKind_Fire, + [Btn_M2] = PP_BindKind_AltFire, #if 0 - [Btn_Alt] = BindKind_Walk, + [Btn_Alt] = PP_BindKind_Walk, #endif /* Testing */ - [Btn_Z] = BindKind_TestTile, - [Btn_M5] = BindKind_DebugDrag, - [Btn_M4] = BindKind_DebugDelete, - [Btn_F] = BindKind_DebugExplode, - [Btn_T] = BindKind_DebugTeleport, - [Btn_C] = BindKind_DebugClear, - [Btn_1] = BindKind_DebugSpawn1, - [Btn_2] = BindKind_DebugSpawn2, - [Btn_3] = BindKind_DebugSpawn3, - [Btn_4] = BindKind_DebugSpawn4, - [Btn_G] = BindKind_DebugWalls, - [Btn_N] = BindKind_DebugStep, - [Btn_Q] = BindKind_DebugFollow, - [Btn_F1] = BindKind_DebugPause, - [Btn_F2] = BindKind_DebugCamera, - [Btn_F3] = BindKind_DebugDraw, - [Btn_F4] = BindKind_DebugToggleTopmost, - [Btn_GraveAccent] = BindKind_DebugConsole, - [Btn_Alt] = BindKind_FullscreenMod, - [Btn_Enter] = BindKind_Fullscreen, - [Btn_MWheelUp] = BindKind_ZoomIn, - [Btn_MWheelDown] = BindKind_ZoomOut, - [Btn_M3] = BindKind_Pan, + [Btn_Z] = PP_BindKind_TestTile, + [Btn_M5] = PP_BindKind_DebugDrag, + [Btn_M4] = PP_BindKind_DebugDelete, + [Btn_F] = PP_BindKind_DebugExplode, + [Btn_T] = PP_BindKind_DebugTeleport, + [Btn_C] = PP_BindKind_DebugClear, + [Btn_1] = PP_BindKind_DebugSpawn1, + [Btn_2] = PP_BindKind_DebugSpawn2, + [Btn_3] = PP_BindKind_DebugSpawn3, + [Btn_4] = PP_BindKind_DebugSpawn4, + [Btn_G] = PP_BindKind_DebugWalls, + [Btn_N] = PP_BindKind_DebugStep, + [Btn_Q] = PP_BindKind_DebugFollow, + [Btn_F1] = PP_BindKind_DebugPause, + [Btn_F2] = PP_BindKind_DebugCamera, + [Btn_F3] = PP_BindKind_DebugDraw, + [Btn_F4] = PP_BindKind_DebugToggleTopmost, + [Btn_GraveAccent] = PP_BindKind_DebugConsole, + [Btn_Alt] = PP_BindKind_FullscreenMod, + [Btn_Enter] = PP_BindKind_Fullscreen, + [Btn_MWheelUp] = PP_BindKind_ZoomIn, + [Btn_MWheelDown] = PP_BindKind_ZoomOut, + [Btn_M3] = PP_BindKind_Pan, #if RtcIsEnabled - [Btn_ForwardSlash] = BindKind_ResetDebugSteps, - [Btn_Comma] = BindKind_DecrementDebugSteps, - [Btn_Period] = BindKind_IncrementDebugSteps + [Btn_ForwardSlash] = PP_BindKind_ResetDebugSteps, + [Btn_Comma] = PP_BindKind_DecrementDebugSteps, + [Btn_Period] = PP_BindKind_IncrementDebugSteps #endif }; //////////////////////////////////////////////////////////// //~ Stats -Struct(SecondsStat) +Struct(PP_SecondsStat) { u64 last_second_start; u64 last_second_end; @@ -108,39 +108,39 @@ Struct(SecondsStat) //////////////////////////////////////////////////////////// //~ Console log -Struct(ConsoleLog) +Struct(PP_ConsoleLog) { String msg; i32 level; i32 color_index; P_DateTime datetime; i64 time_ns; - ConsoleLog *prev; - ConsoleLog *next; + PP_ConsoleLog *prev; + PP_ConsoleLog *next; }; //////////////////////////////////////////////////////////// //~ Sim decode queue -Struct(DecodeQueueNode) +Struct(PP_DecodeQueueNode) { - Client *client; + PP_Client *client; u64 tick; u64 base_tick; String tmp_encoded; - DecodeQueueNode *next; + PP_DecodeQueueNode *next; }; -Struct(DecodeQueue) +Struct(PP_DecodeQueue) { - DecodeQueueNode *first; - DecodeQueueNode *last; + PP_DecodeQueueNode *first; + PP_DecodeQueueNode *last; }; //////////////////////////////////////////////////////////// //~ State types -Struct(BindState) +Struct(PP_BindState) { b32 is_held; /* Is this bind held down this frame */ u32 num_presses; /* How many times was this bind's pressed since last frame */ @@ -149,7 +149,7 @@ Struct(BindState) u32 num_releases; /* How many times was this bind released since last frame */ }; -Struct(SharedUserState) +Struct(PP_SharedUserState) { Atomic32 shutdown; @@ -159,18 +159,18 @@ Struct(SharedUserState) Arena *arena; String connect_address_str; - ClientStore *user_client_store; - Client *user_unblended_client; /* Contains snapshots received from local sim */ - Client *user_blended_client; /* Contains single snapshot from result of blending local sim snapshots */ - Snapshot *ss_blended; /* Points to blended snapshot contained in blended client */ + PP_ClientStore *user_client_store; + PP_Client *user_unblended_client; /* Contains snapshots received from local sim */ + PP_Client *user_blended_client; /* Contains single snapshot from result of blending local sim snapshots */ + PP_Snapshot *ss_blended; /* Points to blended snapshot contained in blended client */ u64 user_tick; u64 window_os_gen; //- Usage stats i64 last_second_reset_ns; - SecondsStat net_bytes_read; - SecondsStat net_bytes_sent; + PP_SecondsStat net_bytes_read; + PP_SecondsStat net_bytes_sent; //- Renderer gbuffers GPU_Resource *albedo; @@ -195,13 +195,13 @@ Struct(SharedUserState) i64 gpu_submit_fence_target; //- Bind state - BindState bind_states[BindKind_Count]; + PP_BindState bind_states[PP_BindKind_Count]; //- Debug console Mutex console_logs_mutex; Arena *console_logs_arena; - ConsoleLog *first_console_log; - ConsoleLog *last_console_log; + PP_ConsoleLog *first_console_log; + PP_ConsoleLog *last_console_log; i32 console_log_color_indices[P_LogLevel_Count]; //- Window -> user @@ -210,8 +210,8 @@ Struct(SharedUserState) //- User -> sim Mutex user_sim_cmd_mutex; - ControlData user_sim_cmd_control; - EntityId user_hovered_ent; + PP_ControlData user_sim_cmd_control; + PP_EntKey user_hovered_ent; u64 last_user_sim_cmd_gen; u64 user_sim_cmd_gen; @@ -220,8 +220,8 @@ Struct(SharedUserState) //- Sim -> user Mutex local_to_user_client_mutex; - ClientStore *local_to_user_client_store; - Client *local_to_user_client; + PP_ClientStore *local_to_user_client_store; + PP_Client *local_to_user_client; i64 local_to_user_client_publish_dt_ns; i64 local_to_user_client_publish_time_ns; @@ -251,7 +251,7 @@ Struct(SharedUserState) //- Debug camera - EntityId debug_following; + PP_EntKey debug_following; b32 debug_camera; b32 debug_camera_panning; Vec2 debug_camera_pan_start; @@ -282,66 +282,66 @@ Struct(SharedUserState) //- Persist end ////////////////////////////// -} extern shared_user_state; +} extern PP_shared_user_state; //////////////////////////////////////////////////////////// //~ Swap types -Struct(SwappedUserState) +Struct(PP_SwappedUserState) { - SharedUserState s; + PP_SharedUserState s; }; //////////////////////////////////////////////////////////// //~ Startup -void StartupUser(void); +void PP_StartupUser(void); //////////////////////////////////////////////////////////// //~ Shutdown -ExitFuncDef(ShutdownUser); +ExitFuncDef(PP_ShutdownUser); //////////////////////////////////////////////////////////// //~ Ui helpers -void PushGameUiStyle(void); -void DrawDebugXform(Xform xf, u32 color_x, u32 color_y); -void DrawDebugMovement(Entity *ent); -String DebugStringFromEntity(Arena *arena, Entity *ent); +void PP_PushGameUiStyle(void); +void PP_DrawDebugXform(Xform xf, u32 color_x, u32 color_y); +void PP_DrawDebugMovement(PP_Ent *ent); +String PP_DebugStringFromEnt(Arena *arena, PP_Ent *ent); //////////////////////////////////////////////////////////// //~ Console draw operations -P_LogEventCallbackFuncDef(ConsoleLogCallback, log); -void DrawDebugConsole(b32 minimized); +P_LogEventCallbackFuncDef(PP_ConsoleLogCallback, log); +void PP_DrawDebugConsole(b32 minimized); //////////////////////////////////////////////////////////// //~ Gpu buffer helpers -GPU_Resource *AcquireGbuffer(GPU_Format format, Vec2I32 size); +GPU_Resource *PP_AcquireGbuffer(GPU_Format format, Vec2I32 size); //////////////////////////////////////////////////////////// -//~ Entity sorting +//~ Ent sorting -MergesortCompareFuncDef(EntitySortCmp, arg_a, arg_b, _); +MergesortCompareFuncDef(PP_EntSortCmp, arg_a, arg_b, _); //////////////////////////////////////////////////////////// //~ User update -void UpdateUser(void); +void PP_UpdateUser(void); //////////////////////////////////////////////////////////// //~ User update job -JobDecl(UpdateUserOrSleep, EmptySig); +JobDecl(PP_UpdateUserOrSleep, EmptySig); //////////////////////////////////////////////////////////// //~ User input cmds -void GenerateuserInputCmds(Client *user_input_client, u64 tick); +void PP_GenerateuserInputCmds(PP_Client *user_input_client, u64 tick); //////////////////////////////////////////////////////////// //~ Sim update job -JobDecl(UpdateSim, EmptySig); +JobDecl(PP_UpdateSim, EmptySig); diff --git a/src/pp/pp.lay b/src/pp/pp.lay index 15b3e5f3..145a20e8 100644 --- a/src/pp/pp.lay +++ b/src/pp/pp.lay @@ -33,14 +33,14 @@ @IncludeGpu pp_draw.gpu //- Embeds -@EmbedDir GameResources pp_res +@EmbedDir PP_Resources pp_res //- Shaders -@VertexShader MaterialVS -@PixelShader MaterialPS -@ComputeShader FloodCS -@ComputeShader ShadeCS +@VertexShader PP_MaterialVS +@PixelShader PP_MaterialPS +@ComputeShader PP_FloodCS +@ComputeShader PP_ShadeCS //- Startup -@Startup StartupSim -@Startup StartupUser +@Startup PP_StartupSim +@Startup PP_StartupUser diff --git a/src/pp/pp_draw.gpu b/src/pp/pp_draw.gpu index e6b50a5c..3dd2b9d6 100644 --- a/src/pp/pp_draw.gpu +++ b/src/pp/pp_draw.gpu @@ -1,11 +1,11 @@ -ConstantBuffer mat_sig : register (b0); -ConstantBuffer flood_sig : register (b0); -ConstantBuffer shade_sig : register (b0); +ConstantBuffer PP_mat_sig : register (b0); +ConstantBuffer PP_flood_sig : register (b0); +ConstantBuffer PP_shade_sig : register (b0); //////////////////////////////////////////////////////////// //~ Material -Struct(MaterialPS_Input) +Struct(PP_MaterialPS_Input) { Semantic(Vec4, sv_position); Semantic(nointerpolation Texture2DRid, tex); @@ -15,7 +15,7 @@ Struct(MaterialPS_Input) Semantic(Vec4, emittance_lin); }; -Struct(MaterialPS_Output) +Struct(PP_MaterialPS_Output) { Semantic(Vec4, sv_target0); /* Albedo */ Semantic(Vec4, sv_target1); /* Emittance */ @@ -23,17 +23,17 @@ Struct(MaterialPS_Output) //- Vertex shader -MaterialPS_Input VSDef(MaterialVS, Semantic(u32, sv_instanceid), Semantic(u32, sv_vertexid)) +PP_MaterialPS_Input VSDef(PP_MaterialVS, Semantic(u32, sv_instanceid), Semantic(u32, sv_vertexid)) { - ConstantBuffer sig = mat_sig; - StructuredBuffer instances = UniformResourceFromRid(sig.instances); - MaterialInstance instance = instances[sv_instanceid]; + ConstantBuffer sig = PP_mat_sig; + StructuredBuffer instances = UniformResourceFromRid(sig.instances); + PP_MaterialInstance instance = instances[sv_instanceid]; Vec2 mat_uv = RectUvFromVertexId(sv_vertexid); Vec2 mat_uv_centered = mat_uv - 0.5f; Vec2 world_pos = mul(instance.xf, Vec3(mat_uv_centered, 1)).xy; - MaterialPS_Input result; + PP_MaterialPS_Input result; result.sv_position = mul(sig.projection, Vec4(world_pos, 0, 1)); result.tex = instance.tex; result.grid_id = instance.grid_id; @@ -45,11 +45,11 @@ MaterialPS_Input VSDef(MaterialVS, Semantic(u32, sv_instanceid), Semantic(u32, s //- Pixel shader -MaterialPS_Output PSDef(MaterialPS, MaterialPS_Input input) +PP_MaterialPS_Output PSDef(PP_MaterialPS, PP_MaterialPS_Input input) { - ConstantBuffer sig = mat_sig; + ConstantBuffer sig = PP_mat_sig; - MaterialPS_Output result; + PP_MaterialPS_Output result; Vec4 albedo = input.tint_lin; /* Texture */ @@ -63,9 +63,9 @@ MaterialPS_Output PSDef(MaterialPS, MaterialPS_Input input) /* Grid */ if (input.grid_id < 0xFFFFFFFF) { - // StructuredBuffer grids = UniformResourceFromRid(sig.grids); - StructuredBuffer grids = ResourceDescriptorHeap[sig.grids]; - MaterialGrid grid = grids[input.grid_id]; + // StructuredBuffer grids = UniformResourceFromRid(sig.grids); + StructuredBuffer grids = ResourceDescriptorHeap[sig.grids]; + PP_MaterialGrid grid = grids[input.grid_id]; Vec2 grid_pos = input.sv_position.xy + grid.offset; f32 half_thickness = grid.line_thickness / 2; f32 spacing = grid.line_spacing; @@ -119,9 +119,9 @@ MaterialPS_Output PSDef(MaterialPS, MaterialPS_Input input) //- Compute shader [numthreads(8, 8, 1)] -void CSDef(FloodCS, Semantic(Vec3U32, sv_dispatchthreadid)) +void CSDef(PP_FloodCS, Semantic(Vec3U32, sv_dispatchthreadid)) { - ConstantBuffer sig = flood_sig; + ConstantBuffer sig = PP_flood_sig; Vec2U32 id = sv_dispatchthreadid.xy; Vec2U32 tex_size = Vec2U32(sig.tex_width, sig.tex_height); @@ -181,15 +181,15 @@ void CSDef(FloodCS, Semantic(Vec3U32, sv_dispatchthreadid)) //////////////////////////////////////////////////////////// //~ Shade -#define LightSamples 16 -#define LightMarches 16 -#define LightEdgeFalloff 100 +#define PP_LightSamples 16 +#define PP_LightMarches 16 +#define PP_LightEdgeFalloff 100 //- Lighting -f32 RandAngleFromPos(Vec2U32 pos, u32 ray_index) +f32 PP_RandAngleFromPos(Vec2U32 pos, u32 ray_index) { - ConstantBuffer sig = shade_sig; + ConstantBuffer sig = PP_shade_sig; Texture3D noise_tex = UniformResourceFromRid(sig.noise); Vec3I32 noise_coord = Vec3U32(1, 1, 1); @@ -201,16 +201,16 @@ f32 RandAngleFromPos(Vec2U32 pos, u32 ray_index) return ((f32)noise / (f32)0xFFFF) * Tau; } -Vec3 LightFromDir(Vec2U32 ray_start, Vec2 ray_dir) +Vec3 PP_LightFromDir(Vec2U32 ray_start, Vec2 ray_dir) { - ConstantBuffer sig = shade_sig; + ConstantBuffer sig = PP_shade_sig; Texture2D flood_tex = UniformResourceFromRid(sig.emittance_flood); Texture2D emittance_tex = UniformResourceFromRid(sig.emittance); Vec3 result = Vec3(0, 0, 0); Vec2 at_f32 = ray_start; Vec2U32 at_u32 = ray_start; - for (u32 i = 0; i < LightMarches; ++i) + for (u32 i = 0; i < PP_LightMarches; ++i) { Vec2U32 flood = flood_tex[at_u32]; Vec2 dist_vec = at_f32 - (Vec2)flood; @@ -220,7 +220,7 @@ Vec3 LightFromDir(Vec2U32 ray_start, Vec2 ray_dir) /* Scale light by distance from edge so that offscreen-lights fade in/out rather than popping in */ f32 dist_x = min(abs(sig.tex_width - at_f32.x), at_f32.x); f32 dist_y = min(abs(sig.tex_height - at_f32.y), at_f32.y); - f32 dist_scale = min(min(dist_x, dist_y) / LightEdgeFalloff, 1); + f32 dist_scale = min(min(dist_x, dist_y) / PP_LightEdgeFalloff, 1); result = emittance_tex[flood].rgb * dist_scale; break; } @@ -238,17 +238,17 @@ Vec3 LightFromDir(Vec2U32 ray_start, Vec2 ray_dir) return result; } -Vec3 AccumulatedLightFromPos(Vec2U32 pos) +Vec3 PP_AccumulatedLightFromPos(Vec2U32 pos) { Vec3 result = 0; - for (u32 i = 0; i < LightSamples; ++i) + for (u32 i = 0; i < PP_LightSamples; ++i) { - f32 angle = RandAngleFromPos(pos, i); + f32 angle = PP_RandAngleFromPos(pos, i); Vec2 dir = Vec2(cos(angle), sin(angle)); - Vec3 light_in_dir = LightFromDir(pos, dir); + Vec3 light_in_dir = PP_LightFromDir(pos, dir); result += light_in_dir; } - result /= LightSamples; + result /= PP_LightSamples; return result; } @@ -256,7 +256,7 @@ Vec3 AccumulatedLightFromPos(Vec2U32 pos) /* ACES approximation by Krzysztof Narkowicz * https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/ */ -Vec3 ToneMap(Vec3 v) +Vec3 PP_ToneMap(Vec3 v) { return saturate((v * (2.51f * v + 0.03f)) / (v * (2.43f * v + 0.59f) + 0.14f)); } @@ -264,9 +264,9 @@ Vec3 ToneMap(Vec3 v) //- Compute shader [numthreads(8, 8, 1)] -void CSDef(ShadeCS, Semantic(Vec3U32, sv_dispatchthreadid)) +void CSDef(PP_ShadeCS, Semantic(Vec3U32, sv_dispatchthreadid)) { - ConstantBuffer sig = shade_sig; + ConstantBuffer sig = PP_shade_sig; Vec2U32 id = sv_dispatchthreadid.xy; if (id.x < sig.tex_width && id.y < sig.tex_height) { @@ -279,17 +279,17 @@ void CSDef(ShadeCS, Semantic(Vec3U32, sv_dispatchthreadid)) color *= albedo_tex[id]; /* Apply lighting */ - if (!(sig.flags & ShadeFlag_DisableEffects)) + if (!(sig.flags & PP_ShadeFlag_DisableEffects)) { - color.rgb *= AccumulatedLightFromPos(id); + color.rgb *= PP_AccumulatedLightFromPos(id); } /* Apply tone mapping */ - if (sig.flags & ShadeFlag_ToneMap) + if (sig.flags & PP_ShadeFlag_ToneMap) { /* TODO: Dynamic exposure based on average scene luminance */ color.rgb *= sig.exposure; - color.rgb = ToneMap(color.rgb); + color.rgb = PP_ToneMap(color.rgb); } /* Apply temporal accumulation */ diff --git a/src/pp/pp_draw.h b/src/pp/pp_draw.h index 7b536589..c8d9683b 100644 --- a/src/pp/pp_draw.h +++ b/src/pp/pp_draw.h @@ -1,7 +1,7 @@ //////////////////////////////////////////////////////////// //~ Material types -Struct(MaterialSig) +Struct(PP_MaterialSig) { /* ----------------------------------------------------- */ Mat4x4 projection; /* 16 consts */ @@ -12,9 +12,9 @@ Struct(MaterialSig) u32 _pad0; /* 01 consts (padding) */ /* ----------------------------------------------------- */ }; -AssertRootConst(MaterialSig, 20); +AssertRootConst(PP_MaterialSig, 20); -Struct(MaterialInstance) +Struct(PP_MaterialInstance) { Texture2DRid tex; u32 grid_id; @@ -25,15 +25,15 @@ Struct(MaterialInstance) u32 is_light; Vec3 light_emittance_srgb; }; -#define DefaultMaterialInstance (MaterialInstance) { \ - .tex = { U32Max }, \ - .grid_id = U32Max, \ - .xf = XformIdentity, \ - .tex_uv1 = VEC2(1, 1), \ - .tint_srgb = Color_White, \ +#define PP_DefaultMaterialInstance (PP_MaterialInstance) { \ + .tex = { U32Max }, \ + .grid_id = U32Max, \ + .xf = XformIdentity, \ + .tex_uv1 = VEC2(1, 1), \ + .tint_srgb = Color_White, \ } -Struct(MaterialGrid) +Struct(PP_MaterialGrid) { f32 line_thickness; f32 line_spacing; @@ -44,17 +44,17 @@ Struct(MaterialGrid) u32 x_srgb; u32 y_srgb; }; -#define DefaultMaterialGrid (MaterialGrid) { \ - .line_thickness = 1, \ - .line_spacing = 1, \ - .bg0_srgb = Color_Black, \ - .bg0_srgb = Color_White \ +#define PP_DefaultMaterialGrid (PP_MaterialGrid) { \ + .line_thickness = 1, \ + .line_spacing = 1, \ + .bg0_srgb = Color_Black, \ + .bg0_srgb = Color_White \ } //////////////////////////////////////////////////////////// //~ Flood types -Struct(FloodSig) +Struct(PP_FloodSig) { /* ----------------------------------------------------- */ i32 step_len; /* 01 consts */ @@ -68,16 +68,16 @@ Struct(FloodSig) u32 _pad1; /* 01 consts (padding) */ /* ----------------------------------------------------- */ }; -AssertRootConst(FloodSig, 8); +AssertRootConst(PP_FloodSig, 8); //////////////////////////////////////////////////////////// //~ Shade types -#define ShadeFlag_None (0 << 0) -#define ShadeFlag_DisableEffects (1 << 0) -#define ShadeFlag_ToneMap (1 << 1) +#define PP_ShadeFlag_None (0 << 0) +#define PP_ShadeFlag_DisableEffects (1 << 0) +#define PP_ShadeFlag_ToneMap (1 << 1) -Struct(ShadeSig) +Struct(PP_ShadeSig) { /* ----------------------------------------------------- */ Vec4U32 frame_seed; /* 04 consts */ @@ -102,4 +102,4 @@ Struct(ShadeSig) u32 noise_tex_depth; /* 01 consts */ /* ----------------------------------------------------- */ }; -AssertRootConst(ShadeSig, 20); +AssertRootConst(PP_ShadeSig, 20); diff --git a/src/pp/pp_ent.c b/src/pp/pp_ent.c index d5ed3e3e..5e9e59c8 100644 --- a/src/pp/pp_ent.c +++ b/src/pp/pp_ent.c @@ -1,12 +1,12 @@ //////////////////////////////////////////////////////////// //~ Acquire -Entity *AcquireRaw(Snapshot *ss, Entity *parent, EntityId id) +PP_Ent *PP_AcquireRawEnt(PP_Snapshot *ss, PP_Ent *parent, PP_EntKey id) { Assert(parent->valid); Assert(ss->valid); Assert(ss == parent->ss); - Entity *ent; + PP_Ent *ent; if (ss->first_free_ent > 0 && ss->first_free_ent < ss->num_ents_reserved) { /* Reuse from free list */ @@ -16,64 +16,64 @@ Entity *AcquireRaw(Snapshot *ss, Entity *parent, EntityId id) else { /* Make new */ - ent = PushStructNoZero(ss->ents_arena, Entity); + ent = PushStructNoZero(ss->ents_arena, PP_Ent); ++ss->num_ents_reserved; } - *ent = *NilEntity(); + *ent = *PP_NilEnt(); ent->ss = ss; ent->valid = 1; ent->owner = ss->client->player_id; ent->_is_xform_dirty = 1; ++ss->num_ents_allocated; - SetEntityId(ent, id); - Link(ent, parent); + PP_SetEntKey(ent, id); + PP_Link(ent, parent); return ent; } /* Acquires a new entity that will not sync */ -Entity *AcquireLocal(Entity *parent) +PP_Ent *PP_AcquireLocalEnt(PP_Ent *parent) { - Snapshot *ss = parent->ss; - Entity *e = AcquireRaw(ss, parent, RandomId()); + PP_Snapshot *ss = parent->ss; + PP_Ent *e = PP_AcquireRawEnt(ss, parent, PP_RandomKey()); e->owner = ss->local_player; return e; } -Entity *AcquireLocalWithId(Entity *parent, EntityId id) +PP_Ent *PP_AcquireLocalEntWithKey(PP_Ent *parent, PP_EntKey id) { - Snapshot *ss = parent->ss; - Entity *e = AcquireRaw(ss, parent, id); + PP_Snapshot *ss = parent->ss; + PP_Ent *e = PP_AcquireRawEnt(ss, parent, id); e->owner = ss->local_player; return e; } /* Acquires a new entity to be synced to clients */ -Entity *AcquireSyncSrc(Entity *parent) +PP_Ent *PP_AcquireSyncSrcEnt(PP_Ent *parent) { - Snapshot *ss = parent->ss; - Entity *e = AcquireRaw(ss, parent, RandomId()); - EnableProp(e, Prop_SyncSrc); + PP_Snapshot *ss = parent->ss; + PP_Ent *e = PP_AcquireRawEnt(ss, parent, PP_RandomKey()); + PP_EnableProp(e, PP_Prop_SyncSrc); e->owner = ss->local_player; return e; } -Entity *AcquireSyncSrcWithId(Entity *parent, EntityId id) +PP_Ent *PP_AcquireSyncSrcEntWithKey(PP_Ent *parent, PP_EntKey id) { - Snapshot *ss = parent->ss; - Entity *e = AcquireRaw(ss, parent, id); - EnableProp(e, Prop_SyncSrc); + PP_Snapshot *ss = parent->ss; + PP_Ent *e = PP_AcquireRawEnt(ss, parent, id); + PP_EnableProp(e, PP_Prop_SyncSrc); e->owner = ss->local_player; return e; } /* Acquires a new entity that will sync with incoming net src ents containing id, and coming from the specified owner */ -Entity *AcquireSyncDst(Entity *parent, EntityId ent_id, EntityId owner_id) +PP_Ent *PP_AcquireSyncDstEnt(PP_Ent *parent, PP_EntKey ent_id, PP_EntKey owner_id) { - Snapshot *ss = parent->ss; - Entity *e = AcquireRaw(ss, parent, ent_id); - EnableProp(e, Prop_SyncDst); + PP_Snapshot *ss = parent->ss; + PP_Ent *e = PP_AcquireRawEnt(ss, parent, ent_id); + PP_EnableProp(e, PP_Prop_SyncDst); e->owner = owner_id; return e; } @@ -81,51 +81,51 @@ Entity *AcquireSyncDst(Entity *parent, EntityId ent_id, EntityId owner_id) //////////////////////////////////////////////////////////// //~ Release -void ReleaseRaw(Entity *ent) +void PP_ReleaseRawEnt(PP_Ent *ent) { - Snapshot *ss = ent->ss; + PP_Snapshot *ss = ent->ss; /* Release children */ - Entity *child = EntityFromId(ss, ent->first); + PP_Ent *child = PP_EntFromKey(ss, ent->first); while (child->valid) { - Entity *next = EntityFromId(ss, child->next); - ReleaseRaw(child); + PP_Ent *next = PP_EntFromKey(ss, child->next); + PP_ReleaseRawEnt(child); child = next; } /* Release uid */ - SetEntityId(ent, NilEntityId); + PP_SetEntKey(ent, PP_NilEntKey); /* Release */ ent->valid = 0; ent->next_free = ss->first_free_ent; - ss->first_free_ent = IndexFromEntity(ss, ent); + ss->first_free_ent = PP_IndexFromEnt(ss, ent); --ss->num_ents_allocated; } -void Release(Entity *ent) +void PP_Release(PP_Ent *ent) { - Snapshot *ss = ent->ss; - Entity *parent = EntityFromId(ss, ent->parent); + PP_Snapshot *ss = ent->ss; + PP_Ent *parent = PP_EntFromKey(ss, ent->parent); if (parent->valid) { - Unlink(ent); + PP_Unlink(ent); } - ReleaseRaw(ent); + PP_ReleaseRawEnt(ent); } -void ReleaseAllWithProp(Snapshot *ss, Prop prop) +void PP_ReleaseAllWithProp(PP_Snapshot *ss, PP_Prop prop) { TempArena scratch = BeginScratchNoConflict(); - Entity **ents_to_release = PushDry(scratch.arena, Entity *); + PP_Ent **ents_to_release = PushDry(scratch.arena, PP_Ent *); u64 ents_to_release_count = 0; for (u64 ent_index = 0; ent_index < ss->num_ents_reserved; ++ent_index) { - Entity *ent = &ss->ents[ent_index]; - if (ent->valid && HasProp(ent, prop)) + PP_Ent *ent = &ss->ents[ent_index]; + if (ent->valid && PP_HasProp(ent, prop)) { - *PushStructNoZero(scratch.arena, Entity *) = ent; + *PushStructNoZero(scratch.arena, PP_Ent *) = ent; ++ents_to_release_count; } } @@ -135,10 +135,10 @@ void ReleaseAllWithProp(Snapshot *ss, Prop prop) * child entities will be released along with parent anyway) */ for (u64 i = 0; i < ents_to_release_count; ++i) { - Entity *ent = ents_to_release[i]; - if (ent->valid && !ent->is_root && !HasProp(ent, Prop_Cmd) && !HasProp(ent, Prop_Player)) + PP_Ent *ent = ents_to_release[i]; + if (ent->valid && !ent->is_root && !PP_HasProp(ent, PP_Prop_Cmd) && !PP_HasProp(ent, PP_Prop_Player)) { - Release(ent); + PP_Release(ent); } } @@ -148,22 +148,22 @@ void ReleaseAllWithProp(Snapshot *ss, Prop prop) //////////////////////////////////////////////////////////// //~ Activate -void Activate(Entity *ent, u64 current_tick) +void PP_ActivateEnt(PP_Ent *ent, u64 current_tick) { - EnableProp(ent, Prop_Active); + PP_EnableProp(ent, PP_Prop_Active); ent->activation_tick = current_tick; ++ent->continuity_gen; } //////////////////////////////////////////////////////////// -//~ Entity id +//~ Ent id -u32 IndexFromEntity(Snapshot *ss, Entity *ent) +u32 PP_IndexFromEnt(PP_Snapshot *ss, PP_Ent *ent) { return ent - ss->ents; } -Entity *EntityFromIndex(Snapshot *ss, u32 index) +PP_Ent *PP_EntFromIndex(PP_Snapshot *ss, u32 index) { if (index > 0 && index < ss->num_ents_reserved) { @@ -171,37 +171,37 @@ Entity *EntityFromIndex(Snapshot *ss, u32 index) } else { - return NilEntity(); + return PP_NilEnt(); } } -EntBin *BinFromId(Snapshot *ss, EntityId id) +PP_EntBin *PP_EntBinFromKey(PP_Snapshot *ss, PP_EntKey id) { return &ss->id_bins[id.uid.lo % ss->num_id_bins]; } /* NOTE: This should only really happen during ent allocation (it doesn't make sense for an allocated ent's id to change) */ -void SetEntityId(Entity *ent, EntityId id) +void PP_SetEntKey(PP_Ent *ent, PP_EntKey id) { - Snapshot *ss = ent->ss; - EntityId old_id = ent->id; - if (!EqId(old_id, id)) + PP_Snapshot *ss = ent->ss; + PP_EntKey old_id = ent->id; + if (!PP_EqEntKey(old_id, id)) { /* Release old from lookup */ - if (!IsNilId(old_id)) + if (!PP_IsNilEntKey(old_id)) { - EntBin *bin = BinFromId(ss, old_id); + PP_EntBin *bin = PP_EntBinFromKey(ss, old_id); u32 prev_index = 0; u32 next_index = 0; u32 search_index = bin->first; - Entity *prev = NilEntity(); - Entity *next = NilEntity(); - Entity *search = EntityFromIndex(ss, search_index); + PP_Ent *prev = PP_NilEnt(); + PP_Ent *next = PP_NilEnt(); + PP_Ent *search = PP_EntFromIndex(ss, search_index); while (search->valid) { next_index = search->next_in_id_bin; - next = EntityFromIndex(ss, next_index); - if (EqId(search->id, old_id)) + next = PP_EntFromIndex(ss, next_index); + if (PP_EqEntKey(search->id, old_id)) { break; } @@ -234,19 +234,19 @@ void SetEntityId(Entity *ent, EntityId id) } /* Insert new id into lookup */ - if (!IsNilId(id)) + if (!PP_IsNilEntKey(id)) { #if RtcIsEnabled { - Entity *existing = EntityFromId(ss, id); + PP_Ent *existing = PP_EntFromKey(ss, id); /* Collision should be extremely unlikely under normal circumstances, there's probably a logic error somewhere. */ Assert(!existing->valid); } #endif - EntBin *bin = BinFromId(ss, id); - u32 ent_index = IndexFromEntity(ss, ent); - Entity *last = EntityFromIndex(ss, bin->last); + PP_EntBin *bin = PP_EntBinFromKey(ss, id); + u32 ent_index = PP_IndexFromEnt(ss, ent); + PP_Ent *last = PP_EntFromIndex(ss, bin->last); if (last->valid) { last->next_in_id_bin = ent_index; @@ -265,15 +265,15 @@ void SetEntityId(Entity *ent, EntityId id) } -Entity *EntityFromId(Snapshot *ss, EntityId id) +PP_Ent *PP_EntFromKey(PP_Snapshot *ss, PP_EntKey id) { - Entity *result = NilEntity(); - if (!IsNilId(id) && ss->valid) + PP_Ent *result = PP_NilEnt(); + if (!PP_IsNilEntKey(id) && ss->valid) { - EntBin *bin = BinFromId(ss, id); - for (Entity *e = EntityFromIndex(ss, bin->first); e->valid; e = EntityFromIndex(ss, e->next_in_id_bin)) + PP_EntBin *bin = PP_EntBinFromKey(ss, id); + for (PP_Ent *e = PP_EntFromIndex(ss, bin->first); e->valid; e = PP_EntFromIndex(ss, e->next_in_id_bin)) { - if (EqId(e->id, id)) + if (PP_EqEntKey(e->id, id)) { result = e; break; @@ -283,18 +283,18 @@ Entity *EntityFromId(Snapshot *ss, EntityId id) return result; } -EntityId RandomId(void) +PP_EntKey PP_RandomKey(void) { - EntityId result = ZI; + PP_EntKey result = ZI; result.uid = UidFromTrueRand(); return result; } /* Returns the deterministic id of the contact constraint ent id that should be produced from e0 & e1 colliding */ -EntityId ContactConstraintIdFromContactingIds(EntityId player_id, EntityId id0, EntityId id1) +PP_EntKey PP_ContactConstraintKeyFromContactingKeys(PP_EntKey player_id, PP_EntKey id0, PP_EntKey id1) { - EntityId result = ZI; - result.uid = ContactBasisUid; + PP_EntKey result = ZI; + result.uid = PP_ContactBasisUid; result.uid = CombineUid(result.uid, player_id.uid); result.uid = CombineUid(result.uid, id0.uid); result.uid = CombineUid(result.uid, id1.uid); @@ -302,10 +302,10 @@ EntityId ContactConstraintIdFromContactingIds(EntityId player_id, EntityId id0, } /* Returns the deterministic id of the debug contact constraint ent id that should be produced from e0 & e1 colliding */ -EntityId CollisionDebugIdFromIds(EntityId player_id, EntityId id0, EntityId id1) +PP_EntKey PP_CollisionDebugKeyFromKeys(PP_EntKey player_id, PP_EntKey id0, PP_EntKey id1) { - EntityId result = ZI; - result.uid = CollisionDebugBasisUid; + PP_EntKey result = ZI; + result.uid = PP_CollisionDebugBasisUid; result.uid = CombineUid(result.uid, player_id.uid); result.uid = CombineUid(result.uid, id0.uid); result.uid = CombineUid(result.uid, id1.uid); @@ -313,10 +313,10 @@ EntityId CollisionDebugIdFromIds(EntityId player_id, EntityId id0, EntityId id1) } /* Returns the deterministic id of the tile chunk that should be produced at chunk pos */ -EntityId TileChunkIdFromIndex(Vec2I32 chunk_index) +PP_EntKey PP_TileChunkKeyFromIndex(Vec2I32 chunk_index) { - EntityId result = ZI; - result.uid = TileChunkBasisUid; + PP_EntKey result = ZI; + result.uid = PP_TileChunkBasisUid; result.uid = CombineUid(result.uid, UID(RandU64FromSeed(chunk_index.x), RandU64FromSeed(chunk_index.y))); return result; } @@ -324,34 +324,34 @@ EntityId TileChunkIdFromIndex(Vec2I32 chunk_index) //////////////////////////////////////////////////////////// //~ Query -Entity *FirstWithProp(Snapshot *ss, Prop prop) +PP_Ent *PP_FirstWithProp(PP_Snapshot *ss, PP_Prop prop) { u64 count = ss->num_ents_reserved; - Entity *entities = ss->ents; + PP_Ent *entities = ss->ents; for (u64 ent_index = 0; ent_index < count; ++ent_index) { - Entity *ent = &entities[ent_index]; - if (ent->valid && HasProp(ent, prop)) + PP_Ent *ent = &entities[ent_index]; + if (ent->valid && PP_HasProp(ent, prop)) { return ent; } } - return NilEntity(); + return PP_NilEnt(); } -Entity *FirstWithAllProps(Snapshot *ss, PropArray props) +PP_Ent *PP_FirstWithAllProps(PP_Snapshot *ss, PP_PropArray props) { u64 count = ss->num_ents_reserved; - Entity *entities = ss->ents; + PP_Ent *entities = ss->ents; for (u64 ent_index = 0; ent_index < count; ++ent_index) { - Entity *ent = &entities[ent_index]; + PP_Ent *ent = &entities[ent_index]; if (ent->valid) { b32 all = 1; for (u64 i = 0; i < props.count; ++i) { - if (!HasProp(ent, props.props[i])) + if (!PP_HasProp(ent, props.props[i])) { all = 0; break; @@ -363,26 +363,26 @@ Entity *FirstWithAllProps(Snapshot *ss, PropArray props) } } } - return NilEntity(); + return PP_NilEnt(); } //////////////////////////////////////////////////////////// //~ Tree -void Link(Entity *ent, Entity *parent) +void PP_Link(PP_Ent *ent, PP_Ent *parent) { - Snapshot *ss = ent->ss; + PP_Snapshot *ss = ent->ss; - Entity *old_parent = EntityFromId(ss, ent->parent); + PP_Ent *old_parent = PP_EntFromKey(ss, ent->parent); if (old_parent->valid) { /* Unlink from current parent */ - Unlink(ent); + PP_Unlink(ent); } - EntityId ent_id = ent->id; - EntityId last_child_id = parent->last; - Entity *last_child = EntityFromId(ss, last_child_id); + PP_EntKey ent_id = ent->id; + PP_EntKey last_child_id = parent->last; + PP_Ent *last_child = PP_EntFromKey(ss, last_child_id); if (last_child->valid) { ent->prev = last_child_id; @@ -407,15 +407,15 @@ void Link(Entity *ent, Entity *parent) ent->parent = parent->id; } -/* NOTE: Entity will be dangling after calling this, should re-link to root ent. */ -void Unlink(Entity *ent) +/* NOTE: PP_Ent will be dangling after calling this, should re-link to root ent. */ +void PP_Unlink(PP_Ent *ent) { - Snapshot *ss = ent->ss; + PP_Snapshot *ss = ent->ss; - EntityId parent_id = ent->parent; - Entity *parent = EntityFromId(ss, parent_id); - Entity *prev = EntityFromId(ss, ent->prev); - Entity *next = EntityFromId(ss, ent->next); + PP_EntKey parent_id = ent->parent; + PP_Ent *parent = PP_EntFromKey(ss, parent_id); + PP_Ent *prev = PP_EntFromKey(ss, ent->prev); + PP_Ent *next = PP_EntFromKey(ss, ent->next); /* Unlink from parent & siblings */ if (prev->valid) @@ -434,16 +434,16 @@ void Unlink(Entity *ent) { parent->last = prev->id; } - ent->prev = NilEntityId; - ent->next = NilEntityId; + ent->prev = PP_NilEntKey; + ent->next = PP_NilEntKey; } //////////////////////////////////////////////////////////// //~ Xform -void MarkChildXformsDirty(Snapshot *ss, Entity *ent) +void PP_MarkChildXformsDirty(PP_Snapshot *ss, PP_Ent *ent) { - for (Entity *child = EntityFromId(ss, ent->first); child->valid; child = EntityFromId(ss, child->next)) + for (PP_Ent *child = PP_EntFromKey(ss, ent->first); child->valid; child = PP_EntFromKey(ss, child->next)) { if (child->_is_xform_dirty) { @@ -452,12 +452,12 @@ void MarkChildXformsDirty(Snapshot *ss, Entity *ent) else { child->_is_xform_dirty = 1; - MarkChildXformsDirty(ss, child); + PP_MarkChildXformsDirty(ss, child); } } } -Xform XformFromEntity_(Snapshot *ss, Entity *ent) +Xform PP_XformFromEnt_(PP_Snapshot *ss, PP_Ent *ent) { Xform xf; if (ent->_is_xform_dirty) @@ -468,8 +468,8 @@ Xform XformFromEntity_(Snapshot *ss, Entity *ent) } else { - Entity *parent = EntityFromId(ss, ent->parent); - xf = XformFromEntity_(ss, parent); + PP_Ent *parent = PP_EntFromKey(ss, ent->parent); + xf = PP_XformFromEnt_(ss, parent); xf = MulXform(xf, ent->_local_xform); ent->_xform = xf; ent->_is_xform_dirty = 0; @@ -484,7 +484,7 @@ Xform XformFromEntity_(Snapshot *ss, Entity *ent) return xf; } -Xform XformFromEntity(Entity *ent) +Xform PP_XformFromEnt(PP_Ent *ent) { Xform xf; if (ent->_is_xform_dirty) @@ -495,9 +495,9 @@ Xform XformFromEntity(Entity *ent) } else { - Snapshot *ss = ent->ss; - Entity *parent = EntityFromId(ss, ent->parent); - xf = XformFromEntity_(ss, parent); + PP_Snapshot *ss = ent->ss; + PP_Ent *parent = PP_EntFromKey(ss, ent->parent); + xf = PP_XformFromEnt_(ss, parent); xf = MulXform(xf, ent->_local_xform); ent->_xform = xf; ent->_is_xform_dirty = 0; @@ -512,16 +512,16 @@ Xform XformFromEntity(Entity *ent) return xf; } -Xform LocalXformFromEntity(Entity *ent) +Xform PP_LocalXformFromEnt(PP_Ent *ent) { return ent->_local_xform; } -void SetXform(Entity *ent, Xform xf) +void PP_SetXform(PP_Ent *ent, Xform xf) { if (!EqXform(xf, ent->_xform)) { - Snapshot *ss = ent->ss; + PP_Snapshot *ss = ent->ss; /* Update local xform */ if (ent->is_top) { @@ -529,95 +529,95 @@ void SetXform(Entity *ent, Xform xf) } else { - Entity *parent = EntityFromId(ss, ent->parent); - Xform parent_global = XformFromEntity_(ss, parent); + PP_Ent *parent = PP_EntFromKey(ss, ent->parent); + Xform parent_global = PP_XformFromEnt_(ss, parent); ent->_local_xform = MulXform(InvertXform(parent_global), xf); } ent->_xform = xf; ent->_is_xform_dirty = 0; - MarkChildXformsDirty(ss, ent); + PP_MarkChildXformsDirty(ss, ent); } } -void SetLocalXform(Entity *ent, Xform xf) +void PP_SetLocalXform(PP_Ent *ent, Xform xf) { if (!EqXform(xf, ent->_local_xform)) { ent->_local_xform = xf; ent->_is_xform_dirty = 1; - MarkChildXformsDirty(ent->ss, ent); + PP_MarkChildXformsDirty(ent->ss, ent); } } //////////////////////////////////////////////////////////// //~ Movement -void SetLinearVelocity(Entity *ent, Vec2 velocity) +void PP_SetLinearVelocity(PP_Ent *ent, Vec2 velocity) { - if (HasProp(ent, Prop_Kinematic) || HasProp(ent, Prop_Dynamic)) + if (PP_HasProp(ent, PP_Prop_Kinematic) || PP_HasProp(ent, PP_Prop_Dynamic)) { ent->linear_velocity = ClampVec2Len(velocity, SIM_MAX_LINEAR_VELOCITY); } } -void SetAngularVelocity(Entity *ent, f32 velocity) +void PP_SetAngularVelocity(PP_Ent *ent, f32 velocity) { - if (HasProp(ent, Prop_Kinematic) || HasProp(ent, Prop_Dynamic)) + if (PP_HasProp(ent, PP_Prop_Kinematic) || PP_HasProp(ent, PP_Prop_Dynamic)) { ent->angular_velocity = ClampF32(velocity, -SIM_MAX_ANGULAR_VELOCITY, SIM_MAX_ANGULAR_VELOCITY); } } -void ApplyLinearImpulse(Entity *ent, Vec2 impulse, Vec2 point) +void PP_ApplyLinearImpulse(PP_Ent *ent, Vec2 impulse, Vec2 point) { - if (HasProp(ent, Prop_Dynamic)) + if (PP_HasProp(ent, PP_Prop_Dynamic)) { - Xform xf = XformFromEntity(ent); + Xform xf = PP_XformFromEnt(ent); Vec2 center = xf.og; f32 scale = AbsF32(DeterminantFromXform(xf)); f32 inv_mass = 1.f / (ent->mass_unscaled * scale); f32 inv_inertia = 1.f / (ent->inertia_unscaled * scale); Vec2 vcp = SubVec2(point, center); - SetLinearVelocity(ent, AddVec2(ent->linear_velocity, MulVec2(impulse, inv_mass))); - SetAngularVelocity(ent, WedgeVec2(vcp, impulse) * inv_inertia); + PP_SetLinearVelocity(ent, AddVec2(ent->linear_velocity, MulVec2(impulse, inv_mass))); + PP_SetAngularVelocity(ent, WedgeVec2(vcp, impulse) * inv_inertia); } } -void ApplyLinearImpulseToCenter(Entity *ent, Vec2 impulse) +void PP_ApplyLinearImpulseToCenter(PP_Ent *ent, Vec2 impulse) { - if (HasProp(ent, Prop_Dynamic)) + if (PP_HasProp(ent, PP_Prop_Dynamic)) { - Xform xf = XformFromEntity(ent); + Xform xf = PP_XformFromEnt(ent); f32 scale = AbsF32(DeterminantFromXform(xf)); f32 inv_mass = 1.f / (ent->mass_unscaled * scale); - SetLinearVelocity(ent, AddVec2(ent->linear_velocity, MulVec2(impulse, inv_mass))); + PP_SetLinearVelocity(ent, AddVec2(ent->linear_velocity, MulVec2(impulse, inv_mass))); } } -void ApplyForceToCenter(Entity *ent, Vec2 force) +void PP_ApplyForceToCenter(PP_Ent *ent, Vec2 force) { - if (HasProp(ent, Prop_Dynamic)) + if (PP_HasProp(ent, PP_Prop_Dynamic)) { ent->force = AddVec2(ent->force, force); } } -void ApplyAngularImpulse(Entity *ent, f32 impulse) +void PP_ApplyAngularImpulse(PP_Ent *ent, f32 impulse) { - if (HasProp(ent, Prop_Dynamic)) + if (PP_HasProp(ent, PP_Prop_Dynamic)) { - Xform xf = XformFromEntity(ent); + Xform xf = PP_XformFromEnt(ent); f32 scale = AbsF32(DeterminantFromXform(xf)); f32 inv_inertia = 1.f / (ent->inertia_unscaled * scale); - SetAngularVelocity(ent, ent->angular_velocity + impulse * inv_inertia); + PP_SetAngularVelocity(ent, ent->angular_velocity + impulse * inv_inertia); } } -void ApplyTorque(Entity *ent, f32 torque) +void PP_ApplyTorque(PP_Ent *ent, f32 torque) { - if (HasProp(ent, Prop_Dynamic)) + if (PP_HasProp(ent, PP_Prop_Dynamic)) { ent->torque += torque; } @@ -626,33 +626,33 @@ void ApplyTorque(Entity *ent, f32 torque) //////////////////////////////////////////////////////////// //~ Tile -Entity *TileChunkFromChunkIndex(Snapshot *ss, Vec2I32 chunk_index) +PP_Ent *PP_TileChunkFromChunkIndex(PP_Snapshot *ss, Vec2I32 chunk_index) { - EntityId chunk_id = TileChunkIdFromIndex(chunk_index); - Entity *chunk_ent = EntityFromId(ss, chunk_id); + PP_EntKey chunk_id = PP_TileChunkKeyFromIndex(chunk_index); + PP_Ent *chunk_ent = PP_EntFromKey(ss, chunk_id); return chunk_ent; } -Entity *TileChunkFromWorldTileIndex(Snapshot *ss, Vec2I32 world_tile_index) +PP_Ent *PP_TileChunkFromWorldTileIndex(PP_Snapshot *ss, Vec2I32 world_tile_index) { - Vec2I32 chunk_index = TileChunkIndexFromWorldTileIndex(world_tile_index); - Entity *chunk_ent = TileChunkFromChunkIndex(ss, chunk_index); + Vec2I32 chunk_index = PP_TileChunkIndexFromWorldTileIndex(world_tile_index); + PP_Ent *chunk_ent = PP_TileChunkFromChunkIndex(ss, chunk_index); return chunk_ent; } -TileKind TileKindFromChunk(Entity *chunk_ent, Vec2I32 local_tile_index) +PP_TileKind PP_TileKindFromChunk(PP_Ent *chunk_ent, Vec2I32 local_tile_index) { - TileKind result = chunk_ent->tile_chunk_tiles[local_tile_index.x + (local_tile_index.y * SIM_TILES_PER_CHUNK_SQRT)]; + PP_TileKind result = chunk_ent->tile_chunk_tiles[local_tile_index.x + (local_tile_index.y * SIM_TILES_PER_CHUNK_SQRT)]; return result; } //////////////////////////////////////////////////////////// //~ Lerp -void LerpEntity(Entity *e, Entity *e0, Entity *e1, f64 blend) +void PP_LerpEnt(PP_Ent *e, PP_Ent *e0, PP_Ent *e1, f64 blend) { - if (IsValidAndActive(e0) && IsValidAndActive(e1) - && EqId(e0->id, e1->id) + if (PP_IsValidAndActive(e0) && PP_IsValidAndActive(e1) + && PP_EqEntKey(e0->id, e1->id) && e0->continuity_gen == e1->continuity_gen) { e->_local_xform = LerpXform(e0->_local_xform, e1->_local_xform, blend); @@ -660,9 +660,9 @@ void LerpEntity(Entity *e, Entity *e0, Entity *e1, f64 blend) if (e->is_top) { /* TODO: Cache parent & child xforms in sim */ - Xform e0_xf = XformFromEntity(e0); - Xform e1_xf = XformFromEntity(e1); - SetXform(e, LerpXform(e0_xf, e1_xf, blend)); + Xform e0_xf = PP_XformFromEnt(e0); + Xform e1_xf = PP_XformFromEnt(e1); + PP_SetXform(e, LerpXform(e0_xf, e1_xf, blend)); } e->control_force = LerpF32(e0->control_force, e1->control_force, blend); @@ -691,35 +691,35 @@ void LerpEntity(Entity *e, Entity *e0, Entity *e1, f64 blend) //~ Sync /* Walks a local & remote ent tree and allocates any missing net dst ents from remote src ents */ -void CreateMissingEntitiesFromSnapshots(Entity *local_parent, Entity *remote, EntityId remote_player) +void PP_CreateMissingEntsFromSnapshots(PP_Ent *local_parent, PP_Ent *remote, PP_EntKey remote_player) { __prof; - if (HasProp(remote, Prop_SyncSrc)) + if (PP_HasProp(remote, PP_Prop_SyncSrc)) { - Snapshot *local_ss = local_parent->ss; - Snapshot *remote_ss = remote->ss; + PP_Snapshot *local_ss = local_parent->ss; + PP_Snapshot *remote_ss = remote->ss; - EntityId id = remote->id; - Entity *local_ent = EntityFromId(local_ss, id); + PP_EntKey id = remote->id; + PP_Ent *local_ent = PP_EntFromKey(local_ss, id); if (!local_ent->valid) { - local_ent = AcquireSyncDst(local_parent, id, remote_player); + local_ent = PP_AcquireSyncDstEnt(local_parent, id, remote_player); } - for (Entity *remote_child = EntityFromId(remote_ss, remote->first); remote_child->valid; remote_child = EntityFromId(remote_ss, remote_child->next)) + for (PP_Ent *remote_child = PP_EntFromKey(remote_ss, remote->first); remote_child->valid; remote_child = PP_EntFromKey(remote_ss, remote_child->next)) { - CreateMissingEntitiesFromSnapshots(local_ent, remote_child, remote_player); + PP_CreateMissingEntsFromSnapshots(local_ent, remote_child, remote_player); } } } /* Copies data between two synced entities */ -void SyncEntity(Entity *local, Entity *remote) +void PP_SyncEnt(PP_Ent *local, PP_Ent *remote) { - Entity old = *local; + PP_Ent old = *local; CopyStruct(local, remote); /* Why would 2 ents w/ different uids ever be synced? */ - Assert(EqId(local->id, old.id)); + Assert(PP_EqEntKey(local->id, old.id)); local->ss = old.ss; local->id = old.id; @@ -738,8 +738,8 @@ void SyncEntity(Entity *local, Entity *remote) local->prev_in_id_bin = old.prev_in_id_bin; local->next_free = old.next_free; - DisableProp(local, Prop_SyncSrc); - EnableProp(local, Prop_SyncDst); + PP_DisableProp(local, PP_Prop_SyncSrc); + PP_EnableProp(local, PP_Prop_SyncDst); } #if 1 @@ -747,9 +747,9 @@ void SyncEntity(Entity *local, Entity *remote) //////////////////////////////////////////////////////////// //~ Encode -void EncodeEntity(BB_Writer *bw, Entity *e0, Entity *e1) +void PP_EncodeEnt(BB_Writer *bw, PP_Ent *e0, PP_Ent *e1) { - Snapshot *ss = e1->ss; + PP_Snapshot *ss = e1->ss; /* FIXME: Things like xforms need to be retreived manually rather than memcopied. */ /* TODO: Granular delta encoding */ @@ -775,9 +775,9 @@ void EncodeEntity(BB_Writer *bw, Entity *e0, Entity *e1) //////////////////////////////////////////////////////////// //~ Decode -void DecodeEntity(BB_Reader *br, Entity *e) +void PP_DecodeEnt(BB_Reader *br, PP_Ent *e) { - Snapshot *old_ss = e->ss; + PP_Snapshot *old_ss = e->ss; { u64 pos = 0; while (pos < sizeof(*e)) @@ -801,9 +801,9 @@ void DecodeEntity(BB_Reader *br, Entity *e) //////////////////////////////////////////////////////////// //~ Encode -void EncodeEntity(BB_Writer *bw, Entity *e0, Entity *e1) +void PP_EncodeEnt(BB_Writer *bw, PP_Ent *e0, PP_Ent *e1) { - Snapshot *ss = e1->ss; + PP_Snapshot *ss = e1->ss; /* FIXME: Things like xforms need to be retreived manually rather than memcopied. @@ -837,9 +837,9 @@ void EncodeEntity(BB_Writer *bw, Entity *e0, Entity *e1) //////////////////////////////////////////////////////////// //~ Decode -void DecodeEntity(BB_Reader *br, Entity *e) +void PP_DecodeEnt(BB_Reader *br, PP_Ent *e) { - Entity decoded = *e; + PP_Ent decoded = *e; { u64 pos = 0; while (pos < sizeof(decoded)) @@ -856,13 +856,13 @@ void DecodeEntity(BB_Reader *br, Entity *e) } decoded.ss = e->ss; - EntityId old_id = e->id; - EntityId new_id = decoded.id; + PP_EntKey old_id = e->id; + PP_EntKey new_id = decoded.id; CopyStruct(e, &decoded); e->id = old_id; - if (!EqId(old_id, new_id)) + if (!PP_EqEntKey(old_id, new_id)) { - SetEntityId(e, new_id); + PP_SetEntKey(e, new_id); } } #endif diff --git a/src/pp/pp_ent.h b/src/pp/pp_ent.h index 1f009da5..1076a6a4 100644 --- a/src/pp/pp_ent.h +++ b/src/pp/pp_ent.h @@ -1,78 +1,78 @@ //////////////////////////////////////////////////////////// -//~ Entity props +//~ Ent props -Enum(Prop) +Enum(PP_Prop) { - Prop_Active, - Prop_Release, + PP_Prop_Active, + PP_Prop_Release, - Prop_SyncSrc, /* This entity is networked to other clients */ - Prop_SyncDst, /* This entity is not locally created, and will sync with incoming net src ents */ + PP_Prop_SyncSrc, /* This entity is networked to other clients */ + PP_Prop_SyncDst, /* This entity is not locally created, and will sync with incoming net src ents */ - Prop_Player, - Prop_IsMaster, + PP_Prop_Player, + PP_Prop_IsMaster, - Prop_Cmd, + PP_Prop_Cmd, - Prop_TileChunk, - Prop_Wall, + PP_Prop_TileChunk, + PP_Prop_Wall, /* Physics collision */ - Prop_Sensor, /* This entity's collisions generate contacts */ - Prop_Solid, /* This entity's collisions generate contacts to be solved by the physics system (overrides Prop_Sensor) */ - Prop_Toi, /* This entity's collisions are processed using TOI (time of impact) for precise collisions */ + PP_Prop_Sensor, /* This entity's collisions generate contacts */ + PP_Prop_Solid, /* This entity's collisions generate contacts to be solved by the physics system (overrides PP_Prop_Sensor) */ + PP_Prop_Toi, /* This entity's collisions are processed using TOI (time of impact) for precise collisions */ /* Physics movement */ - Prop_Kinematic, /* This entity reacts to velocity */ - Prop_Dynamic, /* This entity reacts to velocity and forces (overrides Prop_Kinematic) */ + PP_Prop_Kinematic, /* This entity reacts to velocity */ + PP_Prop_Dynamic, /* This entity reacts to velocity and forces (overrides PP_Prop_Kinematic) */ - Prop_Controlled, + PP_Prop_Controlled, - Prop_CollisionDebug, - Prop_ContactConstraint, - Prop_MotorJoint, - Prop_MouseJoint, - Prop_WeldJoint, + PP_Prop_CollisionDebug, + PP_Prop_ContactConstraint, + PP_Prop_MotorJoint, + PP_Prop_MouseJoint, + PP_Prop_WeldJoint, - Prop_Camera, - Prop_ActiveCamera, + PP_Prop_Camera, + PP_Prop_ActiveCamera, - Prop_Bullet, - Prop_Smg, - Prop_Launcher, - Prop_Chucker, + PP_Prop_Bullet, + PP_Prop_Smg, + PP_Prop_Launcher, + PP_Prop_Chucker, - Prop_ChuckerZone, + PP_Prop_ChuckerZone, - Prop_Explosion, + PP_Prop_Explosion, - Prop_Tracer, + PP_Prop_Tracer, - Prop_Quake, + PP_Prop_Quake, - Prop_Attached, + PP_Prop_Attached, /* Test props */ - Prop_Test, - Prop_SoundEmitterTest, - Prop_LightTest, + PP_Prop_Test, + PP_Prop_SoundEmitterTest, + PP_Prop_LightTest, - Prop_Count + PP_Prop_Count }; //////////////////////////////////////////////////////////// -//~ Entity +//~ Ent -Struct(Entity) +Struct(PP_Ent) { - Snapshot *ss; + PP_Snapshot *ss; //- Metadata b32 valid; /* Is this ent allocated in memory that can be written to (can always be read) */ - EntityId id; - u64 props[(Prop_Count + 63) / 64]; + PP_EntKey id; + u64 props[(PP_Prop_Count + 63) / 64]; u64 continuity_gen; /* Is this the root ent */ @@ -82,14 +82,14 @@ Struct(Entity) b32 is_top; /* The id of the top level parent of the ent tree (if ent is top then this point to itself) */ - EntityId top; + PP_EntKey top; /* Tree */ - EntityId parent; - EntityId next; - EntityId prev; - EntityId first; - EntityId last; + PP_EntKey parent; + PP_EntKey next; + PP_EntKey prev; + PP_EntKey first; + PP_EntKey last; /* Lists keyed by index in snapshot ent array */ u32 next_in_id_bin; @@ -98,14 +98,14 @@ Struct(Entity) //- Sync - /* Prop_SyncSrc */ - /* Prop_SyncDst */ + /* PP_Prop_SyncSrc */ + /* PP_Prop_SyncDst */ /* Id of the player that owns simulation for this entity */ - EntityId owner; + PP_EntKey owner; /* Id of the player that should predict simulation of this this entity locally */ - EntityId predictor; + PP_EntKey predictor; //- Position @@ -126,31 +126,31 @@ Struct(Entity) //- Cmd - /* Prop_Cmd */ + /* PP_Prop_Cmd */ - CmdKind cmd_kind; - EntityId cmd_player; + PP_CmdKind cmd_kind; + PP_EntKey cmd_player; /* FIXME: Lerp */ /* Control cmd */ - ControlData cmd_control; - EntityId cmd_control_hovered_ent; + PP_ControlData cmd_control; + PP_EntKey cmd_control_hovered_ent; /* Chat cmd */ //String cmd_chat_msg; //- Chat - /* Prop_CHAT */ + /* PP_Prop_Chat */ - EntityId chat_player; + PP_EntKey chat_player; //String chat_msg; //- Tile - /* Prop_TileChunk */ + /* PP_Prop_TileChunk */ /* FIXME: Move out of here */ u8 tile_chunk_tiles[SIM_TILES_PER_CHUNK_SQRT * SIM_TILES_PER_CHUNK_SQRT]; @@ -158,20 +158,20 @@ Struct(Entity) //- Client - /* Prop_Player */ + /* PP_Prop_Player */ /* FIXME: Lerp */ - ClientHandle player_client_handle; /* The client handle on the master sim's machine */ + PP_ClientKey player_client_handle; /* The client key on the master sim's machine */ - ControlData player_control; + PP_ControlData player_control; Vec2 player_cursor_pos; - EntityId player_hovered_ent; - EntityId player_control_ent; - EntityId player_camera_ent; + PP_EntKey player_hovered_ent; + PP_EntKey player_control_ent; + PP_EntKey player_camera_ent; - EntityId player_dbg_drag_joint_ent; + PP_EntKey player_dbg_drag_joint_ent; b32 player_dbg_drag_start; b32 player_dbg_drag_stop; @@ -188,41 +188,41 @@ Struct(Entity) ContactDebugData collision_debug_data; #endif - SpaceEntryHandle space_handle; + PP_SpaceEntryKey space_handle; //- Constraints / joints - /* Prop_CONSTRAINT_CONTACT */ - ContactConstraint contact_constraint_data; + /* PP_Prop_ContactConstraint */ + PP_ContactConstraint contact_constraint_data; - /* Prop_MotorJoint */ - MotorJoint motor_joint_data; + /* PP_Prop_MotorJoint */ + PP_MotorJoint motor_joint_data; - /* Prop_MouseJoint */ - MouseJoint mouse_joint_data; + /* PP_Prop_MouseJoint */ + PP_MouseJoint mouse_joint_data; - /* Prop_WeldJoint */ - WeldJoint weld_joint_data; + /* PP_Prop_WeldJoint */ + PP_WeldJoint weld_joint_data; //- Control - /* Prop_Controlled */ + /* PP_Prop_Controlled */ - EntityId controlling_player; + PP_EntKey controlling_player; f32 control_force; /* How much force is applied to achieve desired control movement */ f32 control_force_max_speed; /* Maximum linear velocity achieved by force (m/s) */ f32 control_torque; /* How much torque is applied when turning towards desired focus */ - ControlData control; + PP_ControlData control; - EntityId move_joint; - EntityId aim_joint; + PP_EntKey move_joint; + PP_EntKey aim_joint; //- Physics - /* Prop_Dynamic */ + /* PP_Prop_Dynamic */ //f32 density; /* Density in kg/m^2 */ @@ -231,11 +231,11 @@ Struct(Entity) f32 mass_unscaled; /* Mass of ent in kg before any transformations */ f32 inertia_unscaled; /* Inertia of ent in kg*m^2 before any transformations */ - EntityId ground_friction_joint; + PP_EntKey ground_friction_joint; f32 linear_ground_friction; f32 angular_ground_friction; - /* Use SetLinearVelocity & SetAngularVelocity to set */ + /* Use PP_SetLinearVelocity & PP_SetAngularVelocity to set */ Vec2 linear_velocity; /* m/s */ f32 angular_velocity; /* rad/s */ @@ -258,32 +258,32 @@ Struct(Entity) //- Animation - /* Prop_ANIMATING */ + /* PP_Prop_Animating */ i64 animation_last_frame_change_time_ns; u32 animation_frame; //- Attachment - /* Prop_Attached */ + /* PP_Prop_Attached */ /* Slice name on the parent ent's sprite to attach to */ String attach_slice; //- Equip - EntityId equipped; + PP_EntKey equipped; //- Chucker - /* Prop_Chucker */ + /* PP_Prop_Chucker */ - EntityId chucker_zone; - EntityId chucker_joint; + PP_EntKey chucker_zone; + PP_EntKey chucker_joint; //- Chucker zone - /* Prop_ChuckerZone */ + /* PP_Prop_ChuckerZone */ - EntityId chucker_zone_ent; + PP_EntKey chucker_zone_ent; u64 chucker_zone_ent_tick; //- Triggerable @@ -303,13 +303,13 @@ Struct(Entity) i64 triggered_count; /* Other triggers to activate when this entity has been triggered */ - //EntityId trigger_out_left; - //EntityId trigger_out_right; + //PP_EntKey trigger_out_left; + //PP_EntKey trigger_out_right; //- Bullet - EntityId bullet_src; - EntityId bullet_tracer; + PP_EntKey bullet_src; + PP_EntKey bullet_tracer; Vec2 bullet_src_pos; Vec2 bullet_src_dir; f32 bullet_launch_velocity; @@ -325,7 +325,7 @@ Struct(Entity) //- Tracer - /* Prop_Tracer */ + /* PP_Prop_Tracer */ Vec2 tracer_start; Vec2 tracer_start_velocity; @@ -337,7 +337,7 @@ Struct(Entity) //- Quake - /* Prop_Quake */ + /* PP_Prop_Quake */ f32 quake_intensity; f32 quake_frequency; @@ -345,20 +345,20 @@ Struct(Entity) //- Testing - /* Prop_Test */ + /* PP_Prop_Test */ b32 test_initialized; Xform test_start_local_xform; Xform test_start_sprite_xform; - /* Prop_SoundEmitterTest */ + /* PP_Prop_SoundEmitterTest */ String sound_name; MIX_TrackDesc sound_desc; MIX_Handle sound_handle; //- Camera - /* Prop_Camera */ - EntityId camera_follow; + /* PP_Prop_Camera */ + PP_EntKey camera_follow; Xform camera_quad_xform; f32 camera_lerp; /* Rate at which camera xform approaches target xform */ @@ -369,103 +369,103 @@ Struct(Entity) f32 shake; }; -Struct(EntityArray) +Struct(PP_EntArray) { - Entity *ents; + PP_Ent *ents; u64 count; }; -Struct(PropArray) +Struct(PP_PropArray) { - Prop *props; + PP_Prop *props; u64 count; }; -Struct(EntBin) +Struct(PP_EntBin) { u32 first; u32 last; }; -Inline Entity *NilEntity(void) +Inline PP_Ent *PP_NilEnt(void) { - extern Readonly Entity **_g_sim_ent_nil; - return *_g_sim_ent_nil; + extern Readonly PP_Ent **PP_nil_ent; + return *PP_nil_ent; } //////////////////////////////////////////////////////////// //~ Id types -#define NilEntityId ((EntityId) { UID(0, 0) }) -#define RootEntityId ((EntityId) { UID(0xaaaaaaaaaaaaaaaa, 0xaaaaaaaaaaaaaaaa) }) +#define PP_NilEntKey ((PP_EntKey) { UID(0, 0) }) +#define PP_RootEntKey ((PP_EntKey) { UID(0xaaaaaaaaaaaaaaaa, 0xaaaaaaaaaaaaaaaa) }) /* Id magic number constants (to be used in conjunction with ent ids in deterministic id combinations) */ -#define TileChunkBasisUid (UID(0x3ce42de071dd226b, 0x9b566f7df30c813a)) -#define ContactBasisUid (UID(0x6a2a5d2dbecf534f, 0x0a8ca7c372a015af)) -#define CollisionDebugBasisUid (UID(0x302c01182013bb02, 0x570bd270399d11a5)) +#define PP_TileChunkBasisUid (UID(0x3ce42de071dd226b, 0x9b566f7df30c813a)) +#define PP_ContactBasisUid (UID(0x6a2a5d2dbecf534f, 0x0a8ca7c372a015af)) +#define PP_CollisionDebugBasisUid (UID(0x302c01182013bb02, 0x570bd270399d11a5)) //////////////////////////////////////////////////////////// //~ Id helpers -Inline b32 EqId(EntityId a, EntityId b) +Inline b32 PP_EqEntKey(PP_EntKey a, PP_EntKey b) { return EqUid(a.uid, b.uid); } -Inline b32 IsNilId(EntityId id) +Inline b32 PP_IsNilEntKey(PP_EntKey id) { - return EqUid(id.uid, NilEntityId.uid); + return EqUid(id.uid, PP_NilEntKey.uid); } //////////////////////////////////////////////////////////// //~ Property helpers -Inline void EnableProp(Entity *ent, Prop prop) +Inline void PP_EnableProp(PP_Ent *ent, PP_Prop prop) { u64 index = prop / 64; u64 bit = prop % 64; ent->props[index] |= ((u64)1 << bit); } -Inline void DisableProp(Entity *ent, Prop prop) +Inline void PP_DisableProp(PP_Ent *ent, PP_Prop prop) { u64 index = prop / 64; u64 bit = prop % 64; ent->props[index] &= ~((u64)1 << bit); } -Inline b32 HasProp(Entity *ent, Prop prop) +Inline b32 PP_HasProp(PP_Ent *ent, PP_Prop prop) { u64 index = prop / 64; u64 bit = prop % 64; return !!(ent->props[index] & ((u64)1 << bit)); } -Inline b32 IsValidAndActive(Entity *ent) +Inline b32 PP_IsValidAndActive(PP_Ent *ent) { - return ent->valid && HasProp(ent, Prop_Active); + return ent->valid && PP_HasProp(ent, PP_Prop_Active); } -Inline b32 ShouldPredict(Entity *ent) +Inline b32 PP_ShouldPredict(PP_Ent *ent) { - return EqId(ent->predictor, ent->ss->local_player); + return PP_EqEntKey(ent->predictor, ent->ss->local_player); } -Inline b32 IsOwner(Entity *ent) +Inline b32 PP_IsOwner(PP_Ent *ent) { - return EqId(ent->owner, ent->ss->local_player); + return PP_EqEntKey(ent->owner, ent->ss->local_player); } -Inline b32 ShouldSimulate(Entity *ent) +Inline b32 PP_ShouldSimulate(PP_Ent *ent) { b32 result = 0; - if (IsValidAndActive(ent)) + if (PP_IsValidAndActive(ent)) { result = 1; - if (HasProp(ent, Prop_SyncDst)) + if (PP_HasProp(ent, PP_Prop_SyncDst)) { - EntityId local_player = ent->ss->local_player; - result = EqId(local_player, ent->owner) || EqId(local_player, ent->predictor); + PP_EntKey local_player = ent->ss->local_player; + result = PP_EqEntKey(local_player, ent->owner) || PP_EqEntKey(local_player, ent->predictor); } } return result; @@ -474,95 +474,95 @@ Inline b32 ShouldSimulate(Entity *ent) //////////////////////////////////////////////////////////// //~ Acquire operations -Entity *AcquireRaw(Snapshot *ss, Entity *parent, EntityId id); -Entity *AcquireLocal(Entity *parent); -Entity *AcquireLocalWithId(Entity *parent, EntityId id); -Entity *AcquireSyncSrc(Entity *parent); -Entity *AcquireSyncSrcWithId(Entity *parent, EntityId id); -Entity *AcquireSyncDst(Entity *parent, EntityId ent_id, EntityId owner_id); +PP_Ent *PP_AcquireRawEnt(PP_Snapshot *ss, PP_Ent *parent, PP_EntKey id); +PP_Ent *PP_AcquireLocalEnt(PP_Ent *parent); +PP_Ent *PP_AcquireLocalEntWithKey(PP_Ent *parent, PP_EntKey id); +PP_Ent *PP_AcquireSyncSrcEnt(PP_Ent *parent); +PP_Ent *PP_AcquireSyncSrcEntWithKey(PP_Ent *parent, PP_EntKey id); +PP_Ent *PP_AcquireSyncDstEnt(PP_Ent *parent, PP_EntKey ent_id, PP_EntKey owner_id); //////////////////////////////////////////////////////////// //~ Release operations -void ReleaseRaw(Entity *ent); -void Release(Entity *ent); -void ReleaseAllWithProp(Snapshot *ss, Prop prop); +void PP_ReleaseRawEnt(PP_Ent *ent); +void PP_Release(PP_Ent *ent); +void PP_ReleaseAllWithProp(PP_Snapshot *ss, PP_Prop prop); //////////////////////////////////////////////////////////// //~ Activate operations -void Activate(Entity *ent, u64 current_tick); +void PP_ActivateEnt(PP_Ent *ent, u64 current_tick); //////////////////////////////////////////////////////////// //~ Id operations -u32 IndexFromEntity(Snapshot *ss, Entity *ent); -Entity *EntityFromIndex(Snapshot *ss, u32 index); -EntBin *BinFromId(Snapshot *ss, EntityId id); -void SetEntityId(Entity *ent, EntityId id); -Entity *EntityFromId(Snapshot *ss, EntityId id); -EntityId RandomId(void); -EntityId ContactConstraintIdFromContactingIds(EntityId player_id, EntityId id0, EntityId id1); -EntityId CollisionDebugIdFromIds(EntityId player_id, EntityId id0, EntityId id1); -EntityId TileChunkIdFromIndex(Vec2I32 chunk_start); +u32 PP_IndexFromEnt(PP_Snapshot *ss, PP_Ent *ent); +PP_Ent *PP_EntFromIndex(PP_Snapshot *ss, u32 index); +PP_EntBin *PP_EntBinFromKey(PP_Snapshot *ss, PP_EntKey id); +void PP_SetEntKey(PP_Ent *ent, PP_EntKey id); +PP_Ent *PP_EntFromKey(PP_Snapshot *ss, PP_EntKey id); +PP_EntKey PP_RandomKey(void); +PP_EntKey PP_ContactConstraintKeyFromContactingKeys(PP_EntKey player_id, PP_EntKey id0, PP_EntKey id1); +PP_EntKey PP_CollisionDebugKeyFromKeys(PP_EntKey player_id, PP_EntKey id0, PP_EntKey id1); +PP_EntKey PP_TileChunkKeyFromIndex(Vec2I32 chunk_start); //////////////////////////////////////////////////////////// //~ Query operations -Entity *FirstWithProp(Snapshot *ss, Prop prop); -Entity *FirstWithAllProps(Snapshot *ss, PropArray props); +PP_Ent *PP_FirstWithProp(PP_Snapshot *ss, PP_Prop prop); +PP_Ent *PP_FirstWithAllProps(PP_Snapshot *ss, PP_PropArray props); //////////////////////////////////////////////////////////// //~ Tree operations -void Link(Entity *parent, Entity *child); -void Unlink(Entity *ent); +void PP_Link(PP_Ent *parent, PP_Ent *child); +void PP_Unlink(PP_Ent *ent); //////////////////////////////////////////////////////////// //~ Xform operations -void MarkChildXformsDirty(Snapshot *ss, Entity *ent); -Xform XformFromEntity_(Snapshot *ss, Entity *ent); -Xform XformFromEntity(Entity *ent); -Xform LocalXformFromEntity(Entity *ent); -void SetXform(Entity *ent, Xform xf); -void SetLocalXform(Entity *ent, Xform xf); +void PP_MarkChildXformsDirty(PP_Snapshot *ss, PP_Ent *ent); +Xform PP_XformFromEnt_(PP_Snapshot *ss, PP_Ent *ent); +Xform PP_XformFromEnt(PP_Ent *ent); +Xform PP_LocalXformFromEnt(PP_Ent *ent); +void PP_SetXform(PP_Ent *ent, Xform xf); +void PP_SetLocalXform(PP_Ent *ent, Xform xf); //////////////////////////////////////////////////////////// //~ Movement operations -void SetLinearVelocity(Entity *ent, Vec2 velocity); -void SetAngularVelocity(Entity *ent, f32 velocity); -void ApplyLinearImpulse(Entity *ent, Vec2 impulse, Vec2 world_point); -void ApplyLinearImpulseToCenter(Entity *ent, Vec2 impulse); -void ApplyForceToCenter(Entity *ent, Vec2 force); -void ApplyAngularImpulse(Entity *ent, f32 impulse); -void ApplyTorque(Entity *ent, f32 torque); +void PP_SetLinearVelocity(PP_Ent *ent, Vec2 velocity); +void PP_SetAngularVelocity(PP_Ent *ent, f32 velocity); +void PP_ApplyLinearImpulse(PP_Ent *ent, Vec2 impulse, Vec2 world_point); +void PP_ApplyLinearImpulseToCenter(PP_Ent *ent, Vec2 impulse); +void PP_ApplyForceToCenter(PP_Ent *ent, Vec2 force); +void PP_ApplyAngularImpulse(PP_Ent *ent, f32 impulse); +void PP_ApplyTorque(PP_Ent *ent, f32 torque); //////////////////////////////////////////////////////////// //~ Tile operations -Entity *TileChunkFromChunkIndex(Snapshot *ss, Vec2I32 chunk_index); -Entity *TileChunkFromWorldTileIndex(Snapshot *ss, Vec2I32 world_tile_index); -TileKind TileKindFromChunk(Entity *chunk_ent, Vec2I32 local_tile_index); +PP_Ent *PP_TileChunkFromChunkIndex(PP_Snapshot *ss, Vec2I32 chunk_index); +PP_Ent *PP_TileChunkFromWorldTileIndex(PP_Snapshot *ss, Vec2I32 world_tile_index); +PP_TileKind PP_TileKindFromChunk(PP_Ent *chunk_ent, Vec2I32 local_tile_index); //////////////////////////////////////////////////////////// //~ Lerp operations -void LerpEntity(Entity *e, Entity *e0, Entity *e1, f64 blend); +void PP_LerpEnt(PP_Ent *e, PP_Ent *e0, PP_Ent *e1, f64 blend); //////////////////////////////////////////////////////////// //~ Sync operations -void CreateMissingEntitiesFromSnapshots(Entity *local_parent, Entity *remote, EntityId remote_player); -void SyncEntity(Entity *local, Entity *remote); +void PP_CreateMissingEntsFromSnapshots(PP_Ent *local_parent, PP_Ent *remote, PP_EntKey remote_player); +void PP_SyncEnt(PP_Ent *local, PP_Ent *remote); //////////////////////////////////////////////////////////// //~ Encode -void EncodeEntity(BB_Writer *bw, Entity *e0, Entity *e1); +void PP_EncodeEnt(BB_Writer *bw, PP_Ent *e0, PP_Ent *e1); //////////////////////////////////////////////////////////// //~ Decode -void DecodeEntity(BB_Reader *br, Entity *e); +void PP_DecodeEnt(BB_Reader *br, PP_Ent *e); diff --git a/src/pp/pp_phys.c b/src/pp/pp_phys.c index c6311353..b0611e84 100644 --- a/src/pp/pp_phys.c +++ b/src/pp/pp_phys.c @@ -1,51 +1,51 @@ //////////////////////////////////////////////////////////// //~ Contact -b32 CanEntitiesContact(Entity *e0, Entity *e1) +b32 PP_CanEntsContact(PP_Ent *e0, PP_Ent *e1) { b32 result = 0; result = e0 != e1 && - !EqId(e0->top, e1->top) && - !(HasProp(e0, Prop_Wall) && HasProp(e1, Prop_Wall)); + !PP_EqEntKey(e0->top, e1->top) && + !(PP_HasProp(e0, PP_Prop_Wall) && PP_HasProp(e1, PP_Prop_Wall)); return result; } -void CreateAndUpdateContacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_iteration) +void PP_CreateAndUpdateContacts(PP_PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_iteration) { __prof; - SimStepCtx *sim_step_ctx = ctx->sim_step_ctx; - Snapshot *ss = sim_step_ctx->world; - Space *space = sim_step_ctx->accel->space; - EntityId local_player = ss->local_player; - CollisionCallbackFunc *collision_callback = ctx->collision_callback; + PP_SimStepCtx *sim_step_ctx = ctx->sim_step_ctx; + PP_Snapshot *ss = sim_step_ctx->world; + PP_Space *space = sim_step_ctx->accel->space; + PP_EntKey local_player = ss->local_player; + PP_CollisionCallbackFunc *collision_callback = ctx->collision_callback; - Entity *root = EntityFromId(ss, RootEntityId); + PP_Ent *root = PP_EntFromKey(ss, PP_RootEntKey); u64 tick = ss->tick; for (u64 check0_index = 0; check0_index < ss->num_ents_reserved; ++check0_index) { - Entity *check0 = &ss->ents[check0_index]; - if (!IsValidAndActive(check0)) continue; - if (!(HasProp(check0, Prop_Solid) || HasProp(check0, Prop_Sensor))) continue; + PP_Ent *check0 = &ss->ents[check0_index]; + if (!PP_IsValidAndActive(check0)) continue; + if (!(PP_HasProp(check0, PP_Prop_Solid) || PP_HasProp(check0, PP_Prop_Sensor))) continue; if (check0->local_collider.count <= 0) continue; - Xform check0_xf = XformFromEntity(check0); + Xform check0_xf = PP_XformFromEnt(check0); CLD_Shape check0_collider = check0->local_collider; Aabb aabb = CLD_AabbFromShape(&check0_collider, check0_xf); - SpaceIter iter = BeginSpaceIterAabb(space, aabb); - SpaceEntry *space_entry; - while ((space_entry = NextSpaceIterAabb(&iter)) != 0) + PP_SpaceIter iter = PP_BeginSpaceIterAabb(space, aabb); + PP_SpaceEntry *space_entry; + while ((space_entry = PP_NextSpaceIterAabb(&iter)) != 0) { - Entity *check1 = EntityFromId(ss, space_entry->ent); - if (!IsValidAndActive(check1)) continue; - if (!(HasProp(check1, Prop_Solid) || HasProp(check1, Prop_Sensor))) continue; + PP_Ent *check1 = PP_EntFromKey(ss, space_entry->ent); + if (!PP_IsValidAndActive(check1)) continue; + if (!(PP_HasProp(check1, PP_Prop_Solid) || PP_HasProp(check1, PP_Prop_Sensor))) continue; if (check1->local_collider.count <= 0) continue; - if (!CanEntitiesContact(check0, check1)) continue; + if (!PP_CanEntsContact(check0, check1)) continue; /* Deterministic order based on entity id */ - Entity *e0; - Entity *e1; + PP_Ent *e0; + PP_Ent *e1; Xform e0_xf; Xform e1_xf; CLD_Shape e0_collider; @@ -55,7 +55,7 @@ void CreateAndUpdateContacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_iteratio e0 = check0; e1 = check1; e0_xf = check0_xf; - e1_xf = XformFromEntity(check1); + e1_xf = PP_XformFromEnt(check1); e0_collider = check0_collider; e1_collider = check1->local_collider; } @@ -63,14 +63,14 @@ void CreateAndUpdateContacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_iteratio { e0 = check1; e1 = check0; - e0_xf = XformFromEntity(check1); + e0_xf = PP_XformFromEnt(check1); e1_xf = check0_xf; e0_collider = check1->local_collider; e1_collider = check0_collider; } - EntityId constraint_id = ContactConstraintIdFromContactingIds(local_player, e0->id, e1->id); - Entity *constraint_ent = EntityFromId(ss, constraint_id); + PP_EntKey constraint_id = PP_ContactConstraintKeyFromContactingKeys(local_player, e0->id, e1->id); + PP_Ent *constraint_ent = PP_EntFromKey(ss, constraint_id); if (constraint_ent->valid) { @@ -92,7 +92,7 @@ void CreateAndUpdateContacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_iteratio StaticAssert(countof(constraint_ent->contact_constraint_data.points) == 2); StaticAssert(countof(collision_result.points) == 2); - ContactConstraint *constraint = 0; + PP_ContactConstraint *constraint = 0; if (collision_result.num_points > 0) { b32 is_start = 0; @@ -100,17 +100,17 @@ void CreateAndUpdateContacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_iteratio { is_start = 1; /* Create constraint */ - constraint_ent = AcquireLocalWithId(root, constraint_id); + constraint_ent = PP_AcquireLocalEntWithKey(root, constraint_id); constraint_ent->contact_constraint_data.e0 = e0->id; constraint_ent->contact_constraint_data.e1 = e1->id; /* Both entities must be solid and one must be dynamic for a solve to be necessary. */ - constraint_ent->contact_constraint_data.skip_solve = !HasProp(e0, Prop_Solid) || !HasProp(e1, Prop_Solid) || - !(HasProp(e0, Prop_Dynamic) || HasProp(e1, Prop_Dynamic)); - EnableProp(constraint_ent, Prop_Active); + constraint_ent->contact_constraint_data.skip_solve = !PP_HasProp(e0, PP_Prop_Solid) || !PP_HasProp(e1, PP_Prop_Solid) || + !(PP_HasProp(e0, PP_Prop_Dynamic) || PP_HasProp(e1, PP_Prop_Dynamic)); + PP_EnableProp(constraint_ent, PP_Prop_Active); /* TODO: Should we recalculate normal as more contact points are added? */ - EnableProp(constraint_ent, Prop_ContactConstraint); - Activate(constraint_ent, tick); + PP_EnableProp(constraint_ent, PP_Prop_ContactConstraint); + PP_ActivateEnt(constraint_ent, tick); } constraint = &constraint_ent->contact_constraint_data; constraint->normal = collision_result.normal; @@ -119,7 +119,7 @@ void CreateAndUpdateContacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_iteratio /* Delete old contacts that are no longer present */ for (u32 i = 0; i < constraint->num_points; ++i) { - ContactPoint *old = &constraint->points[i]; + PP_ContactPoint *old = &constraint->points[i]; u32 id = old->id; b32 found = 0; for (u32 j = 0; j < collision_result.num_points; ++j) @@ -145,11 +145,11 @@ void CreateAndUpdateContacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_iteratio Vec2 point = res_point->point; f32 sep = res_point->separation; u32 id = res_point->id; - ContactPoint *contact = 0; + PP_ContactPoint *contact = 0; /* Match */ for (u32 j = 0; j < constraint->num_points; ++j) { - ContactPoint *t = &constraint->points[j]; + PP_ContactPoint *t = &constraint->points[j]; if (t->id == id) { contact = t; @@ -196,7 +196,7 @@ void CreateAndUpdateContacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_iteratio /* Run collision callback */ if (collision_callback) { - CollisionData data = ZI; + PP_CollisionData data = ZI; data.e0 = e0->id; data.e1 = e1->id; data.normal = collision_result.normal; @@ -227,7 +227,7 @@ void CreateAndUpdateContacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_iteratio data.vrel = vrel; /* Collision data from e1's perspective */ - CollisionData data_inverted = data; + PP_CollisionData data_inverted = data; data_inverted.e0 = data.e1; data_inverted.e1 = data.e0; data_inverted.normal = NegVec2(data.normal); @@ -250,13 +250,13 @@ void CreateAndUpdateContacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_iteratio /* TODO: Remove this (debugging) */ #if COLLIDER_DEBUG && COLLIDER_DEBUG_DETAILED { - EntityId dbg_ent_id = CollisionDebugIdFromIds(local_player, e0->id, e1->id); - Entity *dbg_ent = EntityFromId(ss, dbg_ent_id); + PP_EntKey dbg_ent_id = PP_CollisionDebugKeyFromKeys(local_player, e0->id, e1->id); + PP_Ent *dbg_ent = PP_EntFromKey(ss, dbg_ent_id); if (!dbg_ent->valid) { - /* FIXME: Entity never released */ - dbg_ent = AcquireLocalWithId(root, dbg_ent_id); - EnableProp(dbg_ent, Prop_CollisionDebug); + /* FIXME: PP_Ent never released */ + dbg_ent = PP_AcquireLocalEntWithKey(root, dbg_ent_id); + PP_EnableProp(dbg_ent, PP_Prop_CollisionDebug); } ContactDebugData *dbg = &dbg_ent->collision_debug_data; @@ -287,33 +287,33 @@ void CreateAndUpdateContacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_iteratio } #endif } - EndSpaceIter(&iter); + PP_EndSpaceIter(&iter); } } -void PrepareContacts(PhysStepCtx *ctx, u64 phys_iteration) +void PP_PrepareContacts(PP_PhysStepCtx *ctx, u64 phys_iteration) { __prof; - Snapshot *ss = ctx->sim_step_ctx->world; + PP_Snapshot *ss = ctx->sim_step_ctx->world; for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) { - Entity *constraint_ent = &ss->ents[sim_ent_index]; - if (!ShouldSimulate(constraint_ent)) continue; - if (!HasProp(constraint_ent, Prop_ContactConstraint)) continue; + PP_Ent *constraint_ent = &ss->ents[sim_ent_index]; + if (!PP_ShouldSimulate(constraint_ent)) continue; + if (!PP_HasProp(constraint_ent, PP_Prop_ContactConstraint)) continue; - ContactConstraint *constraint = &constraint_ent->contact_constraint_data; + PP_ContactConstraint *constraint = &constraint_ent->contact_constraint_data; u32 num_points = constraint->num_points; - Entity *e0 = EntityFromId(ss, constraint->e0); - Entity *e1 = EntityFromId(ss, constraint->e1); - if (constraint->last_phys_iteration >= phys_iteration && num_points > 0 && IsValidAndActive(e0) && IsValidAndActive(e1)) + PP_Ent *e0 = PP_EntFromKey(ss, constraint->e0); + PP_Ent *e1 = PP_EntFromKey(ss, constraint->e1); + if (constraint->last_phys_iteration >= phys_iteration && num_points > 0 && PP_IsValidAndActive(e0) && PP_IsValidAndActive(e1)) { Vec2 normal = constraint->normal; Vec2 tangent = PerpVec2(normal); - Xform e0_xf = XformFromEntity(e0); - Xform e1_xf = XformFromEntity(e1); + Xform e0_xf = PP_XformFromEnt(e0); + Xform e1_xf = PP_XformFromEnt(e1); /* TODO: Cache this */ /* Calculate masses */ @@ -323,7 +323,7 @@ void PrepareContacts(PhysStepCtx *ctx, u64 phys_iteration) f32 inv_i1 = 0; { /* If not simulated locally or ent is not dynamic, pretend contact mass is infinite */ - if (ShouldSimulate(e0) && HasProp(e0, Prop_Dynamic)) + if (PP_ShouldSimulate(e0) && PP_HasProp(e0, PP_Prop_Dynamic)) { f32 scale = AbsF32(DeterminantFromXform(e0_xf)); f32 scaled_mass = e0->mass_unscaled * scale; @@ -331,7 +331,7 @@ void PrepareContacts(PhysStepCtx *ctx, u64 phys_iteration) inv_m0 = 1.f / scaled_mass; inv_i0 = 1.f / scaled_inertia; } - if (ShouldSimulate(e1) && HasProp(e1, Prop_Dynamic)) + if (PP_ShouldSimulate(e1) && PP_HasProp(e1, PP_Prop_Dynamic)) { f32 scale = AbsF32(DeterminantFromXform(e1_xf)); f32 scaled_mass = e1->mass_unscaled * scale; @@ -349,7 +349,7 @@ void PrepareContacts(PhysStepCtx *ctx, u64 phys_iteration) /* Update / insert returned contacts */ for (u32 i = 0; i < num_points; ++i) { - ContactPoint *contact = &constraint->points[i]; + PP_ContactPoint *contact = &constraint->points[i]; Vec2 vcp0 = contact->vcp0; Vec2 vcp1 = contact->vcp1; @@ -379,8 +379,8 @@ void PrepareContacts(PhysStepCtx *ctx, u64 phys_iteration) { /* Mark constraint for removal */ constraint_ent->contact_constraint_data.num_points = 0; - DisableProp(constraint_ent, Prop_Active); - EnableProp(constraint_ent, Prop_Release); + PP_DisableProp(constraint_ent, PP_Prop_Active); + PP_EnableProp(constraint_ent, PP_Prop_Release); } } @@ -389,44 +389,44 @@ void PrepareContacts(PhysStepCtx *ctx, u64 phys_iteration) /* Remove collision debug ents */ for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) { - Entity *dbg_ent = &ss->ents[sim_ent_index]; - if (!ShouldSimulate(dbg_ent)) continue; - if (!HasProp(dbg_ent, Prop_CollisionDebug)) continue; + PP_Ent *dbg_ent = &ss->ents[sim_ent_index]; + if (!PP_ShouldSimulate(dbg_ent)) continue; + if (!PP_HasProp(dbg_ent, PP_Prop_CollisionDebug)) continue; ContactDebugData *dbg = &dbg_ent->collision_debug_data; - Entity *e0 = EntityFromId(ss, dbg->e0); - Entity *e1 = EntityFromId(ss, dbg->e1); + PP_Ent *e0 = PP_EntFromKey(ss, dbg->e0); + PP_Ent *e1 = PP_EntFromKey(ss, dbg->e1); - if (!(ShouldSimulate(e0) && ShouldSimulate(e1)) || - !(HasProp(e0, Prop_Solid) || HasProp(e0, Prop_Sensor)) || - !(HasProp(e1, Prop_Solid) || HasProp(e1, Prop_Sensor))) + if (!(PP_ShouldSimulate(e0) && PP_ShouldSimulate(e1)) || + !(PP_HasProp(e0, PP_Prop_Solid) || PP_HasProp(e0, PP_Prop_Sensor)) || + !(PP_HasProp(e1, PP_Prop_Solid) || PP_HasProp(e1, PP_Prop_Sensor))) { /* Mark dbg ent for removal */ - DisableProp(dbg_ent, Prop_Active); - EnableProp(dbg_ent, Prop_Release); + PP_DisableProp(dbg_ent, PP_Prop_Active); + PP_EnableProp(dbg_ent, PP_Prop_Release); } } #endif #endif } -void WarmStartContacts(PhysStepCtx *ctx) +void PP_WarmStartContacts(PP_PhysStepCtx *ctx) { __prof; - Snapshot *ss = ctx->sim_step_ctx->world; + PP_Snapshot *ss = ctx->sim_step_ctx->world; for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) { - Entity *constraint_ent = &ss->ents[sim_ent_index]; - if (!ShouldSimulate(constraint_ent)) continue; - if (!HasProp(constraint_ent, Prop_ContactConstraint)) continue; + PP_Ent *constraint_ent = &ss->ents[sim_ent_index]; + if (!PP_ShouldSimulate(constraint_ent)) continue; + if (!PP_HasProp(constraint_ent, PP_Prop_ContactConstraint)) continue; - ContactConstraint *constraint = &constraint_ent->contact_constraint_data; + PP_ContactConstraint *constraint = &constraint_ent->contact_constraint_data; u32 num_points = constraint->num_points; - Entity *e0 = EntityFromId(ss, constraint->e0); - Entity *e1 = EntityFromId(ss, constraint->e1); + PP_Ent *e0 = PP_EntFromKey(ss, constraint->e0); + PP_Ent *e1 = PP_EntFromKey(ss, constraint->e1); - if (num_points > 0 && IsValidAndActive(e0) && IsValidAndActive(e1) && !constraint->skip_solve && !constraint->wrong_dir) + if (num_points > 0 && PP_IsValidAndActive(e0) && PP_IsValidAndActive(e1) && !constraint->skip_solve && !constraint->wrong_dir) { f32 inv_m0 = constraint->inv_m0; f32 inv_m1 = constraint->inv_m1; @@ -444,7 +444,7 @@ void WarmStartContacts(PhysStepCtx *ctx) f32 inv_num_points = 1.f / num_points; for (u32 i = 0; i < num_points; ++i) { - ContactPoint *point = &constraint->points[i]; + PP_ContactPoint *point = &constraint->points[i]; Vec2 vcp0 = point->vcp0; Vec2 vcp1 = point->vcp1; @@ -457,28 +457,28 @@ void WarmStartContacts(PhysStepCtx *ctx) w1 += WedgeVec2(vcp1, impulse) * inv_i1; } - SetLinearVelocity(e0, v0); - SetAngularVelocity(e0, w0); - SetLinearVelocity(e1, v1); - SetAngularVelocity(e1, w1); + PP_SetLinearVelocity(e0, v0); + PP_SetAngularVelocity(e0, w0); + PP_SetLinearVelocity(e1, v1); + PP_SetAngularVelocity(e1, w1); } } } -void SolveContacts(PhysStepCtx *ctx, f32 dt, b32 apply_bias) +void PP_SolveContacts(PP_PhysStepCtx *ctx, f32 dt, b32 apply_bias) { __prof; - Snapshot *ss = ctx->sim_step_ctx->world; + PP_Snapshot *ss = ctx->sim_step_ctx->world; for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) { - Entity *constraint_ent = &ss->ents[sim_ent_index]; - if (!ShouldSimulate(constraint_ent)) continue; - if (!HasProp(constraint_ent, Prop_ContactConstraint)) continue; + PP_Ent *constraint_ent = &ss->ents[sim_ent_index]; + if (!PP_ShouldSimulate(constraint_ent)) continue; + if (!PP_HasProp(constraint_ent, PP_Prop_ContactConstraint)) continue; - ContactConstraint *constraint = &constraint_ent->contact_constraint_data; + PP_ContactConstraint *constraint = &constraint_ent->contact_constraint_data; - Entity *e0 = EntityFromId(ss, constraint->e0); - Entity *e1 = EntityFromId(ss, constraint->e1); + PP_Ent *e0 = PP_EntFromKey(ss, constraint->e0); + PP_Ent *e1 = PP_EntFromKey(ss, constraint->e1); Vec2 v0 = e0->linear_velocity; Vec2 v1 = e1->linear_velocity; @@ -486,10 +486,10 @@ void SolveContacts(PhysStepCtx *ctx, f32 dt, b32 apply_bias) f32 w1 = e1->angular_velocity; u32 num_points = constraint->num_points; - if (num_points > 0 && IsValidAndActive(e0) && IsValidAndActive(e1) && !constraint->skip_solve && !constraint->wrong_dir) + if (num_points > 0 && PP_IsValidAndActive(e0) && PP_IsValidAndActive(e1) && !constraint->skip_solve && !constraint->wrong_dir) { - Xform e0_xf = XformFromEntity(e0); - Xform e1_xf = XformFromEntity(e1); + Xform e0_xf = PP_XformFromEnt(e0); + Xform e1_xf = PP_XformFromEnt(e1); f32 inv_m0 = constraint->inv_m0; f32 inv_m1 = constraint->inv_m1; @@ -500,7 +500,7 @@ void SolveContacts(PhysStepCtx *ctx, f32 dt, b32 apply_bias) Vec2 normal = constraint->normal; for (u32 point_index = 0; point_index < num_points; ++point_index) { - ContactPoint *point = &constraint->points[point_index]; + PP_ContactPoint *point = &constraint->points[point_index]; Vec2 vcp0 = point->vcp0; Vec2 vcp1 = point->vcp1; Vec2 p0 = AddVec2(e0_xf.og, vcp0); @@ -521,7 +521,7 @@ void SolveContacts(PhysStepCtx *ctx, f32 dt, b32 apply_bias) else if (apply_bias) { /* Soft constraint */ - SoftSpring softness = MakeSpring(ContactSpringHz, ContactSpringDamp, dt); + SoftSpring softness = MakeSpring(PP_ContactSpringHz, PP_ContactSpringDamp, dt); f32 pushout_velocity = constraint->pushout_velocity; mass_scale = softness.mass_scale; impulse_scale = softness.impulse_scale; @@ -554,7 +554,7 @@ void SolveContacts(PhysStepCtx *ctx, f32 dt, b32 apply_bias) Vec2 tangent = PerpVec2(normal); for (u32 point_index = 0; point_index < num_points; ++point_index) { - ContactPoint *point = &constraint->points[point_index]; + PP_ContactPoint *point = &constraint->points[point_index]; Vec2 vcp0 = point->vcp0; Vec2 vcp1 = point->vcp1; @@ -581,10 +581,10 @@ void SolveContacts(PhysStepCtx *ctx, f32 dt, b32 apply_bias) w1 += WedgeVec2(vcp1, impulse) * inv_i1; } - SetLinearVelocity(e0, v0); - SetAngularVelocity(e0, w0); - SetLinearVelocity(e1, v1); - SetAngularVelocity(e1, w1); + PP_SetLinearVelocity(e0, v0); + PP_SetAngularVelocity(e0, w0); + PP_SetLinearVelocity(e1, v1); + PP_SetAngularVelocity(e1, w1); } } } @@ -592,15 +592,15 @@ void SolveContacts(PhysStepCtx *ctx, f32 dt, b32 apply_bias) //////////////////////////////////////////////////////////// //~ Motor joint -MotorJointDesc CreateMotorJointDef(void) +PP_MotorJointDesc PP_CreateMotorJointDef(void) { - MotorJointDesc def = ZI; + PP_MotorJointDesc def = ZI; return def; } -MotorJoint MotorJointFromDef(MotorJointDesc def) +PP_MotorJoint PP_MotorJointFromDef(PP_MotorJointDesc def) { - MotorJoint result = ZI; + PP_MotorJoint result = ZI; result.e0 = def.e0; result.e1 = def.e1; result.correction_rate = ClampF32(def.correction_rate, 0, 1); @@ -609,25 +609,25 @@ MotorJoint MotorJointFromDef(MotorJointDesc def) return result; } -void PrepareMotorJoints(PhysStepCtx *ctx) +void PP_PrepareMotorJoints(PP_PhysStepCtx *ctx) { __prof; - Snapshot *ss = ctx->sim_step_ctx->world; + PP_Snapshot *ss = ctx->sim_step_ctx->world; for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) { - Entity *joint_ent = &ss->ents[sim_ent_index]; - if (!ShouldSimulate(joint_ent)) continue; - if (!HasProp(joint_ent, Prop_MotorJoint)) continue; + PP_Ent *joint_ent = &ss->ents[sim_ent_index]; + if (!PP_ShouldSimulate(joint_ent)) continue; + if (!PP_HasProp(joint_ent, PP_Prop_MotorJoint)) continue; - MotorJoint *joint = &joint_ent->motor_joint_data; + PP_MotorJoint *joint = &joint_ent->motor_joint_data; - Entity *e0 = EntityFromId(ss, joint->e0); - Entity *e1 = EntityFromId(ss, joint->e1); + PP_Ent *e0 = PP_EntFromKey(ss, joint->e0); + PP_Ent *e1 = PP_EntFromKey(ss, joint->e1); - if (ShouldSimulate(e0) && ShouldSimulate(e1)) + if (PP_ShouldSimulate(e0) && PP_ShouldSimulate(e1)) { - Xform e0_xf = XformFromEntity(e0); - Xform e1_xf = XformFromEntity(e1); + Xform e0_xf = PP_XformFromEnt(e0); + Xform e1_xf = PP_XformFromEnt(e1); /* TODO: Cache this */ /* Calculate masses */ @@ -671,29 +671,29 @@ void PrepareMotorJoints(PhysStepCtx *ctx) else { /* Mark joint for removal */ - DisableProp(joint_ent, Prop_Active); - EnableProp(joint_ent, Prop_Release); + PP_DisableProp(joint_ent, PP_Prop_Active); + PP_EnableProp(joint_ent, PP_Prop_Release); } } } -void WarmStartMotorJoints(PhysStepCtx *ctx) +void PP_WarmStartMotorJoints(PP_PhysStepCtx *ctx) { __prof; - Snapshot *ss = ctx->sim_step_ctx->world; + PP_Snapshot *ss = ctx->sim_step_ctx->world; for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) { - Entity *joint_ent = &ss->ents[sim_ent_index]; - if (!ShouldSimulate(joint_ent)) continue; - if (!HasProp(joint_ent, Prop_MotorJoint)) continue; + PP_Ent *joint_ent = &ss->ents[sim_ent_index]; + if (!PP_ShouldSimulate(joint_ent)) continue; + if (!PP_HasProp(joint_ent, PP_Prop_MotorJoint)) continue; - MotorJoint *joint = &joint_ent->motor_joint_data; + PP_MotorJoint *joint = &joint_ent->motor_joint_data; - Entity *e0 = EntityFromId(ss, joint->e0); - Entity *e1 = EntityFromId(ss, joint->e1); + PP_Ent *e0 = PP_EntFromKey(ss, joint->e0); + PP_Ent *e1 = PP_EntFromKey(ss, joint->e1); - Xform e0_xf = XformFromEntity(e0); - Xform e1_xf = XformFromEntity(e1); + Xform e0_xf = PP_XformFromEnt(e0); + Xform e1_xf = PP_XformFromEnt(e1); f32 inv_m0 = joint->inv_m0; f32 inv_m1 = joint->inv_m1; @@ -703,30 +703,30 @@ void WarmStartMotorJoints(PhysStepCtx *ctx) Vec2 vcp0 = SubVec2(MulXformV2(e0_xf, joint->point_local_e0), e0_xf.og); Vec2 vcp1 = SubVec2(MulXformV2(e1_xf, joint->point_local_e1), e1_xf.og); - SetLinearVelocity(e0, SubVec2(e0->linear_velocity, MulVec2(joint->linear_impulse, inv_m0))); - SetLinearVelocity(e1, AddVec2(e1->linear_velocity, MulVec2(joint->linear_impulse, inv_m1))); + PP_SetLinearVelocity(e0, SubVec2(e0->linear_velocity, MulVec2(joint->linear_impulse, inv_m0))); + PP_SetLinearVelocity(e1, AddVec2(e1->linear_velocity, MulVec2(joint->linear_impulse, inv_m1))); e0->angular_velocity -= (WedgeVec2(vcp0, joint->linear_impulse) + joint->angular_impulse) * inv_i0; e1->angular_velocity += (WedgeVec2(vcp1, joint->linear_impulse) + joint->angular_impulse) * inv_i1; } } -void SolveMotorJoints(PhysStepCtx *ctx, f32 dt) +void PP_SolveMotorJoints(PP_PhysStepCtx *ctx, f32 dt) { __prof; - Snapshot *ss = ctx->sim_step_ctx->world; + PP_Snapshot *ss = ctx->sim_step_ctx->world; for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) { - Entity *joint_ent = &ss->ents[sim_ent_index]; - if (!ShouldSimulate(joint_ent)) continue; - if (!HasProp(joint_ent, Prop_MotorJoint)) continue; + PP_Ent *joint_ent = &ss->ents[sim_ent_index]; + if (!PP_ShouldSimulate(joint_ent)) continue; + if (!PP_HasProp(joint_ent, PP_Prop_MotorJoint)) continue; - MotorJoint *joint = &joint_ent->motor_joint_data; + PP_MotorJoint *joint = &joint_ent->motor_joint_data; - Entity *e0 = EntityFromId(ss, joint->e0); - Entity *e1 = EntityFromId(ss, joint->e1); + PP_Ent *e0 = PP_EntFromKey(ss, joint->e0); + PP_Ent *e1 = PP_EntFromKey(ss, joint->e1); - Xform e0_xf = XformFromEntity(e0); - Xform e1_xf = XformFromEntity(e1); + Xform e0_xf = PP_XformFromEnt(e0); + Xform e1_xf = PP_XformFromEnt(e1); f32 inv_m0 = joint->inv_m0; f32 inv_m1 = joint->inv_m1; @@ -781,19 +781,19 @@ void SolveMotorJoints(PhysStepCtx *ctx, f32 dt) w1 += WedgeVec2(vcp1, delta) * inv_i1; } - SetLinearVelocity(e0, v0); - SetAngularVelocity(e0, w0); - SetLinearVelocity(e1, v1); - SetAngularVelocity(e1, w1); + PP_SetLinearVelocity(e0, v0); + PP_SetAngularVelocity(e0, w0); + PP_SetLinearVelocity(e1, v1); + PP_SetAngularVelocity(e1, w1); } } //////////////////////////////////////////////////////////// //~ Mouse joint -MouseJointDesc CreateMouseJointDef(void) +PP_MouseJointDesc PP_CreateMouseJointDef(void) { - MouseJointDesc def = ZI; + PP_MouseJointDesc def = ZI; def.linear_spring_hz = 5.0f; def.linear_spring_damp = 0.7f; def.angular_spring_hz = 5.0f; @@ -802,9 +802,9 @@ MouseJointDesc CreateMouseJointDef(void) return def; } -MouseJoint MouseJointFromDef(MouseJointDesc def) +PP_MouseJoint PP_MouseJointFromDef(PP_MouseJointDesc def) { - MouseJoint result = ZI; + PP_MouseJoint result = ZI; result.target = def.target; result.point_local_start = def.point_local_start; result.point_end = def.point_end; @@ -816,21 +816,21 @@ MouseJoint MouseJointFromDef(MouseJointDesc def) return result; } -void PrepareMouseJoints(PhysStepCtx *ctx) +void PP_PrepareMouseJoints(PP_PhysStepCtx *ctx) { __prof; - Snapshot *ss = ctx->sim_step_ctx->world; + PP_Snapshot *ss = ctx->sim_step_ctx->world; for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) { - Entity *joint_ent = &ss->ents[sim_ent_index]; - if (!ShouldSimulate(joint_ent)) continue; - if (!HasProp(joint_ent, Prop_MouseJoint)) continue; + PP_Ent *joint_ent = &ss->ents[sim_ent_index]; + if (!PP_ShouldSimulate(joint_ent)) continue; + if (!PP_HasProp(joint_ent, PP_Prop_MouseJoint)) continue; - MouseJoint *joint = &joint_ent->mouse_joint_data; - Entity *ent = EntityFromId(ss, joint->target); - if (ShouldSimulate(ent)) + PP_MouseJoint *joint = &joint_ent->mouse_joint_data; + PP_Ent *ent = PP_EntFromKey(ss, joint->target); + if (PP_ShouldSimulate(ent)) { - Xform xf = XformFromEntity(ent); + Xform xf = PP_XformFromEnt(ent); /* TODO: Cache this */ /* Calculate masses */ @@ -861,49 +861,49 @@ void PrepareMouseJoints(PhysStepCtx *ctx) else { /* Mark joint for removal */ - DisableProp(joint_ent, Prop_Active); - EnableProp(joint_ent, Prop_Release); + PP_DisableProp(joint_ent, PP_Prop_Active); + PP_EnableProp(joint_ent, PP_Prop_Release); } } } -void WarmStartMouseJoints(PhysStepCtx *ctx) +void PP_WarmStartMouseJoints(PP_PhysStepCtx *ctx) { __prof; - Snapshot *ss = ctx->sim_step_ctx->world; + PP_Snapshot *ss = ctx->sim_step_ctx->world; for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) { - Entity *joint_ent = &ss->ents[sim_ent_index]; - if (!ShouldSimulate(joint_ent)) continue; - if (!HasProp(joint_ent, Prop_MouseJoint)) continue; + PP_Ent *joint_ent = &ss->ents[sim_ent_index]; + if (!PP_ShouldSimulate(joint_ent)) continue; + if (!PP_HasProp(joint_ent, PP_Prop_MouseJoint)) continue; - MouseJoint *joint = &joint_ent->mouse_joint_data; - Entity *ent = EntityFromId(ss, joint->target); - if (ShouldSimulate(ent)) + PP_MouseJoint *joint = &joint_ent->mouse_joint_data; + PP_Ent *ent = PP_EntFromKey(ss, joint->target); + if (PP_ShouldSimulate(ent)) { f32 inv_m = joint->inv_m; f32 inv_i = joint->inv_i; - Xform xf = XformFromEntity(ent); + Xform xf = PP_XformFromEnt(ent); Vec2 vcp = SubVec2(MulXformV2(xf, joint->point_local_start), xf.og); - SetLinearVelocity(ent, AddVec2(ent->linear_velocity, MulVec2(joint->linear_impulse, inv_m))); - SetAngularVelocity(ent, ent->angular_velocity + ((WedgeVec2(vcp, joint->linear_impulse) + joint->angular_impulse) * inv_i)); + PP_SetLinearVelocity(ent, AddVec2(ent->linear_velocity, MulVec2(joint->linear_impulse, inv_m))); + PP_SetAngularVelocity(ent, ent->angular_velocity + ((WedgeVec2(vcp, joint->linear_impulse) + joint->angular_impulse) * inv_i)); } } } -void SolveMouseJoints(PhysStepCtx *ctx, f32 dt) +void PP_SolveMouseJoints(PP_PhysStepCtx *ctx, f32 dt) { __prof; - Snapshot *ss = ctx->sim_step_ctx->world; + PP_Snapshot *ss = ctx->sim_step_ctx->world; for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) { - Entity *joint_ent = &ss->ents[sim_ent_index]; - if (!ShouldSimulate(joint_ent)) continue; - if (!HasProp(joint_ent, Prop_MouseJoint)) continue; + PP_Ent *joint_ent = &ss->ents[sim_ent_index]; + if (!PP_ShouldSimulate(joint_ent)) continue; + if (!PP_HasProp(joint_ent, PP_Prop_MouseJoint)) continue; - MouseJoint *joint = &joint_ent->mouse_joint_data; - Entity *ent = EntityFromId(ss, joint->target); - if (ShouldSimulate(ent)) + PP_MouseJoint *joint = &joint_ent->mouse_joint_data; + PP_Ent *ent = PP_EntFromKey(ss, joint->target); + if (PP_ShouldSimulate(ent)) { Vec2 v = ent->linear_velocity; f32 w = ent->angular_velocity; @@ -925,7 +925,7 @@ void SolveMouseJoints(PhysStepCtx *ctx, f32 dt) { f32 max_impulse = joint->max_force / dt; - Xform xf = XformFromEntity(ent); + Xform xf = PP_XformFromEnt(ent); Vec2 point_start = MulXformV2(xf, joint->point_local_start); Vec2 point_end = joint->point_end; @@ -956,8 +956,8 @@ void SolveMouseJoints(PhysStepCtx *ctx, f32 dt) w += WedgeVec2(vcp, impulse) * inv_i; } - SetLinearVelocity(ent, v); - SetAngularVelocity(ent, w); + PP_SetLinearVelocity(ent, v); + PP_SetAngularVelocity(ent, w); } } } @@ -965,9 +965,9 @@ void SolveMouseJoints(PhysStepCtx *ctx, f32 dt) //////////////////////////////////////////////////////////// //~ Weld joint -WeldJointDesc CreateWeldJointDef(void) +PP_WeldJointDesc PP_CreateWeldJointDef(void) { - WeldJointDesc def = ZI; + PP_WeldJointDesc def = ZI; def.linear_spring_hz = 50; def.linear_spring_damp = 0; def.angular_spring_hz = 50; @@ -975,9 +975,9 @@ WeldJointDesc CreateWeldJointDef(void) return def; } -WeldJoint WeldJointFromDef(WeldJointDesc def) +PP_WeldJoint PP_WeldJointFromDef(PP_WeldJointDesc def) { - WeldJoint result = ZI; + PP_WeldJoint result = ZI; result.e0 = def.e0; result.e1 = def.e1; result.linear_spring_hz = def.linear_spring_hz; @@ -988,25 +988,25 @@ WeldJoint WeldJointFromDef(WeldJointDesc def) return result; } -void PrepareWeldJoints(PhysStepCtx *ctx) +void PP_PrepareWeldJoints(PP_PhysStepCtx *ctx) { __prof; - Snapshot *ss = ctx->sim_step_ctx->world; + PP_Snapshot *ss = ctx->sim_step_ctx->world; for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) { - Entity *joint_ent = &ss->ents[sim_ent_index]; - if (!ShouldSimulate(joint_ent)) continue; - if (!HasProp(joint_ent, Prop_WeldJoint)) continue; + PP_Ent *joint_ent = &ss->ents[sim_ent_index]; + if (!PP_ShouldSimulate(joint_ent)) continue; + if (!PP_HasProp(joint_ent, PP_Prop_WeldJoint)) continue; /* TODO: Lookup and disable collision for any contacts between e0 & e1? */ - WeldJoint *joint = &joint_ent->weld_joint_data; - Entity *e0 = EntityFromId(ss, joint->e0); - Entity *e1 = EntityFromId(ss, joint->e1); - if (ShouldSimulate(e0) && ShouldSimulate(e1)) + PP_WeldJoint *joint = &joint_ent->weld_joint_data; + PP_Ent *e0 = PP_EntFromKey(ss, joint->e0); + PP_Ent *e1 = PP_EntFromKey(ss, joint->e1); + if (PP_ShouldSimulate(e0) && PP_ShouldSimulate(e1)) { - Xform e0_xf = XformFromEntity(e0); - Xform e1_xf = XformFromEntity(e1); + Xform e0_xf = PP_XformFromEnt(e0); + Xform e1_xf = PP_XformFromEnt(e1); f32 inv_m0; f32 inv_m1; @@ -1035,45 +1035,45 @@ void PrepareWeldJoints(PhysStepCtx *ctx) else { /* Mark joint for removal */ - DisableProp(joint_ent, Prop_Active); - EnableProp(joint_ent, Prop_Release); + PP_DisableProp(joint_ent, PP_Prop_Active); + PP_EnableProp(joint_ent, PP_Prop_Release); } } } -void WarmStartWeldJoints(PhysStepCtx *ctx) +void PP_WarmStartWeldJoints(PP_PhysStepCtx *ctx) { __prof; - Snapshot *ss = ctx->sim_step_ctx->world; + PP_Snapshot *ss = ctx->sim_step_ctx->world; for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) { - Entity *joint_ent = &ss->ents[sim_ent_index]; - if (!ShouldSimulate(joint_ent)) continue; - if (!HasProp(joint_ent, Prop_WeldJoint)) continue; + PP_Ent *joint_ent = &ss->ents[sim_ent_index]; + if (!PP_ShouldSimulate(joint_ent)) continue; + if (!PP_HasProp(joint_ent, PP_Prop_WeldJoint)) continue; - WeldJoint *joint = &joint_ent->weld_joint_data; + PP_WeldJoint *joint = &joint_ent->weld_joint_data; #if 0 - Entity *e0 = EntityFromId(ss, joint->e0); - if (ShouldSimulate(e0)) + PP_Ent *e0 = PP_EntFromKey(ss, joint->e0); + if (PP_ShouldSimulate(e0)) { f32 inv_m = joint->inv_m0; f32 inv_i = joint->inv_i0; - Xform xf = XformFromEntity(e1); + Xform xf = PP_XformFromEnt(e1); Vec2 vcp = SubVec2(MulXformV2(xf, joint->point_local_start), xf.og); - SetLinearVelocity(ent, AddVec2(ent->linear_velocity, MulVec2(joint->linear_impulse, inv_m))); + PP_SetLinearVelocity(ent, AddVec2(ent->linear_velocity, MulVec2(joint->linear_impulse, inv_m))); ent->angular_velocity += (WedgeVec2(vcp, joint->linear_impulse) + joint->angular_impulse) * inv_i; } #endif #if 1 - Entity *e1 = EntityFromId(ss, joint->e1); - if (ShouldSimulate(e1)) + PP_Ent *e1 = PP_EntFromKey(ss, joint->e1); + if (PP_ShouldSimulate(e1)) { f32 inv_m = joint->inv_m1; f32 inv_i = joint->inv_i1; - SetLinearVelocity(e1, AddVec2(e1->linear_velocity, MulVec2(joint->linear_impulse1, inv_m))); - SetAngularVelocity(e1, e1->angular_velocity + joint->angular_impulse1 * inv_i); + PP_SetLinearVelocity(e1, AddVec2(e1->linear_velocity, MulVec2(joint->linear_impulse1, inv_m))); + PP_SetAngularVelocity(e1, e1->angular_velocity + joint->angular_impulse1 * inv_i); } #else LAX joint; @@ -1081,23 +1081,23 @@ void WarmStartWeldJoints(PhysStepCtx *ctx) } } -void SolveWeldJoints(PhysStepCtx *ctx, f32 dt) +void PP_SolveWeldJoints(PP_PhysStepCtx *ctx, f32 dt) { __prof; - Snapshot *ss = ctx->sim_step_ctx->world; + PP_Snapshot *ss = ctx->sim_step_ctx->world; for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) { - Entity *joint_ent = &ss->ents[sim_ent_index]; - if (!ShouldSimulate(joint_ent)) continue; - if (!HasProp(joint_ent, Prop_WeldJoint)) continue; + PP_Ent *joint_ent = &ss->ents[sim_ent_index]; + if (!PP_ShouldSimulate(joint_ent)) continue; + if (!PP_HasProp(joint_ent, PP_Prop_WeldJoint)) continue; - WeldJoint *joint = &joint_ent->weld_joint_data; - Entity *e0 = EntityFromId(ss, joint->e0); - Entity *e1 = EntityFromId(ss, joint->e1); - if (ShouldSimulate(e0) && ShouldSimulate(e1)) + PP_WeldJoint *joint = &joint_ent->weld_joint_data; + PP_Ent *e0 = PP_EntFromKey(ss, joint->e0); + PP_Ent *e1 = PP_EntFromKey(ss, joint->e1); + if (PP_ShouldSimulate(e0) && PP_ShouldSimulate(e1)) { - Xform xf0 = XformFromEntity(e0); - Xform xf1 = XformFromEntity(e1); + Xform xf0 = PP_XformFromEnt(e0); + Xform xf1 = PP_XformFromEnt(e1); Xform target_xf1 = MulXform(xf0, joint->xf0_to_xf1); @@ -1141,8 +1141,8 @@ void SolveWeldJoints(PhysStepCtx *ctx, f32 dt) } - SetLinearVelocity(e1, v1); - SetAngularVelocity(e1, w1); + PP_SetLinearVelocity(e1, v1); + PP_SetAngularVelocity(e1, w1); } } } @@ -1150,9 +1150,9 @@ void SolveWeldJoints(PhysStepCtx *ctx, f32 dt) //////////////////////////////////////////////////////////// //~ Integration -Xform GetDerivedEntityXform(Entity *ent, f32 dt) +Xform PP_GetDerivedEntXform(PP_Ent *ent, f32 dt) { - Xform xf = XformFromEntity(ent); + Xform xf = PP_XformFromEnt(ent); Vec2 step_linear_velocity = MulVec2(ent->linear_velocity, dt); f32 step_angular_velocity = ent->angular_velocity * dt; @@ -1162,17 +1162,17 @@ Xform GetDerivedEntityXform(Entity *ent, f32 dt) return xf; } -void IntegrateForces(PhysStepCtx *ctx, f32 dt) +void PP_IntegrateForces(PP_PhysStepCtx *ctx, f32 dt) { __prof; - Snapshot *ss = ctx->sim_step_ctx->world; + PP_Snapshot *ss = ctx->sim_step_ctx->world; for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) { - Entity *ent = &ss->ents[sim_ent_index]; - if (!ShouldSimulate(ent)) continue; + PP_Ent *ent = &ss->ents[sim_ent_index]; + if (!PP_ShouldSimulate(ent)) continue; - b32 is_dynamic = HasProp(ent, Prop_Dynamic); - b32 is_kinematic = HasProp(ent, Prop_Kinematic); + b32 is_dynamic = PP_HasProp(ent, PP_Prop_Dynamic); + b32 is_kinematic = PP_HasProp(ent, PP_Prop_Kinematic); if (is_dynamic || is_kinematic) { Vec2 linear_velocity = ent->linear_velocity; @@ -1183,7 +1183,7 @@ void IntegrateForces(PhysStepCtx *ctx, f32 dt) /* Integrate forces */ if (is_dynamic) { - Xform xf = XformFromEntity(ent); + Xform xf = PP_XformFromEnt(ent); f32 det_abs = AbsF32(DeterminantFromXform(xf)); f32 mass = ent->mass_unscaled * det_abs; f32 inertia = ent->inertia_unscaled * det_abs; @@ -1198,8 +1198,8 @@ void IntegrateForces(PhysStepCtx *ctx, f32 dt) angular_velocity *= angular_damping_factor; /* Update entity */ - SetLinearVelocity(ent, linear_velocity); - SetAngularVelocity(ent, angular_velocity); + PP_SetLinearVelocity(ent, linear_velocity); + PP_SetAngularVelocity(ent, angular_velocity); ent->force = VEC2(0, 0); ent->torque = 0; } @@ -1207,61 +1207,61 @@ void IntegrateForces(PhysStepCtx *ctx, f32 dt) } } -void IntegrateVelocities(PhysStepCtx *ctx, f32 dt) +void PP_IntegrateVelocities(PP_PhysStepCtx *ctx, f32 dt) { __prof; - Snapshot *ss = ctx->sim_step_ctx->world; + PP_Snapshot *ss = ctx->sim_step_ctx->world; for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) { - Entity *ent = &ss->ents[sim_ent_index]; - if (!ShouldSimulate(ent)) continue; - if (!HasProp(ent, Prop_Dynamic) && !HasProp(ent, Prop_Kinematic)) continue; + PP_Ent *ent = &ss->ents[sim_ent_index]; + if (!PP_ShouldSimulate(ent)) continue; + if (!PP_HasProp(ent, PP_Prop_Dynamic) && !PP_HasProp(ent, PP_Prop_Kinematic)) continue; - Xform xf = GetDerivedEntityXform(ent, dt); - SetXform(ent, xf); + Xform xf = PP_GetDerivedEntXform(ent, dt); + PP_SetXform(ent, xf); } } //////////////////////////////////////////////////////////// //~ Earliest time of impact -f32 DetermineEarliestToi(PhysStepCtx *ctx, f32 step_dt, f32 tolerance, u32 max_iterations) +f32 PP_DetermineEarliestToi(PP_PhysStepCtx *ctx, f32 step_dt, f32 tolerance, u32 max_iterations) { __prof; - Snapshot *ss = ctx->sim_step_ctx->world; - Space *space = ctx->sim_step_ctx->accel->space; + PP_Snapshot *ss = ctx->sim_step_ctx->world; + PP_Space *space = ctx->sim_step_ctx->accel->space; f32 smallest_t = 1; for (u64 e0_index = 0; e0_index < ss->num_ents_reserved; ++e0_index) { - Entity *e0 = &ss->ents[e0_index]; - if (!ShouldSimulate(e0)) continue; - if (!(HasProp(e0, Prop_Solid) || HasProp(e0, Prop_Sensor))) continue; - if (!HasProp(e0, Prop_Toi)) continue; + PP_Ent *e0 = &ss->ents[e0_index]; + if (!PP_ShouldSimulate(e0)) continue; + if (!(PP_HasProp(e0, PP_Prop_Solid) || PP_HasProp(e0, PP_Prop_Sensor))) continue; + if (!PP_HasProp(e0, PP_Prop_Toi)) continue; if (e0->local_collider.count <= 0) continue; CLD_Shape e0_collider = e0->local_collider; - Xform e0_xf_t0 = XformFromEntity(e0); - Xform e0_xf_t1 = GetDerivedEntityXform(e0, step_dt); + Xform e0_xf_t0 = PP_XformFromEnt(e0); + Xform e0_xf_t1 = PP_GetDerivedEntXform(e0, step_dt); /* TODO: Use swept aabb rather than combined aabb. This should prevent spikes from bullets returning 0 positive TOIs with irrelevant entities. */ Aabb aabb_t0 = CLD_AabbFromShape(&e0_collider, e0_xf_t0); Aabb aabb_t1 = CLD_AabbFromShape(&e0_collider, e0_xf_t1); Aabb combined_aabb = CLD_CombineAabb(aabb_t0, aabb_t1); - SpaceIter iter = BeginSpaceIterAabb(space, combined_aabb); - SpaceEntry *entry; - while ((entry = NextSpaceIterAabb(&iter)) != 0) + PP_SpaceIter iter = PP_BeginSpaceIterAabb(space, combined_aabb); + PP_SpaceEntry *entry; + while ((entry = PP_NextSpaceIterAabb(&iter)) != 0) { - Entity *e1 = EntityFromId(ss, entry->ent); - if (!ShouldSimulate(e1)) continue; - if (!(HasProp(e1, Prop_Solid) || HasProp(e1, Prop_Sensor))) continue; + PP_Ent *e1 = PP_EntFromKey(ss, entry->ent); + if (!PP_ShouldSimulate(e1)) continue; + if (!(PP_HasProp(e1, PP_Prop_Solid) || PP_HasProp(e1, PP_Prop_Sensor))) continue; if (e1->local_collider.count <= 0) continue; - if (!CanEntitiesContact(e0, e1)) continue; + if (!PP_CanEntsContact(e0, e1)) continue; CLD_Shape e1_collider = e1->local_collider; - Xform e1_xf_t0 = XformFromEntity(e1); - Xform e1_xf_t1 = GetDerivedEntityXform(e1, step_dt); + Xform e1_xf_t0 = PP_XformFromEnt(e1); + Xform e1_xf_t1 = PP_GetDerivedEntXform(e1, step_dt); f32 t = CLD_TimeOfImpact(&e0_collider, &e1_collider, e0_xf_t0, e1_xf_t0, e0_xf_t1, e1_xf_t1, tolerance, max_iterations); if (t != 0 && t < smallest_t) @@ -1269,7 +1269,7 @@ f32 DetermineEarliestToi(PhysStepCtx *ctx, f32 step_dt, f32 tolerance, u32 max_i smallest_t = t; } } - EndSpaceIter(&iter); + PP_EndSpaceIter(&iter); } return smallest_t; @@ -1278,26 +1278,26 @@ f32 DetermineEarliestToi(PhysStepCtx *ctx, f32 step_dt, f32 tolerance, u32 max_i //////////////////////////////////////////////////////////// //~ Spatial -void UpdateAabbs(PhysStepCtx *ctx) +void PP_UpdateAabbs(PP_PhysStepCtx *ctx) { __prof; - Snapshot *ss = ctx->sim_step_ctx->world; - Space *space = ctx->sim_step_ctx->accel->space; + PP_Snapshot *ss = ctx->sim_step_ctx->world; + PP_Space *space = ctx->sim_step_ctx->accel->space; for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) { - Entity *ent = &ss->ents[sim_ent_index]; - if (!IsValidAndActive(ent)) continue; + PP_Ent *ent = &ss->ents[sim_ent_index]; + if (!PP_IsValidAndActive(ent)) continue; if (ent->local_collider.count > 0) { - Xform xf = XformFromEntity(ent); - SpaceEntry *space_entry = SpaceEntryFromHandle(space, ent->space_handle); + Xform xf = PP_XformFromEnt(ent); + PP_SpaceEntry *space_entry = PP_SpaceEntryFromKey(space, ent->space_handle); if (!space_entry->valid) { - space_entry = AcquireSpaceEntry(space, ent->id); + space_entry = PP_AcquireSpaceEntry(space, ent->id); ent->space_handle = space_entry->handle; } Aabb aabb = CLD_AabbFromShape(&ent->local_collider, xf); - UpdateSpaceEntryAabb(space_entry, aabb); + PP_UpdateSpaceEntryAabb(space_entry, aabb); } } } @@ -1306,14 +1306,14 @@ void UpdateAabbs(PhysStepCtx *ctx) //~ Step /* Returns phys iteration to be fed into next step. Supplied iteration must be > 0. */ -void StepPhys(PhysStepCtx *ctx, f32 timestep) +void PP_StepPhys(PP_PhysStepCtx *ctx, f32 timestep) { __prof; - IntegrateForces(ctx, timestep); - Snapshot *ss = ctx->sim_step_ctx->world; + PP_IntegrateForces(ctx, timestep); + PP_Snapshot *ss = ctx->sim_step_ctx->world; u64 phys_iteration = ss->phys_iteration; - UpdateAabbs(ctx); + PP_UpdateAabbs(ctx); f32 remaining_dt = timestep; while (remaining_dt > 0) @@ -1329,20 +1329,20 @@ void StepPhys(PhysStepCtx *ctx, f32 timestep) const f32 min_toi = 0.000001f; const f32 tolerance = 0.0001f; const u32 max_iterations = 16; - f32 earliest_toi = MaxF32(DetermineEarliestToi(ctx, step_dt, tolerance, max_iterations), min_toi); + f32 earliest_toi = MaxF32(PP_DetermineEarliestToi(ctx, step_dt, tolerance, max_iterations), min_toi); step_dt = remaining_dt * earliest_toi; #else - LAX DetermineEarliestToi; + LAX PP_DetermineEarliestToi; #endif } remaining_dt -= step_dt; - CreateAndUpdateContacts(ctx, timestep - remaining_dt, phys_iteration); + PP_CreateAndUpdateContacts(ctx, timestep - remaining_dt, phys_iteration); - PrepareContacts(ctx, phys_iteration); - PrepareMotorJoints(ctx); - PrepareMouseJoints(ctx); - PrepareWeldJoints(ctx); + PP_PrepareContacts(ctx, phys_iteration); + PP_PrepareMotorJoints(ctx); + PP_PrepareMouseJoints(ctx); + PP_PrepareWeldJoints(ctx); f32 substep_dt = step_dt / SIM_PHYSICS_SUBSTEPS; for (u32 i = 0; i < SIM_PHYSICS_SUBSTEPS; ++i) @@ -1351,30 +1351,30 @@ void StepPhys(PhysStepCtx *ctx, f32 timestep) /* Warm start */ #if SIM_PHYSICS_ENABLE_WARM_STARTING - WarmStartContacts(ctx); - WarmStartMotorJoints(ctx); - WarmStartMouseJoints(ctx); - WarmStartWeldJoints(ctx); + PP_WarmStartContacts(ctx); + PP_WarmStartMotorJoints(ctx); + PP_WarmStartMouseJoints(ctx); + PP_WarmStartWeldJoints(ctx); #endif /* Solve */ #if SIM_PHYSICS_ENABLE_COLLISION - SolveContacts(ctx, substep_dt, 1); + PP_SolveContacts(ctx, substep_dt, 1); #endif - SolveMotorJoints(ctx, substep_dt); - SolveMouseJoints(ctx, substep_dt); - SolveWeldJoints(ctx, substep_dt); + PP_SolveMotorJoints(ctx, substep_dt); + PP_SolveMouseJoints(ctx, substep_dt); + PP_SolveWeldJoints(ctx, substep_dt); /* Integrate */ - IntegrateVelocities(ctx, substep_dt); + PP_IntegrateVelocities(ctx, substep_dt); /* Relaxation solve */ #if SIM_PHYSICS_ENABLE_COLLISION && SIM_PHYSICS_ENABLE_RELAXATION - SolveContacts(ctx, substep_dt, 0); + PP_SolveContacts(ctx, substep_dt, 0); #endif } - UpdateAabbs(ctx); + PP_UpdateAabbs(ctx); EndScratch(scratch); } diff --git a/src/pp/pp_phys.h b/src/pp/pp_phys.h index 6b5dbe4c..1c10d06d 100644 --- a/src/pp/pp_phys.h +++ b/src/pp/pp_phys.h @@ -1,13 +1,13 @@ //////////////////////////////////////////////////////////// //~ Collision data types -#define ContactSpringHz 25 -#define ContactSpringDamp 10 +#define PP_ContactSpringHz 25 +#define PP_ContactSpringDamp 10 -Struct(CollisionData) +Struct(PP_CollisionData) { - EntityId e0; - EntityId e1; + PP_EntKey e0; + PP_EntKey e1; Vec2 point; Vec2 normal; /* Normal of the collision from e0 to e1 */ Vec2 vrel; /* Relative velocity at point of collision */ @@ -16,24 +16,24 @@ Struct(CollisionData) }; /* Callback can return 1 to prevent the physics system from resolving */ -struct SimStepCtx; -#define CollisionCallbackFuncDef(name, arg_collision_data, arg_sim_step_ctx) b32 name(CollisionData *arg_collision_data, struct SimStepCtx *arg_sim_step_ctx) -typedef CollisionCallbackFuncDef(CollisionCallbackFunc, collision_data, ctx); +struct PP_SimStepCtx; +#define PP_CollisionCallbackFuncDef(name, arg_collision_data, arg_sim_step_ctx) b32 name(PP_CollisionData *arg_collision_data, struct PP_SimStepCtx *arg_sim_step_ctx) +typedef PP_CollisionCallbackFuncDef(PP_CollisionCallbackFunc, collision_data, ctx); //////////////////////////////////////////////////////////// //~ Step ctx /* Structure containing data used for a single physics step */ -Struct(PhysStepCtx) +Struct(PP_PhysStepCtx) { - struct SimStepCtx *sim_step_ctx; - CollisionCallbackFunc *collision_callback; + struct PP_SimStepCtx *sim_step_ctx; + PP_CollisionCallbackFunc *collision_callback; }; //////////////////////////////////////////////////////////// //~ Contact types -Struct(ContactPoint) +Struct(PP_ContactPoint) { /* Contact point relative to the center of each entity. * @@ -59,13 +59,13 @@ Struct(ContactPoint) #endif }; -Struct(ContactConstraint) +Struct(PP_ContactConstraint) { u64 last_phys_iteration; /* To avoid checking collisions for the same constraint twice in one tick */ b32 skip_solve; b32 wrong_dir; - EntityId e0; - EntityId e1; + PP_EntKey e0; + PP_EntKey e1; f32 inv_m0; f32 inv_m1; f32 inv_i0; @@ -73,7 +73,7 @@ Struct(ContactConstraint) Vec2 normal; /* Normal vector of collision from e0 -> e1 */ u64 last_iteration; - ContactPoint points[2]; + PP_ContactPoint points[2]; u32 num_points; f32 friction; @@ -81,13 +81,13 @@ Struct(ContactConstraint) f32 pushout_velocity; }; -Struct(ContactDebugData) +Struct(PP_ContactDebugData) { - EntityId e0; - EntityId e1; + PP_EntKey e0; + PP_EntKey e1; CLD_CollisionData collision_result; - ContactPoint points[2]; + PP_ContactPoint points[2]; u32 num_points; Vec2 closest0; @@ -100,19 +100,19 @@ Struct(ContactDebugData) //////////////////////////////////////////////////////////// //~ Motor joint types -Struct(MotorJointDesc) +Struct(PP_MotorJointDesc) { - EntityId e0; - EntityId e1; + PP_EntKey e0; + PP_EntKey e1; f32 correction_rate; f32 max_force; f32 max_torque; }; -Struct(MotorJoint) +Struct(PP_MotorJoint) { - EntityId e0; - EntityId e1; + PP_EntKey e0; + PP_EntKey e1; f32 correction_rate; f32 max_force; f32 max_torque; @@ -135,9 +135,9 @@ Struct(MotorJoint) //////////////////////////////////////////////////////////// //~ Mouse joint types -Struct(MouseJointDesc) +Struct(PP_MouseJointDesc) { - EntityId target; + PP_EntKey target; Vec2 point_local_start; Vec2 point_end; f32 linear_spring_hz; @@ -147,9 +147,9 @@ Struct(MouseJointDesc) f32 max_force; }; -Struct(MouseJoint) +Struct(PP_MouseJoint) { - EntityId target; + PP_EntKey target; Vec2 point_local_start; Vec2 point_end; f32 linear_spring_hz; @@ -170,10 +170,10 @@ Struct(MouseJoint) //////////////////////////////////////////////////////////// //~ Weld joint types -Struct(WeldJointDesc) +Struct(PP_WeldJointDesc) { - EntityId e0; - EntityId e1; + PP_EntKey e0; + PP_EntKey e1; /* The xform that transforms a point in e0's space into the desired e1 space * (IE `xf` * VEC2(0, 0) should evaluate to the local point that e1's origin will lie) */ @@ -185,10 +185,10 @@ Struct(WeldJointDesc) f32 angular_spring_damp; }; -Struct(WeldJoint) +Struct(PP_WeldJoint) { - EntityId e0; - EntityId e1; + PP_EntKey e0; + PP_EntKey e1; Xform xf0_to_xf1; f32 linear_spring_hz; @@ -210,58 +210,57 @@ Struct(WeldJoint) //////////////////////////////////////////////////////////// //~ Contact operations -b32 CanEntitiesContact(struct Entity *e0, struct Entity *e1); -void CreateAndUpdateContacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_iteration); -void PrepareContacts(PhysStepCtx *ctx, u64 phys_iteration); -void WarmStartContacts(PhysStepCtx *ctx); -void SolveContacts(PhysStepCtx *ctx, f32 dt, b32 apply_bias); +b32 PP_CanEntsContact(struct PP_Ent *e0, struct PP_Ent *e1); +void PP_CreateAndUpdateContacts(PP_PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_iteration); +void PP_PrepareContacts(PP_PhysStepCtx *ctx, u64 phys_iteration); +void PP_WarmStartContacts(PP_PhysStepCtx *ctx); +void PP_SolveContacts(PP_PhysStepCtx *ctx, f32 dt, b32 apply_bias); //////////////////////////////////////////////////////////// //~ Motor joint operations -MotorJointDesc CreateMotorJointDef(void); -MotorJoint MotorJointFromDef(MotorJointDesc def); -void PrepareMotorJoints(PhysStepCtx *ctx); -void WarmStartMotorJoints(PhysStepCtx *ctx); -void SolveMotorJoints(PhysStepCtx *ctx, f32 dt); +PP_MotorJointDesc PP_CreateMotorJointDef(void); +PP_MotorJoint PP_MotorJointFromDef(PP_MotorJointDesc def); +void PP_PrepareMotorJoints(PP_PhysStepCtx *ctx); +void PP_WarmStartMotorJoints(PP_PhysStepCtx *ctx); +void PP_SolveMotorJoints(PP_PhysStepCtx *ctx, f32 dt); //////////////////////////////////////////////////////////// //~ Mouse joint operations -MouseJointDesc CreateMouseJointDef(void); -MouseJoint MouseJointFromDef(MouseJointDesc def); -void PrepareMouseJoints(PhysStepCtx *ctx); -void WarmStartMouseJoints(PhysStepCtx *ctx); -void SolveMouseJoints(PhysStepCtx *ctx, f32 dt); +PP_MouseJointDesc PP_CreateMouseJointDef(void); +PP_MouseJoint PP_MouseJointFromDef(PP_MouseJointDesc def); +void PP_PrepareMouseJoints(PP_PhysStepCtx *ctx); +void PP_WarmStartMouseJoints(PP_PhysStepCtx *ctx); +void PP_SolveMouseJoints(PP_PhysStepCtx *ctx, f32 dt); //////////////////////////////////////////////////////////// //~ Weld joint operations -WeldJointDesc CreateWeldJointDef(void); -WeldJoint WeldJointFromDef(WeldJointDesc def); -void PrepareWeldJoints(PhysStepCtx *ctx); -void WarmStartWeldJoints(PhysStepCtx *ctx); -void SolveWeldJoints(PhysStepCtx *ctx, f32 dt); +PP_WeldJointDesc PP_CreateWeldJointDef(void); +PP_WeldJoint PP_WeldJointFromDef(PP_WeldJointDesc def); +void PP_PrepareWeldJoints(PP_PhysStepCtx *ctx); +void PP_WarmStartWeldJoints(PP_PhysStepCtx *ctx); +void PP_SolveWeldJoints(PP_PhysStepCtx *ctx, f32 dt); //////////////////////////////////////////////////////////// //~ Integration operations -struct Entity; -Xform GetDerivedEntityXform(struct Entity *ent, f32 dt); -void IntegrateForces(PhysStepCtx *ctx, f32 dt); -void IntegrateVelocities(PhysStepCtx *ctx, f32 dt); +Xform PP_GetDerivedEntXform(struct PP_Ent *ent, f32 dt); +void PP_IntegrateForces(PP_PhysStepCtx *ctx, f32 dt); +void PP_IntegrateVelocities(PP_PhysStepCtx *ctx, f32 dt); //////////////////////////////////////////////////////////// //~ Time of impact operations -f32 DetermineEarliestToi(PhysStepCtx *ctx, f32 step_dt, f32 tolerance, u32 max_iterations); +f32 PP_DetermineEarliestToi(PP_PhysStepCtx *ctx, f32 step_dt, f32 tolerance, u32 max_iterations); //////////////////////////////////////////////////////////// //~ Spatial operations -void UpdateAabbs(PhysStepCtx *ctx); +void PP_UpdateAabbs(PP_PhysStepCtx *ctx); //////////////////////////////////////////////////////////// //~ Step -void StepPhys(PhysStepCtx *ctx, f32 timestep); +void PP_StepPhys(PP_PhysStepCtx *ctx, f32 timestep); diff --git a/src/pp/pp_sim.c b/src/pp/pp_sim.c index 51ccde0b..aab2ee26 100644 --- a/src/pp/pp_sim.c +++ b/src/pp/pp_sim.c @@ -1,6 +1,6 @@ /* Sim hierarchy is as follows: * - * Client store -> clients -> snapshots -> ents + * PP_Client store -> clients -> snapshots -> ents * * A client store holds clients, which can be retrieved by client handle or by a host channel id (if one is assigned). * @@ -27,37 +27,37 @@ //////////////////////////////////////////////////////////// //~ Startup -SharedSimCtx shared_sim_ctx = ZI; -Readonly ClientStore **_g_sim_client_store_nil = &shared_sim_ctx.nil_client_store; -Readonly Client **_g_sim_client_nil = &shared_sim_ctx.nil_client; -Readonly Snapshot **_g_sim_snapshot_nil = &shared_sim_ctx.nil_snapshot; -Readonly Entity **_g_sim_ent_nil = &shared_sim_ctx.nil_ent; +PP_SharedSimCtx PP_shared_sim_ctx = ZI; +Readonly PP_ClientStore **PP_nil_client_store = &PP_shared_sim_ctx.nil_client_store; +Readonly PP_Client **PP_nil_client = &PP_shared_sim_ctx.nil_client; +Readonly PP_Snapshot **PP_nil_snapshot = &PP_shared_sim_ctx.nil_snapshot; +Readonly PP_Ent **PP_nil_ent = &PP_shared_sim_ctx.nil_ent; -void StartupSim(void) +void PP_StartupSim(void) { __prof; - SharedSimCtx *g = &shared_sim_ctx; + PP_SharedSimCtx *g = &PP_shared_sim_ctx; g->nil_arena = AcquireArena(Gibi(1)); /* Nil client store */ - g->nil_client_store = PushStruct(g->nil_arena, ClientStore); + g->nil_client_store = PushStruct(g->nil_arena, PP_ClientStore); g->nil_client_store->valid = 0; /* Nil client */ - g->nil_client = PushStruct(g->nil_arena, Client); + g->nil_client = PushStruct(g->nil_arena, PP_Client); g->nil_client->valid = 0; - g->nil_client->store = sim_client_store_nil(); + g->nil_client->store = PP_NilClientStore(); /* Nil snapshot */ - g->nil_snapshot = PushStruct(g->nil_arena, Snapshot); + g->nil_snapshot = PushStruct(g->nil_arena, PP_Snapshot); g->nil_snapshot->valid = 0; - g->nil_snapshot->client = NilClient(); + g->nil_snapshot->client = PP_NilClient(); /* Nil ent */ - g->nil_ent = PushStruct(g->nil_arena, Entity); - g->nil_ent->ss = NilSnapshot(); + g->nil_ent = PushStruct(g->nil_arena, PP_Ent); + g->nil_ent->ss = PP_NilSnapshot(); g->nil_ent->valid = 0; - g->nil_ent->id = NilEntityId; + g->nil_ent->id = PP_NilEntKey; g->nil_ent->_local_xform = XformIdentity; g->nil_ent->_xform = XformIdentity; g->nil_ent->_is_xform_dirty = 0; @@ -74,32 +74,32 @@ void StartupSim(void) //////////////////////////////////////////////////////////// //~ Acquire client store -ClientStore *AcquireClientStore(void) +PP_ClientStore *PP_AcquireClientStore(void) { __prof; - ClientStore *store; + PP_ClientStore *store; { Arena *arena = AcquireArena(Gibi(64)); - store = PushStruct(arena, ClientStore); + store = PushStruct(arena, PP_ClientStore); store->arena = arena; } store->valid = 1; - store->num_client_lookup_bins = ClientLookupBinsCount; - store->client_lookup_bins = PushStructs(store->arena, ClientLookupBin, store->num_client_lookup_bins); + store->num_client_lookup_bins = PP_ClientLookupBinsCount; + store->client_lookup_bins = PushStructs(store->arena, PP_ClientLookupBin, store->num_client_lookup_bins); store->clients_arena = AcquireArena(Gibi(64)); - store->clients = PushDry(store->clients_arena, Client); + store->clients = PushDry(store->clients_arena, PP_Client); return store; } -void ReleaseClientStore(ClientStore *store) +void PP_ReleaseClientStore(PP_ClientStore *store) { __prof; for (u64 i = 0; i < store->num_clients_reserved; ++i) { - Client *client = &store->clients[i]; + PP_Client *client = &store->clients[i]; if (client->valid) { - ReleaseClient(client); + PP_ReleaseClient(client); } } ReleaseArena(store->clients_arena); @@ -109,10 +109,10 @@ void ReleaseClientStore(ClientStore *store) //////////////////////////////////////////////////////////// //~ Acquire client -Client *AcquireClient(ClientStore *store) +PP_Client *PP_AcquireClient(PP_ClientStore *store) { - ClientHandle handle = ZI; - Client *client = ClientFromHandle(store, store->first_free_client); + PP_ClientKey handle = ZI; + PP_Client *client = PP_ClientFromKey(store, store->first_free_client); if (client->valid) { @@ -122,34 +122,34 @@ Client *AcquireClient(ClientStore *store) } else { - client = PushStructNoZero(store->clients_arena, Client); + client = PushStructNoZero(store->clients_arena, PP_Client); handle.gen = 1; handle.idx = store->num_clients_reserved; ++store->num_clients_reserved; } ++store->num_clients_allocated; - *client = *NilClient(); + *client = *PP_NilClient(); client->store = store; client->valid = 1; client->handle = handle; client->snapshots_arena = AcquireArena(Gibi(8)); - client->num_snapshot_lookup_bins = TickLookupBinsCount; - client->snapshot_lookup_bins = PushStructs(client->snapshots_arena, SnapshotLookupBin, client->num_snapshot_lookup_bins); + client->num_snapshot_lookup_bins = PP_TickLookupBinsCount; + client->snapshot_lookup_bins = PushStructs(client->snapshots_arena, PP_SnapshotLookupBin, client->num_snapshot_lookup_bins); return client; } -void ReleaseClient(Client *client) +void PP_ReleaseClient(PP_Client *client) { /* Release internal snapshot memory */ for (u64 i = 0; i < client->num_snapshot_lookup_bins; ++i) { - SnapshotLookupBin *bin = &client->snapshot_lookup_bins[i]; - Snapshot *ss = bin->first; + PP_SnapshotLookupBin *bin = &client->snapshot_lookup_bins[i]; + PP_Snapshot *ss = bin->first; while (ss) { - Snapshot *next = ss->next_in_bin; + PP_Snapshot *next = ss->next_in_bin; ReleaseArena(ss->ents_arena); ReleaseArena(ss->arena); ss = next; @@ -157,10 +157,10 @@ void ReleaseClient(Client *client) } /* Remove from channel lookup */ - SetClientChannelId(client, N_NilChannelId); + PP_SetClientChannelId(client, N_NilChannelId); /* Release client */ - ClientStore *store = client->store; + PP_ClientStore *store = client->store; client->valid = 0; client->next_free = store->first_free_client; store->first_free_client = client->handle; @@ -172,23 +172,23 @@ void ReleaseClient(Client *client) //////////////////////////////////////////////////////////// //~ Client lookup -u64 ClientChannelHashFromChannelId(N_ChannelId channel_id) +u64 PP_ClientChannelHashFromChannelId(N_ChannelId channel_id) { return HashFnv64(Fnv64Basis, StringFromStruct(&channel_id)); } -void SetClientChannelId(Client *client, N_ChannelId channel_id) +void PP_SetClientChannelId(PP_Client *client, N_ChannelId channel_id) { - ClientStore *store = client->store; + PP_ClientStore *store = client->store; N_ChannelId old_channel_id = client->channel_id; /* Remove old channel id from channel lookup */ if (!N_IsChannelIdNil(old_channel_id)) { u64 bin_index = client->channel_hash % store->num_client_lookup_bins; - ClientLookupBin *bin = &store->client_lookup_bins[bin_index]; - Client *prev = ClientFromHandle(store, client->prev_in_bin); - Client *next = ClientFromHandle(store, client->next_in_bin); + PP_ClientLookupBin *bin = &store->client_lookup_bins[bin_index]; + PP_Client *prev = PP_ClientFromKey(store, client->prev_in_bin); + PP_Client *next = PP_ClientFromKey(store, client->next_in_bin); if (prev->valid) { prev->next_in_bin = next->handle; @@ -209,15 +209,15 @@ void SetClientChannelId(Client *client, N_ChannelId channel_id) /* Insert into channel lookup */ /* TODO: Enforce no duplicates */ - u64 channel_hash = ClientChannelHashFromChannelId(channel_id); + u64 channel_hash = PP_ClientChannelHashFromChannelId(channel_id); client->channel_id = channel_id; client->channel_hash = channel_hash; if (!N_IsChannelIdNil(channel_id)) { u64 bin_index = channel_hash % store->num_client_lookup_bins; - ClientLookupBin *bin = &store->client_lookup_bins[bin_index]; + PP_ClientLookupBin *bin = &store->client_lookup_bins[bin_index]; { - Client *prev_in_bin = ClientFromHandle(store, bin->last); + PP_Client *prev_in_bin = PP_ClientFromKey(store, bin->last); if (prev_in_bin->valid) { prev_in_bin->next_in_bin = client->handle; @@ -232,13 +232,13 @@ void SetClientChannelId(Client *client, N_ChannelId channel_id) } } -Client *ClientFromChannelId(ClientStore *store, N_ChannelId channel_id) +PP_Client *PP_ClientFromChannelId(PP_ClientStore *store, N_ChannelId channel_id) { - Client *result = NilClient(); - u64 channel_hash = ClientChannelHashFromChannelId(channel_id); + PP_Client *result = PP_NilClient(); + u64 channel_hash = PP_ClientChannelHashFromChannelId(channel_id); u64 bin_index = channel_hash % store->num_client_lookup_bins; - ClientLookupBin *bin = &store->client_lookup_bins[bin_index]; - for (Client *client = ClientFromHandle(store, bin->first); client->valid; client = ClientFromHandle(store, client->next_in_bin)) + PP_ClientLookupBin *bin = &store->client_lookup_bins[bin_index]; + for (PP_Client *client = PP_ClientFromKey(store, bin->first); client->valid; client = PP_ClientFromKey(store, client->next_in_bin)) { if (client->channel_hash == channel_hash) { @@ -249,31 +249,31 @@ Client *ClientFromChannelId(ClientStore *store, N_ChannelId channel_id) return result; } -Client *ClientFromHandle(ClientStore *store, ClientHandle handle) +PP_Client *PP_ClientFromKey(PP_ClientStore *store, PP_ClientKey handle) { if (handle.gen != 0 && handle.idx < store->num_clients_reserved) { - Client *client = &store->clients[handle.idx]; + PP_Client *client = &store->clients[handle.idx]; if (client->handle.gen == handle.gen) { return client; } } - return NilClient(); + return PP_NilClient(); } //////////////////////////////////////////////////////////// //~ Acquire snapshot /* Produces a new snapshot at `tick` with data copied from `src` snapshot. */ -Snapshot *AcquireSnapshot(Client *client, Snapshot *src, u64 tick) +PP_Snapshot *PP_AcquireSnapshot(PP_Client *client, PP_Snapshot *src, u64 tick) { if (tick == 0) { - return NilSnapshot(); + return PP_NilSnapshot(); } - Snapshot *ss; + PP_Snapshot *ss; { Arena *arena = ZI; Arena *ents_arena = 0; @@ -294,7 +294,7 @@ Snapshot *AcquireSnapshot(Client *client, Snapshot *src, u64 tick) } } ResetArena(arena); - ss = PushStruct(arena, Snapshot); + ss = PushStruct(arena, PP_Snapshot); ss->arena = arena; ss->ents_arena = ents_arena; @@ -314,8 +314,8 @@ Snapshot *AcquireSnapshot(Client *client, Snapshot *src, u64 tick) ss->phys_iteration = src->phys_iteration; /* Copy id lookup bins */ - ss->num_id_bins = src->num_id_bins > 0 ? src->num_id_bins : IdLookupBinsCount; - ss->id_bins = PushStructsNoZero(ss->arena, EntBin, ss->num_id_bins); + ss->num_id_bins = src->num_id_bins > 0 ? src->num_id_bins : PP_IdLookupBinsCount; + ss->id_bins = PushStructsNoZero(ss->arena, PP_EntBin, ss->num_id_bins); if (src->num_id_bins > 0) { for (u64 i = 0; i < src->num_id_bins; ++i) @@ -332,28 +332,28 @@ Snapshot *AcquireSnapshot(Client *client, Snapshot *src, u64 tick) ss->first_free_ent = src->first_free_ent; ss->num_ents_allocated = src->num_ents_allocated; ss->num_ents_reserved = src->num_ents_reserved; - ss->ents = PushStructsNoZero(ss->ents_arena, Entity, ss->num_ents_reserved); + ss->ents = PushStructsNoZero(ss->ents_arena, PP_Ent, ss->num_ents_reserved); if (ss->num_ents_reserved == 0) { /* Copying from nil snapshot, need to create blank & root entity */ - /* Push blank ent at index 0 (because index 0 is never valid anyway since it maps to NilEntity()) */ + /* Push blank ent at index 0 (because index 0 is never valid anyway since it maps to nil ent) */ { - PushStruct(ss->ents_arena, Entity); + PushStruct(ss->ents_arena, PP_Ent); ++ss->num_ents_allocated; ++ss->num_ents_reserved; } /* Push root ent with constant id */ { - Entity *root = PushStructNoZero(ss->ents_arena, Entity); - *root = *NilEntity(); + PP_Ent *root = PushStructNoZero(ss->ents_arena, PP_Ent); + *root = *PP_NilEnt(); root->ss = ss; root->valid = 1; root->is_root = 1; root->mass_unscaled = F32Infinity; root->inertia_unscaled = F32Infinity; - SetEntityId(root, RootEntityId); + PP_SetEntKey(root, PP_RootEntKey); ++ss->num_ents_allocated; ++ss->num_ents_reserved; } @@ -362,8 +362,8 @@ Snapshot *AcquireSnapshot(Client *client, Snapshot *src, u64 tick) { for (u64 i = 0; i < ss->num_ents_reserved; ++i) { - Entity *dst_ent = &ss->ents[i]; - Entity *src_ent = &src->ents[i]; + PP_Ent *dst_ent = &ss->ents[i]; + PP_Ent *src_ent = &src->ents[i]; *dst_ent = *src_ent; dst_ent->ss = ss; } @@ -371,27 +371,27 @@ Snapshot *AcquireSnapshot(Client *client, Snapshot *src, u64 tick) /* Release duplicate tick if it exists */ { - Snapshot *existing = SnapshotFromTick(client, tick); + PP_Snapshot *existing = PP_SnapshotFromTick(client, tick); if (existing->valid) { - ReleaseSnapshot(existing); + PP_ReleaseSnapshot(existing); } } /* Linear search to insert snapshot in tick order */ { - Snapshot *prev = SnapshotFromTick(client, client->last_tick); + PP_Snapshot *prev = PP_SnapshotFromTick(client, client->last_tick); while (prev->valid) { if (prev->tick < tick) { break; } - prev = SnapshotFromTick(client, prev->prev_tick); + prev = PP_SnapshotFromTick(client, prev->prev_tick); } if (prev->valid) { - Snapshot *next = SnapshotFromTick(client, prev->next_tick); + PP_Snapshot *next = PP_SnapshotFromTick(client, prev->next_tick); if (next->valid) { next->prev_tick = tick; @@ -406,7 +406,7 @@ Snapshot *AcquireSnapshot(Client *client, Snapshot *src, u64 tick) } else { - Snapshot *first = SnapshotFromTick(client, client->first_tick); + PP_Snapshot *first = PP_SnapshotFromTick(client, client->first_tick); if (first->valid) { ss->next_tick = first->tick; @@ -424,7 +424,7 @@ Snapshot *AcquireSnapshot(Client *client, Snapshot *src, u64 tick) /* Insert into lookup */ { u64 bin_index = tick % client->num_snapshot_lookup_bins; - SnapshotLookupBin *bin = &client->snapshot_lookup_bins[bin_index]; + PP_SnapshotLookupBin *bin = &client->snapshot_lookup_bins[bin_index]; if (bin->last) { bin->last->next_in_bin = ss; @@ -440,16 +440,16 @@ Snapshot *AcquireSnapshot(Client *client, Snapshot *src, u64 tick) return ss; } -void ReleaseSnapshot(Snapshot *ss) +void PP_ReleaseSnapshot(PP_Snapshot *ss) { - Client *client = ss->client; + PP_Client *client = ss->client; /* Remove from lookup */ { u64 bin_index = ss->tick % client->num_snapshot_lookup_bins; - SnapshotLookupBin *bin = &client->snapshot_lookup_bins[bin_index]; - Snapshot *prev = ss->prev_in_bin; - Snapshot *next = ss->next_in_bin; + PP_SnapshotLookupBin *bin = &client->snapshot_lookup_bins[bin_index]; + PP_Snapshot *prev = ss->prev_in_bin; + PP_Snapshot *next = ss->next_in_bin; if (prev) { prev->next_in_bin = next; @@ -470,8 +470,8 @@ void ReleaseSnapshot(Snapshot *ss) /* Remove from snapshot list */ { - Snapshot *prev = SnapshotFromTick(client, ss->prev_tick); - Snapshot *next = SnapshotFromTick(client, ss->next_tick); + PP_Snapshot *prev = PP_SnapshotFromTick(client, ss->prev_tick); + PP_Snapshot *next = PP_SnapshotFromTick(client, ss->next_tick); if (prev->valid) { prev->next_tick = next->tick; @@ -497,7 +497,7 @@ void ReleaseSnapshot(Snapshot *ss) } /* Release all snapshots for client with tick in range [start, end] */ -void ReleaseSnapshotsInRange(Client *client, u64 start, u64 end) +void PP_ReleaseSnapshotsInRange(PP_Client *client, u64 start, u64 end) { if (start > end) { @@ -506,7 +506,7 @@ void ReleaseSnapshotsInRange(Client *client, u64 start, u64 end) end = swp; } - Snapshot *ss = SnapshotFromTick(client, client->first_tick); + PP_Snapshot *ss = PP_SnapshotFromTick(client, client->first_tick); while (ss->valid) { u64 tick = ss->tick; @@ -515,28 +515,28 @@ void ReleaseSnapshotsInRange(Client *client, u64 start, u64 end) { if (tick <= end) { - ReleaseSnapshot(ss); + PP_ReleaseSnapshot(ss); } else { break; } } - ss = SnapshotFromTick(client, next_tick); + ss = PP_SnapshotFromTick(client, next_tick); } } //////////////////////////////////////////////////////////// //~ Snapshot lookup -Snapshot *SnapshotFromTick(Client *client, u64 tick) +PP_Snapshot *PP_SnapshotFromTick(PP_Client *client, u64 tick) { - Snapshot *ss = NilSnapshot(); + PP_Snapshot *ss = PP_NilSnapshot(); if (tick > 0) { u64 bin_index = tick % client->num_snapshot_lookup_bins; - SnapshotLookupBin *bin = &client->snapshot_lookup_bins[bin_index]; - for (Snapshot *search = bin->first; search; search = search->next_in_bin) + PP_SnapshotLookupBin *bin = &client->snapshot_lookup_bins[bin_index]; + for (PP_Snapshot *search = bin->first; search; search = search->next_in_bin) { if (search->tick == tick) { @@ -549,40 +549,40 @@ Snapshot *SnapshotFromTick(Client *client, u64 tick) } /* Returns the snapshot at nearest valid tick <= supplied tick */ -Snapshot *SnapshotFromClosestTickLte(Client *client, u64 tick) +PP_Snapshot *PP_SnapshotFromClosestTickLte(PP_Client *client, u64 tick) { - Snapshot *ss = SnapshotFromTick(client, tick); + PP_Snapshot *ss = PP_SnapshotFromTick(client, tick); if (!ss->valid) { /* Degenerate to linear search */ - ss = SnapshotFromTick(client, client->last_tick); + ss = PP_SnapshotFromTick(client, client->last_tick); while (ss->valid) { if (ss->tick <= tick) { break; } - ss = SnapshotFromTick(client, ss->prev_tick); + ss = PP_SnapshotFromTick(client, ss->prev_tick); } } return ss; } /* Returns the snapshot at nearest valid tick >= supplied tick */ -Snapshot *SnapshotFromClosestTickGte(Client *client, u64 tick) +PP_Snapshot *PP_SnapshotFromClosestTickGte(PP_Client *client, u64 tick) { - Snapshot *ss = SnapshotFromTick(client, tick); + PP_Snapshot *ss = PP_SnapshotFromTick(client, tick); if (!ss->valid) { /* Degenerate to linear search */ - ss = SnapshotFromTick(client, client->first_tick); + ss = PP_SnapshotFromTick(client, client->first_tick); while (ss->valid) { if (ss->tick >= tick) { break; } - ss = SnapshotFromTick(client, ss->next_tick); + ss = PP_SnapshotFromTick(client, ss->next_tick); } } return ss; @@ -591,7 +591,7 @@ Snapshot *SnapshotFromClosestTickGte(Client *client, u64 tick) //////////////////////////////////////////////////////////// //~ Tile -Vec2I32 WorldTileIndexFromPos(Vec2 pos) +Vec2I32 PP_WorldTileIndexFromPos(Vec2 pos) { Vec2I32 result = VEC2I32(pos.x * SIM_TILES_PER_UNIT_SQRT, pos.y * SIM_TILES_PER_UNIT_SQRT); result.x -= pos.x < 0; @@ -599,7 +599,7 @@ Vec2I32 WorldTileIndexFromPos(Vec2 pos) return result; } -Vec2 PosFromWorldTileIndex(Vec2I32 world_tile_index) +Vec2 PP_PosFromWorldTileIndex(Vec2I32 world_tile_index) { Vec2 result = ZI; f32 tile_size = 1.f / SIM_TILES_PER_UNIT_SQRT; @@ -608,7 +608,7 @@ Vec2 PosFromWorldTileIndex(Vec2I32 world_tile_index) return result; } -Vec2I32 LocalTileIndexFromWorldTileIndex(Vec2I32 world_tile_index) +Vec2I32 PP_LocalTileIndexFromWorldTileIndex(Vec2I32 world_tile_index) { Vec2I32 result = world_tile_index; result.x += result.x < 0; @@ -620,7 +620,7 @@ Vec2I32 LocalTileIndexFromWorldTileIndex(Vec2I32 world_tile_index) return result; } -Vec2I32 WorldTileIndexFromLocalTileIndex(Vec2I32 tile_chunk_index, Vec2I32 local_tile_index) +Vec2I32 PP_WorldTileIndexFromLocalTileIndex(Vec2I32 tile_chunk_index, Vec2I32 local_tile_index) { Vec2I32 result = ZI; result.x = (tile_chunk_index.x * SIM_TILES_PER_CHUNK_SQRT) + local_tile_index.x; @@ -628,7 +628,7 @@ Vec2I32 WorldTileIndexFromLocalTileIndex(Vec2I32 tile_chunk_index, Vec2I32 local return result; } -Vec2I32 TileChunkIndexFromWorldTileIndex(Vec2I32 world_tile_index) +Vec2I32 PP_TileChunkIndexFromWorldTileIndex(Vec2I32 world_tile_index) { Vec2I32 result = world_tile_index; result.x += result.x < 0; @@ -640,48 +640,48 @@ Vec2I32 TileChunkIndexFromWorldTileIndex(Vec2I32 world_tile_index) return result; } -void SetSnapshotTile(Snapshot *ss, Vec2I32 world_tile_index, TileKind tile_kind) +void PP_SetSnapshotTile(PP_Snapshot *ss, Vec2I32 world_tile_index, PP_TileKind tile_kind) { - Vec2I32 chunk_index = TileChunkIndexFromWorldTileIndex(world_tile_index); + Vec2I32 chunk_index = PP_TileChunkIndexFromWorldTileIndex(world_tile_index); - EntityId chunk_id = TileChunkIdFromIndex(chunk_index); - Entity *chunk_ent = EntityFromId(ss, chunk_id); + PP_EntKey chunk_id = PP_TileChunkKeyFromIndex(chunk_index); + PP_Ent *chunk_ent = PP_EntFromKey(ss, chunk_id); if (!chunk_ent->valid) { - Entity *root = EntityFromId(ss, RootEntityId); - chunk_ent = AcquireSyncSrcWithId(root, chunk_id); - EnableProp(chunk_ent, Prop_TileChunk); + PP_Ent *root = PP_EntFromKey(ss, PP_RootEntKey); + chunk_ent = PP_AcquireSyncSrcEntWithKey(root, chunk_id); + PP_EnableProp(chunk_ent, PP_Prop_TileChunk); chunk_ent->tile_chunk_index = chunk_index; } - Vec2I32 local_index = LocalTileIndexFromWorldTileIndex(world_tile_index); + Vec2I32 local_index = PP_LocalTileIndexFromWorldTileIndex(world_tile_index); chunk_ent->tile_chunk_tiles[local_index.x + (local_index.y * SIM_TILES_PER_CHUNK_SQRT)] = tile_kind; } //////////////////////////////////////////////////////////// //~ Snapshot lerp -Snapshot *AcquireSnapshotFromLerp(Client *client, Snapshot *ss0, Snapshot *ss1, f64 blend) +PP_Snapshot *PP_AcquireSnapshotFromLerp(PP_Client *client, PP_Snapshot *ss0, PP_Snapshot *ss1, f64 blend) { __prof; /* New snapshot will be allocated with same tick as ss0 or ss1, so the result should go into a different client */ Assert(ss0->client != client && ss1->client != client); - Snapshot *ss; + PP_Snapshot *ss; b32 should_blend = 1; if (ss0->continuity_gen == ss1->continuity_gen && 0 < blend && blend < 1) { - ss = AcquireSnapshot(client, ss0, ss0->tick); + ss = PP_AcquireSnapshot(client, ss0, ss0->tick); } else if (RoundF64ToI64(blend) <= 0) { - ss = AcquireSnapshot(client, ss0, ss0->tick); + ss = PP_AcquireSnapshot(client, ss0, ss0->tick); should_blend = 0; } else { - ss = AcquireSnapshot(client, ss1, ss1->tick); + ss = PP_AcquireSnapshot(client, ss1, ss1->tick); should_blend = 0; } @@ -704,10 +704,10 @@ Snapshot *AcquireSnapshotFromLerp(Client *client, Snapshot *ss0, Snapshot *ss1, u64 num_entities = MinU64(ss0->num_ents_reserved, ss1->num_ents_reserved); for (u64 i = 0; i < num_entities; ++i) { - Entity *e = &ss->ents[i]; - Entity *e0 = &ss0->ents[i]; - Entity *e1 = &ss1->ents[i]; - LerpEntity(e, e0, e1, blend); + PP_Ent *e = &ss->ents[i]; + PP_Ent *e0 = &ss0->ents[i]; + PP_Ent *e1 = &ss1->ents[i]; + PP_LerpEnt(e, e0, e1, blend); } } } @@ -719,7 +719,7 @@ Snapshot *AcquireSnapshotFromLerp(Client *client, Snapshot *ss0, Snapshot *ss1, //~ Snapshot sync /* Syncs entity data between snapshots */ -void SyncSnapshotEntities(Snapshot *local_ss, Snapshot *remote_ss, EntityId remote_player, u32 sync_flags) +void PP_SyncSnapshotEnts(PP_Snapshot *local_ss, PP_Snapshot *remote_ss, PP_EntKey remote_player, u32 sync_flags) { __prof; @@ -728,44 +728,44 @@ void SyncSnapshotEntities(Snapshot *local_ss, Snapshot *remote_ss, EntityId remo * - Determine new UUids for newly created ents */ - Entity *local_root = EntityFromId(local_ss, RootEntityId); - Entity *remote_root = EntityFromId(remote_ss, RootEntityId); + PP_Ent *local_root = PP_EntFromKey(local_ss, PP_RootEntKey); + PP_Ent *remote_root = PP_EntFromKey(remote_ss, PP_RootEntKey); /* Create new ents from remote */ - for (Entity *remote_top = EntityFromId(remote_ss, remote_root->first); remote_top->valid; remote_top = EntityFromId(remote_ss, remote_top->next)) + for (PP_Ent *remote_top = PP_EntFromKey(remote_ss, remote_root->first); remote_top->valid; remote_top = PP_EntFromKey(remote_ss, remote_top->next)) { - CreateMissingEntitiesFromSnapshots(local_root, remote_top, remote_player); + PP_CreateMissingEntsFromSnapshots(local_root, remote_top, remote_player); } /* Sync ents with remote, skipping index 0 (nil) & index 1 (root) */ for (u64 i = 2; i < local_ss->num_ents_reserved; ++i) { - Entity *local_ent = &local_ss->ents[i]; - if (local_ent->valid && HasProp(local_ent, Prop_SyncDst)) + PP_Ent *local_ent = &local_ss->ents[i]; + if (local_ent->valid && PP_HasProp(local_ent, PP_Prop_SyncDst)) { - b32 should_sync = EqId(local_ent->owner, remote_player) || IsNilId(remote_player); - if ((sync_flags & SyncFlag_NoSyncPredictables) && EqId(local_ent->predictor, local_ss->local_player)) + b32 should_sync = PP_EqEntKey(local_ent->owner, remote_player) || PP_IsNilEntKey(remote_player); + if ((sync_flags & PP_SyncFlag_NoSyncPredictables) && PP_EqEntKey(local_ent->predictor, local_ss->local_player)) { should_sync = 0; } if (should_sync) { - Entity *remote_ent = EntityFromId(remote_ss, local_ent->id); + PP_Ent *remote_ent = PP_EntFromKey(remote_ss, local_ent->id); if (remote_ent->valid) { /* Copy all ent data from remote */ - SyncEntity(local_ent, remote_ent); + PP_SyncEnt(local_ent, remote_ent); } else { /* Remote ent is no longer valid / networked, release it */ - EnableProp(local_ent, Prop_Release); - DisableProp(local_ent, Prop_SyncDst); + PP_EnableProp(local_ent, PP_Prop_Release); + PP_DisableProp(local_ent, PP_Prop_SyncDst); } } } } - ReleaseAllWithProp(local_ss, Prop_Release); + PP_ReleaseAllWithProp(local_ss, PP_Prop_Release); } @@ -785,7 +785,7 @@ void SyncSnapshotEntities(Snapshot *local_ss, Snapshot *remote_ss, EntityId remo //////////////////////////////////////////////////////////// //~ Snapshot encode -void EncodeSnapshot(BB_Writer *bw, Client *receiver, Snapshot *ss0, Snapshot *ss1) +void PP_EncodeSnapshot(BB_Writer *bw, PP_Client *receiver, PP_Snapshot *ss0, PP_Snapshot *ss1) { __prof; @@ -808,11 +808,11 @@ void EncodeSnapshot(BB_Writer *bw, Client *receiver, Snapshot *ss0, Snapshot *ss u32 old_last = 0; if (i < ss0->num_id_bins) { - EntBin *old_bin = &ss0->id_bins[i]; + PP_EntBin *old_bin = &ss0->id_bins[i]; old_first = old_bin->first; old_last = old_bin->last; } - EntBin *bin = &ss1->id_bins[i]; + PP_EntBin *bin = &ss1->id_bins[i]; b32 first_diff = bin->first != old_first; b32 last_diff = bin->last != old_last; if (first_diff || last_diff) @@ -847,13 +847,13 @@ void EncodeSnapshot(BB_Writer *bw, Client *receiver, Snapshot *ss0, Snapshot *ss for (u64 i = 1; i < ss1->num_ents_reserved; ++i) { - Entity *e0 = NilEntity(); + PP_Ent *e0 = PP_NilEnt(); if (i < ss0->num_ents_reserved) { e0 = &ss0->ents[i]; } - Entity *e1 = &ss1->ents[i]; - EncodeEntity(bw, e0, e1); + PP_Ent *e1 = &ss1->ents[i]; + PP_EncodeEnt(bw, e0, e1); } BB_WriteDebugMarker(bw, Lit("SNAPSHOT END")); @@ -862,7 +862,7 @@ void EncodeSnapshot(BB_Writer *bw, Client *receiver, Snapshot *ss0, Snapshot *ss //////////////////////////////////////////////////////////// //~ Snapshot decode -void DecodeSnapshot(BB_Reader *br, Snapshot *ss) +void PP_DecodeSnapshot(BB_Reader *br, PP_Snapshot *ss) { __prof; @@ -874,7 +874,7 @@ void DecodeSnapshot(BB_Reader *br, Snapshot *ss) ss->continuity_gen = BB_ReadUV(br); ss->phys_iteration = BB_ReadUV(br); - ss->local_player = (EntityId){ .uid = BB_ReadUid(br) }; + ss->local_player = (PP_EntKey){ .uid = BB_ReadUid(br) }; /* Id bins */ /* TODO: Don't decode these, determine them implicitly from decoded ents */ @@ -886,7 +886,7 @@ void DecodeSnapshot(BB_Reader *br, Snapshot *ss) u32 bin_index = BB_ReadUV(br); if (bin_index < ss->num_id_bins) { - EntBin *bin = &ss->id_bins[bin_index]; + PP_EntBin *bin = &ss->id_bins[bin_index]; if (BB_ReadBit(br)) { bin->first = BB_ReadUV(br); @@ -920,11 +920,11 @@ void DecodeSnapshot(BB_Reader *br, Snapshot *ss) i64 reserve_diff = (i64)ss->num_ents_reserved - (i64)old_num_ents_reserved; if (reserve_diff > 0) { - PushStructsNoZero(ss->ents_arena, Entity, reserve_diff); + PushStructsNoZero(ss->ents_arena, PP_Ent, reserve_diff); for (u64 i = old_num_ents_reserved; i < ss->num_ents_reserved; ++i) { - Entity *e = &ss->ents[i]; - *e = *NilEntity(); + PP_Ent *e = &ss->ents[i]; + *e = *PP_NilEnt(); e->ss = ss; } } @@ -940,9 +940,9 @@ void DecodeSnapshot(BB_Reader *br, Snapshot *ss) BB_ReadDebugMarker(br, StringFromStruct(&ss->num_ents_reserved)); for (u64 i = 1; i < ss->num_ents_reserved; ++i) { - Entity *e = &ss->ents[i]; + PP_Ent *e = &ss->ents[i]; e->ss = ss; - DecodeEntity(br, e); + PP_DecodeEnt(br, e); } BB_ReadDebugMarker(br, Lit("SNAPSHOT END")); @@ -954,7 +954,7 @@ void DecodeSnapshot(BB_Reader *br, Snapshot *ss) //////////////////////////////////////////////////////////// //~ Snapshot encode -void EncodeSnapshot(BB_Writer *bw, Client *receiver, Snapshot *ss0, Snapshot *ss1) +void PP_EncodeSnapshot(BB_Writer *bw, PP_Client *receiver, PP_Snapshot *ss0, PP_Snapshot *ss1) { __prof; @@ -993,7 +993,7 @@ void EncodeSnapshot(BB_Writer *bw, Client *receiver, Snapshot *ss0, Snapshot *ss BB_AlignWriter(bw); for (u64 i = 0; i < ss1->num_ents_reserved; ++i) { - Entity *e0 = NilEntity(); + PP_Ent *e0 = PP_NilEnt(); if (i < ss0->num_ents_reserved) { e0 = &ss0->ents[i]; @@ -1015,8 +1015,8 @@ void EncodeSnapshot(BB_Writer *bw, Client *receiver, Snapshot *ss0, Snapshot *ss if (e1->valid) { - Entity *e1 = &ss1->ents[i]; - EncodeEntity(bw, e0, e1); + PP_Ent *e1 = &ss1->ents[i]; + PP_EncodeEnt(bw, e0, e1); } } } @@ -1035,7 +1035,7 @@ struct sim_ent_decode_queue struct sim_ent_decode_node *last; }; -void DecodeSnapshot(BB_Reader *br, Snapshot *ss) +void PP_DecodeSnapshot(BB_Reader *br, PP_Snapshot *ss) { __prof; TempArena scratch = BeginScratchNoConflict(); @@ -1046,7 +1046,7 @@ void DecodeSnapshot(BB_Reader *br, Snapshot *ss) ss->continuity_gen = BB_ReadUV(br); ss->phys_iteration = BB_ReadUV(br); - ss->local_player = (EntityId){ .uid = BB_ReadUid(br) }; + ss->local_player = (PP_EntKey){ .uid = BB_ReadUid(br) }; #if 1 @@ -1061,11 +1061,11 @@ void DecodeSnapshot(BB_Reader *br, Snapshot *ss) i64 reserve_diff = (i64)ss->num_ents_reserved - (i64)old_num_ents_reserved; if (reserve_diff > 0) { - PushStructsNoZero(ss->ents_arena, Entity, reserve_diff); + PushStructsNoZero(ss->ents_arena, PP_Ent, reserve_diff); for (u64 i = old_num_ents_reserved; i < ss->num_ents_reserved; ++i) { - Entity *e = &ss->ents[i]; - *e = *NilEntity(); + PP_Ent *e = &ss->ents[i]; + *e = *PP_NilEnt(); e->ss = ss; } } @@ -1082,17 +1082,17 @@ void DecodeSnapshot(BB_Reader *br, Snapshot *ss) b32 released = 0; u32 alloc_parent_index = ZI; - EntityId alloc_ent_id = ZI; + PP_EntKey alloc_ent_id = ZI; if (allocation_changed) { released = BB_ReadBit(br); if (released) { - Entity *e = sim_ent_from_index(ss, e); + PP_Ent *e = sim_ent_from_index(ss, e); Assert(e->valid); /* An entity that we don't have allocated should never have been marked for release */ if (e->valid) { - EnableProp(e, Prop_Release); + PP_EnableProp(e, PP_Prop_Release); } } else @@ -1135,14 +1135,14 @@ void DecodeSnapshot(BB_Reader *br, Snapshot *ss) if (n->is_new) { u32 index = n->index; - Entity *parent = sim_ent_from_index(ss, n->alloc_parent_index); - Assert(!sim_ent_from_index(ss, index)->valid && !EntityFromId(ss, alloc_ent_id)->valid); /* An entity that we have allocated already should never be marked for allocation */ + PP_Ent *parent = sim_ent_from_index(ss, n->alloc_parent_index); + Assert(!sim_ent_from_index(ss, index)->valid && !PP_EntFromKey(ss, alloc_ent_id)->valid); /* An entity that we have allocated already should never be marked for allocation */ Assert(parent->valid); /* Parent for new entity allocation should always be valid */ if (parent->valid && index < ss->num_ents_reserved) { - Entity *ent = &ss->ents[index]; + PP_Ent *ent = &ss->ents[index]; ent->valid = 1; - SetEntityId(ent, n->alloc_ent_id); + PP_SetEntKey(ent, n->alloc_ent_id); Link(parent, ent); } else @@ -1158,10 +1158,10 @@ void DecodeSnapshot(BB_Reader *br, Snapshot *ss) { BB_Reader ent_br = n->br; u32 index = n->index; - Entity *e = sim_ent_from_index(ss, index); + PP_Ent *e = sim_ent_from_index(ss, index); if (e->valid) { - DecodeEntity(&ent_br, e); + PP_DecodeEnt(&ent_br, e); } else { @@ -1182,11 +1182,11 @@ void DecodeSnapshot(BB_Reader *br, Snapshot *ss) i64 reserve_diff = (i64)ss->num_ents_reserved - (i64)old_num_ents_reserved; if (reserve_diff > 0) { - PushStructsNoZero(ss->ents_arena, Entity, reserve_diff); + PushStructsNoZero(ss->ents_arena, PP_Ent, reserve_diff); for (u64 i = old_num_ents_reserved; i < ss->num_ents_reserved; ++i) { - Entity *e = &ss->ents[i]; - *e = *NilEntity(); + PP_Ent *e = &ss->ents[i]; + *e = *PP_NilEnt(); e->ss = ss; } } @@ -1203,14 +1203,14 @@ void DecodeSnapshot(BB_Reader *br, Snapshot *ss) } else { - EnableProp(e, Prop_Release); + PP_EnableProp(e, PP_Prop_Release); } } } for (u64 i = 0; i < ss->num_ents_reserved; ++i) { - Entity *e = &ss->ents[i]; + PP_Ent *e = &ss->ents[i]; e->ss = ss; b32 valid_changed = BB_ReadBit(br); @@ -1226,15 +1226,15 @@ void DecodeSnapshot(BB_Reader *br, Snapshot *ss) Assert(e->valid); if (e->valid) { - EnableProp(e, Prop_Release); + PP_EnableProp(e, PP_Prop_Release); } } else { - DecodeEntity(br, e); + PP_DecodeEnt(br, e); } } - ReleaseAllWithProp(ss, Prop_Release); + PP_ReleaseAllWithProp(ss, PP_Prop_Release); #endif EndScratch(scratch); diff --git a/src/pp/pp_sim.h b/src/pp/pp_sim.h index 8d17249c..96319907 100644 --- a/src/pp/pp_sim.h +++ b/src/pp/pp_sim.h @@ -1,66 +1,66 @@ //////////////////////////////////////////////////////////// -//~ Id types +//~ Key types -Struct(EntityId) +Struct(PP_EntKey) { Uid uid; }; -Struct(ClientHandle) +Struct(PP_ClientKey) { u32 idx; u32 gen; }; -#define NilClientHandle ((ClientHandle) { .gen = 0, .idx = 0 }) +#define PP_NilClientHandle ((PP_ClientKey) { .gen = 0, .idx = 0 }) //////////////////////////////////////////////////////////// //~ Client store types -Struct(ClientLookupBin) +Struct(PP_ClientLookupBin) { - struct ClientHandle first; - struct ClientHandle last; + PP_ClientKey first; + PP_ClientKey last; }; -Struct(ClientStore) +Struct(PP_ClientStore) { b32 valid; Arena *arena; /* Client lookup */ - ClientLookupBin *client_lookup_bins; + PP_ClientLookupBin *client_lookup_bins; u64 num_client_lookup_bins; /* Clients */ Arena *clients_arena; - struct Client *clients; - ClientHandle first_free_client; + struct PP_Client *clients; + PP_ClientKey first_free_client; u64 num_clients_allocated; u64 num_clients_reserved; }; -Inline ClientStore *sim_client_store_nil(void) +Inline PP_ClientStore *PP_NilClientStore(void) { - extern Readonly ClientStore **_g_sim_client_store_nil; - return *_g_sim_client_store_nil; + extern Readonly PP_ClientStore **PP_nil_client_store; + return *PP_nil_client_store; } //////////////////////////////////////////////////////////// //~ Client types -Struct(SnapshotLookupBin) +Struct(PP_SnapshotLookupBin) { - struct Snapshot *first; - struct Snapshot *last; + struct PP_Snapshot *first; + struct PP_Snapshot *last; }; -Struct(Client) +Struct(PP_Client) { b32 valid; - ClientHandle handle; - ClientStore *store; + PP_ClientKey handle; + PP_ClientStore *store; Arena *snapshots_arena; @@ -70,12 +70,12 @@ Struct(Client) N_ChannelId channel_id; u64 channel_hash; - ClientHandle next_free; - ClientHandle next_in_bin; - ClientHandle prev_in_bin; + PP_ClientKey next_free; + PP_ClientKey next_in_bin; + PP_ClientKey prev_in_bin; /* The client's player entity id in the master sim (if relevant) */ - EntityId player_id; + PP_EntKey player_id; /* This is the highest confirmed tick of ours that we know this client has received */ u64 ack; @@ -92,20 +92,20 @@ Struct(Client) u64 first_tick; u64 last_tick; u64 num_ticks; - struct Snapshot *first_free_snapshot; + struct PP_Snapshot *first_free_snapshot; /* Tick -> snapshot lookup */ u64 num_snapshot_lookup_bins; - SnapshotLookupBin *snapshot_lookup_bins; + PP_SnapshotLookupBin *snapshot_lookup_bins; }; -Inline Client *NilClient(void) +Inline PP_Client *PP_NilClient(void) { - extern Readonly Client **_g_sim_client_nil; - return *_g_sim_client_nil; + extern Readonly PP_Client **PP_nil_client; + return *PP_nil_client; } -Inline b32 EqClientHandle(ClientHandle a, ClientHandle b) +Inline b32 PP_EqClientKey(PP_ClientKey a, PP_ClientKey b) { return a.gen == b.gen && a.idx == b.idx; } @@ -114,82 +114,82 @@ Inline b32 EqClientHandle(ClientHandle a, ClientHandle b) //~ Layer types /* Absolute layers */ -#define Layer_FloorDecals (-300) -#define Layer_Bullets (-200) -#define Layer_Tracers (-100) -#define Layer_Shoulders (0) -#define Layer_Walls (100) +#define PP_Layer_FloorDecals (-300) +#define PP_Layer_Bullets (-200) +#define PP_Layer_Tracers (-100) +#define PP_Layer_Shoulders (0) +#define PP_Layer_Walls (100) /* Relative layers */ -#define Layer_DefaultRelative (0) -#define Layer_RelativeWeapon (1) +#define PP_Layer_DefaultRelative (0) +#define PP_Layer_RelativeWeapon (1) //////////////////////////////////////////////////////////// //~ Control types -Enum(ControlFlag) +Enum(PP_ControlFlag) { - ControlFlag_Fire = 1 << 0, - ControlFlag_AltFire = 1 << 1, + PP_ControlFlag_Fire = 1 << 0, + PP_ControlFlag_AltFire = 1 << 1, /* Testing */ - ControlFlag_Drag = 1 << 2, - ControlFlag_Delete = 1 << 3, - ControlFlag_ClearAll = 1 << 4, - ControlFlag_SpawnTest1 = 1 << 5, - ControlFlag_SpawnTest2 = 1 << 6, - ControlFlag_SpawnTest3 = 1 << 7, - ControlFlag_SpawnTest4 = 1 << 8, - ControlFlag_TestWalls = 1 << 9, - ControlFlag_TestTiles = 1 << 10, - ControlFlag_TestExplode = 1 << 11, - ControlFlag_TestTeleport = 1 << 12, + PP_ControlFlag_Drag = 1 << 2, + PP_ControlFlag_Delete = 1 << 3, + PP_ControlFlag_ClearAll = 1 << 4, + PP_ControlFlag_SpawnTest1 = 1 << 5, + PP_ControlFlag_SpawnTest2 = 1 << 6, + PP_ControlFlag_SpawnTest3 = 1 << 7, + PP_ControlFlag_SpawnTest4 = 1 << 8, + PP_ControlFlag_TestWalls = 1 << 9, + PP_ControlFlag_TestTiles = 1 << 10, + PP_ControlFlag_TestExplode = 1 << 11, + PP_ControlFlag_TestTeleport = 1 << 12, }; -Struct(ControlData) +Struct(PP_ControlData) { Vec2 move; /* Movement direction vector (speed of 0 -> 1) */ Vec2 focus; /* Focus direction vector (where does the controller want to look) */ Vec2 dbg_cursor; /* Where is the user's cursor in the world (used for things like editing the world) */ - ControlFlag flags; + PP_ControlFlag flags; }; -Enum(CmdKind) +Enum(PP_CmdKind) { - CmdKind_Invalid, + PP_CmdKind_Invalid, - CmdKind_Control, - CmdKind_Chat + PP_CmdKind_Control, + PP_CmdKind_Chat }; //////////////////////////////////////////////////////////// //~ Tile types -Enum(TileKind) +Enum(PP_TileKind) { - TileKind_None, - TileKind_Wall, + PP_TileKind_None, + PP_TileKind_Wall, - TileKind_Count + PP_TileKind_Count }; -StaticAssert(TileKind_Count < 256); /* Tile kind must fit in 8 bits */ +StaticAssert(PP_TileKind_Count < 256); /* Tile kind must fit in 8 bits */ //////////////////////////////////////////////////////////// //~ Snapshot types -Enum(SyncFlag) +Enum(PP_SyncFlag) { - SyncFlag_NoSyncPredictables = 1 << 0 + PP_SyncFlag_NoSyncPredictables = 1 << 0 }; -Struct(Snapshot) +Struct(PP_Snapshot) { b32 valid; u64 tick; - Client *client; - Snapshot *next_free; - Snapshot *next_in_bin; - Snapshot *prev_in_bin; + PP_Client *client; + PP_Snapshot *next_free; + PP_Snapshot *next_in_bin; + PP_Snapshot *prev_in_bin; u64 prev_tick; u64 next_tick; @@ -206,119 +206,117 @@ Struct(Snapshot) u64 phys_iteration; /* The id of the receiver's player in the snapshot */ - EntityId local_player; + PP_EntKey local_player; /* Id lookup */ - struct EntBin *id_bins; + struct PP_EntBin *id_bins; u64 num_id_bins; - /* Entities */ + /* Ents */ Arena *ents_arena; - struct Entity *ents; + struct PP_Ent *ents; u32 first_free_ent; u32 num_ents_allocated; u32 num_ents_reserved; }; -Inline Snapshot *NilSnapshot(void) +Inline PP_Snapshot *PP_NilSnapshot(void) { - extern Readonly Snapshot **_g_sim_snapshot_nil; - return *_g_sim_snapshot_nil; + extern Readonly PP_Snapshot **PP_nil_snapshot; + return *PP_nil_snapshot; } //////////////////////////////////////////////////////////// //~ State types -#define ClientLookupBinsCount 127 -#define TickLookupBinsCount 127 -#define IdLookupBinsCount 4096 +#define PP_ClientLookupBinsCount 127 +#define PP_TickLookupBinsCount 127 +#define PP_IdLookupBinsCount 4096 -Struct(SharedSimCtx) +Struct(PP_SharedSimCtx) { Arena *nil_arena; - ClientStore *nil_client_store; - Client *nil_client; - Snapshot *nil_snapshot; - struct Entity *nil_ent; -}; + PP_ClientStore *nil_client_store; + PP_Client *nil_client; + PP_Snapshot *nil_snapshot; + struct PP_Ent *nil_ent; +} extern PP_shared_sim_ctx; -extern SharedSimCtx shared_sim_ctx; +/* Accessed via `PP_NilClientStore()` */ +extern Readonly PP_ClientStore **PP_nil_client_store; -/* Accessed via `sim_client_store_nil()` */ -extern Readonly ClientStore **_g_sim_client_store_nil; - -/* Accessed via `NilClient()` */ -extern Readonly Client **_g_sim_client_nil; +/* Accessed via `PP_NilClient()` */ +extern Readonly PP_Client **PP_nil_client; /* Accessed via `NilSnapshot()` */ -extern Readonly Snapshot **_g_sim_snapshot_nil; -extern Readonly struct Entity **_g_sim_ent_nil; +extern Readonly PP_Snapshot **PP_nil_snapshot; +extern Readonly struct PP_Ent **PP_nil_ent; //////////////////////////////////////////////////////////// //~ Startup -void StartupSim(void); +void PP_StartupSim(void); //////////////////////////////////////////////////////////// //~ Client store acquire operations -ClientStore *AcquireClientStore(void); -void ReleaseClientStore(ClientStore *store); +PP_ClientStore *PP_AcquireClientStore(void); +void PP_ReleaseClientStore(PP_ClientStore *store); //////////////////////////////////////////////////////////// //~ Client acquire operations -Client *AcquireClient(ClientStore *store); -void ReleaseClient(Client *client); +PP_Client *PP_AcquireClient(PP_ClientStore *store); +void PP_ReleaseClient(PP_Client *client); //////////////////////////////////////////////////////////// //~ Client lookup operations -u64 ClientChannelHashFromChannelId(N_ChannelId channel_id); -void SetClientChannelId(Client *client, N_ChannelId channel_id); -Client *ClientFromChannelId(ClientStore *store, N_ChannelId channel_id); -Client *ClientFromHandle(ClientStore *store, ClientHandle handle); +u64 PP_ClientChannelHashFromChannelId(N_ChannelId channel_id); +void PP_SetClientChannelId(PP_Client *client, N_ChannelId channel_id); +PP_Client *PP_ClientFromChannelId(PP_ClientStore *store, N_ChannelId channel_id); +PP_Client *PP_ClientFromKey(PP_ClientStore *store, PP_ClientKey handle); //////////////////////////////////////////////////////////// //~ Snapshot acquire operations -Snapshot *AcquireSnapshot(Client *client, Snapshot *src, u64 tick); -void ReleaseSnapshot(Snapshot *ss); -void ReleaseSnapshotsInRange(Client *client, u64 start, u64 end); +PP_Snapshot *PP_AcquireSnapshot(PP_Client *client, PP_Snapshot *src, u64 tick); +void PP_ReleaseSnapshot(PP_Snapshot *ss); +void PP_ReleaseSnapshotsInRange(PP_Client *client, u64 start, u64 end); //////////////////////////////////////////////////////////// //~ Snapshot lookup operations -Snapshot *SnapshotFromTick(Client *client, u64 tick); -Snapshot *SnapshotFromClosestTickLte(Client *client, u64 tick); -Snapshot *SnapshotFromClosestTickGte(Client *client, u64 tick); +PP_Snapshot *PP_SnapshotFromTick(PP_Client *client, u64 tick); +PP_Snapshot *PP_SnapshotFromClosestTickLte(PP_Client *client, u64 tick); +PP_Snapshot *PP_SnapshotFromClosestTickGte(PP_Client *client, u64 tick); //////////////////////////////////////////////////////////// //~ Tile operations -Vec2I32 WorldTileIndexFromPos(Vec2 pos); -Vec2 PosFromWorldTileIndex(Vec2I32 world_tile_index); -Vec2I32 LocalTileIndexFromWorldTileIndex(Vec2I32 world_tile_index); -Vec2I32 WorldTileIndexFromLocalTileIndex(Vec2I32 tile_chunk_index, Vec2I32 local_tile_index); -Vec2I32 TileChunkIndexFromWorldTileIndex(Vec2I32 world_tile_index); -void SetSnapshotTile(Snapshot *ss, Vec2I32 world_tile_index, TileKind tile_kind); +Vec2I32 PP_WorldTileIndexFromPos(Vec2 pos); +Vec2 PP_PosFromWorldTileIndex(Vec2I32 world_tile_index); +Vec2I32 PP_LocalTileIndexFromWorldTileIndex(Vec2I32 world_tile_index); +Vec2I32 PP_WorldTileIndexFromLocalTileIndex(Vec2I32 tile_chunk_index, Vec2I32 local_tile_index); +Vec2I32 PP_TileChunkIndexFromWorldTileIndex(Vec2I32 world_tile_index); +void PP_SetSnapshotTile(PP_Snapshot *ss, Vec2I32 world_tile_index, PP_TileKind tile_kind); //////////////////////////////////////////////////////////// //~ Snapshot lerp operations -Snapshot *AcquireSnapshotFromLerp(Client *client, Snapshot *ss0, Snapshot *ss1, f64 blend); +PP_Snapshot *PP_AcquireSnapshotFromLerp(PP_Client *client, PP_Snapshot *ss0, PP_Snapshot *ss1, f64 blend); //////////////////////////////////////////////////////////// //~ Snapshot sync operations -void SyncSnapshotEntities(Snapshot *local_ss, Snapshot *remote_ss, EntityId remote_player, u32 sync_flags); +void PP_SyncSnapshotEnts(PP_Snapshot *local_ss, PP_Snapshot *remote_ss, PP_EntKey remote_player, u32 sync_flags); //////////////////////////////////////////////////////////// //~ Snapshot encode operations -void EncodeSnapshot(BB_Writer *bw, Client *receiver, Snapshot *ss0, Snapshot *ss1); +void PP_EncodeSnapshot(BB_Writer *bw, PP_Client *receiver, PP_Snapshot *ss0, PP_Snapshot *ss1); //////////////////////////////////////////////////////////// //~ Snapshot decode operations -void DecodeSnapshot(BB_Reader *br, Snapshot *ss); +void PP_DecodeSnapshot(BB_Reader *br, PP_Snapshot *ss); diff --git a/src/pp/pp_space.c b/src/pp/pp_space.c index e21b487b..a71892eb 100644 --- a/src/pp/pp_space.c +++ b/src/pp/pp_space.c @@ -1,8 +1,8 @@ /* FIXME: Default space entry & cell pointers to nil */ -Readonly SpaceEntry _g_space_entry_nil = ZI; -Readonly SpaceCell _g_space_cell_nil = ZI; -Readonly Space _g_space_nil = ZI; +Readonly PP_SpaceEntry PP_nil_space_entry = ZI; +Readonly PP_SpaceCell PP_nil_space_cell = ZI; +Readonly PP_Space PP_nil_space = ZI; //////////////////////////////////////////////////////////// //~ Space @@ -10,63 +10,63 @@ Readonly Space _g_space_nil = ZI; /* NOTE: * The number of bins determines how often tiles will collide in the spatial hash. * For example, at `num_bins_sqrt` = 256 (65536 bins), tiles <1, 1>, <1, 257>, and <257, 257> will collide. */ -Space *AcquireSpace(f32 cell_size, u32 num_bins_sqrt) +PP_Space *PP_AcquireSpace(f32 cell_size, u32 num_bins_sqrt) { - Space *space; + PP_Space *space; { Arena *arena = AcquireArena(Gibi(64)); - space = PushStruct(arena, Space); + space = PushStruct(arena, PP_Space); space->entry_arena = arena; } space->valid = 1; - space->entries = PushDry(space->entry_arena, SpaceEntry); + space->entries = PushDry(space->entry_arena, PP_SpaceEntry); space->cell_arena = AcquireArena(Gibi(64)); space->cell_size = cell_size; space->num_bins = num_bins_sqrt * num_bins_sqrt; space->num_bins_sqrt = num_bins_sqrt; - space->bins = PushStructs(space->cell_arena, SpaceCellBin, space->num_bins); + space->bins = PushStructs(space->cell_arena, PP_SpaceCellBin, space->num_bins); return space; } -void ReleaseSpace(Space *space) +void PP_ReleaseSpace(PP_Space *space) { ReleaseArena(space->cell_arena); ReleaseArena(space->entry_arena); } -void ResetSpace(Space *space) +void PP_ResetSpace(PP_Space *space) { PopTo(space->entry_arena, (u64)space->entries - (u64)ArenaBase(space->entry_arena)); ResetArena(space->cell_arena); - space->bins = PushStructs(space->cell_arena, SpaceCellBin, space->num_bins); + space->bins = PushStructs(space->cell_arena, PP_SpaceCellBin, space->num_bins); space->num_entries_reserved = 0; space->first_free_cell = 0; space->first_free_cell_node = 0; space->first_free_entry = 0; } -Space *SpaceFromEntry(SpaceEntry *entry) +PP_Space *PP_SpaceFromEntry(PP_SpaceEntry *entry) { if (entry->valid) { u64 first_entry_addr = (u64)(entry - entry->handle.idx); - Space *space = (Space *)(first_entry_addr - SpaceEntriesOffset); - Assert(space->entries == (SpaceEntry *)first_entry_addr); + PP_Space *space = (PP_Space *)(first_entry_addr - PP_SpaceEntriesOffset); + Assert(space->entries == (PP_SpaceEntry *)first_entry_addr); return space; } else { - return NilSpace(); + return PP_NilSpace(); } } //////////////////////////////////////////////////////////// //~ Cell -Vec2I32 SpaceCellCoordsFromWorldCoords(f32 cell_size, Vec2 world_pos) +Vec2I32 PP_SpaceCellCoordsFromWorldCoords(f32 cell_size, Vec2 world_pos) { f32 x = world_pos.x; f32 y = world_pos.y; @@ -75,7 +75,7 @@ Vec2I32 SpaceCellCoordsFromWorldCoords(f32 cell_size, Vec2 world_pos) return VEC2I32((i32)x, (i32)y); } -i32 SpaceBinIndexFromCellCoords(Space *space, Vec2I32 cell_pos) +i32 PP_SpaceBinIndexFromCellCoords(PP_Space *space, Vec2I32 cell_pos) { i32 num_bins_sqrt = space->num_bins_sqrt; @@ -97,12 +97,12 @@ i32 SpaceBinIndexFromCellCoords(Space *space, Vec2I32 cell_pos) return bin_index; } -SpaceCell *SpaceCellFromCellPos(Space *space, Vec2I32 cell_pos) +PP_SpaceCell *PP_SpaceCellFromCellPos(PP_Space *space, Vec2I32 cell_pos) { - i32 bin_index = SpaceBinIndexFromCellCoords(space, cell_pos); - SpaceCellBin *bin = &space->bins[bin_index]; - SpaceCell *result = NilSpaceCell(); - for (SpaceCell *n = bin->first_cell; n; n = n->next_in_bin) + i32 bin_index = PP_SpaceBinIndexFromCellCoords(space, cell_pos); + PP_SpaceCellBin *bin = &space->bins[bin_index]; + PP_SpaceCell *result = PP_NilSpaceCell(); + for (PP_SpaceCell *n = bin->first_cell; n; n = n->next_in_bin) { if (EqVec2I32(n->pos, cell_pos)) { @@ -113,15 +113,15 @@ SpaceCell *SpaceCellFromCellPos(Space *space, Vec2I32 cell_pos) return result; } -void AcquireSpaceCellNode(Vec2I32 cell_pos, SpaceEntry *entry) +void PP_AcquireSpaceCellNode(Vec2I32 cell_pos, PP_SpaceEntry *entry) { - Space *space = SpaceFromEntry(entry); - i32 bin_index = SpaceBinIndexFromCellCoords(space, cell_pos); - SpaceCellBin *bin = &space->bins[bin_index]; + PP_Space *space = PP_SpaceFromEntry(entry); + i32 bin_index = PP_SpaceBinIndexFromCellCoords(space, cell_pos); + PP_SpaceCellBin *bin = &space->bins[bin_index]; /* Find existing cell */ - SpaceCell *cell = 0; - for (SpaceCell *n = bin->first_cell; n; n = n->next_in_bin) + PP_SpaceCell *cell = 0; + for (PP_SpaceCell *n = bin->first_cell; n; n = n->next_in_bin) { if (EqVec2I32(n->pos, cell_pos)) { @@ -140,7 +140,7 @@ void AcquireSpaceCellNode(Vec2I32 cell_pos, SpaceEntry *entry) } else { - cell = PushStructNoZero(space->cell_arena, SpaceCell); + cell = PushStructNoZero(space->cell_arena, PP_SpaceCell); } ZeroStruct(cell); if (bin->last_cell) @@ -159,7 +159,7 @@ void AcquireSpaceCellNode(Vec2I32 cell_pos, SpaceEntry *entry) } /* Acquire node */ - SpaceCellNode *node; + PP_SpaceCellNode *node; { if (space->first_free_cell_node) { @@ -168,7 +168,7 @@ void AcquireSpaceCellNode(Vec2I32 cell_pos, SpaceEntry *entry) } else { - node = PushStructNoZero(space->cell_arena, SpaceCellNode); + node = PushStructNoZero(space->cell_arena, PP_SpaceCellNode); } ZeroStruct(node); } @@ -200,17 +200,17 @@ void AcquireSpaceCellNode(Vec2I32 cell_pos, SpaceEntry *entry) entry->last_node = node; } -void ReleaseSpaceCellNode(SpaceCellNode *n) +void PP_ReleaseSpaceCellNode(PP_SpaceCellNode *n) { - SpaceCell *cell = n->cell; - SpaceEntry *entry = n->entry; - Space *space = SpaceFromEntry(entry); - SpaceCellBin *bin = cell->bin; + PP_SpaceCell *cell = n->cell; + PP_SpaceEntry *entry = n->entry; + PP_Space *space = PP_SpaceFromEntry(entry); + PP_SpaceCellBin *bin = cell->bin; /* Remove from entry list */ { - SpaceCellNode *prev = n->prev_in_entry; - SpaceCellNode *next = n->next_in_entry; + PP_SpaceCellNode *prev = n->prev_in_entry; + PP_SpaceCellNode *next = n->next_in_entry; if (prev) { prev->next_in_entry = next; @@ -231,8 +231,8 @@ void ReleaseSpaceCellNode(SpaceCellNode *n) /* Remove from cell list */ { - SpaceCellNode *prev = n->prev_in_cell; - SpaceCellNode *next = n->next_in_cell; + PP_SpaceCellNode *prev = n->prev_in_cell; + PP_SpaceCellNode *next = n->next_in_cell; if (prev) { prev->next_in_cell = next; @@ -255,8 +255,8 @@ void ReleaseSpaceCellNode(SpaceCellNode *n) if (!cell->first_node && !cell->last_node) { /* Remove from bin */ - SpaceCell *prev = cell->prev_in_bin; - SpaceCell *next = cell->next_in_bin; + PP_SpaceCell *prev = cell->prev_in_bin; + PP_SpaceCell *next = cell->next_in_bin; if (prev) { prev->next_in_bin = next; @@ -288,13 +288,13 @@ void ReleaseSpaceCellNode(SpaceCellNode *n) //////////////////////////////////////////////////////////// //~ Entry -SpaceEntry *SpaceEntryFromHandle(Space *space, SpaceEntryHandle handle) +PP_SpaceEntry *PP_SpaceEntryFromKey(PP_Space *space, PP_SpaceEntryKey handle) { - SpaceEntry *entry = NilSpaceEntry(); + PP_SpaceEntry *entry = PP_NilSpaceEntry(); if (handle.gen > 0 && handle.idx < space->num_entries_reserved) { - SpaceEntry *tmp = &space->entries[handle.idx]; + PP_SpaceEntry *tmp = &space->entries[handle.idx]; if (tmp->handle.gen == handle.gen) { entry = tmp; @@ -304,10 +304,10 @@ SpaceEntry *SpaceEntryFromHandle(Space *space, SpaceEntryHandle handle) return entry; } -SpaceEntry *AcquireSpaceEntry(Space *space, EntityId ent) +PP_SpaceEntry *PP_AcquireSpaceEntry(PP_Space *space, PP_EntKey ent) { - SpaceEntry *entry = 0; - SpaceEntryHandle handle = ZI; + PP_SpaceEntry *entry = 0; + PP_SpaceEntryKey handle = ZI; if (space->first_free_entry) { entry = space->first_free_entry; @@ -316,7 +316,7 @@ SpaceEntry *AcquireSpaceEntry(Space *space, EntityId ent) } else { - entry = PushStructNoZero(space->entry_arena, SpaceEntry); + entry = PushStructNoZero(space->entry_arena, PP_SpaceEntry); handle.idx = space->num_entries_reserved; handle.gen = 1; ++space->num_entries_reserved; @@ -328,28 +328,28 @@ SpaceEntry *AcquireSpaceEntry(Space *space, EntityId ent) return entry; } -void ReleaseSpaceEntry(SpaceEntry *entry) +void PP_ReleaseSpaceEntry(PP_SpaceEntry *entry) { /* Release nodes */ - SpaceCellNode *n = entry->first_node; + PP_SpaceCellNode *n = entry->first_node; while (n) { - SpaceCellNode *next = n->next_in_entry; + PP_SpaceCellNode *next = n->next_in_entry; /* TODO: More efficient batch release that doesn't care about maintaining entry list */ - ReleaseSpaceCellNode(n); + PP_ReleaseSpaceCellNode(n); n = next; } - Space *space = SpaceFromEntry(entry); + PP_Space *space = PP_SpaceFromEntry(entry); entry->next_free = space->first_free_entry; entry->valid = 0; ++entry->handle.gen; space->first_free_entry = entry; } -void UpdateSpaceEntryAabb(SpaceEntry *entry, Aabb new_aabb) +void PP_UpdateSpaceEntryAabb(PP_SpaceEntry *entry, Aabb new_aabb) { - Space *space = SpaceFromEntry(entry); + PP_Space *space = PP_SpaceFromEntry(entry); f32 cell_size = space->cell_size; Vec2I32 old_cell_p0 = VEC2I32(0, 0); @@ -357,24 +357,24 @@ void UpdateSpaceEntryAabb(SpaceEntry *entry, Aabb new_aabb) if (entry->first_node) { Aabb old_aabb = entry->aabb; - old_cell_p0 = SpaceCellCoordsFromWorldCoords(cell_size, old_aabb.p0); - old_cell_p1 = SpaceCellCoordsFromWorldCoords(cell_size, old_aabb.p1); + old_cell_p0 = PP_SpaceCellCoordsFromWorldCoords(cell_size, old_aabb.p0); + old_cell_p1 = PP_SpaceCellCoordsFromWorldCoords(cell_size, old_aabb.p1); } - Vec2I32 new_cell_p0 = SpaceCellCoordsFromWorldCoords(cell_size, new_aabb.p0); - Vec2I32 new_cell_p1 = SpaceCellCoordsFromWorldCoords(cell_size, new_aabb.p1); + Vec2I32 new_cell_p0 = PP_SpaceCellCoordsFromWorldCoords(cell_size, new_aabb.p0); + Vec2I32 new_cell_p1 = PP_SpaceCellCoordsFromWorldCoords(cell_size, new_aabb.p1); /* Release outdated nodes */ - SpaceCellNode *n = entry->first_node; + PP_SpaceCellNode *n = entry->first_node; while (n) { - SpaceCell *cell = n->cell; + PP_SpaceCell *cell = n->cell; Vec2I32 cell_pos = cell->pos; if (cell_pos.x < new_cell_p0.x || cell_pos.x > new_cell_p1.x || cell_pos.y < new_cell_p0.y || cell_pos.y > new_cell_p1.y) { /* Cell is outside of new AABB */ - SpaceCellNode *next = n->next_in_entry; - ReleaseSpaceCellNode(n); + PP_SpaceCellNode *next = n->next_in_entry; + PP_ReleaseSpaceCellNode(n); n = next; } else @@ -391,7 +391,7 @@ void UpdateSpaceEntryAabb(SpaceEntry *entry, Aabb new_aabb) if (x != 0 && y != 0 && (x < old_cell_p0.x || x > old_cell_p1.x || y < old_cell_p0.y || y > old_cell_p1.y)) { /* Cell is outside of old AABB */ - AcquireSpaceCellNode(VEC2I32(x, y), entry); + PP_AcquireSpaceCellNode(VEC2I32(x, y), entry); } } } @@ -402,14 +402,14 @@ void UpdateSpaceEntryAabb(SpaceEntry *entry, Aabb new_aabb) //////////////////////////////////////////////////////////// //~ Iter -SpaceIter BeginSpaceIterAabb(Space *space, Aabb aabb) +PP_SpaceIter PP_BeginSpaceIterAabb(PP_Space *space, Aabb aabb) { - SpaceIter iter = ZI; + PP_SpaceIter iter = ZI; f32 cell_size = space->cell_size; iter.space = space; - iter.cell_start = SpaceCellCoordsFromWorldCoords(cell_size, aabb.p0); - iter.cell_end = SpaceCellCoordsFromWorldCoords(cell_size, aabb.p1); + iter.cell_start = PP_SpaceCellCoordsFromWorldCoords(cell_size, aabb.p0); + iter.cell_end = PP_SpaceCellCoordsFromWorldCoords(cell_size, aabb.p1); if (iter.cell_start.x > iter.cell_end.x || iter.cell_start.y > iter.cell_end.y) { /* Swap cell_start & cell_end */ @@ -426,16 +426,16 @@ SpaceIter BeginSpaceIterAabb(Space *space, Aabb aabb) return iter; } -SpaceEntry *NextSpaceIterAabb(SpaceIter *iter) +PP_SpaceEntry *PP_NextSpaceIterAabb(PP_SpaceIter *iter) { - Space *space = iter->space; + PP_Space *space = iter->space; Aabb iter_aabb = iter->aabb; Vec2I32 cell_start = iter->cell_start; Vec2I32 cell_end = iter->cell_end; Vec2I32 cell_cur = iter->cell_cur; i32 span = cell_end.x - cell_start.x; - SpaceCellNode *next_node = 0; + PP_SpaceCellNode *next_node = 0; if (cell_cur.x >= cell_start.x && cell_cur.x <= cell_end.x && cell_cur.y >= cell_start.y && cell_cur.y <= cell_end.y) { /* Started */ @@ -452,7 +452,7 @@ SpaceEntry *NextSpaceIterAabb(SpaceIter *iter) { if (next_node) { - SpaceEntry *entry = next_node->entry; + PP_SpaceEntry *entry = next_node->entry; Aabb entry_aabb = entry->aabb; if (CLD_TestAabb(entry_aabb, iter_aabb)) { @@ -474,7 +474,7 @@ SpaceEntry *NextSpaceIterAabb(SpaceIter *iter) cell_cur.y += nexty; cell_cur.x += (cell_cur.x == 0); cell_cur.y += (cell_cur.y == 0); - SpaceCell *cell = SpaceCellFromCellPos(space, cell_cur); + PP_SpaceCell *cell = PP_SpaceCellFromCellPos(space, cell_cur); next_node = cell->first_node; } else diff --git a/src/pp/pp_space.h b/src/pp/pp_space.h index 15f64258..4481c292 100644 --- a/src/pp/pp_space.h +++ b/src/pp/pp_space.h @@ -1,24 +1,24 @@ //////////////////////////////////////////////////////////// //~ Space entry types -Struct(SpaceEntryHandle) +Struct(PP_SpaceEntryKey) { u64 idx; u64 gen; }; -Struct(SpaceEntry) +Struct(PP_SpaceEntry) { b32 valid; - SpaceEntryHandle handle; + PP_SpaceEntryKey handle; - struct SpaceCellNode *first_node; - struct SpaceCellNode *last_node; + struct PP_SpaceCellNode *first_node; + struct PP_SpaceCellNode *last_node; Aabb aabb; - EntityId ent; + PP_EntKey ent; - SpaceEntry *next_free; + PP_SpaceEntry *next_free; }; //////////////////////////////////////////////////////////// @@ -26,134 +26,134 @@ Struct(SpaceEntry) /* Links a cell to a entry. * Acts as both a node in the list of entries contained by the cell, and a node in the list of cells containing the entry. */ -Struct(SpaceCellNode) +Struct(PP_SpaceCellNode) { - SpaceEntry *entry; - struct SpaceCell *cell; + PP_SpaceEntry *entry; + struct PP_SpaceCell *cell; /* For list of all entries contained by cell */ - SpaceCellNode *prev_in_cell; - SpaceCellNode *next_in_cell; + PP_SpaceCellNode *prev_in_cell; + PP_SpaceCellNode *next_in_cell; /* For list of all cells containing entry */ - SpaceCellNode *prev_in_entry; - SpaceCellNode *next_in_entry; + PP_SpaceCellNode *prev_in_entry; + PP_SpaceCellNode *next_in_entry; - SpaceCellNode *next_free; + PP_SpaceCellNode *next_free; }; -Struct(SpaceCell) +Struct(PP_SpaceCell) { b32 valid; Vec2I32 pos; - SpaceCellNode *first_node; - SpaceCellNode *last_node; + PP_SpaceCellNode *first_node; + PP_SpaceCellNode *last_node; - struct SpaceCellBin *bin; - SpaceCell *prev_in_bin; - SpaceCell *next_in_bin; + struct PP_SpaceCellBin *bin; + PP_SpaceCell *prev_in_bin; + PP_SpaceCell *next_in_bin; - SpaceCell *next_free; + PP_SpaceCell *next_free; }; -Struct(SpaceCellBin) +Struct(PP_SpaceCellBin) { - SpaceCell *first_cell; - SpaceCell *last_cell; + PP_SpaceCell *first_cell; + PP_SpaceCell *last_cell; }; //////////////////////////////////////////////////////////// //~ Space types -Struct(Space) +Struct(PP_Space) { b32 valid; f32 cell_size; Arena *cell_arena; - SpaceCellBin *bins; + PP_SpaceCellBin *bins; i32 num_bins; i32 num_bins_sqrt; - SpaceCell *first_free_cell; - SpaceCellNode *first_free_cell_node; + PP_SpaceCell *first_free_cell; + PP_SpaceCellNode *first_free_cell_node; Arena *entry_arena; u64 num_entries_reserved; - SpaceEntry *entries; - SpaceEntry *first_free_entry; + PP_SpaceEntry *entries; + PP_SpaceEntry *first_free_entry; }; -Struct(SpaceIter) +Struct(PP_SpaceIter) { Aabb aabb; - Space *space; + PP_Space *space; Vec2I32 cell_start; Vec2I32 cell_end; Vec2I32 cell_cur; - SpaceCellNode *prev; + PP_SpaceCellNode *prev; }; //////////////////////////////////////////////////////////// //~ Nil types /* Offset in bytes from start of space struct to start of entry array (assume adjacently allocated) */ -#define SpaceEntriesOffset (sizeof(Space) + (sizeof(Space) % alignof(SpaceEntry))) +#define PP_SpaceEntriesOffset (sizeof(PP_Space) + (sizeof(PP_Space) % alignof(PP_SpaceEntry))) -/* Accessed via NilEntity() */ -extern Readonly SpaceEntry _g_space_entry_nil; -extern Readonly SpaceCell _g_space_cell_nil; -extern Readonly Space _g_space_nil; +/* Accessed via NilEnt() */ +extern Readonly PP_SpaceEntry PP_nil_space_entry; +extern Readonly PP_SpaceCell PP_nil_space_cell; +extern Readonly PP_Space PP_nil_space; //////////////////////////////////////////////////////////// //~ Nil helpers -Inline SpaceEntry *NilSpaceEntry(void) +Inline PP_SpaceEntry *PP_NilSpaceEntry(void) { - extern Readonly SpaceEntry _g_space_entry_nil; - return &_g_space_entry_nil; + extern Readonly PP_SpaceEntry PP_nil_space_entry; + return &PP_nil_space_entry; } -Inline SpaceCell *NilSpaceCell(void) +Inline PP_SpaceCell *PP_NilSpaceCell(void) { - extern Readonly SpaceCell _g_space_cell_nil; - return &_g_space_cell_nil; + extern Readonly PP_SpaceCell PP_nil_space_cell; + return &PP_nil_space_cell; } -Inline Space *NilSpace(void) +Inline PP_Space *PP_NilSpace(void) { - extern Readonly Space _g_space_nil; - return &_g_space_nil; + extern Readonly PP_Space PP_nil_space; + return &PP_nil_space; } //////////////////////////////////////////////////////////// //~ Space -Space *AcquireSpace(f32 cell_size, u32 num_bins_sqrt); -void ReleaseSpace(Space *space); -void ResetSpace(Space *space); -Space *SpaceFromEntry(SpaceEntry *entry); +PP_Space *PP_AcquireSpace(f32 cell_size, u32 num_bins_sqrt); +void PP_ReleaseSpace(PP_Space *space); +void PP_ResetSpace(PP_Space *space); +PP_Space *PP_SpaceFromEntry(PP_SpaceEntry *entry); //////////////////////////////////////////////////////////// //~ Cell -Vec2I32 SpaceCellCoordsFromWorldCoords(f32 cell_size, Vec2 world_pos); -i32 SpaceBinIndexFromCellCoords(Space *space, Vec2I32 cell_pos); -SpaceCell *SpaceCellFromCellPos(Space *space, Vec2I32 cell_pos); -void AcquireSpaceCellNode(Vec2I32 cell_pos, SpaceEntry *entry); -void ReleaseSpaceCellNode(SpaceCellNode *n); +Vec2I32 PP_SpaceCellCoordsFromWorldCoords(f32 cell_size, Vec2 world_pos); +i32 PP_SpaceBinIndexFromCellCoords(PP_Space *space, Vec2I32 cell_pos); +PP_SpaceCell *PP_SpaceCellFromCellPos(PP_Space *space, Vec2I32 cell_pos); +void PP_AcquireSpaceCellNode(Vec2I32 cell_pos, PP_SpaceEntry *entry); +void PP_ReleaseSpaceCellNode(PP_SpaceCellNode *n); //////////////////////////////////////////////////////////// //~ Entry -SpaceEntry *SpaceEntryFromHandle(Space *space, SpaceEntryHandle handle); -SpaceEntry *AcquireSpaceEntry(Space *space, EntityId ent); -void ReleaseSpaceEntry(SpaceEntry *entry); -void UpdateSpaceEntryAabb(SpaceEntry *entry, Aabb new_aabb); +PP_SpaceEntry *PP_SpaceEntryFromKey(PP_Space *space, PP_SpaceEntryKey handle); +PP_SpaceEntry *PP_AcquireSpaceEntry(PP_Space *space, PP_EntKey ent); +void PP_ReleaseSpaceEntry(PP_SpaceEntry *entry); +void PP_UpdateSpaceEntryAabb(PP_SpaceEntry *entry, Aabb new_aabb); //////////////////////////////////////////////////////////// //~ Iter -SpaceIter BeginSpaceIterAabb(Space *space, Aabb aabb); -SpaceEntry *NextSpaceIterAabb(SpaceIter *iter); -#define EndSpaceIter(i) +PP_SpaceIter PP_BeginSpaceIterAabb(PP_Space *space, Aabb aabb); +PP_SpaceEntry *PP_NextSpaceIterAabb(PP_SpaceIter *iter); +#define PP_EndSpaceIter(i) diff --git a/src/pp/pp_step.c b/src/pp/pp_step.c index d9fdc31c..466ec0e8 100644 --- a/src/pp/pp_step.c +++ b/src/pp/pp_step.c @@ -1,26 +1,26 @@ //////////////////////////////////////////////////////////// //~ Sim accel -SimAccel AcquireSimAccel(void) +PP_Accel PP_AcquireAccel(void) { - SimAccel accel = ZI; - accel.space = AcquireSpace(SPACE_CELL_SIZE, SPACE_CELL_BINS_SQRT); + PP_Accel accel = ZI; + accel.space = PP_AcquireSpace(SPACE_CELL_SIZE, SPACE_CELL_BINS_SQRT); return accel; } -void ReleaseSimAccel(SimAccel *accel) +void PP_ReleaseAccel(PP_Accel *accel) { - ReleaseSpace(accel->space); + PP_ReleaseSpace(accel->space); } -void ResetSimAccel(Snapshot *ss, SimAccel *accel) +void PP_ResetAccel(PP_Snapshot *ss, PP_Accel *accel) { - ResetSpace(accel->space); + PP_ResetSpace(accel->space); /* Reset ent space handles */ for (u64 sim_ent_index = 0; sim_ent_index < ss->num_ents_reserved; ++sim_ent_index) { - Entity *ent = &ss->ents[sim_ent_index]; + PP_Ent *ent = &ss->ents[sim_ent_index]; if (ent->valid) { ZeroStruct(&ent->space_handle); @@ -33,61 +33,61 @@ void ResetSimAccel(Snapshot *ss, SimAccel *accel) /* TODO: Remove this */ -Entity *SpawnTestSmg(Entity *parent) +PP_Ent *PP_SpawnTestSmg(PP_Ent *parent) { - Entity *e = AcquireSyncSrc(parent); - e->sprite = ResourceKeyFromStore(&GameResources, Lit("sprite/gun.ase")); + PP_Ent *e = PP_AcquireSyncSrcEnt(parent); + e->sprite = ResourceKeyFromStore(&PP_Resources, Lit("sprite/gun.ase")); - EnableProp(e, Prop_Attached); + PP_EnableProp(e, PP_Prop_Attached); e->attach_slice = Lit("attach.wep"); - e->layer = Layer_RelativeWeapon; + e->layer = PP_Layer_RelativeWeapon; - EnableProp(e, Prop_Smg); + PP_EnableProp(e, PP_Prop_Smg); e->primary_fire_delay = 1.0f / 10.0f; e->secondary_fire_delay = 1.0f / 10.0f; return e; } -Entity *SpawnTestLauncher(Entity *parent) +PP_Ent *PP_SpawnTestLauncher(PP_Ent *parent) { - Entity *e = AcquireSyncSrc(parent); - e->sprite = ResourceKeyFromStore(&GameResources, Lit("sprite/gun.ase")); + PP_Ent *e = PP_AcquireSyncSrcEnt(parent); + e->sprite = ResourceKeyFromStore(&PP_Resources, Lit("sprite/gun.ase")); - EnableProp(e, Prop_Attached); + PP_EnableProp(e, PP_Prop_Attached); e->attach_slice = Lit("attach.wep"); - e->layer = Layer_RelativeWeapon; + e->layer = PP_Layer_RelativeWeapon; - EnableProp(e, Prop_Launcher); + PP_EnableProp(e, PP_Prop_Launcher); e->primary_fire_delay = 1.0f / 10.0f; e->secondary_fire_delay = 1.0f / 10.0f; return e; } -Entity *SpawnTestChucker(Entity *parent) +PP_Ent *PP_SpawnTestChucker(PP_Ent *parent) { - Entity *chucker = AcquireSyncSrc(parent); - chucker->sprite = ResourceKeyFromStore(&GameResources, Lit("sprite/gun.ase")); + PP_Ent *chucker = PP_AcquireSyncSrcEnt(parent); + chucker->sprite = ResourceKeyFromStore(&PP_Resources, Lit("sprite/gun.ase")); - EnableProp(chucker, Prop_Attached); + PP_EnableProp(chucker, PP_Prop_Attached); chucker->attach_slice = Lit("attach.wep"); - chucker->layer = Layer_RelativeWeapon; + chucker->layer = PP_Layer_RelativeWeapon; - EnableProp(chucker, Prop_Chucker); + PP_EnableProp(chucker, PP_Prop_Chucker); chucker->primary_fire_delay = 1.0f / 10.0f; chucker->secondary_fire_delay = 1.0f / 2.0f; /* Chucker zone */ { - Entity *zone = AcquireSyncSrc(chucker); + PP_Ent *zone = PP_AcquireSyncSrcEnt(chucker); - EnableProp(zone, Prop_ChuckerZone); + PP_EnableProp(zone, PP_Prop_ChuckerZone); - EnableProp(zone, Prop_Attached); + PP_EnableProp(zone, PP_Prop_Attached); zone->attach_slice = Lit("out"); - EnableProp(zone, Prop_Sensor); + PP_EnableProp(zone, PP_Prop_Sensor); CLD_Shape collider = ZI; collider.count = 2; collider.points[1] = VEC2(0, -0.5); @@ -100,13 +100,13 @@ Entity *SpawnTestChucker(Entity *parent) return chucker; } -Entity *SpawnTestEmployee(Entity *parent) +PP_Ent *PP_SpawnTestEmployee(PP_Ent *parent) { /* Player */ - Entity *employee = NilEntity(); + PP_Ent *employee = PP_NilEnt(); { - Entity *e = AcquireSyncSrc(parent); + PP_Ent *e = PP_AcquireSyncSrcEnt(parent); Vec2 pos = VEC2(1, -1); @@ -118,17 +118,17 @@ Entity *SpawnTestEmployee(Entity *parent) f32 r = 0; { - EnableProp(e, Prop_Test); - e->sprite = ResourceKeyFromStore(&GameResources, Lit("sprite/tim.ase")); + PP_EnableProp(e, PP_Prop_Test); + e->sprite = ResourceKeyFromStore(&PP_Resources, Lit("sprite/tim.ase")); e->mass_unscaled = 10; e->inertia_unscaled = 5; } - //e->sprite = ResourceKeyFromStore(GameResources, Lit("sprite/box_rounded.ase")); + //e->sprite = ResourceKeyFromStore(PP_Resources, Lit("sprite/box_rounded.ase")); //e->sprite_span_name = Lit("idle.unarmed"); //e->sprite_span_name = Lit("idle.one_handed"); e->sprite_span_name = Lit("idle.two_handed"); - e->layer = Layer_Shoulders; + e->layer = PP_Layer_Shoulders; e->local_collider.points[0] = VEC2(0, 0); e->local_collider.count = 1; @@ -137,7 +137,7 @@ Entity *SpawnTestEmployee(Entity *parent) Xform xf = XformFromTrs(TRS(.t = pos, .r = r, .s = size)); //xf.bx.y = -1.f; - SetXform(e, xf); + PP_SetXform(e, xf); e->linear_ground_friction = 250; e->angular_ground_friction = 200; @@ -147,7 +147,7 @@ Entity *SpawnTestEmployee(Entity *parent) - EnableProp(e, Prop_LightTest); + PP_EnableProp(e, PP_Prop_LightTest); e->sprite_emittance = VEC3(1, 1, 1); @@ -162,8 +162,8 @@ Entity *SpawnTestEmployee(Entity *parent) //e->control_torque = 5000; e->control_torque = F32Infinity; - EnableProp(e, Prop_Dynamic); - EnableProp(e, Prop_Solid); + PP_EnableProp(e, PP_Prop_Dynamic); + PP_EnableProp(e, PP_Prop_Solid); employee = e; } @@ -171,30 +171,30 @@ Entity *SpawnTestEmployee(Entity *parent) /* Player weapon */ if (employee->valid) { - LAX SpawnTestSmg; - LAX SpawnTestLauncher; - LAX SpawnTestChucker; + LAX PP_SpawnTestSmg; + LAX PP_SpawnTestLauncher; + LAX PP_SpawnTestChucker; - Entity *e = SpawnTestChucker(employee); + PP_Ent *e = PP_SpawnTestChucker(employee); employee->equipped = e->id; - EnableProp(e, Prop_LightTest); + PP_EnableProp(e, PP_Prop_LightTest); e->sprite_emittance = VEC3(1, 1, 1); } return employee; } -Entity *SpawnTestCamera(Entity *parent, Entity *follow) +PP_Ent *PP_SpawnTestCamera(PP_Ent *parent, PP_Ent *follow) { - Entity *camera_ent = NilEntity(); + PP_Ent *camera_ent = PP_NilEnt(); if (follow->valid) { - camera_ent = AcquireSyncSrc(parent); - SetXform(camera_ent, XformIdentity); + camera_ent = PP_AcquireSyncSrcEnt(parent); + PP_SetXform(camera_ent, XformIdentity); - EnableProp(camera_ent, Prop_Camera); - EnableProp(camera_ent, Prop_ActiveCamera); + PP_EnableProp(camera_ent, PP_Prop_Camera); + PP_EnableProp(camera_ent, PP_Prop_ActiveCamera); camera_ent->camera_follow = follow->id; f32 width = (f32)DEFAULT_CAMERA_WIDTH; @@ -205,69 +205,69 @@ Entity *SpawnTestCamera(Entity *parent, Entity *follow) return camera_ent; } -Entity *SpawnTestExplosion(Entity *parent, Vec2 pos, f32 strength, f32 radius) +PP_Ent *PP_SpawnTestExplosion(PP_Ent *parent, Vec2 pos, f32 strength, f32 radius) { - Entity *ent = AcquireSyncSrc(parent); - SetXform(ent, XformFromPos(pos)); + PP_Ent *ent = PP_AcquireSyncSrcEnt(parent); + PP_SetXform(ent, XformFromPos(pos)); - EnableProp(ent, Prop_Explosion); + PP_EnableProp(ent, PP_Prop_Explosion); ent->explosion_strength = strength; ent->explosion_radius = radius; - EnableProp(ent, Prop_Sensor); + PP_EnableProp(ent, PP_Prop_Sensor); ent->local_collider.count = 1; ent->local_collider.radius = radius; return ent; } -void TeleportTest(Entity *ent, Vec2 pos) +void PP_TeleportTest(PP_Ent *ent, Vec2 pos) { //++ent->continuity_gen; - Xform xf = XformFromEntity(ent); + Xform xf = PP_XformFromEnt(ent); xf.og = pos; - SetXform(ent, xf); + PP_SetXform(ent, xf); } -void SpawnTestEntities1(Entity *parent, Vec2 pos) +void PP_SpawnTestEnts1(PP_Ent *parent, Vec2 pos) { LAX pos; /* Enemy */ { - Entity *e = SpawnTestEmployee(parent); - Xform xf = XformFromEntity(e); + PP_Ent *e = PP_SpawnTestEmployee(parent); + Xform xf = PP_XformFromEnt(e); xf.og = pos; - SetXform(e, xf); + PP_SetXform(e, xf); } } -void SpawnTestEntities2(Entity *parent, Vec2 pos) +void PP_SpawnTestEnts2(PP_Ent *parent, Vec2 pos) { LAX pos; /* Small Box */ #if 1 { - //Entity *e = AcquireLocal(parent); - Entity *e = AcquireSyncSrc(parent); + //PP_Ent *e = PP_AcquireLocalEnt(parent); + PP_Ent *e = PP_AcquireSyncSrcEnt(parent); f32 rot = 0; Vec2 size = VEC2(0.125, 0.125); Xform xf = XformFromTrs(TRS(.t = pos, .r = rot, .s = size)); - SetXform(e, xf); + PP_SetXform(e, xf); - e->sprite = ResourceKeyFromStore(&GameResources, Lit("sprite/tile.ase")); - e->layer = Layer_Shoulders; + e->sprite = ResourceKeyFromStore(&PP_Resources, Lit("sprite/tile.ase")); + e->layer = PP_Layer_Shoulders; //e->sprite_tint = Alpha32F(Color_Blue, 0.75); //e->sprite_tint = Alpha32F(Color_White, 1); - EnableProp(e, Prop_Solid); + PP_EnableProp(e, PP_Prop_Solid); Quad collider_quad = QuadFromRect(RectFromScalar(-0.5, -0.5, 1, 1)); e->local_collider = CLD_ShapeFromQuad(collider_quad); - EnableProp(e, Prop_LightTest); + PP_EnableProp(e, PP_Prop_LightTest); /* FIXME: Remove this */ { @@ -279,7 +279,7 @@ void SpawnTestEntities2(Entity *parent, Vec2 pos) e->sprite_tint = Rgba32F(r / 5, g / 5, b / 5, 1); } - EnableProp(e, Prop_Dynamic); + PP_EnableProp(e, PP_Prop_Dynamic); e->mass_unscaled = 50; e->inertia_unscaled = 2; #if 0 @@ -292,20 +292,20 @@ void SpawnTestEntities2(Entity *parent, Vec2 pos) /* Tiny box */ #if 0 { - Entity *e = AcquireSyncSrc(parent); + PP_Ent *e = PP_AcquireSyncSrcEnt(parent); f32 r = Pi / 4; Vec2 size = VEC2(0.5, 0.25); Xform xf = XformFromTrs(.t = pos, .r = r, .s = size); - SetXform(e, xf); + PP_SetXform(e, xf); - e->sprite = ResourceKeyFromStore(GameResources, Lit("sprite/bullet.ase")); + e->sprite = ResourceKeyFromStore(PP_Resources, Lit("sprite/bullet.ase")); e->sprite_collider_slice = Lit("shape"); - e->layer = Layer_Shoulders; + e->layer = PP_Layer_Shoulders; - EnableProp(e, Prop_Solid); + PP_EnableProp(e, PP_Prop_Solid); - EnableProp(e, Prop_Dynamic); + PP_EnableProp(e, PP_Prop_Dynamic); e->mass_unscaled = 0.5; e->inertia_unscaled = 1000; e->linear_ground_friction = 0.001; @@ -313,57 +313,57 @@ void SpawnTestEntities2(Entity *parent, Vec2 pos) #endif } -void SpawnTestEntities3(Entity *parent, Vec2 pos) +void PP_SpawnTestEnts3(PP_Ent *parent, Vec2 pos) { LAX pos; /* Heavy box */ { - //Entity *e = AcquireLocal(parent); - Entity *e = AcquireSyncSrc(parent); + //PP_Ent *e = PP_AcquireLocalEnt(parent); + PP_Ent *e = PP_AcquireSyncSrcEnt(parent); f32 r = 0; Vec2 size = VEC2(1, 1); Xform xf = XformFromTrs(TRS(.t = pos, .r = r, .s = size)); - SetXform(e, xf); + PP_SetXform(e, xf); - e->sprite = ResourceKeyFromStore(&GameResources, Lit("sprite/box.ase")); - e->layer = Layer_Shoulders; + e->sprite = ResourceKeyFromStore(&PP_Resources, Lit("sprite/box.ase")); + e->layer = PP_Layer_Shoulders; e->sprite_tint = Color_Red; - EnableProp(e, Prop_Solid); + PP_EnableProp(e, PP_Prop_Solid); Quad collider_quad = QuadFromRect(RectFromScalar(-0.5, -0.5, 1, 1)); e->local_collider = CLD_ShapeFromQuad(collider_quad); } } -void SpawnTestEntities4(Entity *parent, Vec2 pos) +void PP_SpawnTestEnts4(PP_Ent *parent, Vec2 pos) { LAX pos; /* Light box */ - Entity *e = AcquireSyncSrc(parent); + PP_Ent *e = PP_AcquireSyncSrcEnt(parent); f32 r = 0; Vec2 size = VEC2(2, 1); Xform xf = XformFromTrs(TRS(.t = pos, .r = r, .s = size)); - SetXform(e, xf); + PP_SetXform(e, xf); - //e->sprite = ResourceKeyFromStore(GameResources, Lit("sprite/box.ase")); - e->sprite = ResourceKeyFromStore(&GameResources, Lit("sprite/tile.ase")); - e->layer = Layer_Shoulders; + //e->sprite = ResourceKeyFromStore(PP_Resources, Lit("sprite/box.ase")); + e->sprite = ResourceKeyFromStore(&PP_Resources, Lit("sprite/tile.ase")); + e->layer = PP_Layer_Shoulders; - EnableProp(e, Prop_LightTest); + PP_EnableProp(e, PP_Prop_LightTest); e->sprite_emittance = VEC3(2, 2, 2); e->sprite_tint = Rgb32F(1, 1, 1); } -void SpawnTestTile(Snapshot *world, Vec2 world_pos) +void PP_SpawnTestTile(PP_Snapshot *world, Vec2 world_pos) { #if 0 - Entity *e = AcquireSyncSrc(parent); + PP_Ent *e = PP_AcquireSyncSrcEnt(parent); i32 sign_x = (world_pos.x >= 0) - (world_pos.x < 0); i32 sign_y = (world_pos.y >= 0) - (world_pos.y < 0); @@ -377,33 +377,33 @@ void SpawnTestTile(Snapshot *world, Vec2 world_pos) pos = AddVec2(pos, MulVec2(VEC2(tile_size.x * sign_x, tile_size.y * sign_y), 0.5)); Xform xf = XformFromTrs(.t = pos); - SetXform(e, xf); + PP_SetXform(e, xf); - e->layer = Layer_Walls; - e->sprite = ResourceKeyFromStore(GameResources, Lit("sprite/tile.ase")); + e->layer = PP_Layer_Walls; + e->sprite = ResourceKeyFromStore(PP_Resources, Lit("sprite/tile.ase")); e->sprite_tint = Color_Red; S_Sheet *sheet = S_SheetFromResource(e->sprite); e->sprite_local_xform = XformFromTrs(.s = DivVec2(sheet->frame_size, PIXELS_PER_UNIT)); - EnableProp(e, Prop_Solid); + PP_EnableProp(e, PP_Prop_Solid); Quad collider_quad = QuadFromRect(RectFromScalar(-tile_size.x / 2, -tile_size.y / 2, tile_size.y, tile_size.y)); e->local_collider = CLD_ShapeFromQuad(collider_quad); #else - Vec2I32 tile_index = WorldTileIndexFromPos(world_pos); - SetSnapshotTile(world, tile_index, TileKind_Wall); + Vec2I32 tile_index = PP_WorldTileIndexFromPos(world_pos); + PP_SetSnapshotTile(world, tile_index, PP_TileKind_Wall); #endif } -void ClearLevelTest(SimStepCtx *ctx) +void PP_ClearLevelTest(PP_SimStepCtx *ctx) { - Snapshot *world = ctx->world; + PP_Snapshot *world = ctx->world; for (u64 j = 0; j < world->num_ents_reserved; ++j) { - Entity *ent = &world->ents[j]; + PP_Ent *ent = &world->ents[j]; if (ent->valid) { - EnableProp(ent, Prop_Release); + PP_EnableProp(ent, PP_Prop_Release); } } } @@ -411,10 +411,10 @@ void ClearLevelTest(SimStepCtx *ctx) //////////////////////////////////////////////////////////// //~ Tile test operations -MergesortCompareFuncDef(SortTileXCmp, arg_a, arg_b, _) +MergesortCompareFuncDef(PP_SortTileXCmp, arg_a, arg_b, _) { - Entity *a = *(Entity **)arg_a; - Entity *b = *(Entity **)arg_b; + PP_Ent *a = *(PP_Ent **)arg_a; + PP_Ent *b = *(PP_Ent **)arg_b; i32 a_x = a->tile_chunk_index.x; i32 b_x = b->tile_chunk_index.x; @@ -423,10 +423,10 @@ MergesortCompareFuncDef(SortTileXCmp, arg_a, arg_b, _) return result; } -MergesortCompareFuncDef(SortTileYCmp, arg_a, arg_b, _) +MergesortCompareFuncDef(PP_SortTileYCmp, arg_a, arg_b, _) { - Entity *a = *(Entity **)arg_a; - Entity *b = *(Entity **)arg_b; + PP_Ent *a = *(PP_Ent **)arg_a; + PP_Ent *b = *(PP_Ent **)arg_b; i32 a_y = a->tile_chunk_index.y; i32 b_y = b->tile_chunk_index.y; @@ -435,43 +435,43 @@ MergesortCompareFuncDef(SortTileYCmp, arg_a, arg_b, _) return result; } -void GenerateTestWalls(Snapshot *world) +void PP_GenerateTestWalls(PP_Snapshot *world) { __prof; TempArena scratch = BeginScratchNoConflict(); - Entity *root = EntityFromId(world, RootEntityId); + PP_Ent *root = PP_EntFromKey(world, PP_RootEntKey); /* Release existing walls and gather tile chunks. * NOTE: We sort tile chunks before iterating so that chunk-edge tiles only * need to check for adjacent walls to merge with in one direction */ - Entity **x_sorted_tile_chunks = 0; - Entity **y_sorted_tile_chunks = 0; + PP_Ent **x_sorted_tile_chunks = 0; + PP_Ent **y_sorted_tile_chunks = 0; u64 sorted_tile_chunks_count = 0; { - x_sorted_tile_chunks = PushDry(scratch.arena, Entity *); + x_sorted_tile_chunks = PushDry(scratch.arena, PP_Ent *); for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) { - Entity *ent = &world->ents[ent_index]; + PP_Ent *ent = &world->ents[ent_index]; if (!ent->valid) continue; - if (HasProp(ent, Prop_TileChunk)) + if (PP_HasProp(ent, PP_Prop_TileChunk)) { /* Append chunk to array */ - *PushStructNoZero(scratch.arena, Entity *) = ent; + *PushStructNoZero(scratch.arena, PP_Ent *) = ent; ++sorted_tile_chunks_count; } - else if (HasProp(ent, Prop_Wall)) + else if (PP_HasProp(ent, PP_Prop_Wall)) { /* Release existing wall */ - EnableProp(ent, Prop_Release); + PP_EnableProp(ent, PP_Prop_Release); } } - y_sorted_tile_chunks = PushStructsNoZero(scratch.arena, Entity *, sorted_tile_chunks_count); + y_sorted_tile_chunks = PushStructsNoZero(scratch.arena, PP_Ent *, sorted_tile_chunks_count); CopyBytes(y_sorted_tile_chunks, x_sorted_tile_chunks, sizeof(*x_sorted_tile_chunks) * sorted_tile_chunks_count); /* NOTE: We sort x & y separately because it's possible that a wall * should merge with another wall that was generated from a diagonal chunk. */ - Mergesort(x_sorted_tile_chunks, sorted_tile_chunks_count, sizeof(*x_sorted_tile_chunks), SortTileXCmp, 0); - Mergesort(y_sorted_tile_chunks, sorted_tile_chunks_count, sizeof(*y_sorted_tile_chunks), SortTileYCmp, 0); + Mergesort(x_sorted_tile_chunks, sorted_tile_chunks_count, sizeof(*x_sorted_tile_chunks), PP_SortTileXCmp, 0); + Mergesort(y_sorted_tile_chunks, sorted_tile_chunks_count, sizeof(*y_sorted_tile_chunks), PP_SortTileYCmp, 0); } struct wall_node @@ -492,10 +492,10 @@ void GenerateTestWalls(Snapshot *world) /* Generate horizontal wall nodes */ for (u64 sorted_index = 0; sorted_index < sorted_tile_chunks_count; ++sorted_index) { - Entity *chunk = x_sorted_tile_chunks[sorted_index]; + PP_Ent *chunk = x_sorted_tile_chunks[sorted_index]; Vec2I32 chunk_index = chunk->tile_chunk_index; - Entity *top_chunk = TileChunkFromChunkIndex(world, VEC2I32(chunk_index.x, chunk_index.y - 1)); - Entity *bottom_chunk = TileChunkFromChunkIndex(world, VEC2I32(chunk_index.x, chunk_index.y + 1)); + PP_Ent *top_chunk = PP_TileChunkFromChunkIndex(world, VEC2I32(chunk_index.x, chunk_index.y - 1)); + PP_Ent *bottom_chunk = PP_TileChunkFromChunkIndex(world, VEC2I32(chunk_index.x, chunk_index.y + 1)); /* If there's no chunk below this one, then do an extra iteration (since walls are created at the top of each tile) */ i32 y_iterations = SIM_TILES_PER_CHUNK_SQRT + !bottom_chunk->valid; i32 x_iterations = SIM_TILES_PER_CHUNK_SQRT + 1; @@ -507,30 +507,30 @@ void GenerateTestWalls(Snapshot *world) for (i32 tile_x = 0; tile_x < x_iterations; ++tile_x) { i32 desired_wall_dir = -1; - TileKind tile = TileKind_None; + PP_TileKind tile = PP_TileKind_None; if (tile_x < SIM_TILES_PER_CHUNK_SQRT && tile_y < SIM_TILES_PER_CHUNK_SQRT) { - tile = TileKindFromChunk(chunk, VEC2I32(tile_x, tile_y)); + tile = PP_TileKindFromChunk(chunk, VEC2I32(tile_x, tile_y)); } if (tile_x < SIM_TILES_PER_CHUNK_SQRT) { - TileKind top_tile = TileKind_None; + PP_TileKind top_tile = PP_TileKind_None; if (tile_y == 0) { if (top_chunk->valid) { Vec2I32 top_tile_local_index = VEC2I32(tile_x, SIM_TILES_PER_CHUNK_SQRT - 1); - top_tile = TileKindFromChunk(top_chunk, top_tile_local_index); + top_tile = PP_TileKindFromChunk(top_chunk, top_tile_local_index); } } else { - top_tile = TileKindFromChunk(chunk, VEC2I32(tile_x, tile_y - 1)); + top_tile = PP_TileKindFromChunk(chunk, VEC2I32(tile_x, tile_y - 1)); } - if (tile == TileKind_Wall) + if (tile == PP_TileKind_Wall) { /* Process wall tile */ - if (top_tile != TileKind_Wall) + if (top_tile != PP_TileKind_Wall) { desired_wall_dir = 0; } @@ -538,7 +538,7 @@ void GenerateTestWalls(Snapshot *world) else { /* Process non-wall tile */ - if (top_tile == TileKind_Wall) + if (top_tile == PP_TileKind_Wall) { desired_wall_dir = 2; } @@ -548,8 +548,8 @@ void GenerateTestWalls(Snapshot *world) /* Stop wall */ if (wall_dir >= 0 && desired_wall_dir != wall_dir) { - Vec2I32 start = WorldTileIndexFromLocalTileIndex(chunk_index, VEC2I32(wall_start, tile_y)); - Vec2I32 end = WorldTileIndexFromLocalTileIndex(chunk_index, VEC2I32(wall_end, tile_y)); + Vec2I32 start = PP_WorldTileIndexFromLocalTileIndex(chunk_index, VEC2I32(wall_start, tile_y)); + Vec2I32 end = PP_WorldTileIndexFromLocalTileIndex(chunk_index, VEC2I32(wall_end, tile_y)); struct wall_node *node = 0; if (wall_start == 0) { @@ -602,10 +602,10 @@ void GenerateTestWalls(Snapshot *world) /* Generate vertical wall nodes */ for (u64 sorted_index = 0; sorted_index < sorted_tile_chunks_count; ++sorted_index) { - Entity *chunk = y_sorted_tile_chunks[sorted_index]; + PP_Ent *chunk = y_sorted_tile_chunks[sorted_index]; Vec2I32 chunk_index = chunk->tile_chunk_index; - Entity *left_chunk = TileChunkFromChunkIndex(world, VEC2I32(chunk_index.x - 1, chunk_index.y)); - Entity *right_chunk = TileChunkFromChunkIndex(world, VEC2I32(chunk_index.x + 1, chunk_index.y)); + PP_Ent *left_chunk = PP_TileChunkFromChunkIndex(world, VEC2I32(chunk_index.x - 1, chunk_index.y)); + PP_Ent *right_chunk = PP_TileChunkFromChunkIndex(world, VEC2I32(chunk_index.x + 1, chunk_index.y)); /* If there's no chunk to the right of this one, then do an extra iteration (since walls are created on the left of each tile) */ i32 y_iterations = SIM_TILES_PER_CHUNK_SQRT + 1; i32 x_iterations = SIM_TILES_PER_CHUNK_SQRT + !right_chunk->valid; @@ -617,31 +617,31 @@ void GenerateTestWalls(Snapshot *world) for (i32 tile_y = 0; tile_y < y_iterations; ++tile_y) { i32 desired_wall_dir = -1; - TileKind tile = TileKind_None; + PP_TileKind tile = PP_TileKind_None; if (tile_x < SIM_TILES_PER_CHUNK_SQRT && tile_y < SIM_TILES_PER_CHUNK_SQRT) { - tile = TileKindFromChunk(chunk, VEC2I32(tile_x, tile_y)); + tile = PP_TileKindFromChunk(chunk, VEC2I32(tile_x, tile_y)); } if (tile_y < SIM_TILES_PER_CHUNK_SQRT) { - TileKind left_tile = TileKind_None; + PP_TileKind left_tile = PP_TileKind_None; if (tile_x == 0) { if (left_chunk->valid) { Vec2I32 left_tile_local_index = VEC2I32(SIM_TILES_PER_CHUNK_SQRT - 1, tile_y); - left_tile = TileKindFromChunk(left_chunk, left_tile_local_index); + left_tile = PP_TileKindFromChunk(left_chunk, left_tile_local_index); } } else { - left_tile = TileKindFromChunk(chunk, VEC2I32(tile_x - 1, tile_y)); + left_tile = PP_TileKindFromChunk(chunk, VEC2I32(tile_x - 1, tile_y)); } - if (tile == TileKind_Wall) + if (tile == PP_TileKind_Wall) { /* Process wall tile */ - if (left_tile != TileKind_Wall) + if (left_tile != PP_TileKind_Wall) { desired_wall_dir = 3; } @@ -649,7 +649,7 @@ void GenerateTestWalls(Snapshot *world) else { /* Process non-wall tile */ - if (left_tile == TileKind_Wall) + if (left_tile == PP_TileKind_Wall) { desired_wall_dir = 1; } @@ -659,8 +659,8 @@ void GenerateTestWalls(Snapshot *world) /* Stop wall */ if (wall_dir >= 0 && desired_wall_dir != wall_dir) { - Vec2I32 start = WorldTileIndexFromLocalTileIndex(chunk_index, VEC2I32(tile_x, wall_start)); - Vec2I32 end = WorldTileIndexFromLocalTileIndex(chunk_index, VEC2I32(tile_x, wall_end)); + Vec2I32 start = PP_WorldTileIndexFromLocalTileIndex(chunk_index, VEC2I32(tile_x, wall_start)); + Vec2I32 end = PP_WorldTileIndexFromLocalTileIndex(chunk_index, VEC2I32(tile_x, wall_end)); struct wall_node *node = 0; if (wall_start == 0) { @@ -713,16 +713,16 @@ void GenerateTestWalls(Snapshot *world) /* Create wall entities */ for (struct wall_node *node = first_wall; node; node = node->next) { - Entity *wall_ent = AcquireSyncSrc(root); - EnableProp(wall_ent, Prop_Wall); + PP_Ent *wall_ent = PP_AcquireSyncSrcEnt(root); + PP_EnableProp(wall_ent, PP_Prop_Wall); - Vec2 start = PosFromWorldTileIndex(node->start); - Vec2 end = PosFromWorldTileIndex(node->end); + Vec2 start = PP_PosFromWorldTileIndex(node->start); + Vec2 end = PP_PosFromWorldTileIndex(node->end); Xform xf = XformFromPos(start); - SetXform(wall_ent, xf); + PP_SetXform(wall_ent, xf); - EnableProp(wall_ent, Prop_Solid); + PP_EnableProp(wall_ent, PP_Prop_Solid); wall_ent->local_collider.count = 2; wall_ent->local_collider.points[1] = SubVec2(end, start); @@ -730,7 +730,7 @@ void GenerateTestWalls(Snapshot *world) Assert(node->wall_dir >= 0 && (u32)node->wall_dir < countof(dirs)); wall_ent->collision_dir = dirs[node->wall_dir]; - Activate(wall_ent, world->tick); + PP_ActivateEnt(wall_ent, world->tick); } EndScratch(scratch); @@ -739,54 +739,54 @@ void GenerateTestWalls(Snapshot *world) //////////////////////////////////////////////////////////// //~ On collision -CollisionCallbackFuncDef(OnEntityCollision, data, step_ctx) +PP_CollisionCallbackFuncDef(PP_OnEntCollision, data, step_ctx) { - Snapshot *world = step_ctx->world; - Entity *e0 = EntityFromId(world, data->e0); - Entity *e1 = EntityFromId(world, data->e1); - Entity *root = EntityFromId(world, RootEntityId); + PP_Snapshot *world = step_ctx->world; + PP_Ent *e0 = PP_EntFromKey(world, data->e0); + PP_Ent *e1 = PP_EntFromKey(world, data->e1); + PP_Ent *root = PP_EntFromKey(world, PP_RootEntKey); b32 skip_solve = 0; - if (ShouldSimulate(e0) && ShouldSimulate(e1)) + if (PP_ShouldSimulate(e0) && PP_ShouldSimulate(e1)) { /* Bullet impact */ - if (HasProp(e0, Prop_Bullet)) + if (PP_HasProp(e0, PP_Prop_Bullet)) { Vec2 normal = data->normal; /* Impact normal */ Vec2 vrel = data->vrel; /* Impact velocity */ - Entity *bullet = e0; - Entity *target = e1; - Entity *src = EntityFromId(world, bullet->bullet_src); + PP_Ent *bullet = e0; + PP_Ent *target = e1; + PP_Ent *src = PP_EntFromKey(world, bullet->bullet_src); /* Process collision if bullet already spent or * target share same top level parent */ - if (!bullet->bullet_has_hit && !EqId(src->top, target->top) && HasProp(target, Prop_Solid)) + if (!bullet->bullet_has_hit && !PP_EqEntKey(src->top, target->top) && PP_HasProp(target, PP_Prop_Solid)) { Vec2 point = data->point; /* Update tracer */ - Entity *tracer = EntityFromId(world, bullet->bullet_tracer); - if (ShouldSimulate(tracer)) + PP_Ent *tracer = PP_EntFromKey(world, bullet->bullet_tracer); + if (PP_ShouldSimulate(tracer)) { - Xform xf = XformFromEntity(tracer); + Xform xf = PP_XformFromEnt(tracer); xf.og = point; - SetXform(tracer, xf); - SetLinearVelocity(tracer, VEC2(0, 0)); + PP_SetXform(tracer, xf); + PP_SetLinearVelocity(tracer, VEC2(0, 0)); } /* Update target */ Vec2 knockback = MulVec2(NormVec2(vrel), bullet->bullet_knockback); - ApplyLinearImpulse(target, knockback, point); + PP_ApplyLinearImpulse(target, knockback, point); /* Create test blood */ /* TODO: Remove this */ { Xform xf = XformFromTrs(TRS(.t = point, .r = RandF64FromState(&step_ctx->rand, 0, Tau))); - Entity *decal = AcquireSyncSrc(root); - decal->sprite = ResourceKeyFromStore(&GameResources, Lit("sprite/blood.ase")); + PP_Ent *decal = PP_AcquireSyncSrcEnt(root); + decal->sprite = ResourceKeyFromStore(&PP_Resources, Lit("sprite/blood.ase")); decal->sprite_tint = Rgba32F(1, 1, 1, 0.25f); - decal->layer = Layer_FloorDecals; - SetXform(decal, xf); + decal->layer = PP_Layer_FloorDecals; + PP_SetXform(decal, xf); f32 perp_range = 0.5; Vec2 linear_velocity = MulVec2(normal, 0.5); @@ -795,9 +795,9 @@ CollisionCallbackFuncDef(OnEntityCollision, data, step_ctx) f32 angular_velocity_range = 5; f32 angular_velocity = RandF64FromState(&step_ctx->rand, -angular_velocity_range, angular_velocity_range); - EnableProp(decal, Prop_Kinematic); - SetLinearVelocity(decal, linear_velocity); - SetAngularVelocity(decal, angular_velocity); + PP_EnableProp(decal, PP_Prop_Kinematic); + PP_SetLinearVelocity(decal, linear_velocity); + PP_SetAngularVelocity(decal, angular_velocity); decal->linear_damping = 5.0f; decal->angular_damping = 5.0f; @@ -806,27 +806,27 @@ CollisionCallbackFuncDef(OnEntityCollision, data, step_ctx) /* Create explosion */ if (bullet->bullet_explosion_strength > 0) { - SpawnTestExplosion(root, point, bullet->bullet_explosion_strength, bullet->bullet_explosion_radius); + PP_SpawnTestExplosion(root, point, bullet->bullet_explosion_strength, bullet->bullet_explosion_radius); } /* Update bullet */ bullet->bullet_has_hit = 1; - EnableProp(bullet, Prop_Release); + PP_EnableProp(bullet, PP_Prop_Release); } } /* Explosion blast collision */ - if (HasProp(e0, Prop_Explosion)) + if (PP_HasProp(e0, PP_Prop_Explosion)) { - Entity *exp = e0; - Entity *victim = e1; + PP_Ent *exp = e0; + PP_Ent *victim = e1; - Xform xf = XformFromEntity(exp); + Xform xf = PP_XformFromEnt(exp); CLD_Shape origin_collider = ZI; origin_collider.count = 1; - Xform victim_xf = XformFromEntity(victim); + Xform victim_xf = PP_XformFromEnt(victim); CLD_ClosestPointData closest_points = CLD_ClosestPointDataFromShapes(&origin_collider, &victim->local_collider, xf, victim_xf); Vec2 dir = SubVec2(closest_points.p1, closest_points.p0); Vec2 point = closest_points.p1; @@ -854,14 +854,14 @@ CollisionCallbackFuncDef(OnEntityCollision, data, step_ctx) const f32 falloff_curve = 3; /* Cubic falloff */ f32 strength_factor = PowF32(1 - distance/radius, falloff_curve); Vec2 impulse = Vec2WithLen(dir, strength_center * strength_factor); - ApplyLinearImpulse(victim, impulse, point); + PP_ApplyLinearImpulse(victim, impulse, point); } } /* Chucker zone */ - if (HasProp(e0, Prop_ChuckerZone)) + if (PP_HasProp(e0, PP_Prop_ChuckerZone)) { - if (!EqId(e0->top, e1->top) && HasProp(e1, Prop_Solid)) + if (!PP_EqEntKey(e0->top, e1->top) && PP_HasProp(e1, PP_Prop_Solid)) { e0->chucker_zone_ent = e1->id; e0->chucker_zone_ent_tick = world->tick; @@ -875,19 +875,19 @@ CollisionCallbackFuncDef(OnEntityCollision, data, step_ctx) //////////////////////////////////////////////////////////// //~ Step -void StepSim(SimStepCtx *ctx) +void PP_StepSim(PP_SimStepCtx *ctx) { __prof; TempArena scratch = BeginScratchNoConflict(); b32 is_master = ctx->is_master; - Snapshot *world = ctx->world; + PP_Snapshot *world = ctx->world; - ClientStore *client_store = world->client->store; - Client *world_client = world->client; - Client *user_input_client = ctx->user_input_client; - Client *publish_client = ctx->publish_client; - Client *master_client = ctx->master_client; + PP_ClientStore *client_store = world->client->store; + PP_Client *world_client = world->client; + PP_Client *user_input_client = ctx->user_input_client; + PP_Client *publish_client = ctx->publish_client; + PP_Client *master_client = ctx->master_client; i64 sim_dt_ns = ctx->sim_dt_ns; @@ -897,7 +897,7 @@ void StepSim(SimStepCtx *ctx) world->sim_time_ns += world->sim_dt_ns; f32 sim_dt = SecondsFromNs(world->sim_dt_ns); - Entity *root = EntityFromId(world, RootEntityId); + PP_Ent *root = PP_EntFromKey(world, PP_RootEntKey); root->owner = world->client->player_id; //- Sync ents from cmd producing clients @@ -906,20 +906,20 @@ void StepSim(SimStepCtx *ctx) /* FIXME: Ensure only cmds are synced to master player */ for (u64 client_index = 0; client_index < client_store->num_clients_reserved; ++client_index) { - Client *client = &client_store->clients[client_index]; + PP_Client *client = &client_store->clients[client_index]; if (client->valid && client != master_client && client != world_client && client != publish_client) { - Entity *player = EntityFromId(world, client->player_id); + PP_Ent *player = PP_EntFromKey(world, client->player_id); /* Create player if necessary */ if (is_master && !player->valid) { /* FIXME: Player never released upon disconnect */ - player = AcquireSyncSrc(root); + player = PP_AcquireSyncSrcEnt(root); player->player_client_handle = client->handle; - EnableProp(player, Prop_Player); + PP_EnableProp(player, PP_Prop_Player); player->predictor = player->id; - Activate(player, world->tick); + PP_ActivateEnt(player, world->tick); client->player_id = player->id; if (client == user_input_client) { @@ -927,9 +927,9 @@ void StepSim(SimStepCtx *ctx) world_client->player_id = player->id; world->local_player = player->id; player->owner = player->id; - EnableProp(player, Prop_IsMaster); + PP_EnableProp(player, PP_Prop_IsMaster); } - P_LogInfoF("Created player with id %F for sim client %F. is_master: %F", FmtUid(player->id.uid), FmtHandle(client->handle), FmtUint(HasProp(player, Prop_IsMaster))); + P_LogInfoF("Created player with id %F for sim client %F. is_master: %F", FmtUid(player->id.uid), FmtHandle(client->handle), FmtUint(PP_HasProp(player, PP_Prop_IsMaster))); } /* Update rtt */ @@ -943,10 +943,10 @@ void StepSim(SimStepCtx *ctx) /* Sync ents from client */ if (player->valid) { - Snapshot *src_ss = SnapshotFromTick(client, world->tick); + PP_Snapshot *src_ss = PP_SnapshotFromTick(client, world->tick); if (src_ss->valid) { - SyncSnapshotEntities(world, src_ss, player->id, 0); + PP_SyncSnapshotEnts(world, src_ss, player->id, 0); } } } @@ -955,19 +955,19 @@ void StepSim(SimStepCtx *ctx) /* Mark all incoming ents as sync dsts */ for (u64 i = 0; i < world->num_ents_reserved; ++i) { - Entity *ent = &world->ents[i]; - if (ent->valid && HasProp(ent, Prop_SyncSrc) && !EqId(ent->owner, world_client->player_id)) + PP_Ent *ent = &world->ents[i]; + if (ent->valid && PP_HasProp(ent, PP_Prop_SyncSrc) && !PP_EqEntKey(ent->owner, world_client->player_id)) { - DisableProp(ent, Prop_SyncSrc); - EnableProp(ent, Prop_SyncDst); + PP_DisableProp(ent, PP_Prop_SyncSrc); + PP_EnableProp(ent, PP_Prop_SyncDst); } } /* Mark incoming cmds with correct client */ for (u64 i = 0; i < world->num_ents_reserved; ++i) { - Entity *ent = &world->ents[i]; - if (ent->valid && HasProp(ent, Prop_Cmd) && HasProp(ent, Prop_SyncDst)) + PP_Ent *ent = &world->ents[i]; + if (ent->valid && PP_HasProp(ent, PP_Prop_Cmd) && PP_HasProp(ent, PP_Prop_SyncDst)) { ent->cmd_player = ent->owner; } @@ -978,12 +978,12 @@ void StepSim(SimStepCtx *ctx) { for (u64 i = 0; i < world->num_ents_reserved; ++i) { - Entity *ent = &world->ents[i]; - if (IsValidAndActive(ent) && HasProp(ent, Prop_Cmd)) + PP_Ent *ent = &world->ents[i]; + if (PP_IsValidAndActive(ent) && PP_HasProp(ent, PP_Prop_Cmd)) { - if (!IsNilId(ent->cmd_player) && EqId(ent->cmd_player, world->local_player)) + if (!PP_IsNilEntKey(ent->cmd_player) && PP_EqEntKey(ent->cmd_player, world->local_player)) { - EnableProp(ent, Prop_SyncSrc); + PP_EnableProp(ent, PP_Prop_SyncSrc); } } } @@ -992,24 +992,24 @@ void StepSim(SimStepCtx *ctx) //- Release entities at beginning of frame - ReleaseAllWithProp(world, Prop_Release); - ResetSimAccel(world, ctx->accel); + PP_ReleaseAllWithProp(world, PP_Prop_Release); + PP_ResetAccel(world, ctx->accel); //- Activate entities for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) { - Entity *ent = &world->ents[ent_index]; + PP_Ent *ent = &world->ents[ent_index]; if (!ent->valid) continue; - if (HasProp(ent, Prop_SyncDst) && !IsOwner(ent) && !ShouldPredict(ent)) continue; + if (PP_HasProp(ent, PP_Prop_SyncDst) && !PP_IsOwner(ent) && !PP_ShouldPredict(ent)) continue; - if (!HasProp(ent, Prop_Active)) + if (!PP_HasProp(ent, PP_Prop_Active)) { u64 atick = ent->activation_tick; if (atick != 0 || world->tick >= atick) { - Activate(ent, world->tick); + PP_ActivateEnt(ent, world->tick); } } } @@ -1018,22 +1018,22 @@ void StepSim(SimStepCtx *ctx) for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) { - Entity *cmd_ent = &world->ents[ent_index]; - if (!is_master && !ShouldSimulate(cmd_ent)) continue; + PP_Ent *cmd_ent = &world->ents[ent_index]; + if (!is_master && !PP_ShouldSimulate(cmd_ent)) continue; - if (HasProp(cmd_ent, Prop_Cmd)) + if (PP_HasProp(cmd_ent, PP_Prop_Cmd)) { - Entity *player = EntityFromId(world, cmd_ent->cmd_player); - if (ShouldSimulate(player)) + PP_Ent *player = PP_EntFromKey(world, cmd_ent->cmd_player); + if (PP_ShouldSimulate(player)) { b32 persist_cmd = 0; - if (!is_master && !EqId(player->id, world->local_player)) + if (!is_master && !PP_EqEntKey(player->id, world->local_player)) { /* We are not the master and the command is not our own, skip processing */ continue; } - CmdKind kind = cmd_ent->cmd_kind; + PP_CmdKind kind = cmd_ent->cmd_kind; switch (kind) { default: @@ -1042,17 +1042,17 @@ void StepSim(SimStepCtx *ctx) Assert(0); } break; - case CmdKind_Control: + case PP_CmdKind_Control: { /* Player's will send control cmds a lot, so keep it around to prevent re-creating it each time */ persist_cmd = 1; /* Process control cmd for player */ - ControlData old_control = player->player_control; - ControlData *control = &player->player_control; + PP_ControlData old_control = player->player_control; + PP_ControlData *control = &player->player_control; *control = cmd_ent->cmd_control; { - ControlFlag flags = control->flags; + PP_ControlFlag flags = control->flags; player->player_cursor_pos = control->dbg_cursor; player->player_hovered_ent = cmd_ent->cmd_control_hovered_ent; @@ -1068,33 +1068,33 @@ void StepSim(SimStepCtx *ctx) /* Debug cmds */ if (ctx->is_master) { - if (flags & ControlFlag_Drag) + if (flags & PP_ControlFlag_Drag) { - if (!(old_control.flags & ControlFlag_Drag)) + if (!(old_control.flags & PP_ControlFlag_Drag)) { player->player_dbg_drag_start = 1; } } else { - if (old_control.flags & ControlFlag_Drag) + if (old_control.flags & PP_ControlFlag_Drag) { player->player_dbg_drag_stop = 1; } } - if (flags & ControlFlag_Delete) + if (flags & PP_ControlFlag_Delete) { - Entity *ent = EntityFromId(world, player->player_hovered_ent); + PP_Ent *ent = PP_EntFromKey(world, player->player_hovered_ent); if (ent->valid) { - EnableProp(ent, Prop_Release); + PP_EnableProp(ent, PP_Prop_Release); } } - if (flags & ControlFlag_ClearAll) + if (flags & PP_ControlFlag_ClearAll) { - ClearLevelTest(ctx); + PP_ClearLevelTest(ctx); } - if (flags & ControlFlag_SpawnTest1) + if (flags & PP_ControlFlag_SpawnTest1) { P_LogDebugF("Spawn test 1"); u32 count = 1; @@ -1103,10 +1103,10 @@ void StepSim(SimStepCtx *ctx) { Vec2 pos = player->player_cursor_pos; pos.y += (((f32)j / (f32)count) - 0.5) * spread; - SpawnTestEntities1(root, pos); + PP_SpawnTestEnts1(root, pos); } } - if (flags & ControlFlag_SpawnTest2) + if (flags & PP_ControlFlag_SpawnTest2) { P_LogDebugF("Spawn test 2"); u32 count = 1; @@ -1115,10 +1115,10 @@ void StepSim(SimStepCtx *ctx) { Vec2 pos = player->player_cursor_pos; pos.y += (((f32)j / (f32)count) - 0.5) * spread; - SpawnTestEntities2(root, pos); + PP_SpawnTestEnts2(root, pos); } } - if (flags & ControlFlag_SpawnTest3) + if (flags & PP_ControlFlag_SpawnTest3) { P_LogDebugF("Spawn test 3"); u32 count = 1; @@ -1127,10 +1127,10 @@ void StepSim(SimStepCtx *ctx) { Vec2 pos = player->player_cursor_pos; pos.y += (((f32)j / (f32)count) - 0.5) * spread; - SpawnTestEntities3(root, pos); + PP_SpawnTestEnts3(root, pos); } } - if (flags & ControlFlag_SpawnTest4) + if (flags & PP_ControlFlag_SpawnTest4) { P_LogDebugF("Spawn test 4"); u32 count = 1; @@ -1139,40 +1139,40 @@ void StepSim(SimStepCtx *ctx) { Vec2 pos = player->player_cursor_pos; pos.y += (((f32)j / (f32)count) - 0.5) * spread; - SpawnTestEntities4(root, pos); + PP_SpawnTestEnts4(root, pos); } } - if (flags & ControlFlag_TestWalls) + if (flags & PP_ControlFlag_TestWalls) { - GenerateTestWalls(world); + PP_GenerateTestWalls(world); } - if (flags & ControlFlag_TestExplode) + if (flags & PP_ControlFlag_TestExplode) { P_LogDebugF("Explosion test"); - SpawnTestExplosion(root, player->player_cursor_pos, 100, 2); + PP_SpawnTestExplosion(root, player->player_cursor_pos, 100, 2); } } - if (flags & ControlFlag_TestTiles) + if (flags & PP_ControlFlag_TestTiles) { - SpawnTestTile(world, player->player_cursor_pos); + PP_SpawnTestTile(world, player->player_cursor_pos); } - else if (old_control.flags & ControlFlag_TestTiles) + else if (old_control.flags & PP_ControlFlag_TestTiles) { - GenerateTestWalls(world); + PP_GenerateTestWalls(world); } } } break; #if 0 - case CmdKind_Chat: + case PP_CmdKind_Chat: { struct sim_data_key msg_key = cmd_ent->cmd_chat_msg; String msg = sim_data_from_key(sim_data_store, msg_key); if (msg.len > 0) { - Entity *chat_ent = AcquireSyncSrc(root); - EnableProp(chat_ent, Prop_CHAT); + PP_Ent *chat_ent = PP_AcquireSyncSrcEnt(root); + PP_EnableProp(chat_ent, PP_Prop_CHAT); chat_ent->chat_player = player->id; chat_ent->chat_msg = msg_key; } @@ -1183,7 +1183,7 @@ void StepSim(SimStepCtx *ctx) /* Release cmd */ if (!persist_cmd) { - EnableProp(cmd_ent, Prop_Release); + PP_EnableProp(cmd_ent, PP_Prop_Release); } } } @@ -1193,12 +1193,12 @@ void StepSim(SimStepCtx *ctx) for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) { - Entity *ent = &world->ents[ent_index]; - if (!ShouldSimulate(ent)) continue; + PP_Ent *ent = &world->ents[ent_index]; + if (!PP_ShouldSimulate(ent)) continue; - if (HasProp(ent, Prop_Controlled)) + if (PP_HasProp(ent, PP_Prop_Controlled)) { - Entity *player = EntityFromId(world, ent->controlling_player); + PP_Ent *player = PP_EntFromKey(world, ent->controlling_player); if (player->valid) { ent->control = player->player_control; @@ -1213,28 +1213,28 @@ void StepSim(SimStepCtx *ctx) { for (u64 i = 0; i < world->num_ents_reserved; ++i) { - Entity *ent = &world->ents[i]; - if (!ShouldSimulate(ent)) continue; - if (HasProp(ent, Prop_Player)) + PP_Ent *ent = &world->ents[i]; + if (!PP_ShouldSimulate(ent)) continue; + if (PP_HasProp(ent, PP_Prop_Player)) { /* FIXME: Ents never released when client disconnects */ - Entity *control_ent = EntityFromId(world, ent->player_control_ent); + PP_Ent *control_ent = PP_EntFromKey(world, ent->player_control_ent); if (!control_ent->valid) { - control_ent = SpawnTestEmployee(root); + control_ent = PP_SpawnTestEmployee(root); control_ent->predictor = ent->id; - EnableProp(control_ent, Prop_Controlled); + PP_EnableProp(control_ent, PP_Prop_Controlled); ent->player_control_ent = control_ent->id; control_ent->controlling_player = ent->id; } - Entity *camera_ent = EntityFromId(world, ent->player_camera_ent); + PP_Ent *camera_ent = PP_EntFromKey(world, ent->player_camera_ent); if (!camera_ent->valid) { - camera_ent = SpawnTestCamera(root, control_ent); + camera_ent = PP_SpawnTestCamera(root, control_ent); camera_ent->predictor = ent->id; ent->player_camera_ent = camera_ent->id; } - Entity *camera_follow = EntityFromId(world, camera_ent->camera_follow); + PP_Ent *camera_follow = PP_EntFromKey(world, camera_ent->camera_follow); if (!camera_follow->valid) { camera_ent->camera_follow = control_ent->id; @@ -1247,8 +1247,8 @@ void StepSim(SimStepCtx *ctx) for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) { - Entity *ent = &world->ents[ent_index]; - if (!ShouldSimulate(ent)) continue; + PP_Ent *ent = &world->ents[ent_index]; + if (!PP_ShouldSimulate(ent)) continue; if (IsResourceNil(ent->sprite)) continue; S_Sheet *sheet = S_SheetFromResource(ent->sprite); @@ -1315,7 +1315,7 @@ void StepSim(SimStepCtx *ctx) /* Test collider */ #if 0 - if (HasProp(ent, Prop_Test)) + if (PP_HasProp(ent, PP_Prop_Test)) { //if ((1)) { #if 0 @@ -1354,11 +1354,11 @@ void StepSim(SimStepCtx *ctx) for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) { - Entity *ent = &world->ents[ent_index]; - if (!ShouldSimulate(ent)) continue; - if (!HasProp(ent, Prop_Attached)) continue; + PP_Ent *ent = &world->ents[ent_index]; + if (!PP_ShouldSimulate(ent)) continue; + if (!PP_HasProp(ent, PP_Prop_Attached)) continue; - Entity *parent = EntityFromId(world, ent->parent); + PP_Ent *parent = PP_EntFromKey(world, ent->parent); ResourceKey parent_sprite = parent->sprite; S_Sheet *parent_sheet = S_SheetFromResource(parent_sprite); @@ -1368,42 +1368,42 @@ void StepSim(SimStepCtx *ctx) Vec2 attach_pos = MulXformV2(parent_sprite_xf, attach_slice.center); Vec2 attach_dir = MulXformBasisV2(parent_sprite_xf, attach_slice.dir); - Xform xf = LocalXformFromEntity(ent); + Xform xf = PP_LocalXformFromEnt(ent); xf.og = attach_pos; xf = XformWithWorldRotation(xf, AngleFromVec2(attach_dir) + Pi / 2); - SetLocalXform(ent, xf); + PP_SetLocalXform(ent, xf); } //- Process ent control for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) { - Entity *ent = &world->ents[ent_index]; - if (!ShouldSimulate(ent)) continue; + PP_Ent *ent = &world->ents[ent_index]; + if (!PP_ShouldSimulate(ent)) continue; - if (HasProp(ent, Prop_Controlled)) + if (PP_HasProp(ent, PP_Prop_Controlled)) { - ControlData *control = &ent->control; - ControlFlag flags = control->flags; - if (flags & ControlFlag_Fire) + PP_ControlData *control = &ent->control; + PP_ControlFlag flags = control->flags; + if (flags & PP_ControlFlag_Fire) { - Entity *equipped = EntityFromId(world, ent->equipped); + PP_Ent *equipped = PP_EntFromKey(world, ent->equipped); if (equipped->valid) { ++equipped->num_primary_triggers; } } - if (flags & ControlFlag_AltFire) + if (flags & PP_ControlFlag_AltFire) { - Entity *equipped = EntityFromId(world, ent->equipped); + PP_Ent *equipped = PP_EntFromKey(world, ent->equipped); if (equipped->valid) { ++equipped->num_secondary_triggers; } } - if (flags & ControlFlag_TestTeleport) + if (flags & PP_ControlFlag_TestTeleport) { - TeleportTest(ent, control->dbg_cursor); + PP_TeleportTest(ent, control->dbg_cursor); } } } @@ -1412,8 +1412,8 @@ void StepSim(SimStepCtx *ctx) for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) { - Entity *ent = &world->ents[ent_index]; - if (!ShouldSimulate(ent)) continue; + PP_Ent *ent = &world->ents[ent_index]; + if (!PP_ShouldSimulate(ent)) continue; b32 primary_triggered = ent->num_primary_triggers > 0; b32 secondary_triggered = ent->num_secondary_triggers > 0; @@ -1446,7 +1446,7 @@ void StepSim(SimStepCtx *ctx) } /* Fire smg */ - if (HasProp(ent, Prop_Smg)) + if (PP_HasProp(ent, PP_Prop_Smg)) { if (primary_triggered) { @@ -1459,35 +1459,35 @@ void StepSim(SimStepCtx *ctx) Vec2 rel_dir = MulXformBasisV2(sprite_local_xform, out_slice.dir); /* Spawn bullet */ - Entity *bullet; + PP_Ent *bullet; { - bullet = AcquireSyncSrc(root); + bullet = PP_AcquireSyncSrcEnt(root); - EnableProp(bullet, Prop_Bullet); + PP_EnableProp(bullet, PP_Prop_Bullet); bullet->bullet_src = ent->id; bullet->bullet_src_pos = rel_pos; bullet->bullet_src_dir = rel_dir; //bullet->bullet_launch_velocity = 0.75f; bullet->bullet_launch_velocity = 50.0f; bullet->bullet_knockback = 10; - bullet->layer = Layer_Bullets; + bullet->layer = PP_Layer_Bullets; #if 1 /* Point collider */ bullet->local_collider.points[0] = VEC2(0, 0); bullet->local_collider.count = 1; #else - bullet->sprite = ResourceKeyFromStore(GameResources, Lit("sprite/bullet.ase")); + bullet->sprite = ResourceKeyFromStore(PP_Resources, Lit("sprite/bullet.ase")); bullet->sprite_collider_slice = Lit("shape"); #endif } /* Spawn tracer */ { - Entity *tracer = AcquireSyncSrc(root); + PP_Ent *tracer = PP_AcquireSyncSrcEnt(root); tracer->tracer_fade_duration = 0.025f; - tracer->layer = Layer_Tracers; - EnableProp(tracer, Prop_Tracer); + tracer->layer = PP_Layer_Tracers; + PP_EnableProp(tracer, PP_Prop_Tracer); bullet->bullet_tracer = tracer->id; } @@ -1495,7 +1495,7 @@ void StepSim(SimStepCtx *ctx) } /* Fire launcher */ - if (HasProp(ent, Prop_Launcher)) + if (PP_HasProp(ent, PP_Prop_Launcher)) { if (primary_triggered) { @@ -1508,11 +1508,11 @@ void StepSim(SimStepCtx *ctx) Vec2 rel_dir = MulXformBasisV2(sprite_local_xform, out_slice.dir); /* Spawn bullet */ - Entity *bullet; + PP_Ent *bullet; { - bullet = AcquireSyncSrc(root); + bullet = PP_AcquireSyncSrcEnt(root); - EnableProp(bullet, Prop_Bullet); + PP_EnableProp(bullet, PP_Prop_Bullet); bullet->bullet_src = ent->id; bullet->bullet_src_pos = rel_pos; bullet->bullet_src_dir = rel_dir; @@ -1521,7 +1521,7 @@ void StepSim(SimStepCtx *ctx) bullet->bullet_knockback = 50; bullet->bullet_explosion_strength = 100; bullet->bullet_explosion_radius = 4; - bullet->layer = Layer_Bullets; + bullet->layer = PP_Layer_Bullets; /* Point collider */ bullet->local_collider.points[0] = VEC2(0, 0); @@ -1532,10 +1532,10 @@ void StepSim(SimStepCtx *ctx) /* Spawn tracer */ { - Entity *tracer = AcquireSyncSrc(root); + PP_Ent *tracer = PP_AcquireSyncSrcEnt(root); tracer->tracer_fade_duration = 0.025f; - tracer->layer = Layer_Tracers; - EnableProp(tracer, Prop_Tracer); + tracer->layer = PP_Layer_Tracers; + PP_EnableProp(tracer, PP_Prop_Tracer); bullet->bullet_tracer = tracer->id; } @@ -1543,29 +1543,29 @@ void StepSim(SimStepCtx *ctx) } /* Fire chucker */ - if (HasProp(ent, Prop_Chucker)) + if (PP_HasProp(ent, PP_Prop_Chucker)) { if (primary_triggered) { } if (secondary_triggered) { - Entity *zone = EntityFromId(world, ent->chucker_zone); - Entity *target = EntityFromId(world, zone->chucker_zone_ent); - Entity *old_joint_ent = EntityFromId(world, ent->chucker_joint); - if (IsValidAndActive(target) && zone->chucker_zone_ent_tick == world->tick - 1) + PP_Ent *zone = PP_EntFromKey(world, ent->chucker_zone); + PP_Ent *target = PP_EntFromKey(world, zone->chucker_zone_ent); + PP_Ent *old_joint_ent = PP_EntFromKey(world, ent->chucker_joint); + if (PP_IsValidAndActive(target) && zone->chucker_zone_ent_tick == world->tick - 1) { - if (!EqId(old_joint_ent->weld_joint_data.e1, target->id)) + if (!PP_EqEntKey(old_joint_ent->weld_joint_data.e1, target->id)) { - Entity *joint_ent = AcquireSyncSrc(root); - EnableProp(joint_ent, Prop_Active); + PP_Ent *joint_ent = PP_AcquireSyncSrcEnt(root); + PP_EnableProp(joint_ent, PP_Prop_Active); - Xform xf0 = XformFromEntity(ent); - Xform xf1 = XformFromEntity(target); + Xform xf0 = PP_XformFromEnt(ent); + Xform xf1 = PP_XformFromEnt(target); Xform xf0_to_xf1 = MulXform(InvertXform(xf0), xf1); - EnableProp(joint_ent, Prop_WeldJoint); - WeldJointDesc def = CreateWeldJointDef(); + PP_EnableProp(joint_ent, PP_Prop_WeldJoint); + PP_WeldJointDesc def = PP_CreateWeldJointDef(); def.e0 = ent->id; def.e1 = target->id; def.xf = xf0_to_xf1; @@ -1573,14 +1573,14 @@ void StepSim(SimStepCtx *ctx) def.linear_spring_damp = 0.3f; def.angular_spring_hz = 10; def.angular_spring_damp = 0.3f; - joint_ent->weld_joint_data = WeldJointFromDef(def); + joint_ent->weld_joint_data = PP_WeldJointFromDef(def); ent->chucker_joint = joint_ent->id; } } if (old_joint_ent->valid) { - EnableProp(old_joint_ent, Prop_Release); - DisableProp(old_joint_ent, Prop_Active); + PP_EnableProp(old_joint_ent, PP_Prop_Release); + PP_DisableProp(old_joint_ent, PP_Prop_Active); } } } @@ -1590,36 +1590,36 @@ void StepSim(SimStepCtx *ctx) for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) { - Entity *ent = &world->ents[ent_index]; - if (!ShouldSimulate(ent)) continue; + PP_Ent *ent = &world->ents[ent_index]; + if (!PP_ShouldSimulate(ent)) continue; - if (HasProp(ent, Prop_Controlled)) + if (PP_HasProp(ent, PP_Prop_Controlled)) { - Entity *joint_ent = EntityFromId(world, ent->move_joint); - if (is_master && !IsValidAndActive(joint_ent)) + PP_Ent *joint_ent = PP_EntFromKey(world, ent->move_joint); + if (is_master && !PP_IsValidAndActive(joint_ent)) { - joint_ent = AcquireSyncSrc(root); + joint_ent = PP_AcquireSyncSrcEnt(root); joint_ent->predictor = ent->predictor; joint_ent->mass_unscaled = F32Infinity; joint_ent->inertia_unscaled = F32Infinity; - EnableProp(joint_ent, Prop_Active); - EnableProp(joint_ent, Prop_Kinematic); + PP_EnableProp(joint_ent, PP_Prop_Active); + PP_EnableProp(joint_ent, PP_Prop_Kinematic); ent->move_joint = joint_ent->id; - EnableProp(joint_ent, Prop_MotorJoint); - MotorJointDesc def = CreateMotorJointDef(); + PP_EnableProp(joint_ent, PP_Prop_MotorJoint); + PP_MotorJointDesc def = PP_CreateMotorJointDef(); def.e0 = joint_ent->id; /* Re-using joint entity as e0 */ def.e1 = ent->id; def.correction_rate = 0; def.max_force = ent->control_force; def.max_torque = 0; - joint_ent->motor_joint_data = MotorJointFromDef(def); + joint_ent->motor_joint_data = PP_MotorJointFromDef(def); } - if (ShouldSimulate(joint_ent)) + if (PP_ShouldSimulate(joint_ent)) { - SetXform(joint_ent, XformIdentity); /* Reset joint ent position */ - SetLinearVelocity(joint_ent, MulVec2(ClampVec2Len(ent->control.move, 1), ent->control_force_max_speed)); + PP_SetXform(joint_ent, XformIdentity); /* Reset joint ent position */ + PP_SetLinearVelocity(joint_ent, MulVec2(ClampVec2Len(ent->control.move, 1), ent->control_force_max_speed)); } } } @@ -1629,36 +1629,36 @@ void StepSim(SimStepCtx *ctx) #if SIM_PLAYER_AIM for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) { - Entity *ent = &world->ents[ent_index]; - if (!ShouldSimulate(ent)) continue; + PP_Ent *ent = &world->ents[ent_index]; + if (!PP_ShouldSimulate(ent)) continue; - if (HasProp(ent, Prop_Controlled)) + if (PP_HasProp(ent, PP_Prop_Controlled)) { - Xform xf = XformFromEntity(ent); + Xform xf = PP_XformFromEnt(ent); Xform sprite_xf = MulXform(xf, ent->sprite_local_xform); /* Retrieve / create aim joint */ - Entity *joint_ent = EntityFromId(world, ent->aim_joint); - if (is_master && !IsValidAndActive(joint_ent)) + PP_Ent *joint_ent = PP_EntFromKey(world, ent->aim_joint); + if (is_master && !PP_IsValidAndActive(joint_ent)) { - joint_ent = AcquireSyncSrc(root); + joint_ent = PP_AcquireSyncSrcEnt(root); joint_ent->predictor = ent->predictor; joint_ent->mass_unscaled = F32Infinity; joint_ent->inertia_unscaled = F32Infinity; - EnableProp(joint_ent, Prop_Kinematic); /* Since we'll be setting velocity manually */ - EnableProp(joint_ent, Prop_MotorJoint); - EnableProp(joint_ent, Prop_Active); + PP_EnableProp(joint_ent, PP_Prop_Kinematic); /* Since we'll be setting velocity manually */ + PP_EnableProp(joint_ent, PP_Prop_MotorJoint); + PP_EnableProp(joint_ent, PP_Prop_Active); ent->aim_joint = joint_ent->id; - MotorJointDesc def = CreateMotorJointDef(); + PP_MotorJointDesc def = PP_CreateMotorJointDef(); def.e0 = joint_ent->id; /* Re-using joint entity as e0 */ def.e1 = ent->id; def.max_force = 0; def.max_torque = ent->control_torque; - joint_ent->motor_joint_data = MotorJointFromDef(def); + joint_ent->motor_joint_data = PP_MotorJointFromDef(def); } - if (ShouldSimulate(joint_ent)) + if (PP_ShouldSimulate(joint_ent)) { /* Set correction rate dynamically since motor velocity is only set for one frame */ joint_ent->motor_joint_data.correction_rate = 10 * sim_dt; @@ -1712,7 +1712,7 @@ void StepSim(SimStepCtx *ctx) if (!IsF32Nan(new_angle)) { const f32 angle_error_allowed = 0.001f; - Xform joint_xf = XformFromEntity(joint_ent); + Xform joint_xf = PP_XformFromEnt(joint_ent); f32 diff = UnwindAngleF32(new_angle - RotationFromXform(joint_xf)); if (AbsF32(diff) > angle_error_allowed) { @@ -1720,7 +1720,7 @@ void StepSim(SimStepCtx *ctx) new_vel = diff / sim_dt; } } - SetAngularVelocity(joint_ent, new_vel); + PP_SetAngularVelocity(joint_ent, new_vel); } } @@ -1732,13 +1732,13 @@ void StepSim(SimStepCtx *ctx) #if 1 for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) { - Entity *ent = &world->ents[ent_index]; - if (!ShouldSimulate(ent)) continue; - if (!HasProp(ent, Prop_Dynamic)) continue; + PP_Ent *ent = &world->ents[ent_index]; + if (!PP_ShouldSimulate(ent)) continue; + if (!PP_HasProp(ent, PP_Prop_Dynamic)) continue; - Entity *joint_ent = EntityFromId(world, ent->ground_friction_joint); + PP_Ent *joint_ent = PP_EntFromKey(world, ent->ground_friction_joint); - MotorJointDesc def = CreateMotorJointDef(); + PP_MotorJointDesc def = PP_CreateMotorJointDef(); def.e0 = root->id; def.e1 = ent->id; def.correction_rate = 0; @@ -1746,13 +1746,13 @@ void StepSim(SimStepCtx *ctx) def.max_torque = ent->angular_ground_friction; if (joint_ent->motor_joint_data.max_force != def.max_force || joint_ent->motor_joint_data.max_torque != def.max_torque) { - if (is_master && !IsValidAndActive(joint_ent)) + if (is_master && !PP_IsValidAndActive(joint_ent)) { - joint_ent = AcquireSyncSrc(root); + joint_ent = PP_AcquireSyncSrcEnt(root); joint_ent->predictor = ent->predictor; - EnableProp(joint_ent, Prop_MotorJoint); - EnableProp(joint_ent, Prop_Active); - joint_ent->motor_joint_data = MotorJointFromDef(def); + PP_EnableProp(joint_ent, PP_Prop_MotorJoint); + PP_EnableProp(joint_ent, PP_Prop_Active); + joint_ent->motor_joint_data = PP_MotorJointFromDef(def); ent->ground_friction_joint = joint_ent->id; } } @@ -1765,43 +1765,43 @@ void StepSim(SimStepCtx *ctx) { for (u64 i = 0; i < world->num_ents_reserved; ++i) { - Entity *player = &world->ents[i]; - if (!ShouldSimulate(player)) continue; - if (!HasProp(player, Prop_Player)) continue; + PP_Ent *player = &world->ents[i]; + if (!PP_ShouldSimulate(player)) continue; + if (!PP_HasProp(player, PP_Prop_Player)) continue; Vec2 cursor = player->player_cursor_pos; b32 start_dragging = player->player_dbg_drag_start; b32 stop_dragging = player->player_dbg_drag_stop; - Entity *joint_ent = EntityFromId(world, player->player_dbg_drag_joint_ent); - Entity *target_ent = EntityFromId(world, joint_ent->mouse_joint_data.target); + PP_Ent *joint_ent = PP_EntFromKey(world, player->player_dbg_drag_joint_ent); + PP_Ent *target_ent = PP_EntFromKey(world, joint_ent->mouse_joint_data.target); if (stop_dragging) { - target_ent = NilEntity(); + target_ent = PP_NilEnt(); } else if (start_dragging) { - target_ent = EntityFromId(world, player->player_hovered_ent); + target_ent = PP_EntFromKey(world, player->player_hovered_ent); } - if (ShouldSimulate(target_ent)) + if (PP_ShouldSimulate(target_ent)) { - if (!IsValidAndActive(joint_ent)) + if (!PP_IsValidAndActive(joint_ent)) { /* FIXME: Joint ent may never release */ - joint_ent = AcquireLocal(root); + joint_ent = PP_AcquireLocalEnt(root); joint_ent->mass_unscaled = F32Infinity; joint_ent->inertia_unscaled = F32Infinity; player->player_dbg_drag_joint_ent = joint_ent->id; - EnableProp(joint_ent, Prop_MouseJoint); - EnableProp(joint_ent, Prop_Active); + PP_EnableProp(joint_ent, PP_Prop_MouseJoint); + PP_EnableProp(joint_ent, PP_Prop_Active); } - Xform xf = XformFromEntity(target_ent); + Xform xf = PP_XformFromEnt(target_ent); - MouseJointDesc def = CreateMouseJointDef(); + PP_MouseJointDesc def = PP_CreateMouseJointDef(); def.target = target_ent->id; - if (EqId(joint_ent->mouse_joint_data.target, target_ent->id)) + if (PP_EqEntKey(joint_ent->mouse_joint_data.target, target_ent->id)) { def.point_local_start = joint_ent->mouse_joint_data.point_local_start; } @@ -1815,9 +1815,9 @@ void StepSim(SimStepCtx *ctx) def.linear_spring_damp = 0.7f; def.angular_spring_hz = 1; def.angular_spring_damp = 0.1f; - joint_ent->mouse_joint_data = MouseJointFromDef(def); + joint_ent->mouse_joint_data = PP_MouseJointFromDef(def); } - else if (IsValidAndActive(joint_ent)) + else if (PP_IsValidAndActive(joint_ent)) { joint_ent->mouse_joint_data.target = target_ent->id; } @@ -1827,33 +1827,33 @@ void StepSim(SimStepCtx *ctx) //- Physics step { - PhysStepCtx phys = ZI; + PP_PhysStepCtx phys = ZI; phys.sim_step_ctx = ctx; - phys.collision_callback = OnEntityCollision; - StepPhys(&phys, sim_dt); + phys.collision_callback = PP_OnEntCollision; + PP_StepPhys(&phys, sim_dt); } //- Update explosions for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) { - Entity *ent = &world->ents[ent_index]; - if (!ShouldSimulate(ent)) continue; - if (!HasProp(ent, Prop_Explosion)) continue; + PP_Ent *ent = &world->ents[ent_index]; + if (!PP_ShouldSimulate(ent)) continue; + if (!PP_HasProp(ent, PP_Prop_Explosion)) continue; /* Explosion doesn't need to generate any more collisions after initial physics step */ - DisableProp(ent, Prop_Sensor); + PP_DisableProp(ent, PP_Prop_Sensor); } //- Update tracers for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) { - Entity *ent = &world->ents[ent_index]; - if (!ShouldSimulate(ent)) continue; - if (!HasProp(ent, Prop_Tracer)) continue; + PP_Ent *ent = &world->ents[ent_index]; + if (!PP_ShouldSimulate(ent)) continue; + if (!PP_HasProp(ent, PP_Prop_Tracer)) continue; - Vec2 end = XformFromEntity(ent).og; + Vec2 end = PP_XformFromEnt(ent).og; Vec2 tick_velocity = MulVec2(ent->tracer_start_velocity, sim_dt); Vec2 gradient_start = AddVec2(ent->tracer_gradient_start, tick_velocity); @@ -1862,7 +1862,7 @@ void StepSim(SimStepCtx *ctx) if (DotVec2(tick_velocity, SubVec2(gradient_start, end)) > 0) { /* Tracer has disappeared */ - EnableProp(ent, Prop_Release); + PP_EnableProp(ent, PP_Prop_Release); } ent->tracer_gradient_start = gradient_start; @@ -1873,18 +1873,18 @@ void StepSim(SimStepCtx *ctx) for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) { - Entity *ent = &world->ents[ent_index]; - if (!ShouldSimulate(ent)) continue; - if (!HasProp(ent, Prop_Bullet)) continue; + PP_Ent *ent = &world->ents[ent_index]; + if (!PP_ShouldSimulate(ent)) continue; + if (!PP_HasProp(ent, PP_Prop_Bullet)) continue; if (ent->activation_tick == world->tick) { - Entity *src = EntityFromId(world, ent->bullet_src); - Xform src_xf = XformFromEntity(src); + PP_Ent *src = PP_EntFromKey(world, ent->bullet_src); + Xform src_xf = PP_XformFromEnt(src); /* Activate collision */ - EnableProp(ent, Prop_Sensor); - EnableProp(ent, Prop_Toi); + PP_EnableProp(ent, PP_Prop_Sensor); + PP_EnableProp(ent, PP_Prop_Toi); Vec2 pos = MulXformV2(src_xf, ent->bullet_src_pos); Vec2 vel = MulXformBasisV2(src_xf, ent->bullet_src_dir); @@ -1894,24 +1894,24 @@ void StepSim(SimStepCtx *ctx) /* Add shooter velocity to bullet */ { /* TODO: Add angular velocity as well? */ - Entity *top = EntityFromId(ss_blended, src->top); + PP_Ent *top = PP_EntFromKey(ss_blended, src->top); impulse = AddVec2(impulse, MulVec2(top->linear_velocity, dt)); } #endif Xform xf = XformFromTrs(TRS(.t = pos, .r = AngleFromVec2(vel) + Pi / 2)); - SetXform(ent, xf); + PP_SetXform(ent, xf); - EnableProp(ent, Prop_Kinematic); - SetLinearVelocity(ent, vel); + PP_EnableProp(ent, PP_Prop_Kinematic); + PP_SetLinearVelocity(ent, vel); /* Initialize tracer */ - Entity *tracer = EntityFromId(world, ent->bullet_tracer); - if (ShouldSimulate(tracer)) + PP_Ent *tracer = PP_EntFromKey(world, ent->bullet_tracer); + if (PP_ShouldSimulate(tracer)) { - SetXform(tracer, xf); - EnableProp(tracer, Prop_Kinematic); - SetLinearVelocity(tracer, ent->linear_velocity); + PP_SetXform(tracer, xf); + PP_EnableProp(tracer, PP_Prop_Kinematic); + PP_SetLinearVelocity(tracer, ent->linear_velocity); tracer->tracer_start = pos; tracer->tracer_start_velocity = ent->linear_velocity; tracer->tracer_gradient_end = pos; @@ -1920,11 +1920,11 @@ void StepSim(SimStepCtx *ctx) /* Spawn quake */ { - Entity *quake = AcquireSyncSrc(root); - SetXform(quake, XformFromPos(pos)); + PP_Ent *quake = PP_AcquireSyncSrcEnt(root); + PP_SetXform(quake, XformFromPos(pos)); quake->quake_intensity = 0.2f; quake->quake_fade = quake->quake_intensity / 0.1f; - EnableProp(quake, Prop_Quake); + PP_EnableProp(quake, PP_Prop_Quake); } } } @@ -1933,19 +1933,19 @@ void StepSim(SimStepCtx *ctx) for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) { - Entity *ent = &world->ents[ent_index]; - if (!ShouldSimulate(ent)) continue; - if (!HasProp(ent, Prop_Camera)) continue; + PP_Ent *ent = &world->ents[ent_index]; + if (!PP_ShouldSimulate(ent)) continue; + if (!PP_HasProp(ent, PP_Prop_Camera)) continue; - Xform xf = XformFromEntity(ent); + Xform xf = PP_XformFromEnt(ent); /* Camera follow */ { - Entity *follow = EntityFromId(world, ent->camera_follow); + PP_Ent *follow = PP_EntFromKey(world, ent->camera_follow); f32 aspect_ratio = 1.0; { - Xform quad_xf = MulXform(XformFromEntity(ent), ent->camera_quad_xform); + Xform quad_xf = MulXform(PP_XformFromEnt(ent), ent->camera_quad_xform); Vec2 camera_size = ScaleFromXform(quad_xf); if (!IsVec2Zero(camera_size)) { @@ -1955,7 +1955,7 @@ void StepSim(SimStepCtx *ctx) f32 ratio_y = 0.33f; f32 ratio_x = ratio_y / aspect_ratio; Vec2 camera_focus_dir = MulVec2Vec2(follow->control.focus, VEC2(ratio_x, ratio_y)); - Vec2 camera_focus_pos = AddVec2(XformFromEntity(follow).og, camera_focus_dir); + Vec2 camera_focus_pos = AddVec2(PP_XformFromEnt(follow).og, camera_focus_dir); ent->camera_xform_target = xf; ent->camera_xform_target.og = camera_focus_pos; @@ -1979,28 +1979,28 @@ void StepSim(SimStepCtx *ctx) ent->shake = 0; for (u64 quake_ent_index = 0; quake_ent_index < world->num_ents_reserved; ++quake_ent_index) { - Entity *quake = &world->ents[quake_ent_index]; - if (!ShouldSimulate(quake)) continue; - if (!HasProp(quake, Prop_Quake)) continue; + PP_Ent *quake = &world->ents[quake_ent_index]; + if (!PP_ShouldSimulate(quake)) continue; + if (!PP_HasProp(quake, PP_Prop_Quake)) continue; ent->shake += quake->quake_intensity; } } - SetXform(ent, xf); + PP_SetXform(ent, xf); } //- Update quakes for (u64 ent_index = 0; ent_index < world->num_ents_reserved; ++ent_index) { - Entity *ent = &world->ents[ent_index]; - if (!ShouldSimulate(ent)) continue; - if (!HasProp(ent, Prop_Quake)) continue; + PP_Ent *ent = &world->ents[ent_index]; + if (!PP_ShouldSimulate(ent)) continue; + if (!PP_HasProp(ent, PP_Prop_Quake)) continue; ent->quake_intensity = MaxF32(0, ent->quake_intensity - (ent->quake_fade * sim_dt)); if (ent->quake_intensity <= 0) { - EnableProp(ent, Prop_Release); + PP_EnableProp(ent, PP_Prop_Release); } } @@ -2009,23 +2009,23 @@ void StepSim(SimStepCtx *ctx) { TempArena temp = BeginTempArena(scratch.arena); - Entity **stack = PushStructNoZero(temp.arena, Entity *); + PP_Ent **stack = PushStructNoZero(temp.arena, PP_Ent *); u64 stack_count = 1; *stack = root; while (stack_count > 0) { - Entity *parent; - PopStruct(temp.arena, Entity *, &parent); + PP_Ent *parent; + PopStruct(temp.arena, PP_Ent *, &parent); --stack_count; i32 parent_layer = parent->final_layer; - for (Entity *child = EntityFromId(world, parent->first); child->valid; child = EntityFromId(world, child->next)) + for (PP_Ent *child = PP_EntFromKey(world, parent->first); child->valid; child = PP_EntFromKey(world, child->next)) { - if (ShouldSimulate(child)) + if (PP_ShouldSimulate(child)) { child->final_layer = parent_layer + child->layer; - *PushStructNoZero(temp.arena, Entity *) = child; + *PushStructNoZero(temp.arena, PP_Ent *) = child; ++stack_count; } } @@ -2036,26 +2036,26 @@ void StepSim(SimStepCtx *ctx) //- Release entities at end of frame - ReleaseAllWithProp(world, Prop_Release); + PP_ReleaseAllWithProp(world, PP_Prop_Release); //- Sync to publish client if (publish_client->valid && world->tick > publish_client->last_tick) { - Snapshot *prev_pub_world = SnapshotFromTick(publish_client, publish_client->last_tick); - Snapshot *pub_world = AcquireSnapshot(publish_client, prev_pub_world, world->tick); + PP_Snapshot *prev_pub_world = PP_SnapshotFromTick(publish_client, publish_client->last_tick); + PP_Snapshot *pub_world = PP_AcquireSnapshot(publish_client, prev_pub_world, world->tick); /* Sync */ - SyncSnapshotEntities(pub_world, world, world_client->player_id, 0); + PP_SyncSnapshotEnts(pub_world, world, world_client->player_id, 0); /* Mark all synced ents as both sync dsts & sync srcs */ for (u64 ent_index = 2; ent_index < pub_world->num_ents_reserved; ++ent_index) { - Entity *ent = &pub_world->ents[ent_index]; + PP_Ent *ent = &pub_world->ents[ent_index]; if (ent->valid) { - EnableProp(ent, Prop_SyncDst); - EnableProp(ent, Prop_SyncSrc); + PP_EnableProp(ent, PP_Prop_SyncDst); + PP_EnableProp(ent, PP_Prop_SyncSrc); } } diff --git a/src/pp/pp_step.h b/src/pp/pp_step.h index 2bee3943..838bfc06 100644 --- a/src/pp/pp_step.h +++ b/src/pp/pp_step.h @@ -4,65 +4,65 @@ /* Structure used to accelerate up entity lookup (rebuilt every step) */ /* TODO: Remove this and do something better. Just a hack to de-couple old sim ctx from step. */ -Struct(SimAccel) +Struct(PP_Accel) { - Space *space; + PP_Space *space; }; //////////////////////////////////////////////////////////// //~ Step ctx -Struct(SimStepCtx) +Struct(PP_SimStepCtx) { b32 is_master; - SimAccel *accel; + PP_Accel *accel; RandState rand; /* TODO: Replace with per-sim rand for deterministic rng */ - Snapshot *world; /* The world to simulate */ + PP_Snapshot *world; /* The world to simulate */ i64 sim_dt_ns; /* How much sim time should progress */ - Client *user_input_client; /* The client that contains input from the user thread */ - Client *master_client; /* The master client to read snapshots from (nil if world is master) */ - Client *publish_client; /* The publish client to write syncable state to (nil if skipping publish) */ + PP_Client *user_input_client; /* The client that contains input from the user thread */ + PP_Client *master_client; /* The master client to read snapshots from (nil if world is master) */ + PP_Client *publish_client; /* The publish client to write syncable state to (nil if skipping publish) */ }; //////////////////////////////////////////////////////////// //~ Accel operations -SimAccel AcquireSimAccel(void); -void ReleaseSimAccel(SimAccel *accel); -void ResetSimAccel(Snapshot *ss, SimAccel *accel); +PP_Accel PP_AcquireAccel(void); +void PP_ReleaseAccel(PP_Accel *accel); +void PP_ResetAccel(PP_Snapshot *ss, PP_Accel *accel); //////////////////////////////////////////////////////////// //~ Spawn test operations -Entity *SpawnTestSmg(Entity *parent); -Entity *SpawnTestLauncher(Entity *parent); -Entity *SpawnTestChucker(Entity *parent); -Entity *SpawnTestEmployee(Entity *parent); -Entity *SpawnTestCamera(Entity *parent, Entity *follow); -Entity *SpawnTestExplosion(Entity *parent, Vec2 pos, f32 strength, f32 radius); -void TeleportTest(Entity *ent, Vec2 pos); -void SpawnTestEntities1(Entity *parent, Vec2 pos); -void SpawnTestEntities2(Entity *parent, Vec2 pos); -void SpawnTestEntities3(Entity *parent, Vec2 pos); -void SpawnTestEntities4(Entity *parent, Vec2 pos); -void SpawnTestTile(Snapshot *world, Vec2 world_pos); -void ClearLevelTest(SimStepCtx *ctx); +PP_Ent *PP_SpawnTestSmg(PP_Ent *parent); +PP_Ent *PP_SpawnTestLauncher(PP_Ent *parent); +PP_Ent *PP_SpawnTestChucker(PP_Ent *parent); +PP_Ent *PP_SpawnTestEmployee(PP_Ent *parent); +PP_Ent *PP_SpawnTestCamera(PP_Ent *parent, PP_Ent *follow); +PP_Ent *PP_SpawnTestExplosion(PP_Ent *parent, Vec2 pos, f32 strength, f32 radius); +void PP_TeleportTest(PP_Ent *ent, Vec2 pos); +void PP_SpawnTestEnts1(PP_Ent *parent, Vec2 pos); +void PP_SpawnTestEnts2(PP_Ent *parent, Vec2 pos); +void PP_SpawnTestEnts3(PP_Ent *parent, Vec2 pos); +void PP_SpawnTestEnts4(PP_Ent *parent, Vec2 pos); +void PP_SpawnTestTile(PP_Snapshot *world, Vec2 world_pos); +void PP_ClearLevelTest(PP_SimStepCtx *ctx); //////////////////////////////////////////////////////////// //~ Tile test operations -MergesortCompareFuncDef(SortTileXCmp, arg_a, arg_b, _); -MergesortCompareFuncDef(SortTileYCmp, arg_a, arg_b, _); -void GenerateTestWalls(Snapshot *world); +MergesortCompareFuncDef(PP_SortTileXCmp, arg_a, arg_b, _); +MergesortCompareFuncDef(PP_SortTileYCmp, arg_a, arg_b, _); +void PP_GenerateTestWalls(PP_Snapshot *world); //////////////////////////////////////////////////////////// //~ Collision response -CollisionCallbackFuncDef(OnEntityCollision, data, step_ctx); +PP_CollisionCallbackFuncDef(PP_OnEntCollision, data, step_ctx); //////////////////////////////////////////////////////////// //~ Step -void StepSim(SimStepCtx *ctx); +void PP_StepSim(PP_SimStepCtx *ctx);