Skip to content

Commit

Permalink
Cleanup ;;'s
Browse files Browse the repository at this point in the history
  • Loading branch information
grant-olson committed Mar 31, 2010
1 parent 633d69f commit bb0ef1f
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 100 deletions.
24 changes: 12 additions & 12 deletions binfile.ml
Expand Up @@ -6,21 +6,21 @@ Generic functions for reading binary files.
*)

let int32_of_int =
Int32.of_int;;
Int32.of_int

let in_char_as_int32 f =
Int32.of_int (input_byte f);;
Int32.of_int (input_byte f)

let in_char f =
Int32.to_int (in_char_as_int32 f);;
Int32.to_int (in_char_as_int32 f)

let in_word_as_int32 f =
let c1 = in_char_as_int32 f in
let c2 = in_char_as_int32 f in
Int32.add c1 (Int32.mul 256l c2);;
Int32.add c1 (Int32.mul 256l c2)

let in_word f =
Int32.to_int (in_word_as_int32 f);;
Int32.to_int (in_word_as_int32 f)

let in_signed_word f =
let w1 = Int32.to_int (in_word_as_int32 f) in
Expand All @@ -29,20 +29,20 @@ let in_signed_word f =
then
w1 - 65545
else
w1;;
w1

let in_dword_as_int32 f =
let w1 = in_word_as_int32 f in
let c1 = in_char_as_int32 f in
let c2 = in_char_as_int32 f in
Int32.add w1 (Int32.add (Int32.mul c1 65536l) (Int32.mul c2 16777216l));;
Int32.add w1 (Int32.add (Int32.mul c1 65536l) (Int32.mul c2 16777216l))

let in_dword f =
Int32.to_int (in_dword_as_int32 f);;
Int32.to_int (in_dword_as_int32 f)

let in_single f =
let dw = in_dword_as_int32 f in
Int32.float_of_bits dw;;
Int32.float_of_bits dw

let in_string f len =
let buf = String.create len in
Expand All @@ -51,11 +51,11 @@ let in_string f len =
with a \000, so we skip that and fix later *)
let eos = String.index_from buf 1 '\000' in
let str = String.sub buf 0 eos in
str;;
str

let in_array f count constructor =
Array.init count (fun x -> constructor f);;
Array.init count (fun x -> constructor f)

let in_array_array f rows columns constructor =
Array.init rows (fun x -> in_array f columns constructor);;
Array.init rows (fun x -> in_array f columns constructor)

2 changes: 1 addition & 1 deletion c3a.ml
Expand Up @@ -625,7 +625,7 @@ let vect_to_angle x y =
let set_material_color r g b a =
GlLight.material `front (`specular (r, g, b, a));
GlLight.material `front (`diffuse (r *. 0.5, g *. 0.5, b *. 0.5, a));
GlLight.material `front (`ambient (r *. 0.5, g *. 0.5, b *. 0.5, a));;
GlLight.material `front (`ambient (r *. 0.5, g *. 0.5, b *. 0.5, a))

