Skip to content

Add a shared character state #9

Open

Description

@jon-zu
  • Create a shared state for each session behind a lock, which book-keeps changes
  • Expose the shared state via the Session handle
  • Upon updating the state, notify the Session via an Update message

Further thoughts:
Deadlocks and other problems should be avoided per-design. As in not exposing the lock directly and just having functions to access and update the state. For example instead of getting a mutable reference to the current stats we should allow add/sub stats:

state.sub_stats(CharStats {
 hp: 50,
 mp: 5,
 ..Default::default()
});

instead of exposing the lock and doing It by hand:

state.lock().hp -= 50;
state.lock().mp -= 5;

Which is also prone to overflows.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions