Jump to content
  • Advertisement
Sign in to follow this  
CelticSir

How to prevent race condition bugs due to ping ?

Recommended Posts

Hi

 

I have a situation where players can use an item in a game where they walk up to an item and interact with it. But only one person can at a time. 

How do you prevent the situation where the local user interacts and a remote player interacts at the same time and decide who should use it ? It seems like there is a potential window where both could end up using it before the system is aware that one of them is already using it. 

My other worry is if i have players who go to use a component, request the host if they can use it based on if its available for use, then everything will feel laggy in terms of response times when using things. Is there no real clean way to solve that other than accept a slower responsive time by asking the host if its usable ? 

Share this post


Link to post
Share on other sites
Advertisement

Make the "time to use" the item longer than the maximum round-trip-time you're prepared to accept. (The canonical example is walking over a health pack in a game like Quake.)

Thus, when the player walks up to the item and uses it, you can start playing the "use item" sound, but don't apply the effects until enough time has passed to break the tie.

If two players walk up and use the item, one of them will "win" (be first,) both of them will hear the "start using" sound, and the effects will accrue to whomever won the tie.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!