build: move map & rng logic to their own libraries
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I1802469f3baff4576f61accfb5a197d86a6a6964
This commit is contained in:
parent
702b4258e0
commit
ef0a20c1f8
11 changed files with 68 additions and 20 deletions
72
build.zig
72
build.zig
|
|
@ -4,6 +4,56 @@ pub fn build(b: *std.Build) void {
|
|||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
const c_flags = [_][]const u8{
|
||||
"-std=c99",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-O2",
|
||||
};
|
||||
|
||||
// RNG library
|
||||
const rng_lib = b.addLibrary(.{
|
||||
.name = "rng",
|
||||
.root_module = b.createModule(.{
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
.link_libc = true,
|
||||
}),
|
||||
});
|
||||
rng_lib.addCSourceFiles(.{
|
||||
.files = &[_][]const u8{"libs/rng/rng.c"},
|
||||
.flags = &c_flags,
|
||||
});
|
||||
rng_lib.addIncludePath(b.path("libs/rng"));
|
||||
|
||||
// Map library
|
||||
const map_lib = b.addLibrary(.{
|
||||
.name = "map",
|
||||
.root_module = b.createModule(.{
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
.link_libc = true,
|
||||
}),
|
||||
});
|
||||
map_lib.addCSourceFiles(.{
|
||||
.files = &[_][]const u8{
|
||||
"libs/map/map.c",
|
||||
"libs/map/utils.c",
|
||||
},
|
||||
.flags = &c_flags,
|
||||
});
|
||||
// map.h includes common.h and settings.h which live in src/
|
||||
map_lib.addIncludePath(b.path("src"));
|
||||
// map.c includes rng/rng.h via libs/ root
|
||||
map_lib.addIncludePath(b.path("libs"));
|
||||
// utils.h is co-located with map.c
|
||||
map_lib.addIncludePath(b.path("libs/map"));
|
||||
map_lib.linkLibrary(rng_lib);
|
||||
// map.c doesn't call raylib, but common.h (via map.h) includes raylib.h;
|
||||
// add the include path without linking the library into the static archive
|
||||
const raylib_include = std.mem.trim(u8, b.run(&.{ "pkg-config", "--variable=includedir", "raylib" }), "\n ");
|
||||
map_lib.addSystemIncludePath(.{ .cwd_relative = raylib_include });
|
||||
|
||||
// Zig combat library
|
||||
const combat_lib = b.addLibrary(.{
|
||||
.name = "combat",
|
||||
|
|
@ -14,29 +64,22 @@ pub fn build(b: *std.Build) void {
|
|||
.link_libc = true,
|
||||
}),
|
||||
});
|
||||
// common.h and settings.h live in src/; rng.h exposed bare from libs/rng
|
||||
combat_lib.addIncludePath(b.path("src"));
|
||||
combat_lib.addIncludePath(b.path("libs/rng"));
|
||||
combat_lib.linkLibrary(rng_lib);
|
||||
combat_lib.linkSystemLibrary("raylib");
|
||||
|
||||
// C sources (everything except combat, which is now Zig)
|
||||
// C sources remaining in src/
|
||||
const c_sources = [_][]const u8{
|
||||
"src/audio.c",
|
||||
"src/enemy.c",
|
||||
"src/items.c",
|
||||
"src/main.c",
|
||||
"src/map.c",
|
||||
"src/player.c",
|
||||
"src/movement.c",
|
||||
"src/player.c",
|
||||
"src/render.c",
|
||||
"src/rng.c",
|
||||
"src/settings.c",
|
||||
"src/utils.c",
|
||||
};
|
||||
|
||||
const c_flags = [_][]const u8{
|
||||
"-std=c99",
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-O2",
|
||||
};
|
||||
|
||||
// Main executable
|
||||
|
|
@ -54,7 +97,12 @@ pub fn build(b: *std.Build) void {
|
|||
.flags = &c_flags,
|
||||
});
|
||||
|
||||
// src/ for own headers; libs/ so "rng/rng.h" and "map/map.h" resolve
|
||||
exe.addIncludePath(b.path("src"));
|
||||
exe.addIncludePath(b.path("libs"));
|
||||
|
||||
exe.linkLibrary(rng_lib);
|
||||
exe.linkLibrary(map_lib);
|
||||
exe.linkLibrary(combat_lib);
|
||||
exe.linkSystemLibrary("raylib");
|
||||
exe.linkSystemLibrary("m");
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#include "map.h"
|
||||
#include "rng.h"
|
||||
#include "rng/rng.h"
|
||||
#include "settings.h"
|
||||
#include "utils.h"
|
||||
#include <stdlib.h>
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
#include "enemy.h"
|
||||
#include "combat.h"
|
||||
#include "common.h"
|
||||
#include "map.h"
|
||||
#include "map/map.h"
|
||||
#include "movement.h"
|
||||
#include "rng.h"
|
||||
#include "rng/rng.h"
|
||||
#include "settings.h"
|
||||
#include <string.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include "common.h"
|
||||
#include "map.h"
|
||||
#include "rng.h"
|
||||
#include "map/map.h"
|
||||
#include "rng/rng.h"
|
||||
#include "settings.h"
|
||||
#include <stddef.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@
|
|||
#include "common.h"
|
||||
#include "enemy.h"
|
||||
#include "items.h"
|
||||
#include "map.h"
|
||||
#include "map/map.h"
|
||||
#include "movement.h"
|
||||
#include "player.h"
|
||||
#include "raylib.h"
|
||||
#include "render.h"
|
||||
#include "rng.h"
|
||||
#include "rng/rng.h"
|
||||
#include "settings.h"
|
||||
#include <ctype.h>
|
||||
#include <stddef.h>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include "movement.h"
|
||||
#include "enemy.h"
|
||||
#include "map.h"
|
||||
#include "map/map.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
// Check if position is occupied by player
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue