Jump to content

Handle ticking server data that needs to be accessible from client at any point?


Turtledove

Recommended Posts

I've written a player capability class which keeps track of some statistics kept and incremented on the server. Most of the information isn't expected to be updated very often so it's only synchronized with the client when it meets a certain flag. However, some of the information (stamina, fuel, etc) is updated every tick, and directly affects client-side rendering. For example, the player cannot left click (the hand's swing render event doesn't even trigger) if stamina does not meet a certain threshold. Sending packets back and forth between client/server every tick is obviously a terrible idea, how should I approach something like this? Is it possible to keep two counts running synchronously between client/server? And then sync the two every once in a while.

Edited by Turtledove
Link to comment
Share on other sites

Hi

 

Yeah that's exactly how vanilla does it in many places (eg block mining); it executes the code logic on both client and server (eg eating to reduce fuel, gradual regeneration of stamina, etc), and periodically resynchs the client by sending it a packet.

 

It will help a lot if you design your gameplay to be tolerant of mis-synch between client and server - for example, instead of making the player unable to swing at all below a certain stamina, you could make it always swing but just be very weak.  That makes mis-synchronisation a lot less noticeable to the player than an on/off threshold (i.e. where the client thinks the player can swing but the server doesn't).

 

-TGG

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.