How should channels be used #81
-
I'm not really sure how channels should be used Currently I have a list of all the messages and I assign a channel to each one. This doesn't seem the right way to me since soon I could finish the amount of available channels since it's just a u8. Should I instead use a different channel when I need a different channel configuration and wrap the messages in an enum? Thank you :) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey, Something like // Critical messages that should be reliable and could break game if lost (just an example)
enum ServerReliableMessage {
PlayerAttack {
player_id: ID,
direction: Vec2
},
PlayerMoved {
player_id: ID,
position: Vec2
},
PlayerDeath {
player_id: ID
}
...
}
// Sounds/Particle Effects can be unreliable if you want (they shouldn't break gameplay if lost)
enum ServerUnreliableMessage {
Sound {
sound_id: ID,
position: Vec2
}
SpawnParticle {
particle_id: ID,
position: Vec2,
duration: Duration
}
...
} So each enum would have a channel if the correct configuration that suits their need. For example, you could have 2 reliable channel messages, one for gameplay that is more critical and they would have a resend time of 100 ms, and another reliable channel for chat messages that are not critical, so we could use a resend time of 1 second. |
Beta Was this translation helpful? Give feedback.
Hey,
Your guess is correct, you want to group messages that share the same configuration in an enum.
So probably having an enum for reliable messages, and another one for unreliable is good enough.
Something like