Created
February 2, 2020 23:33
-
-
Save stormouse/33a153ee38f9204db1ca10920dcd300d to your computer and use it in GitHub Desktop.
game network event design discussion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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