reflect client acks
This commit is contained in:
parent
327a0e4af4
commit
36be516584
@ -318,7 +318,7 @@ void S_TickForever(WaveLaneCtx *lane)
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//- Read client snapshots
|
||||
//- Read snapshots
|
||||
|
||||
for (P_MsgNode *msg_node = in_msgs.first; msg_node; msg_node = msg_node->next)
|
||||
{
|
||||
@ -333,7 +333,7 @@ void S_TickForever(WaveLaneCtx *lane)
|
||||
|
||||
//- Read header
|
||||
BB_ReadBit(&bbr); // Raw
|
||||
i64 remote_ack = BB_ReadIV(&bbr);
|
||||
i64 tmp_remote_ack = BB_ReadIV(&bbr);
|
||||
|
||||
//- Read control
|
||||
b32 done = 0;
|
||||
@ -374,6 +374,12 @@ void S_TickForever(WaveLaneCtx *lane)
|
||||
}
|
||||
}
|
||||
|
||||
//- Update remote ack
|
||||
if (tmp_remote_ack > client->remote_ack)
|
||||
{
|
||||
client->remote_ack = tmp_remote_ack;
|
||||
}
|
||||
|
||||
//- Update ack
|
||||
if (control->tick < world_frame->tick)
|
||||
{
|
||||
@ -538,77 +544,10 @@ void S_TickForever(WaveLaneCtx *lane)
|
||||
// }
|
||||
// }
|
||||
|
||||
//////////////////////////////
|
||||
//- Apply player snapshots
|
||||
|
||||
// P_MsgList user_msgs = Zi;
|
||||
// {
|
||||
// i64 user_msgs_min_tick = world_frame->tick + user_msg_tick_range.min;
|
||||
// i64 user_msgs_max_tick = world_frame->tick + user_msg_tick_range.max;
|
||||
// // Prune queued player msgs
|
||||
// {
|
||||
// for (P_MsgNode *msg_node = queued_user_msgs.first; msg_node;)
|
||||
// {
|
||||
// P_MsgNode *next = msg_node->next;
|
||||
// b32 prune = 0;
|
||||
// if (msg_node->msg.predicted && (msg_node->msg.tick < user_msgs_min_tick || msg_node->msg.tick > user_msgs_max_tick))
|
||||
// {
|
||||
// prune = 1;
|
||||
// }
|
||||
// if (prune)
|
||||
// {
|
||||
// DllQueueRemove(queued_user_msgs.first, queued_user_msgs.last, msg_node);
|
||||
// SllStackPush(first_free_user_msg_node, msg_node);
|
||||
// --queued_user_msgs.count;
|
||||
// }
|
||||
// msg_node = next;
|
||||
// }
|
||||
// }
|
||||
// // Push player msgs to queue
|
||||
// {
|
||||
// for (P_MsgNode *src_msg_node = input->msgs.first; src_msg_node; src_msg_node = src_msg_node->next)
|
||||
// {
|
||||
// if (!src_msg_node->msg.predicted || (src_msg_node->msg.tick >= user_msgs_min_tick && src_msg_node->msg.tick <= user_msgs_max_tick))
|
||||
// {
|
||||
// P_MsgNode *dst_msg_node = first_free_user_msg_node;
|
||||
// if (dst_msg_node)
|
||||
// {
|
||||
// SllStackPop(first_free_user_msg_node);
|
||||
// ZeroStruct(dst_msg_node);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// dst_msg_node = PushStruct(perm, P_MsgNode);
|
||||
// }
|
||||
// dst_msg_node->msg = src_msg_node->msg;
|
||||
// DllQueuePush(queued_user_msgs.first, queued_user_msgs.last, dst_msg_node);
|
||||
// ++queued_user_msgs.count;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// // Pop frame player msgs from queue
|
||||
// {
|
||||
// for (P_MsgNode *src_msg_node = queued_user_msgs.first; src_msg_node;)
|
||||
// {
|
||||
// P_MsgNode *next = src_msg_node->next;
|
||||
// if (!src_msg_node->msg.predicted || src_msg_node->msg.tick == world_frame->tick)
|
||||
// {
|
||||
// {
|
||||
// P_MsgNode *dst_msg_node = PushStruct(frame_arena, P_MsgNode);
|
||||
// dst_msg_node->msg = src_msg_node->msg;
|
||||
// DllQueuePush(user_msgs.first, user_msgs.last, dst_msg_node);
|
||||
// ++user_msgs.count;
|
||||
// }
|
||||
// {
|
||||
// DllQueueRemove(queued_user_msgs.first, queued_user_msgs.last, src_msg_node);
|
||||
// SllStackPush(first_free_user_msg_node, src_msg_node);
|
||||
// --queued_user_msgs.count;
|
||||
// }
|
||||
// }
|
||||
// src_msg_node = next;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
//////////////////////////////
|
||||
//- Process player edit messages
|
||||
@ -749,29 +688,6 @@ void S_TickForever(WaveLaneCtx *lane)
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//- Update ent controls
|
||||
|
||||
// for (P_Ent *ent = P_FirstEnt(frame); !P_IsEntNil(ent); ent = P_NextEnt(ent))
|
||||
// {
|
||||
// ent->fire_presses = 0;
|
||||
// }
|
||||
|
||||
// for (P_Ent *player = P_FirstEnt(frame); !P_IsEntNil(player); player = P_NextEnt(player))
|
||||
// {
|
||||
// if (player->is_iser)
|
||||
// {
|
||||
// P_Ent *target = P_EntFromKey(player->guy);
|
||||
// if (!P_IsEntNil(target))
|
||||
// {
|
||||
// target->move = ClampVec2Len(player->move, 1);
|
||||
// target->look = player->look;
|
||||
// target->fire_held = player->fire_held;
|
||||
// target->fire_presses += player->fire_presses;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
//////////////////////////////
|
||||
//- Step frame
|
||||
|
||||
@ -799,58 +715,6 @@ void S_TickForever(WaveLaneCtx *lane)
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//- Push snapshot messages
|
||||
|
||||
// for (P_Ent *player = P_FirstEnt(world_frame); !P_IsEntNil(player); player = P_NextEnt(player))
|
||||
// {
|
||||
// if (player->is_user)
|
||||
// {
|
||||
// Arena *msgs_arena = P_tl.out_msgs_arena;
|
||||
// P_Msg *msg = P_PushMsg(P_MsgKind_SimSnapshot, Zstr);
|
||||
// msg->dst_user = player->key;
|
||||
// NET_SendFlag_None = 1;
|
||||
// P_SimSnapshot *snapshot = &msg->sim_snapshot;
|
||||
// {
|
||||
// snapshot->world_seed = world->seed;
|
||||
// snapshot->tick = world_frame->tick;
|
||||
// snapshot->time_ns = world_frame->time_ns;
|
||||
// //- Push entity deltas
|
||||
// for (P_Ent *ent = P_FirstEnt(world_frame); !P_IsEntNil(ent); ent = P_NextEnt(ent))
|
||||
// {
|
||||
// P_Delta *delta = 0;
|
||||
// {
|
||||
// P_DeltaNode *dn = PushStruct(frame_arena, P_DeltaNode);
|
||||
// snapshot->deltas_count += 1;
|
||||
// SllQueuePush(snapshot->first_delta_node, snapshot->last_delta_node, dn);
|
||||
// delta = &dn->delta;
|
||||
// }
|
||||
// delta->kind = P_DeltaKind_RawEnt;
|
||||
// delta->ent = *ent;
|
||||
// }
|
||||
// //- Push debug draw information
|
||||
// {
|
||||
// i64 dst_idx = 0;
|
||||
// snapshot->first_debug_draw_node = 0;
|
||||
// snapshot->last_debug_draw_node = 0;
|
||||
// snapshot->debug_draw_nodes_count = P_tl.debug_draw_nodes_count;
|
||||
// P_DebugDrawNode *dst_nodes = PushStructsNoZero(frame_arena, P_DebugDrawNode, snapshot->debug_draw_nodes_count);
|
||||
// for (P_DebugDrawNode *src = P_tl.first_debug_draw_node; src; src = src->next)
|
||||
// {
|
||||
// P_DebugDrawNode *dst = &dst_nodes[dst_idx];
|
||||
// *dst = *src;
|
||||
// dst_idx += 1;
|
||||
// SllQueuePush(snapshot->first_debug_draw_node, snapshot->last_debug_draw_node, dst);
|
||||
// }
|
||||
// ResetArena(P_tl.debug_arena);
|
||||
// P_tl.first_debug_draw_node = 0;
|
||||
// P_tl.last_debug_draw_node = 0;
|
||||
// P_tl.debug_draw_nodes_count = 0;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
//////////////////////////////
|
||||
//- Send snapshots
|
||||
|
||||
@ -866,7 +730,8 @@ void S_TickForever(WaveLaneCtx *lane)
|
||||
PackedDeltaNode *last_delta_node = 0;
|
||||
|
||||
//- Pack entity deltas
|
||||
P_Frame *src_frame = &P_NilFrame;
|
||||
// P_Frame *src_frame = P_FrameFromTick(world, client->remote_ack);
|
||||
P_Frame *src_frame = P_FrameFromTick(world, 0);
|
||||
for (P_Ent *ent = P_FirstEnt(world_frame); !P_IsEntNil(ent); ent = P_NextEnt(ent))
|
||||
{
|
||||
b32 should_transmit = 0;
|
||||
@ -936,6 +801,7 @@ void S_TickForever(WaveLaneCtx *lane)
|
||||
BB_WriteUBits(&packer_bbw, world->seed, 64);
|
||||
BB_WriteUBits(&packer_bbw, client->player.v, 64);
|
||||
BB_WriteIV(&packer_bbw, client->ack);
|
||||
BB_WriteIV(&packer_bbw, client->remote_ack);
|
||||
}
|
||||
|
||||
//- Append packed delta
|
||||
@ -1039,177 +905,6 @@ void S_TickForever(WaveLaneCtx *lane)
|
||||
ZeroStruct(&P_tl.out_msgs);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// {
|
||||
// // Group messages by client
|
||||
// for (P_MsgNode *msg_node = P_tl.out_msgs.first; msg_node; msg_node = msg_node->next)
|
||||
// {
|
||||
// P_Msg *msg = &msg_node->msg;
|
||||
// if (NET_IsKeyNil(msg->dst))
|
||||
// {
|
||||
// // Broadcast msg
|
||||
// for (S_Client *client = S.first_client; client; client = client->next)
|
||||
// {
|
||||
// P_MsgNode *dst_msg_node = PushStruct(frame_arena, P_MsgNode);
|
||||
// *dst_msg_node = *msg_node;
|
||||
// DllQueuePush(client->out_msgs.first, client->out_msgs.last, dst_msg_node);
|
||||
// ++client->out_msgs.count;
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // Targeted msg
|
||||
// S_Client client = S_ClientFromNetKey(msg->dst);
|
||||
// if (!S_IsClientNil(client))
|
||||
// {
|
||||
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// for (S_Client *client = first_client; client; client = client->next)
|
||||
// {
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// for (P_MsgNode *msg_node = P_tl.out_msgs.first; msg_node; msg_node = msg_node->next)
|
||||
// {
|
||||
// P_Msg *msg = &msg_node->msg;
|
||||
// if (P_IsKeyNil(msg->dst_user))
|
||||
// {
|
||||
// // Broadcast
|
||||
// String packed = P_PackMessage(frame_arena, msg);
|
||||
// for (P_Ent *player = P_FirstEnt(world_frame); !P_IsEntNil(player); player = P_NextEnt(player))
|
||||
// {
|
||||
// if (player->is_user)
|
||||
// {
|
||||
// NET_Send(net_pipe, player->net, packed, NET_SendFlag_None);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// P_Ent *player = P_EntFromKey(world_frame, msg->dst_user);
|
||||
// if (!NET_IsKeyNil(player->net))
|
||||
// {
|
||||
// String packed = P_PackMessage(frame_arena, msg);
|
||||
// NET_Send(net_pipe, player->net, packed, NET_SendFlag_None);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// for (P_MsgNode *msg_node = P_tl.out_msgs.first; msg_node; msg_node = msg_node->next)
|
||||
// {
|
||||
// P_Msg *msg = &msg_node->msg;
|
||||
// if (P_IsKeyNil(msg->dst_user))
|
||||
// {
|
||||
// // Broadcast
|
||||
// String packed = P_PackMessage(frame_arena, msg);
|
||||
// for (P_Ent *player = P_FirstEnt(world_frame); !P_IsEntNil(player); player = P_NextEnt(player))
|
||||
// {
|
||||
// if (player->is_user)
|
||||
// {
|
||||
// NET_Send(net_pipe, player->net, packed, NET_SendFlag_None);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// P_Ent *player = P_EntFromKey(world_frame, msg->dst_user);
|
||||
// if (!NET_IsKeyNil(player->net))
|
||||
// {
|
||||
// String packed = P_PackMessage(frame_arena, msg);
|
||||
// NET_Send(net_pipe, player->net, packed, NET_SendFlag_None);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
// // TODO: Only copy active entities
|
||||
// LockTicketMutex(&P.sim_output_back_tm);
|
||||
// {
|
||||
// P_OutputState *output = &P.sim_output_states[P.sim_output_back_idx];
|
||||
|
||||
// // Build messages
|
||||
// {
|
||||
// // Push tiles
|
||||
// if (tiles_dirty)
|
||||
// {
|
||||
// P_Msg *msg = 0;
|
||||
// {
|
||||
// P_MsgNode *msg_node = PushStruct(output->arena, P_MsgNode);
|
||||
// DllQueuePush(output->msgs.first, output->msgs.last, msg_node);
|
||||
// ++output->msgs.count;
|
||||
// msg = &msg_node->msg;
|
||||
// }
|
||||
// msg->kind = P_MsgKind_Tiles;
|
||||
// msg->tiles_hash = world->tiles_hash;
|
||||
// msg->raw_tiles = PushStructsNoZero(output->arena, u8, P_TilesCount);
|
||||
// msg->tile_range = RNG2I32(VEC2I32(0, 0), VEC2I32(P_TilesPitch, P_TilesPitch));
|
||||
// CopyBytes(msg->raw_tiles, world->tiles, P_TilesCount);
|
||||
// has_sent_initial_tick = 1;
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Build snapshot
|
||||
// {
|
||||
// P_Snapshot *snapshot = &output->snapshot;
|
||||
|
||||
// snapshot->world_seed = world->seed;
|
||||
// snapshot->tick = world_frame->tick;
|
||||
// snapshot->time_ns = world_frame->time_ns;
|
||||
|
||||
// // Push entity deltas
|
||||
// for (P_Ent *ent = P_FirstEnt(world_frame); !P_IsEntNil(ent); ent = P_NextEnt(ent))
|
||||
// {
|
||||
// P_Delta *delta = 0;
|
||||
// {
|
||||
// P_DeltaNode *dn = PushStruct(output->arena, P_DeltaNode);
|
||||
// snapshot->deltas_count += 1;
|
||||
// SllQueuePush(snapshot->first_delta_node, snapshot->last_delta_node, dn);
|
||||
// delta = &dn->delta;
|
||||
// }
|
||||
// delta->kind = P_DeltaKind_RawEnt;
|
||||
// delta->ent = *ent;
|
||||
// }
|
||||
|
||||
// // Push debug draw information
|
||||
// {
|
||||
// i64 dst_idx = 0;
|
||||
// snapshot->first_debug_draw_node = 0;
|
||||
// snapshot->last_debug_draw_node = 0;
|
||||
// snapshot->debug_draw_nodes_count = P_tl.debug_draw_nodes_count;
|
||||
// P_DebugDrawNode *dst_nodes = PushStructsNoZero(output->arena, P_DebugDrawNode, snapshot->debug_draw_nodes_count);
|
||||
// for (P_DebugDrawNode *src = P_tl.first_debug_draw_node; src; src = src->next)
|
||||
// {
|
||||
// P_DebugDrawNode *dst = &dst_nodes[dst_idx];
|
||||
// *dst = *src;
|
||||
// dst_idx += 1;
|
||||
// SllQueuePush(snapshot->first_debug_draw_node, snapshot->last_debug_draw_node, dst);
|
||||
// }
|
||||
|
||||
// ResetArena(P_tl.debug_arena);
|
||||
// P_tl.first_debug_draw_node = 0;
|
||||
// P_tl.last_debug_draw_node = 0;
|
||||
// P_tl.debug_draw_nodes_count = 0;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// UnlockTicketMutex(&P.sim_output_back_tm);
|
||||
|
||||
//////////////////////////////
|
||||
//- Prune ents
|
||||
|
||||
|
||||
@ -20,6 +20,7 @@ Struct(S_Client)
|
||||
i64 max_controls;
|
||||
P_Control *controls;
|
||||
|
||||
i64 remote_ack;
|
||||
i64 ack;
|
||||
|
||||
u64 remote_tiles_hash;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user