finished enet

This commit is contained in:
peterino2 2025-10-13 17:53:42 -07:00
parent 8024469d79
commit 179bbf0eef
9 changed files with 79 additions and 38 deletions

View File

@ -1,10 +1,19 @@
# Backlog
zig version: 0.14
zig version: 0.15.1
Backlog Labs Game Engine.
run tools/scripts/first-time-setup.py
ffmpeg -i INPUT.mp4 -c:v libtheora -q:v 7 -c:a libvorbis -q:a 4 OUTPUT.ogv
/// --------------------------------------------------------
void* malloc(size_t size); // gives you a pointer to a memory buffer of size
void free(void* ptr); // releases a pointer to memory
/// --------------------------------------------------------

View File

@ -19,10 +19,12 @@ pub fn build(b: *std.Build) void {
mod.addIncludePath(b.path("cimplot"));
mod.addIncludePath(b.path("cimplot/implot"));
const cimgui = b.addStaticLibrary(.{
const cimgui = b.addLibrary(.{
.name = "cimgui",
.target = target,
.root_module = b.createModule(.{
.optimize = optimize,
.target = target,
}),
});
cimgui.linkLibC();
@ -68,9 +70,11 @@ pub fn build(b: *std.Build) void {
// I can seperate it out later if needed.
const test_step = b.step("test", "run unit tests for imgui");
const tests = b.addTest(.{
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.root_source_file = b.path("tests/tests.zig"),
}),
});
tests.root_module.addImport("cimgui", mod);

41
lib/enet/build.zig vendored
View File

@ -7,14 +7,23 @@ pub fn build(b: *std.Build) void {
_ = static_build;
// am i good to always have enet as static?
const enet = if (true) b.addStaticLibrary(.{
.name = "enet_c",
.target = target,
.optimize = optimize,
}) else b.addSharedLibrary(.{
// const enet = if (true) b.addStaticLibrary(.{
// .name = "enet_c",
// .target = target,
// .optimize = optimize,
// }) else b.addSharedLibrary(.{
// .name = "enet_c",
// .target = target,
// .optimize = optimize,
// });
const enet = b.addLibrary(.{
.name = "enet_c",
.linkage = .static,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
}),
});
enet.linkLibC();
@ -64,11 +73,14 @@ pub fn build(b: *std.Build) void {
const test_step = b.step("test", "run unit tests for enet");
const tests = b.addTest(.{
.root_module = b.createModule(.{
.link_libc = true,
.target = target,
.optimize = optimize,
.root_source_file = b.path("src/tests.zig"),
.link_libc = true,
}),
});
tests.root_module.addImport("enet", mod);
tests.root_module.addIncludePath(b.path("enet-1.3.18/include/"));
const runArtifact = b.addRunArtifact(tests);
@ -77,9 +89,11 @@ pub fn build(b: *std.Build) void {
// Test server executable
const test_server = b.addExecutable(.{
.name = "test-server",
.root_module = b.createModule(.{
.root_source_file = b.path("src/test_server.zig"),
.target = target,
.optimize = optimize,
}),
});
test_server.root_module.addImport("enet", mod);
test_server.linkLibC();
@ -87,9 +101,11 @@ pub fn build(b: *std.Build) void {
// Test client executable
const test_client = b.addExecutable(.{
.name = "test-client",
.root_module = b.createModule(.{
.root_source_file = b.path("src/test_client.zig"),
.target = target,
.optimize = optimize,
}),
});
test_client.root_module.addImport("enet", mod);
test_client.linkLibC();
@ -172,7 +188,7 @@ const LoopbackTestStep = struct {
}
// Give server time to start
std.time.sleep(1 * std.time.ns_per_s);
std.Thread.sleep(1 * std.time.ns_per_s);
// Start the client process
std.debug.print("Starting test client...\n", .{});
@ -186,7 +202,7 @@ const LoopbackTestStep = struct {
const client_result = try client_process.wait();
// Give server a moment to process the quit message and shut down naturally
std.time.sleep(2 * std.time.ns_per_s);
std.Thread.sleep(2 * std.time.ns_per_s);
// Check if server is still running and terminate if needed
const server_result = server_process.wait() catch {
@ -197,15 +213,16 @@ const LoopbackTestStep = struct {
// Read and display output
if (client_process.stdout) |stdout| {
const client_output = try stdout.reader().readAllAlloc(allocator, 8192);
const client_output = try stdout.readToEndAlloc(allocator, 8192);
defer allocator.free(client_output);
std.debug.print("\n=== CLIENT OUTPUT ===\n{s}\n", .{client_output});
}
if (server_process.stdout) |stdout| {
const server_output = try stdout.reader().readAllAlloc(allocator, 8192);
defer allocator.free(server_output);
std.debug.print("\n=== SERVER OUTPUT ===\n{s}\n", .{server_output});
const output = try stdout.readToEndAlloc(allocator, 8192);
// const server_output = try stdout.readToEndAlloc.read(allocator, 8192);
defer allocator.free(output);
std.debug.print("\n=== SERVER OUTPUT ===\n{s}\n", .{output});
}
std.debug.print("\n=== LOOPBACK TEST RESULTS ===\n", .{});

View File

@ -113,7 +113,7 @@ pub fn main() !void {
if (!connected) break;
// Small delay between messages
std.time.sleep(100 * std.time.ns_per_ms);
std.Thread.sleep(100 * std.time.ns_per_ms);
}
// Disconnect if still connected

View File

@ -77,7 +77,6 @@ pub fn build(b: *std.Build) void {
.desc = "headless program, core-only",
.root_source_file = b.path("headless/main.zig"),
});
std.debug.print("headless", .{});
headless.setModuleEnabled("assets", false);
headless.setModuleEnabled("platform", false);

View File

@ -5,14 +5,20 @@ pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
var nwbuild = Backlog.init(b, .{
var blbuild = Backlog.init(b, .{
.target = target,
.optimize = optimize,
});
_ = nwbuild.addProgram(.{
const testAll = blbuild.addProgram(.{
.name = "tests",
.desc = "a test runner that runs every single module test",
.root_source_file = b.path("test-all.zig"),
});
testAll.setModuleEnabled("assets", false);
testAll.setModuleEnabled("platform", false);
testAll.setModuleEnabled("audio", false);
testAll.setModuleEnabled("net", false);
testAll.setModuleEnabled("rend", false);
}

View File

@ -1,5 +1,5 @@
.{
.name = "tests",
.name = .tests,
.version = "0.0.0",
.dependencies = .{
// engine libraries
@ -9,4 +9,5 @@
.paths = .{
"",
},
.fingerprint = 0x1260fc5eb99f7cca,
}

View File

@ -29,8 +29,6 @@ def run(cmd, cwd=None):
def buildAndPackage(branch, target, deploy):
run(['zig', 'env'])
run(['zig', 'build', f'-Dtarget={target}', '--prefix', 'zig-out-debug', 'install'])
run(['zig', 'build', f'-Dtarget={target}', '-Dstatic_build', '-Doptimize=ReleaseSafe', '--prefix', 'zig-out-release', 'install'])
if deploy is not None:
@ -45,7 +43,15 @@ def buildAndPackage(branch, target, deploy):
binariesDeploy = f'{path}/binaries/{branch}/{deploy}'
def makePackage(target, branch, deploy, tag):
buildCmd = ['zig', 'build', f'-Dtarget={target}', '--prefix', f'zig-out-{tag}', 'install']
if tag == 'release':
buildCmd += ['-Dstatic_build']
if tag == 'release-optimized':
buildCmd += ['-Dstatic_build', '-Doptimize=ReleaseSafe']
run(buildCmd)
run(['ssh', host, f'mkdir -p {binariesDeploy}'])
run(['ssh', host, f'mkdir -p {sampleGameDeploy}'])
@ -86,7 +92,6 @@ def buildAndPackage(branch, target, deploy):
shutil.copy(os.path.join(f'zig-out-{tag}/modules', f), f"staging/sampleGame/zig-out/modules/" + f)
makePackage(target, branch, deploy, 'debug')
makePackage(target, branch, deploy, 'release')