From d16fdcd26028eee7a410cdda3bfd17528acbcc07 Mon Sep 17 00:00:00 2001 From: jacob Date: Fri, 28 Feb 2025 17:42:26 -0600 Subject: [PATCH] rename 'client_ent' -> 'player' --- src/sim.c | 18 ++++---- src/sim.h | 10 ++--- src/sim_ent.c | 18 ++++---- src/sim_ent.h | 44 +++++++++--------- src/sim_step.c | 120 ++++++++++++++++++++++++------------------------- src/user.c | 40 ++++++++--------- 6 files changed, 125 insertions(+), 125 deletions(-) diff --git a/src/sim.c b/src/sim.c index ba3b662f..2ba7da7f 100644 --- a/src/sim.c +++ b/src/sim.c @@ -314,7 +314,7 @@ struct sim_snapshot *sim_snapshot_alloc(struct sim_client *client, struct sim_sn ss->sim_dt_ns = src->sim_dt_ns; ss->sim_time_ns = src->sim_time_ns; ss->continuity_gen = src->continuity_gen; - ss->local_client_ent = src->local_client_ent; + ss->local_player = src->local_player; ss->phys_iteration = src->phys_iteration; /* Copy id lookup bins */ @@ -599,7 +599,7 @@ struct sim_snapshot *sim_snapshot_alloc_from_lerp(struct sim_client *client, str * ========================== */ /* Syncs entity data between snapshots */ -void sim_snapshot_sync_ents(struct sim_snapshot *local_ss, struct sim_snapshot *remote_ss, struct sim_ent_id remote_client_ent, u32 sync_flags) +void sim_snapshot_sync_ents(struct sim_snapshot *local_ss, struct sim_snapshot *remote_ss, struct sim_ent_id remote_player, u32 sync_flags) { __prof; @@ -613,15 +613,15 @@ void sim_snapshot_sync_ents(struct sim_snapshot *local_ss, struct sim_snapshot * /* Create new ents from remote */ for (struct sim_ent *remote_top = sim_ent_from_id(remote_ss, remote_root->first); remote_top->valid; remote_top = sim_ent_from_id(remote_ss, remote_top->next)) { - sim_ent_sync_alloc_tree(local_root, remote_top, remote_client_ent); + sim_ent_sync_alloc_tree(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) { struct sim_ent *local_ent = &local_ss->ents[i]; if (local_ent->valid && sim_ent_has_prop(local_ent, SIM_ENT_PROP_SYNC_DST)) { - b32 should_sync = sim_ent_id_eq(local_ent->owner, remote_client_ent) || sim_ent_id_is_nil(remote_client_ent); - if ((sync_flags & SIM_SYNC_FLAG_NOSYNC_PREDICTABLES) && sim_ent_id_eq(local_ent->predictor, local_ss->local_client_ent)) { + b32 should_sync = sim_ent_id_eq(local_ent->owner, remote_player) || sim_ent_id_is_nil(remote_player); + if ((sync_flags & SIM_SYNC_FLAG_NOSYNC_PREDICTABLES) && sim_ent_id_eq(local_ent->predictor, local_ss->local_player)) { should_sync = false; } if (should_sync) { @@ -670,7 +670,7 @@ void sim_snapshot_encode(struct bitbuff_writer *bw, struct sim_client *receiver, bw_write_uv(bw, ss1->continuity_gen); bw_write_uv(bw, ss1->phys_iteration); - bw_write_uid(bw, receiver->ent_id.uid); + bw_write_uid(bw, receiver->player_id.uid); /* Id bins */ /* TODO: Don't encode these */ @@ -739,7 +739,7 @@ void sim_snapshot_decode(struct bitbuff_reader *br, struct sim_snapshot *ss) ss->continuity_gen = br_read_uv(br); ss->phys_iteration = br_read_uv(br); - ss->local_client_ent = (struct sim_ent_id) { .uid = br_read_uid(br) }; + ss->local_player = (struct sim_ent_id) { .uid = br_read_uid(br) }; /* Id bins */ /* TODO: Don't decode these, determine them implicitly from decoded ents */ @@ -817,7 +817,7 @@ void sim_snapshot_encode(struct bitbuff_writer *bw, struct sim_client *receiver, bw_write_uv(bw, ss1->continuity_gen); bw_write_uv(bw, ss1->phys_iteration); - bw_write_uid(bw, receiver->ent_id.uid); + bw_write_uid(bw, receiver->player_id.uid); /* Ents */ @@ -885,7 +885,7 @@ void sim_snapshot_decode(struct bitbuff_reader *br, struct sim_snapshot *ss) ss->continuity_gen = br_read_uv(br); ss->phys_iteration = br_read_uv(br); - ss->local_client_ent = (struct sim_ent_id) { .uid = br_read_uid(br) }; + ss->local_player = (struct sim_ent_id) { .uid = br_read_uid(br) }; #if 1 diff --git a/src/sim.h b/src/sim.h index 1b7d4055..b8b3f6b6 100644 --- a/src/sim.h +++ b/src/sim.h @@ -82,8 +82,8 @@ struct sim_client { struct sim_client_handle next_in_bin; struct sim_client_handle prev_in_bin; - /* The client entity's id in the master sim (if relevant) */ - struct sim_ent_id ent_id; + /* The client's player entity id in the master sim (if relevant) */ + struct sim_ent_id player_id; /* This is the highest confirmed tick of ours that we know this client has received */ u64 ack; @@ -174,8 +174,8 @@ struct sim_snapshot { /* The last physics iteration (used for tracking contact lifetime) */ u64 phys_iteration; - /* The id of the receiver's client ent in the snapshot */ - struct sim_ent_id local_client_ent; + /* The id of the receiver's player in the snapshot */ + struct sim_ent_id local_player; /* Id lookup */ struct sim_ent_bin *id_bins; @@ -212,7 +212,7 @@ struct sim_snapshot *sim_snapshot_from_closest_tick_gte(struct sim_client *clien struct sim_snapshot *sim_snapshot_alloc_from_lerp(struct sim_client *client, struct sim_snapshot *ss0, struct sim_snapshot *ss1, f64 blend); /* Sync */ -void sim_snapshot_sync_ents(struct sim_snapshot *local_ss, struct sim_snapshot *remote_ss, struct sim_ent_id remote_client_ent, u32 sync_flags); +void sim_snapshot_sync_ents(struct sim_snapshot *local_ss, struct sim_snapshot *remote_ss, struct sim_ent_id remote_player, u32 sync_flags); /* Encode / decode */ void sim_snapshot_encode(struct bitbuff_writer *bw, struct sim_client *receiver, struct sim_snapshot *ss0, struct sim_snapshot *ss1); diff --git a/src/sim_ent.c b/src/sim_ent.c index db442435..72b81e75 100644 --- a/src/sim_ent.c +++ b/src/sim_ent.c @@ -43,7 +43,7 @@ struct sim_ent *sim_ent_alloc_raw(struct sim_snapshot *ss, struct sim_ent *paren *ent = *sim_ent_nil(); ent->ss = ss; ent->valid = true; - ent->owner = ss->client->ent_id; + ent->owner = ss->client->player_id; ent->_is_xform_dirty = true; ++ss->num_ents_allocated; @@ -58,7 +58,7 @@ struct sim_ent *sim_ent_alloc_local(struct sim_ent *parent) { struct sim_snapshot *ss = parent->ss; struct sim_ent *e = sim_ent_alloc_raw(ss, parent, sim_ent_random_id()); - e->owner = ss->local_client_ent; + e->owner = ss->local_player; return e; } @@ -66,7 +66,7 @@ struct sim_ent *sim_ent_alloc_local_with_id(struct sim_ent *parent, struct sim_e { struct sim_snapshot *ss = parent->ss; struct sim_ent *e = sim_ent_alloc_raw(ss, parent, id); - e->owner = ss->local_client_ent; + e->owner = ss->local_player; return e; } @@ -76,7 +76,7 @@ struct sim_ent *sim_ent_alloc_sync_src(struct sim_ent *parent) struct sim_snapshot *ss = parent->ss; struct sim_ent *e = sim_ent_alloc_raw(ss, parent, sim_ent_random_id()); sim_ent_enable_prop(e, SIM_ENT_PROP_SYNC_SRC); - e->owner = ss->local_client_ent; + e->owner = ss->local_player; return e; } @@ -85,7 +85,7 @@ struct sim_ent *sim_ent_alloc_sync_src_with_id(struct sim_ent *parent, struct si struct sim_snapshot *ss = parent->ss; struct sim_ent *e = sim_ent_alloc_raw(ss, parent, id); sim_ent_enable_prop(e, SIM_ENT_PROP_SYNC_SRC); - e->owner = ss->local_client_ent; + e->owner = ss->local_player; return e; } @@ -149,7 +149,7 @@ void sim_ent_release_all_with_prop(struct sim_snapshot *ss, enum sim_ent_prop pr * child entities will be released along with parent anyway) */ for (u64 i = 0; i < ents_to_release_count; ++i) { struct sim_ent *ent = ents_to_release[i]; - if (ent->valid && !ent->is_root && !sim_ent_has_prop(ent, SIM_ENT_PROP_CMD_CONTROL) && !sim_ent_has_prop(ent, SIM_ENT_PROP_CLIENT)) { + if (ent->valid && !ent->is_root && !sim_ent_has_prop(ent, SIM_ENT_PROP_CMD_CONTROL) && !sim_ent_has_prop(ent, SIM_ENT_PROP_PLAYER)) { sim_ent_release(ent); } } @@ -557,7 +557,7 @@ void sim_ent_lerp(struct sim_ent *e, struct sim_ent *e0, struct sim_ent *e1, f64 * ========================== */ /* Walks a local & remote ent tree and allocates any missing net dst ents from remote src ents */ -void sim_ent_sync_alloc_tree(struct sim_ent *local_parent, struct sim_ent *remote, struct sim_ent_id remote_client_ent) +void sim_ent_sync_alloc_tree(struct sim_ent *local_parent, struct sim_ent *remote, struct sim_ent_id remote_player) { __prof; if (sim_ent_has_prop(remote, SIM_ENT_PROP_SYNC_SRC)) { @@ -567,10 +567,10 @@ void sim_ent_sync_alloc_tree(struct sim_ent *local_parent, struct sim_ent *remot struct sim_ent_id id = remote->id; struct sim_ent *local_ent = sim_ent_from_id(local_ss, id); if (!local_ent->valid) { - local_ent = sim_ent_alloc_sync_dst(local_parent, id, remote_client_ent); + local_ent = sim_ent_alloc_sync_dst(local_parent, id, remote_player); } for (struct sim_ent *remote_child = sim_ent_from_id(remote_ss, remote->first); remote_child->valid; remote_child = sim_ent_from_id(remote_ss, remote_child->next)) { - sim_ent_sync_alloc_tree(local_ent, remote_child, remote_client_ent); + sim_ent_sync_alloc_tree(local_ent, remote_child, remote_player); } } } diff --git a/src/sim_ent.h b/src/sim_ent.h index e08292f7..45924f41 100644 --- a/src/sim_ent.h +++ b/src/sim_ent.h @@ -19,8 +19,8 @@ enum sim_ent_prop { SIM_ENT_PROP_SYNC_SRC, /* This entity should be networked to other clients */ SIM_ENT_PROP_SYNC_DST, /* This entity is not locally created, and should sync with incoming net src ents */ - SIM_ENT_PROP_CLIENT, - SIM_ENT_PROP_CLIENT_IS_MASTER, + SIM_ENT_PROP_PLAYER, + SIM_ENT_PROP_PLAYER_IS_MASTER, SIM_ENT_PROP_CMD_CONTROL, @@ -95,11 +95,11 @@ struct sim_ent { /* SIM_ENT_PROP_SYNC_SRC */ /* SIM_ENT_PROP_SYNC_DST */ - /* SIM_ENT_PROP_SYNC_PREDICT */ - /* Id of the client ent that owns simulation for this entity */ + /* Id of the player that owns simulation for this entity */ struct sim_ent_id owner; + /* Id of the player that should predict simulation of this this entity locally */ struct sim_ent_id predictor; /* ====================================================================== */ @@ -129,33 +129,33 @@ struct sim_ent { /* FIXME: Lerp */ - struct sim_ent_id cmd_client; + struct sim_ent_id cmd_player; struct sim_control cmd_control; struct sim_ent_id cmd_hovered_ent; /* ====================================================================== */ /* Client */ - /* SIM_ENT_PROP_CLIENT */ + /* SIM_ENT_PROP_PLAYER */ /* FIXME: Lerp */ - struct sim_client_handle client_handle; /* The client handle on the master sim's machine */ + struct sim_client_handle player_client_handle; /* The client handle on the master sim's machine */ - struct sim_control client_control; - struct v2 client_cursor_pos; + struct sim_control player_control; + struct v2 player_cursor_pos; - struct sim_ent_id client_hovered_ent; - struct sim_ent_id client_control_ent; - struct sim_ent_id client_camera_ent; + struct sim_ent_id player_hovered_ent; + struct sim_ent_id player_control_ent; + struct sim_ent_id player_camera_ent; - struct sim_ent_id client_dbg_drag_joint_ent; - b32 client_dbg_drag_start; - b32 client_dbg_drag_stop; + struct sim_ent_id player_dbg_drag_joint_ent; + b32 player_dbg_drag_start; + b32 player_dbg_drag_stop; /* Client round-trip-time to server */ - i64 client_last_rtt_ns; - f64 client_average_rtt_seconds; + i64 player_last_rtt_ns; + f64 player_average_rtt_seconds; /* ====================================================================== */ /* Collider */ @@ -398,12 +398,12 @@ INLINE b32 sim_ent_is_valid_and_active(struct sim_ent *ent) INLINE b32 sim_ent_should_predict(struct sim_ent *ent) { - return sim_ent_id_eq(ent->predictor, ent->ss->local_client_ent); + return sim_ent_id_eq(ent->predictor, ent->ss->local_player); } INLINE b32 sim_ent_is_owner(struct sim_ent *ent) { - return sim_ent_id_eq(ent->owner, ent->ss->local_client_ent); + return sim_ent_id_eq(ent->owner, ent->ss->local_player); } INLINE b32 sim_ent_should_simulate(struct sim_ent *ent) @@ -412,8 +412,8 @@ INLINE b32 sim_ent_should_simulate(struct sim_ent *ent) if (sim_ent_is_valid_and_active(ent)) { res = true; if (sim_ent_has_prop(ent, SIM_ENT_PROP_SYNC_DST)) { - struct sim_ent_id client_ent_id = ent->ss->local_client_ent; - res = sim_ent_id_eq(client_ent_id, ent->owner) || sim_ent_id_eq(client_ent_id, ent->predictor); + struct sim_ent_id local_player = ent->ss->local_player; + res = sim_ent_id_eq(local_player, ent->owner) || sim_ent_id_eq(local_player, ent->predictor); } } return res; @@ -471,7 +471,7 @@ void sim_ent_apply_torque(struct sim_ent *ent, f32 torque); void sim_ent_lerp(struct sim_ent *e, struct sim_ent *e0, struct sim_ent *e1, f64 blend); /* Sync */ -void sim_ent_sync_alloc_tree(struct sim_ent *local_parent, struct sim_ent *remote, struct sim_ent_id remote_client_ent); +void sim_ent_sync_alloc_tree(struct sim_ent *local_parent, struct sim_ent *remote, struct sim_ent_id remote_player); void sim_ent_sync(struct sim_ent *local, struct sim_ent *remote); /* Encode / decode */ diff --git a/src/sim_step.c b/src/sim_step.c index 1d989748..9a911b03 100644 --- a/src/sim_step.c +++ b/src/sim_step.c @@ -358,50 +358,50 @@ void sim_step(struct sim_step_ctx *ctx) struct sprite_scope *sprite_frame_scope = sprite_scope_begin(); struct sim_ent *root = sim_ent_from_id(world, SIM_ENT_ROOT_ID); - root->owner = world->client->ent_id; + root->owner = world->client->player_id; /* ========================== * * Sync ents from cmd producing clients * ========================== */ { - /* FIXME: Ensure only cmds are synced to master client */ + /* FIXME: Ensure only cmds are synced to master player */ for (u64 client_index = 0; client_index < client_store->num_clients_reserved; ++client_index) { struct sim_client *client = &client_store->clients[client_index]; if (client->valid && client != master_client && client != world_client && client != publish_client) { - struct sim_ent *client_ent = sim_ent_from_id(world, client->ent_id); + struct sim_ent *player = sim_ent_from_id(world, client->player_id); - /* Create client ent if necessary */ - if (is_master && !client_ent->valid) { - /* FIXME: Client ent never released upon disconnect */ - client_ent = sim_ent_alloc_sync_src(root); - client_ent->client_handle = client->handle; - sim_ent_enable_prop(client_ent, SIM_ENT_PROP_CLIENT); - client_ent->predictor = client_ent->id; - sim_ent_enable_prop(client_ent, SIM_ENT_PROP_ACTIVE); - client->ent_id = client_ent->id; + /* Create player if necessary */ + if (is_master && !player->valid) { + /* FIXME: Player never released upon disconnect */ + player = sim_ent_alloc_sync_src(root); + player->player_client_handle = client->handle; + sim_ent_enable_prop(player, SIM_ENT_PROP_PLAYER); + player->predictor = player->id; + sim_ent_enable_prop(player, SIM_ENT_PROP_ACTIVE); + client->player_id = player->id; if (client == user_input_client) { - user_input_client->ent_id = client_ent->id; - world_client->ent_id = client_ent->id; - world->local_client_ent = client_ent->id; - client_ent->owner = client_ent->id; - sim_ent_enable_prop(client_ent, SIM_ENT_PROP_CLIENT_IS_MASTER); + user_input_client->player_id = player->id; + world_client->player_id = player->id; + world->local_player = player->id; + player->owner = player->id; + sim_ent_enable_prop(player, SIM_ENT_PROP_PLAYER_IS_MASTER); } - logf_info("Created client ent with id %F for sim client %F. is_master: %F", FMT_UID(client_ent->id.uid), FMT_HANDLE(client->handle), FMT_UINT(sim_ent_has_prop(client_ent, SIM_ENT_PROP_CLIENT_IS_MASTER))); + logf_info("Created player with id %F for sim client %F. is_master: %F", FMT_UID(player->id.uid), FMT_HANDLE(client->handle), FMT_UINT(sim_ent_has_prop(player, SIM_ENT_PROP_PLAYER_IS_MASTER))); } /* Update rtt */ - if (is_master && client_ent->valid) { - client_ent->client_last_rtt_ns = client->last_rtt_ns; - client_ent->client_average_rtt_seconds -= client_ent->client_average_rtt_seconds / 200; - client_ent->client_average_rtt_seconds += SECONDS_FROM_NS(client->last_rtt_ns) / 200; + if (is_master && player->valid) { + player->player_last_rtt_ns = client->last_rtt_ns; + player->player_average_rtt_seconds -= player->player_average_rtt_seconds / 200; + player->player_average_rtt_seconds += SECONDS_FROM_NS(client->last_rtt_ns) / 200; } /* Sync ents from client */ - if (client_ent->valid) { + if (player->valid) { struct sim_snapshot *src_ss = sim_snapshot_from_tick(client, world->tick); if (src_ss->valid) { - sim_snapshot_sync_ents(world, src_ss, client_ent->id, 0); + sim_snapshot_sync_ents(world, src_ss, player->id, 0); } } } @@ -410,7 +410,7 @@ void sim_step(struct sim_step_ctx *ctx) /* Mark all incoming ents as sync dsts */ for (u64 i = 0; i < world->num_ents_reserved; ++i) { struct sim_ent *ent = &world->ents[i]; - if (ent->valid && sim_ent_has_prop(ent, SIM_ENT_PROP_SYNC_SRC) && !sim_ent_id_eq(ent->owner, world_client->ent_id)) { + if (ent->valid && sim_ent_has_prop(ent, SIM_ENT_PROP_SYNC_SRC) && !sim_ent_id_eq(ent->owner, world_client->player_id)) { sim_ent_disable_prop(ent, SIM_ENT_PROP_SYNC_SRC); sim_ent_enable_prop(ent, SIM_ENT_PROP_SYNC_DST); } @@ -420,7 +420,7 @@ void sim_step(struct sim_step_ctx *ctx) for (u64 i = 0; i < world->num_ents_reserved; ++i) { struct sim_ent *ent = &world->ents[i]; if (ent->valid && sim_ent_has_prop(ent, SIM_ENT_PROP_CMD_CONTROL) && sim_ent_has_prop(ent, SIM_ENT_PROP_SYNC_DST)) { - ent->cmd_client = ent->owner; + ent->cmd_player = ent->owner; } } @@ -429,7 +429,7 @@ void sim_step(struct sim_step_ctx *ctx) for (u64 i = 0; i < world->num_ents_reserved; ++i) { struct sim_ent *ent = &world->ents[i]; if (sim_ent_is_valid_and_active(ent) && sim_ent_has_prop(ent, SIM_ENT_PROP_CMD_CONTROL)) { - if (!sim_ent_id_is_nil(ent->cmd_client) && sim_ent_id_eq(ent->cmd_client, world->local_client_ent)) { + if (!sim_ent_id_is_nil(ent->cmd_player) && sim_ent_id_eq(ent->cmd_player, world->local_player)) { sim_ent_enable_prop(ent, SIM_ENT_PROP_SYNC_SRC); } } @@ -486,20 +486,20 @@ void sim_step(struct sim_step_ctx *ctx) if (!is_master && !sim_ent_should_simulate(cmd_ent)) continue; if (sim_ent_has_prop(cmd_ent, SIM_ENT_PROP_CMD_CONTROL)) { - struct sim_ent *client_ent = sim_ent_from_id(world, cmd_ent->cmd_client); - if (sim_ent_should_simulate(client_ent)) { - if (!is_master && !sim_ent_id_eq(client_ent->id, world->local_client_ent)) { + struct sim_ent *player = sim_ent_from_id(world, cmd_ent->cmd_player); + if (sim_ent_should_simulate(player)) { + if (!is_master && !sim_ent_id_eq(player->id, world->local_player)) { /* We are not the master and the command is not our own, skip processing */ continue; } /* Process control cmd for client */ - struct sim_control old_control = client_ent->client_control; - struct sim_control *control = &client_ent->client_control; + struct sim_control old_control = player->player_control; + struct sim_control *control = &player->player_control; *control = cmd_ent->cmd_control; { - client_ent->client_dbg_drag_start = false; - client_ent->client_dbg_drag_stop = false; + player->player_dbg_drag_start = false; + player->player_dbg_drag_stop = false; if (v2_len_sq(control->move) > 1) { /* Cap movement vector magnitude at 1 */ @@ -508,24 +508,24 @@ void sim_step(struct sim_step_ctx *ctx) /* Determine cursor pos from focus */ { - struct sim_ent_id client_control_ent_id = client_ent->client_control_ent; - struct sim_ent *client_control_ent = sim_ent_from_id(world, client_control_ent_id); - if (client_control_ent->valid || sim_ent_id_is_nil(client_control_ent_id)) { + struct sim_ent_id player_control_ent_id = player->player_control_ent; + struct sim_ent *player_control_ent = sim_ent_from_id(world, player_control_ent_id); + if (player_control_ent->valid || sim_ent_id_is_nil(player_control_ent_id)) { /* Only update cursor pos if focus ent is valid (or nil) */ - client_ent->client_cursor_pos = v2_add(sim_ent_get_xform(client_control_ent).og, client_ent->client_control.focus); + player->player_cursor_pos = v2_add(sim_ent_get_xform(player_control_ent).og, player->player_control.focus); } } - client_ent->client_hovered_ent = cmd_ent->cmd_hovered_ent; + player->player_hovered_ent = cmd_ent->cmd_hovered_ent; u32 flags = control->flags; if (flags & SIM_CONTROL_FLAG_DRAG) { if (!(old_control.flags & SIM_CONTROL_FLAG_DRAG)) { - client_ent->client_dbg_drag_start = true; + player->player_dbg_drag_start = true; } } else { if (old_control.flags & SIM_CONTROL_FLAG_DRAG) { - client_ent->client_dbg_drag_stop = true; + player->player_dbg_drag_stop = true; } } if (flags & SIM_CONTROL_FLAG_CLEAR_ALL) { @@ -556,21 +556,21 @@ void sim_step(struct sim_step_ctx *ctx) for (u64 i = 0; i < world->num_ents_reserved; ++i) { struct sim_ent *ent = &world->ents[i]; if (!sim_ent_should_simulate(ent)) continue; - if (sim_ent_has_prop(ent, SIM_ENT_PROP_CLIENT)) { + if (sim_ent_has_prop(ent, SIM_ENT_PROP_PLAYER)) { /* FIXME: Ents never released when client disconnects */ - struct sim_ent *control_ent = sim_ent_from_id(world, ent->client_control_ent); + struct sim_ent *control_ent = sim_ent_from_id(world, ent->player_control_ent); if (!control_ent->valid) { control_ent = spawn_test_player(ctx); control_ent->predictor = ent->id; sim_ent_enable_prop(control_ent, SIM_ENT_PROP_CONTROLLED); - ent->client_control_ent = control_ent->id; + ent->player_control_ent = control_ent->id; control_ent->controlling_client = ent->id; } - struct sim_ent *camera_ent = sim_ent_from_id(world, ent->client_camera_ent); + struct sim_ent *camera_ent = sim_ent_from_id(world, ent->player_camera_ent); if (!camera_ent->valid) { camera_ent = spawn_test_player_camera(world, control_ent); camera_ent->predictor = ent->id; - ent->client_camera_ent = camera_ent->id; + ent->player_camera_ent = camera_ent->id; } } } @@ -585,9 +585,9 @@ void sim_step(struct sim_step_ctx *ctx) if (!sim_ent_should_simulate(ent)) continue; if (sim_ent_has_prop(ent, SIM_ENT_PROP_CONTROLLED)) { - struct sim_ent *client_ent = sim_ent_from_id(world, ent->controlling_client); - if (client_ent->valid) { - ent->control = client_ent->client_control; + struct sim_ent *player = sim_ent_from_id(world, ent->controlling_client); + if (player->valid) { + ent->control = player->player_control; /* TODO: Move this */ if (ent->control.flags & SIM_CONTROL_FLAG_FIRE) { sim_ent_enable_prop(ent, SIM_ENT_PROP_TRIGGERING_EQUIPPED); @@ -1024,21 +1024,21 @@ void sim_step(struct sim_step_ctx *ctx) if (is_master) { for (u64 i = 0; i < world->num_ents_reserved; ++i) { - struct sim_ent *client_ent = &world->ents[i]; - if (!sim_ent_should_simulate(client_ent)) continue; - if (!sim_ent_has_prop(client_ent, SIM_ENT_PROP_CLIENT)) continue; + struct sim_ent *player = &world->ents[i]; + if (!sim_ent_should_simulate(player)) continue; + if (!sim_ent_has_prop(player, SIM_ENT_PROP_PLAYER)) continue; - struct v2 cursor = client_ent->client_cursor_pos; - b32 start_dragging = client_ent->client_dbg_drag_start; - b32 stop_dragging = client_ent->client_dbg_drag_stop; + struct v2 cursor = player->player_cursor_pos; + b32 start_dragging = player->player_dbg_drag_start; + b32 stop_dragging = player->player_dbg_drag_stop; - struct sim_ent *joint_ent = sim_ent_from_id(world, client_ent->client_dbg_drag_joint_ent); + struct sim_ent *joint_ent = sim_ent_from_id(world, player->player_dbg_drag_joint_ent); struct sim_ent *target_ent = sim_ent_from_id(world, joint_ent->mouse_joint_data.target); if (stop_dragging) { target_ent = sim_ent_nil(); } else if (start_dragging) { - target_ent = sim_ent_from_id(world, client_ent->client_hovered_ent); + target_ent = sim_ent_from_id(world, player->player_hovered_ent); } if (sim_ent_should_simulate(target_ent)) { @@ -1047,7 +1047,7 @@ void sim_step(struct sim_step_ctx *ctx) joint_ent = sim_ent_alloc_local(root); joint_ent->mass_unscaled = F32_INFINITY; joint_ent->inertia_unscaled = F32_INFINITY; - client_ent->client_dbg_drag_joint_ent = joint_ent->id; + player->player_dbg_drag_joint_ent = joint_ent->id; sim_ent_enable_prop(joint_ent, SIM_ENT_PROP_MOUSE_JOINT); sim_ent_enable_prop(joint_ent, SIM_ENT_PROP_ACTIVE); } @@ -1275,7 +1275,7 @@ void sim_step(struct sim_step_ctx *ctx) struct sim_snapshot *pub_world = sim_snapshot_alloc(publish_client, prev_pub_world, world->tick); /* Sync */ - sim_snapshot_sync_ents(pub_world, world, world_client->ent_id, 0); + sim_snapshot_sync_ents(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) { @@ -1290,7 +1290,7 @@ void sim_step(struct sim_step_ctx *ctx) pub_world->sim_time_ns = world->sim_time_ns; pub_world->continuity_gen = world->continuity_gen; pub_world->phys_iteration = world->phys_iteration; - pub_world->local_client_ent = world->local_client_ent; + pub_world->local_player = world->local_player; } /* ========================== * diff --git a/src/user.c b/src/user.c index 50e61f65..d18686f1 100644 --- a/src/user.c +++ b/src/user.c @@ -646,9 +646,9 @@ INTERNAL void user_update(void) * Find local entities * ========================== */ - struct sim_ent *local_client_ent = sim_ent_from_id(G.ss_blended, G.ss_blended->local_client_ent); - struct sim_ent *local_player = sim_ent_from_id(G.ss_blended, local_client_ent->client_control_ent); - struct sim_ent *local_camera = sim_ent_from_id(G.ss_blended, local_client_ent->client_camera_ent); + struct sim_ent *local_player = sim_ent_from_id(G.ss_blended, G.ss_blended->local_player); + struct sim_ent *local_control = sim_ent_from_id(G.ss_blended, local_player->player_control_ent); + struct sim_ent *local_camera = sim_ent_from_id(G.ss_blended, local_player->player_camera_ent); /* ========================== * * Find hovered entity @@ -1022,7 +1022,7 @@ INTERNAL void user_update(void) } /* Draw focus arrow */ - if (ent == local_player || sim_ent_id_eq(ent->id, G.debug_following)) { + if (ent == local_control || sim_ent_id_eq(ent->id, G.debug_following)) { struct sprite_sheet *sheet = sprite_sheet_from_tag_async(sprite_frame_scope, ent->sprite); struct sprite_sheet_slice slice = sprite_sheet_get_slice(sheet, LIT("attach.wep"), ent->animation_frame); struct v2 start = xform_mul_v2(sprite_xform, slice.center); @@ -1481,7 +1481,7 @@ INTERNAL void user_update(void) input_move_dir = xform_basis_invert_mul_v2(G.world_to_ui_xf, input_move_dir); /* Make move dir relative to world view */ input_move_dir = v2_mul(v2_norm(input_move_dir), move_speed); } - struct v2 input_aim_dir = v2_sub(G.world_cursor, sim_ent_get_xform(local_player).og); + struct v2 input_aim_dir = v2_sub(G.world_cursor, sim_ent_get_xform(local_control).og); /* Queue player control cmd */ { @@ -1625,30 +1625,30 @@ INTERNAL void user_update(void) pos.y += spacing; pos.y += spacing; - draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("local client ent: [%F]"), FMT_UID(local_client_ent->id.uid))); + draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("local player: [%F]"), FMT_UID(local_player->id.uid))); pos.y += spacing; pos.y += spacing; - draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("Network read: %F mbit/s"), FMT_FLOAT_P((f64)G.net_bytes_read.last_second * 8 / 1000 / 1000, 3))); + draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("Network read: %F mbit/s"), FMT_FLOAT_P((f64)G.net_bytes_read.last_second * 8 / 1000 / 1000, 3))); pos.y += spacing; - draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("Network write: %F mbit/s"), FMT_FLOAT_P((f64)G.net_bytes_sent.last_second * 8 / 1000 / 1000, 3))); + draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("Network write: %F mbit/s"), FMT_FLOAT_P((f64)G.net_bytes_sent.last_second * 8 / 1000 / 1000, 3))); pos.y += spacing; - draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("Ping (real): %F ms"), FMT_FLOAT_P(SECONDS_FROM_NS(local_client_ent->client_last_rtt_ns) * 1000, 3))); + draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("Ping (real): %F ms"), FMT_FLOAT_P(SECONDS_FROM_NS(local_player->player_last_rtt_ns) * 1000, 3))); pos.y += spacing; - draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("Ping (average): %F ms"), FMT_FLOAT_P(local_client_ent->client_average_rtt_seconds * 1000, 3))); + draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("Ping (average): %F ms"), FMT_FLOAT_P(local_player->player_average_rtt_seconds * 1000, 3))); pos.y += spacing; pos.y += spacing; - draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("Memory usage: %F MiB"), FMT_FLOAT_P((f64)gstat_get(GSTAT_MEMORY_COMMITTED) / 1024 / 1024, 3))); + draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("Memory usage: %F MiB"), FMT_FLOAT_P((f64)gstat_get(GSTAT_MEMORY_COMMITTED) / 1024 / 1024, 3))); pos.y += spacing; - draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("Virtual memory usage: %F TiB"), FMT_FLOAT_P((f64)gstat_get(GSTAT_MEMORY_RESERVED) / 1024 / 1024 / 1024 / 1024, 3))); + draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("Virtual memory usage: %F TiB"), FMT_FLOAT_P((f64)gstat_get(GSTAT_MEMORY_RESERVED) / 1024 / 1024 / 1024 / 1024, 3))); pos.y += spacing; - draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("Arenas allocated: %F"), FMT_UINT(gstat_get(GSTAT_NUM_ARENAS)))); + draw_text(G.ui_cmd_buffer, font, pos, string_format(temp.arena, LIT("Arenas allocated: %F"), FMT_UINT(gstat_get(GSTAT_NUM_ARENAS)))); pos.y += spacing; pos.y += spacing; @@ -1854,9 +1854,9 @@ INTERNAL void generate_user_input_cmds(struct sim_client *user_input_client, u64 struct sim_ent *control_cmd_ent = sim_ent_find_first_match_one(user_input_ss, SIM_ENT_PROP_CMD_CONTROL); if (!control_cmd_ent->valid) { control_cmd_ent = sim_ent_alloc_sync_src(user_input_root); - control_cmd_ent->predictor = user_input_ss->local_client_ent; + control_cmd_ent->predictor = user_input_ss->local_player; sim_ent_enable_prop(control_cmd_ent, SIM_ENT_PROP_CMD_CONTROL); - control_cmd_ent->predictor = user_input_client->ent_id; + control_cmd_ent->predictor = user_input_client->player_id; sim_ent_activate(control_cmd_ent, user_input_ss->tick); } /* Update local control cmd ent */ @@ -2313,12 +2313,12 @@ INTERNAL SYS_THREAD_ENTRY_POINT_FUNC_DEF(user_local_sim_thread_entry_point, arg) } if (master_ss->valid) { - struct sim_ent *master_client_ent = sim_ent_find_first_match_one(master_ss, SIM_ENT_PROP_CLIENT_IS_MASTER); + struct sim_ent *master_player = sim_ent_find_first_match_one(master_ss, SIM_ENT_PROP_PLAYER_IS_MASTER); /* Update ent id from master */ { - user_input_client->ent_id = master_ss->local_client_ent; - local_client->ent_id = master_ss->local_client_ent; + user_input_client->player_id = master_ss->local_player; + local_client->player_id = master_ss->local_player; } /* Check for misprediction */ @@ -2373,7 +2373,7 @@ INTERNAL SYS_THREAD_ENTRY_POINT_FUNC_DEF(user_local_sim_thread_entry_point, arg) struct sim_snapshot *base_ss = sim_snapshot_from_tick(local_client, step_base_tick); if (mispredicted_tick) { if (base_ss->valid) { - sim_snapshot_sync_ents(base_ss, master_ss, master_client_ent->id, 0); + sim_snapshot_sync_ents(base_ss, master_ss, master_player->id, 0); } else { base_ss = sim_snapshot_alloc(local_client, master_ss, step_base_tick); } @@ -2398,7 +2398,7 @@ INTERNAL SYS_THREAD_ENTRY_POINT_FUNC_DEF(user_local_sim_thread_entry_point, arg) while (step_tick <= step_end_tick) { ctx.world = sim_snapshot_alloc(local_client, prev_ss, step_tick); if (!mispredicted_tick && step_tick == step_end_tick) { - sim_snapshot_sync_ents(ctx.world, master_ss, master_client_ent->id, SIM_SYNC_FLAG_NOSYNC_PREDICTABLES); + sim_snapshot_sync_ents(ctx.world, master_ss, master_player->id, SIM_SYNC_FLAG_NOSYNC_PREDICTABLES); } sim_step(&ctx); prev_ss = ctx.world;