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

Sending entity updates to the render thread #21

Open
eranimo opened this issue Mar 30, 2019 · 0 comments
Open

Sending entity updates to the render thread #21

eranimo opened this issue Mar 30, 2019 · 0 comments

Comments

@eranimo
Copy link
Owner

eranimo commented Mar 30, 2019

Background

  • passing data between the two threads:
    • game thread: game.worker.ts - handles simulation, game loop
    • render thread: (i.e. main thread) GameManager.ts - renders React UI, map renderer
  • data is sent to the render thread using:
    • "shared memory" - SharedArrayBuffers (population map mode uses this)
      • this is hugely performant for very fast updates and anything that can be expressed in 2D
    • "data passing" - observables, passed via postMessage-style events I called "channels". Render thread only receives updates to observables they subscribe to, not all of them. Components that listen to these should unsubscribe from the channel after they unmount.
      • this is less memory efficient but it's far easier to use
  • ObservableDict allows you to observe both a specific key or the entire dict itself.

Problem

  • This above is kinda clunky and primitive, since what we really want is an "entity system" that can:
    • have references to each other (game cell -> pop for instance)
    • easily send updates to the render thread
    • work with the game loop
    • use as little memory as possible

Proposal

  • Entities have an ID and a type.
  • Entities have an ObservableDict called data whose values can be anything JSON serializable, or special types which we define, one of which is a Reference object to another Entity (more will probably be added later)

Open questions

  • Should entities have references, or should a "manager" class hold the references?
  • Is the above proposal too memory inefficient?
  • should attributes be defined as observables that belong to an entity, which is simply an ID number in a lookup table? (this is called an entity-attribute system). This might be more flexible, and better allow for references.
  • How should the entity updates be sent?

Related

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

1 participant