diff --git a/examples/hello/hello.fs b/examples/hello/hello.fs index 21ed963..f626a48 100644 --- a/examples/hello/hello.fs +++ b/examples/hello/hello.fs @@ -38,8 +38,8 @@ module Model = } type Msg = - | MovePaddle1 of float - | MovePaddle2 of float + | MovePaddle1 + | MovePaddle2 let game: Game = GameBuilder.local Model.initial @@ -74,7 +74,7 @@ let tick model (tick: Time.FrameTime) = |> handleCollisionWithPaddle model.paddle1 |> handleCollisionWithPaddle model.paddle2) - ( { model with ball = newBall; counter = model.counter + 3 }, Effect.none () ) + ( { model with ball = newBall; counter = model.counter + 3 }, Effect.wrapped (MovePaddle2) |> Effect.map(fun _a -> MovePaddle1) ) open Fable.Core.Rust @@ -85,6 +85,7 @@ let init (_args: array) = game |> GameBuilder.draw3d (fun world frameTime -> + let eff = Effect.wrapped (MovePaddle2) |> Effect.map (fun _a -> MovePaddle1); let colorMaterial = Material.color(0.0f, 1.0f, 0.0f, 1.0f); let textureMaterial = Material.texture( Texture.file("vr_glove_color.jpg")); // let barrelModel = Model.file("ExplodingBarrel.glb"); diff --git a/runtime/functor-runtime-common/src/effect.rs b/runtime/functor-runtime-common/src/effect.rs index 4c9d4fb..01e209d 100644 --- a/runtime/functor-runtime-common/src/effect.rs +++ b/runtime/functor-runtime-common/src/effect.rs @@ -1,3 +1,5 @@ +use fable_library_rust::Native_::Func1; + #[derive(Clone)] pub enum Effect { None, @@ -12,4 +14,11 @@ impl Effect { pub fn wrapped(data: T) -> Effect { Effect::Wrapped(data) } + + pub fn map(mapping: Func1, source: Effect) -> Effect { + match source { + Effect::None => Effect::None, + Effect::Wrapped(v) => Effect::Wrapped(mapping(v)), + } + } } diff --git a/src/Functor.Game/Effect.fs b/src/Functor.Game/Effect.fs index b361e78..3819404 100644 --- a/src/Functor.Game/Effect.fs +++ b/src/Functor.Game/Effect.fs @@ -3,9 +3,14 @@ open Fable.Core [")>] type effect<'msg> = | Noop + module Effect = + [] let none (): effect<_> = nativeOnly [] - let wrapped a: 'a -> effect<'a> = nativeOnly \ No newline at end of file + let wrapped (a: 'a) : effect<'a> = nativeOnly + + [] + let map (fn: 'a -> 'b) (eff: effect<'a>) : effect<'b> = nativeOnly \ No newline at end of file diff --git a/src/Functor.Game/Runtime.fs b/src/Functor.Game/Runtime.fs index 80256b1..3955b2e 100644 --- a/src/Functor.Game/Runtime.fs +++ b/src/Functor.Game/Runtime.fs @@ -95,7 +95,15 @@ module Runtime member this.setState(incomingState) = state <- OpaqueState.unsafe_coerce incomingState member this.tick(frameTime: Time.FrameTime) = + + // Todo: If first frame, run 'init' + + // Todo: Run any pending effects + let (newState, effects) = GameRunner.tick myGame state frameTime + + // Todo: Run tick effects + state <- newState () member this.render(frameTime: Time.FrameTime) =