updating p2 to 0.14

This commit is contained in:
Peter Li 2025-04-11 14:35:42 -07:00
parent 3b65cdb8f5
commit b500809d6f
8 changed files with 34 additions and 14 deletions

View File

@ -1,8 +1,9 @@
.{
.name = "p2",
.name = .p2,
.version = "0.0.0",
.dependencies = .{},
.paths = .{
"",
},
.fingerprint = 0xa6313a892725ee21,
}

View File

@ -19,6 +19,7 @@ pub const BumpArena = struct {
.alloc = alloc,
.free = free,
.resize = resize,
.remap = std.mem.Allocator.noRemap,
};
pub fn init(backing: std.mem.Allocator) !@This() {
@ -37,15 +38,15 @@ pub const BumpArena = struct {
self.large.deinit();
}
fn respectAlignment(offset: usize, alignment: u8) usize {
fn respectAlignment(offset: usize, alignment: std.mem.Alignment) usize {
if (offset == 0) {
return 0;
}
const a: usize = @intCast(@as(usize, @intCast(1)) << @as(u6, @truncate(alignment)));
const a: usize = @intCast(@as(usize, @intCast(1)) << @as(u6, @truncate(@intFromEnum(alignment))));
return ((offset / a) + 1) * @as(usize, @intCast(a));
}
pub fn alloc(ctx: *anyopaque, len: usize, ptr_align: u8, ret_addr: usize) ?[*]u8 {
pub fn alloc(ctx: *anyopaque, len: usize, ptr_align: std.mem.Alignment, ret_addr: usize) ?[*]u8 {
const self: *@This() = @ptrCast(@alignCast(ctx));
self.mutex.lock();
@ -77,7 +78,7 @@ pub const BumpArena = struct {
return self.large.allocator();
}
pub fn free(ctx: *anyopaque, buf: []u8, buf_align: u8, ret_addr: usize) void {
pub fn free(ctx: *anyopaque, buf: []u8, buf_align: std.mem.Alignment, ret_addr: usize) void {
// it's a bump allocator, it does nothing on free.
_ = ctx;
_ = buf;
@ -86,7 +87,7 @@ pub const BumpArena = struct {
}
// do not support resize in place.
pub fn resize(ctx: *anyopaque, buf: []u8, buf_align: u8, new_len: usize, ret_addr: usize) bool {
pub fn resize(ctx: *anyopaque, buf: []u8, buf_align: std.mem.Alignment, new_len: usize, ret_addr: usize) bool {
_ = ctx;
_ = buf;
_ = buf_align;

View File

@ -37,7 +37,7 @@ test "simple" {
}
};
inline for (@typeInfo(Wrap).Struct.decls) |d| {
inline for (@typeInfo(Wrap).@"struct".decls) |d| {
if (!@hasDecl(T, d.name)) {
@compileError(@typeName(T) ++ " is missing implementation of func " ++ d.name);
}
@ -65,7 +65,7 @@ test "simple" {
}
};
inline for (@typeInfo(Wrap).Struct.decls) |d| {
inline for (@typeInfo(Wrap).@"struct".decls) |d| {
if (!@hasDecl(T, d.name)) {
@compileError(@typeName(T) ++ " is missing implementation of func " ++ d.name);
}

View File

@ -227,7 +227,7 @@ pub fn SparseMultiSetAdvanced(comptime T: type, comptime SparseSize: u32) type {
return true;
}
var prng = std.rand.DefaultPrng.init(0x1234);
var prng = std.Random.DefaultPrng.init(0x1234);
var rand = prng.random();
pub fn newRandomIndex() IndexType {
@ -402,7 +402,7 @@ pub fn SparseSetAdvanced(comptime T: type, comptime SparseSize: u32) type {
}
}
var prng = std.rand.DefaultPrng.init(0x1234);
var prng = std.Random.DefaultPrng.init(0x1234);
var rand = prng.random();
fn newRandomIndex() IndexType {

View File

@ -58,7 +58,7 @@ pub const ShellProcess = struct {
}
} else {
if (terminalStack.items[terminalStack.items.len - 1] == c) {
try currentCmd.append(terminalStack.pop());
try currentCmd.append(terminalStack.pop().?);
} else {
try currentCmd.append(c);
}

2
lib/sdl3/build.zig vendored
View File

@ -33,4 +33,6 @@ pub fn build(b: *std.Build) void {
const runArtifact = b.addRunArtifact(tests);
test_step.dependOn(&runArtifact.step);
b.installArtifact(tests);
}

View File

@ -6,6 +6,13 @@ import math
import subprocess
# yeah I ain't gonna sugar coat it,
# parsing C files is really awful.
# goal with these files is to use em to generate usable APIs only for the stuff that's going to be widely exposed througout
# the engine.
# which.. in this case... the only there is- is the gpu API.
def convertCase(x):
s = ''
underbar = False
@ -33,11 +40,17 @@ SDL_files = [
typeMap = {
'Uint32': 'u32', 'float': 'f32', 'Sint32': 'i32', 'bool': 'bool', 'Uint8': 'u8', 'SDL_PropertiesID': 'PropertiesID','char': 'u8',
'Uint32': 'u32',
'float': 'f32',
'Sint32': 'i32',
'bool': 'bool',
'Uint8': 'u8',
'SDL_PropertiesID': 'PropertiesID',
'char': 'u8',
'void': 'void',
'int': 'c_int',
'size_t': 'usize',
'SDL_Window': 'Window',
'SDL_Window': 'Window'
}
typeMap_r = {}

View File

@ -43,6 +43,7 @@ pub fn startContext(self: *@This()) !void {
return error.UnableToClaimGpu;
const formats = self.device.getGPUShaderFormats();
std.debug.print("SDL Context Loaded: {}\n", .{formats});
if (formats.shaderformatSpirv) {
self.shaderpath = "./content/_cooked/spv"; // shaderformatSpirv
@ -121,10 +122,10 @@ pub fn loadShader(
}
pub fn loop(self: *@This()) !void {
const dt = @as(f64, @floatFromInt(self.timer.lap())) / 1000 / 1000 / 1000;
std.debug.print("loop started\n", .{});
try self.startContext();
while (self.running) {
const dt = @as(f64, @floatFromInt(self.timer.lap())) / 1000 / 1000 / 1000;
self.update(dt);
}
}
@ -140,7 +141,9 @@ fn update(self: *@This(), dt: f64) void {
self.draw(dt);
}
std.debug.print("frameTime: {d}ms ({d}fps)\n", .{ dt * 1000, 1 / dt });
}
pub fn draw(self: *@This(), dt: f64) void {
_ = dt;
const cmd = self.device.acquireGPUCommandBuffer();