w/e
This commit is contained in:
parent
c41f8866d9
commit
6d69fa8898
90
build.zig
90
build.zig
@ -46,6 +46,8 @@ pub fn build(b: *std.Build) void {
|
|||||||
});
|
});
|
||||||
server.root_module.strip = true;
|
server.root_module.strip = true;
|
||||||
|
|
||||||
|
// ztracy
|
||||||
|
{
|
||||||
const ztracy = b.dependency(
|
const ztracy = b.dependency(
|
||||||
"ztracy",
|
"ztracy",
|
||||||
.{
|
.{
|
||||||
@ -56,14 +58,20 @@ pub fn build(b: *std.Build) void {
|
|||||||
);
|
);
|
||||||
client.root_module.addImport("ztracy", ztracy.module("root"));
|
client.root_module.addImport("ztracy", ztracy.module("root"));
|
||||||
client.linkLibrary(ztracy.artifact("tracy"));
|
client.linkLibrary(ztracy.artifact("tracy"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// mach-freetype
|
||||||
|
{
|
||||||
const mach_freetype = b.dependency("mach_freetype", .{
|
const mach_freetype = b.dependency("mach_freetype", .{
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
client.root_module.addImport("mach-freetype", mach_freetype.module("mach-freetype"));
|
client.root_module.addImport("mach-freetype", mach_freetype.module("mach-freetype"));
|
||||||
client.root_module.addImport("mach-harfbuzz", mach_freetype.module("mach-harfbuzz"));
|
client.root_module.addImport("mach-harfbuzz", mach_freetype.module("mach-harfbuzz"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// kb_text_shape
|
||||||
|
{
|
||||||
client.root_module.addCSourceFile(.{
|
client.root_module.addCSourceFile(.{
|
||||||
.file = b.path("vendor/kb_text_shape/kb_text_shape.h"),
|
.file = b.path("vendor/kb_text_shape/kb_text_shape.h"),
|
||||||
.language = .c,
|
.language = .c,
|
||||||
@ -82,7 +90,10 @@ pub fn build(b: *std.Build) void {
|
|||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
client.root_module.addImport("kb", kb_text_shape.createModule());
|
client.root_module.addImport("kb", kb_text_shape.createModule());
|
||||||
|
}
|
||||||
|
|
||||||
|
// stb_rect_pack
|
||||||
|
{
|
||||||
client.root_module.addCSourceFile(.{ .file = b.path("vendor/stb/stb_rect_pack.h"), .language = .c, .flags = &.{} });
|
client.root_module.addCSourceFile(.{ .file = b.path("vendor/stb/stb_rect_pack.h"), .language = .c, .flags = &.{} });
|
||||||
const stb_rect_pack = b.addTranslateC(.{
|
const stb_rect_pack = b.addTranslateC(.{
|
||||||
.root_source_file = b.path("vendor/stb/stb_rect_pack.h"),
|
.root_source_file = b.path("vendor/stb/stb_rect_pack.h"),
|
||||||
@ -90,7 +101,10 @@ pub fn build(b: *std.Build) void {
|
|||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
client.root_module.addImport("stb_rect_pack", stb_rect_pack.createModule());
|
client.root_module.addImport("stb_rect_pack", stb_rect_pack.createModule());
|
||||||
|
}
|
||||||
|
|
||||||
|
// zmath
|
||||||
|
{
|
||||||
const zmath = b.dependency(
|
const zmath = b.dependency(
|
||||||
"zmath",
|
"zmath",
|
||||||
.{
|
.{
|
||||||
@ -101,17 +115,68 @@ pub fn build(b: *std.Build) void {
|
|||||||
client.root_module.addImport("zmath", zmath.module("root"));
|
client.root_module.addImport("zmath", zmath.module("root"));
|
||||||
server.root_module.addImport("zmath", zmath.module("root"));
|
server.root_module.addImport("zmath", zmath.module("root"));
|
||||||
shared.addImport("zmath", zmath.module("root"));
|
shared.addImport("zmath", zmath.module("root"));
|
||||||
|
|
||||||
const znet = b.dependency(
|
|
||||||
"znet",
|
|
||||||
.{
|
|
||||||
.target = target,
|
|
||||||
.optimize = optimize,
|
|
||||||
}
|
}
|
||||||
);
|
|
||||||
client.root_module.addImport("znet", znet.module("znet"));
|
|
||||||
server.root_module.addImport("znet", znet.module("znet"));
|
|
||||||
|
|
||||||
|
|
||||||
|
// ENet
|
||||||
|
{
|
||||||
|
client.addCSourceFiles(.{
|
||||||
|
.root = b.path("vendor/enet"),
|
||||||
|
.files = &[_][]const u8{
|
||||||
|
"callbacks.c",
|
||||||
|
"compress.c",
|
||||||
|
"host.c",
|
||||||
|
"list.c",
|
||||||
|
"packet.c",
|
||||||
|
"peer.c",
|
||||||
|
"protocol.c",
|
||||||
|
"unix.c",
|
||||||
|
"win32.c",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (target.result.os.tag == .windows) {
|
||||||
|
// client.root_module.linkSystemLibrary("ws2_32", .{});
|
||||||
|
// client.root_module.linkSystemLibrary("winmm", .{});
|
||||||
|
}
|
||||||
|
|
||||||
|
client.root_module.addIncludePath(b.path("vendor/enet/include/"));
|
||||||
|
|
||||||
|
server.addCSourceFiles(.{
|
||||||
|
.root = b.path("vendor/enet"),
|
||||||
|
.files = &[_][]const u8{
|
||||||
|
"callbacks.c",
|
||||||
|
"compress.c",
|
||||||
|
"host.c",
|
||||||
|
"list.c",
|
||||||
|
"packet.c",
|
||||||
|
"peer.c",
|
||||||
|
"protocol.c",
|
||||||
|
"unix.c",
|
||||||
|
"win32.c",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (target.result.os.tag == .windows) {
|
||||||
|
server.root_module.linkSystemLibrary("ws2_32", .{});
|
||||||
|
server.root_module.linkSystemLibrary("winmm", .{});
|
||||||
|
}
|
||||||
|
|
||||||
|
server.root_module.addIncludePath(b.path("vendor/enet/include/"));
|
||||||
|
|
||||||
|
// const znet = b.dependency(
|
||||||
|
// "znet",
|
||||||
|
// .{
|
||||||
|
// .target = target,
|
||||||
|
// .optimize = optimize,
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
// client.root_module.addImport("znet", znet.module("znet"));
|
||||||
|
// server.root_module.addImport("znet", znet.module("znet"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bufzilla
|
||||||
|
{
|
||||||
const bufzilla = b.dependency(
|
const bufzilla = b.dependency(
|
||||||
"bufzilla",
|
"bufzilla",
|
||||||
.{
|
.{
|
||||||
@ -120,7 +185,10 @@ pub fn build(b: *std.Build) void {
|
|||||||
});
|
});
|
||||||
client.root_module.addImport("bufzilla", bufzilla.module("bufzilla"));
|
client.root_module.addImport("bufzilla", bufzilla.module("bufzilla"));
|
||||||
server.root_module.addImport("bufzilla", bufzilla.module("bufzilla"));
|
server.root_module.addImport("bufzilla", bufzilla.module("bufzilla"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Raylib
|
||||||
|
{
|
||||||
const raylib_dep = b.dependency("raylib_zig", .{
|
const raylib_dep = b.dependency("raylib_zig", .{
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
@ -134,6 +202,10 @@ pub fn build(b: *std.Build) void {
|
|||||||
client.linkLibrary(raylib_artifact);
|
client.linkLibrary(raylib_artifact);
|
||||||
client.root_module.addImport("raylib", raylib);
|
client.root_module.addImport("raylib", raylib);
|
||||||
client.root_module.addImport("raygui", raygui);
|
client.root_module.addImport("raygui", raygui);
|
||||||
|
}
|
||||||
|
|
||||||
|
client.root_module.link_libc = true;
|
||||||
|
server.root_module.link_libc = true;
|
||||||
|
|
||||||
b.installArtifact(client);
|
b.installArtifact(client);
|
||||||
b.installArtifact(server);
|
b.installArtifact(server);
|
||||||
|
|||||||
@ -3,3 +3,8 @@ pub const c = @cImport({
|
|||||||
@cInclude("raymath.h");
|
@cInclude("raymath.h");
|
||||||
@cInclude("rlgl.h");
|
@cInclude("rlgl.h");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
pub const enet = @cImport({
|
||||||
|
@cDefine("WIN32_LEAN_AND_MEAN", "");
|
||||||
|
@cInclude("enet/enet.h");
|
||||||
|
});
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const zm = @import("zmath");
|
const zm = @import("zmath");
|
||||||
const znet = @import("znet");
|
|
||||||
const rl = @import("raylib");
|
const rl = @import("raylib");
|
||||||
const bufzilla = @import("bufzilla");
|
const bufzilla = @import("bufzilla");
|
||||||
const ft = @import("mach-freetype");
|
const ft = @import("mach-freetype");
|
||||||
@ -9,6 +8,8 @@ const kb = @import("kb");
|
|||||||
|
|
||||||
const shared = @import("shared");
|
const shared = @import("shared");
|
||||||
|
|
||||||
|
const c = @import("c.zig").c;
|
||||||
|
const enet = @import("c.zig").enet;
|
||||||
const client = @import("client.zig");
|
const client = @import("client.zig");
|
||||||
const entity = @import("entity.zig");
|
const entity = @import("entity.zig");
|
||||||
const misc = @import("misc.zig");
|
const misc = @import("misc.zig");
|
||||||
@ -48,9 +49,14 @@ pub fn main() !void {
|
|||||||
|
|
||||||
_ = try stdout.write("Hello, Client!\n");
|
_ = try stdout.write("Hello, Client!\n");
|
||||||
|
|
||||||
try znet.init();
|
if (enet.enet_initialize() != 0) {
|
||||||
defer znet.deinit();
|
std.log.info("Failed to load ENet", .{});
|
||||||
// rl.setConfigFlags(.{ .window_highdpi = true, .vsync_hint = true });
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
defer enet.enet_deinitialize();
|
||||||
|
|
||||||
|
rl.setConfigFlags(.{ .window_highdpi = true, .vsync_hint = false });
|
||||||
rl.initWindow(screen_width, screen_height, "zzz");
|
rl.initWindow(screen_width, screen_height, "zzz");
|
||||||
defer rl.closeWindow();
|
defer rl.closeWindow();
|
||||||
|
|
||||||
@ -107,14 +113,14 @@ pub fn main() !void {
|
|||||||
// const tx = try rl.loadTextureFromImage(img);
|
// const tx = try rl.loadTextureFromImage(img);
|
||||||
// rl.unloadImage(img);
|
// rl.unloadImage(img);
|
||||||
|
|
||||||
const host = try znet.Host.init(.{
|
// const host = try znet.Host.init(.{
|
||||||
.addr = null,
|
// .addr = null,
|
||||||
.peer_limit = 1,
|
// .peer_limit = 1,
|
||||||
.channel_limit = .max,
|
// .channel_limit = .max,
|
||||||
.incoming_bandwidth = .unlimited,
|
// .incoming_bandwidth = .unlimited,
|
||||||
.outgoing_bandwidth = .unlimited,
|
// .outgoing_bandwidth = .unlimited,
|
||||||
});
|
// });
|
||||||
defer host.deinit();
|
// defer host.deinit();
|
||||||
|
|
||||||
// const peer = try host.connect(.{
|
// const peer = try host.connect(.{
|
||||||
// .addr = try .init(.{
|
// .addr = try .init(.{
|
||||||
@ -195,27 +201,27 @@ pub fn main() !void {
|
|||||||
|
|
||||||
// std.log.info("t: {}", .{t});
|
// std.log.info("t: {}", .{t});
|
||||||
|
|
||||||
while (try host.service(0)) |event| switch (event) {
|
// while (try host.service(0)) |event| switch (event) {
|
||||||
.connect => |data| {
|
// .connect => |data| {
|
||||||
_ = data;
|
// _ = data;
|
||||||
// std.log.info("{}", .{data.peer});
|
// // std.log.info("{}", .{data.peer});
|
||||||
},
|
// },
|
||||||
.disconnect => |data| {
|
// .disconnect => |data| {
|
||||||
_ = data;
|
// _ = data;
|
||||||
// std.log.info("{}", .{data.peer});
|
// // std.log.info("{}", .{data.peer});
|
||||||
},
|
// },
|
||||||
.receive => |data| {
|
// .receive => |data| {
|
||||||
defer data.packet.deinit();
|
// defer data.packet.deinit();
|
||||||
|
|
||||||
const slice = data.packet.dataSlice();
|
// const slice = data.packet.dataSlice();
|
||||||
|
|
||||||
var reader = bufzilla.Reader(.{}).init(slice);
|
// var reader = bufzilla.Reader(.{}).init(slice);
|
||||||
|
|
||||||
const id = try reader.readPath("id");
|
// const id = try reader.readPath("id");
|
||||||
|
|
||||||
std.log.info("{any}", .{id});
|
// std.log.info("{any}", .{id});
|
||||||
},
|
// },
|
||||||
};
|
// };
|
||||||
|
|
||||||
rl.pollInputEvents();
|
rl.pollInputEvents();
|
||||||
|
|
||||||
|
|||||||
3
src/server/c.zig
Normal file
3
src/server/c.zig
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
pub const c = @cImport({
|
||||||
|
// @cInclude("enet/enet.h");
|
||||||
|
});
|
||||||
@ -1,5 +1,4 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const znet = @import("znet");
|
|
||||||
const bufzilla = @import("bufzilla");
|
const bufzilla = @import("bufzilla");
|
||||||
|
|
||||||
const shared = @import("shared");
|
const shared = @import("shared");
|
||||||
@ -30,14 +29,14 @@ pub fn spawn(chunk: *shared.chunk.Chunk, comptime T: type, allocator: std.mem.Al
|
|||||||
var writer = bufzilla.Writer.init(&fixed);
|
var writer = bufzilla.Writer.init(&fixed);
|
||||||
try writer.writeAny(msg);
|
try writer.writeAny(msg);
|
||||||
|
|
||||||
const encoded = fixed.buffered();
|
// const encoded = fixed.buffered();
|
||||||
|
|
||||||
const packet = try znet.Packet.init(encoded, 0, .reliable);
|
// const packet = try znet.Packet.init(encoded, 0, .reliable);
|
||||||
var iterator = server.host.iterPeers();
|
// var iterator = server.host.iterPeers();
|
||||||
|
|
||||||
while (iterator.next()) |peer| {
|
// while (iterator.next()) |peer| {
|
||||||
if (peer.state() == .connected) {
|
// if (peer.state() == .connected) {
|
||||||
try peer.send(packet);
|
// try peer.send(packet);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const zm = @import("zmath");
|
const zm = @import("zmath");
|
||||||
const znet = @import("znet");
|
|
||||||
|
|
||||||
const shared = @import("shared");
|
const shared = @import("shared");
|
||||||
|
|
||||||
@ -28,19 +27,19 @@ pub fn main() !void {
|
|||||||
|
|
||||||
try stdout.flush();
|
try stdout.flush();
|
||||||
|
|
||||||
try znet.init();
|
// try znet.init();
|
||||||
defer znet.deinit();
|
// defer znet.deinit();
|
||||||
|
|
||||||
server.host = try znet.Host.init(.{
|
// server.host = try znet.Host.init(.{
|
||||||
.addr = try .init(.{
|
// .addr = try .init(.{
|
||||||
.ip = .any,
|
// .ip = .any,
|
||||||
.port = .{ .uint = 5000 },
|
// .port = .{ .uint = 5000 },
|
||||||
}),
|
// }),
|
||||||
.peer_limit = 32,
|
// .peer_limit = 32,
|
||||||
.channel_limit = .max,
|
// .channel_limit = .max,
|
||||||
.incoming_bandwidth = .unlimited,
|
// .incoming_bandwidth = .unlimited,
|
||||||
.outgoing_bandwidth = .unlimited,
|
// .outgoing_bandwidth = .unlimited,
|
||||||
});
|
// });
|
||||||
|
|
||||||
// const address = try std.net.Address.parseIp4("127.0.0.1", shared.protocol.SERVER_PORT);
|
// const address = try std.net.Address.parseIp4("127.0.0.1", shared.protocol.SERVER_PORT);
|
||||||
// var tcp_server = try address.listen(.{});
|
// var tcp_server = try address.listen(.{});
|
||||||
@ -65,20 +64,20 @@ pub fn main() !void {
|
|||||||
|
|
||||||
// std.log.info("t: {}", .{t});
|
// std.log.info("t: {}", .{t});
|
||||||
|
|
||||||
while (try server.host.service(0)) |event| switch (event) {
|
// while (try server.host.service(0)) |event| switch (event) {
|
||||||
.connect => |data| {
|
// .connect => |data| {
|
||||||
_ = data;
|
// _ = data;
|
||||||
// std.log.info("{}", .{data.peer});
|
// // std.log.info("{}", .{data.peer});
|
||||||
},
|
// },
|
||||||
.disconnect => |data| {
|
// .disconnect => |data| {
|
||||||
_ = data;
|
// _ = data;
|
||||||
// std.log.info("{}", .{data.peer});
|
// // std.log.info("{}", .{data.peer});
|
||||||
},
|
// },
|
||||||
.receive => |data| {
|
// .receive => |data| {
|
||||||
std.log.info("{s}", .{data.packet.dataSlice()});
|
// std.log.info("{s}", .{data.packet.dataSlice()});
|
||||||
defer data.packet.deinit();
|
// defer data.packet.deinit();
|
||||||
},
|
// },
|
||||||
};
|
// };
|
||||||
|
|
||||||
// const connection = try tcp_server.accept();
|
// const connection = try tcp_server.accept();
|
||||||
// defer connection.stream.close();
|
// defer connection.stream.close();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user