~octaspire/cl-octaspire-csfml

beb079a85e91aeba08d958be5d77e6ed15df3fe5 — octaspire 1 year, 5 months ago 4fc6081
Fix portability issues presented on macOS
4 files changed, 56 insertions(+), 29 deletions(-)

M doc/API.org
M src/package.lisp
M src/system.lisp
M test/system-test.lisp
M doc/API.org => doc/API.org +4 -2
@@ 101,7 101,8 @@ Helper function ~CLAMP~ is available.
     members ~mx~ and ~my~. Use exported symbol ~:VECTOR2F~ instead.
     So instead of writing ~(:STRUCT SFVECTOR2F)~, please write ~:VECTOR2F~.
     Additional constructor ~MAKE-VECTOR2F~ and destructor ~RELEASE-VECTOR2F~
     are available. Predicate function ~VECTOR2F-EQUAL-P~ compares one to n
     are available. Helper function ~VECTOR2F-SET~ can be used to set the
     components to given values. Predicate function ~VECTOR2F-EQUAL-P~ compares one to n
     ~VECTOR2F~ values and returns true if the given vectors are all equal
     (when only one time value is given, returns true). Function ~VECTOR2F-LERP~
     can be used for linear interpolation between two ~:VECTOR2F~ values.


@@ 111,7 112,8 @@ Helper function ~CLAMP~ is available.
     members ~mx~, ~my~, and ~mz~. Use exported symbol ~:VECTOR3F~ instead.
     So instead of writing ~(:STRUCT SFVECTOR3F)~, please write ~:VECTOR3F~.
     Additional constructor ~MAKE-VECTOR3F~ and destructor ~RELEASE-VECTOR3F~
     are available. Predicate function ~VECTOR3F-EQUAL-P~ compares one to n
     are available. Helper function ~VECTOR3F-SET~ can be used to set the
     components to given values. Predicate function ~VECTOR3F-EQUAL-P~ compares one to n
     ~VECTOR3F~ values and returns true if the given vectors are all equal
     (when only one time value is given, returns true). Function ~VECTOR3F-LERP~
     can be used for linear interpolation between two ~:VECTOR3F~ values.

M src/package.lisp => src/package.lisp +2 -0
@@ 32,11 32,13 @@
   :vector2u-lerp
   :vector2f :mx :my
   :make-vector2f :release-vector2f
   :vector2f-set
   :vector2f-to-str
   :vector2f-equal-p
   :vector2f-lerp
   :vector3f :mx :my :mz
   :make-vector3f :release-vector3f
   :vector3f-set
   :vector3f-to-str
   :vector3f-equal-p
   :vector3f-lerp

