summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--COPYING8
-rw-r--r--build.zig25
m---------lib/gfz0
m---------lib/ini0
m---------lib/loca0
m---------lib/zeal0
-rw-r--r--src/cimport.zig5
-rw-r--r--src/config.zig2
-rw-r--r--src/main.zig11
-rw-r--r--src/misc.zig69
10 files changed, 63 insertions, 57 deletions
diff --git a/COPYING b/COPYING
index 94a9ed0..f288702 100644
--- a/COPYING
+++ b/COPYING
@@ -1,7 +1,7 @@
                     GNU GENERAL PUBLIC LICENSE
                        Version 3, 29 June 2007
 
- Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
  Everyone is permitted to copy and distribute verbatim copies
  of this license document, but changing it is not allowed.
 
@@ -645,7 +645,7 @@ the "copyright" line and a pointer to where the full notice is found.
     GNU General Public License for more details.
 
     You should have received a copy of the GNU General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+    along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
 Also add information on how to contact you by electronic and paper mail.
 
@@ -664,11 +664,11 @@ might be different; for a GUI interface, you would use an "about box".
   You should also get your employer (if you work as a programmer) or school,
 if any, to sign a "copyright disclaimer" for the program, if necessary.
 For more information on this, and how to apply and follow the GNU GPL, see
-<http://www.gnu.org/licenses/>.
+<https://www.gnu.org/licenses/>.
 
   The GNU General Public License does not permit incorporating your program
 into proprietary programs.  If your program is a subroutine library, you
 may consider it more useful to permit linking proprietary applications with
 the library.  If this is what you want to do, use the GNU Lesser General
 Public License instead of this License.  But first, please read
-<http://www.gnu.org/philosophy/why-not-lgpl.html>.
+<https://www.gnu.org/licenses/why-not-lgpl.html>.
diff --git a/build.zig b/build.zig
index 11b8baf..46a93d2 100644
--- a/build.zig
+++ b/build.zig
@@ -22,11 +22,16 @@ const Builder = std.build.Builder;
 
 const data = InstallDirectoryOptions{
     .source_dir = "data",
-    .install_dir = .{ .Custom = "share" }, // break in future Zig
+    .install_dir = .{ .custom = "share" },
     .install_subdir = "blackshades",
 };
 
 pub fn build(b: *Builder) void {
+    b.installDirectory(data);
+    const options = b.addOptions();
+    const data_dir = b.getInstallPath(data.install_dir, data.install_subdir);
+    options.addOption([]const u8, "data_dir", data_dir);
+
     const exe = b.addExecutable("blackshades", "src/main.zig");
     exe.addIncludeDir("src");
 
@@ -48,13 +53,12 @@ pub fn build(b: *Builder) void {
 
     exe.addCSourceFile("lib/lodepng/lodepng.c", &.{ "-ansi", "-pedantic" });
     exe.addIncludeDir("lib/lodepng");
-    exe.addPackage(.{ .name = "gfz", .path = "lib/gfz/src/gfz.zig" });
-    exe.linkSystemLibrary("glfw");
-    exe.addPackage(.{ .name = "ini", .path = "lib/ini/src/ini.zig" });
-    exe.addPackage(.{ .name = "loca", .path = "lib/loca/src/main.zig" });
-    exe.addPackage(.{ .name = "zeal", .path = "lib/zeal/src/zeal.zig" });
-    exe.linkSystemLibrary("openal");
-    exe.linkSystemLibrary("sndfile");
+    exe.addPackagePath("gfz", "lib/gfz/src/gfz.zig");
+    @import("lib/gfz/build.zig").link(exe);
+    exe.addPackagePath("ini", "lib/ini/src/ini.zig");
+    exe.addPackagePath("loca", "lib/loca/src/main.zig");
+    exe.addPackagePath("zeal", "lib/zeal/src/zeal.zig");
+    @import("lib/zeal/build.zig").link(exe);
 
     exe.linkSystemLibrary("GL");
     exe.linkSystemLibrary("GLU");
@@ -69,10 +73,7 @@ pub fn build(b: *Builder) void {
     // Standard release options allow the person running `zig build` to select
     // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
     exe.setBuildMode(b.standardReleaseOptions());
-
-    const data_dir = b.getInstallPath(data.install_dir, data.install_subdir);
-    exe.addBuildOption([]const u8, "data_dir", data_dir);
-    b.installDirectory(data);
+    exe.addOptions("build_options", options);
     exe.install();
 
     const run_cmd = exe.run();
diff --git a/lib/gfz b/lib/gfz
-Subproject bbd457fc16a8d4a637ca08686a584a7d0874450
+Subproject 7c1b42634198dbc996acf5e920e19790aebc4e0
diff --git a/lib/ini b/lib/ini
-Subproject cceafc18d7f72a532224be80b36ea1b3b9e2bfd
+Subproject d980d828f5cd53fac19f474ffd8b7b368ebbd10
diff --git a/lib/loca b/lib/loca
-Subproject 09ff9ba76aa572afd4144bab25e0ca91458379c
+Subproject 25a807f09c6b7cec721d07f89f19644320ad88c
diff --git a/lib/zeal b/lib/zeal
-Subproject 29a1ea1aa2038a3d4bad44741c25e6d34c0e4e9
+Subproject b694ce54a1eae6882ddda484cf34d75cc931acb
diff --git a/src/cimport.zig b/src/cimport.zig
index b5d66e9..88061db 100644
--- a/src/cimport.zig
+++ b/src/cimport.zig
@@ -1,4 +1,9 @@
 usingnamespace @cImport({
+    @cInclude("AL/al.h");
+    @cInclude("GL/gl.h");
+    @cInclude("GL/glu.h");
+    @cInclude("lodepng.h");
+
     @cInclude("Game.h");
     @cInclude("Constants.h");
 });
diff --git a/src/config.zig b/src/config.zig
index ecb199f..6622ef2 100644
--- a/src/config.zig
+++ b/src/config.zig
@@ -92,7 +92,7 @@ fn parseLevels(dir_path: []const u8, length: usize) ![*]Level {
                 else return error.InvalidData;
             } else if (eql(u8, kv.key, "evil weapons")) {
                 var weapons = IntegerBitSet(8).initEmpty();
-                var enums = tokenize(kv.value, " ");
+                var enums = tokenize(u8, kv.value, " ");
                 while (enums.next()) |weapon|
                     weapons.set(try parseInt(u3, weapon, 10));
                 levels[i].evil_weapons = weapons.mask;
diff --git a/src/main.zig b/src/main.zig
index 6cbf240..f861b19 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -37,38 +37,43 @@ var game: *c.Game = undefined;
 var prng: DefaultPrng = undefined;
 
 fn resizeWindow(window: gf.Window, width: c_int, height: c_int) void {
+    _ = window;
     c.resizeWindow(game, width, height);
 }
 
 fn handleKey(window: gf.Window, key: gf.Key, scancode: c_int,
              action: gf.KeyAction, mods: gf.Mods) void {
+    _ = window;
+    _ = scancode;
     c.handleKey(game, @enumToInt(key), @enumToInt(action), mods.toInt());
 }
 
 fn look(window: gf.Window, xpos: f64, ypos: f64) void {
+    _ = window;
     c.look(game, xpos, ypos);
 }
 
 fn click(window: gf.Window, button: gf.MouseButton,
          action: gf.MouseButton.Action, mods: gf.Mods) void {
+    _ = window;
     c.click(game, @enumToInt(button), @enumToInt(action), mods.toInt());
 }
 
 /// Return a floating point value evenly distributed in the range [0, 1).
 export fn randFloat() f32 {
-    return prng.random.float(f32);
+    return prng.random().float(f32);
 }
 
 /// Return a random integer i where at_least <= i <= at_most.
 /// The results of this function may be biased.
 export fn randInt(at_least: i32, at_most: i32) i32 {
-    return prng.random.intRangeAtMostBiased(i32, at_least, at_most);
+    return prng.random().intRangeAtMostBiased(i32, at_least, at_most);
 }
 
 /// Return a random integer i where 0 <= i < less_than.
 /// The results of this function may be biased.
 export fn randUint(less_than: u32) u32 {
-    return prng.random.uintLessThanBiased(u32, less_than);
+    return prng.random().uintLessThanBiased(u32, less_than);
 }
 
 pub fn main() !void {
diff --git a/src/misc.zig b/src/misc.zig
index f61fc2d..eb09cc2 100644
--- a/src/misc.zig
+++ b/src/misc.zig
@@ -16,15 +16,8 @@
 // You should have received a copy of the GNU General Public License
 // along with Black Shades.  If not, see <https://www.gnu.org/licenses/>.
 
-usingnamespace @cImport({
-    @cInclude("AL/al.h");
-    @cInclude("GL/gl.h");
-    @cInclude("GL/glu.h");
-    @cInclude("lodepng.h");
-});
-
 const Dir = std.fs.Dir;
-const TokenIterator = std.mem.TokenIterator;
+const TokenIterator = std.mem.TokenIterator(u8);
 const allocPrint = std.fmt.allocPrint;
 const allocator = std.heap.c_allocator;
 const assert = std.debug.assert;
@@ -48,6 +41,7 @@ const gf = @import("gfz");
 const ini = @import("ini");
 
 const data_dir = @import("build_options").data_dir ++ [_]u8{ sep };
+const c = @import("cimport.zig");
 
 /// Return whether the given keyboard key is pressed.
 export fn keyPress(key: c_int) bool {
@@ -83,22 +77,22 @@ export fn loadAnimation(name: [*:0]const u8) extern struct {
     }) catch unreachable;
     defer allocator.free(anim_file);
     const length = count(u8, anim_file, "\t") - 1;
-    var anim = tokenize(anim_file, "\n");
+    var anim = tokenize(u8, anim_file, "\n");
     _ = anim.next().?; // ignore field names
 
     const frames = allocator.alloc(Frame, length) catch unreachable;
     for (frames) |*frame| {
-        var values = tokenize(anim.next().?, "\t");
+        var values = tokenize(u8, anim.next().?, "\t");
         const frame_file = readFile(dir, "{s}{c}frames{c}{s}.tsv", .{
             name, sep, sep, values.next().?, // $animation/frames/$frame.tsv
         }) catch unreachable;
         defer allocator.free(frame_file);
         frame.speed = parseFloat(f32, values.next().?) catch unreachable;
 
-        var joints = tokenize(frame_file, "\n");
+        var joints = tokenize(u8, frame_file, "\n");
         _ = joints.next().?; // ignore field names
         for (frame.joints) |*joint| {
-            var coordinates = tokenize(joints.next().?, "\t");
+            var coordinates = tokenize(u8, joints.next().?, "\t");
             joint.* = .{
                 .x = parseFloat(f32, coordinates.next().?) catch unreachable,
                 .y = parseFloat(f32, coordinates.next().?) catch unreachable,
@@ -129,7 +123,7 @@ const Joint = extern struct {
     parent: i8,
 
     pub fn load(self: *Joint, row: []const u8) !void {
-        var values = tokenize(row, "\t");
+        var values = tokenize(u8, row, "\t");
         self.x = try parseFloat(f32, values.next().?);
         self.y = try parseFloat(f32, values.next().?);
         self.z = try parseFloat(f32, values.next().?);
@@ -146,7 +140,7 @@ export fn loadJoints(joints: [*]Joint) void {
     const file = readFile(cwd(), data_dir ++ "joints.tsv", .{})
         catch unreachable;
     defer allocator.free(file);
-    var tsv = tokenize(file, "\n");
+    var tsv = tokenize(u8, file, "\n");
     _ = tsv.next().?; // ignore field names
     var i = @as(u8, 0);
     while (tsv.next()) |row| : (i += 1)
@@ -167,7 +161,7 @@ const OffIterator = struct {
     token_iterator: TokenIterator,
 
     pub fn init(buffer: []const u8) OffIterator {
-        var self = .{ .token_iterator = tokenize(buffer, "\n") };
+        var self = .{ .token_iterator = tokenize(u8, buffer, "\n") };
         if (!endsWith(u8, self.token_iterator.next().?, "OFF"))
             self.token_iterator.reset();
         return self;
@@ -175,7 +169,7 @@ const OffIterator = struct {
 
     pub fn next(self: *OffIterator) ?TokenIterator {
         while (self.token_iterator.next()) |line| {
-            var words = tokenize(line, " ");
+            var words = tokenize(u8, line, " ");
             if (words.next()) |word| { // not empty
                 if (!startsWith(u8, word, "#")) { // not comment
                     words.reset();
@@ -250,7 +244,7 @@ const Muscle = extern struct {
     parent2: i8,
 
     pub fn load(self: *Muscle, row: []const u8) !void {
-        var values = tokenize(row, "\t");
+        var values = tokenize(u8, row, "\t");
         self.length = try parseFloat(f32, values.next().?);
         self.initlen = try parseFloat(f32, values.next().?);
         self.minlen = try parseFloat(f32, values.next().?);
@@ -267,7 +261,7 @@ export fn loadMuscles(muscles: [*]Muscle) void {
     const file = readFile(cwd(), data_dir ++ "muscles.tsv", .{})
         catch unreachable;
     defer allocator.free(file);
-    var tsv = tokenize(file, "\n");
+    var tsv = tokenize(u8, file, "\n");
     _ = tsv.next().?; // ignore field names
     var i = @as(u8, 0);
     while (tsv.next()) |row| : (i += 1)
@@ -322,7 +316,7 @@ fn check(errorString: fn (c_uint) callconv(.C) [*c]const u8,
 }
 
 /// Load PNG file into an OpenGL buffer and return it.
-export fn loadTexture(filename: [*:0]const u8) GLuint {
+export fn loadTexture(filename: [*:0]const u8) c.GLuint {
     const file = readFile(cwd(), data_dir ++ "textures{c}{s}", .{
         sep, filename,
     }) catch unreachable;
@@ -331,32 +325,33 @@ export fn loadTexture(filename: [*:0]const u8) GLuint {
     var data: [*c]u8 = undefined;
     var w: c_uint = undefined;
     var h: c_uint = undefined;
-    check(lodepng_error_text,
-          lodepng_decode32(&data, &w, &h, file.ptr, file.len));
+    check(c.lodepng_error_text,
+          c.lodepng_decode32(&data, &w, &h, file.ptr, file.len));
     defer free(data);
 
-    var texture: GLuint = undefined;
-    glGenTextures(1, &texture);
-    glBindTexture(GL_TEXTURE_2D, texture);
-    defer glBindTexture(GL_TEXTURE_2D, 0);
-    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-
-    const width = @intCast(GLint, w);
-    const height = @intCast(GLint, h);
-    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-    glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height,
-                 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
-    check(gluErrorString, gluBuild2DMipmaps(GL_TEXTURE_2D, 4, width, height,
-                                            GL_RGBA, GL_UNSIGNED_BYTE, data));
+    var texture: c.GLuint = undefined;
+    c.glGenTextures(1, &texture);
+    c.glBindTexture(c.GL_TEXTURE_2D, texture);
+    defer c.glBindTexture(c.GL_TEXTURE_2D, 0);
+    c.glTexEnvi(c.GL_TEXTURE_ENV, c.GL_TEXTURE_ENV_MODE, c.GL_MODULATE);
+    c.glTexParameteri(c.GL_TEXTURE_2D, c.GL_TEXTURE_MAG_FILTER, c.GL_LINEAR);
+    c.glTexParameteri(c.GL_TEXTURE_2D, c.GL_TEXTURE_MIN_FILTER, c.GL_LINEAR);
+
+    const width = @intCast(c.GLint, w);
+    const height = @intCast(c.GLint, h);
+    c.glPixelStorei(c.GL_UNPACK_ALIGNMENT, 1);
+    c.glTexImage2D(c.GL_TEXTURE_2D, 0, 4, width, height,
+                 0, c.GL_RGBA, c.GL_UNSIGNED_BYTE, data);
+    check(c.gluErrorString,
+          c.gluBuild2DMipmaps(c.GL_TEXTURE_2D, 4, width, height,
+                              c.GL_RGBA, c.GL_UNSIGNED_BYTE, data));
     return texture;
 }
 
 /// Move sound source to given position and play it.
 export fn playSound(source: u32, x: f32, y: f32, z: f32) void {
     const src = al.Source{ .reference = source };
-    _ = alGetError(); // TODO: remove when completely migrate to zeal
+    _ = c.alGetError(); // TODO: remove when completely migrate to zeal
     src.setPosition(.{ x / 32, y / 32, z / 32 }) catch unreachable;
     src.play() catch unreachable;
 }