rework of user input system
This commit is contained in:
parent
6feef49545
commit
8a88f07366
BIN
display.cmi
BIN
display.cmi
Binary file not shown.
BIN
display.cmx
BIN
display.cmx
Binary file not shown.
50
display.ml
50
display.ml
|
@ -414,9 +414,12 @@ let is_visible_cube (cube : pt_3d array) (hash : (int * int * int, coloredCube d
|
|||
let draw_texture (rect : (int * int) array) (text : texture) light =
|
||||
(*set_color white;
|
||||
fill_poly rect ;;*)
|
||||
Stdlib.print_endline "{";
|
||||
for i = 0 to text.width -1 do
|
||||
for j = 0 to text.height -1 do
|
||||
if true then begin
|
||||
Printf.printf " (((%f)))" light;
|
||||
Stdlib.print_endline " ";
|
||||
let face_R = int_of_float ((float_of_int text.arr_red.(i).(j)) *. light)
|
||||
and face_G = int_of_float ((float_of_int text.arr_green.(i).(j)) *. light)
|
||||
and face_B = int_of_float ((float_of_int text.arr_blue.(i).(j)) *. light) in
|
||||
|
@ -435,7 +438,8 @@ let draw_texture (rect : (int * int) array) (text : texture) light =
|
|||
fill_poly [|bot_left; bot_right; top_right; top_left|]
|
||||
end
|
||||
done
|
||||
done ;;
|
||||
done;
|
||||
Stdlib.print_endline "}" ;;
|
||||
|
||||
let draw_cube_p (cube : pt_3d array) (hash : (int * int * int, coloredCube dynamic) Hashtbl.t) screen_wd screen_ht fov r g b =
|
||||
let adjusted = adjust_to_camera cube in
|
||||
|
@ -764,17 +768,17 @@ let chunkify_2 laby sz =
|
|||
let (cw, ch, cd) = coords_to_chunk (w*sz) (h*sz) (d*sz) in
|
||||
match Hashtbl.find_opt cubes (cw, ch, cd) with
|
||||
| None -> begin
|
||||
Printf.printf "created cube (%d, %d, %d) (%d)\n" (w*sz) (h*sz) (d*sz) sz;
|
||||
(*Printf.printf "created cube (%d, %d, %d) (%d)\n" (w*sz) (h*sz) (d*sz) sz;
|
||||
Printf.printf "in chunk (%d, %d, %d)\n" cw ch cd;
|
||||
Stdlib.print_endline " ";
|
||||
Stdlib.print_endline " ";*)
|
||||
let dyna = dyn_create {cube = create_cube (w*sz) (h*sz) (d*sz) sz; red = r; green = g; blue = b} in
|
||||
dyn_append dyna {cube = create_cube (w*sz) (h*sz) (d*sz) sz; red = r; green = g; blue = b};
|
||||
Hashtbl.add cubes (cw, ch, cd) dyna
|
||||
end
|
||||
| Some dyna -> begin
|
||||
Printf.printf "created cube (%d, %d, %d) (%d)\n" (w*sz) (h*sz) (d*sz) sz;
|
||||
(*Printf.printf "created cube (%d, %d, %d) (%d)\n" (w*sz) (h*sz) (d*sz) sz;
|
||||
Printf.printf "in chunk (%d, %d, %d)\n" cw ch cd;
|
||||
Stdlib.print_endline " ";
|
||||
Stdlib.print_endline " ";*)
|
||||
Hashtbl.remove cubes (cw, ch, cd);
|
||||
dyn_append dyna {cube = create_cube (w*sz) (h*sz) (d*sz) sz; red = r; green = g; blue = b};
|
||||
Hashtbl.add cubes (cw, ch, cd) dyna
|
||||
|
@ -1015,6 +1019,12 @@ let render_chunks hash camx camy camz ch_distance screen_wd screen_ht fov =
|
|||
manage_unexisting_chunk hash (fst (fst arr.(i))) (snd (fst arr.(i))) (fst (snd arr.(i))) screen_wd screen_ht fov ;
|
||||
done ;;
|
||||
|
||||
let get1char_plus () =
|
||||
if key_pressed () then
|
||||
read_key ()
|
||||
else
|
||||
'@' ;;
|
||||
|
||||
let play_dos laby =
|
||||
try
|
||||
Stdlib.print_endline "Building terrain...";
|
||||
|
@ -1029,30 +1039,36 @@ let play_dos laby =
|
|||
|
||||
(*print_cubes cs ;*)
|
||||
|
||||
while true do
|
||||
ignore (Sys.command "clear") ;
|
||||
let redraw = ref true in
|
||||
|
||||
Stdlib.print_endline "Rendering terrain...";
|
||||
let ch_x = ref 0
|
||||
and ch_y = ref 0
|
||||
and ch_z = ref 0 in
|
||||
|
||||
while true do
|
||||
if !redraw then begin
|
||||
auto_synchronize false;
|
||||
open_graph " 1500x1000";
|
||||
set_color black;
|
||||
fill_poly [|(0, 0); (__width__, 0); (__width__, __height__); (0, __height__); (0, 0)|];
|
||||
|
||||
let (ch_x, ch_y, ch_z) = coords_to_chunk_f (-. camera_xyz.x) (-. camera_xyz.y) camera_xyz.z in
|
||||
let (cx, cy, cz) = coords_to_chunk_f (-. camera_xyz.x) (-. camera_xyz.y) camera_xyz.z in
|
||||
ch_x := cx ; ch_y := cy ; ch_z := cz;
|
||||
|
||||
render_chunks hash ch_x ch_y ch_z chunk_dist __width__ __height__ fov ;
|
||||
render_chunks hash !ch_x !ch_y !ch_z chunk_dist __width__ __height__ fov ;
|
||||
|
||||
auto_synchronize true;
|
||||
end;
|
||||
redraw := false;
|
||||
|
||||
Printf.printf "current pos : (%f, %f, %f)\n" (-. camera_xyz.x) (-. camera_xyz.y) camera_xyz.z;
|
||||
Printf.printf "current chunk : (%d, %d, %d)" ch_x ch_y ch_z;
|
||||
Stdlib.print_endline " ";
|
||||
|
||||
let usr_input = get1char () in
|
||||
move_cam_hash_2 hash ch_x ch_y ch_z true usr_input
|
||||
let usr_input = get1char_plus () in
|
||||
if usr_input <> '@' then begin
|
||||
move_cam_hash_2 hash !ch_x !ch_y !ch_z true usr_input;
|
||||
redraw := true
|
||||
end
|
||||
done ;
|
||||
()
|
||||
with
|
||||
| Not_found -> Stdlib.print_endline "Looks like you tried to load an uninitialized chunk..." ;;
|
||||
| Not_found -> Stdlib.print_endline "Wait that's illegal\n" ;;
|
||||
|
||||
play_dos laby ;;
|
Loading…
Reference in New Issue