diff --git a/examples/core/2d_camera.zig b/examples/core/2d_camera.zig index 46f63b3..392c6b6 100755 --- a/examples/core/2d_camera.zig +++ b/examples/core/2d_camera.zig @@ -93,14 +93,9 @@ pub fn main() anyerror!void for (buildings) |building, i| { - //DrawRectangleRec(building, buildColors[i]); - DrawRectangle(@floatToInt(c_int, building.x), @floatToInt(c_int, building.y), - @floatToInt(c_int, building.width), @floatToInt(c_int, building.height), buildColors[i]); + DrawRectangleRec(building, buildColors[i]); } - - DrawRectangle(@floatToInt(c_int, player.x), @floatToInt(c_int, player.y), - @floatToInt(c_int, player.width), @floatToInt(c_int, player.height), DARKGRAY); - //DrawRectangleRec(player, RED); + DrawRectangleRec(player, RED); DrawLine(@floatToInt(c_int, camera.target.x), -screenHeight*10, @floatToInt(c_int, camera.target.x), screenHeight*10, GREEN); DrawLine(-screenWidth*10, @floatToInt(c_int, camera.target.y), screenWidth*10, @floatToInt(c_int, camera.target.y), GREEN); diff --git a/examples/core/input_keys.zig b/examples/core/input_keys.zig index 149a3b7..12a141a 100755 --- a/examples/core/input_keys.zig +++ b/examples/core/input_keys.zig @@ -40,8 +40,7 @@ pub fn main() anyerror!void DrawText("move the ball with arrow keys", 10, 10, 20, DARKGRAY); - DrawCircle(@floatToInt(c_int, ballPosition.x), @floatToInt(c_int, ballPosition.y), 50, MAROON); - //DrawCircleV(ballPosition, 50, MAROON); + DrawCircleV(ballPosition, 50, MAROON); EndDrawing(); //---------------------------------------------------------------------------------- diff --git a/examples/core/input_mouse.zig b/examples/core/input_mouse.zig index 87c70c6..ecb1d85 100755 --- a/examples/core/input_mouse.zig +++ b/examples/core/input_mouse.zig @@ -40,8 +40,7 @@ pub fn main() anyerror!void ClearBackground(RAYWHITE); - DrawCircle(@floatToInt(c_int, ballPosition.x), @floatToInt(c_int, ballPosition.y), 50, ballColor); - //DrawCircleV(ballPosition, 40, ballColor); + DrawCircleV(ballPosition, 40, ballColor); DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY); diff --git a/examples/core/input_mouse_wheel.zig b/examples/core/input_mouse_wheel.zig index 4224cd7..42cc419 100755 --- a/examples/core/input_mouse_wheel.zig +++ b/examples/core/input_mouse_wheel.zig @@ -39,7 +39,7 @@ pub fn main() anyerror!void DrawRectangle(screenWidth/2 - 40, boxPositionY, 80, 80, MAROON); DrawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, GRAY); - //DrawText(FormatText("Box position Y: %03i", boxPositionY), 10, 40, 20, LIGHTGRAY); + DrawText(FormatText("Box position Y: %03i", boxPositionY), 10, 40, 20, LIGHTGRAY); EndDrawing(); //---------------------------------------------------------------------------------- diff --git a/examples/core/input_multitouch.zig b/examples/core/input_multitouch.zig index 974d4c8..7006230 100755 --- a/examples/core/input_multitouch.zig +++ b/examples/core/input_multitouch.zig @@ -59,15 +59,13 @@ pub fn main() anyerror!void if ((touchPosition.x >= 0) and (touchPosition.y >= 0)) // Make sure point is not (-1,-1) as this means there is no touch for it { // Draw circle and touch index number - DrawCircle(@floatToInt(c_int, touchPosition.x), @floatToInt(c_int, touchPosition.y), 34, ORANGE); - //DrawCircleV(touchPosition, 34, ORANGE); - //DrawText(FormatText("%d", i), @floatToInt(c_int, touchPosition.x) - 10, @floatToInt(c_int, touchPosition.y) - 70, 40, BLACK); + DrawCircleV(touchPosition, 34, ORANGE); + DrawText(FormatText("%d", i), @floatToInt(c_int, touchPosition.x) - 10, @floatToInt(c_int, touchPosition.y) - 70, 40, BLACK); } } // Draw the normal mouse location - DrawCircle(@floatToInt(c_int, ballPosition.x), @floatToInt(c_int, ballPosition.y), 30 + (touchCounter*3), ballColor); - //DrawCircleV(ballPosition, 30 + (touchCounter*3), ballColor); + DrawCircleV(ballPosition, 30 + (touchCounter*3), ballColor); DrawText("move ball with mouse and click mouse button to change color", 10, 10, 20, DARKGRAY); DrawText("touch the screen at multiple locations to get multiple balls", 10, 30, 20, DARKGRAY); diff --git a/lib/generate_functions.py b/lib/generate_functions.py index 38d217e..0550abb 100644 --- a/lib/generate_functions.py +++ b/lib/generate_functions.py @@ -75,7 +75,9 @@ def parse_header(header_name: str, output_file: str, prefix: str): func_name = result.group(2) arguments = result.group(3) - if "..." in arguments or return_type in small_structs or return_type == "float3" or return_type == "float16": + # Igoring function here because: + # a) C va_args are supported in Zig but I + if return_type in small_structs or return_type == "float3" or return_type == "float16": continue for struct in small_structs: @@ -89,6 +91,9 @@ def parse_header(header_name: str, output_file: str, prefix: str): for arg in arguments.split(", "): if arg == "void": break + if arg == "...": + zig_arguments.append("...") + break arg_type = " ".join(arg.split(" ")[0:-1]) # everything but the last element (for stuff like "const Vector3") arg_type = arg_type.replace("const ", "") # zig doesn't like const in function arguments that aren't pointer and really we don't need const arg_name = arg.split(" ")[-1] # last element should be the name @@ -101,6 +106,10 @@ def parse_header(header_name: str, output_file: str, prefix: str): zig_heads.append("pub extern fn " + func_name + "(" + zig_arguments + ") " + return_type + ";") continue + # If we find variable arguments in a workaround function + # + if "..." in arguments: continue + zig_arguments_w = [] # arguments for the workaround function head on the zig side zig_arguments = [] # arguments that are passed to the copied raylib function zig_pass = [] # arguments that are passed to the workaround function on the zig side @@ -108,7 +117,7 @@ def parse_header(header_name: str, output_file: str, prefix: str): c_pass = [] # arguments that are passed to the actual raylib function for arg in arguments.split(", "): - if arg == "void": break + if arg == "void" : break arg_type = " ".join(arg.split(" ")[0:-1]).replace("const ", "") # everything but the last element (for stuff like "const Vector3"), but discarding const arg_name = arg.split(" ")[-1] # last element should be the name arg_type = fix_enums(arg_name, arg_type, func_name) @@ -142,7 +151,7 @@ def parse_header(header_name: str, output_file: str, prefix: str): zig_name = zig_name[1:] zig_type = "[*c][]const " + zig_type else: - zig_type = "[]const " + zig_type + zig_type = "[*c]const " + zig_type zig_pass_name = "&" + zig_name + "[0]" else: # Normal argument i.e. float, int, etc. zig_pass_name = zig_name diff --git a/lib/raylib-wa.zig b/lib/raylib-wa.zig index f7821cb..2a67763 100644 --- a/lib/raylib-wa.zig +++ b/lib/raylib-wa.zig @@ -56,6 +56,7 @@ pub extern fn SetConfigFlags(flags: c_uint) void; pub extern fn SetTraceLogLevel(logType: c_int) void; pub extern fn SetTraceLogExit(logType: c_int) void; pub extern fn SetTraceLogCallback(callback: TraceLogCallback) void; +pub extern fn TraceLog(logType: c_int, text: [*c]const u8, ...) void; pub extern fn TakeScreenshot(fileName: [*c]const u8) void; pub extern fn GetRandomValue(min: c_int, max: c_int) c_int; pub extern fn LoadFileData(fileName: [*c]const u8, bytesRead: [*c]const c_uint) [*c]const u8; @@ -257,6 +258,7 @@ pub extern fn GetGlyphIndex(font: Font, codepoint: c_int) c_int; pub extern fn TextCopy(dst: [*c]const u8, src: [*c]const u8) c_int; pub extern fn TextIsEqual(text1: [*c]const u8, text2: [*c]const u8) bool; pub extern fn TextLength(text: [*c]const u8) c_uint; +pub extern fn TextFormat(text: [*c]const u8, ...) [*c]const u8; pub extern fn TextSubtext(text: [*c]const u8, position: c_int, length: c_int) [*c]const u8; pub extern fn TextReplace(text: [*c]const u8, replace: [*c]const u8, by: [*c]const u8) [*c]const u8; pub extern fn TextInsert(text: [*c]const u8, insert: [*c]const u8, position: c_int) [*c]const u8; @@ -460,7 +462,7 @@ pub fn DrawLineBezier(startPos: Vector2, endPos: Vector2, thick: f32, color: Col WDrawLineBezier(&startPos, &endPos, thick, &color); } -pub fn DrawLineStrip(points: []const Vector2, numPoints: c_int, color: Color) void +pub fn DrawLineStrip(points: [*c]const Vector2, numPoints: c_int, color: Color) void { WDrawLineStrip(&points[0], numPoints, &color); } @@ -580,12 +582,12 @@ pub fn DrawTriangleLines(v1: Vector2, v2: Vector2, v3: Vector2, color: Color) vo WDrawTriangleLines(&v1, &v2, &v3, &color); } -pub fn DrawTriangleFan(points: []const Vector2, numPoints: c_int, color: Color) void +pub fn DrawTriangleFan(points: [*c]const Vector2, numPoints: c_int, color: Color) void { WDrawTriangleFan(&points[0], numPoints, &color); } -pub fn DrawTriangleStrip(points: []const Vector2, pointsCount: c_int, color: Color) void +pub fn DrawTriangleStrip(points: [*c]const Vector2, pointsCount: c_int, color: Color) void { WDrawTriangleStrip(&points[0], pointsCount, &color); } @@ -630,7 +632,7 @@ pub fn CheckCollisionPointTriangle(point: Vector2, p1: Vector2, p2: Vector2, p3: return WCheckCollisionPointTriangle(&point, &p1, &p2, &p3); } -pub fn LoadImageEx(pixels: []const Color, width: c_int, height: c_int) Image +pub fn LoadImageEx(pixels: [*c]const Color, width: c_int, height: c_int) Image { return WLoadImageEx(&pixels[0], width, height); } @@ -665,112 +667,112 @@ pub fn ImageFromImage(image: Image, rec: Rectangle) Image return WImageFromImage(image, &rec); } -pub fn ImageText(text: []const u8, fontSize: c_int, color: Color) Image +pub fn ImageText(text: [*c]const u8, fontSize: c_int, color: Color) Image { return WImageText(&text[0], fontSize, &color); } -pub fn ImageTextEx(font: Font, text: []const u8, fontSize: f32, spacing: f32, tint: Color) Image +pub fn ImageTextEx(font: Font, text: [*c]const u8, fontSize: f32, spacing: f32, tint: Color) Image { return WImageTextEx(font, &text[0], fontSize, spacing, &tint); } -pub fn ImageToPOT(image: []const Image, fillColor: Color) void +pub fn ImageToPOT(image: [*c]const Image, fillColor: Color) void { WImageToPOT(&image[0], &fillColor); } -pub fn ImageAlphaClear(image: []const Image, color: Color, threshold: f32) void +pub fn ImageAlphaClear(image: [*c]const Image, color: Color, threshold: f32) void { WImageAlphaClear(&image[0], &color, threshold); } -pub fn ImageCrop(image: []const Image, crop: Rectangle) void +pub fn ImageCrop(image: [*c]const Image, crop: Rectangle) void { WImageCrop(&image[0], &crop); } -pub fn ImageResizeCanvas(image: []const Image, newWidth: c_int, newHeight: c_int, offsetX: c_int, offsetY: c_int, color: Color) void +pub fn ImageResizeCanvas(image: [*c]const Image, newWidth: c_int, newHeight: c_int, offsetX: c_int, offsetY: c_int, color: Color) void { WImageResizeCanvas(&image[0], newWidth, newHeight, offsetX, offsetY, &color); } -pub fn ImageColorTint(image: []const Image, color: Color) void +pub fn ImageColorTint(image: [*c]const Image, color: Color) void { WImageColorTint(&image[0], &color); } -pub fn ImageColorReplace(image: []const Image, color: Color, replace: Color) void +pub fn ImageColorReplace(image: [*c]const Image, color: Color, replace: Color) void { WImageColorReplace(&image[0], &color, &replace); } -pub fn ImageClearBackground(dst: []const Image, color: Color) void +pub fn ImageClearBackground(dst: [*c]const Image, color: Color) void { WImageClearBackground(&dst[0], &color); } -pub fn ImageDrawPixel(dst: []const Image, posX: c_int, posY: c_int, color: Color) void +pub fn ImageDrawPixel(dst: [*c]const Image, posX: c_int, posY: c_int, color: Color) void { WImageDrawPixel(&dst[0], posX, posY, &color); } -pub fn ImageDrawPixelV(dst: []const Image, position: Vector2, color: Color) void +pub fn ImageDrawPixelV(dst: [*c]const Image, position: Vector2, color: Color) void { WImageDrawPixelV(&dst[0], &position, &color); } -pub fn ImageDrawLine(dst: []const Image, startPosX: c_int, startPosY: c_int, endPosX: c_int, endPosY: c_int, color: Color) void +pub fn ImageDrawLine(dst: [*c]const Image, startPosX: c_int, startPosY: c_int, endPosX: c_int, endPosY: c_int, color: Color) void { WImageDrawLine(&dst[0], startPosX, startPosY, endPosX, endPosY, &color); } -pub fn ImageDrawLineV(dst: []const Image, start: Vector2, end: Vector2, color: Color) void +pub fn ImageDrawLineV(dst: [*c]const Image, start: Vector2, end: Vector2, color: Color) void { WImageDrawLineV(&dst[0], &start, &end, &color); } -pub fn ImageDrawCircle(dst: []const Image, centerX: c_int, centerY: c_int, radius: c_int, color: Color) void +pub fn ImageDrawCircle(dst: [*c]const Image, centerX: c_int, centerY: c_int, radius: c_int, color: Color) void { WImageDrawCircle(&dst[0], centerX, centerY, radius, &color); } -pub fn ImageDrawCircleV(dst: []const Image, center: Vector2, radius: c_int, color: Color) void +pub fn ImageDrawCircleV(dst: [*c]const Image, center: Vector2, radius: c_int, color: Color) void { WImageDrawCircleV(&dst[0], ¢er, radius, &color); } -pub fn ImageDrawRectangle(dst: []const Image, posX: c_int, posY: c_int, width: c_int, height: c_int, color: Color) void +pub fn ImageDrawRectangle(dst: [*c]const Image, posX: c_int, posY: c_int, width: c_int, height: c_int, color: Color) void { WImageDrawRectangle(&dst[0], posX, posY, width, height, &color); } -pub fn ImageDrawRectangleV(dst: []const Image, position: Vector2, size: Vector2, color: Color) void +pub fn ImageDrawRectangleV(dst: [*c]const Image, position: Vector2, size: Vector2, color: Color) void { WImageDrawRectangleV(&dst[0], &position, &size, &color); } -pub fn ImageDrawRectangleRec(dst: []const Image, rec: Rectangle, color: Color) void +pub fn ImageDrawRectangleRec(dst: [*c]const Image, rec: Rectangle, color: Color) void { WImageDrawRectangleRec(&dst[0], &rec, &color); } -pub fn ImageDrawRectangleLines(dst: []const Image, rec: Rectangle, thick: c_int, color: Color) void +pub fn ImageDrawRectangleLines(dst: [*c]const Image, rec: Rectangle, thick: c_int, color: Color) void { WImageDrawRectangleLines(&dst[0], &rec, thick, &color); } -pub fn ImageDraw(dst: []const Image, src: Image, srcRec: Rectangle, dstRec: Rectangle, tint: Color) void +pub fn ImageDraw(dst: [*c]const Image, src: Image, srcRec: Rectangle, dstRec: Rectangle, tint: Color) void { WImageDraw(&dst[0], src, &srcRec, &dstRec, &tint); } -pub fn ImageDrawText(dst: []const Image, position: Vector2, text: []const u8, fontSize: c_int, color: Color) void +pub fn ImageDrawText(dst: [*c]const Image, position: Vector2, text: [*c]const u8, fontSize: c_int, color: Color) void { WImageDrawText(&dst[0], &position, &text[0], fontSize, &color); } -pub fn ImageDrawTextEx(dst: []const Image, position: Vector2, font: Font, text: []const u8, fontSize: f32, spacing: f32, color: Color) void +pub fn ImageDrawTextEx(dst: [*c]const Image, position: Vector2, font: Font, text: [*c]const u8, fontSize: f32, spacing: f32, color: Color) void { WImageDrawTextEx(&dst[0], &position, font, &text[0], fontSize, spacing, &color); } @@ -815,27 +817,27 @@ pub fn LoadFontFromImage(image: Image, key: Color, firstChar: c_int) Font return WLoadFontFromImage(image, &key, firstChar); } -pub fn GenImageFontAtlas(chars: []const CharInfo, recs: [*c][]const Rectangle, charsCount: c_int, fontSize: c_int, padding: c_int, packMethod: c_int) Image +pub fn GenImageFontAtlas(chars: [*c]const CharInfo, recs: [*c][]const Rectangle, charsCount: c_int, fontSize: c_int, padding: c_int, packMethod: c_int) Image { return WGenImageFontAtlas(&chars[0], &recs[0], charsCount, fontSize, padding, packMethod); } -pub fn DrawText(text: []const u8, posX: c_int, posY: c_int, fontSize: c_int, color: Color) void +pub fn DrawText(text: [*c]const u8, posX: c_int, posY: c_int, fontSize: c_int, color: Color) void { WDrawText(&text[0], posX, posY, fontSize, &color); } -pub fn DrawTextEx(font: Font, text: []const u8, position: Vector2, fontSize: f32, spacing: f32, tint: Color) void +pub fn DrawTextEx(font: Font, text: [*c]const u8, position: Vector2, fontSize: f32, spacing: f32, tint: Color) void { WDrawTextEx(font, &text[0], &position, fontSize, spacing, &tint); } -pub fn DrawTextRec(font: Font, text: []const u8, rec: Rectangle, fontSize: f32, spacing: f32, wordWrap: bool, tint: Color) void +pub fn DrawTextRec(font: Font, text: [*c]const u8, rec: Rectangle, fontSize: f32, spacing: f32, wordWrap: bool, tint: Color) void { WDrawTextRec(font, &text[0], &rec, fontSize, spacing, wordWrap, &tint); } -pub fn DrawTextRecEx(font: Font, text: []const u8, rec: Rectangle, fontSize: f32, spacing: f32, wordWrap: bool, tint: Color, selectStart: c_int, selectLength: c_int, selectTint: Color, selectBackTint: Color) void +pub fn DrawTextRecEx(font: Font, text: [*c]const u8, rec: Rectangle, fontSize: f32, spacing: f32, wordWrap: bool, tint: Color, selectStart: c_int, selectLength: c_int, selectTint: Color, selectBackTint: Color) void { WDrawTextRecEx(font, &text[0], &rec, fontSize, spacing, wordWrap, &tint, selectStart, selectLength, &selectTint, &selectBackTint); } @@ -985,7 +987,7 @@ pub fn CheckCollisionRaySphere(ray: Ray, center: Vector3, radius: f32) bool return WCheckCollisionRaySphere(ray, ¢er, radius); } -pub fn CheckCollisionRaySphereEx(ray: Ray, center: Vector3, radius: f32, collisionPoint: []const Vector3) bool +pub fn CheckCollisionRaySphereEx(ray: Ray, center: Vector3, radius: f32, collisionPoint: [*c]const Vector3) bool { return WCheckCollisionRaySphereEx(ray, ¢er, radius, &collisionPoint[0]); } @@ -1005,17 +1007,17 @@ pub fn SetShapesTexture(texture: Texture2D, source: Rectangle) void WSetShapesTexture(texture, &source); } -pub fn GetShaderLocation(shader: Shader, uniformName: []const u8) int +pub fn GetShaderLocation(shader: Shader, uniformName: [*c]const u8) int { return WGetShaderLocation(&shader, &uniformName[0]); } -pub fn SetShaderValue(shader: Shader, uniformLoc: c_int, value: []const void, uniformType: c_int) void +pub fn SetShaderValue(shader: Shader, uniformLoc: c_int, value: [*c]const void, uniformType: c_int) void { WSetShaderValue(&shader, uniformLoc, &value[0], uniformType); } -pub fn SetShaderValueV(shader: Shader, uniformLoc: c_int, value: []const void, uniformType: c_int, count: c_int) void +pub fn SetShaderValueV(shader: Shader, uniformLoc: c_int, value: [*c]const void, uniformType: c_int, count: c_int) void { WSetShaderValueV(&shader, uniformLoc, &value[0], uniformType, count); } diff --git a/lib/raylib-zig-math.zig b/lib/raylib-zig-math.zig index 4f4a8d7..e9ac14c 100755 --- a/lib/raylib-zig-math.zig +++ b/lib/raylib-zig-math.zig @@ -69,7 +69,7 @@ pub fn Vector3Distance(v1: Vector3, v2: Vector3) float return WVector3Distance(&v1, &v2); } -pub fn Vector3OrthoNormalize(v1: []const Vector3, v2: []const Vector3) void +pub fn Vector3OrthoNormalize(v1: [*c]const Vector3, v2: [*c]const Vector3) void { WVector3OrthoNormalize(&v1[0], &v2[0]); } @@ -99,7 +99,7 @@ pub fn QuaternionToMatrix(q: Quaternion) Matrix return WQuaternionToMatrix(&q); } -pub fn QuaternionToAxisAngle(q: Quaternion, outAxis: []const Vector3, outAngle: []const f32) void +pub fn QuaternionToAxisAngle(q: Quaternion, outAxis: [*c]const Vector3, outAngle: [*c]const f32) void { WQuaternionToAxisAngle(&q, &outAxis[0], &outAngle[0]); } diff --git a/lib/raylib-zig.zig b/lib/raylib-zig.zig index 9786aa9..327137b 100755 --- a/lib/raylib-zig.zig +++ b/lib/raylib-zig.zig @@ -743,5 +743,6 @@ pub const PI = 3.141593; pub const SpriteFont = Font; pub const SubText = TextSubtext; pub const ShowWindow = UnhideWindow; +pub const FormatText = TextFormat; pub usingnamespace @import("raylib-wa.zig");