M src/system.lisp => src/system.lisp +25 -7
@@ 100,14 100,22 @@ Foreign CSFML type is defined in file SFML/System/Vector2.h."
  "Constructor for allocating and initializing new :VECTOR2F."
  (let ((v (foreign-alloc :vector2f)))
    (with-foreign-slots ((mx my) v :vector2f)
      (setf mx (float x)
            my (float y)))
      (setf mx (coerce x 'single-float)
            my (coerce y 'single-float)))
    (return-from make-vector2f v)))

(defun release-vector2f (self)
  "Release memory allocated for :VECTOR2F SELF."
  (foreign-free self))

(defun vector2f-set (self &key (x 0 x-supplied-p) (y 0 y-supplied-p))
  "Helper function for setting X and Y components of :VECTOR2F SELF."
  (with-foreign-slots ((mx my) self :vector2f)
    (when x-supplied-p
      (setf mx (coerce x 'single-float)))
    (when y-supplied-p
      (setf my (coerce y 'single-float)))))

;;
;; VECTOR3
;;


@@ 133,9 141,9 @@ Foreign CSFML type is defined in file SFML/System/Vector3.h."
  "Constructor for allocating and initializing new :VECTOR3F."
  (let ((v (foreign-alloc :vector3f)))
    (with-foreign-slots ((mx my mz) v :vector3f)
      (setf mx (float x)
            my (float y)
            mz (float z)))
      (setf mx (coerce x 'single-float)
            my (coerce y 'single-float)
            mz (coerce z 'single-float)))
    (return-from make-vector3f v)))

(defun release-vector3f (self)


@@ 144,6 152,16 @@ Foreign CSFML type is defined in file SFML/System/Vector3.h."

;; VECTOR RELATED HELPER FUNCTIONS

(defun vector3f-set (self &key (x 0 x-supplied-p) (y 0 y-supplied-p) (z 0 z-supplied-p))
  "Helper function for setting X, Y, and Z components of :VECTO32F SELF."
  (with-foreign-slots ((mx my mz) self :vector3f)
    (when x-supplied-p
      (setf mx (coerce x 'single-float)))
    (when y-supplied-p
      (setf my (coerce y 'single-float)))
    (when z-supplied-p
      (setf mz (coerce z 'single-float)))))

(defun vector2i-equal-p (v1 &rest vectors)
  "Predicate for telling if the csfml :VECTOR2I value V1 is equal to all
the rest given VECTORS of type :VECTOR2I (if only one value is given,


@@ 212,7 230,7 @@ Real value A is clamped between zero and one (inclusive)."

(defun vector2f-to-str (self)
  "Return string representation of SELF of type :VECTOR2F."
  (format nil "(make-vector2f ~A ~A)"
  (format nil "(make-vector2f ~f ~f)"
          (foreign-slot-value self :vector2f 'mx)
          (foreign-slot-value self :vector2f 'my)))



@@ 241,7 259,7 @@ Real value A is clamped between zero and one (inclusive)."

(defun vector3f-to-str (self)
  "Return string representation of SELF of type :VECTOR3F."
  (format nil "(make-vector3f ~A ~A ~A)"
  (format nil "(make-vector3f ~f ~f ~f)"
          (foreign-slot-value self :vector3f 'mx)
          (foreign-slot-value self :vector3f 'my)
          (foreign-slot-value self :vector3f 'mz)))

M test/system-test.lisp => test/system-test.lisp +25 -20
@@ 128,10 128,9 @@
   (let ((x 123.1)
         (y 999.2))
     (with-foreign-slots ((mx my) v :vector2f)
       (setf mx x
             my y)
       (is (= x mx) #?"X component is $(mx) when $(x) was expected.")
       (is (= y my) #?"Y component is $(my) when $(y) was expected.")))))
       (vector2f-set v :x x :y y)
       (is (= (coerce x 'single-float) mx) #?"X component is $(mx) when $(x) was expected.")
       (is (= (coerce y 'single-float) my) #?"Y component is $(my) when $(y) was expected.")))))

(fiveam:test
 test-make-vector2f--release-vector2f


@@ 139,8 138,8 @@
        (y 20.2)
        (v (make-vector2f x y)))
   (with-foreign-slots ((mx my) v :vector2f)
     (is (= x mx) #?"X component is $(mx) when $(x) was expected.")
     (is (= y my) #?"Y component is $(my) when $(y) was expected."))
     (is (= (coerce x 'single-float) mx) #?"X component is $(mx) when $(x) was expected.")
     (is (= (coerce y 'single-float) my) #?"Y component is $(my) when $(y) was expected."))
   (release-vector2f v)))

;; VECTOR3F


@@ 152,28 151,34 @@
         (y 512.2)
         (z 999.3))
     (with-foreign-slots ((mx my mz) v :vector3f)
       (setf mx x
             my y
             mz z)
       (is (= x mx) #?"X component is $(mx) when $(x) was expected.")
       (is (= y my) #?"Y component is $(my) when $(y) was expected.")
       (is (= z mz) #?"Z component is $(mz) when $(z) was expected.")))))
       (vector3f-set v :x x :y y :z z)
       (is (= (coerce x 'single-float) mx) #?"X component is $(mx) when $(x) was expected.")
       (is (= (coerce y 'single-float) my) #?"Y component is $(my) when $(y) was expected.")
       (is (= (coerce z 'single-float) mz) #?"Z component is $(mz) when $(z) was expected.")))))

(fiveam:test
 test-make-vector3f--release-vectorff
 test-make-vector3f--release-vector3f
 (let* ((x 10.1)
        (y 20.2)
        (z 30.3)
        (v (make-vector3f x y z)))
   (with-foreign-slots ((mx my mz) v :vector3f)
     (is (= x mx) #?"X component is $(mx) when $(x) was expected.")
     (is (= y my) #?"Y component is $(my) when $(y) was expected.")
     (is (= z mz) #?"Z component is $(mz) when $(z) was expected."))
     (is (= (coerce x 'single-float) mx) #?"X component is $(mx) when $(x) was expected.")
     (is (= (coerce y 'single-float) my) #?"Y component is $(my) when $(y) was expected.")
     (is (= (coerce z 'single-float) mz) #?"Z component is $(mz) when $(z) was expected."))
   (release-vector3f v)))

;; VECTOR RELATED HELPER FUNCTIONS

(fiveam:test
 test-vector3f-to-str-10.1-20.2-30.3
 (let* ((v (make-vector3f 10.1 20.2 30.3))
        (e "(make-vector3f 10.1 20.2 30.3)")
        (s (vector3f-to-str v)))
   (is (string= e s) #?"Is as string $(s) when $(e) expected")
   (release-vector3f v)))

(fiveam:test
 test-vector2i-equal-p--10-11
 (let* ((v1 (make-vector2i 10 11)))
   (is (vector2i-equal-p v1)


@@ 496,7 501,7 @@ was expected.")))))

(fiveam:test
 test-sfseconds-0-01
 (let* ((seconds 0.01)
 (let* ((seconds 0.01f0)
        (v (sfseconds seconds))
        (e 10000))
   (is (= e v)


@@ 531,21 536,21 @@ was expected.")))))
(fiveam:test
 test-time-asseconds-10000
 (let* ((s (time-asseconds 10000))
        (e 0.01))
        (e 0.01f0))
   (is (= e s)
       #?"Time was $(s) seconds when $(e) was expected.")))

(fiveam:test
 test-time-asseconds-100000
 (let* ((s (time-asseconds 100000))
        (e 0.1))
        (e 0.1f0))
   (is (= e s)
       #?"Time was $(s) seconds when $(e) was expected.")))

(fiveam:test
 test-time-asseconds-1000000
 (let* ((s (time-asseconds 1000000))
        (e 1.0))
        (e 1.0f0))
   (is (= e s)
       #?"Time was $(s) seconds when $(e) was expected.")))