Automatically generate functions that return their slice length, where possible
This commit is contained in:
parent
c30197911a
commit
d6c77762cb
4 changed files with 216 additions and 296 deletions
|
|
@ -14,11 +14,17 @@ test {
|
|||
|
||||
pub const RaylibError = error{
|
||||
LoadFileData,
|
||||
CompressData,
|
||||
DecompressData,
|
||||
EncodeDataBase64,
|
||||
DecodeDataBase64,
|
||||
ExportImageToMemory,
|
||||
LoadImageColors,
|
||||
LoadImagePalette,
|
||||
LoadFont,
|
||||
LoadFontData,
|
||||
LoadCodepoints,
|
||||
TextSplit,
|
||||
LoadMaterial,
|
||||
LoadMaterials,
|
||||
LoadModelAnimations,
|
||||
|
|
@ -2032,19 +2038,6 @@ pub fn loadRandomSequence(count: u32, min: i32, max: i32) []i32 {
|
|||
return res;
|
||||
}
|
||||
|
||||
/// Load file data as byte array (read)
|
||||
pub fn loadFileData(fileName: [:0]const u8) RaylibError![]u8 {
|
||||
var bytesRead: i32 = 0;
|
||||
var res: []u8 = undefined;
|
||||
|
||||
const ptr = cdef.LoadFileData(@as([*c]const u8, @ptrCast(fileName)), @as([*c]c_int, @ptrCast(&bytesRead)));
|
||||
if (ptr == 0) return RaylibError.LoadFileData;
|
||||
|
||||
res.ptr = @as([*]u8, @ptrCast(ptr));
|
||||
res.len = @as(usize, @intCast(bytesRead));
|
||||
return res;
|
||||
}
|
||||
|
||||
/// Save data to file from byte array (write), returns true on success
|
||||
pub fn saveFileData(fileName: [:0]const u8, data: []u8) bool {
|
||||
return cdef.SaveFileData(@as([*c]const u8, @ptrCast(fileName)), @as(*anyopaque, @ptrCast(data.ptr)), @as(c_int, @intCast(data.len)));
|
||||
|
|
@ -2055,42 +2048,6 @@ pub fn exportDataAsCode(data: []const u8, fileName: [:0]const u8) bool {
|
|||
return cdef.ExportDataAsCode(@as([*c]const u8, @ptrCast(data)), @as(c_int, @intCast(data.len)), @as([*c]const u8, @ptrCast(fileName)));
|
||||
}
|
||||
|
||||
/// Compress data (DEFLATE algorithm), memory must be MemFree()
|
||||
pub fn compressData(data: []const u8) []u8 {
|
||||
var compDataSize: i32 = 0;
|
||||
var res: []u8 = undefined;
|
||||
res.ptr = cdef.CompressData(@as([*c]const u8, @ptrCast(data)), @as(c_int, @intCast(data.len)), @as([*c]c_int, @ptrCast(&compDataSize)));
|
||||
res.len = @as(usize, @intCast(compDataSize));
|
||||
return res;
|
||||
}
|
||||
|
||||
/// Decompress data (DEFLATE algorithm), memory must be MemFree()
|
||||
pub fn decompressData(compData: []const u8) []u8 {
|
||||
var dataSize: i32 = 0;
|
||||
var res: []u8 = undefined;
|
||||
res.ptr = cdef.DecompressData(@as([*c]const u8, @ptrCast(compData)), @as(c_int, @intCast(compData.len)), @as([*c]c_int, @ptrCast(&dataSize)));
|
||||
res.len = @as(usize, @intCast(dataSize));
|
||||
return res;
|
||||
}
|
||||
|
||||
/// Encode data to Base64 string, memory must be MemFree()
|
||||
pub fn encodeDataBase64(data: []const u8) []u8 {
|
||||
var outputSize: i32 = 0;
|
||||
var res: []u8 = undefined;
|
||||
res.ptr = cdef.EncodeDataBase64(@as([*c]const u8, @ptrCast(data)), @as(c_int, @intCast(data.len)), @as([*c]c_int, @ptrCast(&outputSize)));
|
||||
res.len = @as(usize, @intCast(outputSize));
|
||||
return res;
|
||||
}
|
||||
|
||||
/// Decode Base64 string data, memory must be MemFree()
|
||||
pub fn decodeDataBase64(data: []const u8) []u8 {
|
||||
var outputSize: i32 = 0;
|
||||
var res: []u8 = undefined;
|
||||
res.ptr = cdef.DecodeDataBase64(@as([*c]const u8, @ptrCast(data)), @as([*c]c_int, @ptrCast(&outputSize)));
|
||||
res.len = @as(usize, @intCast(outputSize));
|
||||
return res;
|
||||
}
|
||||
|
||||
pub fn computeCRC32(data: []u8) u32 {
|
||||
return cdef.ComputeCRC32(@as([*c]u8, @ptrCast(data)), @as(c_int, @intCast(data.len)));
|
||||
}
|
||||
|
|
@ -2181,19 +2138,6 @@ pub fn loadImageColors(image: Image) RaylibError![]Color {
|
|||
return res;
|
||||
}
|
||||
|
||||
/// Load colors palette from image as a Color array (RGBA - 32bit)
|
||||
pub fn loadImagePalette(image: Image, maxPaletteSize: i32) RaylibError![]Color {
|
||||
var colorCount: i32 = 0;
|
||||
var res: []Color = undefined;
|
||||
|
||||
const ptr = cdef.LoadImagePalette(image, @as(c_int, maxPaletteSize), @as([*c]c_int, @ptrCast(&colorCount)));
|
||||
if (ptr == 0) return RaylibError.LoadImagePalette;
|
||||
|
||||
res.ptr = @as([*]Color, @ptrCast(ptr));
|
||||
res.len = @as(usize, @intCast(colorCount));
|
||||
return res;
|
||||
}
|
||||
|
||||
/// Load texture from file into GPU memory (VRAM)
|
||||
pub fn loadTexture(fileName: [:0]const u8) RaylibError!Texture2D {
|
||||
const texture = cdef.LoadTexture(@as([*c]const u8, @ptrCast(fileName)));
|
||||
|
|
@ -2290,22 +2234,6 @@ pub fn loadFontData(fileData: []const u8, fontSize: i32, fontChars: []i32, ty: F
|
|||
return res;
|
||||
}
|
||||
|
||||
/// Load all codepoints from a UTF-8 text string, codepoints count returned by parameter
|
||||
pub fn loadCodepoints(text: [:0]const u8) RaylibError![]i32 {
|
||||
if (@sizeOf(c_int) != @sizeOf(i32)) {
|
||||
@compileError("Can't cast pointer to c_int array to i32 because they don't have the same size");
|
||||
}
|
||||
var count: i32 = 0;
|
||||
var res: []i32 = undefined;
|
||||
|
||||
const ptr = cdef.LoadCodepoints(@as([*c]const u8, @ptrCast(text)), @as([*c]c_int, @ptrCast(&count)));
|
||||
if (ptr == 0) return RaylibError.LoadCodepoints;
|
||||
|
||||
res.ptr = @as([*]i32, @ptrCast(ptr));
|
||||
res.len = @as(usize, @intCast(count));
|
||||
return res;
|
||||
}
|
||||
|
||||
/// Text formatting with variables (sprintf() style)
|
||||
pub fn textFormat(text: [:0]const u8, args: anytype) [:0]const u8 {
|
||||
comptime {
|
||||
|
|
@ -2342,15 +2270,6 @@ pub fn traceLog(logLevel: TraceLogLevel, text: [:0]const u8, args: anytype) void
|
|||
@call(.auto, cdef.TraceLog, .{ logLevel, @as([*c]const u8, @ptrCast(text)) } ++ args);
|
||||
}
|
||||
|
||||
/// Split text into multiple strings
|
||||
pub fn textSplit(text: [:0]const u8, delimiter: u8) [][:0]const u8 {
|
||||
var count: i32 = 0;
|
||||
var res: [][:0]const u8 = undefined;
|
||||
res.ptr = @as([*][:0]const u8, @ptrCast(cdef.TextSplit(@as([*c]const u8, @ptrCast(text)), delimiter, @as([*c]c_int, @ptrCast(&count)))));
|
||||
res.len = @as(usize, @intCast(count));
|
||||
return res;
|
||||
}
|
||||
|
||||
/// Draw multiple mesh instances with material and different transforms
|
||||
pub fn drawMeshInstanced(mesh: Mesh, material: Material, transforms: []const Matrix) void {
|
||||
cdef.DrawMeshInstanced(mesh, material, @as([*c]const Matrix, @ptrCast(transforms)), @as(c_int, @intCast(transforms.len)));
|
||||
|
|
@ -2396,19 +2315,6 @@ pub fn loadModelFromMesh(mesh: Mesh) RaylibError!Model {
|
|||
return if (isValid) model else RaylibError.LoadModel;
|
||||
}
|
||||
|
||||
/// Load model animations from file
|
||||
pub fn loadModelAnimations(fileName: [:0]const u8) RaylibError![]ModelAnimation {
|
||||
var animCount: i32 = 0;
|
||||
var res: []ModelAnimation = undefined;
|
||||
|
||||
const ptr = cdef.LoadModelAnimations(@as([*c]const u8, @ptrCast(fileName)), @as([*c]c_int, @ptrCast(&animCount)));
|
||||
if (ptr == 0) return RaylibError.LoadModelAnimations;
|
||||
|
||||
res.ptr = @as([*]ModelAnimation, @ptrCast(ptr));
|
||||
res.len = @as(usize, @intCast(animCount));
|
||||
return res;
|
||||
}
|
||||
|
||||
/// Unload animation data
|
||||
pub fn unloadModelAnimations(animations: []ModelAnimation) void {
|
||||
cdef.UnloadModelAnimations(@as([*c]ModelAnimation, @ptrCast(animations)), @as(c_int, @intCast(animations.len)));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue