Bladeren bron

Simplify and document the regeneration process

Soaku 4 jaren geleden
bovenliggende
commit
b5944f48f0
3 gewijzigde bestanden met toevoegingen van 173 en 90 verwijderingen
  1. 67 0
      source/generating.md
  2. 7 90
      source/raylib.d
  3. 99 0
      source/raylib_types.d

+ 67 - 0
source/generating.md

@@ -0,0 +1,67 @@
+# Regenerating bindings
+
+In order to update `raylib-d` to work with a newer version of `raylib`, the headers must be regenerated with [dstep].
+
+Three modules should be regenerated: `raylib`, `raymath` and `rlgl`.
+
+```
+dstep raylib.h raymath.h rlgl.h -o ~/git/contrib/raylib-d/source --space-after-function-name=false --skip Vector2 \
+    --skip Vector3 --skip Vector4 --skip Quaternion --skip Matrix --skip Rectangle --skip RL_MALLOC --skip RL_CALLOC \
+    --skip RL_REALLOC --skip RL_FREE
+```
+
+Note: we're skipping a couple symbols because we define them manually in `raylib_types`. We also skip memory functions
+because they only have effect when compiling Raylib in C.
+
+After you regenerate them, they won't be ready to use yet. We need to add module declarations and imports at the top
+of each module:
+
+```d
+module raylib;
+
+public
+{
+    import rlgl;
+    import easings;
+    import raymath;
+    import raymathext;
+    import raylib_types;
+}
+```
+
+```d
+module raymath;
+
+import raylib;
+```
+
+```d
+module rlgl;
+
+import raylib;
+```
+
+Additionally, each of those modules will have an automatically generated `extern (C):` line. We need to find it and
+edit it to `extern (C) @nogc nothrow:`.
+
+dstep will also make a mistake in `raylib.d` and incorrectly define a couple `alias`es as `enums`. Those must be fixed.
+Look for a block of code similar to this:
+
+```d
+// Temporal hacks to avoid breaking old codebases using
+// deprecated raylib implementation or definitions
+enum FormatText = TextFormat;
+enum LoadText = LoadFileText;
+enum GetExtension = GetFileExtension;
+enum GetImageData = LoadImageColors;
+enum FILTER_POINT = TextureFilter.TEXTURE_FILTER_POINT;
+enum FILTER_BILINEAR = TextureFilter.TEXTURE_FILTER_BILINEAR;
+enum MAP_DIFFUSE = MATERIAL_MAP_DIFFUSE;
+enum PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 = PixelFormat.PIXELFORMAT_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8;
+```
+
+and replace each `enum` with `alias`.
+
+This should be enough. Run `dub test` and see if it compiles.
+
+[dstep]: https://github.com/jacob-carlborg/dstep

+ 7 - 90
source/raylib.d

