Skip to content

Commit

Permalink
updated OO interfaces for new API
Browse files Browse the repository at this point in the history
  • Loading branch information
fccm committed Aug 28, 2019
1 parent d3e6eb6 commit 5f1a6ab
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 96 deletions.
2 changes: 1 addition & 1 deletion src/oo_sfml_audio.ml
Expand Up @@ -48,7 +48,7 @@ class listener =
method set_position ~pos = SFListener.setPosition ~pos
method set_position3 ~posX ~posY ~posZ = SFListener.setPosition3 ~posX ~posY ~posZ
method set_direction ~orientation = SFListener.setDirection ~orientation
method set_up_vector ~vec = SFListener.setUpVector ~vec
method set_up_vector ~vector = SFListener.setUpVector ~vector
method set_up_vector3 ~vecX ~vecY ~vecZ = SFListener.setUpVector3 ~vecX ~vecY ~vecZ
method global_volume = SFListener.getGlobalVolume ()
method position = SFListener.getPosition ()
Expand Down
4 changes: 2 additions & 2 deletions src/oo_sfml_audio.mli
Expand Up @@ -34,13 +34,13 @@ class listener :
method direction : float * float * float
method global_volume : float
method position : float * float * float
method up_vector : float * float * float
method set_direction : orientation:float * float * float -> unit
method set_global_volume : volume:float -> unit
method set_position : pos:float * float * float -> unit
method set_position3 : posX:float -> posY:float -> posZ:float -> unit
method set_up_vector : vec:float * float * float -> unit
method set_up_vector : vector:float * float * float -> unit
method set_up_vector3 : vecX:float -> vecY:float -> vecZ:float -> unit
method up_vector : float * float * float
end
type sound_buffer_src =
[ `FromFile of string
Expand Down
10 changes: 4 additions & 6 deletions src/oo_sfml_graphics.ml
Expand Up @@ -70,9 +70,9 @@ class float_rect ((left, top), (width, height)) =

type image_src = [
| `FromFile of string
| `FromMemory of string
| `FromMemory of bytes
| `FromColor of (int * int * SFColor.t)
| `FromPixels of (int * int * string)
| `FromPixels of (int * int * bytes)
| `FromPixelsArray of (int * int * int * int) array array
| `FromSFImage of SFImage.t
]
Expand Down Expand Up @@ -347,7 +347,6 @@ class view ?rect () =
| None -> SFView.create ()
| Some rect -> SFView.createFromRect ~rect

method destroy () = SFView.destroy ~view
method set_center ~center = SFView.setCenter ~view ~center
method set_center2 ~x ~y = SFView.setCenter2 ~view ~x ~y
method move ~offset = SFView.move ~view ~offset
Expand All @@ -360,11 +359,10 @@ class view ?rect () =


class render_window
?style ?bpp ?depth ?stencil ?antialiasing ?srgb_capable (width, height) title =
?style ?bpp ?settings (width, height) title =
object
val this =
let sRgbCapable = srgb_capable in
SFRenderWindow.make ?style ?bpp ?depth ?stencil ?antialiasing ?sRgbCapable
SFRenderWindow.make ?style ?bpp ?settings
(width, height) title

method is_open = SFRenderWindow.isOpen this
Expand Down
16 changes: 6 additions & 10 deletions src/oo_sfml_graphics.mli
Expand Up @@ -31,8 +31,8 @@ class float_rect :
type image_src =
[ `FromColor of int * int * SFColor.t
| `FromFile of string
| `FromMemory of string
| `FromPixels of int * int * string
| `FromMemory of bytes
| `FromPixels of int * int * bytes
| `FromPixelsArray of (int * int * int * int) array array
| `FromSFImage of SFImage.t ]
type flip_direction = [ `horizontally | `vertically ]
Expand Down Expand Up @@ -192,7 +192,6 @@ class view :
object
val view : SFView.t
method center : float * float
method destroy : unit -> unit
method move : offset:float * float -> unit
method move2 : offset_x:float -> offset_y:float -> unit
method set_center : center:float * float -> unit
Expand All @@ -201,12 +200,9 @@ class view :
method zoom : factor:float -> unit
end
class render_window :
?style:SFRenderWindow.window_style list ->
?style:SFStyle.t list ->
?bpp:int ->
?depth:int ->
?stencil:int ->
?antialiasing:int ->
?srgb_capable:bool ->
?settings:SFContextSettings.t ->
int * int ->
string ->
object
Expand Down Expand Up @@ -235,10 +231,10 @@ class render_window :
method set_framerate_limit : limit:int -> unit
method set_joystick_threshold : threshold:float -> unit
method set_key_repeat_enabled : enabled:bool -> unit
method set_mouse_cursor_grabbed : unit -> unit
method set_mouse_cursor_invisible : unit -> unit
method set_mouse_cursor_visible : unit -> unit
method set_mouse_cursor_ungrabbed : unit -> unit
method set_mouse_cursor_grabbed : unit -> unit
method set_mouse_cursor_visible : unit -> unit
method set_position : pos:int * int -> unit
method set_position2 : left:int -> top:int -> unit
method set_size : size:int * int -> unit
Expand Down
4 changes: 2 additions & 2 deletions src/oo_sfml_network.ml
Expand Up @@ -315,8 +315,8 @@ class ftp =
let dir_resp = SFFtp.getWorkingDirectory ftp in
(new directory_response dir_resp)

method send_command () =
let com_resp = SFFtp.sendCommand ftp in
method send_command ~command ~parameter =
let com_resp = SFFtp.sendCommand ftp ~command ~parameter in
(new response com_resp)
end

9 changes: 5 additions & 4 deletions src/oo_sfml_network.mli
Expand Up @@ -66,6 +66,7 @@ class packet :
method write_int16 : int -> unit
method write_int31 : int -> unit
method write_int32 : int32 -> unit
method write_int64 : int64 -> unit
method write_int8 : int -> unit
method write_string : string -> unit
method write_uint16 : int -> unit
Expand All @@ -77,8 +78,8 @@ class tcp_socket :
method connect :
port:int -> address:SFIpAddress.t -> timeout:SFTime.t -> unit -> unit
method destroy : unit -> unit
method receive : unit -> string
method receive_buf : buf:string -> int
method receive : unit -> bytes
method receive_buf : buf:bytes -> int
method receive_packet : packet:packet -> unit
method send : data:string -> unit
method send_packet : packet:packet -> unit
Expand All @@ -89,7 +90,7 @@ class tcp_socket :
class udp_socket :
object
val socket : SFUdpSocket.t
method bind : port:int -> unit
method bind : port:int -> ?address:SFIpAddress.t -> unit
method destroy : unit -> unit
method receive : data:string -> int * SFIpAddress.t * int
method receive_packet : packet:packet -> SFIpAddress.t * int
Expand Down Expand Up @@ -183,8 +184,8 @@ class ftp :
method login_anonymous : unit -> response
method parent_directory : unit -> response
method rename_file : file:string -> newName:string -> response
method send_command : command:string -> parameter:string -> response
method upload :
localFile:string ->
destPath:string -> mode:SFFtp.transferMode -> response
method send_command : command:string -> parameter:string -> response
end
59 changes: 14 additions & 45 deletions src/oo_sfml_system.ml
Expand Up @@ -18,9 +18,9 @@ class time (src : time_src) =
object
val time =
match src with
| `of_seconds amount -> SFTime.of_seconds ~amount
| `of_milliseconds amount -> SFTime.of_milliseconds ~amount
| `of_microseconds amount -> SFTime.of_microseconds ~amount
| `of_seconds amount -> SFTime.of_seconds amount
| `of_milliseconds amount -> SFTime.of_milliseconds amount
| `of_microseconds amount -> SFTime.of_microseconds amount
| `of_sfTime t -> t

method as_seconds () = SFTime.asSeconds time
Expand All @@ -38,29 +38,21 @@ module Time = struct
let sub (t1 : time) (t2 : time) =
new time (`of_sfTime (SFTime.sub t1#t t2#t))

let mul f (t : time) =
new time (`of_sfTime (SFTime.mul f t#t))

let mult (t : time) f =
new time (`of_sfTime (SFTime.mult t#t f))
let mul (t : time) f =
new time (`of_sfTime (SFTime.mul t#t f))

let div (t : time) d =
new time (`of_sfTime (SFTime.div t#t d))

let ( + ) = add
let ( - ) = sub
let ( * ) = mul
let ( *. ) = mult
let ( / ) = div
end



let sleep ~duration:(d : time) = SFTime.sleep ~duration:d#t

let sleep_sec = SFTime.sleep_sec ;;
let sleep_msec = SFTime.sleep_msec ;;
let sleep_musec = SFTime.sleep_musec ;;
let sleep ~duration:(d : time) = SFTime.sleep d#t


type time_as = [
Expand All @@ -72,43 +64,20 @@ type time_as = [
class clock =
object
val clock = SFClock.create ()
method destroy () = SFClock.destroy ~clock
method restart () = SFClock.restart ~clock

method restart_as_seconds () = SFClock.restart_asSeconds ~clock
method restart_as_milliseconds () = SFClock.restart_asMilliseconds ~clock
method restart_as_microseconds () = SFClock.restart_asMicroseconds ~clock

method restart_as (u : time_as) =
match u with
| `seconds -> SFClock.restart_asSeconds ~clock
| `milliseconds -> Int32.to_float (SFClock.restart_asMilliseconds ~clock)
| `microseconds -> Int64.to_float (SFClock.restart_asMicroseconds ~clock)

method get_elapsed_time () = SFClock.getElapsedTime ~clock

method elapsed_time_as_seconds = SFClock.getElapsedTime_asSeconds ~clock
method elapsed_time_as_milliseconds = SFClock.getElapsedTime_asMilliseconds ~clock
method elapsed_time_as_microseconds = SFClock.getElapsedTime_asMicroseconds ~clock

method get_elapsed_time_as (u : time_as) =
match u with
| `seconds -> SFClock.getElapsedTime_asSeconds ~clock
| `milliseconds -> Int32.to_float (SFClock.getElapsedTime_asMilliseconds ~clock)
| `microseconds -> Int64.to_float (SFClock.getElapsedTime_asMicroseconds ~clock)
method restart () = SFClock.restart clock
method get_elapsed_time () = SFClock.getElapsedTime clock
end


class pausable_clock ~paused =
object
val clock = SFPausableClock.create ~paused
method destroy () = SFPausableClock.destroy ~clock
method pause () = SFPausableClock.pause ~clock
method is_paused () = SFPausableClock.isPaused ~clock
method start () = SFPausableClock.start ~clock
method restart ~paused = SFPausableClock.restart ~clock ~paused
method get_elapsed_time () = SFPausableClock.getElapsedTime ~clock
method elapsed_time = SFPausableClock.getElapsedTime ~clock
method pause () = SFPausableClock.pause clock
method is_paused () = SFPausableClock.isPaused clock
method start () = SFPausableClock.start clock
method restart ~paused = SFPausableClock.restart clock ~paused
method get_elapsed_time () = SFPausableClock.getElapsedTime clock
method elapsed_time = SFPausableClock.getElapsedTime clock
end


Expand Down
19 changes: 2 additions & 17 deletions src/oo_sfml_system.mli
Expand Up @@ -20,40 +20,25 @@ module Time :
sig
val add : time -> time -> time
val sub : time -> time -> time
val mul : float -> time -> time
val mult : time -> float -> time
val mul : time -> float -> time
val div : time -> float -> time
val ( + ) : time -> time -> time
val ( - ) : time -> time -> time
val ( * ) : float -> time -> time
val ( *. ) : time -> float -> time
val ( * ) : time -> float -> time
val ( / ) : time -> float -> time
end
val sleep : duration:time -> unit
val sleep_sec : duration:float -> unit
val sleep_msec : duration:int32 -> unit
val sleep_musec : duration:int64 -> unit
type time_as = [ `microseconds | `milliseconds | `seconds ]
class clock :
object
val clock : SFClock.t
method destroy : unit -> unit
method elapsed_time_as_microseconds : int64
method elapsed_time_as_milliseconds : int32
method elapsed_time_as_seconds : float
method get_elapsed_time : unit -> SFTime.t
method get_elapsed_time_as : time_as -> float
method restart : unit -> SFTime.t
method restart_as : time_as -> float
method restart_as_microseconds : unit -> int64
method restart_as_milliseconds : unit -> int32
method restart_as_seconds : unit -> float
end
class pausable_clock :
paused:bool ->
object
val clock : SFPausableClock.t
method destroy : unit -> unit
method elapsed_time : SFTime.t
method get_elapsed_time : unit -> SFTime.t
method is_paused : unit -> bool
Expand Down
5 changes: 2 additions & 3 deletions src/oo_sfml_window.ml
Expand Up @@ -7,18 +7,17 @@


class window
?style ?bpp ?depth ?stencil ?antialiasing ?version (width, height) title =
?style ?bpp ?settings (width, height) title =
object
val this =
SFWindow.make ?style ?bpp ?depth ?stencil ?antialiasing ?version
SFWindow.make ?style ?bpp ?settings
(width, height) title

(* TODO: SFWindow.createFromHandle : handle:nativeint -> settings:window_settings -> t *)

method is_open = SFWindow.isOpen this
method close () = SFWindow.close this
method display () = SFWindow.display this
method destroy () = SFWindow.destroy this

method poll_event () = SFWindow.pollEvent this
method wait_event () = SFWindow.waitEvent this
Expand Down
8 changes: 2 additions & 6 deletions src/oo_sfml_window.mli
Expand Up @@ -3,18 +3,14 @@
Online documentation for the window module} *)

class window :
?style:SFWindow.window_style list ->
?style:SFStyle.t list ->
?bpp:int ->
?depth:int ->
?stencil:int ->
?antialiasing:int ->
?version:int * int ->
?settings:SFContextSettings.t ->
int * int ->
string ->
object
val this : SFWindow.t
method close : unit -> unit
method destroy : unit -> unit
method display : unit -> unit
method get_mouse_position : unit -> int * int
method height : int
Expand Down

0 comments on commit 5f1a6ab

Please sign in to comment.