events use lwt_stream, mainloop uses recusive fun, better binding handling, binding pretty printing
This commit is contained in:
54
oplevel.ml
54
oplevel.ml
@ -81,21 +81,28 @@ let main =
|
||||
in
|
||||
|
||||
load_fonts ui.gv;
|
||||
|
||||
let event_stream, event_push = Lwt_stream.create () in
|
||||
Ogui.Ui.process_events ui event_stream;
|
||||
GLFW.setKeyCallback ~window
|
||||
~f:
|
||||
(Some
|
||||
(fun _window key _int state mods ->
|
||||
Lwt.async (fun () ->
|
||||
(* ignore key releases and capslock *)
|
||||
match (state, key, mods) with
|
||||
| Release, _, _ | _, CapsLock, _ -> ()
|
||||
| _ -> event_push (Some (`Key (state, key, mods)))
|
||||
(*Lwt.async (fun () ->
|
||||
Ogui.Ui.keycallback ui state key mods >>= fun _ ->
|
||||
Lwt.return_unit)))
|
||||
Lwt.return_unit) *)))
|
||||
|> ignore;
|
||||
|
||||
GLFW.setCharCallback ~window
|
||||
~f:
|
||||
(Some
|
||||
(fun _window ch ->
|
||||
Lwt.async (fun () ->
|
||||
Ogui.Ui.chrcallback ui ch >>= fun _ -> Lwt.return_unit)))
|
||||
event_push (Some (`Char ch))
|
||||
(* Lwt.async (fun () -> Ogui.Ui.chrcallback ui ch) *)))
|
||||
|> ignore;
|
||||
|
||||
GLFW.setWindowSizeCallback ~window
|
||||
@ -188,23 +195,7 @@ let main =
|
||||
let period_min = 1.0 /. 30. in
|
||||
let t = GLFW.getTime () |> ref in
|
||||
|
||||
let render root =
|
||||
let page = Lwd.quick_sample root in
|
||||
let win_w, win_h = GLFW.getWindowSize ~window in
|
||||
let width, height = (float win_w, float win_h) in
|
||||
let box = Gg.(Box2.v V2.zero Size2.(v width (height -. 20.))) in
|
||||
Gv.begin_frame ctx ~width ~height ~device_ratio:1.;
|
||||
Perfgraph.render graph ctx (width -. 205.) 5.;
|
||||
(* F.epr "box=%a@." Gg.Box2.pp box;
|
||||
F.epr "Painter.layout=%a@." Gg.Box2.pp *)
|
||||
Painter.layout box ui page >>= fun _ ->
|
||||
(* Demo.render_demo ctx mx my win_w win_h now !blowup data; *)
|
||||
Gv.end_frame ctx;
|
||||
|
||||
Lwt.return_unit
|
||||
in
|
||||
|
||||
while not GLFW.(windowShouldClose ~window) do
|
||||
let rec draw_loop () =
|
||||
let now = GLFW.getTime () in
|
||||
let dt = now -. !t in
|
||||
t := now;
|
||||
@ -225,13 +216,26 @@ let main =
|
||||
Gl.blend_func Gl.src_alpha Gl.one_minus_src_alpha;
|
||||
Gl.enable Gl.cull_face_enum;
|
||||
Gl.disable Gl.depth_test;
|
||||
Lwt.async (fun () -> render page_root);
|
||||
let page = Lwd.quick_sample page_root in
|
||||
let win_w, win_h = GLFW.getWindowSize ~window in
|
||||
let width, height = (float win_w, float win_h) in
|
||||
let box = Gg.(Box2.v V2.zero Size2.(v width (height -. 20.))) in
|
||||
Gv.begin_frame ctx ~width ~height ~device_ratio:1.;
|
||||
Perfgraph.render graph ctx (width -. 205.) 5.;
|
||||
(*F.epr "Painter.layout=%a@." Gg.Box2.pp box; *)
|
||||
Painter.layout box ui page >>= fun _ ->
|
||||
(* Demo.render_demo ctx mx my win_w win_h now !blowup data; *)
|
||||
Gv.end_frame ctx;
|
||||
Gc.major_slice 0 |> ignore;
|
||||
GLFW.swapBuffers ~window;
|
||||
GLFW.pollEvents ();
|
||||
Unix.sleepf Float.(max 0. (period_min -. GLFW.getTime () +. !t))
|
||||
done;
|
||||
|
||||
Lwt_unix.sleep
|
||||
Float.(max 0. (period_min -. GLFW.getTime () +. !t))
|
||||
>>= fun () ->
|
||||
if not GLFW.(windowShouldClose ~window) then draw_loop ()
|
||||
else Lwt.return_unit
|
||||
in
|
||||
draw_loop () >>= fun () ->
|
||||
Printf.printf "MIN %.2f\n" !min_fps;
|
||||
Printf.printf "MAX %.2f\n%!" !max_fps;
|
||||
Lwt.return_unit
|
||||
|
||||
Reference in New Issue
Block a user