Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check remaining time before executing an action #51

Closed
bvssvni opened this issue Aug 19, 2015 · 7 comments
Closed

Check remaining time before executing an action #51

bvssvni opened this issue Aug 19, 2015 · 7 comments

Comments

@bvssvni
Copy link
Member

bvssvni commented Aug 19, 2015

Might solve #46.

Currently, instant actions that does not consume time can execute when there is no remaining time. This might cause problems when an action consumes the whole time interval and trigger an instant action.

@bvssvni
Copy link
Member Author

bvssvni commented Aug 19, 2015

One argument against this change: If your update each half second and wait one second, then it will execute the next action in 1.5 seconds. However, if you wait 1.1 seconds it will execute in 1.5 seconds.

@bvssvni
Copy link
Member Author

bvssvni commented Aug 19, 2015

Sequence(Wait(0.5), Action(Inc), Wait(0.5), Action(Inc)) will increment 1 with this change and 2 with the current design.

@bvssvni
Copy link
Member Author

bvssvni commented Aug 19, 2015

The question is whether you need time to run or whether you consume time to stop. If you should have time to run then 0.0 is treated as exactly zero time, while if you consume time to stop then 0.0 and an infinitesimal amount of time is the same.

Currently I'm thinking you should consume time to stop, because the semantics of "update something" implies that you intend to update, even if there is no time.

@dobrite
Copy link

dobrite commented Aug 20, 2015

This is my use case:

let behavior = While(Box::new(WaitForever), vec![Sequence(vec![
    Action(Action::Down), Action(Action::Up)
])]);

A simulation game where turns are fixed units of time e.g. a tile based game. Actions take a full UpdateEvent worth of time to run. The dt for the UpdateEvent is, say, 0.2. Down moves the unit down, and returns (Success, 0.0). This moves on to Up which receives 0.0.

Is it the responsibility of the Action to check if there is time remaining or should the tree prevent Up from running, since no dt is remaining? e.g.

if args.dt == 0.0 {
  return RUNNING;
} else {
  // move unit up
  return (Success, 0.0)
};

My feeling is that it would be nice if the library prevented Up from running, but in that case I'm not sure how to differentiate between an instant action (returns same dt) from one that receives 0.0 and returns 0.0, in effect making it "instant".

See the test all_time_sequence from #49 with this line and this line commented out. The test runs forever with actions that take "full" turns.

I hope that makes sense.

@bvssvni
Copy link
Member Author

bvssvni commented Aug 20, 2015

If the action does not check the time, but assumes it will be given a full delta time, then it messes up partial updates. For example, assume you change the UPS so .dt becomes 0.1 instead of 0.2, now your game logic runs at twice the speed. Or, if you wait 0.1 seconds before the action, it executes at 0.1 instead of 0.2.

I believe it should be the action's responsibility to check the remaining time.

There are two ways you can solve your issue:

  1. Check the remaining time and "consume" it until it hits 0.2 seconds.
  2. Make it instant by returning args.dt and use Wait(0.2).

@dobrite
Copy link

dobrite commented Aug 21, 2015

Thanks for the outstanding discussion! I appreciate the help and work that you've done.

@bvssvni
Copy link
Member Author

bvssvni commented Aug 21, 2015

Closing since this won't be implemented.

@bvssvni bvssvni closed this as completed Aug 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants