Update zig version

This commit is contained in:
IntegratedQuantum 2024-09-14 13:42:25 +02:00
parent 8987dc4eb0
commit 330187b9ae
23 changed files with 95 additions and 95 deletions

View File

@ -1 +1 @@
0.13.0
0.14.0-dev.1550+4fba7336a

View File

@ -151,14 +151,14 @@ pub const ChunkPosition = struct { // MARK: ChunkPosition
}
pub fn equals(self: ChunkPosition, other: anytype) bool {
if(@typeInfo(@TypeOf(other)) == .Optional) {
if(@typeInfo(@TypeOf(other)) == .optional) {
if(other) |notNull| {
return self.equals(notNull);
}
return false;
} else if(@TypeOf(other.*) == ServerChunk) {
return self.wx == other.super.pos.wx and self.wy == other.super.pos.wy and self.wz == other.super.pos.wz and self.voxelSize == other.super.pos.voxelSize;
} else if(@typeInfo(@TypeOf(other)) == .Pointer) {
} else if(@typeInfo(@TypeOf(other)) == .pointer) {
return self.wx == other.pos.wx and self.wy == other.pos.wy and self.wz == other.pos.wz and self.voxelSize == other.pos.voxelSize;
} else @compileError("Unsupported");
}

View File

@ -1220,7 +1220,7 @@ pub const Shader = struct { // MARK: Shader
pub fn initAndGetUniforms(vertex: []const u8, fragment: []const u8, defines: []const u8, ptrToUniformStruct: anytype) Shader {
const self = Shader.init(vertex, fragment, defines);
inline for(@typeInfo(@TypeOf(ptrToUniformStruct.*)).Struct.fields) |field| {
inline for(@typeInfo(@TypeOf(ptrToUniformStruct.*)).@"struct".fields) |field| {
if(field.type == c_int) {
@field(ptrToUniformStruct, field.name) = c.glGetUniformLocation(self.id, field.name[0..]);
}
@ -1237,7 +1237,7 @@ pub const Shader = struct { // MARK: Shader
pub fn initComputeAndGetUniforms(compute: []const u8, defines: []const u8, ptrToUniformStruct: anytype) Shader {
const self = Shader.initCompute(compute, defines);
inline for(@typeInfo(@TypeOf(ptrToUniformStruct.*)).Struct.fields) |field| {
inline for(@typeInfo(@TypeOf(ptrToUniformStruct.*)).@"struct".fields) |field| {
if(field.type == c_int) {
@field(ptrToUniformStruct, field.name) = c.glGetUniformLocation(self.id, field.name[0..]);
}

View File

@ -131,7 +131,7 @@ pub fn init() void { // MARK: init()
windowList = List(*GuiWindow).init(main.globalAllocator);
hudWindows = List(*GuiWindow).init(main.globalAllocator);
openWindows = List(*GuiWindow).init(main.globalAllocator);
inline for(@typeInfo(windowlist).Struct.decls) |decl| {
inline for(@typeInfo(windowlist).@"struct".decls) |decl| {
const windowStruct = @field(windowlist, decl.name);
windowStruct.window.id = decl.name;
addWindow(&windowStruct.window);
@ -173,7 +173,7 @@ pub fn deinit() void {
ContinuousSlider.__deinit();
DiscreteSlider.__deinit();
TextInput.__deinit();
inline for(@typeInfo(windowlist).Struct.decls) |decl| {
inline for(@typeInfo(windowlist).@"struct".decls) |decl| {
const WindowStruct = @field(windowlist, decl.name);
if(@hasDecl(WindowStruct, "deinit")) {
WindowStruct.deinit();

View File

@ -36,7 +36,7 @@ pub fn render() void {
const loss = @as(f64, @floatFromInt(resent))/@as(f64, @floatFromInt(sent))*100;
draw.print("Packet loss: {d:.1}% ({}/{})", .{loss, resent, sent}, 0, y, 8, .left);
y += 8;
inline for(@typeInfo(network.Protocols).Struct.decls) |decl| {
inline for(@typeInfo(network.Protocols).@"struct".decls) |decl| {
if(@TypeOf(@field(network.Protocols, decl.name)) == type) {
const id = @field(network.Protocols, decl.name).id;
draw.print("{s}: {}kiB in {} packets", .{decl.name, network.bytesReceived[id].load(.monotonic) >> 10, network.packetsReceived[id].load(.monotonic)}, 0, y, 8, .left);

View File

@ -51,7 +51,7 @@ const names = [_][]const u8 {
const buffers = 4;
var curBuffer: u2 = 0;
var queryObjects: [buffers][@typeInfo(Samples).Enum.fields.len]c_uint = undefined;
var queryObjects: [buffers][@typeInfo(Samples).@"enum".fields.len]c_uint = undefined;
var activeSample: ?Samples = null;

View File

@ -87,36 +87,36 @@ pub const JsonElement = union(JsonType) { // MARK: JsonElement
pub fn as(self: *const JsonElement, comptime T: type, replacement: T) T {
comptime var typeInfo : std.builtin.Type = @typeInfo(T);
comptime var innerType = T;
inline while(typeInfo == .Optional) {
innerType = typeInfo.Optional.child;
inline while(typeInfo == .optional) {
innerType = typeInfo.optional.child;
typeInfo = @typeInfo(innerType);
}
switch(typeInfo) {
.Int => {
.int => {
switch(self.*) {
.JsonInt => return std.math.cast(innerType, self.JsonInt) orelse replacement,
.JsonFloat => return std.math.lossyCast(innerType, std.math.round(self.JsonFloat)),
else => return replacement,
}
},
.Float => {
.float => {
switch(self.*) {
.JsonInt => return @floatFromInt(self.JsonInt),
.JsonFloat => return @floatCast(self.JsonFloat),
else => return replacement,
}
},
.Vector => {
const len = typeInfo.Vector.len;
.vector => {
const len = typeInfo.vector.len;
const elems = self.toSlice();
if(elems.len != len) return replacement;
var result: innerType = undefined;
if(innerType == T) result = replacement;
inline for(0..len) |i| {
if(innerType == T) {
result[i] = elems[i].as(typeInfo.Vector.child, result[i]);
result[i] = elems[i].as(typeInfo.vector.child, result[i]);
} else {
result[i] = elems[i].as(?typeInfo.Vector.child, null) orelse return replacement;
result[i] = elems[i].as(?typeInfo.vector.child, null) orelse return replacement;
}
}
return result;
@ -146,39 +146,39 @@ pub const JsonElement = union(JsonType) { // MARK: JsonElement
fn createElementFromRandomType(value: anytype, allocator: std.mem.Allocator) JsonElement {
switch(@typeInfo(@TypeOf(value))) {
.Void => return JsonElement{.JsonNull={}},
.Null => return JsonElement{.JsonNull={}},
.Bool => return JsonElement{.JsonBool=value},
.Int, .ComptimeInt => return JsonElement{.JsonInt=@intCast(value)},
.Float, .ComptimeFloat => return JsonElement{.JsonFloat=@floatCast(value)},
.Union => {
.void => return JsonElement{.JsonNull={}},
.null => return JsonElement{.JsonNull={}},
.bool => return JsonElement{.JsonBool=value},
.int, .comptime_int => return JsonElement{.JsonInt=@intCast(value)},
.float, .comptime_float => return JsonElement{.JsonFloat=@floatCast(value)},
.@"union" => {
if(@TypeOf(value) == JsonElement) {
return value;
} else {
@compileError("Unknown value type.");
}
},
.Pointer => |ptr| {
.pointer => |ptr| {
if(ptr.child == u8 and ptr.size == .Slice) {
return JsonElement{.JsonString=value};
} else {
const childInfo = @typeInfo(ptr.child);
if(ptr.size == .One and childInfo == .Array and childInfo.Array.child == u8) {
if(ptr.size == .One and childInfo == .array and childInfo.array.child == u8) {
return JsonElement{.JsonString=value};
} else {
@compileError("Unknown value type.");
}
}
},
.Optional => {
.optional => {
if(value) |val| {
return createElementFromRandomType(val, allocator);
} else {
return JsonElement{.JsonNull={}};
}
},
.Vector => {
const len = @typeInfo(@TypeOf(value)).Vector.len;
.vector => {
const len = @typeInfo(@TypeOf(value)).vector.len;
const result = initArray(main.utils.NeverFailingAllocator{.allocator = allocator, .IAssertThatTheProvidedAllocatorCantFail = {}});
result.JsonArray.ensureCapacity(len);
inline for(0..len) |i| {

View File

@ -56,7 +56,7 @@ pub const std_options: std.Options = .{ // MARK: std_options
.log_level = .debug,
.logFn = struct {pub fn logFn(
comptime level: std.log.Level,
comptime _: @Type(.EnumLiteral),
comptime _: @Type(.enum_literal),
comptime format: []const u8,
args: anytype,
) void {
@ -125,10 +125,10 @@ pub const std_options: std.Options = .{ // MARK: std_options
types = types ++ &[_]type{i64};
} else if(@TypeOf(args[i_1]) == comptime_float) {
types = types ++ &[_]type{f64};
} else if(TI == .Pointer and TI.Pointer.size == .Slice and TI.Pointer.child == u8) {
} else if(TI == .pointer and TI.pointer.size == .Slice and TI.pointer.child == u8) {
types = types ++ &[_]type{[]const u8};
} else if(TI == .Int and TI.Int.bits <= 64) {
if(TI.Int.signedness == .signed) {
} else if(TI == .int and TI.int.bits <= 64) {
if(TI.int.signedness == .signed) {
types = types ++ &[_]type{i64};
} else {
types = types ++ &[_]type{u64};

View File

@ -32,7 +32,7 @@ const gridSize = 4096;
fn snapToGrid(x: anytype) @TypeOf(x) {
const T = @TypeOf(x);
const int = @as(@Vector(@typeInfo(T).Vector.len, i32), @intFromFloat(std.math.round(x*@as(T, @splat(gridSize)))));
const int = @as(@Vector(@typeInfo(T).vector.len, i32), @intFromFloat(std.math.round(x*@as(T, @splat(gridSize)))));
return @as(T, @floatFromInt(int))/@as(T, @splat(gridSize));
}
@ -212,7 +212,7 @@ pub const Model = struct {
continue;
if (std.mem.eql(u8, line[0..2], "v ")) {
var coordsIter = std.mem.split(u8, line[2..], " ");
var coordsIter = std.mem.splitScalar(u8, line[2..], ' ');
var coords: Vec3f = undefined;
var i: usize = 0;
while (coordsIter.next()) |coord| : (i += 1) {
@ -221,7 +221,7 @@ pub const Model = struct {
const coordsCorrect: Vec3f = .{coords[0], coords[1], coords[2]};
vertices.append(coordsCorrect);
} else if (std.mem.eql(u8, line[0..3], "vn ")) {
var coordsIter = std.mem.split(u8, line[3..], " ");
var coordsIter = std.mem.splitScalar(u8, line[3..], ' ');
var norm: Vec3f = undefined;
var i: usize = 0;
while (coordsIter.next()) |coord| : (i += 1) {
@ -230,7 +230,7 @@ pub const Model = struct {
const normCorrect: Vec3f = .{norm[0], norm[1], norm[2]};
normals.append(normCorrect);
} else if (std.mem.eql(u8, line[0..3], "vt ")) {
var coordsIter = std.mem.split(u8, line[3..], " ");
var coordsIter = std.mem.splitScalar(u8, line[3..], ' ');
var uv: Vec2f = undefined;
var i: usize = 0;
while (coordsIter.next()) |coord| : (i += 1) {
@ -240,7 +240,7 @@ pub const Model = struct {
uv[1] *= 4;
uvs.append(.{uv[0], uv[1]});
} else if (std.mem.eql(u8, line[0..2], "f ")) {
var coordsIter = std.mem.split(u8, line[2..], " ");
var coordsIter = std.mem.splitScalar(u8, line[2..], ' ');
var faceData: [3][4]usize = undefined;
var i: usize = 0;
var failed = false;
@ -250,7 +250,7 @@ pub const Model = struct {
std.log.err("More than 4 verticies in a face", .{});
break;
}
var d = std.mem.split(u8, vertex, "/");
var d = std.mem.splitScalar(u8, vertex, '/');
var j: usize = 0;
if (std.mem.count(u8, vertex, "/") != 2 or std.mem.count(u8, vertex, "//") != 0) {
failed = true;

View File

@ -113,7 +113,7 @@ const Socket = struct {
pub fn init() void {
Socket.startup();
inline for(@typeInfo(Protocols).Struct.decls) |decl| {
inline for(@typeInfo(Protocols).@"struct".decls) |decl| {
if(@TypeOf(@field(Protocols, decl.name)) == type) {
const id = @field(Protocols, decl.name).id;
if(id != Protocols.keepAlive and id != Protocols.important and Protocols.list[id] == null) {

View File

@ -35,8 +35,8 @@ pub fn nextInt(comptime T: type, seed: *u64) T {
}
pub fn nextIntBounded(comptime T: type, seed: *u64, bound: T) T {
if(@typeInfo(T) != .Int) @compileError("Type must be integer.");
if(@typeInfo(T).Int.signedness == .signed) return nextIntBounded(std.meta.Int(.unsigned, @bitSizeOf(T) - 1), seed, @intCast(bound));
if(@typeInfo(T) != .int) @compileError("Type must be integer.");
if(@typeInfo(T).int.signedness == .signed) return nextIntBounded(std.meta.Int(.unsigned, @bitSizeOf(T) - 1), seed, @intCast(bound));
const bitSize = std.math.log2_int_ceil(T, bound);
var result = nextWithBitSize(T, seed, bitSize);
while(result >= bound) {

View File

@ -669,14 +669,14 @@ pub const RotationModes = struct {
pub fn init() void {
rotationModes = std.StringHashMap(RotationMode).init(main.globalAllocator.allocator);
inline for(@typeInfo(RotationModes).Struct.decls) |declaration| {
inline for(@typeInfo(RotationModes).@"struct".decls) |declaration| {
register(@field(RotationModes, declaration.name));
}
}
pub fn deinit() void {
rotationModes.deinit();
inline for(@typeInfo(RotationModes).Struct.decls) |declaration| {
inline for(@typeInfo(RotationModes).@"struct".decls) |declaration| {
@field(RotationModes, declaration.name).deinit();
}
}
@ -690,7 +690,7 @@ pub fn getByID(id: []const u8) *RotationMode {
pub fn register(comptime Mode: type) void {
Mode.init();
var result: RotationMode = RotationMode{};
inline for(@typeInfo(RotationMode).Struct.fields) |field| {
inline for(@typeInfo(RotationMode).@"struct".fields) |field| {
if(@hasDecl(Mode, field.name)) {
if(field.type == @TypeOf(@field(Mode, field.name))) {
@field(result, field.name) = @field(Mode, field.name);

View File

@ -15,7 +15,7 @@ pub var commands: std.StringHashMap(Command) = undefined;
pub fn init() void {
commands = std.StringHashMap(Command).init(main.globalAllocator.allocator);
const commandList = @import("_list.zig");
inline for(@typeInfo(commandList).Struct.decls) |decl| {
inline for(@typeInfo(commandList).@"struct".decls) |decl| {
commands.put(decl.name, .{
.name = decl.name,
.description = @field(commandList, decl.name).description,

View File

@ -575,7 +575,7 @@ var profile: TerrainGenerationProfile = undefined;
pub fn initGenerators() void {
const list = @import("cavebiomegen/_list.zig");
inline for(@typeInfo(list).Struct.decls) |decl| {
inline for(@typeInfo(list).@"struct".decls) |decl| {
CaveBiomeGenerator.registerGenerator(@field(list, decl.name));
}
}

View File

@ -316,7 +316,7 @@ fn cacheInit(pos: ChunkPosition) *CaveMapFragment {
pub fn initGenerators() void {
const list = @import("cavegen/_list.zig");
inline for(@typeInfo(list).Struct.decls) |decl| {
inline for(@typeInfo(list).@"struct".decls) |decl| {
CaveGenerator.registerGenerator(@field(list, decl.name));
}
}

View File

@ -109,7 +109,7 @@ var profile: TerrainGenerationProfile = undefined;
pub fn initGenerators() void {
const list = @import("climategen/_list.zig");
inline for(@typeInfo(list).Struct.decls) |decl| {
inline for(@typeInfo(list).@"struct".decls) |decl| {
ClimateMapGenerator.registerGenerator(@field(list, decl.name));
}
}

View File

@ -157,7 +157,7 @@ fn cacheInit(pos: ChunkPosition) *StructureMapFragment {
pub fn initGenerators() void {
const list = @import("structuremapgen/_list.zig");
inline for(@typeInfo(list).Struct.decls) |decl| {
inline for(@typeInfo(list).@"struct".decls) |decl| {
StructureMapGenerator.registerGenerator(@field(list, decl.name));
}
}

View File

@ -251,7 +251,7 @@ var profile: TerrainGenerationProfile = undefined;
pub fn initGenerators() void {
const list = @import("mapgen/_list.zig");
inline for(@typeInfo(list).Struct.decls) |decl| {
inline for(@typeInfo(list).@"struct".decls) |decl| {
MapGenerator.registerGenerator(@field(list, decl.name));
}
}

View File

@ -141,24 +141,24 @@ const Stripe = struct { // MARK: Stripe
fn hashGeneric(input: anytype) u64 {
const T = @TypeOf(input);
return switch(@typeInfo(T)) {
.Bool => @intFromBool(input),
.Enum => @intFromEnum(input),
.Int, .Float => @as(std.meta.Int(.unsigned, @bitSizeOf(T)), @bitCast(input)),
.Struct => blk: {
.bool => @intFromBool(input),
.@"enum" => @intFromEnum(input),
.int, .float => @as(std.meta.Int(.unsigned, @bitSizeOf(T)), @bitCast(input)),
.@"struct" => blk: {
if(@hasDecl(T, "getHash")) {
break :blk input.getHash();
}
var result: u64 = 0;
inline for(@typeInfo(T).Struct.fields) |field| {
inline for(@typeInfo(T).@"struct".fields) |field| {
result ^= hashGeneric(@field(input, field.name))*%hashGeneric(@as([]const u8, field.name));
}
break :blk result;
},
.Optional => if(input) |_input| hashGeneric(_input) else 0,
.Pointer => switch(@typeInfo(T).Pointer.size) {
.optional => if(input) |_input| hashGeneric(_input) else 0,
.pointer => switch(@typeInfo(T).pointer.size) {
.One => blk: {
if(@typeInfo(@typeInfo(T).Pointer.child) == .Fn) break :blk 0;
if(@typeInfo(T).Pointer.child == anyopaque) break :blk 0;
if(@typeInfo(@typeInfo(T).pointer.child) == .@"fn") break :blk 0;
if(@typeInfo(T).pointer.child == anyopaque) break :blk 0;
break :blk hashGeneric(input.*);
},
.Slice => blk: {
@ -170,16 +170,16 @@ fn hashGeneric(input: anytype) u64 {
},
else => @compileError("Unsupported type " ++ @typeName(T)),
},
.Array => blk: {
.array => blk: {
var result: u64 = 0;
for(input) |val| {
result = result*%33 +% hashGeneric(val);
}
break :blk result;
},
.Vector => blk: {
.vector => blk: {
var result: u64 = 0;
inline for(0..@typeInfo(T).Vector.len) |i| {
inline for(0..@typeInfo(T).vector.len) |i| {
result = result*%33 +% hashGeneric(input[i]);
}
break :blk result;
@ -222,7 +222,7 @@ pub const Biome = struct { // MARK: Biome
var result: GenerationProperties = .{};
for(json.toSlice()) |child| {
const property = child.as([]const u8, "");
inline for(@typeInfo(GenerationProperties).Struct.fields) |field| {
inline for(@typeInfo(GenerationProperties).@"struct".fields) |field| {
if(std.mem.eql(u8, field.name, property)) {
@field(result, field.name) = true;
}
@ -546,7 +546,7 @@ pub fn init() void {
caveBiomes = main.List(Biome).init(main.globalAllocator);
biomesById = std.StringHashMap(*Biome).init(main.globalAllocator.allocator);
const list = @import("simple_structures/_list.zig");
inline for(@typeInfo(list).Struct.decls) |decl| {
inline for(@typeInfo(list).@"struct".decls) |decl| {
SimpleStructureModel.registerGenerator(@field(list, decl.name));
}
}

View File

@ -131,7 +131,7 @@ pub fn initGenerators() void {
CaveMap.initGenerators();
StructureMap.initGenerators();
const list = @import("chunkgen/_list.zig");
inline for(@typeInfo(list).Struct.decls) |decl| {
inline for(@typeInfo(list).@"struct".decls) |decl| {
BlockGenerator.registerGenerator(@field(list, decl.name));
}
const t1 = std.time.milliTimestamp();

View File

@ -66,17 +66,17 @@ pub fn init() void {
};
defer json.free(main.stackAllocator);
inline for(@typeInfo(@This()).Struct.decls) |decl| {
const is_const = @typeInfo(@TypeOf(&@field(@This(), decl.name))).Pointer.is_const; // Sadly there is no direct way to check if a declaration is const.
inline for(@typeInfo(@This()).@"struct".decls) |decl| {
const is_const = @typeInfo(@TypeOf(&@field(@This(), decl.name))).pointer.is_const; // Sadly there is no direct way to check if a declaration is const.
if(!is_const) {
const declType = @TypeOf(@field(@This(), decl.name));
if(@typeInfo(declType) == .Struct) {
if(@typeInfo(declType) == .@"struct") {
@compileError("Not implemented yet.");
}
@field(@This(), decl.name) = json.get(declType, decl.name, @field(@This(), decl.name));
if(@typeInfo(declType) == .Pointer) {
if(@typeInfo(declType).Pointer.size == .Slice) {
@field(@This(), decl.name) = main.globalAllocator.dupe(@typeInfo(declType).Pointer.child, @field(@This(), decl.name));
if(@typeInfo(declType) == .pointer) {
if(@typeInfo(declType).pointer.size == .Slice) {
@field(@This(), decl.name) = main.globalAllocator.dupe(@typeInfo(declType).pointer.child, @field(@This(), decl.name));
} else {
@compileError("Not implemented yet.");
}
@ -98,15 +98,15 @@ pub fn init() void {
pub fn deinit() void {
save();
inline for(@typeInfo(@This()).Struct.decls) |decl| {
const is_const = @typeInfo(@TypeOf(&@field(@This(), decl.name))).Pointer.is_const; // Sadly there is no direct way to check if a declaration is const.
inline for(@typeInfo(@This()).@"struct".decls) |decl| {
const is_const = @typeInfo(@TypeOf(&@field(@This(), decl.name))).pointer.is_const; // Sadly there is no direct way to check if a declaration is const.
if(!is_const) {
const declType = @TypeOf(@field(@This(), decl.name));
if(@typeInfo(declType) == .Struct) {
if(@typeInfo(declType) == .@"struct") {
@compileError("Not implemented yet.");
}
if(@typeInfo(declType) == .Pointer) {
if(@typeInfo(declType).Pointer.size == .Slice) {
if(@typeInfo(declType) == .pointer) {
if(@typeInfo(declType).pointer.size == .Slice) {
main.globalAllocator.free(@field(@This(), decl.name));
} else {
@compileError("Not implemented yet.");
@ -120,11 +120,11 @@ pub fn save() void {
const jsonObject = JsonElement.initObject(main.stackAllocator);
defer jsonObject.free(main.stackAllocator);
inline for(@typeInfo(@This()).Struct.decls) |decl| {
const is_const = @typeInfo(@TypeOf(&@field(@This(), decl.name))).Pointer.is_const; // Sadly there is no direct way to check if a declaration is const.
inline for(@typeInfo(@This()).@"struct".decls) |decl| {
const is_const = @typeInfo(@TypeOf(&@field(@This(), decl.name))).pointer.is_const; // Sadly there is no direct way to check if a declaration is const.
if(!is_const) {
const declType = @TypeOf(@field(@This(), decl.name));
if(@typeInfo(declType) == .Struct) {
if(@typeInfo(declType) == .@"struct") {
@compileError("Not implemented yet.");
}
if(declType == []const u8) {

View File

@ -725,7 +725,7 @@ pub const NeverFailingAllocator = struct { // MARK: NeverFailingAllocator
/// can be larger, smaller, or the same size as the old memory allocation.
/// If `new_n` is 0, this is the same as `free` and it always succeeds.
pub fn realloc(self: NeverFailingAllocator, old_mem: anytype, new_n: usize) t: {
const Slice = @typeInfo(@TypeOf(old_mem)).Pointer;
const Slice = @typeInfo(@TypeOf(old_mem)).pointer;
break :t []align(Slice.alignment) Slice.child;
} {
return self.allocator.realloc(old_mem, new_n) catch unreachable;
@ -737,7 +737,7 @@ pub const NeverFailingAllocator = struct { // MARK: NeverFailingAllocator
new_n: usize,
return_address: usize,
) t: {
const Slice = @typeInfo(@TypeOf(old_mem)).Pointer;
const Slice = @typeInfo(@TypeOf(old_mem)).pointer;
break :t []align(Slice.alignment) Slice.child;
} {
return self.allocator.reallocAdvanced(old_mem, new_n, return_address) catch unreachable;

View File

@ -14,23 +14,23 @@ pub inline fn combine(pos: Vec3f, w: f32) Vec4f {
return .{pos[0], pos[1], pos[2], w};
}
pub fn xyz(self: anytype) @Vector(3, @typeInfo(@TypeOf(self)).Vector.child) {
return @Vector(3, @typeInfo(@TypeOf(self)).Vector.child){self[0], self[1], self[2]};
pub fn xyz(self: anytype) @Vector(3, @typeInfo(@TypeOf(self)).vector.child) {
return @Vector(3, @typeInfo(@TypeOf(self)).vector.child){self[0], self[1], self[2]};
}
pub fn xy(self: anytype) @Vector(2, @typeInfo(@TypeOf(self)).Vector.child) {
return @Vector(2, @typeInfo(@TypeOf(self)).Vector.child){self[0], self[1]};
pub fn xy(self: anytype) @Vector(2, @typeInfo(@TypeOf(self)).vector.child) {
return @Vector(2, @typeInfo(@TypeOf(self)).vector.child){self[0], self[1]};
}
pub fn dot(self: anytype, other: @TypeOf(self)) @typeInfo(@TypeOf(self)).Vector.child {
pub fn dot(self: anytype, other: @TypeOf(self)) @typeInfo(@TypeOf(self)).vector.child {
return @reduce(.Add, self*other);
}
pub fn lengthSquare(self: anytype) @typeInfo(@TypeOf(self)).Vector.child {
pub fn lengthSquare(self: anytype) @typeInfo(@TypeOf(self)).vector.child {
return @reduce(.Add, self*self);
}
pub fn length(self: anytype) @typeInfo(@TypeOf(self)).Vector.child {
pub fn length(self: anytype) @typeInfo(@TypeOf(self)).vector.child {
return @sqrt(@reduce(.Add, self*self));
}
@ -39,7 +39,7 @@ pub fn normalize(self: anytype) @TypeOf(self) {
}
pub fn cross(self: anytype, other: @TypeOf(self)) @TypeOf(self) {
if(@typeInfo(@TypeOf(self)).Vector.len != 3) @compileError("Only available for vectors of length 3.");
if(@typeInfo(@TypeOf(self)).vector.len != 3) @compileError("Only available for vectors of length 3.");
return @TypeOf(self) {
self[1]*other[2] - self[2]*other[1],
self[2]*other[0] - self[0]*other[2],
@ -47,8 +47,8 @@ pub fn cross(self: anytype, other: @TypeOf(self)) @TypeOf(self) {
};
}
pub fn rotateX(self: anytype, angle: @typeInfo(@TypeOf(self)).Vector.child) @TypeOf(self) {
if(@typeInfo(@TypeOf(self)).Vector.len != 3) @compileError("Only available for vectors of length 3.");
pub fn rotateX(self: anytype, angle: @typeInfo(@TypeOf(self)).vector.child) @TypeOf(self) {
if(@typeInfo(@TypeOf(self)).vector.len != 3) @compileError("Only available for vectors of length 3.");
const sin = @sin(angle);
const cos = @cos(angle);
return @TypeOf(self){
@ -58,8 +58,8 @@ pub fn rotateX(self: anytype, angle: @typeInfo(@TypeOf(self)).Vector.child) @Typ
};
}
pub fn rotateY(self: anytype, angle: @typeInfo(@TypeOf(self)).Vector.child) @TypeOf(self) {
if(@typeInfo(@TypeOf(self)).Vector.len != 3) @compileError("Only available for vectors of length 3.");
pub fn rotateY(self: anytype, angle: @typeInfo(@TypeOf(self)).vector.child) @TypeOf(self) {
if(@typeInfo(@TypeOf(self)).vector.len != 3) @compileError("Only available for vectors of length 3.");
const sin = @sin(angle);
const cos = @cos(angle);
return @TypeOf(self){
@ -69,8 +69,8 @@ pub fn rotateY(self: anytype, angle: @typeInfo(@TypeOf(self)).Vector.child) @Typ
};
}
pub fn rotateZ(self: anytype, angle: @typeInfo(@TypeOf(self)).Vector.child) @TypeOf(self) {
if(@typeInfo(@TypeOf(self)).Vector.len != 3) @compileError("Only available for vectors of length 3.");
pub fn rotateZ(self: anytype, angle: @typeInfo(@TypeOf(self)).vector.child) @TypeOf(self) {
if(@typeInfo(@TypeOf(self)).vector.len != 3) @compileError("Only available for vectors of length 3.");
const sin = @sin(angle);
const cos = @cos(angle);
return @TypeOf(self){