Coder Social home page Coder Social logo

Player state variables about thnk HOT 3 CLOSED

arthuro555 avatar arthuro555 commented on August 22, 2024
Player state variables

from thnk.

Comments (3)

arthuro555 avatar arthuro555 commented on August 22, 2024 1

Sure! Here are a few pointers:

In FlatBuffers, your whole payload needs to be all created at once. That means you cannot include player-only data in the game-wide state update messages that is the same for for everyone: that would require regenerating data meant for everyone for each player, and would absolutely kill performance. What you'll want to do is therefore create a new separate message type to update player-only data.

To create a new message type, you'll need to:

  1. Go in protocol/ServerMessages and write a FlatBuffer definition of your payload. A table with a Variable should be good enough for now.
  2. In protocol/ServerMessages/ServerMessage.fbs, import your new message file and add it to the ServerMessagesContent union.
  3. In code/server/ServerMessagesSender.ts, add a function similar to the previous ones, that creates a FlatBuffer ServerMessage using a Builder, and sends it via the adapter.
  4. In code/client/ClientLifetimeFunctions.ts, add to the switch statement for processing incoming messages a new case fr your new message type.

Once that is done, you'll have your message implemented. All that you will have left to do is:

On the server:

  • Store a SyncedVariable for each player in Code/PlayerContext.ts
  • Make the switching of player context replace the scene variable PlayerState with the stored SyncedVariable
  • Send a diff of their own variables to each player in the server lifetime function, just after the shared game state

On the client:

  • In the message handler for your new message type, deserialize the diffs sent in that message into the PlayerState scene variable

There should be no need (for now) to support full snapshots, since a player variable is empty when the player connects (as it is only for that player :p), so there is no previous state the client should be aware of before applying the diffs from the server.


I'll be leaving this to you then, don't hesitate to ask if you have any questions! If that is too difficult after all, please say so so someone else may give the issue a try ;)

I also recommend reading the flat buffers doc a quick read before you get started:

https://google.github.io/flatbuffers/flatbuffers_guide_writing_schema.html
https://google.github.io/flatbuffers/flatbuffers_guide_tutorial.html (Click on "TypeScript" to get accurate code snippets)

from thnk.

Oxey405 avatar Oxey405 commented on August 22, 2024

Can I try to work on it ?

from thnk.

arthuro555 avatar arthuro555 commented on August 22, 2024

Since I haven't heard back, I'll assume it didn't work out. This is a pretty crucial feature so I'll be working on it myself now.

from thnk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.