@@ -3,9 +3,10 @@ module raylib;
 public
 {
     import rlgl;
-    import raymath;
     import easings;
+    import raymath;
     import raymathext;
+    import raylib_types;
 }
 /**********************************************************************************************
 *
@@ -87,7 +88,6 @@ public
 
 import core.stdc.config;
 import core.stdc.stdarg;
-import core.stdc.stdlib;
 
 extern (C) @nogc nothrow:
 
@@ -112,50 +112,17 @@ enum RAD2DEG = 180.0f / PI;
 
 // Allow custom memory allocators
 
-alias RL_MALLOC = malloc;
-
-alias RL_CALLOC = calloc;
-
-alias RL_REALLOC = realloc;
-
-alias RL_FREE = free;
-
 // NOTE: MSVC C++ compiler does not support compound literals (C99 feature)
 // Plain structures in C++ (without constructors) can be initialized from { } initializers.
 
-enum Colors
+extern (D) auto CLITERAL(T)(auto ref T type)
 {
-    // Some Basic Colors
-    // NOTE: Custom raylib color palette for amazing visuals on WHITE background
-    LIGHTGRAY = Color(200, 200, 200, 255), // Light Gray
-    GRAY = Color(130, 130, 130, 255), // Gray
-    DARKGRAY = Color(80, 80, 80, 255), // Dark Gray
-    YELLOW = Color(253, 249, 0, 255), // Yellow
-    GOLD = Color(255, 203, 0, 255), // Gold
-    ORANGE = Color(255, 161, 0, 255), // Orange
-    PINK = Color(255, 109, 194, 255), // Pink
-    RED = Color(230, 41, 55, 255), // Red
-    MAROON = Color(190, 33, 55, 255), // Maroon
-    GREEN = Color(0, 228, 48, 255), // Green
-    LIME = Color(0, 158, 47, 255), // Lime
-    DARKGREEN = Color(0, 117, 44, 255), // Dark Green
-    SKYBLUE = Color(102, 191, 255, 255), // Sky Blue
-    BLUE = Color(0, 121, 241, 255), // Blue
-    DARKBLUE = Color(0, 82, 172, 255), // Dark Blue
-    PURPLE = Color(200, 122, 255, 255), // Purple
-    VIOLET = Color(135, 60, 190, 255), // Violet
-    DARKPURPLE = Color(112, 31, 126, 255), // Dark Purple
-    BEIGE = Color(211, 176, 131, 255), // Beige
-    BROWN = Color(127, 106, 79, 255), // Brown
-    DARKBROWN = Color(76, 63, 47, 255), // Dark Brown
-
-    WHITE = Color(255, 255, 255, 255), // White
-    BLACK = Color(0, 0, 0, 255), // Black
-    BLANK = Color(0, 0, 0, 0), // Blank (Transparent)
-    MAGENTA = Color(255, 0, 255, 255), // Magenta
-    RAYWHITE = Color(245, 245, 245, 255), // My own White (raylib logo)
+    return type;
 }
 
+// Some Basic Colors
+// NOTE: Custom raylib color palette for amazing visuals on WHITE background // Light Gray // Gray // Dark Gray // Yellow // Gold // Orange // Pink // Red // Maroon // Green // Lime // Dark Green // Sky Blue // Blue // Dark Blue // Purple // Violet // Dark Purple // Beige // Brown // Dark Brown // White // Black // Blank (Transparent) // Magenta // My own White (raylib logo)
+
 // Temporal hacks to avoid breaking old codebases using
 // deprecated raylib implementation or definitions
 alias FormatText = TextFormat;
@@ -173,55 +140,14 @@ alias PIXELFORMAT_UNCOMPRESSED_R8G8B8A8 = PixelFormat.PIXELFORMAT_PIXELFORMAT_UN
 // Boolean type
 
 // Vector2 type
-struct Vector2
-{
-    float x = 0.0f;
-    float y = 0.0f;
-    mixin Linear;
-}
 
 // Vector3 type
-struct Vector3
-{
-    float x = 0.0f;
-    float y = 0.0f;
-    float z = 0.0f;
-    mixin Linear;
-}
 
 // Vector4 type
-struct Vector4
-{
-    float x = 0.0f;
-    float y = 0.0f;
-    float z = 0.0f;
-    float w = 0.0f;
-    mixin Linear;
-}
 
 // Quaternion type, same as Vector4
-alias Quaternion = Vector4;
 
 // Matrix type (OpenGL style 4x4 - right handed, column major)
-struct Matrix
-{
-    float m0 = 0.0f;
-    float m4 = 0.0f;
-    float m8 = 0.0f;
-    float m12 = 0.0f;
-    float m1 = 0.0f;
-    float m5 = 0.0f;
-    float m9 = 0.0f;
-    float m13 = 0.0f;
-    float m2 = 0.0f;
-    float m6 = 0.0f;
-    float m10 = 0.0f;
-    float m14 = 0.0f;
-    float m3 = 0.0f;
-    float m7 = 0.0f;
-    float m11 = 0.0f;
-    float m15 = 0.0f;
-}
 
 // Color type, RGBA (32bit)
 struct Color
@@ -233,15 +159,6 @@ struct Color
 }
 
 // Rectangle type
-struct Rectangle
-{
-    float x;
-    float y;
-    float width;
-    float height;
-    alias w = width;
-    alias h = height;
-}
 
 // Image type, bpp always RGBA (32bit)
 // NOTE: Data stored in CPU memory (RAM)

+ 99 - 0
source/raylib_types.d

@@ -0,0 +1,99 @@
+/// This module defines basic types from Raylib with local modifications to make them easier to use.
+module raylib_types;
+
+import raylib;
+
+// Vector2 type
+struct Vector2
+{
+    float x = 0.0f;
+    float y = 0.0f;
+    mixin Linear;
+}
+
+// Vector3 type
+struct Vector3
+{
+    float x = 0.0f;
+    float y = 0.0f;
+    float z = 0.0f;
+    mixin Linear;
+}
+
+// Vector4 type
+struct Vector4
+{
+    float x = 0.0f;
+    float y = 0.0f;
+    float z = 0.0f;
+    float w = 0.0f;
+    mixin Linear;
+}
+
+// Quaternion type, same as Vector4
+alias Quaternion = Vector4;
+
+// Matrix type (OpenGL style 4x4 - right handed, column major)
+struct Matrix
+{
+    float m0 = 0.0f;
+    float m4 = 0.0f;
+    float m8 = 0.0f;
+    float m12 = 0.0f;
+    float m1 = 0.0f;
+    float m5 = 0.0f;
+    float m9 = 0.0f;
+    float m13 = 0.0f;
+    float m2 = 0.0f;
+    float m6 = 0.0f;
+    float m10 = 0.0f;
+    float m14 = 0.0f;
+    float m3 = 0.0f;
+    float m7 = 0.0f;
+    float m11 = 0.0f;
+    float m15 = 0.0f;
+}
+
+// Rectangle type
+struct Rectangle
+{
+    float x;
+    float y;
+    float width;
+    float height;
+    alias w = width;
+    alias h = height;
+}
+
+enum Colors
+{
+    // Some Basic Colors
+    // NOTE: Custom raylib color palette for amazing visuals on WHITE background
+    LIGHTGRAY = Color(200, 200, 200, 255), // Light Gray
+    GRAY = Color(130, 130, 130, 255), // Gray
+    DARKGRAY = Color(80, 80, 80, 255), // Dark Gray
+    YELLOW = Color(253, 249, 0, 255), // Yellow
+    GOLD = Color(255, 203, 0, 255), // Gold
+    ORANGE = Color(255, 161, 0, 255), // Orange
+    PINK = Color(255, 109, 194, 255), // Pink
+    RED = Color(230, 41, 55, 255), // Red
+    MAROON = Color(190, 33, 55, 255), // Maroon
+    GREEN = Color(0, 228, 48, 255), // Green
+    LIME = Color(0, 158, 47, 255), // Lime
+    DARKGREEN = Color(0, 117, 44, 255), // Dark Green
+    SKYBLUE = Color(102, 191, 255, 255), // Sky Blue
+    BLUE = Color(0, 121, 241, 255), // Blue
+    DARKBLUE = Color(0, 82, 172, 255), // Dark Blue
+    PURPLE = Color(200, 122, 255, 255), // Purple
+    VIOLET = Color(135, 60, 190, 255), // Violet
+    DARKPURPLE = Color(112, 31, 126, 255), // Dark Purple
+    BEIGE = Color(211, 176, 131, 255), // Beige
+    BROWN = Color(127, 106, 79, 255), // Brown
+    DARKBROWN = Color(76, 63, 47, 255), // Dark Brown
+
+    WHITE = Color(255, 255, 255, 255), // White
+    BLACK = Color(0, 0, 0, 255), // Black
+    BLANK = Color(0, 0, 0, 0), // Blank (Transparent)
+    MAGENTA = Color(255, 0, 255, 255), // Magenta
+    RAYWHITE = Color(245, 245, 245, 255), // My own White (raylib logo)
+}