You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 1970 Reporter: administrator Status: closed Resolution: not a bug Priority: normal Severity: minor Category: ~DO NOT USE (was: OCaml general)
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:
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
The text was updated successfully, but these errors were encountered:
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
The text was updated successfully, but these errors were encountered: