Explorar el Código

Remove fluent asserts as a dependency. Add raylib.binding to allow
validation of the raylib binding library (also may put some other d
stuff in there)

Steven Schveighoffer hace 3 años
padre
commit
4551e55896

+ 1 - 8
dub.json

@@ -6,13 +6,6 @@
 		"ONROUNDIT"
 	],
 	"copyright": "Copyright (c) Ramon Santamaria (@raysan5), Petro Romanovych (@onroundit), Jan Hoenig (@m3m0ry), Steven Schveighoffer (@schveiguy)",
-	"configurations": [
-        {
-            "name": "unittest",
-            "dependencies": {
-                "fluent-asserts": "~>0.13.0"
-            }
-        }
-    ],	
+        "excludedSourceFiles": ["source/rlgl.d", "source/raymath.d", "source/easings.d", "source/raygui.d", "source/raymathext.d", "source/raylib_types.d"],
 	"targetType": "sourceLibrary"
 }

+ 2 - 0
source/raygui.d

@@ -1,3 +1,5 @@
+deprecated("raygui is not up to date and will be removed in a future version of raylib-d")
+module raygui;
 /*******************************************************************************************
 *
 *   raygui v2.7 - A simple and easy-to-use immediate-mode gui library

+ 32 - 0
source/raylib/binding.d

@@ -0,0 +1,32 @@
+/**
+ * D-specialized raylib functions. These functions help the D experience on
+ * raylib.
+ */
+module raylib.binding;
+import raylib;
+
+// stored inside raylib to validate the binding
+private extern(C) extern __gshared const(char)* raylibVersion;
+
+/**
+ * Call this function before using any raylib functions to validate the binding
+ * matches what the header information says. If you don't call this, it's
+ * possible your binding will fail with such fun issues as memory corruption.
+ *
+ * If the binding is not valid, then the program will exit with a -1 error code.
+ *
+ * This is a template to avoid requiring linking libraylib for unittests.
+ */
+void validateRaylibBinding()() @nogc nothrow {
+    import core.stdc.stdio;
+    import core.stdc.stdlib;
+    import core.stdc.string;
+    auto rlv = raylibVersion[0 .. strlen(raylibVersion)];
+    if(rlv != RAYLIB_VERSION)
+    {
+        printf("FATAL ERROR: Raylib binding expected version %.*s, library version is %.*s\n",
+               cast(int)RAYLIB_VERSION.length, RAYLIB_VERSION.ptr,
+               cast(int)rlv.length, rlv.ptr);
+        exit(-1);
+    }
+}

+ 12 - 11
source/raylib/package.d

@@ -1,14 +1,3 @@
-module raylib;
-
-public
-{
-    import rlgl;
-    import reasings;
-    import raymath;
-    import raymathext;
-    import raylib_types;
-}
-
 /**********************************************************************************************
 *
 *   raylib v4.2 - A simple and easy-to-use library to enjoy videogames programming (www.raylib.com)
@@ -85,6 +74,18 @@ public
 *     3. This notice may not be removed or altered from any source distribution.
 *
 **********************************************************************************************/
+module raylib;
+
+public
+{
+    import raylib.rlgl;
+    import raylib.reasings;
+    import raylib.raymath;
+    import raylib.raymathext;
+    import raylib.raylib_types;
+    import raylib.binding;
+}
+
 import core.stdc.config;
 import core.stdc.stdarg;
 

+ 1 - 1
source/raylib/raylib_types.d

@@ -1,5 +1,5 @@
 /// This module defines basic types from Raylib with local modifications to make them easier to use.
-module raylib_types;
+module raylib.raylib_types;
 
 import raylib;
 

+ 1 - 1
source/raylib/raymath.d

@@ -1,4 +1,4 @@
-module raymath;
+module raylib.raymath;
 
 import raylib;
 /**********************************************************************************************

+ 16 - 21
source/raylib/raymathext.d

@@ -1,4 +1,4 @@
-module raymathext;
+module raylib.raymathext;
 
 import raylib;
 import std.math;
@@ -67,11 +67,6 @@ struct Rotor3
 
 alias Matrix4 = Matrix;
 
-version (unittest)
-{
-    import fluent.asserts;
-}
-
 mixin template Linear()
 {
     import std.algorithm : canFind, map;
@@ -168,21 +163,21 @@ mixin template Linear()
 
 unittest
 {
-    Assert.equal(Vector2.init, Vector2.zero);
-    Assert.equal(Vector2(), Vector2.zero);
-    Assert.equal(-Vector2(1, 2), Vector2(-1, -2));
+    assert(Vector2.init == Vector2.zero);
+    assert(Vector2() == Vector2.zero);
+    assert(-Vector2(1, 2) == Vector2(-1, -2));
     auto a = Vector3(1, 2, 9);
     immutable b = Vector3(3, 4, 9);
     Vector3 c = a + b;
-    Assert.equal(c, Vector3(4, 6, 18));
-    Assert.equal(4.0f - Vector2.zero, Vector2(4, 4));
-    Assert.equal(Vector2.one - 3.0f, Vector2(-2, -2));
+    assert(c == Vector3(4, 6, 18));
+    assert(4.0f - Vector2.zero == Vector2(4, 4));
+    assert(Vector2.one - 3.0f == Vector2(-2, -2));
     a += 5;
-    Assert.equal(a, Vector3(6, 7, 14));
+    assert(a == Vector3(6, 7, 14));
     a *= 0.5;
-    Assert.equal(a, Vector3(3, 3.5, 7));
+    assert(a == Vector3(3, 3.5, 7));
     a += Vector3(3, 2.5, -1);
-    Assert.equal(a, Vector3(6, 6, 6));
+    assert(a == Vector3(6, 6, 6));
 }
 
 import std.traits : FieldNameTuple;
@@ -214,18 +209,18 @@ float dot(T)(T lhs, T rhs)
 
 unittest
 {
-    Assert.equal(Vector2(3, 4).length, 5);
+    assert(Vector2(3, 4).length == 5);
     const a = Vector2(-3, 4);
-    Assert.equal(a.normal, Vector2(-3. / 5., 4. / 5.));
+    assert(a.normal == Vector2(-3. / 5., 4. / 5.));
     immutable b = Vector2(9, 8);
-    Assert.equal(b.distance(Vector2(-3, 3)), 13);
-    Assert.equal(Vector3(2, 3, 4).dot(Vector3(4, 5, 6)), 47);
-    Assert.equal(Vector2.one.length, sqrt(2.0f));
+    assert(b.distance(Vector2(-3, 3)) == 13);
+    assert(Vector3(2, 3, 4).dot(Vector3(4, 5, 6)) == 47);
+    assert(Vector2.one.length == sqrt(2.0f));
 }
 
 unittest
 {
-    Assert.equal(Rotor3(1, 2, 3, 4), Rotor3(1, Bivector3(2, 3, 4)));
+    assert(Rotor3(1, 2, 3, 4) == Rotor3(1, Bivector3(2, 3, 4)));
 }
 
 /// Mix `amount` of `lhs` with `1-amount` of `rhs`

+ 1 - 1
source/raylib/reasings.d

@@ -78,7 +78,7 @@
 *     3. This notice may not be removed or altered from any source distribution.
 *
 **********************************************************************************************/
-module reasings;
+module raylib.reasings;
 
 extern (C) nothrow @nogc:
 pragma(inline, true): // NOTE: By default, compile functions as static inline

+ 1 - 1
source/raylib/rlgl.d

@@ -1,4 +1,4 @@
-module rlgl;
+module raylib.rlgl;
 
 import raylib;
 /**********************************************************************************************