Queue iter over elements instead of headers

main
Cameron Murphy Reikes 2 years ago
parent 3ff13d5529
commit 9ff100561a

@ -1719,7 +1719,7 @@ SerMaybeFailure ser_client_to_server(SerState *ser, ClientToServer *msg)
{ {
size_t to_skip = queue_num_elements(msg->input_data) - num; size_t to_skip = queue_num_elements(msg->input_data) - num;
size_t i = 0; size_t i = 0;
QUEUE_ITER(msg->input_data, cur_header) QUEUE_ITER(msg->input_data, InputFrame, cur)
{ {
if (i < to_skip) if (i < to_skip)
{ {
@ -1727,7 +1727,6 @@ SerMaybeFailure ser_client_to_server(SerState *ser, ClientToServer *msg)
} }
else else
{ {
InputFrame *cur = (InputFrame *)cur_header->data;
SER_MAYBE_RETURN(ser_inputframe(ser, cur)); SER_MAYBE_RETURN(ser_inputframe(ser, cur));
} }
} }

@ -1427,9 +1427,8 @@ static void draw_dots(cpVect camera_pos, double gap)
void apply_this_tick_of_input_to_player(uint64_t tick_to_search_for) void apply_this_tick_of_input_to_player(uint64_t tick_to_search_for)
{ {
InputFrame *to_apply = NULL; InputFrame *to_apply = NULL;
QUEUE_ITER(&input_queue, cur_header) QUEUE_ITER(&input_queue, InputFrame, cur)
{ {
InputFrame *cur = (InputFrame *)cur_header->data;
if (cur->tick == tick(&gs)) if (cur->tick == tick(&gs))
{ {
to_apply = cur; to_apply = cur;

@ -25,7 +25,7 @@ typedef struct Queue
#define QUEUE_SIZE_FOR_ELEMENTS(element_size, max_elements) ((sizeof(QueueElementHeader) + element_size) * max_elements) #define QUEUE_SIZE_FOR_ELEMENTS(element_size, max_elements) ((sizeof(QueueElementHeader) + element_size) * max_elements)
// oldest to newest // oldest to newest
#define QUEUE_ITER(q_ptr, cur_header) for (QueueElementHeader *cur_header = (q_ptr)->next; cur_header != NULL; cur_header = cur_header->next) #define QUEUE_ITER(q_ptr, type, cur) for (QueueElementHeader *cur_header = (q_ptr)->next; cur_header != NULL; cur_header = cur_header->next) for(type *cur = (type*)cur_header->data; cur != NULL; cur = NULL)
void queue_init(Queue *q, size_t element_size, char *data, size_t data_length); void queue_init(Queue *q, size_t element_size, char *data, size_t data_length);
void queue_clear(Queue *q); void queue_clear(Queue *q);
void *queue_push_element(Queue *q); void *queue_push_element(Queue *q);

@ -312,9 +312,8 @@ void server(void *info_raw)
CONNECTED_PEERS(enet_host, cur) CONNECTED_PEERS(enet_host, cur)
{ {
int this_player_index = (int)(int64_t)cur->data; int this_player_index = (int)(int64_t)cur->data;
QUEUE_ITER(&player_input_queues[this_player_index], cur_header) QUEUE_ITER(&player_input_queues[this_player_index], InputFrame, cur)
{ {
InputFrame *cur = (InputFrame *)cur_header->data;
if (cur->tick == tick(&gs)) if (cur->tick == tick(&gs))
{ {
gs.players[this_player_index].input = *cur; gs.players[this_player_index].input = *cur;

Loading…
Cancel
Save