diff options
-rw-r--r-- | data/config.ini (renamed from src/config.ini) | 0 | ||||
-rw-r--r-- | src/config.zig | 13 | ||||
-rw-r--r-- | src/main.zig | 27 |
3 files changed, 23 insertions, 17 deletions
diff --git a/src/config.ini b/data/config.ini index fdd3793..fdd3793 100644 --- a/src/config.ini +++ b/data/config.ini diff --git a/src/config.zig b/src/config.zig index 2ecb69b..dbe0f7d 100644 --- a/src/config.zig +++ b/src/config.zig @@ -16,9 +16,10 @@ // You should have received a copy of the GNU General Public License // along with Black Shades. If not, see <https://www.gnu.org/licenses/>. -const Allocator = std.mem.Allocator; +const allocator = std.heap.c_allocator; const createFile = std.fs.createFileAbsolute; const cwd = std.fs.cwd; +const data_dir = @import("build_options").data_dir; const eql = std.mem.eql; const ini = @import("ini"); const join = std.fs.path.join; @@ -46,16 +47,18 @@ pub const Config = extern struct { }; /// Parse config.ini in the given base directory. -pub fn parse(allocator: *Allocator, base_dir: []const u8) !Config { +pub fn parse(base_dir: []const u8) !Config { const config_dir = try join(allocator, &.{ base_dir, "blackshades" }); defer allocator.free(config_dir); var dir = try cwd().makeOpenPath(config_dir, .{}); defer dir.close(); var config = Config{}; - const input = dir.openFile("config.ini", .{}) catch { - try dir.writeFile("config.ini", @embedFile("config.ini")); - return config; + const input = dir.openFile("config.ini", .{}) catch blk: { + var source = try cwd().makeOpenPath(data_dir, .{}); + defer source.close(); + try source.copyFile("config.ini", dir, "config.ini", .{}); + break :blk try dir.openFile("config.ini", .{}); }; defer input.close(); diff --git a/src/main.zig b/src/main.zig index d7a1da1..d40f012 100644 --- a/src/main.zig +++ b/src/main.zig @@ -19,37 +19,40 @@ const Loca = @import("loca").Loca; const al = @import("zeal"); const allocator = @import("std").heap.c_allocator; +const c = @cImport({ + @cInclude("Game.h"); + @cInclude("Constants.h"); +}); const configuration = @import("config.zig"); const gf = @import("gfz"); const gl = @import("zgl"); -const legacy = @cImport(@cInclude("Game.h")); const misc = @import("misc.zig"); -var game: *legacy.Game = undefined; +var game: *c.Game = undefined; fn resizeWindow(window: ?*gf.Window.Impl, width: c_int, height: c_int) callconv(.C) void { - legacy.resizeWindow(game, width, height); + c.resizeWindow(game, width, height); } fn handleKey(window: ?*gf.Window.Impl, key: c_int, scancode: c_int, action: c_int, mods: c_int) callconv(.C) void { - legacy.handleKey(game, key, action, mods); + c.handleKey(game, key, action, mods); } fn look(window: ?*gf.Window.Impl, xpos: f64, ypos: f64) callconv(.C) void { - legacy.look(game, xpos, ypos); + c.look(game, xpos, ypos); } fn click(window: ?*gf.Window.Impl, button: c_int, action: c_int, mods: c_int) callconv(.C) void { - legacy.click(game, button, action, mods); + c.click(game, button, action, mods); } pub fn main() !void { const loca = try Loca.init(allocator, .{}); defer loca.deinit(); - const config = try configuration.parse(allocator, loca.user_config); + const config = try configuration.parse(loca.user_config); try gf.init(); defer gf.deinit() catch unreachable; @@ -57,10 +60,10 @@ pub fn main() !void { "Black Shades", .{}, .{}); try window.makeCurrent(); - game = legacy.makeGame(@bitCast(legacy.Config, config)).?; + game = c.makeGame(@bitCast(c.Config, config)).?; try window.setSizeCallback(resizeWindow); try gf.swapInterval(@boolToInt(config.vsync)); - legacy.initGl(game); + c.initGl(game); if (try gf.rawMouseMotionSupported()) try window.setInputMode(.raw_mouse_motion, true); @@ -76,10 +79,10 @@ pub fn main() !void { defer context.deinit() catch unreachable; try context.makeCurrent(); - legacy.initGame(game); - defer legacy.closeGame(game); + c.initGame(game); + defer c.closeGame(game); while (!try window.shouldClose()) { - legacy.eventLoop(game); + c.eventLoop(game); try window.swapBuffers(); try gf.pollEvents(); } |