s2 event loop passes time variable

This commit is contained in:
tali 2024-01-19 15:23:05 -05:00
parent d6882feb15
commit 95758ed7c6
2 changed files with 16 additions and 7 deletions

View File

@ -19,20 +19,18 @@ let main () =
let scene = Scene.load "main" ~tg ~sg in let scene = Scene.load "main" ~tg ~sg in
let root = Scene.get scene "root" in let root = Scene.get scene "root" in
let render () = let render time =
begin begin
(* Update *)
let time = Sdl.get_ticks () |> Int32.to_int in let tf = TG.model (Scene.transform root) in
begin begin
let tx = let tx =
Float_infix.( Float_infix.(
Float.sin (flt time / 1000.0 * 2.0) * 300.0 Float.sin (time * 2.0) * 300.0
+ 512.0 + 512.0
) )
in in
let ty = 400.0 in let ty = 400.0 in
let tf = TG.model (Scene.transform root) in
Mat2A.set tf ~tx ~ty ~sx:1.0 ~sy:1.0 Mat2A.set tf ~tx ~ty ~sx:1.0 ~sy:1.0
end; end;
@ -48,7 +46,12 @@ let main () =
end end
in in
Window.event_loop window ~render; Window.event_loop window ~render;
info (fun m -> m "quitting")
begin
info (fun m -> m "quitting");
Window.destroy window;
Renderer.destroy ren;
end
let () = let () =
Ohlog.init () ~min_level:DEBUG; Ohlog.init () ~min_level:DEBUG;

View File

@ -19,6 +19,8 @@ let make ~title =
let event_loop window ~render = let event_loop window ~render =
let event = Sdl.Event.create () in let event = Sdl.Event.create () in
let some_event = Some event in let some_event = Some event in
let time = ref 0.0 in
try try
Sdl.show_window window; Sdl.show_window window;
while true do while true do
@ -28,7 +30,11 @@ let event_loop window ~render =
| _ -> | _ ->
trace (fun m -> m "uncaught event (%d)" Sdl.Event.(get event typ)) trace (fun m -> m "uncaught event (%d)" Sdl.Event.(get event typ))
done; done;
render ()
time := Int32.to_float (Sdl.get_ticks ()) /. 1000.0;
render !time;
done done
with Quit -> with Quit ->
() ()
let destroy = Sdl.destroy_window