.
This commit is contained in:
parent
5eba80a6c6
commit
5864401129
24
build.zig
24
build.zig
@ -136,18 +136,18 @@ pub fn build(b: *std.Build) void {
|
|||||||
server.root_module.linkLibrary(enet.artifact("enet"));
|
server.root_module.linkLibrary(enet.artifact("enet"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bufzilla
|
// // Bufzilla
|
||||||
{
|
// {
|
||||||
const bufzilla = b.dependency(
|
// const bufzilla = b.dependency(
|
||||||
"bufzilla",
|
// "bufzilla",
|
||||||
.{
|
// .{
|
||||||
.target = target,
|
// .target = target,
|
||||||
.optimize = optimize,
|
// .optimize = optimize,
|
||||||
});
|
// });
|
||||||
shared.addImport("bufzilla", bufzilla.module("bufzilla"));
|
// shared.addImport("bufzilla", bufzilla.module("bufzilla"));
|
||||||
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
|
// Raylib
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const zm = @import("zmath");
|
const zm = @import("zmath");
|
||||||
const bufzilla = @import("bufzilla");
|
// const bufzilla = @import("bufzilla");
|
||||||
const ft = @import("freetype");
|
const ft = @import("freetype");
|
||||||
const tracy = @import("tracy");
|
const tracy = @import("tracy");
|
||||||
const kb = @import("kb");
|
const kb = @import("kb");
|
||||||
@ -330,24 +330,24 @@ fn on_packet(packet: *enet.ENetPacket, peer: *enet.ENetPeer, channelID: i32) !vo
|
|||||||
_ = peer;
|
_ = peer;
|
||||||
_ = channelID;
|
_ = channelID;
|
||||||
|
|
||||||
const encoded: []const u8 = packet.*.data[0 .. packet.*.dataLength];
|
const bytes: []const u8 = packet.*.data[0 .. packet.*.dataLength];
|
||||||
|
|
||||||
std.log.info("{d} bytes: {s}", .{encoded.len, encoded});
|
std.log.info("{d} bytes: {s}", .{bytes.len, bytes});
|
||||||
|
|
||||||
var buffer2: [4096]u8 = undefined;
|
// var buffer2: [4096]u8 = undefined;
|
||||||
var fixed2 = std.io.Writer.fixed(&buffer2);
|
// var fixed2 = std.io.Writer.fixed(&buffer2);
|
||||||
|
|
||||||
var inspector = bufzilla.Inspect(.{}).init(encoded, &fixed2, .{});
|
// var inspector = bufzilla.Inspect(.{}).init(encoded, &fixed2, .{});
|
||||||
try inspector.inspect();
|
// try inspector.inspect();
|
||||||
|
|
||||||
std.log.info("{s}\n", .{fixed2.buffered()});
|
// std.log.info("{s}\n", .{fixed2.buffered()});
|
||||||
|
|
||||||
var r = bufzilla.Reader(.{}).init(encoded);
|
// var r = bufzilla.Reader(.{}).init(encoded);
|
||||||
|
|
||||||
// Read values sequentially
|
// Read values sequentially
|
||||||
|
|
||||||
const e = try shared.protocol.Soldier_v1.decode(&r);
|
// const e = try shared.protocol.Soldier_v1.decode(&r);
|
||||||
_ = e;
|
// _ = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn connect() !void {
|
fn connect() !void {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const bufzilla = @import("bufzilla");
|
// const bufzilla = @import("bufzilla");
|
||||||
|
|
||||||
const shared = @import("shared");
|
const shared = @import("shared");
|
||||||
const server = @import("server.zig");
|
const server = @import("server.zig");
|
||||||
@ -27,18 +27,18 @@ pub fn spawn(allocator: std.mem.Allocator, host: *enet.ENetHost, chunk: *shared.
|
|||||||
var buffer: [128]u8 = undefined;
|
var buffer: [128]u8 = undefined;
|
||||||
var fixed = std.io.Writer.fixed(&buffer);
|
var fixed = std.io.Writer.fixed(&buffer);
|
||||||
|
|
||||||
const msg = shared.protocol.makeSpawnMessage(T, entity);
|
// const msg = shared.protocol.makeSpawnMessage(T, entity);
|
||||||
|
|
||||||
var writer = bufzilla.Writer.init(&fixed);
|
// var writer = bufzilla.Writer.init(&fixed);
|
||||||
try writer.writeAny(msg);
|
// try writer.writeAny(msg);
|
||||||
|
|
||||||
// std.log.info("{s}", .{fixed.buffered()});
|
// std.log.info("{s}", .{fixed.buffered()});
|
||||||
|
|
||||||
var buffer2: [4096]u8 = undefined;
|
// var buffer2: [4096]u8 = undefined;
|
||||||
var fixed2 = std.io.Writer.fixed(&buffer2);
|
// var fixed2 = std.io.Writer.fixed(&buffer2);
|
||||||
|
|
||||||
var inspector = bufzilla.Inspect(.{}).init(fixed.buffered(), &fixed2, .{});
|
// var inspector = bufzilla.Inspect(.{}).init(fixed.buffered(), &fixed2, .{});
|
||||||
try inspector.inspect();
|
// try inspector.inspect();
|
||||||
|
|
||||||
// std.log.info("{}", .{msg});
|
// std.log.info("{}", .{msg});
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const zm = @import("zmath");
|
const zm = @import("zmath");
|
||||||
const enet = @import("c.zig").enet;
|
const enet = @import("c.zig").enet;
|
||||||
const bufzilla = @import("bufzilla");
|
// const bufzilla = @import("bufzilla");
|
||||||
|
|
||||||
const shared = @import("shared");
|
const shared = @import("shared");
|
||||||
|
|
||||||
@ -135,23 +135,23 @@ fn on_connect(allocator: std.mem.Allocator, host: *enet.ENetHost, peer: *enet.EN
|
|||||||
var aw = try std.io.Writer.Allocating.initCapacity(allocator, 128);
|
var aw = try std.io.Writer.Allocating.initCapacity(allocator, 128);
|
||||||
defer aw.deinit();
|
defer aw.deinit();
|
||||||
|
|
||||||
var writer = bufzilla.Writer.init(&aw.writer);
|
// var writer = bufzilla.Writer.init(&aw.writer);
|
||||||
|
|
||||||
const fields = @typeInfo(shared.chunk.Chunk).@"struct".fields;
|
const fields = @typeInfo(shared.chunk.Chunk).@"struct".fields;
|
||||||
|
|
||||||
inline for (fields) |field| {
|
inline for (fields) |field| {
|
||||||
const list = &@field(the_chunk, field.name);
|
const list = &@field(the_chunk, field.name);
|
||||||
|
|
||||||
const itemsType = @FieldType(field.type, "items");
|
// const itemsType = @FieldType(field.type, "items");
|
||||||
const T = std.meta.Child(itemsType);
|
// const T = std.meta.Child(itemsType);
|
||||||
|
|
||||||
for (list.items) |entity| {
|
for (list.items) |entity| {
|
||||||
|
|
||||||
const msg = shared.protocol.makeSpawnMessage(T, entity);
|
// const msg = shared.protocol.makeSpawnMessage(T, entity);
|
||||||
|
|
||||||
std.log.info("{}", .{entity});
|
std.log.info("{}", .{entity});
|
||||||
|
|
||||||
try writer.writeAny(msg);
|
// try writer.writeAny(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,11 +159,11 @@ fn on_connect(allocator: std.mem.Allocator, host: *enet.ENetHost, peer: *enet.EN
|
|||||||
|
|
||||||
// std.log.info("{d} bytes: {s}", .{encoded.len, encoded});
|
// std.log.info("{d} bytes: {s}", .{encoded.len, encoded});
|
||||||
|
|
||||||
var buffer2: [4096]u8 = undefined;
|
// var buffer2: [4096]u8 = undefined;
|
||||||
var fixed2 = std.io.Writer.fixed(&buffer2);
|
// var fixed2 = std.io.Writer.fixed(&buffer2);
|
||||||
|
|
||||||
var inspector = bufzilla.Inspect(.{}).init(encoded, &fixed2, .{});
|
// var inspector = bufzilla.Inspect(.{}).init(encoded, &fixed2, .{});
|
||||||
try inspector.inspect();
|
// try inspector.inspect();
|
||||||
|
|
||||||
// std.log.info("{s}\n", .{fixed2.buffered()});
|
// std.log.info("{s}\n", .{fixed2.buffered()});
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const zm = @import("zmath");
|
const zm = @import("zmath");
|
||||||
const bufzilla = @import("bufzilla");
|
// const bufzilla = @import("bufzilla");
|
||||||
|
|
||||||
const entity = @import("entity.zig");
|
const entity = @import("entity.zig");
|
||||||
|
|
||||||
@ -63,141 +63,15 @@ pub const Soldier_v1 = struct {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn decode(r: *bufzilla.Reader(.{})) !Soldier_v1 {
|
pub fn decode() !Soldier_v1 {
|
||||||
var soldier_v1 : Soldier_v1 = .{
|
const soldier_v1 : Soldier_v1 = .{
|
||||||
.id = 0,
|
.id = 0,
|
||||||
.hp = 0,
|
.hp = 0,
|
||||||
.pos = .{0, 0, 0, 0},
|
.pos = .{0, 0, 0, 0},
|
||||||
.vel = .{0, 0, 0, 0},
|
.vel = .{0, 0, 0, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
const obj = try r.read();
|
|
||||||
|
|
||||||
var w = std.fs.File.stdout();
|
|
||||||
|
|
||||||
while (try r.iterateObject(obj)) |kv| {
|
|
||||||
|
|
||||||
switch (kv.value) {
|
|
||||||
.object => {
|
|
||||||
try w.writeAll("{\n");
|
|
||||||
|
|
||||||
while (try self.reader.iterateObject(val)) |kv| {
|
|
||||||
if (count > 0) {
|
|
||||||
try w.writeAll(",\n");
|
|
||||||
}
|
|
||||||
count += 1;
|
|
||||||
|
|
||||||
try self.writeIndent(depth + 1);
|
|
||||||
try self.printValue(kv.key, depth + 1);
|
|
||||||
try w.writeAll(": ");
|
|
||||||
try self.printValue(kv.value, depth + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count > 0) try w.writeByte('\n');
|
|
||||||
try self.writeIndent(depth);
|
|
||||||
try w.writeByte('}');
|
|
||||||
},
|
|
||||||
.array => {
|
|
||||||
try w.writeAll("[\n");
|
|
||||||
|
|
||||||
while (try self.reader.iterateArray(val)) |item| {
|
|
||||||
if (count > 0) {
|
|
||||||
try w.writeAll(",\n");
|
|
||||||
}
|
|
||||||
count += 1;
|
|
||||||
|
|
||||||
try self.writeIndent(depth + 1);
|
|
||||||
try self.printValue(item, depth + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count > 0) try w.writeByte('\n');
|
|
||||||
try self.writeIndent(depth);
|
|
||||||
try w.writeByte(']');
|
|
||||||
},
|
|
||||||
.typedArray => {
|
|
||||||
const ta = val.typedArray;
|
|
||||||
const elem_size = common.typedArrayElemSize(ta.elem);
|
|
||||||
const expected_len = std.math.mul(usize, ta.count, elem_size) catch return error.InvalidEnumTag;
|
|
||||||
if (expected_len != ta.bytes.len) return error.InvalidEnumTag;
|
|
||||||
|
|
||||||
try w.writeAll("[\n");
|
|
||||||
|
|
||||||
var i: usize = 0;
|
|
||||||
while (i < ta.count) : (i += 1) {
|
|
||||||
if (i > 0) try w.writeAll(",\n");
|
|
||||||
try self.writeIndent(depth + 1);
|
|
||||||
|
|
||||||
const off = i * elem_size;
|
|
||||||
const chunk = ta.bytes[off..][0..elem_size];
|
|
||||||
|
|
||||||
switch (ta.elem) {
|
|
||||||
.u8 => try w.print("{d}", .{chunk[0]}),
|
|
||||||
.i8 => try w.print("{d}", .{@as(i8, @bitCast(chunk[0]))}),
|
|
||||||
.u16 => try w.print("{d}", .{std.mem.readInt(u16, chunk[0..2], .little)}),
|
|
||||||
.i16 => try w.print("{d}", .{std.mem.readInt(i16, chunk[0..2], .little)}),
|
|
||||||
.u32 => try w.print("{d}", .{std.mem.readInt(u32, chunk[0..4], .little)}),
|
|
||||||
.i32 => try w.print("{d}", .{std.mem.readInt(i32, chunk[0..4], .little)}),
|
|
||||||
.u64 => try w.print("{d}", .{std.mem.readInt(u64, chunk[0..8], .little)}),
|
|
||||||
.i64 => try w.print("{d}", .{std.mem.readInt(i64, chunk[0..8], .little)}),
|
|
||||||
.f16 => {
|
|
||||||
const bits = std.mem.readInt(u16, chunk[0..2], .little);
|
|
||||||
const fv: f16 = @bitCast(bits);
|
|
||||||
const f: f64 = @floatCast(fv);
|
|
||||||
if (!std.math.isFinite(f)) return error.NonFiniteFloat;
|
|
||||||
try w.printFloat(f, .{ .precision = self.options.float_precision, .mode = .decimal });
|
|
||||||
},
|
|
||||||
.f32 => {
|
|
||||||
const bits = std.mem.readInt(u32, chunk[0..4], .little);
|
|
||||||
const fv: f32 = @bitCast(bits);
|
|
||||||
const f: f64 = @floatCast(fv);
|
|
||||||
if (!std.math.isFinite(f)) return error.NonFiniteFloat;
|
|
||||||
try w.printFloat(f, .{ .precision = self.options.float_precision, .mode = .decimal });
|
|
||||||
},
|
|
||||||
.f64 => {
|
|
||||||
const bits = std.mem.readInt(u64, chunk[0..8], .little);
|
|
||||||
const f: f64 = @bitCast(bits);
|
|
||||||
if (!std.math.isFinite(f)) return error.NonFiniteFloat;
|
|
||||||
try w.printFloat(f, .{ .precision = self.options.float_precision, .mode = .decimal });
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ta.count > 0) try w.writeByte('\n');
|
|
||||||
try self.writeIndent(depth);
|
|
||||||
try w.writeByte(']');
|
|
||||||
},
|
|
||||||
.f64 => {
|
|
||||||
if (!std.math.isFinite(val.f64)) return error.NonFiniteFloat;
|
|
||||||
try w.printFloat(val.f64, .{ .precision = self.options.float_precision, .mode = .decimal });
|
|
||||||
},
|
|
||||||
.f32 => {
|
|
||||||
if (!std.math.isFinite(val.f32)) return error.NonFiniteFloat;
|
|
||||||
try w.printFloat(val.f32, .{ .precision = self.options.float_precision, .mode = .decimal });
|
|
||||||
},
|
|
||||||
.f16 => {
|
|
||||||
const f: f64 = @floatCast(val.f16);
|
|
||||||
if (!std.math.isFinite(f)) return error.NonFiniteFloat;
|
|
||||||
try w.printFloat(f, .{ .precision = self.options.float_precision, .mode = .decimal });
|
|
||||||
},
|
|
||||||
.smallUint => try w.print("{d}", .{val.smallUint}),
|
|
||||||
.i64 => try w.print("{d}", .{val.i64}),
|
|
||||||
.i32 => try w.print("{d}", .{val.i32}),
|
|
||||||
.i16 => try w.print("{d}", .{val.i16}),
|
|
||||||
.i8 => try w.print("{d}", .{val.i8}),
|
|
||||||
.u64 => try w.print("{d}", .{val.u64}),
|
|
||||||
.u32 => try w.print("{d}", .{val.u32}),
|
|
||||||
.u16 => try w.print("{d}", .{val.u16}),
|
|
||||||
.u8 => try w.print("{d}", .{val.u8}),
|
|
||||||
.bool => try w.writeAll(if (val.bool) "true" else "false"),
|
|
||||||
.bytes => try self.writeString(val.bytes),
|
|
||||||
.varIntBytes => try self.writeString(val.varIntBytes),
|
|
||||||
.smallBytes => try self.writeString(val.smallBytes),
|
|
||||||
.null => try w.writeAll("null"),
|
|
||||||
.containerEnd => try w.writeAll("END"),
|
|
||||||
.smallIntPositive => try w.print("{d}", .{val.smallIntPositive}),
|
|
||||||
.smallIntNegative => try w.print("-{d}", .{val.smallIntNegative}),
|
|
||||||
.varIntUnsigned, .varIntSignedPositive, .varIntSignedNegative => {},
|
|
||||||
}
|
|
||||||
|
|
||||||
// switch (kv.value) {
|
// switch (kv.value) {
|
||||||
// .i32 => |val| {
|
// .i32 => |val| {
|
||||||
@ -205,7 +79,6 @@ pub const Soldier_v1 = struct {
|
|||||||
// },
|
// },
|
||||||
// else => {}
|
// else => {}
|
||||||
// }
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
return soldier_v1;
|
return soldier_v1;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user