3mcd / javelin

ECS and multiplayer game development toolkit
https://javelin.games
198 stars 16 forks source link

Question: is it possible to use world.tryGet outside of a system? #160

Closed kenjinp closed 3 years ago

kenjinp commented 3 years ago

I'm finding inconsistent behaviors when changing or fetching component data using world.tryGet. In some cases, it seems to work just find, but in others, the update seems to work only in the context of a system and the change is not visible outside of a system context.

3mcd commented 3 years ago

When you say the change is not visible, do you mean the component itself is not updated? Or is the entity not synchronized as expected via @javelin/net?

kenjinp commented 3 years ago

Sorry, I mean changing a components data after it has been synced from the server on the client. With a system I can see that the component has taken on the new data but not outside of it (referencing the world directly).

3mcd commented 3 years ago

I see. This may depend on how the MessageHandler system is registered. messageHandler.push() enqueues the message, which lets messageHandler.system apply the operations contained within the messages during the next tick.

Are you expecting push() to update the component immediately/synchronously? e.g.

world.addSystem(messageHandler.system)

connection.subscribe(message => {
  messageHandler.push(message) // message has insert(player, Position)
  world.tryGet(player, Position) // null
  world.tick()
  world.tryGet(player, Position) // { x: 0, ... }
});

Sorry for the lack of documentation around the networking stuff.