Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

World State

Olaf Szmidt edited this page Aug 30, 2017 · 6 revisions

Found in file: world_state.py

The world state class servers act as a gateway/buffer between the updates generated in different parts of the back-end and the data emitted by the socket.

It contains all the parameters that need to be sent to the client every time the world is updated. These are:

  • Player (aka avatars) creation, deletion and update.
  • Changes in map features, i.e. creation and deletion of:
    • Health points
    • Score points
    • Pickups
    • Obstacles

Rather than sending the whole state of the world each time, we only send updates of the current world of the state.

A typical initial state sent by the server may look like:

   {
      "map_features":{
         "obstacle":{
            "create":[
               {
                  "y":4,
                  "x":4,
                  "id":3713084879516988331
               },
               {
                  "y":5,
                  "x":2,
                  "id":3713082714461575706
               },
               [...]
               {
                  "y":2,
                  "x":5,
                  "id":3713085962047400956
               }
            ],
            "delete":[
            ]
         },
         "health_point":{
            "create":[
            ],
            "delete":[
            ]
         },
         [...]
      },
      "players":{
         "create":[
            {
               "y":2,
               "x":-5,
               "score":0,
               "health":5,
               "id":1
            }
         ],
         "update":[
         ],
         "delete":[
         ]
      }
   }

A typical update, on the other hand, should be much more lightweight, and have most of the data in the update part:

   {
      "map_features":{
         "pickup":{
            "create":[
            ],
            "delete":[
            ]
         },
         "obstacle":{
            "create":[

            ],
            "delete":[

            ]
         },
         [...]
      },
      "players":{
         "create":[
         ],
         "update":[
            {
               "y":-1,
               "x":-4,
               "score":0,
               "health":5,
               "id":1
            }
         ],
         "delete":[
         ]
      }
   }

Each avatar has its own personalized view of the world, this feature being implemented in pull request 223. This feature is crucial for the Unity client in big worlds as the view of each avatar will be always small enough to put very few pressure on obeject rendering.

Clone this wiki locally