added some lwd, not sure it's useful yet

This commit is contained in:
cqc
2024-05-19 13:21:18 -05:00
parent accf22a9f9
commit 5c9c41487c
3 changed files with 207 additions and 187 deletions

View File

@ -18,7 +18,7 @@ end
let errorcb error desc =
Printf.printf "GLFW error %d: %s\n%!" error desc
let load_data vg =
let load_fonts vg =
let _ = Gv.Text.create vg ~name:"mono" ~file:"./assets/mono.ttf" in
let _ =
Gv.Text.create vg ~name:"icons" ~file:"./assets/entypo.ttf"
@ -62,8 +62,6 @@ let () =
in
let graph = Perfgraph.init Perfgraph.FPS "Frame Time" in
let _odata = load_data ctx in
let continue = ref true in
let min_fps = ref Float.max_float in
let max_fps = ref Float.min_float in
@ -78,9 +76,11 @@ let () =
in
let ui =
Ogui.Ui.window ctx ~window Gg.(Box2.v P2.o (P2.v 500. 500.))
Ogui.Ui.window ctx ~window
(Lwd.var Gg.(Box2.v P2.o (P2.v 500. 500.)))
in
load_fonts ui.gv;
GLFW.setKeyCallback ~window
~f:
(Some
@ -100,7 +100,7 @@ let () =
F.pr "oplevel.ml: building initial page@.";
let page =
ref
Lwd.var
Layout.(
vbox
~style:
@ -108,82 +108,76 @@ let () =
[
textedit
(TextEdit.multiline ui
(TextBuffer.of_repo
~path:[ ".config"; "init.ml" ]
~repo:rootrepo));
(Lwt_main.run
(TextBuffer.of_repo
~path:[ ".config"; "init.ml" ]
~repo:rootrepo)));
(*textedit
(TextEdit.multiline ui
(TextBuffer.of_repo ~path:[ "README" ] ~repo:rootrepo)); *)
])
in
(let open GLFW in
let open Event in
let open Ui in
Ui.update_bindings ui
(adds
let open GLFW in
let open Event in
Ui.update_bindings ui
Ui.(
adds
[
[ Key (Press, X, [ Control ]); Key (Press, E, [ Control ]) ];
]
[ Custom (fun () -> Lwt.return ()) ]));
[ Custom (fun () -> Lwt.return ()) ]);
F.pr "oplevel.ml: entering drawing loop@.";
let period_min = 1.0 /. 30. in
let t = GLFW.getTime () |> ref in
while (not GLFW.(windowShouldClose ~window)) && !continue do
Lwt_main.run
((fun () ->
let now = GLFW.getTime () in
let dt = now -. !t in
t := now;
Perfgraph.update graph dt;
let render page =
let now = GLFW.getTime () in
let dt = now -. !t in
t := now;
if now > 2. then (
let avg = 1. /. Perfgraph.average graph in
min_fps := Float.min avg !min_fps;
max_fps := Float.max avg !max_fps);
Perfgraph.update graph dt;
let _mx, _my = GLFW.getCursorPos ~window in
let win_w, win_h = GLFW.getWindowSize ~window in
if now > 2. then (
let avg = 1. /. Perfgraph.average graph in
min_fps := Float.min avg !min_fps;
max_fps := Float.max avg !max_fps);
Gl.viewport 0 0 win_w win_h;
Gl.clear
(Gl.color_buffer_bit lor Gl.depth_buffer_bit
lor Gl.stencil_buffer_bit);
Gl.enable Gl.blend;
Gl.blend_func Gl.src_alpha Gl.one_minus_src_alpha;
Gl.enable Gl.cull_face_enum;
Gl.disable Gl.depth_test;
let _mx, _my = GLFW.getCursorPos ~window 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;
Gl.viewport 0 0 win_w win_h;
Gl.clear
(Gl.color_buffer_bit lor Gl.depth_buffer_bit
lor Gl.stencil_buffer_bit);
Gl.enable Gl.blend;
Gl.blend_func Gl.src_alpha Gl.one_minus_src_alpha;
Gl.enable Gl.cull_face_enum;
Gl.disable Gl.depth_test;
Gc.major_slice 0 |> ignore;
GLFW.swapBuffers ~window;
GLFW.pollEvents ();
Unix.sleepf
Float.(max 0. (period_min -. GLFW.getTime () +. !t));
Lwt.return_unit)
())
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;
Gc.major_slice 0 |> ignore;
GLFW.swapBuffers ~window;
GLFW.pollEvents ();
Unix.sleepf Float.(max 0. (period_min -. GLFW.getTime () +. !t));
Lwt.return_unit
in
while not GLFW.(windowShouldClose ~window) do
Lwt_main.run (render (Lwd.peek page))
done;
Printf.printf "MIN %.2f\n" !min_fps;
Printf.printf "MAX %.2f\n%!" !max_fps;
if Array.length Sys.argv = 1 then
while not GLFW.(windowShouldClose ~window) do
GLFW.pollEvents ();
Unix.sleepf 0.25
done
Printf.printf "MAX %.2f\n%!" !max_fps
(* let out_ppf =
Format.formatter_of_out_functions
@ -205,5 +199,3 @@ let () =
(* ignore
(Toploop.use_input out_ppf
(String "#use \"topfind\";;\n#list;;")); *)
(* ignore (Toploop.use_input Format.std_formatter (String text)); *)
(* Wait for it to be closed. *)