From 5f1a6ab4eb73ce14bd1734bb0b0fab8406cfb3f0 Mon Sep 17 00:00:00 2001 From: Florent Monnier Date: Wed, 28 Aug 2019 12:44:34 +0159 Subject: [PATCH] updated OO interfaces for new API --- src/oo_sfml_audio.ml | 2 +- src/oo_sfml_audio.mli | 4 +-- src/oo_sfml_graphics.ml | 10 +++---- src/oo_sfml_graphics.mli | 16 ++++------- src/oo_sfml_network.ml | 4 +-- src/oo_sfml_network.mli | 9 +++--- src/oo_sfml_system.ml | 59 ++++++++++------------------------------ src/oo_sfml_system.mli | 19 ++----------- src/oo_sfml_window.ml | 5 ++-- src/oo_sfml_window.mli | 8 ++---- 10 files changed, 40 insertions(+), 96 deletions(-) diff --git a/src/oo_sfml_audio.ml b/src/oo_sfml_audio.ml index 703c9e8..ae58909 100644 --- a/src/oo_sfml_audio.ml +++ b/src/oo_sfml_audio.ml @@ -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 () diff --git a/src/oo_sfml_audio.mli b/src/oo_sfml_audio.mli index dc846a7..253a3c1 100644 --- a/src/oo_sfml_audio.mli +++ b/src/oo_sfml_audio.mli @@ -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 diff --git a/src/oo_sfml_graphics.ml b/src/oo_sfml_graphics.ml index eb546a4..4edfc24 100644 --- a/src/oo_sfml_graphics.ml +++ b/src/oo_sfml_graphics.ml @@ -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 ] @@ -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 @@ -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 diff --git a/src/oo_sfml_graphics.mli b/src/oo_sfml_graphics.mli index 45ae4c7..4efe243 100644 --- a/src/oo_sfml_graphics.mli +++ b/src/oo_sfml_graphics.mli @@ -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 ] @@ -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 @@ -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 @@ -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 diff --git a/src/oo_sfml_network.ml b/src/oo_sfml_network.ml index 2c7c52e..e360a92 100644 --- a/src/oo_sfml_network.ml +++ b/src/oo_sfml_network.ml @@ -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 diff --git a/src/oo_sfml_network.mli b/src/oo_sfml_network.mli index 24c5da5..e5fa324 100644 --- a/src/oo_sfml_network.mli +++ b/src/oo_sfml_network.mli @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src/oo_sfml_system.ml b/src/oo_sfml_system.ml index 970e5d4..b1dccb7 100644 --- a/src/oo_sfml_system.ml +++ b/src/oo_sfml_system.ml @@ -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 @@ -38,11 +38,8 @@ 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)) @@ -50,17 +47,12 @@ module Time = struct 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 = [ @@ -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 diff --git a/src/oo_sfml_system.mli b/src/oo_sfml_system.mli index 4b1a058..0690ad1 100644 --- a/src/oo_sfml_system.mli +++ b/src/oo_sfml_system.mli @@ -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 diff --git a/src/oo_sfml_window.ml b/src/oo_sfml_window.ml index 9a7459c..df98685 100644 --- a/src/oo_sfml_window.ml +++ b/src/oo_sfml_window.ml @@ -7,10 +7,10 @@ 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 *) @@ -18,7 +18,6 @@ class window 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 diff --git a/src/oo_sfml_window.mli b/src/oo_sfml_window.mli index 37501fd..e51289e 100644 --- a/src/oo_sfml_window.mli +++ b/src/oo_sfml_window.mli @@ -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