This commit is contained in:
Vicente Ferrari Smith 2026-02-02 11:12:50 +01:00
parent b91bce8840
commit 510c19fbd5
3 changed files with 62 additions and 95 deletions

View File

@ -29,8 +29,6 @@ var running: bool = true;
var dbg_allocator = std.heap.DebugAllocator(.{}){}; var dbg_allocator = std.heap.DebugAllocator(.{}){};
// var connection: ?std.net.Stream = undefined;
pub fn main() !void { pub fn main() !void {
const tracy_zone = tracy.ZoneNC(@src(), "main", 0x00_ff_00_00); const tracy_zone = tracy.ZoneNC(@src(), "main", 0x00_ff_00_00);
defer tracy_zone.End(); defer tracy_zone.End();
@ -79,60 +77,21 @@ pub fn main() !void {
} }
font.shader = rl.LoadShader(null, "assets/text.frag"); font.shader = rl.LoadShader(null, "assets/text.frag");
// const test_shader1 = try c.LoadShader(null, "assets/test_1.frag"); // const test_shader1 = try rl.LoadShader(null, "assets/test_1.frag");
// const test_shader2 = try c.LoadShader(null, "assets/test_2.frag"); // const test_shader2 = try rl.LoadShader(null, "assets/test_2.frag");
// font.shader = try rl.loadShader(null, "assets/text.frag"); const host = enet.enet_host_create(null, 32, 2, 0, 0);
// const test_shader1 = try rl.loadShader(null, "assets/test_1.frag"); defer enet.enet_host_destroy(host);
// const test_shader2 = try rl.loadShader(null, "assets/test_2.frag");
// const img = rl.genImageColor(32, 32, .blank); var address = enet.ENetAddress{ .port = shared.protocol.SERVER_PORT };
// const tx = try rl.loadTextureFromImage(img); _ = enet.enet_address_set_host(&address, "localhost");
// rl.unloadImage(img);
// const host = try znet.Host.init(.{ const peer = enet.enet_host_connect(host, &address, 2, 0);
// .addr = null, defer enet.enet_peer_reset(peer);
// .peer_limit = 1,
// .channel_limit = .max,
// .incoming_bandwidth = .unlimited,
// .outgoing_bandwidth = .unlimited,
// });
// defer host.deinit();
// const peer = try host.connect(.{
// .addr = try .init(.{
// .ip = .{ .ipv4 = "127.0.0.1" },
// .port = .{ .uint = 5000 },
// }),
// .channel_limit = .max,
// .data = 0,
// });
// connect() catch |err| switch (err) {
// error.ConnectionRefused => {
// std.log.err("server refused connection", .{});
// },
// else => {
// std.log.err("unexpected connect error: {}", .{err});
// return err;
// },
// };
// try stdout.flush();
var the_chunk = try shared.chunk.initChunk(allocator); var the_chunk = try shared.chunk.initChunk(allocator);
defer shared.chunk.deinitChunk(&the_chunk, allocator); defer shared.chunk.deinitChunk(&the_chunk, allocator);
// var send_buf: [1024]u8 = undefined;
// var writer = if (connection) |*conn| conn.writer(&send_buf) else return;
// try shared.protocol.sendHello(&writer.interface, .{ .msg = "Hello from client" });
// var recv_buf: [1024]u8 = undefined;
// var reader = if (connection) |*conn| conn.reader(&recv_buf) else return;
// const line = try reader.interface().takeDelimiterExclusive('\n');
// std.log.info("{s}", .{line});
// const camera = rl.Camera{ // const camera = rl.Camera{
// .fovy = 45, // .fovy = 45,
// .position = .{ .x = 0, .y = 0, .z = 10 }, // .position = .{ .x = 0, .y = 0, .z = 10 },
@ -157,7 +116,7 @@ pub fn main() !void {
var old_time : f32 = @floatCast(rl.GetTime()); var old_time : f32 = @floatCast(rl.GetTime());
while (!rl.WindowShouldClose()) { while (!rl.WindowShouldClose()) {
const tracy_main_zone = tracy.ZoneNC(@src(), "loop", 0x00_ff_00_00); const tracy_main_zone = tracy.ZoneNC(@src(), "loop", 0x00_aa_33_10);
defer tracy_main_zone.End(); defer tracy_main_zone.End();
const new_time : f32 = @floatCast(rl.GetTime()); const new_time : f32 = @floatCast(rl.GetTime());
@ -171,27 +130,21 @@ pub fn main() !void {
accumulator += frame_time * k; accumulator += frame_time * k;
// while (try host.service(0)) |event| switch (event) { var event = enet.ENetEvent{};
// .connect => |data| { while (enet.enet_host_service(host, &event, 0) > 0) {
// _ = data; switch (event.type) {
// // std.log.info("{}", .{data.peer}); enet.ENET_EVENT_TYPE_CONNECT => {
// }, std.log.info("connect", .{});
// .disconnect => |data| { },
// _ = data; enet.ENET_EVENT_TYPE_RECEIVE => {
// // std.log.info("{}", .{data.peer}); std.log.info("receive", .{});
// }, },
// .receive => |data| { enet.ENET_EVENT_TYPE_DISCONNECT => {
// defer data.packet.deinit(); std.log.info("disconnect", .{});
},
// const slice = data.packet.dataSlice(); else => {}
}
// var reader = bufzilla.Reader(.{}).init(slice); }
// const id = try reader.readPath("id");
// std.log.info("{any}", .{id});
// },
// };
rl.PollInputEvents(); rl.PollInputEvents();

View File

@ -33,13 +33,13 @@ pub fn main() !void {
std.log.info("Failed to load ENet", .{}); std.log.info("Failed to load ENet", .{});
return; return;
} }
defer enet.enet_deinitialize(); defer enet.enet_deinitialize();
const address = enet.ENetAddress{ .host = enet.ENET_HOST_ANY, .port = shared.protocol.SERVER_PORT }; const address = enet.ENetAddress{ .host = enet.ENET_HOST_ANY, .port = shared.protocol.SERVER_PORT };
var host : ?*enet.ENetHost = null; const host = enet.enet_host_create(&address, 32, 2, 0, 0);
if (host == null) {
host = enet.enet_host_create(&address, 32, 2, 0, 0); @panic("host is null");
}
defer enet.enet_host_destroy(host); defer enet.enet_host_destroy(host);
var the_chunk = try shared.chunk.initChunk(allocator); var the_chunk = try shared.chunk.initChunk(allocator);
@ -62,33 +62,18 @@ pub fn main() !void {
while (enet.enet_host_service(host, &event, 0) > 0) { while (enet.enet_host_service(host, &event, 0) > 0) {
switch (event.type) { switch (event.type) {
enet.ENET_EVENT_TYPE_CONNECT => { enet.ENET_EVENT_TYPE_CONNECT => {
std.log.info("hello", .{}); std.log.info("connect", .{});
}, },
enet.ENET_EVENT_TYPE_RECEIVE => { enet.ENET_EVENT_TYPE_RECEIVE => {
std.log.info("hello", .{}); std.log.info("receive", .{});
}, },
enet.ENET_EVENT_TYPE_DISCONNECT => { enet.ENET_EVENT_TYPE_DISCONNECT => {
std.log.info("hello", .{}); std.log.info("disconnect", .{});
}, },
else => {} else => {}
} }
} }
// while (try server.host.service(0)) |event| switch (event) {
// .connect => |data| {
// _ = data;
// // std.log.info("{}", .{data.peer});
// },
// .disconnect => |data| {
// _ = data;
// // std.log.info("{}", .{data.peer});
// },
// .receive => |data| {
// std.log.info("{s}", .{data.packet.dataSlice()});
// defer data.packet.deinit();
// },
// };
// const connection = try tcp_server.accept(); // const connection = try tcp_server.accept();
// defer connection.stream.close(); // defer connection.stream.close();

31
vendor/enet/build.zig vendored
View File

@ -1,6 +1,6 @@
const std = @import("std"); const std = @import("std");
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{}); const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{}); const optimize = b.standardOptimizeOption(.{});
@ -15,6 +15,24 @@ pub fn build(b: *std.Build) void {
}), }),
}); });
var flags = try std.ArrayList([]const u8).initCapacity(b.allocator, 0);
switch (target.result.os.tag) {
.linux, .macos => {
try flags.append(b.allocator, "-DHAS_FCNTL=1");
try flags.append(b.allocator, "-DHAS_POLL=1");
try flags.append(b.allocator, "-DHAS_GETADDRINFO=1");
try flags.append(b.allocator, "-DHAS_GETNAMEINFO=1");
try flags.append(b.allocator, "-DHAS_INET_PTON=1");
try flags.append(b.allocator, "-DHAS_INET_NTOP=1");
try flags.append(b.allocator, "-DHAS_MSGHDR_FLAGS=1");
},
else => {},
}
try flags.append(b.allocator, "-DHAS_OFFSETOF=1");
try flags.append(b.allocator, "-DHAS_SOCKLEN_T=1");
lib.root_module.addCSourceFiles(.{ lib.root_module.addCSourceFiles(.{
.root = enet_src.path(""), .root = enet_src.path(""),
.files = &[_][]const u8{ .files = &[_][]const u8{
@ -28,6 +46,17 @@ pub fn build(b: *std.Build) void {
"unix.c", "unix.c",
"win32.c", "win32.c",
}, },
.flags = &[_][]const u8{
"-DHAS_OFFSETOF=1",
"-DHAS_SOCKLEN_T=1",
"-DHAS_FCNTL=1",
"-DHAS_POLL=1",
"-DHAS_GETADDRINFO=1",
"-DHAS_GETNAMEINFO=1",
"-DHAS_INET_PTON=1",
"-DHAS_INET_NTOP=1",
"-DHAS_MSGHDR_FLAGS=1",
}
}); });