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

Delayed messages #15

Open
matmleave opened this issue Apr 30, 2024 · 3 comments
Open

Delayed messages #15

matmleave opened this issue Apr 30, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@matmleave
Copy link
Collaborator

  • A general case is that one may want to send a message later, like do something after 10 secs, or do something when mouse clicks next time, instead of doing something right now
  • planned effect:
type LayerMsg
    = ...
    | LayerMsgDelayedOnce (EnvC -> Maybe LayerMsg)       -- triggered only once
    | LayerMsgDelayed (EnvC -> Maybe LayerMsg)           -- always valid
  • example1: If one want to send 1 to a layer called "A" when mouse is clicked next time
updateModel env lmsg model =
    ...
    let cond fenv =
        case fenv.msg of
            MouseDown _ _ ->
                Just (LayerIntMsg 1)
            _ ->
                Nothing
    in
    (model, [(LayerName "A", LayerMsgDelayedOnce cond)], env)
  • example2: If one want to send 1 to layer "A" after some time, then write
updateModel env lmsg model =
    ...
    let cond fenv =
        case fenv.msg of
            Tick t ->
                let cond2 fenv2 =
                    case fenv2.msg of
                        Tick t2 ->
                            if (toSecond utc t2) >= (toSecond utc t) + 100 then
                                Just (LayerIntMsg 1)
                            else
                                Nothing
                        _ ->
                            Nothing
                in 
                Just (LayerMsgDelayedOnce cond2)
            _ ->
                Nothing
   (model, [(LayerName "A", LayerMsgDelayedOnce cond)], env)

this will start counting time after next Tick.

@matmleave matmleave added the enhancement New feature or request label Apr 30, 2024
@linsyking
Copy link
Owner

This could be implemented by event bus subsystem which might be implemented as a component.

@Monolitho
Copy link

Yes... But since it is a highly-demanded feature in game-development, I still would say it is necessary to add it into messenger.

@linsyking
Copy link
Owner

linsyking commented Aug 7, 2024

Using the latest messenger, this could be implemented easily as a global component. We could implement this in extra.

Yes... But since it is a highly-demanded feature in game-development, I still would say it is necessary to add it into messenger.

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

3 participants