diff --git a/src/pp/pp_core.c b/src/pp/pp_core.c index 998ba6a0..decfce4b 100644 --- a/src/pp/pp_core.c +++ b/src/pp/pp_core.c @@ -166,12 +166,12 @@ String DebugStringFromEntity(Arena *arena, Entity *ent) result.len += PushString(arena, Lit("\n")).len; } - if (!EqEntityId(ent->parent, RootEntityId)) + if (!EqId(ent->parent, RootEntityId)) { result.len += StringFormat(arena, Lit("parent: [%F]\n"), FmtUid(ent->parent.uid)).len; } - if (!IsNilEntityId(ent->next) || !IsNilEntityId(ent->prev)) + if (!IsNilId(ent->next) || !IsNilId(ent->prev)) { result.len += StringFormat(arena, Lit("prev: [%F]\n"), FmtUid(ent->prev.uid)).len; result.len += StringFormat(arena, Lit("next: [%F]\n"), FmtUid(ent->next.uid)).len; @@ -191,10 +191,10 @@ String DebugStringFromEntity(Arena *arena, Entity *ent) result.len += StringFormat(arena, Lit("collision dir: (%F, %F)\n"), FmtFloat(ent->collision_dir.x), FmtFloat(ent->collision_dir.y)).len; /* Children */ - if (!IsNilEntityId(ent->first) || !IsNilEntityId(ent->last)) + if (!IsNilId(ent->first) || !IsNilId(ent->last)) { Entity *child = EntityFromId(ss, ent->first); - if (!EqEntityId(ent->first, ent->last) || !child->valid) + if (!EqId(ent->first, ent->last) || !child->valid) { result.len += StringFormat(arena, Lit("first child: [%F]\n"), FmtUid(ent->first.uid)).len; result.len += StringFormat(arena, Lit("last child: [%F]\n"), FmtUid(ent->last.uid)).len; @@ -685,7 +685,7 @@ void UpdateUser(P_Window *window) { if (g->bind_states[BindKind_DebugFollow].num_presses > 0) { - if (IsNilEntityId(g->debug_following)) + if (IsNilId(g->debug_following)) { g->debug_following = hovered_ent->id; } @@ -694,7 +694,7 @@ void UpdateUser(P_Window *window) g->debug_following = NilEntityId; } } - if (!IsNilEntityId(g->debug_following)) + if (!IsNilId(g->debug_following)) { Entity *follow_ent = EntityFromId(g->ss_blended, g->debug_following); Entity *follow_camera = NilEntity(); @@ -746,7 +746,7 @@ void UpdateUser(P_Window *window) Xform xf = XformFromEntity(ent); xf.og = AddVec2(xf.og, MulVec2(vec, shake)); - SetEntityXform(ent, xf); + SetXform(ent, xf); } } @@ -1212,7 +1212,7 @@ void UpdateUser(P_Window *window) } /* Draw focus arrow */ - if (ent == local_control || EqEntityId(ent->id, g->debug_following)) + if (ent == local_control || EqId(ent->id, g->debug_following)) { S_Sheet *sheet = S_SheetFromTagAsync(sprite_frame_scope, ent->sprite); S_Slice slice = S_SliceFromNameIndex(sheet, Lit("attach.wep"), ent->animation_frame); @@ -2086,14 +2086,14 @@ void GenerateuserInputCmds(Client *user_input_client, u64 tick) Snapshot *user_input_ss = sim_snapshot_acquire(user_input_client, prev_user_input_ss, tick); Entity *user_input_root = EntityFromId(user_input_ss, RootEntityId); /* Find / create local control cmd ent */ - Entity *control_cmd = FirstEntityWithProp(user_input_ss, Prop_Cmd); + Entity *control_cmd = FirstWithProp(user_input_ss, Prop_Cmd); if (!control_cmd->valid) { - control_cmd = AcquireSyncSrcEntity(user_input_root); + control_cmd = AcquireSyncSrc(user_input_root); control_cmd->cmd_kind = SIM_CMD_KIND_CONTROL; control_cmd->predictor = user_input_client->player_id; EnableProp(control_cmd, Prop_Cmd); - ActivateEntity(control_cmd, user_input_ss->tick); + Activate(control_cmd, user_input_ss->tick); } { Lock lock = LockE(&g->user_sim_cmd_mutex); @@ -2106,7 +2106,7 @@ void GenerateuserInputCmds(Client *user_input_client, u64 tick) /* Create chat cmd */ if (g->user_sim_cmd_chat.len > 0) { - Entity *chat_cmd = AcquireSyncSrcEntity(user_input_root); + Entity *chat_cmd = AcquireSyncSrc(user_input_root); chat_cmd->cmd_kind = SIM_CMD_KIND_CHAT; //chat_cmd->chat_msg = ZI } @@ -2620,7 +2620,7 @@ JobDef(SimJob, UNUSED sig, UNUSED id) if (master_ss->valid) { - Entity *master_player = FirstEntityWithProp(master_ss, Prop_IsMaster); + Entity *master_player = FirstWithProp(master_ss, Prop_IsMaster); /* Update ent id from master */ { diff --git a/src/pp/pp_ent.c b/src/pp/pp_ent.c index f09f5e39..dd0d0acc 100644 --- a/src/pp/pp_ent.c +++ b/src/pp/pp_ent.c @@ -1,7 +1,7 @@ //////////////////////////////// //~ Acquire -Entity *AcquireEntityRaw(Snapshot *ss, Entity *parent, EntityId id) +Entity *AcquireRaw(Snapshot *ss, Entity *parent, EntityId id) { Assert(parent->valid); Assert(ss->valid); @@ -24,52 +24,52 @@ Entity *AcquireEntityRaw(Snapshot *ss, Entity *parent, EntityId id) ++ss->num_ents_allocated; SetEntityId(ent, id); - LinkEntity(ent, parent); + Link(ent, parent); return ent; } /* Acquires a new entity that will not sync */ -Entity *AcquireLocalEntity(Entity *parent) +Entity *AcquireLocal(Entity *parent) { Snapshot *ss = parent->ss; - Entity *e = AcquireEntityRaw(ss, parent, RandomEntityId()); + Entity *e = AcquireRaw(ss, parent, RandomId()); e->owner = ss->local_player; return e; } -Entity *AcquireLocalEntityWithId(Entity *parent, EntityId id) +Entity *AcquireLocalWithId(Entity *parent, EntityId id) { Snapshot *ss = parent->ss; - Entity *e = AcquireEntityRaw(ss, parent, id); + Entity *e = AcquireRaw(ss, parent, id); e->owner = ss->local_player; return e; } /* Acquires a new entity to be synced to clients */ -Entity *AcquireSyncSrcEntity(Entity *parent) +Entity *AcquireSyncSrc(Entity *parent) { Snapshot *ss = parent->ss; - Entity *e = AcquireEntityRaw(ss, parent, RandomEntityId()); + Entity *e = AcquireRaw(ss, parent, RandomId()); EnableProp(e, Prop_SyncSrc); e->owner = ss->local_player; return e; } -Entity *AcquireSyncSrcEntityWithId(Entity *parent, EntityId id) +Entity *AcquireSyncSrcWithId(Entity *parent, EntityId id) { Snapshot *ss = parent->ss; - Entity *e = AcquireEntityRaw(ss, parent, id); + Entity *e = AcquireRaw(ss, parent, id); EnableProp(e, 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 *AcquireSyncDstEntity(Entity *parent, EntityId ent_id, EntityId owner_id) +Entity *AcquireSyncDst(Entity *parent, EntityId ent_id, EntityId owner_id) { Snapshot *ss = parent->ss; - Entity *e = AcquireEntityRaw(ss, parent, ent_id); + Entity *e = AcquireRaw(ss, parent, ent_id); EnableProp(e, Prop_SyncDst); e->owner = owner_id; return e; @@ -78,14 +78,14 @@ Entity *AcquireSyncDstEntity(Entity *parent, EntityId ent_id, EntityId owner_id) //////////////////////////////// //~ Release -void ReleaseEntityRaw(Entity *ent) +void ReleaseRaw(Entity *ent) { Snapshot *ss = ent->ss; /* Release children */ Entity *child = EntityFromId(ss, ent->first); while (child->valid) { Entity *next = EntityFromId(ss, child->next); - ReleaseEntityRaw(child); + ReleaseRaw(child); child = next; } @@ -99,17 +99,17 @@ void ReleaseEntityRaw(Entity *ent) --ss->num_ents_allocated; } -void ReleaseEntity(Entity *ent) +void Release(Entity *ent) { Snapshot *ss = ent->ss; Entity *parent = EntityFromId(ss, ent->parent); if (parent->valid) { - UnlinkEntity(ent); + Unlink(ent); } - ReleaseEntityRaw(ent); + ReleaseRaw(ent); } -void ReleaseAllEntitiesWithProp(Snapshot *ss, Prop prop) +void ReleaseAllWithProp(Snapshot *ss, Prop prop) { TempArena scratch = BeginScratchNoConflict(); @@ -129,7 +129,7 @@ void ReleaseAllEntitiesWithProp(Snapshot *ss, Prop prop) 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)) { - ReleaseEntity(ent); + Release(ent); } } @@ -139,7 +139,7 @@ void ReleaseAllEntitiesWithProp(Snapshot *ss, Prop prop) //////////////////////////////// //~ Activate -void ActivateEntity(Entity *ent, u64 current_tick) +void Activate(Entity *ent, u64 current_tick) { EnableProp(ent, Prop_Active); ent->activation_tick = current_tick; @@ -163,7 +163,7 @@ Entity *EntityFromIndex(Snapshot *ss, u32 index) } } -EntBin *BinFromEntityId(Snapshot *ss, EntityId id) +EntBin *BinFromId(Snapshot *ss, EntityId id) { return &ss->id_bins[id.uid.lo % ss->num_id_bins]; } @@ -173,10 +173,10 @@ void SetEntityId(Entity *ent, EntityId id) { Snapshot *ss = ent->ss; EntityId old_id = ent->id; - if (!EqEntityId(old_id, id)) { + if (!EqId(old_id, id)) { /* Release old from lookup */ - if (!IsNilEntityId(old_id)) { - EntBin *bin = BinFromEntityId(ss, old_id); + if (!IsNilId(old_id)) { + EntBin *bin = BinFromId(ss, old_id); u32 prev_index = 0; u32 next_index = 0; u32 search_index = bin->first; @@ -186,7 +186,7 @@ void SetEntityId(Entity *ent, EntityId id) while (search->valid) { next_index = search->next_in_id_bin; next = EntityFromIndex(ss, next_index); - if (EqEntityId(search->id, old_id)) { + if (EqId(search->id, old_id)) { break; } prev_index = search_index; @@ -212,7 +212,7 @@ void SetEntityId(Entity *ent, EntityId id) } /* Insert new id into lookup */ - if (!IsNilEntityId(id)) { + if (!IsNilId(id)) { #if RtcIsEnabled { Entity *existing = EntityFromId(ss, id); @@ -221,7 +221,7 @@ void SetEntityId(Entity *ent, EntityId id) } #endif - EntBin *bin = BinFromEntityId(ss, id); + EntBin *bin = BinFromId(ss, id); u32 ent_index = IndexFromEntity(ss, ent); Entity *last = EntityFromIndex(ss, bin->last); if (last->valid) { @@ -242,10 +242,10 @@ void SetEntityId(Entity *ent, EntityId id) Entity *EntityFromId(Snapshot *ss, EntityId id) { Entity *result = NilEntity(); - if (!IsNilEntityId(id) && ss->valid) { - EntBin *bin = BinFromEntityId(ss, id); + if (!IsNilId(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)) { - if (EqEntityId(e->id, id)) { + if (EqId(e->id, id)) { result = e; break; } @@ -254,7 +254,7 @@ Entity *EntityFromId(Snapshot *ss, EntityId id) return result; } -EntityId RandomEntityId(void) +EntityId RandomId(void) { EntityId result = ZI; result.uid = UidFromTrueRand(); @@ -295,7 +295,7 @@ EntityId TileChunkIdFromIndex(Vec2I32 chunk_index) //////////////////////////////// //~ Query -Entity *FirstEntityWithProp(Snapshot *ss, Prop prop) +Entity *FirstWithProp(Snapshot *ss, Prop prop) { u64 count = ss->num_ents_reserved; Entity *entities = ss->ents; @@ -308,7 +308,7 @@ Entity *FirstEntityWithProp(Snapshot *ss, Prop prop) return NilEntity(); } -Entity *FirstEntityWithAllProps(Snapshot *ss, PropArray props) +Entity *FirstWithAllProps(Snapshot *ss, PropArray props) { u64 count = ss->num_ents_reserved; Entity *entities = ss->ents; @@ -333,14 +333,14 @@ Entity *FirstEntityWithAllProps(Snapshot *ss, PropArray props) //////////////////////////////// //~ Tree -void LinkEntity(Entity *ent, Entity *parent) +void Link(Entity *ent, Entity *parent) { Snapshot *ss = ent->ss; Entity *old_parent = EntityFromId(ss, ent->parent); if (old_parent->valid) { /* Unlink from current parent */ - UnlinkEntity(ent); + Unlink(ent); } EntityId ent_id = ent->id; @@ -365,7 +365,7 @@ void LinkEntity(Entity *ent, Entity *parent) } /* NOTE: Entity will be dangling after calling this, should re-link to root ent. */ -void UnlinkEntity(Entity *ent) +void Unlink(Entity *ent) { Snapshot *ss = ent->ss; @@ -392,14 +392,14 @@ void UnlinkEntity(Entity *ent) //////////////////////////////// //~ Xform -void MarkChildEntityXformsDirty(Snapshot *ss, Entity *ent) +void MarkChildXformsDirty(Snapshot *ss, Entity *ent) { for (Entity *child = EntityFromId(ss, ent->first); child->valid; child = EntityFromId(ss, child->next)) { if (child->_is_xform_dirty) { break; } else { child->_is_xform_dirty = 1; - MarkChildEntityXformsDirty(ss, child); + MarkChildXformsDirty(ss, child); } } } @@ -452,7 +452,7 @@ Xform LocalXformFromEntity(Entity *ent) return ent->_local_xform; } -void SetEntityXform(Entity *ent, Xform xf) +void SetXform(Entity *ent, Xform xf) { if (!EqXform(xf, ent->_xform)) { Snapshot *ss = ent->ss; @@ -466,16 +466,16 @@ void SetEntityXform(Entity *ent, Xform xf) } ent->_xform = xf; ent->_is_xform_dirty = 0; - MarkChildEntityXformsDirty(ss, ent); + MarkChildXformsDirty(ss, ent); } } -void SetEntityLocalXform(Entity *ent, Xform xf) +void SetLocalXform(Entity *ent, Xform xf) { if (!EqXform(xf, ent->_local_xform)) { ent->_local_xform = xf; ent->_is_xform_dirty = 1; - MarkChildEntityXformsDirty(ent->ss, ent); + MarkChildXformsDirty(ent->ss, ent); } } @@ -575,7 +575,7 @@ TileKind TileKindFromChunk(Entity *chunk_ent, Vec2I32 local_tile_index) void LerpEntity(Entity *e, Entity *e0, Entity *e1, f64 blend) { if (IsValidAndActive(e0) && IsValidAndActive(e1) - && EqEntityId(e0->id, e1->id) + && EqId(e0->id, e1->id) && e0->continuity_gen == e1->continuity_gen) { e->_local_xform = LerpXform(e0->_local_xform, e1->_local_xform, blend); @@ -583,7 +583,7 @@ void LerpEntity(Entity *e, Entity *e0, Entity *e1, f64 blend) /* TODO: Cache parent & child xforms in sim */ Xform e0_xf = XformFromEntity(e0); Xform e1_xf = XformFromEntity(e1); - SetEntityXform(e, LerpXform(e0_xf, e1_xf, blend)); + SetXform(e, LerpXform(e0_xf, e1_xf, blend)); } e->control_force = LerpF32(e0->control_force, e1->control_force, blend); @@ -622,7 +622,7 @@ void CreateMissingEntitiesFromSnapshots(Entity *local_parent, Entity *remote, En EntityId id = remote->id; Entity *local_ent = EntityFromId(local_ss, id); if (!local_ent->valid) { - local_ent = AcquireSyncDstEntity(local_parent, id, remote_player); + local_ent = AcquireSyncDst(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)) { CreateMissingEntitiesFromSnapshots(local_ent, remote_child, remote_player); @@ -637,7 +637,7 @@ void SyncEntity(Entity *local, Entity *remote) CopyStruct(local, remote); /* Why would 2 ents w/ different uids ever be synced? */ - Assert(EqEntityId(local->id, old.id)); + Assert(EqId(local->id, old.id)); local->ss = old.ss; local->id = old.id; @@ -767,7 +767,7 @@ void DecodeEntity(BB_Reader *br, Entity *e) EntityId new_id = decoded.id; CopyStruct(e, &decoded); e->id = old_id; - if (!EqEntityId(old_id, new_id)) { + if (!EqId(old_id, new_id)) { SetEntityId(e, new_id); } } diff --git a/src/pp/pp_ent.h b/src/pp/pp_ent.h index 8b15fcef..4597636c 100644 --- a/src/pp/pp_ent.h +++ b/src/pp/pp_ent.h @@ -407,12 +407,12 @@ Inline Entity *NilEntity(void) //////////////////////////////// //~ Id helpers -Inline b32 EqEntityId(EntityId a, EntityId b) +Inline b32 EqId(EntityId a, EntityId b) { return EqUid(a.uid, b.uid); } -Inline b32 IsNilEntityId(EntityId id) +Inline b32 IsNilId(EntityId id) { return EqUid(id.uid, NilEntityId.uid); } @@ -448,12 +448,12 @@ Inline b32 IsValidAndActive(Entity *ent) Inline b32 ShouldPredict(Entity *ent) { - return EqEntityId(ent->predictor, ent->ss->local_player); + return EqId(ent->predictor, ent->ss->local_player); } Inline b32 IsOwner(Entity *ent) { - return EqEntityId(ent->owner, ent->ss->local_player); + return EqId(ent->owner, ent->ss->local_player); } Inline b32 ShouldSimulate(Entity *ent) @@ -465,7 +465,7 @@ Inline b32 ShouldSimulate(Entity *ent) if (HasProp(ent, Prop_SyncDst)) { EntityId local_player = ent->ss->local_player; - result = EqEntityId(local_player, ent->owner) || EqEntityId(local_player, ent->predictor); + result = EqId(local_player, ent->owner) || EqId(local_player, ent->predictor); } } return result; @@ -474,34 +474,34 @@ Inline b32 ShouldSimulate(Entity *ent) //////////////////////////////// //~ Acquire operations -Entity *AcquireEntityRaw(Snapshot *ss, Entity *parent, EntityId id); -Entity *AcquireLocalEntity(Entity *parent); -Entity *AcquireLocalEntityWithId(Entity *parent, EntityId id); -Entity *AcquireSyncSrcEntity(Entity *parent); -Entity *AcquireSyncSrcEntityWithId(Entity *parent, EntityId id); -Entity *AcquireSyncDstEntity(Entity *parent, EntityId ent_id, EntityId owner_id); +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); //////////////////////////////// //~ Release operations -void ReleaseEntityRaw(Entity *ent); -void ReleaseEntity(Entity *ent); -void ReleaseAllEntitiesWithProp(Snapshot *ss, Prop prop); +void ReleaseRaw(Entity *ent); +void Release(Entity *ent); +void ReleaseAllWithProp(Snapshot *ss, Prop prop); //////////////////////////////// //~ Activate operations -void ActivateEntity(Entity *ent, u64 current_tick); +void Activate(Entity *ent, u64 current_tick); //////////////////////////////// //~ Id operations u32 IndexFromEntity(Snapshot *ss, Entity *ent); Entity *EntityFromIndex(Snapshot *ss, u32 index); -EntBin *BinFromEntityId(Snapshot *ss, EntityId id); +EntBin *BinFromId(Snapshot *ss, EntityId id); void SetEntityId(Entity *ent, EntityId id); Entity *EntityFromId(Snapshot *ss, EntityId id); -EntityId RandomEntityId(void); +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); @@ -509,24 +509,24 @@ EntityId TileChunkIdFromIndex(Vec2I32 chunk_start); //////////////////////////////// //~ Query operations -Entity *FirstEntityWithProp(Snapshot *ss, Prop prop); -Entity *FirstEntityWithAllProps(Snapshot *ss, PropArray props); +Entity *FirstWithProp(Snapshot *ss, Prop prop); +Entity *FirstWithAllProps(Snapshot *ss, PropArray props); //////////////////////////////// //~ Tree operations -void LinkEntity(Entity *parent, Entity *child); -void UnlinkEntity(Entity *ent); +void Link(Entity *parent, Entity *child); +void Unlink(Entity *ent); //////////////////////////////// //~ Xform operations -void MarkChildEntityXformsDirty(Snapshot *ss, Entity *ent); +void MarkChildXformsDirty(Snapshot *ss, Entity *ent); Xform XformFromEntity_(Snapshot *ss, Entity *ent); Xform XformFromEntity(Entity *ent); Xform LocalXformFromEntity(Entity *ent); -void SetEntityXform(Entity *ent, Xform xf); -void SetEntityLocalXform(Entity *ent, Xform xf); +void SetXform(Entity *ent, Xform xf); +void SetLocalXform(Entity *ent, Xform xf); //////////////////////////////// //~ Movement operations diff --git a/src/pp/pp_phys.c b/src/pp/pp_phys.c index 8fe71517..7e26aeb1 100644 --- a/src/pp/pp_phys.c +++ b/src/pp/pp_phys.c @@ -9,7 +9,7 @@ internal b32 can_contact(Entity *e0, Entity *e1) { b32 result = 0; result = e0 != e1 && - !EqEntityId(e0->top, e1->top) && + !EqId(e0->top, e1->top) && !(HasProp(e0, Prop_Wall) && HasProp(e1, Prop_Wall)); return result; } @@ -93,7 +93,7 @@ void phys_create_and_update_contacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_ if (!constraint_ent->valid) { is_start = 1; /* Create constraint */ - constraint_ent = AcquireLocalEntityWithId(root, constraint_id); + constraint_ent = AcquireLocalWithId(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. */ @@ -103,7 +103,7 @@ void phys_create_and_update_contacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_ /* TODO: Should we recalculate normal as more contact points are added? */ EnableProp(constraint_ent, Prop_ContactConstraint); - ActivateEntity(constraint_ent, tick); + Activate(constraint_ent, tick); } constraint = &constraint_ent->contact_constraint_data; constraint->normal = collision_result.normal; @@ -232,7 +232,7 @@ void phys_create_and_update_contacts(PhysStepCtx *ctx, f32 elapsed_dt, u64 phys_ Entity *dbg_ent = EntityFromId(ss, dbg_ent_id); if (!dbg_ent->valid) { /* FIXME: Entity never released */ - dbg_ent = AcquireLocalEntityWithId(root, dbg_ent_id); + dbg_ent = AcquireLocalWithId(root, dbg_ent_id); EnableProp(dbg_ent, Prop_CollisionDebug); } @@ -1150,7 +1150,7 @@ void phys_integrate_velocities(PhysStepCtx *ctx, f32 dt) if (!HasProp(ent, Prop_Dynamic) && !HasProp(ent, Prop_Kinematic)) continue; Xform xf = get_derived_xform(ent, dt); - SetEntityXform(ent, xf); + SetXform(ent, xf); } } diff --git a/src/pp/pp_sim.c b/src/pp/pp_sim.c index 28e86256..c3440d72 100644 --- a/src/pp/pp_sim.c +++ b/src/pp/pp_sim.c @@ -596,7 +596,7 @@ void sim_snapshot_set_tile(Snapshot *ss, Vec2I32 world_tile_index, TileKind tile Entity *chunk_ent = EntityFromId(ss, chunk_id); if (!chunk_ent->valid) { Entity *root = EntityFromId(ss, RootEntityId); - chunk_ent = AcquireSyncSrcEntityWithId(root, chunk_id); + chunk_ent = AcquireSyncSrcWithId(root, chunk_id); EnableProp(chunk_ent, Prop_TileChunk); chunk_ent->tile_chunk_index = chunk_index; } @@ -681,8 +681,8 @@ void sim_snapshot_sync_ents(Snapshot *local_ss, Snapshot *remote_ss, EntityId re 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)) { - b32 should_sync = EqEntityId(local_ent->owner, remote_player) || IsNilEntityId(remote_player); - if ((sync_flags & SIM_SYNC_FLAG_NOSYNC_PREDICTABLES) && EqEntityId(local_ent->predictor, local_ss->local_player)) { + b32 should_sync = EqId(local_ent->owner, remote_player) || IsNilId(remote_player); + if ((sync_flags & SIM_SYNC_FLAG_NOSYNC_PREDICTABLES) && EqId(local_ent->predictor, local_ss->local_player)) { should_sync = 0; } if (should_sync) { @@ -698,7 +698,7 @@ void sim_snapshot_sync_ents(Snapshot *local_ss, Snapshot *remote_ss, EntityId re } } } - ReleaseAllEntitiesWithProp(local_ss, Prop_Release); + ReleaseAllWithProp(local_ss, Prop_Release); } @@ -1025,7 +1025,7 @@ void sim_snapshot_decode(BB_Reader *br, Snapshot *ss) Entity *ent = &ss->ents[index]; ent->valid = 1; SetEntityId(ent, n->alloc_ent_id); - LinkEntity(parent, ent); + Link(parent, ent); } else { /* Received an invalid entity allocation */ Assert(0); @@ -1095,7 +1095,7 @@ void sim_snapshot_decode(BB_Reader *br, Snapshot *ss) DecodeEntity(br, e); } } - ReleaseAllEntitiesWithProp(ss, Prop_Release); + ReleaseAllWithProp(ss, Prop_Release); #endif EndScratch(scratch); diff --git a/src/pp/pp_step.c b/src/pp/pp_step.c index 5dfc00f6..90a99072 100644 --- a/src/pp/pp_step.c +++ b/src/pp/pp_step.c @@ -33,7 +33,7 @@ void ResetSimAccel(Snapshot *ss, SimAccel *accel) Entity *SpawnTestSmg(Entity *parent) { - Entity *e = AcquireSyncSrcEntity(parent); + Entity *e = AcquireSyncSrc(parent); e->sprite = S_TagFromPath(Lit("sprite/gun.ase")); EnableProp(e, Prop_Attached); @@ -49,7 +49,7 @@ Entity *SpawnTestSmg(Entity *parent) Entity *SpawnTestLauncher(Entity *parent) { - Entity *e = AcquireSyncSrcEntity(parent); + Entity *e = AcquireSyncSrc(parent); e->sprite = S_TagFromPath(Lit("sprite/gun.ase")); EnableProp(e, Prop_Attached); @@ -65,7 +65,7 @@ Entity *SpawnTestLauncher(Entity *parent) Entity *SpawnTestChucker(Entity *parent) { - Entity *chucker = AcquireSyncSrcEntity(parent); + Entity *chucker = AcquireSyncSrc(parent); chucker->sprite = S_TagFromPath(Lit("sprite/gun.ase")); EnableProp(chucker, Prop_Attached); @@ -78,7 +78,7 @@ Entity *SpawnTestChucker(Entity *parent) /* Chucker zone */ { - Entity *zone = AcquireSyncSrcEntity(chucker); + Entity *zone = AcquireSyncSrc(chucker); EnableProp(zone, Prop_ChuckerZone); @@ -104,7 +104,7 @@ Entity *SpawnTestEmployee(Entity *parent) Entity *employee = NilEntity(); { - Entity *e = AcquireSyncSrcEntity(parent); + Entity *e = AcquireSyncSrc(parent); Vec2 pos = VEC2(1, -1); @@ -135,7 +135,7 @@ Entity *SpawnTestEmployee(Entity *parent) Xform xf = XformFromTrs(TRS(.t = pos, .r = r, .s = size)); //xf.bx.y = -1.f; - SetEntityXform(e, xf); + SetXform(e, xf); e->linear_ground_friction = 250; e->angular_ground_friction = 200; @@ -186,8 +186,8 @@ Entity *SpawnTestCamera(Entity *parent, Entity *follow) { Entity *camera_ent = NilEntity(); if (follow->valid) { - camera_ent = AcquireSyncSrcEntity(parent); - SetEntityXform(camera_ent, XformIdentity); + camera_ent = AcquireSyncSrc(parent); + SetXform(camera_ent, XformIdentity); EnableProp(camera_ent, Prop_Camera); EnableProp(camera_ent, Prop_ActiveCamera); @@ -203,8 +203,8 @@ Entity *SpawnTestCamera(Entity *parent, Entity *follow) Entity *SpawnTestExplosion(Entity *parent, Vec2 pos, f32 strength, f32 radius) { - Entity *ent = AcquireSyncSrcEntity(parent); - SetEntityXform(ent, XformFromPos(pos)); + Entity *ent = AcquireSyncSrc(parent); + SetXform(ent, XformFromPos(pos)); EnableProp(ent, Prop_Explosion); ent->explosion_strength = strength; @@ -222,7 +222,7 @@ void TeleportTest(Entity *ent, Vec2 pos) //++ent->continuity_gen; Xform xf = XformFromEntity(ent); xf.og = pos; - SetEntityXform(ent, xf); + SetXform(ent, xf); } void SpawnTestEntities1(Entity *parent, Vec2 pos) @@ -234,7 +234,7 @@ void SpawnTestEntities1(Entity *parent, Vec2 pos) Entity *e = SpawnTestEmployee(parent); Xform xf = XformFromEntity(e); xf.og = pos; - SetEntityXform(e, xf); + SetXform(e, xf); } } @@ -245,13 +245,13 @@ void SpawnTestEntities2(Entity *parent, Vec2 pos) /* Small Box */ #if 1 { - //Entity *e = AcquireLocalEntity(parent); - Entity *e = AcquireSyncSrcEntity(parent); + //Entity *e = AcquireLocal(parent); + Entity *e = AcquireSyncSrc(parent); f32 rot = 0; Vec2 size = VEC2(0.125, 0.125); Xform xf = XformFromTrs(TRS(.t = pos, .r = rot, .s = size)); - SetEntityXform(e, xf); + SetXform(e, xf); e->sprite = S_TagFromPath(Lit("sprite/tile.ase")); e->layer = SIM_LAYER_SHOULDERS; @@ -288,12 +288,12 @@ void SpawnTestEntities2(Entity *parent, Vec2 pos) /* Tiny box */ #if 0 { - Entity *e = AcquireSyncSrcEntity(parent); + Entity *e = AcquireSyncSrc(parent); f32 r = Pi / 4; Vec2 size = VEC2(0.5, 0.25); Xform xf = XformFromTrs(.t = pos, .r = r, .s = size); - SetEntityXform(e, xf); + SetXform(e, xf); e->sprite = S_TagFromPath(Lit("sprite/bullet.ase")); e->sprite_collider_slice = Lit("shape"); @@ -315,13 +315,13 @@ void SpawnTestEntities3(Entity *parent, Vec2 pos) /* Heavy box */ { - //Entity *e = AcquireLocalEntity(parent); - Entity *e = AcquireSyncSrcEntity(parent); + //Entity *e = AcquireLocal(parent); + Entity *e = AcquireSyncSrc(parent); f32 r = 0; Vec2 size = VEC2(1, 1); Xform xf = XformFromTrs(TRS(.t = pos, .r = r, .s = size)); - SetEntityXform(e, xf); + SetXform(e, xf); e->sprite = S_TagFromPath(Lit("sprite/box.ase")); e->layer = SIM_LAYER_SHOULDERS; @@ -339,12 +339,12 @@ void SpawnTestEntities4(Entity *parent, Vec2 pos) LAX pos; /* Light box */ - Entity *e = AcquireSyncSrcEntity(parent); + Entity *e = AcquireSyncSrc(parent); f32 r = 0; Vec2 size = VEC2(2, 1); Xform xf = XformFromTrs(TRS(.t = pos, .r = r, .s = size)); - SetEntityXform(e, xf); + SetXform(e, xf); //e->sprite = S_TagFromPath(Lit("sprite/box.ase")); e->sprite = S_TagFromPath(Lit("sprite/tile.ase")); @@ -359,7 +359,7 @@ void SpawnTestEntities4(Entity *parent, Vec2 pos) void SpawnTestTile(Snapshot *world, Vec2 world_pos) { #if 0 - Entity *e = AcquireSyncSrcEntity(parent); + Entity *e = AcquireSyncSrc(parent); i32 sign_x = (world_pos.x >= 0) - (world_pos.x < 0); i32 sign_y = (world_pos.y >= 0) - (world_pos.y < 0); @@ -373,7 +373,7 @@ 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); - SetEntityXform(e, xf); + SetXform(e, xf); e->layer = SIM_LAYER_WALLS; e->sprite = S_TagFromPath(Lit("sprite/tile.ase")); @@ -663,14 +663,14 @@ void GenerateTestWalls(Snapshot *world) /* Create wall entities */ for (struct wall_node *node = first_wall; node; node = node->next) { - Entity *wall_ent = AcquireSyncSrcEntity(root); + Entity *wall_ent = AcquireSyncSrc(root); EnableProp(wall_ent, Prop_Wall); Vec2 start = sim_pos_from_world_tile_index(node->start); Vec2 end = sim_pos_from_world_tile_index(node->end); Xform xf = XformFromPos(start); - SetEntityXform(wall_ent, xf); + SetXform(wall_ent, xf); EnableProp(wall_ent, Prop_Solid); wall_ent->local_collider.count = 2; @@ -680,7 +680,7 @@ void GenerateTestWalls(Snapshot *world) Assert(node->wall_dir >= 0 && (u32)node->wall_dir < countof(dirs)); wall_ent->collision_dir = dirs[node->wall_dir]; - ActivateEntity(wall_ent, world->tick); + Activate(wall_ent, world->tick); } EndScratch(scratch); @@ -708,7 +708,7 @@ PHYS_COLLISION_CALLBACK_FUNC_DEF(OnEntityCollision, data, step_ctx) Entity *src = EntityFromId(world, bullet->bullet_src); /* Process collision if bullet already spent or * target share same top level parent */ - if (!bullet->bullet_has_hit && !EqEntityId(src->top, target->top) && HasProp(target, Prop_Solid)) { + if (!bullet->bullet_has_hit && !EqId(src->top, target->top) && HasProp(target, Prop_Solid)) { Vec2 point = data->point; /* Update tracer */ @@ -716,7 +716,7 @@ PHYS_COLLISION_CALLBACK_FUNC_DEF(OnEntityCollision, data, step_ctx) if (ShouldSimulate(tracer)) { Xform xf = XformFromEntity(tracer); xf.og = point; - SetEntityXform(tracer, xf); + SetXform(tracer, xf); SetLinearVelocity(tracer, VEC2(0, 0)); } @@ -728,11 +728,11 @@ PHYS_COLLISION_CALLBACK_FUNC_DEF(OnEntityCollision, data, step_ctx) /* TODO: Remove this */ { Xform xf = XformFromTrs(TRS(.t = point, .r = RandF64FromState(&step_ctx->rand, 0, Tau))); - Entity *decal = AcquireSyncSrcEntity(root); + Entity *decal = AcquireSyncSrc(root); decal->sprite = S_TagFromPath(Lit("sprite/blood.ase")); decal->sprite_tint = Rgba32F(1, 1, 1, 0.25f); decal->layer = SIM_LAYER_FLOOR_DECALS; - SetEntityXform(decal, xf); + SetXform(decal, xf); f32 perp_range = 0.5; Vec2 linear_velocity = MulVec2(normal, 0.5); @@ -801,7 +801,7 @@ PHYS_COLLISION_CALLBACK_FUNC_DEF(OnEntityCollision, data, step_ctx) /* Chucker zone */ if (HasProp(e0, Prop_ChuckerZone)) { - if (!EqEntityId(e0->top, e1->top) && HasProp(e1, Prop_Solid)) { + if (!EqId(e0->top, e1->top) && HasProp(e1, Prop_Solid)) { e0->chucker_zone_ent = e1->id; e0->chucker_zone_ent_tick = world->tick; } @@ -853,11 +853,11 @@ void StepSim(SimStepCtx *ctx) /* Create player if necessary */ if (is_master && !player->valid) { /* FIXME: Player never released upon disconnect */ - player = AcquireSyncSrcEntity(root); + player = AcquireSyncSrc(root); player->player_client_handle = client->handle; EnableProp(player, Prop_Player); player->predictor = player->id; - ActivateEntity(player, world->tick); + Activate(player, world->tick); client->player_id = player->id; if (client == user_input_client) { user_input_client->player_id = player->id; @@ -889,7 +889,7 @@ 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) && !EqEntityId(ent->owner, world_client->player_id)) { + if (ent->valid && HasProp(ent, Prop_SyncSrc) && !EqId(ent->owner, world_client->player_id)) { DisableProp(ent, Prop_SyncSrc); EnableProp(ent, Prop_SyncDst); } @@ -908,7 +908,7 @@ 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)) { - if (!IsNilEntityId(ent->cmd_player) && EqEntityId(ent->cmd_player, world->local_player)) { + if (!IsNilId(ent->cmd_player) && EqId(ent->cmd_player, world->local_player)) { EnableProp(ent, Prop_SyncSrc); } } @@ -919,7 +919,7 @@ void StepSim(SimStepCtx *ctx) //- Release entities at beginning of frame - ReleaseAllEntitiesWithProp(world, Prop_Release); + ReleaseAllWithProp(world, Prop_Release); ResetSimAccel(world, ctx->accel); @@ -933,7 +933,7 @@ void StepSim(SimStepCtx *ctx) if (!HasProp(ent, Prop_Active)) { u64 atick = ent->activation_tick; if (atick != 0 || world->tick >= atick) { - ActivateEntity(ent, world->tick); + Activate(ent, world->tick); } } } @@ -949,7 +949,7 @@ void StepSim(SimStepCtx *ctx) Entity *player = EntityFromId(world, cmd_ent->cmd_player); if (ShouldSimulate(player)) { b32 persist_cmd = 0; - if (!is_master && !EqEntityId(player->id, world->local_player)) { + if (!is_master && !EqId(player->id, world->local_player)) { /* We are not the master and the command is not our own, skip processing */ continue; } @@ -1061,7 +1061,7 @@ void StepSim(SimStepCtx *ctx) 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 = AcquireSyncSrcEntity(root); + Entity *chat_ent = AcquireSyncSrc(root); EnableProp(chat_ent, Prop_CHAT); chat_ent->chat_player = player->id; chat_ent->chat_msg = msg_key; @@ -1252,7 +1252,7 @@ void StepSim(SimStepCtx *ctx) Xform xf = LocalXformFromEntity(ent); xf.og = attach_pos; xf = XformWIthWorldRotation(xf, AngleFromVec2(attach_dir) + Pi / 2); - SetEntityLocalXform(ent, xf); + SetLocalXform(ent, xf); } @@ -1326,7 +1326,7 @@ void StepSim(SimStepCtx *ctx) /* Spawn bullet */ Entity *bullet; { - bullet = AcquireSyncSrcEntity(root); + bullet = AcquireSyncSrc(root); EnableProp(bullet, Prop_Bullet); bullet->bullet_src = ent->id; @@ -1349,7 +1349,7 @@ void StepSim(SimStepCtx *ctx) /* Spawn tracer */ { - Entity *tracer = AcquireSyncSrcEntity(root); + Entity *tracer = AcquireSyncSrc(root); tracer->tracer_fade_duration = 0.025f; tracer->layer = SIM_LAYER_TRACERS; EnableProp(tracer, Prop_Tracer); @@ -1373,7 +1373,7 @@ void StepSim(SimStepCtx *ctx) /* Spawn bullet */ Entity *bullet; { - bullet = AcquireSyncSrcEntity(root); + bullet = AcquireSyncSrc(root); EnableProp(bullet, Prop_Bullet); bullet->bullet_src = ent->id; @@ -1395,7 +1395,7 @@ void StepSim(SimStepCtx *ctx) /* Spawn tracer */ { - Entity *tracer = AcquireSyncSrcEntity(root); + Entity *tracer = AcquireSyncSrc(root); tracer->tracer_fade_duration = 0.025f; tracer->layer = SIM_LAYER_TRACERS; EnableProp(tracer, Prop_Tracer); @@ -1414,8 +1414,8 @@ void StepSim(SimStepCtx *ctx) 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) { - if (!EqEntityId(old_joint_ent->weld_joint_data.e1, target->id)) { - Entity *joint_ent = AcquireSyncSrcEntity(root); + if (!EqId(old_joint_ent->weld_joint_data.e1, target->id)) { + Entity *joint_ent = AcquireSyncSrc(root); EnableProp(joint_ent, Prop_Active); Xform xf0 = XformFromEntity(ent); @@ -1453,7 +1453,7 @@ void StepSim(SimStepCtx *ctx) if (HasProp(ent, Prop_Controlled)) { Entity *joint_ent = EntityFromId(world, ent->move_joint); if (is_master && !IsValidAndActive(joint_ent)) { - joint_ent = AcquireSyncSrcEntity(root); + joint_ent = AcquireSyncSrc(root); joint_ent->predictor = ent->predictor; joint_ent->mass_unscaled = F32Infinity; joint_ent->inertia_unscaled = F32Infinity; @@ -1472,7 +1472,7 @@ void StepSim(SimStepCtx *ctx) } if (ShouldSimulate(joint_ent)) { - SetEntityXform(joint_ent, XformIdentity); /* Reset joint ent position */ + SetXform(joint_ent, XformIdentity); /* Reset joint ent position */ SetLinearVelocity(joint_ent, MulVec2(ClampVec2Len(ent->control.move, 1), ent->control_force_max_speed)); } } @@ -1493,7 +1493,7 @@ void StepSim(SimStepCtx *ctx) /* Retrieve / create aim joint */ Entity *joint_ent = EntityFromId(world, ent->aim_joint); if (is_master && !IsValidAndActive(joint_ent)) { - joint_ent = AcquireSyncSrcEntity(root); + joint_ent = AcquireSyncSrc(root); joint_ent->predictor = ent->predictor; joint_ent->mass_unscaled = F32Infinity; joint_ent->inertia_unscaled = F32Infinity; @@ -1594,7 +1594,7 @@ 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)) { - joint_ent = AcquireSyncSrcEntity(root); + joint_ent = AcquireSyncSrc(root); joint_ent->predictor = ent->predictor; EnableProp(joint_ent, Prop_MotorJoint); EnableProp(joint_ent, Prop_Active); @@ -1630,7 +1630,7 @@ void StepSim(SimStepCtx *ctx) if (ShouldSimulate(target_ent)) { if (!IsValidAndActive(joint_ent)) { /* FIXME: Joint ent may never release */ - joint_ent = AcquireLocalEntity(root); + joint_ent = AcquireLocal(root); joint_ent->mass_unscaled = F32Infinity; joint_ent->inertia_unscaled = F32Infinity; player->player_dbg_drag_joint_ent = joint_ent->id; @@ -1641,7 +1641,7 @@ void StepSim(SimStepCtx *ctx) MouseJointDesc def = phys_mouse_joint_def_init(); def.target = target_ent->id; - if (EqEntityId(joint_ent->mouse_joint_data.target, target_ent->id)) { + if (EqId(joint_ent->mouse_joint_data.target, target_ent->id)) { def.point_local_start = joint_ent->mouse_joint_data.point_local_start; } else { def.point_local_start = InvertXformMulV2(xf, cursor); @@ -1734,7 +1734,7 @@ void StepSim(SimStepCtx *ctx) #endif Xform xf = XformFromTrs(TRS(.t = pos, .r = AngleFromVec2(vel) + Pi / 2)); - SetEntityXform(ent, xf); + SetXform(ent, xf); EnableProp(ent, Prop_Kinematic); SetLinearVelocity(ent, vel); @@ -1742,7 +1742,7 @@ void StepSim(SimStepCtx *ctx) /* Initialize tracer */ Entity *tracer = EntityFromId(world, ent->bullet_tracer); if (ShouldSimulate(tracer)) { - SetEntityXform(tracer, xf); + SetXform(tracer, xf); EnableProp(tracer, Prop_Kinematic); SetLinearVelocity(tracer, ent->linear_velocity); tracer->tracer_start = pos; @@ -1753,8 +1753,8 @@ void StepSim(SimStepCtx *ctx) /* Spawn quake */ { - Entity *quake = AcquireSyncSrcEntity(root); - SetEntityXform(quake, XformFromPos(pos)); + Entity *quake = AcquireSyncSrc(root); + SetXform(quake, XformFromPos(pos)); quake->quake_intensity = 0.2f; quake->quake_fade = quake->quake_intensity / 0.1f; EnableProp(quake, Prop_Quake); @@ -1814,7 +1814,7 @@ void StepSim(SimStepCtx *ctx) } } - SetEntityXform(ent, xf); + SetXform(ent, xf); } @@ -1862,7 +1862,7 @@ void StepSim(SimStepCtx *ctx) //- Release entities at end of frame - ReleaseAllEntitiesWithProp(world, Prop_Release); + ReleaseAllWithProp(world, Prop_Release); //- Sync to publish client