Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finish up incomplete serialization work #428

Open
4 tasks
patowen opened this issue Aug 13, 2024 · 2 comments
Open
4 tasks

Finish up incomplete serialization work #428

patowen opened this issue Aug 13, 2024 · 2 comments

Comments

@patowen
Copy link
Collaborator

patowen commented Aug 13, 2024

I'm filing a separate issue from #397 for this to better track the work I have left for later while working on inventory code.

I plan to try to keep the below sections up-to-date to serve as a living design document that I or someone else will be able to reference while implementing the above.

Decision status

Disconnection vs deactivation

The concept of "player disconnecting" and "player character becoming inactive", while generally simultaneous, should not be baked in as fundamentally the same in the engine. Keeping them separate would allow for more options, such as a "battle royale" game mode, where disconnected players stand there doing nothing (like a sitting duck) to prevent cheating while also preventing disqualification from accidental disconnection.

Whether a player is active or inactive is included when serializing. Although all active players will be immediately logged out if a server is rebooted, we don't necessarily want to enforce that their characters should be deactivated as well.

Serialization of inactive characters

Each inactive player should have its own EntityNode-like data structure but keyed by their player ID instead of NodeId (in a different redb table from the EntityNodes in the graph). The inactive players can keep track of where they would be in if they were active (probably with a new component than the way position is tracked for active entities), but since they're inactive, they're not part of the Graph at all.

This way, they would only need to be stored in disk and never loaded into memory until they log on. An EntityNode that is part of the Graph will only contain active players, so with this idea, it would be safe to save changes to it without taking inactive players into account.

Deactivating entities not associated with players is not handled by the above logic if the key is PlayerId, but there is no clear use case for this, and we should be able to support it with some adjustments if it comes up.

Open questions

How to better represent characters in ECS

The current split between Character and InactiveCharacter is a little clunky. For instance, some existing code has to extract the name field from both for serialization.

I had expressed uncertainty about this in #414 (comment).

I'm hopeful that we will be able to bypass this issue completely and get rid of the InactiveCharacter component after we update the way InactiveCharacters are serialized to no longer be part of the Graph. Since there will be no clear reason we need inactive characters to be loaded into memory at all, we might not need to have any way to represent that active/inactive state.

@Ralith
Copy link
Owner

Ralith commented Aug 14, 2024

CharacterId

A more apt name for this might be PlayerId, since what we're really using this for is identifying the player who gets to control the entity.

@patowen
Copy link
Collaborator Author

patowen commented Oct 5, 2024

A more apt name for this might be PlayerId, since what we're really using this for is identifying the player who gets to control the entity.

Oh, thinking about this again, I think there might be an even stronger reason for saying PlayerId instead of CharacterId.

It would probably be good ensure that the abstraction we choose is powerful enough to handle the possibility of a player trading characters with another player or a player having multiple characters in the same server.

Going this route, there is effectively both a "character identifier" and a "player identifier". Fortunately, with this line of reasoning, the "character identifier" can simply be EntityId, basically saying "this player controls that particular entity".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants