Update to make it work with zig 0.11.0-dev-2680

This commit is contained in:
Dendy 2023-04-21 00:00:14 +02:00
parent eccc24811f
commit ed031c9b8c
10 changed files with 60 additions and 58 deletions

View File

@ -1,7 +1,7 @@
const std = @import("std");
const Sdk = @import("lib/SDL.zig/Sdk.zig");
const Sdk = @import("lib/SDL.zig/build.zig");
pub fn build(b: *std.build.Builder) void {
pub fn build(b: *std.Build) void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
@ -10,34 +10,38 @@ pub fn build(b: *std.build.Builder) void {
// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const mode = b.standardReleaseOptions();
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable("usg", "src/main.zig");
const exe = b.addExecutable(.{
.name = "usg",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
const sdk = Sdk.init(b);
const sdk = Sdk.init(b, null);
sdk.link(exe, .dynamic);
exe.addPackagePath("zgl", "lib/zgl/zgl.zig");
exe.addPackagePath("zlm", "lib/zlm/zlm.zig");
exe.addPackage(sdk.getWrapperPackage("sdl2"));
exe.linkSystemLibrary("sdl2_ttf");
exe.linkSystemLibrary("sdl2_image");
exe.linkSystemLibrary("gl");
exe.linkSystemLibrary("epoxy");
exe.setTarget(target);
exe.setBuildMode(mode);
exe.install();
const relative = std.Build.FileSource.relative;
exe.addModule("zgl", b.createModule(.{ .source_file = relative("lib/zgl/zgl.zig") }));
exe.addModule("zlm", b.createModule(.{ .source_file = relative("lib/zlm/zlm.zig") }));
exe.addModule("sdl2", sdk.getWrapperModule());
const run_cmd = exe.run();
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
// Allow the user to pass arguments to the applecation
if (b.args) |args| {
run_cmd.addArgs(args);
}
// Create the build step
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
const exe_tests = b.addTest("src/main.zig");
exe_tests.setTarget(target);
exe_tests.setBuildMode(mode);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&exe_tests.step);
}

@ -1 +1 @@
Subproject commit 21b63f7abbe8e5b76ea11aaa6b17342548e30154
Subproject commit 36e192a74f3be878766e1aa3e6f13ba5f92650cb

@ -1 +1 @@
Subproject commit cac42e0692374742036f14d44379dd085c084caa
Subproject commit b40eff53f384ced9481d1c8754651976de22588c

@ -1 +1 @@
Subproject commit dff2959b5fff0aa7697fdf1a2843a15210aab695
Subproject commit 2dc8c0db2e92529bb618ca639bb891b6187fa579

View File

@ -13,13 +13,13 @@ pub fn init() Self {
.prng = std.rand.DefaultPrng.init(@intCast(u64, std.time.milliTimestamp())),
};
// We must fill all of the array
for (ret.contents[0..7]) |_, i| {
for (ret.contents[0..7], 0..) |_, i| {
ret.contents[i] = @intToEnum(Piece.Type, i);
}
// Then we shuffle
ret.prng.random().shuffle(?Piece.Type, ret.contents[0..7]);
for (ret.contents[7..14]) |_, i| {
for (ret.contents[7..14], 0..) |_, i| {
ret.contents[i + 7] = @intToEnum(Piece.Type, i);
}
// Then we shuffle
@ -34,7 +34,7 @@ pub fn pop(self: *Self) Piece {
if (self.contents[0]) |head| {
ret_type = head;
// Reorganize the bag
for (self.contents) |_, i| {
for (self.contents, 0..) |_, i| {
if (i + 1 >= self.contents.len) {
break;
}
@ -45,7 +45,7 @@ pub fn pop(self: *Self) Piece {
}
// Get more pieces if needed
if (self.contents[7] == null) {
for (self.contents[7..14]) |_, i| {
for (self.contents[7..14], 0..) |_, i| {
self.contents[i + 7] = @intToEnum(Piece.Type, i);
}
self.updateSeed();

View File

@ -21,8 +21,8 @@ pub fn init() Self {
.cells = undefined,
};
for (self.cells) |_, i| {
for (self.cells[i]) |_, j| {
for (self.cells, 0..) |_, i| {
for (self.cells[i], 0..) |_, j| {
self.cells[i][j] = Cell.init();
}
}
@ -31,15 +31,15 @@ pub fn init() Self {
}
pub fn clearLines(self: *Self) void {
for (self.cells) |_, y| {
for (self.cells[y]) |cell_x, x| {
for (self.cells, 0..) |_, y| {
for (self.cells[y], 0..) |cell_x, x| {
if (cell_x.free) {
break;
} else {
// Reached the end of the column?
if (x == self.cells[y].len - 1) {
// Delete current row and bring the others down
for (self.cells[1..y]) |_, i| {
for (self.cells[1..y], 0..) |_, i| {
self.cells[y - i] = self.cells[y - i - 1];
}
}

View File

@ -136,7 +136,7 @@ pub fn rotate(self: Self, dir: Rot) Self {
new_piece.rot_stage = @intToEnum(RotStage, @mod((@enumToInt(new_piece.rot_stage) + 1), 4));
// Rotate structure CW
inline for (sequences) |seq| {
inline for (seq) |_, i| {
inline for (seq, 0..) |_, i| {
const refi = @mod((@intCast(i32, i) - 1), 4);
new_piece.structure[seq[i][0]][seq[i][1]] = self.structure[seq[refi][0]][seq[refi][1]];
}
@ -146,7 +146,7 @@ pub fn rotate(self: Self, dir: Rot) Self {
new_piece.rot_stage = @intToEnum(RotStage, @mod((@enumToInt(new_piece.rot_stage) - 1), 4));
// Rotate structure CCW
inline for (sequences) |seq| {
inline for (seq) |_, i| {
inline for (seq, 0..) |_, i| {
const refi = @mod((@intCast(i32, i) + 1), 4);
new_piece.structure[seq[i][0]][seq[i][1]] = self.structure[seq[refi][0]][seq[refi][1]];
}
@ -160,7 +160,7 @@ pub fn rotate(self: Self, dir: Rot) Self {
new_piece.rot_stage = @intToEnum(RotStage, @mod((@enumToInt(new_piece.rot_stage) + 1), 4));
// Rotate structure CW
inline for (sequences) |seq| {
inline for (seq) |_, i| {
inline for (seq, 0..) |_, i| {
const refi = @mod((@intCast(i32, i) - 1), 4);
new_piece.structure[seq[i][0]][seq[i][1]] = self.structure[seq[refi][0]][seq[refi][1]];
}
@ -170,7 +170,7 @@ pub fn rotate(self: Self, dir: Rot) Self {
new_piece.rot_stage = @intToEnum(RotStage, @mod((@enumToInt(new_piece.rot_stage) - 1), 4));
// Rotate structure CCW
inline for (sequences) |seq| {
inline for (seq) |_, i| {
inline for (seq, 0..) |_, i| {
const refi = @mod((@intCast(i32, i) + 1), 4);
new_piece.structure[seq[i][0]][seq[i][1]] = self.structure[seq[refi][0]][seq[refi][1]];
}
@ -184,4 +184,3 @@ pub fn rotate(self: Self, dir: Rot) Self {
return new_piece;
}

View File

@ -38,12 +38,12 @@ pub fn renderBag(self: *Self, game: Game) void {
var b: u8 = 0;
var a: u8 = 255;
for (game.bag.contents[0..5]) |_, i| {
for (game.bag.contents[0..5], 0..) |_, i| {
if (game.bag.contents[i]) |piece_type| {
var piece = Piece.init(piece_type);
for (piece.structure) |_, y| {
for (piece.structure[y]) |_, x| {
for (piece.structure, 0..) |_, y| {
for (piece.structure[y], 0..) |_, x| {
if (piece.structure[y][x]) {
r = piece.color.r;
g = piece.color.g;
@ -81,8 +81,8 @@ pub fn renderHeld(self: *Self, game: Game) void {
if (game.held) |held_type| {
var held = Piece.init(held_type);
for (held.structure) |_, y| {
for (held.structure[y]) |_, x| {
for (held.structure, 0..) |_, y| {
for (held.structure[y], 0..) |_, x| {
if (held.structure[y][x]) {
r = held.color.r;
g = held.color.g;
@ -119,8 +119,8 @@ pub fn renderPiece(self: *Self, piece: Piece) void {
const pos_x = self.grid_pos_x;
const pos_y = self.grid_pos_y;
for (piece.structure) |_, y| {
for (piece.structure[y]) |_, x| {
for (piece.structure, 0..) |_, y| {
for (piece.structure[y], 0..) |_, x| {
// We don't want to paint void cells
if (piece.structure[y][x] == false) {
continue;
@ -148,8 +148,8 @@ pub fn renderGrid(self: *Self, grid: Grid) void {
const lg = color.light_grey;
var visible = grid.cells[Grid.buffer..];
for (visible) |_, y| {
for (visible[y]) |_, x| {
for (visible, 0..) |_, y| {
for (visible[y], 0..) |_, x| {
var r = visible[y][x].color.r;
var g = visible[y][x].color.g;
var b = visible[y][x].color.b;

View File

@ -65,8 +65,8 @@ pub fn hardDrop(grid: Grid, piece: Piece) Piece {
pub fn drop(grid: Grid, piece: Piece) Grid {
var new_grid = grid;
for (piece.structure) |_, y| {
for (piece.structure[y]) |_, x| {
for (piece.structure, 0..) |_, y| {
for (piece.structure[y], 0..) |_, x| {
if (piece.structure[y][x]) {
new_grid.cells[@intCast(usize, piece.row + @intCast(i32, y))][@intCast(usize, piece.col + @intCast(i32, x))].free = false;
new_grid.cells[@intCast(usize, piece.row + @intCast(i32, y))][@intCast(usize, piece.col + @intCast(i32, x))].color = piece.color;
@ -83,8 +83,8 @@ pub fn shadow(grid: Grid, piece: Piece) Piece {
}
fn checkCollision(grid: Grid, piece: Piece) bool {
for (piece.structure) |_, y| {
for (piece.structure[y]) |_, x| {
for (piece.structure, 0..) |_, y| {
for (piece.structure[y], 0..) |_, x| {
if (piece.structure[y][x] and
((@intCast(i32, x) + piece.col > Grid.ncolumns - 1) or
(@intCast(i32, x) + piece.col < 0) or
@ -215,7 +215,7 @@ fn checkTTwist(grid: Grid, piece: Piece) bool {
//
const rows = [_]i32{ 0, 2, 0, 2 };
const cols = [_]i32{ 0, 0, 2, 2 };
for (rows) |_, i| {
for (rows, 0..) |_, i| {
var row = piece.row + rows[i];
var col = piece.col + cols[i];
if ((row > 0 and row < Grid.nrows and col > 0 and col < Grid.ncolumns) and
@ -265,5 +265,4 @@ pub fn isToppedOut(grid: Grid) bool {
}
}
return false;
}

View File

@ -35,7 +35,7 @@ pub fn render(self: Self, main_menu: MainMenu) void {
const screen_width = @intCast(i32, wsize.width);
const screen_height = @intCast(i32, wsize.height);
for (tabs) |u_tab, u_tab_i| {
for (tabs, 0..) |u_tab, u_tab_i| {
//const tab = @intCast(i32, u_tab);
const tab_i = @intCast(i32, u_tab_i);
const curr_tab = main_menu.tab_list[u_tab];
@ -77,14 +77,14 @@ pub fn render(self: Self, main_menu: MainMenu) void {
self.renderMenu(x, y, curr_tab, curr_tab.sel, alpha, true);
}
for (range(n_sel_below)) |_, i| {
for (range(n_sel_below), 0..) |_, i| {
const aux_sel: i32 = @intCast(i32, i + 1);
const curr_sel: usize = main_menu.getSelIdx(aux_sel);
const y = @intCast(i32, sel_y_offset + ((y_spacing + height) * (aux_sel)));
self.renderMenu(x - ((skew + 8) * aux_sel), y, curr_tab, curr_sel, alpha, false);
}
for (range(n_sel_above)) |_, i| {
for (range(n_sel_above), 0..) |_, i| {
const aux_sel: i32 = -@intCast(i32, i + 1);
const curr_sel: usize = main_menu.getSelIdx(aux_sel);
const y = @intCast(i32, sel_y_offset + ((y_spacing + height) * (aux_sel)));