Sign in to follow this  
PumpkinPieman

Event based input in a state model

Recommended Posts

I've been thinking this over, and I'm not really sure how to handle it. I'm using an input library that has a call back for windows events, this event is passed to the current state then processed. The state has a few functions: OnLoad, OnEvent, OnDestroy, OnCalculate, OnDraw, DoneState. OnEvent gets sent the message and it's processed there, however I was planning on OnCalculating updating the state variables and I don't want new events to rush in while it's calculating. The only think I can think of is an event buffer, but I don't know if that's a wise choice seeing as it may delay input. What would be a wise choice for a model where events aren't handled in the same thread?

Share this post


Link to post
Share on other sites
Well, either you will have to block other event handling (or at least that which affects the state) while handling the Calculating event (delaying any input received at that time), or find a way of coping with two handlers being run simultaneously. Which is the better solution depends on a number of factors:

  • How long does the calculation take? If it's longer than say 50ms, if this is an action game, or 250ms for any supposedly responsive environment, the delay is probably unacceptably long.
  • How critical is it that partially-recalculated data is not read? If it's just a case of some parts being a frame behind, does that matter? You can certainly mitigate this effect by having OnCalculating buffer an entire copy of the new data, and only locking the global state data for long enough to write (not calculate) that new data.

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