davidyu / Sonar

Networked multiplayer SHMUP-lite
http://lewenyu.com/sonar
MIT License
0 stars 0 forks source link

Merge sonar-socket-experiment back into sonar #22

Closed davidyu closed 10 years ago

davidyu commented 10 years ago
  1. remove all message sending from God and delegate to various systems that need to do it
    • all input should be handled outside of God (98f0121, 6bbcb2a).
    • all network updates should be handled outside of God (77d9b32f3cb2875a5658b9f969f39810e2e80654).
  2. allow all systems access EntityBuilder and the Client Socket without lambda-passing (b9ef756, 77d9b32f3cb2875a5658b9f969f39810e2e80654).
davidyu commented 10 years ago

Thought dump

To do 2. (ONLY w.r.t making Client socket accessible), I can make the player entity contain the ClientCmp (which has the socket), and then all relevant systems will have access. But this seems hacky. Alternatively, all interested systems could do a query for entities with the ClientCmp (there is only one), and refer to it there. This is more roundabount (and it is perhaps not so efficient if we have to iterate over all entities every time we process), but its intent is more clear and less confusing than giving the ClientCmp to the player.

What we really need is for the ClientSys (which for now, manages reading from the socket, but in the future, should also manage writing to the socket) to subscribe to and receive events from other systems. It should also notify other systems when it reads from the socket and finds relevant data for them.

Message passing must be implemented, though, and it makes the game more complex than I'd like it to be.

This can be implemented in a more distributed manner by implementing a NetworkSystem interface (with read/write methods and an identifier). Each System reads and writes updates that it cares about, and the socket is implemented in a higher level system (parallel to World rather than under it). The master socket system will read from the socket and multiplex incoming data to the correct systems. The downside is that this unnecessarily ties systems to network logic. Recall that the ideal implementation is one where the dev just adds a SyncCmp to any entity he wants synchronized, and the SyncSys will take care of everything (also realize this is very non-distributed).

To make EntityBuilder accessible to all systems, just make it into a system, and everyone else can grab it via World.getSystem( EntityAssemblySys )

davidyu commented 10 years ago

It is possible to make everything nice and pretty with a SyncSys, designed as follows:

Cons:

davidyu commented 10 years ago

Done in a89a35dfd6effbd9acb4a6b15589642e1b56cd88