diff --git a/build.zig b/build.zig index 3ccfdc6..70c9335 100644 --- a/build.zig +++ b/build.zig @@ -91,10 +91,10 @@ pub fn build(b: *std.Build) !void { //SDL { //wgpu - var wgpu_from_source = b.option(bool, "wgpu_from_source", "Compile WGPU from source") orelse false; + const wgpu_from_source = b.option(bool, "wgpu_from_source", "Compile WGPU from source") orelse false; if (wgpu_from_source) { - var wgpu_lib = try wgpu.create_wgpu(b, target, optimize); + const wgpu_lib = try wgpu.create_wgpu(b, target, optimize); if (target.getOsTag() == .windows) { @panic("TODO"); //we need to force dynamic linking here. @@ -110,7 +110,7 @@ pub fn build(b: *std.Build) !void { try wgpu_bin_path.append('-'); try wgpu_bin_path.appendSlice(@tagName(target.getCpuArch())); - var wgpu_bin_path_slice = try wgpu_bin_path.toOwnedSlice(); + const wgpu_bin_path_slice = try wgpu_bin_path.toOwnedSlice(); exe.addLibraryPath(.{ .path = wgpu_bin_path_slice }); exe.linkSystemLibrary("wgpu_native"); @@ -154,7 +154,7 @@ pub fn build(b: *std.Build) !void { //zigimg { //iconv - var iconv_lib = iconv.createIconv(b, target, optimize); + const iconv_lib = iconv.createIconv(b, target, optimize); exe.linkLibrary(iconv_lib); diff --git a/build.zig.zon b/build.zig.zon index ec365a9..dc7e3ff 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -3,12 +3,12 @@ .version = "0.0.0", .dependencies = .{ .SDL2 = .{ - .url = "https://github.com/Beyley/SDL/archive/0a6995fbf53a00e181ddac434eaab3dd48ce1846.tar.gz", - .hash = "122076ecd1f0ff2720fa7011af7174b2b463989ecd0a3422e186c9b29b370e165da5", + .url = "https://github.com/Beyley/SDL/archive/f254788cd768adac006a25d7f1fe1e726596d9fd.tar.gz", + .hash = "1220f430383c1d7c198901c99dcd0b10cce8b3a34e77e60026f4c55ecf548e6d1ecc", }, .zigimg = .{ - .url = "https://github.com/zigimg/zigimg/archive/368658aa6b4d22cd532f2785d11f75b2ec2b490c.tar.gz", - .hash = "12201a74c6aa44832f8eac3e4a0e92e7bb7f3d6a12777f517fd470d7f6643cdc33fc", + .url = "https://github.com/zigimg/zigimg/archive/bb4dd9854c64cec6d810e1f9fa858ec308ac260c.tar.gz", + .hash = "12201813d83afa600cdbd68bbe5daf90c4b05edea8a99bded98217472760b425ec96", }, .clap = .{ .url = "https://github.com/Hejsil/zig-clap/archive/f49b94700e0761b7514abdca0e4f0e7f3f938a93.tar.gz", diff --git a/game/convert.zig b/game/convert.zig index 7f65525..20eab8a 100644 --- a/game/convert.zig +++ b/game/convert.zig @@ -35,7 +35,7 @@ pub fn readUTypingConversions(allocator: std.mem.Allocator) !Self { var file = try std.fs.cwd().openFile("convert.dat", .{}); defer file.close(); - var raw_data = try allocator.alloc(u8, try file.getEndPos()); + const raw_data = try allocator.alloc(u8, try file.getEndPos()); defer allocator.free(raw_data); _ = try file.readAll(raw_data); @@ -58,10 +58,10 @@ pub fn readUTypingConversions(allocator: std.mem.Allocator) !Self { const yen_replaced = std.mem.replace(u8, raw_replaced_data[0..(raw_replaced_data.len - underlines_replaced * ("‾".len - "~".len))], "¥", "\\", converted_data); //Calculate the length to cut off the end of the file, as the replacements will have shortened it - var length_to_cut = underlines_replaced * ("‾".len - "~".len) + yen_replaced * ("¥".len - "\\".len); + const length_to_cut = underlines_replaced * ("‾".len - "~".len) + yen_replaced * ("¥".len - "\\".len); //Cut off the end of the file - var data = converted_data[0..(converted_data.len - length_to_cut)]; + const data = converted_data[0..(converted_data.len - length_to_cut)]; var conversions = std.ArrayList(Conversion).init(allocator); errdefer { @@ -81,11 +81,11 @@ pub fn readUTypingConversions(allocator: std.mem.Allocator) !Self { var line = if (raw_line[raw_line.len - 1] == '\r') raw_line[0..(raw_line.len - 1)] else raw_line; - var idx1 = std.mem.indexOf(u8, line, "\t") orelse return error.InvalidConvertFile; - var idx2 = std.mem.indexOfPos(u8, line, idx1 + 1, "\t"); + const idx1 = std.mem.indexOf(u8, line, "\t") orelse return error.InvalidConvertFile; + const idx2 = std.mem.indexOfPos(u8, line, idx1 + 1, "\t"); - var romaji = line[0..idx1]; - var hiragana = line[(idx1 + 1)..(idx2 orelse line.len)]; + const romaji = line[0..idx1]; + const hiragana = line[(idx1 + 1)..(idx2 orelse line.len)]; var end_cut: ?[]const u8 = if (idx2 == null) null else line[(idx2.? + 1)..]; //The end cut must not be empty, so if it is, set it to null diff --git a/game/fontstash.zig b/game/fontstash.zig index 79047a4..04b8e5a 100644 --- a/game/fontstash.zig +++ b/game/fontstash.zig @@ -50,8 +50,8 @@ pub fn init(self: *Self, gfx: *Gfx, allocator: std.mem.Allocator) !void { self.renderer = try Renderer.init(allocator, gfx, self.texture.?); errdefer self.renderer.deinit(); - var gothic_data = @embedFile("fonts/gothic.ttf"); - var mincho_data = @embedFile("fonts/mincho.ttf"); + const gothic_data = @embedFile("fonts/gothic.ttf"); + const mincho_data = @embedFile("fonts/mincho.ttf"); self.gothic = try self.context.addFontMem("gothic", gothic_data); self.mincho = try self.context.addFontMem("mincho", mincho_data); @@ -61,7 +61,7 @@ pub fn verticalMetrics(self: *Self, state: Fontstash.State) struct { ascender: f var internal_state = state; internal_state.size *= self.gfx.scale; - var metrics = self.context.verticalMetrics(internal_state); + const metrics = self.context.verticalMetrics(internal_state); return .{ .ascender = metrics.ascender / self.gfx.scale, @@ -96,7 +96,7 @@ const Bounds = extern struct { }; pub fn textBounds(self: *Self, text: []const u8, state: Fontstash.State) !Bounds { - var bounds = try self.context.textBounds(Gfx.Vector2Zero, text, state); + const bounds = try self.context.textBounds(Gfx.Vector2Zero, text, state); return .{ .x1 = bounds.bounds.tl[0], @@ -158,11 +158,11 @@ fn handleError(self_ptr: ?*anyopaque, err: anyerror) anyerror!void { fn update(self_ptr: ?*anyopaque, rect: Fontstash.Rectangle, data: []const u8) anyerror!void { var self = toSelf(self_ptr.?); - var rect_x = rect.tl[0]; - var rect_y = rect.tl[1]; - var rect_wh = rect.br - rect.tl; - var w = rect_wh[0]; - var h = rect_wh[1]; + const rect_x = rect.tl[0]; + const rect_y = rect.tl[1]; + const rect_wh = rect.br - rect.tl; + const w = rect_wh[0]; + const h = rect_wh[1]; var full = try self.allocator.alloc(Gfx.ColorB, @intCast(w * h)); defer self.allocator.free(full); diff --git a/game/fontstash_impl.zig b/game/fontstash_impl.zig index f967d38..fa46588 100644 --- a/game/fontstash_impl.zig +++ b/game/fontstash_impl.zig @@ -176,7 +176,7 @@ pub const Atlas = struct { } fn addSkylineLevel(self: *Atlas, index: usize, rect: Rectangle) !void { - var new_node = SkylineNode{ + const new_node = SkylineNode{ .pos = .{ rect.tl[0], rect.tl[1] + rect.br[1], @@ -223,7 +223,7 @@ pub const Atlas = struct { var i: usize = 0; while (i < self.nodes.items.len - 1) : (i += 1) { var curr_node: *SkylineNode = &self.nodes.items[i]; - var next_node: SkylineNode = self.nodes.items[i + 1]; + const next_node: SkylineNode = self.nodes.items[i + 1]; if (curr_node.pos[1] == next_node.pos[1]) { curr_node.width += next_node.width; @@ -292,15 +292,15 @@ pub const Atlas = struct { i = idx; while (i < self.nodes.items.len and self.nodes.items[i].pos[0] < rect_right) { - var curr_node = self.nodes.items[i]; + const curr_node = self.nodes.items[i]; //If the current node is outside of the rect, if (curr_node.pos[0] >= rect_right or curr_node.pos[0] + curr_node.width <= rect_left) { break; } - var left_side = curr_node.pos[0]; - var right_side = @min(rect_right, left_side + curr_node.width); + const left_side = curr_node.pos[0]; + const right_side = @min(rect_right, left_side + curr_node.width); std.debug.assert(y >= curr_node.pos[1]); @@ -482,19 +482,19 @@ fn getGlyph(self: *Self, font: *Font, codepoint: u21, state: State) !*Font.Glyph var render_font = font; //Convert the blur into a pixel padding, 1blur = 10px - var pad = @as(isize, @intFromFloat(state.blur * 10)) + 2; + const pad = @as(isize, @intFromFloat(state.blur * 10)) + 2; //Reset the scratch buffer usage self.scratch_buffer.len = 0; //Hash the codepoint - var hash = hashInt(codepoint) & (hash_lut_size - 1); + const hash = hashInt(codepoint) & (hash_lut_size - 1); //Get the index of the codepoint from the hash var i = font.lut[hash]; while (i != null) { //Get the glyph - var glyph = &font.glyphs.items[i.?]; + const glyph = &font.glyphs.items[i.?]; //If the codepoint, size, and blur matches, return the cached glyph if (glyph.codepoint == codepoint and glyph.size == state.size and glyph.blur == state.blur) { @@ -511,7 +511,7 @@ fn getGlyph(self: *Self, font: *Font, codepoint: u21, state: State) !*Font.Glyph //Try to find the glyph in the fallback fonts if there was none in the main font if (glyph_index == 0) { for (font.fallbacks.items) |fallback_font| { - var fallback_index = getGlyphIndex(fallback_font, codepoint); + const fallback_index = getGlyphIndex(fallback_font, codepoint); //If the fallback font has the glyph, render that index and font instead if (fallback_index != 0) { @@ -522,7 +522,7 @@ fn getGlyph(self: *Self, font: *Font, codepoint: u21, state: State) !*Font.Glyph } } - var scale = c.stbtt_ScaleForPixelHeight(&render_font.font, state.size); + const scale = c.stbtt_ScaleForPixelHeight(&render_font.font, state.size); var advance: c_int = undefined; var left_side_bearing: c_int = undefined; @@ -547,15 +547,15 @@ fn getGlyph(self: *Self, font: *Font, codepoint: u21, state: State) !*Font.Glyph &y1c, ); - var x0: isize = @intCast(x0c); - var y0: isize = @intCast(y0c); - var x1: isize = @intCast(x1c); - var y1: isize = @intCast(y1c); + const x0: isize = @intCast(x0c); + const y0: isize = @intCast(y0c); + const x1: isize = @intCast(x1c); + const y1: isize = @intCast(y1c); - var glyph_width: usize = @intCast(x1 - x0 + @as(isize, @intCast(pad)) * 2); - var glyph_height: usize = @intCast(y1 - y0 + @as(isize, @intCast(pad)) * 2); + const glyph_width: usize = @intCast(x1 - x0 + @as(isize, @intCast(pad)) * 2); + const glyph_height: usize = @intCast(y1 - y0 + @as(isize, @intCast(pad)) * 2); - var glyph_position = self.atlas.getRect(glyph_width, glyph_height) catch |err| blk: { + const glyph_position = self.atlas.getRect(glyph_width, glyph_height) catch |err| blk: { if (err == Atlas.AtlasErrors.AtlasFull) { try self.parameters.impl_handle_error(self.parameters.user_ptr, err); break :blk try self.atlas.getRect(glyph_width, glyph_height); @@ -564,7 +564,7 @@ fn getGlyph(self: *Self, font: *Font, codepoint: u21, state: State) !*Font.Glyph } }; - var glyph = Font.Glyph{ + const glyph = Font.Glyph{ .blur = state.blur, .codepoint = codepoint, .index = glyph_index, @@ -584,7 +584,7 @@ fn getGlyph(self: *Self, font: *Font, codepoint: u21, state: State) !*Font.Glyph font.lut[hash] = font.glyphs.items.len - 1; //Rasterize - var dst_ptr = &self.tex_cache[(glyph.rectangle.tl[0] + @as(usize, @intCast(pad))) + (glyph.rectangle.tl[1] + @as(usize, @intCast(pad))) * self.parameters.width]; + const dst_ptr = &self.tex_cache[(glyph.rectangle.tl[0] + @as(usize, @intCast(pad))) + (glyph.rectangle.tl[1] + @as(usize, @intCast(pad))) * self.parameters.width]; c.stbtt_MakeGlyphBitmap( &render_font.font, dst_ptr, @@ -615,7 +615,7 @@ fn getGlyph(self: *Self, font: *Font, codepoint: u21, state: State) !*Font.Glyph //Blur if (state.blur > 0) { self.scratch_buffer.len = 0; - var blur_dst_offset: usize = @intCast(glyph.rectangle.tl[0] + glyph.rectangle.tl[1] * self.parameters.width); + const blur_dst_offset: usize = @intCast(glyph.rectangle.tl[0] + glyph.rectangle.tl[1] * self.parameters.width); _ = blur_dst_offset; // TODO @@ -661,19 +661,19 @@ fn getQuad( // Each glyph has a 2px border to allow good interpolation, // one pixel to prevent leaking, and one to allow good interpolation for rendering. // Inset the texture region by one pixel for correct interpolation. - var x_offset = glyph.x_offset + 1; - var y_offset = glyph.y_offset + 1; + const x_offset = glyph.x_offset + 1; + const y_offset = glyph.y_offset + 1; //Inset the rect - var rect = RectangleF{ + const rect = RectangleF{ .tl = Gfx.vector2UToF(glyph.rectangle.tl) + Gfx.Vector2One, .br = Gfx.vector2UToF(glyph.rectangle.br) - Gfx.Vector2One, }; - var quad = switch (self.parameters.zero_position) { + const quad = switch (self.parameters.zero_position) { .top_left => blk: { //TODO: make a way to disable rounding here - var rounded_x = @round(x.* + x_offset); - var rounded_y = @round(y.* + y_offset); + const rounded_x = @round(x.* + x_offset); + const rounded_y = @round(y.* + y_offset); break :blk Quad{ .rect = RectangleF{ @@ -687,8 +687,8 @@ fn getQuad( }; }, .bottom_left => blk: { - var rounded_x = @round(x.* + x_offset); - var rounded_y = @round(y.* - y_offset); + const rounded_x = @round(x.* + x_offset); + const rounded_y = @round(y.* - y_offset); break :blk Quad{ .rect = RectangleF{ @@ -728,7 +728,7 @@ pub fn textBounds( var font = self.fonts.get(state.font) orelse return error.MissingFont; - var scale = c.stbtt_ScaleForPixelHeight(&font.font, state.size); + const scale = c.stbtt_ScaleForPixelHeight(&font.font, state.size); //Align vertically draw_position[1] += self.getVerticalAlignment(font.*, state); @@ -736,18 +736,18 @@ pub fn textBounds( var min = draw_position; var max = draw_position; - var x_start = draw_position[0]; + const x_start = draw_position[0]; var iter = std.unicode.Utf8Iterator{ .bytes = text, .i = 0 }; var previous_glyph_index: ?usize = null; var next = iter.nextCodepoint(); while (next != null) : (next = iter.nextCodepoint()) { - var codepoint: u21 = next.?; + const codepoint: u21 = next.?; - var glyph = try self.getGlyph(font, codepoint, state); + const glyph = try self.getGlyph(font, codepoint, state); - var quad = self.getQuad( + const quad = self.getQuad( font, previous_glyph_index, glyph, @@ -831,11 +831,11 @@ pub fn write(context: *WriterContext, text: []const u8) WriteError!usize { var min = context.bounds.tl; var max = context.bounds.br; - var previous_glyph_index: ?usize = null; + const previous_glyph_index: ?usize = null; while (iter.nextCodepoint()) |codepoint| { - var glyph = try self.getGlyph(context._font, codepoint, state); + const glyph = try self.getGlyph(context._font, codepoint, state); - var quad = self.getQuad( + const quad = self.getQuad( context._font, previous_glyph_index, glyph, @@ -906,7 +906,7 @@ pub fn drawText(self: *Self, position: Gfx.Vector2, text: []const u8, state: Sta var font = self.fonts.get(state.font) orelse return error.MissingFont; - var scale = c.stbtt_ScaleForPixelHeight(&font.font, state.size); + const scale = c.stbtt_ScaleForPixelHeight(&font.font, state.size); //Align horizontally switch (state.alignment.horizontal) { @@ -929,14 +929,14 @@ pub fn drawText(self: *Self, position: Gfx.Vector2, text: []const u8, state: Sta var return_size: Gfx.Vector2 = draw_position; - var previous_glyph_index: ?usize = null; + const previous_glyph_index: ?usize = null; var next: ?u21 = iter.nextCodepoint(); while (next != null) : (next = iter.nextCodepoint()) { - var codepoint = next.?; + const codepoint = next.?; - var glyph = try self.getGlyph(font, codepoint, state); + const glyph = try self.getGlyph(font, codepoint, state); - var quad = self.getQuad(font, previous_glyph_index, glyph, scale, state.spacing, &draw_position[0], &draw_position[1]); + const quad = self.getQuad(font, previous_glyph_index, glyph, scale, state.spacing, &draw_position[0], &draw_position[1]); if (self.vertex_count + 6 > vertex_count) { try self.flush(); @@ -1003,12 +1003,12 @@ fn flush(self: *Self) !void { ///Adds a white rectangle to the atlas fn addWhiteRect(self: *Self, width: usize, height: usize) !void { - var rect_pos = try self.atlas.getRect(width, height); + const rect_pos = try self.atlas.getRect(width, height); for (0..height) |y| { const start_pos = rect_pos[0] + y * self.parameters.width; - var row = self.tex_cache[start_pos .. start_pos + width]; + const row = self.tex_cache[start_pos .. start_pos + width]; @memset(row, 0); } @@ -1022,7 +1022,7 @@ pub fn verticalMetrics(self: *Self, state: State) struct { descender: f32, lineh: f32, } { - var font: *Font = self.fonts.get(state.font) orelse unreachable; + const font: *Font = self.fonts.get(state.font) orelse unreachable; return .{ .ascender = font.ascender * state.size, @@ -1111,7 +1111,7 @@ pub fn addFontMem( &line_gap, ); - var fh = ascent - descent; + const fh = ascent - descent; font.ascender = @as(f32, @floatFromInt(ascent)) / @as(f32, @floatFromInt(fh)); font.descender = @as(f32, @floatFromInt(descent)) / @as(f32, @floatFromInt(fh)); @@ -1130,7 +1130,7 @@ pub fn deinit(self: *Self) void { var next: ?**Font = iter.next(); while (next != null) : (next = iter.next()) { - var font = next.?; + const font = next.?; font.*.glyphs.deinit(); diff --git a/game/fumen.zig b/game/fumen.zig index 526636b..2e36729 100644 --- a/game/fumen.zig +++ b/game/fumen.zig @@ -149,7 +149,7 @@ pub fn readFromFile(allocator: std.mem.Allocator, file: std.fs.File, dir: std.fs var orig_line: []u8 = try file.reader().readUntilDelimiterOrEofAlloc(allocator, '\n', std.math.maxInt(u32)) orelse break; defer allocator.free(orig_line); - var returnless = if (orig_line[orig_line.len - 1] == '\r') orig_line[0 .. orig_line.len - 1] else orig_line; + const returnless = if (orig_line[orig_line.len - 1] == '\r') orig_line[0 .. orig_line.len - 1] else orig_line; var converted = try iconv.convert(allocator, returnless); defer allocator.free(converted); @@ -161,9 +161,9 @@ pub fn readFromFile(allocator: std.mem.Allocator, file: std.fs.File, dir: std.fs self.audio_path = try allocator.dupeZ(u8, without_identifier); }, '+' => { - var space_idx = std.mem.indexOf(u8, without_identifier, &.{' '}).?; + const space_idx = std.mem.indexOf(u8, without_identifier, &.{' '}).?; - var lyric = Lyric{ + const lyric = Lyric{ .time = try std.fmt.parseFloat(f64, without_identifier[0..space_idx]), .text = try allocator.dupeZ(u8, without_identifier[(space_idx + 1)..]), }; @@ -207,7 +207,7 @@ pub fn readFromFile(allocator: std.mem.Allocator, file: std.fs.File, dir: std.fs next = split_iterator.next(); } - var lyric = LyricKanji{ + const lyric = LyricKanji{ .time = time, .time_end = std.math.inf(f64), .parts = try part_list.toOwnedSlice(), @@ -228,7 +228,7 @@ pub fn readFromFile(allocator: std.mem.Allocator, file: std.fs.File, dir: std.fs }); }, '/' => { - var time = try std.fmt.parseFloat(f64, without_identifier); + const time = try std.fmt.parseFloat(f64, without_identifier); if (lyrics_kanji.items.len > 0) { lyrics_kanji.items[lyrics_kanji.items.len - 1].time_end = time; diff --git a/game/gfx.zig b/game/gfx.zig index c1a9fba..e6460ef 100644 --- a/game/gfx.zig +++ b/game/gfx.zig @@ -205,7 +205,7 @@ pub fn init(window: *c.SDL_Window, scale: f32) !Self { self.shader = try self.device.createShaderModule(); //Get the surface format - var preferred_surface_format = self.surface.getPreferredFormat(self.adapter); + const preferred_surface_format = self.surface.getPreferredFormat(self.adapter); //Create the bind group layouts self.bind_group_layouts = try self.device.createBindGroupLayouts(); @@ -492,7 +492,7 @@ pub const Instance = struct { pub fn createSurface(self: Instance, window: *c.SDL_Window) !Surface { var info: c.SDL_SysWMinfo = undefined; c.SDL_GetVersion(&info.version); - var result = c.SDL_GetWindowWMInfo(window, &info); + const result = c.SDL_GetWindowWMInfo(window, &info); if (result == c.SDL_FALSE) { return Error.UnableToRetrieveWindowWMInfo; @@ -559,7 +559,7 @@ pub const Instance = struct { return Error.UnknownWindowSubsystem; } - var surface = c.wgpuInstanceCreateSurface(self.c, &descriptor); + const surface = c.wgpuInstanceCreateSurface(self.c, &descriptor); std.debug.print("got surface {*}\n", .{surface.?}); @@ -663,7 +663,7 @@ pub const Device = struct { } pub fn createShaderModule(self: Device) !c.WGPUShaderModule { - var module = c.wgpuDeviceCreateShaderModule(self.c, &c.WGPUShaderModuleDescriptor{ + const module = c.wgpuDeviceCreateShaderModule(self.c, &c.WGPUShaderModuleDescriptor{ .label = "Shader", .nextInChain = @as( [*c]c.WGPUChainedStruct, @@ -751,7 +751,7 @@ pub const Device = struct { } pub fn createPipelineLayout(self: Device, bind_group_layouts: BindGroupLayouts) !c.WGPUPipelineLayout { - var layout = c.wgpuDeviceCreatePipelineLayout(self.c, &c.WGPUPipelineLayoutDescriptor{ + const layout = c.wgpuDeviceCreatePipelineLayout(self.c, &c.WGPUPipelineLayoutDescriptor{ .label = "Pipeline Layout", .bindGroupLayoutCount = 2, .bindGroupLayouts = @as([]const c.WGPUBindGroupLayout, &.{ @@ -767,7 +767,7 @@ pub const Device = struct { } pub fn createRenderPipeline(self: Device, layout: c.WGPUPipelineLayout, shader: c.WGPUShaderModule, surface_format: c.WGPUTextureFormat) !RenderPipeline { - var pipeline = c.wgpuDeviceCreateRenderPipeline(self.c, &c.WGPURenderPipelineDescriptor{ + const pipeline = c.wgpuDeviceCreateRenderPipeline(self.c, &c.WGPURenderPipelineDescriptor{ .nextInChain = null, .label = "Render Pipeline", .layout = layout, @@ -871,7 +871,7 @@ pub const Device = struct { var texFormat: c_uint = c.WGPUTextureFormat_RGBA8UnormSrgb; - var tex = c.wgpuDeviceCreateTexture(self.c, &c.WGPUTextureDescriptor{ + const tex = c.wgpuDeviceCreateTexture(self.c, &c.WGPUTextureDescriptor{ .nextInChain = null, .label = "Texture", .usage = c.WGPUTextureUsage_CopyDst | c.WGPUTextureUsage_TextureBinding, @@ -888,7 +888,7 @@ pub const Device = struct { .viewFormats = &texFormat, }) orelse return Error.UnableToCreateDeviceTexture; - var view = c.wgpuTextureCreateView(tex, &c.WGPUTextureViewDescriptor{ + const view = c.wgpuTextureCreateView(tex, &c.WGPUTextureViewDescriptor{ .nextInChain = null, .label = "Texture View", .format = texFormat, @@ -928,7 +928,7 @@ pub const Device = struct { }, ); - var texture = Texture{ + const texture = Texture{ .width = @intCast(image.width), .height = @intCast(image.height), .tex = tex, @@ -941,7 +941,7 @@ pub const Device = struct { pub fn createBlankTexture(self: Device, width: u32, height: u32) !Texture { var texFormat: c_uint = c.WGPUTextureFormat_RGBA8UnormSrgb; - var tex = c.wgpuDeviceCreateTexture(self.c, &c.WGPUTextureDescriptor{ + const tex = c.wgpuDeviceCreateTexture(self.c, &c.WGPUTextureDescriptor{ .nextInChain = null, .label = "Texture", .usage = c.WGPUTextureUsage_CopyDst | c.WGPUTextureUsage_TextureBinding, @@ -958,7 +958,7 @@ pub const Device = struct { .viewFormats = &texFormat, }) orelse return Error.UnableToCreateDeviceTexture; - var view = c.wgpuTextureCreateView(tex, &c.WGPUTextureViewDescriptor{ + const view = c.wgpuTextureCreateView(tex, &c.WGPUTextureViewDescriptor{ .nextInChain = null, .label = "Texture View", .format = texFormat, @@ -970,7 +970,7 @@ pub const Device = struct { .aspect = c.WGPUTextureAspect_All, }) orelse return Error.UnableToCreateTextureView; - var texture = Texture{ + const texture = Texture{ .width = width, .height = height, .tex = tex, @@ -983,7 +983,7 @@ pub const Device = struct { pub fn createBuffer(self: Device, comptime contents_type: type, count: u64, comptime buffer_type: BufferType) !Buffer { const size: u64 = @intCast(@sizeOf(contents_type) * count); - var buffer = c.wgpuDeviceCreateBuffer(self.c, &c.WGPUBufferDescriptor{ + const buffer = c.wgpuDeviceCreateBuffer(self.c, &c.WGPUBufferDescriptor{ .nextInChain = null, .size = size, .mappedAtCreation = 0, //false @@ -1022,7 +1022,7 @@ pub const Buffer = struct { }; pub fn createInstance() !Instance { - var instance = c.wgpuCreateInstance(null); + const instance = c.wgpuCreateInstance(null); std.debug.print("got instance {*}\n", .{instance.?}); @@ -1050,7 +1050,7 @@ fn deviceLost(reason: c.WGPUDeviceLostReason, message: [*c]const u8, user_data: } pub fn handleDeviceCallback(status: c.WGPURequestDeviceStatus, device: c.WGPUDevice, message: [*c]const u8, userdata: ?*anyopaque) callconv(.C) void { - var device_ptr: *c.WGPUDevice = @ptrCast(@alignCast(userdata)); + const device_ptr: *c.WGPUDevice = @ptrCast(@alignCast(userdata)); if (status != c.WGPURequestDeviceStatus_Success) { std.debug.print("Failed to get wgpu adapter, status: {d}, message {s}", .{ status, std.mem.span(message) }); @@ -1061,7 +1061,7 @@ pub fn handleDeviceCallback(status: c.WGPURequestDeviceStatus, device: c.WGPUDev } pub fn handleAdapterCallback(status: c.WGPURequestAdapterStatus, adapter: c.WGPUAdapter, message: [*c]const u8, userdata: ?*anyopaque) callconv(.C) void { - var adapter_ptr: *c.WGPUAdapter = @ptrCast(@alignCast(userdata)); + const adapter_ptr: *c.WGPUAdapter = @ptrCast(@alignCast(userdata)); if (status != c.WGPURequestAdapterStatus_Success) { std.debug.print("Failed to get wgpu adapter, status: {d}, message {s}", .{ status, std.mem.span(message) }); @@ -1080,7 +1080,7 @@ pub fn updateProjectionMatrixBuffer(self: *Self, queue: Queue, window: *c.SDL_Wi w = 640; h = 480; - var mat = zmath.orthographicOffCenterLh(0, @floatFromInt(w), 0, @floatFromInt(h), 0, 1); + const mat = zmath.orthographicOffCenterLh(0, @floatFromInt(w), 0, @floatFromInt(h), 0, 1); queue.writeBuffer(self.projection_matrix_buffer, 0, zmath.Mat, &.{mat}); } diff --git a/game/iconv.zig b/game/iconv.zig index 5f89cfb..47bb5a7 100644 --- a/game/iconv.zig +++ b/game/iconv.zig @@ -17,9 +17,9 @@ const Context = extern struct { while (orig_bytes_left > 0) { //Convert as much of the data as we can - var ret = ziconv_convert(self, &orig_c_ptr, &dst_c_ptr, &orig_bytes_left, &dest_bytes_left); + const ret = ziconv_convert(self, &orig_c_ptr, &dst_c_ptr, &orig_bytes_left, &dest_bytes_left); if (ret == @as(usize, @bitCast(@as(isize, -1)))) { - var errno = std.c._errno().*; + const errno = std.c._errno().*; //errno 7 = E2BIG if (errno != 7) { diff --git a/game/ini.zig b/game/ini.zig index 5e9cc84..0a93007 100644 --- a/game/ini.zig +++ b/game/ini.zig @@ -11,7 +11,7 @@ pub fn Ini(comptime ReaderType: type, comptime max_line_size: comptime_int, comp const Self = @This(); pub fn init(reader: ReaderType) Self { - var self = Self{ + const self = Self{ .read_buf = undefined, .current_section = undefined, .current_section_len = 0, diff --git a/game/main.zig b/game/main.zig index f42b4a1..8976096 100644 --- a/game/main.zig +++ b/game/main.zig @@ -114,24 +114,24 @@ fn runGame() !void { var gfx: Gfx = try Gfx.init(window, state.config.window_scale); defer gfx.deinit(); - var imgui_context = c.igCreateContext(null); + const imgui_context = c.igCreateContext(null); defer c.igDestroyContext(imgui_context); c.igSetCurrentContext(imgui_context); - var imgui_io = c.igGetIO(); + const imgui_io = c.igGetIO(); //Enable keyboard nav imgui_io.*.ConfigFlags |= c.ImGuiConfigFlags_NavEnableKeyboard; //Create a font config - var font_config = c.ImFontConfig_ImFontConfig(); + const font_config = c.ImFontConfig_ImFontConfig(); //Mark that the atlas does *not* own the font data font_config.*.FontDataOwnedByAtlas = false; - var mincho_data = @embedFile("fonts/mincho.ttf"); + const mincho_data = @embedFile("fonts/mincho.ttf"); //Create the font from the mincho ttf - var mincho = c.ImFontAtlas_AddFontFromMemoryTTF(imgui_io.*.Fonts, @constCast(mincho_data.ptr), mincho_data.len, 15, font_config, c.ImFontAtlas_GetGlyphRangesJapanese(imgui_io.*.Fonts)); + const mincho = c.ImFontAtlas_AddFontFromMemoryTTF(imgui_io.*.Fonts, @constCast(mincho_data.ptr), mincho_data.len, 15, font_config, c.ImFontAtlas_GetGlyphRangesJapanese(imgui_io.*.Fonts)); if (!c.ImGui_ImplSDL2_InitForD3D(window)) { return error.UnableToInitSDL2ImGui; @@ -207,7 +207,7 @@ fn runGame() !void { try screen_stack.load(&Screen.MainMenu.MainMenu, gfx, &state); while (state.is_running) { - var current_counter = c.SDL_GetPerformanceCounter(); + const current_counter = c.SDL_GetPerformanceCounter(); state.counter_curr = current_counter; const delta_time: f64 = @as(f64, @floatFromInt((current_counter - delta_start))) / freq; state.delta_time = delta_time; @@ -234,7 +234,7 @@ fn runGame() !void { }, c.SDL_TEXTINPUT => { //Get the end of the arr - var end = std.mem.indexOf(u8, &ev.text.text, &.{0}) orelse 32; + const end = std.mem.indexOf(u8, &ev.text.text, &.{0}) orelse 32; //Send the event to the screen if (screen.char) |char| { @@ -270,7 +270,7 @@ fn runGame() !void { //Get the current texture view for the swap chain // var next_texture = try gfx.swap_chain.?.getCurrentSwapChainTexture(); - var surface_texture = gfx.surface.getCurrentTexture(); + const surface_texture = gfx.surface.getCurrentTexture(); defer c.wgpuTextureRelease(surface_texture.texture); switch (surface_texture.status) { c.WGPUSurfaceGetCurrentTextureStatus_Success => {}, @@ -301,7 +301,7 @@ fn runGame() !void { .label = "Command Encoder", }); - var next_texture = c.wgpuTextureCreateView(surface_texture.texture, null).?; + const next_texture = c.wgpuTextureCreateView(surface_texture.texture, null).?; defer c.wgpuTextureViewRelease(next_texture); //Begin the render pass @@ -328,7 +328,7 @@ fn runGame() !void { render_pass_encoder.end(); - var command_buffer = try command_encoder.finish(&c.WGPUCommandBufferDescriptor{ + const command_buffer = try command_encoder.finish(&c.WGPUCommandBufferDescriptor{ .label = "Command buffer", .nextInChain = null, }); @@ -362,7 +362,7 @@ pub fn main() !void { if (err == std.mem.Allocator.Error.OutOfMemory) { _ = c.SDL_ShowSimpleMessageBox(0, "Unhandled Error!", error_str ++ "OutOfMemory", null); } else { - var fmt = try std.mem.concatWithSentinel(std.heap.c_allocator, u8, &.{ error_str, @errorName(err) }, 0); + const fmt = try std.mem.concatWithSentinel(std.heap.c_allocator, u8, &.{ error_str, @errorName(err) }, 0); defer std.heap.c_allocator.free(fmt); _ = c.SDL_ShowSimpleMessageBox(0, "Unhandled Error!", fmt, null); diff --git a/game/music.zig b/game/music.zig index 9d6802c..4171709 100644 --- a/game/music.zig +++ b/game/music.zig @@ -77,10 +77,10 @@ pub fn readFromFile(allocator: std.mem.Allocator, path: std.fs.Dir, file: std.fs errdefer if (fumen_file_name) |fumen_file_name_ptr| allocator.free(fumen_file_name_ptr); errdefer if (ranking_file_name) |ranking_file_name_ptr| allocator.free(ranking_file_name_ptr); - var orig_file = try file.readToEndAlloc(allocator, 10000); + const orig_file = try file.readToEndAlloc(allocator, 10000); defer allocator.free(orig_file); - var read_file = try iconv.convert(allocator, orig_file); + const read_file = try iconv.convert(allocator, orig_file); defer allocator.free(read_file); var iter = std.mem.split(u8, read_file, "\n"); @@ -141,7 +141,7 @@ pub fn readFromFile(allocator: std.mem.Allocator, path: std.fs.Dir, file: std.fs self.folder_path = try path.realpathAlloc(allocator, "."); errdefer allocator.free(self.folder_path); - var fumen_path = try path.realpathAlloc(allocator, self.fumen_file_name); + const fumen_path = try path.realpathAlloc(allocator, self.fumen_file_name); defer allocator.free(fumen_path); var fumen_file = try std.fs.openFileAbsolute(fumen_path, .{}); @@ -184,7 +184,7 @@ pub fn readUTypingList(allocator: std.mem.Allocator) ![]Self { defer allocator.free(line); //Normalize, aka remove \r and change `\` to `/` - var normalized = try std.mem.replaceOwned(u8, allocator, if (line[line.len - 1] == '\r') line[0 .. line.len - 1] else line, &.{'\\'}, &.{'/'}); + const normalized = try std.mem.replaceOwned(u8, allocator, if (line[line.len - 1] == '\r') line[0 .. line.len - 1] else line, &.{'\\'}, &.{'/'}); defer allocator.free(normalized); var music_file = try std.fs.cwd().openFile(normalized, .{}); @@ -193,7 +193,7 @@ pub fn readUTypingList(allocator: std.mem.Allocator) ![]Self { var music_dir = try std.fs.cwd().openDir(std.fs.path.dirname(normalized) orelse "", .{}); defer music_dir.close(); - var music = try readFromFile(allocator, music_dir, music_file, i); + const music = try readFromFile(allocator, music_dir, music_file, i); try music_list.append(music); i += 1; @@ -262,8 +262,8 @@ pub fn draw( const width = (try render_state.fontstash.textBounds(self.artist, Fontstash.Normal)).x2; var x = (Screen.display_width - 150) - width * 2 / 3; - var width_l = x - (title_x + title_width); - var width_r = (num_x - width_num) - (x + width); + const width_l = x - (title_x + title_width); + const width_r = (num_x - width_num) - (x + width); if (width_l <= 20 or width_r <= 20) { x += (width_r - width_l) / 4; diff --git a/game/renderer.zig b/game/renderer.zig index 71d5a61..c6932fd 100644 --- a/game/renderer.zig +++ b/game/renderer.zig @@ -281,7 +281,7 @@ pub fn reserve(self: *Self, vtx_count: u64, idx_count: u64) !ReservedData { //Assert that we have started recording std.debug.assert(self.started); - var recording_buf: RenderBuffer = self.recording_buffer.?; + const recording_buf: RenderBuffer = self.recording_buffer.?; //If the vertex count or index count would put us over the limit of the current recording buffer if (recording_buf.used_vtx + vtx_count > vtx_per_buf or recording_buf.used_idx + idx_count > idx_per_buf) { diff --git a/game/screens/gameplay.zig b/game/screens/gameplay.zig index 8836ff3..7dcfabb 100644 --- a/game/screens/gameplay.zig +++ b/game/screens/gameplay.zig @@ -139,7 +139,7 @@ const GaugeData = struct { const icount: isize = @intCast(count); const iclear_count: isize = @intCast(self.clear_count); - var lost: isize = icount - iclear_count; + const lost: isize = icount - iclear_count; var t = lost - self.gauge_last_lost; self.gauge_last_lost = lost; while (t > 0) : (t -= 1) { @@ -284,7 +284,7 @@ pub fn initScreen(self: *Screen, allocator: std.mem.Allocator, gfx: Gfx) anyerro _ = gfx; self.allocator = allocator; - var data = try allocator.create(GameplayData); + const data = try allocator.create(GameplayData); errdefer allocator.destroy(data); data.* = .{ @@ -307,11 +307,11 @@ pub fn initScreen(self: *Screen, allocator: std.mem.Allocator, gfx: Gfx) anyerro var dir = try std.fs.openDirAbsolute(data.music.fumen.fumen_folder, .{}); defer dir.close(); //Get the real path of the audio file - var full_audio_path = try dir.realpathAlloc(allocator, data.music.fumen.audio_path); + const full_audio_path = try dir.realpathAlloc(allocator, data.music.fumen.audio_path); defer allocator.free(full_audio_path); //Create a sentinel-ending array for the path - var audio_pathZ = try allocator.dupeZ(u8, full_audio_path); + const audio_pathZ = try allocator.dupeZ(u8, full_audio_path); defer allocator.free(audio_pathZ); std.debug.print("Loading song file {s}\n", .{audio_pathZ}); self.state.audio_tracker.music = try bass.createFileStream( @@ -330,7 +330,7 @@ pub fn initScreen(self: *Screen, allocator: std.mem.Allocator, gfx: Gfx) anyerro } pub fn deinitScreen(self: *Screen) void { - var data = self.getData(GameplayData); + const data = self.getData(GameplayData); //Stop the song self.state.audio_tracker.music.?.stop() catch |err| { @@ -402,13 +402,13 @@ pub fn char(self: *Screen, typed_char: []const u8) anyerror!void { // std.debug.print("user wrote {s}\n", .{typed_char}); - var current_time = try self.state.audio_tracker.music.?.getSecondPosition() - data.audio_offset; + const current_time = try self.state.audio_tracker.music.?.getSecondPosition() - data.audio_offset; var current_note: *Fumen.Lyric = &data.music.fumen.lyrics[data.active_note]; var next_note: ?*Fumen.Lyric = if (data.active_note + 1 == data.music.fumen.lyrics.len) null else &data.music.fumen.lyrics[data.active_note + 1]; var hiragana_to_type = current_note.text[data.typed_hiragana.len..]; - var hiragana_to_type_next: ?[:0]const u8 = if (next_note != null) next_note.?.text else &.{}; + const hiragana_to_type_next: ?[:0]const u8 = if (next_note != null) next_note.?.text else &.{}; const Match = struct { //The matched conversion @@ -420,7 +420,7 @@ pub fn char(self: *Screen, typed_char: []const u8) anyerror!void { //The found match for the current note var matched: ?Match = null; //The found match for the next hiragana (only for the current note, check matched_next for the next note) - var next_hiragana_matched: ?Match = null; + const next_hiragana_matched: ?Match = null; //The found match for the next note var matched_next: ?Match = null; @@ -442,7 +442,7 @@ pub fn char(self: *Screen, typed_char: []const u8) anyerror!void { //If the conversion starts with the romaji we have already typed, if (std.mem.startsWith(u8, conversion.romaji, data.typed_romaji)) { //Get the romaji we have left to type - var romaji_to_type = conversion.romaji[data.typed_romaji.len..]; + const romaji_to_type = conversion.romaji[data.typed_romaji.len..]; //If the romaji we need to type starts with the characters the user has just typed if (std.mem.startsWith(u8, romaji_to_type, typed_char)) { @@ -482,7 +482,7 @@ pub fn char(self: *Screen, typed_char: []const u8) anyerror!void { if (matched) |matched_for_current_note| { if (current_note.pending_hit_result == null) { //Get the offset the user hit the note at, used to determine the hit result of the note - var delta = current_time - current_note.time; + const delta = current_time - current_note.time; //Get the hit result, using the absolute value var hit_result = deltaToHitResult(@abs(delta)); @@ -600,10 +600,10 @@ pub fn char(self: *Screen, typed_char: []const u8) anyerror!void { if (matched_next) |matched_for_next_note| { //Get the offset the user hit the note at, used to determine the hit result of the note - var delta = current_time - next_note.?.time; + const delta = current_time - next_note.?.time; //Get the hit result, using the absolute value - var hit_result = deltaToHitResult(@abs(delta)); + const hit_result = deltaToHitResult(@abs(delta)); // std.debug.print("next \"{s}\"/{d}/{any}\n", .{ matched_for_next_note.conversion.romaji, delta, hit_result }); @@ -655,7 +655,7 @@ fn handleTypedRomaji(data: *GameplayData, typed: []const u8) !void { fn handleNoteFirstChar(data: *GameplayData, note: *Fumen.Lyric) void { //Get the extra score from having a combo, capped to the `combo_score_max` value - var score_combo = @min(combo_score * data.score.combo, combo_score_max); + const score_combo = @min(combo_score * data.score.combo, combo_score_max); //Add the accuracy the user has reached to the accuracy score, ignore bonus score with a `poor` hit data.score.accuracy_score += (if (note.pending_hit_result.? == .poor) 0 else score_combo) + hitResultToAccuracyScore(note.pending_hit_result.?); @@ -776,7 +776,7 @@ pub fn keyDown(self: *Screen, key: c.SDL_Keysym) anyerror!void { data.music.fumen.deinit(); //Get the filename of the source file - var source_filename = try std.fmt.allocPrint(data.music.allocator, "{s}_src.txt", .{std.fs.path.stem(data.music.fumen_file_name)}); + const source_filename = try std.fmt.allocPrint(data.music.allocator, "{s}_src.txt", .{std.fs.path.stem(data.music.fumen_file_name)}); defer data.music.allocator.free(source_filename); //Open the output dir @@ -868,10 +868,10 @@ pub fn renderScreen(self: *Screen, render_state: RenderState) anyerror!void { if (data.scrub_frame_counter > 20) { var mouse_x_i: c_int = 0; var mouse_y: c_int = 0; - var mouse_buttons = c.SDL_GetMouseState(&mouse_x_i, &mouse_y); + const mouse_buttons = c.SDL_GetMouseState(&mouse_x_i, &mouse_y); var mouse_x: f32 = @floatFromInt(mouse_x_i); - var max_x = render_state.gfx.scale * 640.0; + const max_x = render_state.gfx.scale * 640.0; if (mouse_x < 0) { mouse_x = 0; @@ -882,7 +882,7 @@ pub fn renderScreen(self: *Screen, render_state: RenderState) anyerror!void { } if ((mouse_buttons & c.SDL_BUTTON(3)) != 0 and mouse_x != data.last_mouse_x) { - var byte: u64 = @intFromFloat(@as(f64, @floatFromInt(try self.state.audio_tracker.music.?.getLength(.byte))) * (mouse_x / max_x)); + const byte: u64 = @intFromFloat(@as(f64, @floatFromInt(try self.state.audio_tracker.music.?.getLength(.byte))) * (mouse_x / max_x)); try self.state.audio_tracker.music.?.setPosition(byte, .byte, .{}); } @@ -1119,9 +1119,9 @@ fn checkForMissedNotes(data: *GameplayData) void { } //The current note the user is playing - var current_note = data.music.fumen.lyrics[data.active_note]; + const current_note = data.music.fumen.lyrics[data.active_note]; //The next note the user *could* hit - var next_note: ?Fumen.Lyric = if (data.active_note < data.music.fumen.lyrics.len - 1) data.music.fumen.lyrics[data.active_note + 1] else null; + const next_note: ?Fumen.Lyric = if (data.active_note < data.music.fumen.lyrics.len - 1) data.music.fumen.lyrics[data.active_note + 1] else null; //If the user should miss the current note if (missCheck(data, current_note, next_note)) { @@ -1227,8 +1227,8 @@ const stat_gauge_width = 400; const stat_gauge_height = 40; fn drawStatGauge(render_state: Screen.RenderState, data: *GameplayData) !void { - var y: f32 = stat_gauge_y; - var single_bar_height: f32 = stat_gauge_height / 4; + const y: f32 = stat_gauge_y; + const single_bar_height: f32 = stat_gauge_height / 4; for (&data.gauge_data.draw_x, &data.gauge_data.draw_v, &data.gauge_data.lengths) |*x, *velocity, length| { //Add a little bit of velocity, depending on the amount we need to change @@ -1278,9 +1278,9 @@ fn drawBar(render_state: Screen.RenderState, val: f32, y: f32, h: f32, color: Gf //Set opacity to 7/8 display_color[3] = 0.875; - var rounded_val = @floor(val); + const rounded_val = @floor(val); - var val_fractional = val - rounded_val; + const val_fractional = val - rounded_val; try render_state.renderer.reserveSolidBox(.{ stat_gauge_x - rounded_val, y }, .{ rounded_val, h }, display_color); //Multiply opacity by the fractional part of the number @@ -1299,7 +1299,7 @@ fn drawLight(render_state: Screen.RenderState, light: f32, y: f32, h: f32, color display_light = @min(1, display_light); //The amount to change the height of the light as it fades out - var delta_height = @round(h * 0.5 * (1 - display_light) * (1 - display_light)) * 4; + const delta_height = @round(h * 0.5 * (1 - display_light) * (1 - display_light)) * 4; try render_state.renderer.reserveSolidBox(.{ stat_gauge_x - stat_gauge_width, y + delta_height / 2 }, .{ stat_gauge_width, h - delta_height }, display_color); } @@ -1312,7 +1312,7 @@ fn drawScoreUi(render_state: Screen.RenderState, data: *GameplayData) !void { //Draw the score var buf: [8]u8 = .{ 0, 0, 0, 0, 0, 0, 0, 0 }; - var used = std.fmt.formatIntBuf( + const used = std.fmt.formatIntBuf( &buf, @as(u64, @intFromFloat(@ceil(data.draw_score))), 10, @@ -1345,7 +1345,7 @@ fn drawScoreUi(render_state: Screen.RenderState, data: *GameplayData) !void { }; //Get the accuracy timer in seconds, note we divide in 2 stages to help remove floating point inaccuracies - var accuracy_text_timer = @as(f32, @floatFromInt(data.animation_timers.accuracy_text.read() / std.time.ns_per_ms)) / std.time.ms_per_s; + const accuracy_text_timer = @as(f32, @floatFromInt(data.animation_timers.accuracy_text.read() / std.time.ns_per_ms)) / std.time.ms_per_s; var accuracy_text_offset: f32 = 0; if (accuracy_text_timer < 0.05) { @@ -1363,7 +1363,7 @@ fn drawScoreUi(render_state: Screen.RenderState, data: *GameplayData) !void { state.color[3] = @max(0, 1.0 - time_since_start_fade * 10); } - var metrics = render_state.fontstash.verticalMetrics(state); + const metrics = render_state.fontstash.verticalMetrics(state); _ = try render_state.fontstash.drawText( .{ accuracy_x, accuracy_y + metrics.line_height + accuracy_text_offset }, data.accuracy_text, @@ -1371,7 +1371,7 @@ fn drawScoreUi(render_state: Screen.RenderState, data: *GameplayData) !void { ); if (data.score.combo >= 10) { - var digits = std.fmt.count("{d}", .{data.score.combo}); + const digits = std.fmt.count("{d}", .{data.score.combo}); _ = std.fmt.formatIntBuf( &buf, @@ -1400,11 +1400,11 @@ fn drawScoreUi(render_state: Screen.RenderState, data: *GameplayData) !void { fn drawGameplayLyrics(render_state: Screen.RenderState, data: *GameplayData) !void { //Draw all the beat lines for (0..data.music.fumen.beat_lines.len) |i| { - var beat_line = data.music.fumen.beat_lines[i]; + const beat_line = data.music.fumen.beat_lines[i]; - var time_diff = data.current_time - beat_line.time; - var posX = getDrawPosX(time_diff); - var posY = getDrawPosY(posX); + const time_diff = data.current_time - beat_line.time; + const posX = getDrawPosX(time_diff); + const posY = getDrawPosY(posX); if (posX < 0) continue; if (posX > 640) break; @@ -1421,13 +1421,13 @@ fn drawGameplayLyrics(render_state: Screen.RenderState, data: *GameplayData) !vo //Draw all the typing cutoffs for (0..data.music.fumen.lyric_cutoffs.len) |j| { - var i = data.music.fumen.lyric_cutoffs.len - 1 - j; + const i = data.music.fumen.lyric_cutoffs.len - 1 - j; - var lyric_cutoff = data.music.fumen.lyric_cutoffs[i]; - var time_diff = data.current_time - lyric_cutoff.time; + const lyric_cutoff = data.music.fumen.lyric_cutoffs[i]; + const time_diff = data.current_time - lyric_cutoff.time; - var posX = getDrawPosX(time_diff); - var posY = getDrawPosY(posX); + const posX = getDrawPosX(time_diff); + const posY = getDrawPosY(posX); if (posX < 0 - circle_r) break; if (posX > 640 + circle_r) continue; @@ -1463,13 +1463,13 @@ fn drawGameplayLyrics(render_state: Screen.RenderState, data: *GameplayData) !vo //Draw all the lyrics for (0..data.music.fumen.lyrics.len) |j| { - var i = data.music.fumen.lyrics.len - 1 - j; + const i = data.music.fumen.lyrics.len - 1 - j; var lyric = data.music.fumen.lyrics[i]; - var time_diff = data.current_time - lyric.time; + const time_diff = data.current_time - lyric.time; - var posX = getDrawPosX(time_diff); - var posY = getDrawPosY(posX); + const posX = getDrawPosX(time_diff); + const posY = getDrawPosY(posX); //If the note is fully off the left side of the screen, break out, dont try to render any more notes if (posX < 0 - circle_r) break; diff --git a/game/screens/song_select.zig b/game/screens/song_select.zig index 14e4ea0..32e4447 100644 --- a/game/screens/song_select.zig +++ b/game/screens/song_select.zig @@ -35,7 +35,7 @@ pub fn initScreen(self: *Screen, allocator: std.mem.Allocator, gfx: Gfx) anyerro _ = gfx; self.allocator = allocator; - var data = try allocator.create(SongSelectData); + const data = try allocator.create(SongSelectData); data.* = .{ .draw_info = DrawInfo{ .ranking_flag = false, @@ -57,7 +57,7 @@ pub fn initScreen(self: *Screen, allocator: std.mem.Allocator, gfx: Gfx) anyerro } pub fn deinitScreen(self: *Screen) void { - var data = self.getData(SongSelectData); + const data = self.getData(SongSelectData); self.allocator.destroy(data); } @@ -213,10 +213,10 @@ const DrawInfo = struct { pub fn step(self: *DrawInfo) void { for (&self.add_height, 0..) |*height, i| { - var h: f32 = + const h: f32 = if (i == add_height_middle) blk: { - var h: f32 = if (self.ranking_flag) + const h: f32 = if (self.ranking_flag) h_ranking else if (self.ranking_pos == 0) h_ranking1 @@ -742,7 +742,7 @@ pub fn renderScreen(self: *Screen, render_state: RenderState) anyerror!void { { var state = Fontstash.Normal; - var sign: bool = blk: { + const sign: bool = blk: { if (data.challenge_info.key > 8) { state.color = .{ 1, 0.125, 0, 1 }; break :blk true; @@ -764,7 +764,7 @@ pub fn renderScreen(self: *Screen, render_state: RenderState) anyerror!void { .draw = true, .draw_position = Gfx.Vector2{ 330, Screen.display_height - 20 } * @as(Gfx.Vector2, @splat(render_state.gfx.scale)), }; - var writer = try render_state.fontstash.context.writer(&context); + const writer = try render_state.fontstash.context.writer(&context); if (data.challenge_info.key == 0) { context.state.color = .{ 0.25, 0.25, 0.25, 1 }; @@ -836,7 +836,7 @@ pub fn renderScreen(self: *Screen, render_state: RenderState) anyerror!void { .draw = true, .draw_position = Gfx.Vector2{ 470, Screen.display_height - 20 } * @as(Gfx.Vector2, @splat(render_state.gfx.scale)), }; - var writer = try render_state.fontstash.context.writer(&context); + const writer = try render_state.fontstash.context.writer(&context); try std.fmt.format(writer, "[ Offset: {d} ]", .{data.challenge_info.audio_offset}); } @@ -859,9 +859,9 @@ pub fn renderScreen(self: *Screen, render_state: RenderState) anyerror!void { } fn drawMainRanking(render_state: Screen.RenderState, music: Music, ranking_pos: isize, pos: Gfx.Vector2, height: f32) !void { - var yMin = @max(pos[1], 0); + const yMin = @max(pos[1], 0); _ = yMin; - var yMax = @min(pos[1] + height, 360); + const yMax = @min(pos[1] + height, 360); _ = yMax; // TODO: debug why scissors are borked :( diff --git a/game/shader.wgsl b/game/shader.wgsl index fdc1ec0..f67e1d8 100644 --- a/game/shader.wgsl +++ b/game/shader.wgsl @@ -63,4 +63,4 @@ fn toLinear(sRGB: vec4) -> vec4 var lower: vec4 = sRGB/vec4(12.92); return mix(higher, lower, cutoff); -} \ No newline at end of file +} diff --git a/image_processor.zig b/image_processor.zig index 74970ba..f11259a 100644 --- a/image_processor.zig +++ b/image_processor.zig @@ -19,7 +19,7 @@ pub fn main() !void { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; const allocator = gpa.allocator(); - var args = try std.process.argsAlloc(allocator); + const args = try std.process.argsAlloc(allocator); defer std.process.argsFree(allocator, args); try processImages(allocator, args[1]); @@ -40,7 +40,7 @@ pub fn processImages(allocator: std.mem.Allocator, root_path: []const u8) !void const content_path = try std.mem.concat(allocator, u8, &.{ root_path, "content/" }); defer allocator.free(content_path); - var png_files = try find_png_files(allocator, content_path); + const png_files = try find_png_files(allocator, content_path); defer allocator.free(png_files); const atlas_gen_folder = try std.mem.concat(allocator, u8, &.{ root_path, "zig-cache/atlas-gen/" }); @@ -66,10 +66,10 @@ pub fn processImages(allocator: std.mem.Allocator, root_path: []const u8) !void defer file.close(); //Get the length of the PNG file - var len = try file.getEndPos(); + const len = try file.getEndPos(); //allocate a buffer for the file - var buf = try allocator.alloc(u8, len); + const buf = try allocator.alloc(u8, len); defer allocator.free(buf); //Read the whole file @@ -88,7 +88,7 @@ pub fn processImages(allocator: std.mem.Allocator, root_path: []const u8) !void hashes[i] = (try hash_hex.toOwnedSlice())[0..8]; //Try to open the file which may contain the hash - var cache_file = cache_dir.openFile(hashes[i], .{}); + const cache_file = cache_dir.openFile(hashes[i], .{}); //If the file failed to open, then we need to rebuild var cach_file_val = cache_file catch { @@ -115,10 +115,10 @@ pub fn processImages(allocator: std.mem.Allocator, root_path: []const u8) !void var path_without_content = path_without_root["content/".len..]; - var name = path_without_content[0 .. path_without_content.len - 4]; + const name = path_without_content[0 .. path_without_content.len - 4]; //Load the file - var image = try img.png.load(&image_stream, allocator, .{ .temp_allocator = allocator }); + const image = try img.png.load(&image_stream, allocator, .{ .temp_allocator = allocator }); try images.append(.{ .width = @as(u32, @intCast(image.width)) + 2, .height = @as(u32, @intCast(image.height)) + 2, @@ -136,7 +136,7 @@ pub fn processImages(allocator: std.mem.Allocator, root_path: []const u8) !void const bin_size = 4096; - var packed_images = try packImages(allocator, Image, images.items, .{ .w = bin_size, .h = bin_size }); + const packed_images = try packImages(allocator, Image, images.items, .{ .w = bin_size, .h = bin_size }); defer allocator.free(packed_images); var final_image = try img.Image.create(allocator, bin_size, bin_size, .rgba32); @@ -162,7 +162,7 @@ pub fn processImages(allocator: std.mem.Allocator, root_path: []const u8) !void .rgb24 => |pix| { for (0..(packed_image.image.width - 2)) |x| { for (0..(packed_image.image.height - 2)) |y| { - var pixel = pix[y * (packed_image.image.width - 2) + x]; + const pixel = pix[y * (packed_image.image.width - 2) + x]; final_image.pixels.rgba32[(y + 1 + packed_image.pos.y) * final_image.width + packed_image.pos.x + 1 + x] = .{ .r = pixel.r, .g = pixel.g, .b = pixel.b, .a = 255 }; } } @@ -201,7 +201,7 @@ pub fn processImages(allocator: std.mem.Allocator, root_path: []const u8) !void try output_atlas_info.writeAll(try std.fmt.allocPrint(allocator, "pub const atlas_width: comptime_float = {d};\npub const atlas_height: comptime_float = {d};\n\n", .{ bin_size, bin_size })); for (packed_images) |packed_image| { - var image_rect = try std.fmt.allocPrint(allocator, + const image_rect = try std.fmt.allocPrint(allocator, \\pub const {s}: Rectangle = .{{.x = {d}, .y = {d}, .w = {d}, .h = {d}}}; , .{ packed_image.image.name, @@ -221,25 +221,27 @@ pub fn processImages(allocator: std.mem.Allocator, root_path: []const u8) !void fn find_png_files(allocator: std.mem.Allocator, search_path: []const u8) ![]const []const u8 { var png_list = std.ArrayList([]const u8).init(allocator); - var dir = try std.fs.openIterableDirAbsolute(search_path, .{}); + var dir = try std.fs.openDirAbsolute(search_path, .{ + .iterate = true, + }); defer dir.close(); - var walker: std.fs.IterableDir.Walker = try dir.walk(allocator); + var walker: std.fs.Dir.Walker = try dir.walk(allocator); defer walker.deinit(); - var itr_next: ?std.fs.IterableDir.Walker.WalkerEntry = try walker.next(); + var itr_next: ?std.fs.Dir.Walker.WalkerEntry = try walker.next(); while (itr_next != null) { - var next: std.fs.IterableDir.Walker.WalkerEntry = itr_next.?; + const next: std.fs.Dir.Walker.WalkerEntry = itr_next.?; //if the file is a png file if (std.mem.endsWith(u8, next.path, ".png")) { var item = try allocator.alloc(u8, next.path.len + search_path.len); //copy the root first - std.mem.copy(u8, item, search_path); + @memcpy(item[0..search_path.len], search_path); //copy the filepath next - std.mem.copy(u8, item[search_path.len..], next.path); + @memcpy(item[search_path.len..], next.path); try png_list.append(item); } @@ -286,8 +288,8 @@ pub fn packImages(allocator: std.mem.Allocator, comptime T: type, images: []cons //Iterate backwards through all the items for (0..empty_spaces.items.len) |j| { - var i = empty_spaces.items.len - 1 - j; - var empty_space: EmptySpace = empty_spaces.items[i]; + const i = empty_spaces.items.len - 1 - j; + const empty_space: EmptySpace = empty_spaces.items[i]; //If the empty space can fit the image if (empty_space.w >= image.width and empty_space.h >= image.height) { @@ -299,7 +301,7 @@ pub fn packImages(allocator: std.mem.Allocator, comptime T: type, images: []cons return error.UnableToFitRect; } - var empty_space: EmptySpace = empty_spaces.items[candidate_space_index.?]; + const empty_space: EmptySpace = empty_spaces.items[candidate_space_index.?]; // std.debug.print("space: {d}/{d}/{d}/{d}\n", .{ empty_space.x, empty_space.y, empty_space.w, empty_space.h }); try packed_images.append(.{ diff --git a/libs/cimgui b/libs/cimgui index 50a9a8d..a8d914b 160000 --- a/libs/cimgui +++ b/libs/cimgui @@ -1 +1 @@ -Subproject commit 50a9a8d596e071b35485e769e8a25d30de78bbe7 +Subproject commit a8d914b1befdea87e463077a96c5a7860892c48a diff --git a/libs/zig-bass b/libs/zig-bass index 8fec3a0..f6ada86 160000 --- a/libs/zig-bass +++ b/libs/zig-bass @@ -1 +1 @@ -Subproject commit 8fec3a02af4623e1751a8e952ad99cc1cb57c4f2 +Subproject commit f6ada863a25d78d9d3b13d1807ae1c79b97ba9cd diff --git a/libs/zmath/build.zig b/libs/zmath/build.zig index 96847c0..62df329 100644 --- a/libs/zmath/build.zig +++ b/libs/zmath/build.zig @@ -32,7 +32,7 @@ pub fn package( const zmath_options = step.createModule(); - const zmath = b.createModule(.{ + const zmath = b.addModule("zmath", .{ .source_file = .{ .path = thisDir() ++ "/src/main.zig" }, .dependencies = &.{ .{ .name = "zmath_options", .module = zmath_options }, @@ -50,6 +50,10 @@ pub fn build(b: *std.Build) void { const optimize = b.standardOptimizeOption(.{}); const target = b.standardTargetOptions(.{}); + _ = package(b, target, optimize, .{ .options = .{ + .enable_cross_platform_determinism = b.option(bool, "enable_cross_platform_determinism", "Whether to enable cross-platform determinism.") orelse true, + } }); + const test_step = b.step("test", "Run zmath tests"); test_step.dependOn(runTests(b, optimize, target)); diff --git a/libs/zmath/build.zig.zon b/libs/zmath/build.zig.zon new file mode 100644 index 0000000..2b53853 --- /dev/null +++ b/libs/zmath/build.zig.zon @@ -0,0 +1,5 @@ +.{ + .name = "zmath", + .version = "0.9.6", + .paths = .{""}, +} diff --git a/libs/zmath/src/zmath.zig b/libs/zmath/src/zmath.zig index c08d986..61f8e62 100644 --- a/libs/zmath/src/zmath.zig +++ b/libs/zmath/src/zmath.zig @@ -341,7 +341,7 @@ pub inline fn splatInt(comptime T: type, value: u32) T { pub fn load(mem: []const f32, comptime T: type, comptime len: u32) T { var v = splat(T, 0.0); - comptime var loop_len = if (len == 0) veclen(T) else len; + const loop_len = if (len == 0) veclen(T) else len; comptime var i: u32 = 0; inline while (i < loop_len) : (i += 1) { v[i] = mem[i]; @@ -368,7 +368,7 @@ test "zmath.load" { pub fn store(mem: []f32, v: anytype, comptime len: u32) void { const T = @TypeOf(v); - comptime var loop_len = if (len == 0) veclen(T) else len; + const loop_len = if (len == 0) veclen(T) else len; comptime var i: u32 = 0; inline while (i < loop_len) : (i += 1) { mem[i] = v[i]; @@ -474,7 +474,7 @@ pub fn all(vb: anytype, comptime len: u32) bool { if (len > veclen(T)) { @compileError("zmath.all(): 'len' is greater than vector len of type " ++ @typeName(T)); } - comptime var loop_len = if (len == 0) veclen(T) else len; + const loop_len = if (len == 0) veclen(T) else len; const ab: [veclen(T)]bool = vb; comptime var i: u32 = 0; var result = true; @@ -501,7 +501,7 @@ pub fn any(vb: anytype, comptime len: u32) bool { if (len > veclen(T)) { @compileError("zmath.any(): 'len' is greater than vector len of type " ++ @typeName(T)); } - comptime var loop_len = if (len == 0) veclen(T) else len; + const loop_len = if (len == 0) veclen(T) else len; const ab: [veclen(T)]bool = vb; comptime var i: u32 = 0; var result = false; @@ -924,7 +924,7 @@ test "zmath.round" { try expect(all(isNan(round(splat(F32x4, -math.snan(f32)))), 0)); } { - var v = round(f32x16(1.1, -1.1, -1.5, 1.5, 2.1, 2.8, 2.9, 4.1, 5.8, 6.1, 7.9, 8.9, 10.1, 11.2, 12.7, 13.1)); + const v = round(f32x16(1.1, -1.1, -1.5, 1.5, 2.1, 2.8, 2.9, 4.1, 5.8, 6.1, 7.9, 8.9, 10.1, 11.2, 12.7, 13.1)); try expect(approxEqAbs( v, f32x16(1.0, -1.0, -2.0, 2.0, 2.0, 3.0, 3.0, 4.0, 6.0, 6.0, 8.0, 9.0, 10.0, 11.0, 13.0, 13.0), @@ -1018,7 +1018,7 @@ test "zmath.trunc" { try expect(all(isNan(trunc(splat(F32x4, -math.snan(f32)))), 0)); } { - var v = trunc(f32x16(1.1, -1.1, -1.5, 1.5, 2.1, 2.8, 2.9, 4.1, 5.8, 6.1, 7.9, 8.9, 10.1, 11.2, 12.7, 13.1)); + const v = trunc(f32x16(1.1, -1.1, -1.5, 1.5, 2.1, 2.8, 2.9, 4.1, 5.8, 6.1, 7.9, 8.9, 10.1, 11.2, 12.7, 13.1)); try expect(approxEqAbs( v, f32x16(1.0, -1.0, -1.0, 1.0, 2.0, 2.0, 2.0, 4.0, 5.0, 6.0, 7.0, 8.0, 10.0, 11.0, 12.0, 13.0), @@ -1110,7 +1110,7 @@ test "zmath.floor" { try expect(all(isNan(floor(splat(F32x4, -math.snan(f32)))), 0)); } { - var v = floor(f32x16(1.1, -1.1, -1.5, 1.5, 2.1, 2.8, 2.9, 4.1, 5.8, 6.1, 7.9, 8.9, 10.1, 11.2, 12.7, 13.1)); + const v = floor(f32x16(1.1, -1.1, -1.5, 1.5, 2.1, 2.8, 2.9, 4.1, 5.8, 6.1, 7.9, 8.9, 10.1, 11.2, 12.7, 13.1)); try expect(approxEqAbs( v, f32x16(1.0, -2.0, -2.0, 1.0, 2.0, 2.0, 2.0, 4.0, 5.0, 6.0, 7.0, 8.0, 10.0, 11.0, 12.0, 13.0), @@ -1202,7 +1202,7 @@ test "zmath.ceil" { try expect(all(isNan(ceil(splat(F32x4, -math.snan(f32)))), 0)); } { - var v = ceil(f32x16(1.1, -1.1, -1.5, 1.5, 2.1, 2.8, 2.9, 4.1, 5.8, 6.1, 7.9, 8.9, 10.1, 11.2, 12.7, 13.1)); + const v = ceil(f32x16(1.1, -1.1, -1.5, 1.5, 2.1, 2.8, 2.9, 4.1, 5.8, 6.1, 7.9, 8.9, 10.1, 11.2, 12.7, 13.1)); try expect(approxEqAbs( v, f32x16(2.0, -1.0, -1.0, 2.0, 3.0, 3.0, 3.0, 5.0, 6.0, 7.0, 8.0, 9.0, 11.0, 12.0, 13.0, 14.0), @@ -1912,14 +1912,14 @@ test "zmath.atan2" { // ------------------------------------------------------------------------------ pub inline fn dot2(v0: Vec, v1: Vec) F32x4 { var xmm0 = v0 * v1; // | x0*x1 | y0*y1 | -- | -- | - var xmm1 = swizzle(xmm0, .y, .x, .x, .x); // | y0*y1 | -- | -- | -- | + const xmm1 = swizzle(xmm0, .y, .x, .x, .x); // | y0*y1 | -- | -- | -- | xmm0 = f32x4(xmm0[0] + xmm1[0], xmm0[1], xmm0[2], xmm0[3]); // | x0*x1 + y0*y1 | -- | -- | -- | return swizzle(xmm0, .x, .x, .x, .x); } test "zmath.dot2" { const v0 = f32x4(-1.0, 2.0, 300.0, -2.0); const v1 = f32x4(4.0, 5.0, 600.0, 2.0); - var v = dot2(v0, v1); + const v = dot2(v0, v1); try expect(approxEqAbs(v, splat(F32x4, 6.0), 0.0001)); } @@ -1930,7 +1930,7 @@ pub inline fn dot3(v0: Vec, v1: Vec) F32x4 { test "zmath.dot3" { const v0 = f32x4(-1.0, 2.0, 3.0, 1.0); const v1 = f32x4(4.0, 5.0, 6.0, 1.0); - var v = dot3(v0, v1); + const v = dot3(v0, v1); try expect(approxEqAbs(v, splat(F32x4, 24.0), 0.0001)); } @@ -1945,7 +1945,7 @@ pub inline fn dot4(v0: Vec, v1: Vec) F32x4 { test "zmath.dot4" { const v0 = f32x4(-1.0, 2.0, 3.0, -2.0); const v1 = f32x4(4.0, 5.0, 6.0, 2.0); - var v = dot4(v0, v1); + const v = dot4(v0, v1); try expect(approxEqAbs(v, splat(F32x4, 20.0), 0.0001)); } @@ -1962,19 +1962,19 @@ test "zmath.cross3" { { const v0 = f32x4(1.0, 0.0, 0.0, 1.0); const v1 = f32x4(0.0, 1.0, 0.0, 1.0); - var v = cross3(v0, v1); + const v = cross3(v0, v1); try expect(approxEqAbs(v, f32x4(0.0, 0.0, 1.0, 0.0), 0.0001)); } { const v0 = f32x4(1.0, 0.0, 0.0, 1.0); const v1 = f32x4(0.0, -1.0, 0.0, 1.0); - var v = cross3(v0, v1); + const v = cross3(v0, v1); try expect(approxEqAbs(v, f32x4(0.0, 0.0, -1.0, 0.0), 0.0001)); } { const v0 = f32x4(-3.0, 0, -2.0, 1.0); const v1 = f32x4(5.0, -1.0, 2.0, 1.0); - var v = cross3(v0, v1); + const v = cross3(v0, v1); try expect(approxEqAbs(v, f32x4(-2.0, -4.0, 3.0, 0.0), 0.0001)); } } @@ -2029,7 +2029,7 @@ pub inline fn normalize4(v: Vec) Vec { test "zmath.normalize3" { { const v0 = f32x4(1.0, -2.0, 3.0, 1000.0); - var v = normalize3(v0); + const v = normalize3(v0); try expect(approxEqAbs(v, v0 * splat(F32x4, 1.0 / math.sqrt(14.0)), 0.0005)); } { @@ -2042,7 +2042,7 @@ test "zmath.normalize3" { test "zmath.normalize4" { { const v0 = f32x4(1.0, -2.0, 3.0, 10.0); - var v = normalize4(v0); + const v = normalize4(v0); try expect(approxEqAbs(v, v0 * splat(F32x4, 1.0 / math.sqrt(114.0)), 0.0005)); } { @@ -2054,10 +2054,10 @@ test "zmath.normalize4" { } fn vecMulMat(v: Vec, m: Mat) Vec { - var vx = @shuffle(f32, v, undefined, [4]i32{ 0, 0, 0, 0 }); - var vy = @shuffle(f32, v, undefined, [4]i32{ 1, 1, 1, 1 }); - var vz = @shuffle(f32, v, undefined, [4]i32{ 2, 2, 2, 2 }); - var vw = @shuffle(f32, v, undefined, [4]i32{ 3, 3, 3, 3 }); + const vx = @shuffle(f32, v, undefined, [4]i32{ 0, 0, 0, 0 }); + const vy = @shuffle(f32, v, undefined, [4]i32{ 1, 1, 1, 1 }); + const vz = @shuffle(f32, v, undefined, [4]i32{ 2, 2, 2, 2 }); + const vw = @shuffle(f32, v, undefined, [4]i32{ 3, 3, 3, 3 }); return vx * m[0] + vy * m[1] + vz * m[2] + vw * m[3]; } fn matMulVec(m: Mat, v: Vec) Vec { @@ -2501,7 +2501,7 @@ pub fn determinant(m: Mat) F32x4 { v1 = swizzle(m[1], .z, .z, .y, .y); v2 = swizzle(m[1], .y, .x, .x, .x); - var s = m[0] * f32x4(1.0, -1.0, 1.0, -1.0); + const s = m[0] * f32x4(1.0, -1.0, 1.0, -1.0); var r = v0 * p0; r = mulAdd(-v1, p1, r); r = mulAdd(v2, p2, r); @@ -2721,7 +2721,7 @@ test "zmath.matrix.matFromAxisAngle" { } pub fn matFromQuat(quat: Quat) Mat { - var q0 = quat + quat; + const q0 = quat + quat; var q1 = quat * q0; var v0 = swizzle(q1, .y, .x, .x, .w); @@ -2730,18 +2730,18 @@ pub fn matFromQuat(quat: Quat) Mat { var v1 = swizzle(q1, .z, .z, .y, .w); v1 = andInt(v1, f32x4_mask3); - var r0 = (f32x4(1.0, 1.0, 1.0, 0.0) - v0) - v1; + const r0 = (f32x4(1.0, 1.0, 1.0, 0.0) - v0) - v1; v0 = swizzle(quat, .x, .x, .y, .w); v1 = swizzle(q0, .z, .y, .z, .w); v0 = v0 * v1; v1 = swizzle(quat, .w, .w, .w, .w); - var v2 = swizzle(q0, .y, .z, .x, .w); + const v2 = swizzle(q0, .y, .z, .x, .w); v1 = v1 * v2; - var r1 = v0 + v1; - var r2 = v0 - v1; + const r1 = v0 + v1; + const r2 = v0 - v1; v0 = @shuffle(f32, r1, r2, [4]i32{ 1, 2, ~@as(i32, 0), ~@as(i32, 1) }); v0 = swizzle(v0, .x, .z, .w, .y); @@ -2974,7 +2974,7 @@ test "zmath.quatFromMat" { } pub fn quatFromNormAxisAngle(axis: Vec, angle: f32) Quat { - var n = f32x4(axis[0], axis[1], axis[2], 1.0); + const n = f32x4(axis[0], axis[1], axis[2], 1.0); const sc = sincos(0.5 * angle); return n * f32x4(sc[0], sc[0], sc[0], sc[1]); } @@ -3066,7 +3066,7 @@ pub fn slerpV(q0: Quat, q1: Quat, t: F32x4) Quat { var s0 = sin(v01 * omega) / sin_omega; s0 = select(cos_omega < splat(F32x4, 1.0 - 0.00001), s0, v01); - var s1 = swizzle(s0, .y, .y, .y, .y); + const s1 = swizzle(s0, .y, .y, .y, .y); s0 = swizzle(s0, .x, .x, .x, .x); return q0 * s0 + sign * q1 * s1; @@ -3097,9 +3097,9 @@ pub fn quatToRollPitchYaw(q: Quat) [3]f32 { angles[2] = 0.0; } else { const sq = p * p; - var y = splat(F32x4, 2.0) * f32x4(p[0] * p[1] - sign * p[2] * p[3], p[0] * p[3] - sign * p[1] * p[2], 0.0, 0.0); - var x = splat(F32x4, 1.0) - (splat(F32x4, 2.0) * f32x4(sq[1] + sq[2], sq[2] + sq[3], 0.0, 0.0)); - var res = atan2(y, x); + const y = splat(F32x4, 2.0) * f32x4(p[0] * p[1] - sign * p[2] * p[3], p[0] * p[3] - sign * p[1] * p[2], 0.0, 0.0); + const x = splat(F32x4, 1.0) - (splat(F32x4, 2.0) * f32x4(sq[1] + sq[2], sq[2] + sq[3], 0.0, 0.0)); + const res = atan2(y, x); angles[0] = math.asin(2.0 * singularity); angles[1] = res[0]; angles[2] = res[1]; @@ -3513,7 +3513,7 @@ test "zmath.linePointDistance" { const linept0 = f32x4(-1.0, -2.0, -3.0, 1.0); const linept1 = f32x4(1.0, 2.0, 3.0, 1.0); const pt = f32x4(1.0, 1.0, 1.0, 1.0); - var v = linePointDistance(linept0, linept1, pt); + const v = linePointDistance(linept0, linept1, pt); try expect(approxEqAbs(v, splat(F32x4, 0.654), 0.001)); } } @@ -4312,8 +4312,8 @@ pub fn fft(re: []F32x4, im: []F32x4, unity_table: []const F32x4) void { var re_temp_storage: [128]F32x4 = undefined; var im_temp_storage: [128]F32x4 = undefined; - var re_temp = re_temp_storage[0..re.len]; - var im_temp = im_temp_storage[0..im.len]; + const re_temp = re_temp_storage[0..re.len]; + const im_temp = im_temp_storage[0..im.len]; std.mem.copy(F32x4, re_temp, re); std.mem.copy(F32x4, im_temp, im); diff --git a/util/fumen_compile.zig b/util/fumen_compile.zig index b61e175..4b0d0d7 100644 --- a/util/fumen_compile.zig +++ b/util/fumen_compile.zig @@ -143,7 +143,7 @@ pub fn compile(allocator: std.mem.Allocator, input_file: std.fs.File, output_dir //Get the writer for the output file var buffered_writer = std.io.bufferedWriter(output_file.writer()); - var writer = buffered_writer.writer(); + const writer = buffered_writer.writer(); //Write the path of the music file try std.fmt.format(writer, "@{s}\n", .{stripNewline(try reader.readUntilDelimiterOrEof(&buf, '\n') orelse return error.UnexpectedEOF)}); @@ -412,8 +412,8 @@ fn setSpeed(info: *Info, speed: []const u8) !void { var iter = std.mem.tokenizeAny(u8, speed, "= \t\n"); //Parse out the BPM and BPM divisor - var bpm_divsor: f64 = @floatFromInt(try std.fmt.parseInt(usize, iter.next() orelse return error.MissingTimeSignature, 0)); - var bpm = try std.fmt.parseFloat(f64, iter.next() orelse return error.MissingBPM); + const bpm_divsor: f64 = @floatFromInt(try std.fmt.parseInt(usize, iter.next() orelse return error.MissingTimeSignature, 0)); + const bpm = try std.fmt.parseFloat(f64, iter.next() orelse return error.MissingBPM); //Validate BPM and BPM divisor are within valid ranges if (bpm_divsor <= 0) return error.InvalidTimeSignature; @@ -433,7 +433,7 @@ fn setBase(info: *Info, base: []const u8) !void { //Every token while (iter.next()) |item| { //Parse the base from the token - var base_value = try std.fmt.parseInt(usize, item, 0); + const base_value = try std.fmt.parseInt(usize, item, 0); //Verify the value is valid if (base_value <= 0) { @@ -479,7 +479,7 @@ fn setTimeSignature(info: *Info, beat: []const u8) !void { //Get the last item in the time signature command if (iter.next()) |d_str| { //TODO: what the fuck does this do - var d = try std.fmt.parseFloat(f64, d_str); + const d = try std.fmt.parseFloat(f64, d_str); //The integer part of the beat info.beat_int = @intFromFloat(@ceil(d)); diff --git a/wgpu.zig b/wgpu.zig index 0e1d70f..64d3edf 100644 --- a/wgpu.zig +++ b/wgpu.zig @@ -5,13 +5,13 @@ pub fn create_wgpu(b: *std.Build, target: std.zig.CrossTarget, optimize: std.bui const wgpu_native_path = root_path ++ "libs/wgpu-native/"; //Get the users name - var username = try std.process.getEnvVarOwned(b.allocator, "USER"); + const username = try std.process.getEnvVarOwned(b.allocator, "USER"); //TODO: install the proper toolchains //Get the possible path to `cross` //TODO: make this logic much smarter - var cross_path = try std.mem.concat(b.allocator, u8, &.{ "/home/", username, "/.cargo/bin/cross" }); + const cross_path = try std.mem.concat(b.allocator, u8, &.{ "/home/", username, "/.cargo/bin/cross" }); //Array list will store our target name var cross_target = std.ArrayList(u8).init(b.allocator); @@ -49,7 +49,7 @@ pub fn create_wgpu(b: *std.Build, target: std.zig.CrossTarget, optimize: std.bui try args.append("--release"); } - var build_result = try std.ChildProcess.run(.{ + const build_result = try std.ChildProcess.run(.{ .allocator = b.allocator, .argv = args.items, .cwd = wgpu_native_path, @@ -63,7 +63,7 @@ pub fn create_wgpu(b: *std.Build, target: std.zig.CrossTarget, optimize: std.bui return error.UnableToCompileWgpu; } - var target_path = try std.mem.concat(b.allocator, u8, &.{ root_path, "libs/wgpu-native/target/", cross_target.items, "/", if (optimize == std.builtin.OptimizeMode.Debug) "debug" else "release" }); + const target_path = try std.mem.concat(b.allocator, u8, &.{ root_path, "libs/wgpu-native/target/", cross_target.items, "/", if (optimize == std.builtin.OptimizeMode.Debug) "debug" else "release" }); return (try std.mem.concat(b.allocator, u8, &.{ target_path, "/libwgpu_native.a" })); }