enet
This commit is contained in:
1 parent
b91bce8840
commit
510c19fbd5
3 files changed
+62
-95
No files matched your search
+24
-71
@@ -29,8 +29,6 @@ var running: bool = true;
|
||||
|
||||
var dbg_allocator = std.heap.DebugAllocator(.{}){};
|
||||
|
||||
// var connection: ?std.net.Stream = undefined;
|
||||
|
||||
pub fn main() !void {
|
||||
const tracy_zone = tracy.ZoneNC(@src(), "main", 0x00_ff_00_00);
|
||||
defer tracy_zone.End();
|
||||
@@ -79,60 +77,21 @@ pub fn main() !void {
|
||||
}
|
||||
|
||||
font.shader = rl.LoadShader(null, "assets/text.frag");
|
||||
// const test_shader1 = try c.LoadShader(null, "assets/test_1.frag");
|
||||
// const test_shader2 = try c.LoadShader(null, "assets/test_2.frag");
|
||||
// const test_shader1 = try rl.LoadShader(null, "assets/test_1.frag");
|
||||
// const test_shader2 = try rl.LoadShader(null, "assets/test_2.frag");
|
||||
|
||||
// font.shader = try rl.loadShader(null, "assets/text.frag");
|
||||
// const test_shader1 = try rl.loadShader(null, "assets/test_1.frag");
|
||||
// const test_shader2 = try rl.loadShader(null, "assets/test_2.frag");
|
||||
const host = enet.enet_host_create(null, 32, 2, 0, 0);
|
||||
defer enet.enet_host_destroy(host);
|
||||
|
||||
// const img = rl.genImageColor(32, 32, .blank);
|
||||
// const tx = try rl.loadTextureFromImage(img);
|
||||
// rl.unloadImage(img);
|
||||
var address = enet.ENetAddress{ .port = shared.protocol.SERVER_PORT };
|
||||
_ = enet.enet_address_set_host(&address, "localhost");
|
||||
|
||||
// const host = try znet.Host.init(.{
|
||||
// .addr = null,
|
||||
// .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();
|
||||
const peer = enet.enet_host_connect(host, &address, 2, 0);
|
||||
defer enet.enet_peer_reset(peer);
|
||||
|
||||
var the_chunk = try shared.chunk.initChunk(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{
|
||||
// .fovy = 45,
|
||||
// .position = .{ .x = 0, .y = 0, .z = 10 },
|
||||
@@ -157,7 +116,7 @@ pub fn main() !void {
|
||||
var old_time : f32 = @floatCast(rl.GetTime());
|
||||
|
||||
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();
|
||||
|
||||
const new_time : f32 = @floatCast(rl.GetTime());
|
||||
@@ -171,27 +130,21 @@ pub fn main() !void {
|
||||
accumulator += frame_time * k;
|
||||
|
||||
|
||||
// while (try host.service(0)) |event| switch (event) {
|
||||
// .connect => |data| {
|
||||
// _ = data;
|
||||
// // std.log.info("{}", .{data.peer});
|
||||
// },
|
||||
// .disconnect => |data| {
|
||||
// _ = data;
|
||||
// // std.log.info("{}", .{data.peer});
|
||||
// },
|
||||
// .receive => |data| {
|
||||
// defer data.packet.deinit();
|
||||
|
||||
// const slice = data.packet.dataSlice();
|
||||
|
||||
// var reader = bufzilla.Reader(.{}).init(slice);
|
||||
|
||||
// const id = try reader.readPath("id");
|
||||
|
||||
// std.log.info("{any}", .{id});
|
||||
// },
|
||||
// };
|
||||
var event = enet.ENetEvent{};
|
||||
while (enet.enet_host_service(host, &event, 0) > 0) {
|
||||
switch (event.type) {
|
||||
enet.ENET_EVENT_TYPE_CONNECT => {
|
||||
std.log.info("connect", .{});
|
||||
},
|
||||
enet.ENET_EVENT_TYPE_RECEIVE => {
|
||||
std.log.info("receive", .{});
|
||||
},
|
||||
enet.ENET_EVENT_TYPE_DISCONNECT => {
|
||||
std.log.info("disconnect", .{});
|
||||
},
|
||||
else => {}
|
||||
}
|
||||
}
|
||||
|
||||
rl.PollInputEvents();
|
||||
|
||||
|
||||
+8
-23
@@ -32,14 +32,14 @@ pub fn main() !void {
|
||||
if (enet.enet_initialize() != 0) {
|
||||
std.log.info("Failed to load ENet", .{});
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
defer enet.enet_deinitialize();
|
||||
|
||||
const address = enet.ENetAddress{ .host = enet.ENET_HOST_ANY, .port = shared.protocol.SERVER_PORT };
|
||||
var host : ?*enet.ENetHost = null;
|
||||
|
||||
host = enet.enet_host_create(&address, 32, 2, 0, 0);
|
||||
const host = enet.enet_host_create(&address, 32, 2, 0, 0);
|
||||
if (host == null) {
|
||||
@panic("host is null");
|
||||
}
|
||||
defer enet.enet_host_destroy(host);
|
||||
|
||||
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) {
|
||||
switch (event.type) {
|
||||
enet.ENET_EVENT_TYPE_CONNECT => {
|
||||
std.log.info("hello", .{});
|
||||
std.log.info("connect", .{});
|
||||
},
|
||||
enet.ENET_EVENT_TYPE_RECEIVE => {
|
||||
std.log.info("hello", .{});
|
||||
std.log.info("receive", .{});
|
||||
},
|
||||
enet.ENET_EVENT_TYPE_DISCONNECT => {
|
||||
std.log.info("hello", .{});
|
||||
std.log.info("disconnect", .{});
|
||||
},
|
||||
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();
|
||||
// defer connection.stream.close();
|
||||
|
||||
|
||||
Reference in new issue
Block a user