Update to make it work with zig 0.11.0-dev-2680
This commit is contained in:
parent
eccc24811f
commit
ed031c9b8c
42
build.zig
42
build.zig
|
@ -1,7 +1,7 @@
|
||||||
const std = @import("std");
|
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
|
// Standard target options allows the person running `zig build` to choose
|
||||||
// what target to build for. Here we do not override the defaults, which
|
// 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
|
// 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
|
// Standard release options allow the person running `zig build` to select
|
||||||
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
|
// 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);
|
sdk.link(exe, .dynamic);
|
||||||
|
exe.linkSystemLibrary("sdl2_ttf");
|
||||||
exe.addPackagePath("zgl", "lib/zgl/zgl.zig");
|
exe.linkSystemLibrary("sdl2_image");
|
||||||
exe.addPackagePath("zlm", "lib/zlm/zlm.zig");
|
|
||||||
exe.addPackage(sdk.getWrapperPackage("sdl2"));
|
|
||||||
|
|
||||||
exe.linkSystemLibrary("gl");
|
exe.linkSystemLibrary("gl");
|
||||||
exe.linkSystemLibrary("epoxy");
|
exe.linkSystemLibrary("epoxy");
|
||||||
|
|
||||||
exe.setTarget(target);
|
const relative = std.Build.FileSource.relative;
|
||||||
exe.setBuildMode(mode);
|
exe.addModule("zgl", b.createModule(.{ .source_file = relative("lib/zgl/zgl.zig") }));
|
||||||
exe.install();
|
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());
|
run_cmd.step.dependOn(b.getInstallStep());
|
||||||
|
|
||||||
|
// Allow the user to pass arguments to the applecation
|
||||||
if (b.args) |args| {
|
if (b.args) |args| {
|
||||||
run_cmd.addArgs(args);
|
run_cmd.addArgs(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create the build step
|
||||||
const run_step = b.step("run", "Run the app");
|
const run_step = b.step("run", "Run the app");
|
||||||
run_step.dependOn(&run_cmd.step);
|
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
|
2
lib/zgl
2
lib/zgl
|
@ -1 +1 @@
|
||||||
Subproject commit cac42e0692374742036f14d44379dd085c084caa
|
Subproject commit b40eff53f384ced9481d1c8754651976de22588c
|
2
lib/zlm
2
lib/zlm
|
@ -1 +1 @@
|
||||||
Subproject commit dff2959b5fff0aa7697fdf1a2843a15210aab695
|
Subproject commit 2dc8c0db2e92529bb618ca639bb891b6187fa579
|
|
@ -13,13 +13,13 @@ pub fn init() Self {
|
||||||
.prng = std.rand.DefaultPrng.init(@intCast(u64, std.time.milliTimestamp())),
|
.prng = std.rand.DefaultPrng.init(@intCast(u64, std.time.milliTimestamp())),
|
||||||
};
|
};
|
||||||
// We must fill all of the array
|
// 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);
|
ret.contents[i] = @intToEnum(Piece.Type, i);
|
||||||
}
|
}
|
||||||
// Then we shuffle
|
// Then we shuffle
|
||||||
ret.prng.random().shuffle(?Piece.Type, ret.contents[0..7]);
|
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);
|
ret.contents[i + 7] = @intToEnum(Piece.Type, i);
|
||||||
}
|
}
|
||||||
// Then we shuffle
|
// Then we shuffle
|
||||||
|
@ -34,7 +34,7 @@ pub fn pop(self: *Self) Piece {
|
||||||
if (self.contents[0]) |head| {
|
if (self.contents[0]) |head| {
|
||||||
ret_type = head;
|
ret_type = head;
|
||||||
// Reorganize the bag
|
// Reorganize the bag
|
||||||
for (self.contents) |_, i| {
|
for (self.contents, 0..) |_, i| {
|
||||||
if (i + 1 >= self.contents.len) {
|
if (i + 1 >= self.contents.len) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ pub fn pop(self: *Self) Piece {
|
||||||
}
|
}
|
||||||
// Get more pieces if needed
|
// Get more pieces if needed
|
||||||
if (self.contents[7] == null) {
|
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.contents[i + 7] = @intToEnum(Piece.Type, i);
|
||||||
}
|
}
|
||||||
self.updateSeed();
|
self.updateSeed();
|
||||||
|
|
|
@ -21,8 +21,8 @@ pub fn init() Self {
|
||||||
.cells = undefined,
|
.cells = undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (self.cells) |_, i| {
|
for (self.cells, 0..) |_, i| {
|
||||||
for (self.cells[i]) |_, j| {
|
for (self.cells[i], 0..) |_, j| {
|
||||||
self.cells[i][j] = Cell.init();
|
self.cells[i][j] = Cell.init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,15 +31,15 @@ pub fn init() Self {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clearLines(self: *Self) void {
|
pub fn clearLines(self: *Self) void {
|
||||||
for (self.cells) |_, y| {
|
for (self.cells, 0..) |_, y| {
|
||||||
for (self.cells[y]) |cell_x, x| {
|
for (self.cells[y], 0..) |cell_x, x| {
|
||||||
if (cell_x.free) {
|
if (cell_x.free) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
// Reached the end of the column?
|
// Reached the end of the column?
|
||||||
if (x == self.cells[y].len - 1) {
|
if (x == self.cells[y].len - 1) {
|
||||||
// Delete current row and bring the others down
|
// 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];
|
self.cells[y - i] = self.cells[y - i - 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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));
|
new_piece.rot_stage = @intToEnum(RotStage, @mod((@enumToInt(new_piece.rot_stage) + 1), 4));
|
||||||
// Rotate structure CW
|
// Rotate structure CW
|
||||||
inline for (sequences) |seq| {
|
inline for (sequences) |seq| {
|
||||||
inline for (seq) |_, i| {
|
inline for (seq, 0..) |_, i| {
|
||||||
const refi = @mod((@intCast(i32, i) - 1), 4);
|
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]];
|
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));
|
new_piece.rot_stage = @intToEnum(RotStage, @mod((@enumToInt(new_piece.rot_stage) - 1), 4));
|
||||||
// Rotate structure CCW
|
// Rotate structure CCW
|
||||||
inline for (sequences) |seq| {
|
inline for (sequences) |seq| {
|
||||||
inline for (seq) |_, i| {
|
inline for (seq, 0..) |_, i| {
|
||||||
const refi = @mod((@intCast(i32, i) + 1), 4);
|
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]];
|
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));
|
new_piece.rot_stage = @intToEnum(RotStage, @mod((@enumToInt(new_piece.rot_stage) + 1), 4));
|
||||||
// Rotate structure CW
|
// Rotate structure CW
|
||||||
inline for (sequences) |seq| {
|
inline for (sequences) |seq| {
|
||||||
inline for (seq) |_, i| {
|
inline for (seq, 0..) |_, i| {
|
||||||
const refi = @mod((@intCast(i32, i) - 1), 4);
|
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]];
|
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));
|
new_piece.rot_stage = @intToEnum(RotStage, @mod((@enumToInt(new_piece.rot_stage) - 1), 4));
|
||||||
// Rotate structure CCW
|
// Rotate structure CCW
|
||||||
inline for (sequences) |seq| {
|
inline for (sequences) |seq| {
|
||||||
inline for (seq) |_, i| {
|
inline for (seq, 0..) |_, i| {
|
||||||
const refi = @mod((@intCast(i32, i) + 1), 4);
|
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]];
|
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;
|
return new_piece;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,12 +38,12 @@ pub fn renderBag(self: *Self, game: Game) void {
|
||||||
var b: u8 = 0;
|
var b: u8 = 0;
|
||||||
var a: u8 = 255;
|
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| {
|
if (game.bag.contents[i]) |piece_type| {
|
||||||
var piece = Piece.init(piece_type);
|
var piece = Piece.init(piece_type);
|
||||||
|
|
||||||
for (piece.structure) |_, y| {
|
for (piece.structure, 0..) |_, y| {
|
||||||
for (piece.structure[y]) |_, x| {
|
for (piece.structure[y], 0..) |_, x| {
|
||||||
if (piece.structure[y][x]) {
|
if (piece.structure[y][x]) {
|
||||||
r = piece.color.r;
|
r = piece.color.r;
|
||||||
g = piece.color.g;
|
g = piece.color.g;
|
||||||
|
@ -81,8 +81,8 @@ pub fn renderHeld(self: *Self, game: Game) void {
|
||||||
if (game.held) |held_type| {
|
if (game.held) |held_type| {
|
||||||
var held = Piece.init(held_type);
|
var held = Piece.init(held_type);
|
||||||
|
|
||||||
for (held.structure) |_, y| {
|
for (held.structure, 0..) |_, y| {
|
||||||
for (held.structure[y]) |_, x| {
|
for (held.structure[y], 0..) |_, x| {
|
||||||
if (held.structure[y][x]) {
|
if (held.structure[y][x]) {
|
||||||
r = held.color.r;
|
r = held.color.r;
|
||||||
g = held.color.g;
|
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_x = self.grid_pos_x;
|
||||||
const pos_y = self.grid_pos_y;
|
const pos_y = self.grid_pos_y;
|
||||||
|
|
||||||
for (piece.structure) |_, y| {
|
for (piece.structure, 0..) |_, y| {
|
||||||
for (piece.structure[y]) |_, x| {
|
for (piece.structure[y], 0..) |_, x| {
|
||||||
// We don't want to paint void cells
|
// We don't want to paint void cells
|
||||||
if (piece.structure[y][x] == false) {
|
if (piece.structure[y][x] == false) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -148,8 +148,8 @@ pub fn renderGrid(self: *Self, grid: Grid) void {
|
||||||
const lg = color.light_grey;
|
const lg = color.light_grey;
|
||||||
|
|
||||||
var visible = grid.cells[Grid.buffer..];
|
var visible = grid.cells[Grid.buffer..];
|
||||||
for (visible) |_, y| {
|
for (visible, 0..) |_, y| {
|
||||||
for (visible[y]) |_, x| {
|
for (visible[y], 0..) |_, x| {
|
||||||
var r = visible[y][x].color.r;
|
var r = visible[y][x].color.r;
|
||||||
var g = visible[y][x].color.g;
|
var g = visible[y][x].color.g;
|
||||||
var b = visible[y][x].color.b;
|
var b = visible[y][x].color.b;
|
||||||
|
|
|
@ -65,8 +65,8 @@ pub fn hardDrop(grid: Grid, piece: Piece) Piece {
|
||||||
pub fn drop(grid: Grid, piece: Piece) Grid {
|
pub fn drop(grid: Grid, piece: Piece) Grid {
|
||||||
var new_grid = grid;
|
var new_grid = grid;
|
||||||
|
|
||||||
for (piece.structure) |_, y| {
|
for (piece.structure, 0..) |_, y| {
|
||||||
for (piece.structure[y]) |_, x| {
|
for (piece.structure[y], 0..) |_, x| {
|
||||||
if (piece.structure[y][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))].free = false;
|
||||||
new_grid.cells[@intCast(usize, piece.row + @intCast(i32, y))][@intCast(usize, piece.col + @intCast(i32, x))].color = piece.color;
|
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 {
|
fn checkCollision(grid: Grid, piece: Piece) bool {
|
||||||
for (piece.structure) |_, y| {
|
for (piece.structure, 0..) |_, y| {
|
||||||
for (piece.structure[y]) |_, x| {
|
for (piece.structure[y], 0..) |_, x| {
|
||||||
if (piece.structure[y][x] and
|
if (piece.structure[y][x] and
|
||||||
((@intCast(i32, x) + piece.col > Grid.ncolumns - 1) or
|
((@intCast(i32, x) + piece.col > Grid.ncolumns - 1) or
|
||||||
(@intCast(i32, x) + piece.col < 0) 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 rows = [_]i32{ 0, 2, 0, 2 };
|
||||||
const cols = [_]i32{ 0, 0, 2, 2 };
|
const cols = [_]i32{ 0, 0, 2, 2 };
|
||||||
for (rows) |_, i| {
|
for (rows, 0..) |_, i| {
|
||||||
var row = piece.row + rows[i];
|
var row = piece.row + rows[i];
|
||||||
var col = piece.col + cols[i];
|
var col = piece.col + cols[i];
|
||||||
if ((row > 0 and row < Grid.nrows and col > 0 and col < Grid.ncolumns) and
|
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;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ pub fn render(self: Self, main_menu: MainMenu) void {
|
||||||
const screen_width = @intCast(i32, wsize.width);
|
const screen_width = @intCast(i32, wsize.width);
|
||||||
const screen_height = @intCast(i32, wsize.height);
|
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 = @intCast(i32, u_tab);
|
||||||
const tab_i = @intCast(i32, u_tab_i);
|
const tab_i = @intCast(i32, u_tab_i);
|
||||||
const curr_tab = main_menu.tab_list[u_tab];
|
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);
|
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 aux_sel: i32 = @intCast(i32, i + 1);
|
||||||
const curr_sel: usize = main_menu.getSelIdx(aux_sel);
|
const curr_sel: usize = main_menu.getSelIdx(aux_sel);
|
||||||
const y = @intCast(i32, sel_y_offset + ((y_spacing + height) * (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);
|
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 aux_sel: i32 = -@intCast(i32, i + 1);
|
||||||
const curr_sel: usize = main_menu.getSelIdx(aux_sel);
|
const curr_sel: usize = main_menu.getSelIdx(aux_sel);
|
||||||
const y = @intCast(i32, sel_y_offset + ((y_spacing + height) * (aux_sel)));
|
const y = @intCast(i32, sel_y_offset + ((y_spacing + height) * (aux_sel)));
|
||||||
|
|
Loading…
Reference in New Issue