Hi guys,
I'm working on a 2D platformer / RPG mix using Java with LibGDX and Kryonet. I recently finished implementing a reliable UDP protocol and thought that I can now finally start implementing some gameplay but I somehow hit a wall that stops me from progressing further:
How do I properly synchronize all entities to a player who just connected?
Some additional context:
- the game uses an entity component system architecture. Every networked entity has a network component which provides a unique id set by the server.
- the game's world is divided into several maps. This narrows down the number entities relevant for replication without much hassle: Entities on the same map as the client should be replicated.
- All entities are created by a factory using the entity's unique entity id to generate a copy of a "blueprint".
One solution I thought of is to just send the entityID along with movement updates and create the entity if the client can't find the entity by network id. This works for simple cases but what if I have to set things like for example a player's name or equipment? I need a full state update for this, not just the default entity. - the current and super naive way of replicating entities: When a client enters a map I loop through specific types of entities (players, monsters, loot, projectiles,...) and send a "create" packet related to the entity type to the client. E.g.: for each monster I send a "create monster" packet telling the client what kind of monster it is and a full state update. For each player I send a "create Player" packet including information about the equipped items, the player's hairstyle, etc.
I feel like this is a really bad way to handle this topic because I have to take care of every single entity type this way
Do you have any recommendations or know of best practices to properly handle this type of entity synchronization or "creation" without me handling each new entity type manually by writing additional packet types etc.?
Thanks for your help!