Refactor addon system: derive module list from build.zig, prune inactive prefixes at runtime
- Eliminate hardcoded module_names in addons.zig — now derived from
build.zig via all_module_names build option
- Add module_active.zig runtime registry: main.zig registers isActive
pointers during install(), addons.zig queries them without importing
each module directly
- Prune embedded file prefixes at startup: after all modules claim
mutexes, build a runtime active_prefixes table excluding modules we
don't own. findEmbeddedFile searches only active entries — no
per-lookup isActive check on the hot path
- Tag both addon and asset prefixes with module_name so pruning applies
to all embedded files for a module
- Rename src/markers/ → src/worldmarkers/, src/outline/api.zig →
src/outline/outline.zig to follow {name}/{name}.zig convention
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
// Runtime registry for module isActive() function pointers.
|
||||
// Populated by main.zig during install(), queried by addons.zig during login.
|
||||
// Exists solely to avoid duplicating module imports in addons.zig.
|
||||
|
||||
const std = @import("std");
|
||||
|
||||
const MAX = 32;
|
||||
var names: [MAX][*:0]const u8 = undefined;
|
||||
var fns: [MAX]*const fn () bool = undefined;
|
||||
var count: usize = 0;
|
||||
|
||||
/// Register a module's isActive function. Called from main.zig install().
|
||||
pub fn register(name: [*:0]const u8, f: *const fn () bool) void {
|
||||
if (count >= MAX) return;
|
||||
names[count] = name;
|
||||
fns[count] = f;
|
||||
count += 1;
|
||||
}
|
||||
|
||||
/// Check if a module is active by name. Returns true if unknown (no isActive).
|
||||
pub fn isActive(name: [*:0]const u8) bool {
|
||||
for (0..count) |i| {
|
||||
if (std.mem.orderZ(u8, names[i], name) == .eq) return fns[i]();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user