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 # Backlog
zig version: 0.14 zig version: 0.15.1
Backlog Labs Game Engine. Backlog Labs Game Engine.
run tools/scripts/first-time-setup.py 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 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
/// --------------------------------------------------------

16
lib/cimgui/build.zig vendored
View File

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

63
lib/enet/build.zig vendored
View File

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

View File

@ -113,7 +113,7 @@ pub fn main() !void {
if (!connected) break; if (!connected) break;
// Small delay between messages // 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 // Disconnect if still connected

View File

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

View File

@ -5,14 +5,20 @@ pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{}); const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{}); const optimize = b.standardOptimizeOption(.{});
var nwbuild = Backlog.init(b, .{ var blbuild = Backlog.init(b, .{
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
}); });
_ = nwbuild.addProgram(.{ const testAll = blbuild.addProgram(.{
.name = "tests", .name = "tests",
.desc = "a test runner that runs every single module test", .desc = "a test runner that runs every single module test",
.root_source_file = b.path("test-all.zig"), .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", .version = "0.0.0",
.dependencies = .{ .dependencies = .{
// engine libraries // engine libraries
@ -9,4 +9,5 @@
.paths = .{ .paths = .{
"", "",
}, },
.fingerprint = 0x1260fc5eb99f7cca,
} }

View File

@ -29,8 +29,6 @@ def run(cmd, cwd=None):
def buildAndPackage(branch, target, deploy): def buildAndPackage(branch, target, deploy):
run(['zig', 'env']) 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: if deploy is not None:
@ -45,7 +43,15 @@ def buildAndPackage(branch, target, deploy):
binariesDeploy = f'{path}/binaries/{branch}/{deploy}' binariesDeploy = f'{path}/binaries/{branch}/{deploy}'
def makePackage(target, branch, deploy, tag): 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 {binariesDeploy}'])
run(['ssh', host, f'mkdir -p {sampleGameDeploy}']) 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) 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, 'debug')
makePackage(target, branch, deploy, 'release') makePackage(target, branch, deploy, 'release')