1 min
When connected to the server the players can send each other messages. This is done using the packet system mentioned in a previous post. Special streamming operaters had to be set up for sending strings across the network compared to other data like ints or chars. A string is a pointer to an array of chars if you tried to stream it in using the normal way of streamming thne it would give you memory location of the pointer and what would of been outputted was a load of nonsense that you couldn’t understand or nothing at all.
// normal packet
packet_data.insert(packet_data.end(), as_char, as_char + size);
// string packet
packet_data.insert(packet_data.end(), string.data(), string.data() + string_length);
As you can see the string is passed in but we have to do string.data() in order to get the correct data. We can’t do this in the normal packet as it uses a template class so it allows for anything and only the string is used that requires .data() after the variable has been passed in. Since we can’t check what type of variable has been passed in with T, it is much esaier to have a separate functions for sending strings.
Subscribe to this blog via RSS.
Low level programming dev diary 28
Text based adventure dev diary 6
Level design developer diary 3
Game engine programming dev diary 14
Audio-visual production dev diary 7
Audio-Visual Production: Particle System Mesh Spawning Issues
Posted on 20 Feb 2020Low level programming dev diary (28) Text based adventure dev diary (6) Level design developer diary (3) Post mortem (4) Ex-machina dev diary (11) Game engine programming dev diary (14) Network game dev diary (11) Audio-visual production dev diary (7)