From defc6a87d8ce5c5b50c5daf0340cc95222e93283 Mon Sep 17 00:00:00 2001 From: "nazarov.andrey" Date: Mon, 17 Sep 2012 17:07:06 +0400 Subject: [PATCH] pending touches when enter background fixed --- src/Lightning.ml | 14 ++++++++++---- src/Stage.ml | 16 +++++++++++----- src/Stage.mli | 2 ++ src/ios/mlwrapper_ios.m | 3 ++- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/Lightning.ml b/src/Lightning.ml index b177cd25..d36eb3d8 100644 --- a/src/Lightning.ml +++ b/src/Lightning.ml @@ -48,21 +48,27 @@ type stage_constructor = float -> float -> Stage.c; (* value _stage: ref (option (float -> float -> stage eventTypeDisplayObject eventEmptyData)) = ref None; *) IFDEF PC THEN -value init s = +value init s = let s = (s :> stage_constructor) in - Pc_run.run s; + Pc_run.run s; + ELSE value _stage : ref (option stage_constructor) = ref None; value init s = let s = (s :> stage_constructor) in - _stage.val := Some s; + _stage.val := Some s; value stage_create width height = match _stage.val with [ None -> failwith "Stage not initialized" - | Some stage -> stage width height + | Some stage -> + let s = stage width height in + ( + Stage.instance.val := Some s; + s; + ) ]; IFDEF ANDROID THEN (* for link mlwrapper_android *) diff --git a/src/Stage.ml b/src/Stage.ml index 76b8b2e1..eed591f8 100644 --- a/src/Stage.ml +++ b/src/Stage.ml @@ -51,6 +51,7 @@ exception Touch_not_found; value _screenSize = ref (0.,0.); value screenSize () = !_screenSize; +value instance = ref None; value onBackground = ref None; value on_background () = @@ -59,7 +60,12 @@ value on_background () = match !onBackground with [ Some f -> f() | None -> () - ] + ]; + + match !instance with + [ Some s -> s#cancelAllTouches () + | _ -> () + ]; ); Callback.register "on_background" on_background; @@ -154,10 +160,10 @@ class virtual c (_width:float) (_height:float) = end touches in let otherTouches = !cTouches in - let () = debug:touches "Length of other touches: %d" (List.length otherTouches) in + (* let () = debug:touches "Length of other touches: %d" (List.length otherTouches) in *) ( List.iter (fun (_,tch) -> tch.n_phase := TouchPhaseStationary) otherTouches; - let () = debug:touches +(* let () = debug:touches List.iter begin fun (target,touch) -> debug:touches "touch: %ld %f [%f:%f], [%F:%F], %d, %s, [ %s ]\n%!" touch.n_tid touch.n_timestamp touch.n_globalX touch.n_globalY @@ -165,7 +171,7 @@ class virtual c (_width:float) (_height:float) = touch.n_tapCount (string_of_touchPhase touch.n_phase) target#name end (processedTouches @ otherTouches) - in + in *) (* группируем их по таргетам и вперед - incorrect *) let fireTouches = List.fold_left (fun res (target,touch) -> MList.add_assoc target (Touch.t_of_n touch) res) [] processedTouches in let fireTouches = @@ -270,4 +276,4 @@ class virtual c (_width:float) (_height:float) = initializer Timers.init 0.; -end; +end; \ No newline at end of file diff --git a/src/Stage.mli b/src/Stage.mli index 66597153..40210bf3 100644 --- a/src/Stage.mli +++ b/src/Stage.mli @@ -46,3 +46,5 @@ class virtual c: [ float ] -> [ float ] -> method onUnload: unit -> unit; method dispatchBackPressedEv : unit -> bool; end; + +value instance: ref (option c); \ No newline at end of file diff --git a/src/ios/mlwrapper_ios.m b/src/ios/mlwrapper_ios.m index 09d86bc2..8325df57 100644 --- a/src/ios/mlwrapper_ios.m +++ b/src/ios/mlwrapper_ios.m @@ -13,7 +13,7 @@ void process_touches(UIView *view, NSSet* touches, UIEvent *event, mlstage *mlstage) { - PRINT_DEBUG("process touched"); + PRINT_DEBUG("process touched %d", [touches count]); caml_acquire_runtime_system(); value mltouch = 1,mltouches = 1,globalX = 1,globalY = 1,time = 1, lst_el = 1; Begin_roots5(mltouch,time,globalX,globalY,mltouches); @@ -49,6 +49,7 @@ void process_touches(UIView *view, NSSet* touches, UIEvent *event, mlstage *mls } End_roots(); caml_release_runtime_system(); + PRINT_DEBUG("process touches end"); }