let draw_squares () =
Gl.disable `texture_2d;
Expand Down
6 changes: 3 additions & 3 deletions font_test.ml
Expand Up @@ -47,7 +47,7 @@ let display () =

Gl.flush ();

Glut.postRedisplay () ;;
Glut.postRedisplay ()

let main () =
ignore(Glut.init Sys.argv);
Expand All @@ -56,8 +56,8 @@ let main () =
ignore(Glut.createWindow ~title:"lablglut & LablGL");
Glut.displayFunc ~cb:display;

Glut.mainLoop();
;;
Glut.mainLoop()


let _ = main ()

72 changes: 36 additions & 36 deletions md3.ml
Expand Up @@ -4,38 +4,38 @@
(* Load a Quake 3 .md3 format file into a structure and provide
render it in openGl *)

open Binfile;;
open Binfile

exception Invalid_md3_format;;
exception Invalid_md3_format



type vector = {x:float;y:float;z:float};;
type vector = {x:float;y:float;z:float}

let print_vector vect =
Printf.printf " vector = {x = %.2f; y = %.2f; z = %.2f;}" vect.x
vect.y vect.z;;
vect.y vect.z

(*#install_printer print_vector;;*)

type triangle = {a:int;b:int;c:int};;
type triangle = {a:int;b:int;c:int}

type st = {s:float;t:float};;
type st = {s:float;t:float}

type frame = {min_bounds:vector;
max_bounds:vector;
frame_origin:vector;
radius:float;
frame_name:string};;
frame_name:string}


type tag = {tag_name:string;
tag_origin:vector;
axis1:vector;
axis2:vector;
axis3:vector;};;
axis3:vector;}

type vertex = {vx:float;vy:float;vz:float;nx:float;ny:float;nz:float};;
type vertex = {vx:float;vy:float;vz:float;nx:float;ny:float;nz:float}

type shader = {shader_name:string;
shader_index:int;}
Expand All @@ -55,7 +55,7 @@ type surface = {surface_name:string;
triangles:triangle array;
sts:st array;
vertexes:vertex array array;
};;
}

type md3 = {path:string;
flags:int32;
Expand All @@ -69,32 +69,32 @@ type md3 = {path:string;
eof_offset:int;
frames:frame array;
tags:tag array array;
surfaces:surface array;};;
surfaces:surface array;}


let in_packed_float f =
(* I guess to save space, md3 files pack floats
as a signed 16 bit int. You devide by 64.0
to get the float *)
let sw1 = float_of_int (in_signed_word f) in
sw1 /. 64.0;;
sw1 /. 64.0

let in_vector f =
let x = in_single f in
let y = in_single f in
let z = in_single f in
{x=x;y=y;z=z};;
{x=x;y=y;z=z}

let in_triangle f =
let a = in_dword f in
let b = in_dword f in
let c = in_dword f in
{a=a;b=b;c=c};;
{a=a;b=b;c=c}

let in_st f =
let s = in_single f in
let t = in_single f in
{s=s;t=t};;
{s=s;t=t}

let in_vertex f =
let vx = in_packed_float f in
Expand All @@ -107,11 +107,11 @@ let in_vertex f =
let nx = (cos lat) *. (sin lng) in
let ny = (sin lat) *. (sin lng) in
let nz = (cos lng) in
{vx=vx;vy=vy;vz=vz;nx=nx;ny=ny;nz=nz};;
{vx=vx;vy=vy;vz=vz;nx=nx;ny=ny;nz=nz}

let read_path f =
let buf = in_string f 64 in
buf;;
buf

let in_frame f =
let min_bounds = in_vector f in
Expand All @@ -120,7 +120,7 @@ let in_frame f =
let radius = in_single f in
let name = in_string f 16 in
{min_bounds=min_bounds;max_bounds=max_bounds;frame_origin=local_origin;
radius=radius;frame_name=name};;
radius=radius;frame_name=name}


let in_tag f =
Expand All @@ -129,7 +129,7 @@ let in_tag f =
let axis1 = in_vector f in
let axis2 = in_vector f in
let axis3 = in_vector f in
{tag_name=name;tag_origin=origin;axis1=axis1;axis2=axis2;axis3=axis3};;
{tag_name=name;tag_origin=origin;axis1=axis1;axis2=axis2;axis3=axis3}


let tag_to_matrix t =
Expand All @@ -141,7 +141,7 @@ let tag_to_matrix t =
[| a2.x;a2.y;a2.z;0.0 |];
[| a3.x;a3.y;a3.z;0.0 |];
[| o.x; o.y ;o.z;1.0;|] |] in
GlMat.of_array matrix;;
GlMat.of_array matrix



Expand All @@ -151,15 +151,15 @@ let in_shader f =
let shader_index = in_dword f in
String.set shader_name 0 'm';
Texture.load_texture_from_file shader_name;
{shader_name=shader_name;shader_index=shader_index};;
{shader_name=shader_name;shader_index=shader_index}

let in_frame_vertexes f surface_offset vertex_offset vertex_count frame_no =
let begin_frame = surface_offset + vertex_offset + (vertex_count * frame_no *8) in (* 8 is sizeof(vertex) *)
let _ = seek_in f begin_frame in
Array.init vertex_count (fun x -> in_vertex f);;
Array.init vertex_count (fun x -> in_vertex f)

let in_vertexes f surface_offset vertex_offset vertex_count frame_count =
Array.init frame_count (fun x -> in_frame_vertexes f surface_offset vertex_offset vertex_count x);;
Array.init frame_count (fun x -> in_frame_vertexes f surface_offset vertex_offset vertex_count x)


let in_surface surface_offset f =
Expand Down Expand Up @@ -212,11 +212,11 @@ let in_surface surface_offset f =
triangles=triangles;
sts=sts;
vertexes=vertexes};
| _ -> raise Invalid_md3_format;;
| _ -> raise Invalid_md3_format

let in_surface_array f offset count =
seek_in f offset;
Array.init count (fun x -> in_surface (pos_in f) f);;
Array.init count (fun x -> in_surface (pos_in f) f)

let read_version f =
match in_dword_as_int32 f with
Expand Down Expand Up @@ -251,39 +251,39 @@ let read_version f =
tags=tags;
surfaces=surfaces;}

| _ -> raise Invalid_md3_format;;
| _ -> raise Invalid_md3_format

let rec get_tag_two name tags =
match tags with
[] -> raise Not_found
| h::t ->
(if h.tag_name = name then h else get_tag_two name t);;
(if h.tag_name = name then h else get_tag_two name t)

let get_tag name md3 frame_no =
let tags = Array.get md3.tags frame_no in
let tag_list = Array.to_list tags in
get_tag_two name tag_list;;
get_tag_two name tag_list

let readfile f =
match input_char f, input_char f,
input_char f, input_char f with
'I','D','P','3' -> read_version f;
| _ -> raise Invalid_md3_format;;
| _ -> raise Invalid_md3_format

let get_point v p =
Array.get v p;;
Array.get v p

let triangle_to_points t v =
get_point v t.a, get_point v t.b, get_point v t.c;;
get_point v t.a, get_point v t.b, get_point v t.c

let all_triangles_to_points s =
let t = s.triangles in
let v = s.vertexes in
Array.map (fun x -> triangle_to_points x v) t;;
Array.map (fun x -> triangle_to_points x v) t

let map_triangles f s =
let triangles = all_triangles_to_points s in
Array.map f triangles;;
Array.map f triangles

let draw_triangle surface current_frame triangle =
let (v1,v2,v3) = triangle_to_points triangle current_frame in
Expand Down Expand Up @@ -316,7 +316,7 @@ let draw_surface surface frame_no =
GlDraw.ends ()

let draw_surfaces md3 frame_no =
Array.iter (fun x -> draw_surface x frame_no) md3.surfaces;;
Array.iter (fun x -> draw_surface x frame_no) md3.surfaces

let draw_md3 md3 frame_no =
GlMat.push();
Expand Down Expand Up @@ -349,11 +349,11 @@ let skin_md3 md3 =
(* We defer loading of skins on players so we don't load the 'normal'
skins. But we need to do this for weapons *)
let iter_shaders shader =
Printf.printf "Loading shader %s\n" shader.shader_name;
(*Printf.printf "Loading shader %s\n" shader.shader_name;*)
Texture.load_texture_from_file shader.shader_name
in
let iter_surfaces surface =
Printf.printf "Loading surface %s\n" surface.surface_name;
(*Printf.printf "Loading surface %s\n" surface.surface_name;*)
Array.iter iter_shaders surface.shaders
in
Array.iter iter_surfaces md3.surfaces
Expand Down
14 changes: 7 additions & 7 deletions player.ml
Expand Up @@ -5,7 +5,7 @@
Player model is build up of 3 md3s. THis will probably be a class (once I learn how classes work!)
*)

open Md3;;
open Md3

type player = {lower:md3;upper:md3;head:md3;}

Expand Down Expand Up @@ -45,7 +45,7 @@ let draw_player p weapon state =
GlMat.mult head_matrix;
draw_md3 p.head 0;

GlMat.pop();;
GlMat.pop()


(*
Expand Down Expand Up @@ -84,7 +84,7 @@ let load_player preferred_detail_level path =
let lower = load path "lower" in
let upper = load path "upper" in
let head = load path "head" in
{lower=lower;upper=upper;head=head;};;
{lower=lower;upper=upper;head=head;}

let load_player = load_player 1

Expand All @@ -94,13 +94,13 @@ let init_anim_state start stop loop fps =
let frame_rate = 1.0 /. (float_of_int fps) in
let update_time = frame_rate +. (Unix.gettimeofday ()) in
{time_to_advance=update_time;start_pos=start;end_pos=stop;
loop_pos=loop;current_pos=start;frame_rate=frame_rate};;
loop_pos=loop;current_pos=start;frame_rate=frame_rate}

let init_player_anim_state (lstart,lstop,lloop,lfps)
(tstart,tstop,tloop,tfps) =
let leg_state = init_anim_state lstart lstop lloop lfps in
let torso_state = init_anim_state tstart tstop tloop tfps in
{leg=leg_state;torso=torso_state;};;
{leg=leg_state;torso=torso_state;}

let rec update_anim_state cur_time cur_state =
if
Expand All @@ -116,12 +116,12 @@ let rec update_anim_state cur_time cur_state =
current_pos=next_frame;
frame_rate=cur_state.frame_rate;}
else
cur_state;;
cur_state

let update_player_anim_state cur_time cur_state =
let leg_state = update_anim_state cur_time cur_state.leg in
let torso_state = update_anim_state cur_time cur_state.torso in
{leg=leg_state;torso=torso_state;};;
{leg=leg_state;torso=torso_state;}

let skin_player player =
Md3.skin_md3 player.lower;
Expand Down

0 comments on commit bb0ef1f

Please sign in to comment.