Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance of Graphics module #8406

Closed
vicuna opened this issue Dec 9, 2003 · 1 comment
Closed

Performance of Graphics module #8406

vicuna opened this issue Dec 9, 2003 · 1 comment
Labels

Comments

@vicuna
Copy link

vicuna commented Dec 9, 2003

Original bug ID: 1970
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: Christopher Zimmermann
Version: 3.04
OS: GNU/Linux
Submission from: p50842e30.dip0.t-ipconnect.de (80.132.46.48)

This is a wishlist bug.

Hello,

I was just trying to program the game "pong". But the graphics module is just
too slow to do this. Try the following code on a Pentium 166 and you'll see that
it displays only about every second frame:

Graphics.open_graph " 300x225";;
Graphics.set_window_title "Pong";;
Graphics.set_line_width 0;;
Graphics.auto_synchronize false;;

let sleepf x = let y = Unix.gettimeofday () +. x in
while y > Unix.gettimeofday () do () done;;

(let usleep timeout = sleepf timeout;;)
let usleep timeout =
let t1 = Unix.gettimeofday () in
let to_wait = ref timeout in
while !to_wait > 0. do
try ignore (Unix.select [] [] [] !to_wait) ; to_wait := 0.
with Unix.Unix_error (Unix.EINTR, _, _) ->
to_wait := t1 +. timeout -. Unix.gettimeofday ()
done;;

let x = ref 50 and y = ref 51 and mx = ref 1 and my = ref 1
and time = ref (Unix.gettimeofday ()) in
while true do
if !x > 290 && !mx > 0 then mx := 0 - !mx else
if !x < 10 && !mx < 0 then mx := 0 - !mx;
if !y > 215 && !my > 0 then my := 0 - !my else
if !y < 10 && !my < 0 then my := 0 - !my;
x := !x + !mx;
y := !y + !my;
time := !time +. 0.005;
if !time -. Unix.gettimeofday () > 0.
then begin
usleep (!time -. Unix.gettimeofday ());
(* Graphics.clear_graph ();)
Graphics.plot !x !y;
(
Graphics.fill_circle !x !y 10;*)
Graphics.synchronize ();
end;
done;;

As you see an usleep function is also missing.

I hope this helps improving OCaml,
Christopher Zimmermann

@vicuna
Copy link
Author

vicuna commented Jul 2, 2004

Comment author: administrator

usleep can already be done with Unix.select. Unwarranted use of
Graphics.synchronize is what causes the poor performance observed here. -XL

@vicuna vicuna closed this as completed Jul 2, 2004
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant