Hello everyone!
First I'd like to be transparent and say as this is my first time posting on these forums (although I have been an avid reader!), so please let me know if I did not follow any posting guidelines that I might have missed.
I'm a software engineer who has been pursuing game development as a hobby for the past 3 to 4 years. I'm currently exploring game networking for a fast-paced 2D shooter game. While I've delved into various aspects of game dev, networking is a new challenge for me. I'm using an ECS architecture with Typescript/HTML canvas for the client and Typescript/node.js for the server, employing WebSockets for communication.
I'm facing an issue integrating WebSocket initialization and events management with ECS. My server initiates the WebSocket server and, on a new connection, a function handles initializing the network event callbacks. A significant amount of functionality is within this single function (e.g. calls to world.createEntity
and world.destroyEntity
), which seems inefficient. My challenge is determining where to process WebSocket messages within the ECS structure.
As an example, let's assume that the following JSON message is sent by a game client to the server:
{
"type": "command",
"frame": 54,
"payload": {
"moveRight": true,
"fire": true
}
}
Each of my player entities wear a CommandStreamComponent
that contains the past X frames of input that the server can use as it progresses through its simulation. This component looks a little like this:
class CommandStreamComponent extends Component {
commands: CircularBuffer<CommandMessage>
}
class CommandMessage{
frameNumber: number
command: Command
}
class Command{
moveRight: boolean = false
moveLeft: boolean = false
fire: boolean = false
}
What I am missing here, is the connection between the WebSocket events callbacks (e.g. on('message', …)
) and the ECS components/Systems. In other words, I aim for seamless integration where network event messages are smoothly channeled into the ECS workflow for various types of messages.
How can this be accomplished without compromising clarity? How should WebSockets (or any other full duplex communication solution) be integrated into an ECS architecture? I'm not religiously complying with pure ECS principles but aim for a clean networking approach within it. Insights from experienced developers in ECS and/or netcode would be invaluable.
TLDR: Need a clean method for integrating WebSockets and passing network messages within an ECS flow. Some resources I've used while studying games networking include :
- https://www.gabrielgambetta.com/client-server-game-architecture.html
- https://fabiensanglard.net/quake3/network.php
- https://snapnet.dev/blog/netcode-architectures-part-3-snapshot-interpolation
- https://developer.valvesoftware.com/wiki/Source_Multiplayer_Networking
- https://docs.unity3d.com/Packages/com.unity.netcode@1.0/manual/index.html
- Overwatch Gameplay Architecture and Netcode: https://www.youtube.com/watch?v=zrIY0eIyqmI