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

Add Instant Transitions #82

Open
TheDudeFromCI opened this issue Dec 17, 2020 · 5 comments
Open

Add Instant Transitions #82

TheDudeFromCI opened this issue Dec 17, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@TheDudeFromCI
Copy link
Member

Currently, manual transitions only mark the transition as should transition on the next physics tick. Since this is not Instant, many events may be missed or sent to the wrong target.

There should be a method for transitioning instantly.

@TheDudeFromCI TheDudeFromCI added the enhancement New feature or request label Dec 17, 2020
@sefirosweb
Copy link
Contributor

sefirosweb commented Sep 25, 2021

Hi @TheDudeFromCI , do you have any ideas how to do it? How can I help you?

I think I need it, I have some process so that it needs to be "faster"

Example -> When digging a block and it has water behind it, the BOT needs to calculate where to place the block to prevent water from entering the tunnel

Currently it is "a little" slow and the water gets to enter and bothers,

For now I have it done in different state machines and for that reason it is "slow",
I have replaced it so that it calculates everything in a function without jumping between state machines, with this method dont jump between state machines and is faster, but the code is more "dirty"

It would be interesting what you comment to avoid dirty code

Maybe adding a opitional value similar has "fasterJump: true" ?

 new StateTransition({
      parent: mineBlock,
      child: placeBlock1,
      fasterJump: true, // <----
      name: 'mineBlock -> placeBlock1',
      onTransition: () => {
        placeBlock2Position = targets.position.clone()
        const positionForPlaceBlock = getNewPositionForPlaceBlock(targets.position.offset(0, -1, 0))
        targets.position = positionForPlaceBlock.newPosition
        placeBlock1.setOffset(positionForPlaceBlock.blockOffset)
      },
      shouldTransition: () => mineBlock.isFinished()
    })

PS: I am attaching a video that shows what I mean is "slow" https://www.youtube.com/watch?v=9OH_71bTH-k

@TheDudeFromCI
Copy link
Member Author

It couldn't be a normal shouldTransition? state transition as those all run on clocks. In order to achieve this effect, it will need to be triggered manually and run synchronously.

@sefirosweb
Copy link
Contributor

Hi @TheDudeFromCI I don't know if we talking of the same,

If i do the "checks" via state machines is going a """bit slow""" (really only in 1-2 seconds is done but the water is faster =P )

I need to do that because i need to check a large numbers of possible blocks, in in the logic return one of them "good" then pass to new statemachine if not they return back for check if more blocks needs to be check

I can do it without state machine, but the code starts to be confusing, via "state machine" is friendly to see,

I attach video of """slow""" check

https://www.youtube.com/watch?v=B6JJwgIrTX0

@TheDudeFromCI
Copy link
Member Author

@sefirosweb I understand your problem. The problem comes from the fact that the state machine runs on an async timer which prevents instant updates. See this diagram.

state machine loop

This is basically how the state machine chooses when to transition and actually performs the transition. (Link)

The update() function is called once every tick current the physicsTick event. In the diagram, this is represented by the blue part. If a transition should occur, then it calls the yellow part which calls all of the corresponding events and marks the new state as active. Because this part is exclusively hidden behind the timer, it can't run any faster than this while still remaining async.

The solution would be to extract the yellow part of the code into a new function that you can call from your own code, the green part, on the state machine itself and turn this part into a synchronous function.

@sefirosweb
Copy link
Contributor

Thanks a lot, understood!

I'm trying to read your code, if it is possible to add to the end of "onStateEntered" to force the update function without waiting to next physic tick,

But I think for a now the best way is do as you said

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants