Skip to content

Instantly share code, notes, and snippets.

@stormouse
Created February 2, 2020 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stormouse/33a153ee38f9204db1ca10920dcd300d to your computer and use it in GitHub Desktop.
Save stormouse/33a153ee38f9204db1ca10920dcd300d to your computer and use it in GitHub Desktop.
game network event design discussion
void main()
{
start_network();
start_game();
}
void network(callback on_receive_a, callback on_receive_b)
{
while(1)
{
auto data = network_library.receive();
switch(data->library_packet_type)
{
case A:
on_receive_a(data->payload);
break;
case B:
on_receive_b(data->payload);
break;
}
}
}
void on_receive_callback(byte* payload)
{
event_system::event_queue.enqueue(
event_parser_i_somehow_found.parse(payload)
);
}
void game()
{
// copy old state
// [code omitted]
// process events
while(!event_system::event_queue.empty())
{
auto evt = event_system::event_queue.dequeue();
}
// render or other stuff
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment