not even compiling :( gotta go to bed
This commit is contained in:
parent
395320a794
commit
5eba80a6c6
@ -10,7 +10,7 @@ pub fn build(b: *std.Build) void {
|
||||
.{},
|
||||
});
|
||||
|
||||
const optimize = b.standardOptimizeOption(.{ .preferred_optimize_mode = .ReleaseFast });
|
||||
const optimize = b.standardOptimizeOption(.{ .preferred_optimize_mode = .Debug });
|
||||
|
||||
const assets = b.addInstallDirectory(.{
|
||||
.source_dir = b.path("assets"),
|
||||
@ -144,6 +144,7 @@ pub fn build(b: *std.Build) void {
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
shared.addImport("bufzilla", bufzilla.module("bufzilla"));
|
||||
client.root_module.addImport("bufzilla", bufzilla.module("bufzilla"));
|
||||
server.root_module.addImport("bufzilla", bufzilla.module("bufzilla"));
|
||||
}
|
||||
|
||||
@ -342,21 +342,12 @@ fn on_packet(packet: *enet.ENetPacket, peer: *enet.ENetPeer, channelID: i32) !vo
|
||||
|
||||
std.log.info("{s}\n", .{fixed2.buffered()});
|
||||
|
||||
var reader = bufzilla.Reader(.{}).init(encoded);
|
||||
var r = bufzilla.Reader(.{}).init(encoded);
|
||||
|
||||
// Read values sequentially
|
||||
const val = try reader.read();
|
||||
switch (val) {
|
||||
.object => { std.debug.print("{}\n", .{val}); },
|
||||
.array => { },
|
||||
.u32 => |n| std.debug.print("u32: {d}\n", .{n}),
|
||||
.u64 => |n| std.debug.print("u64: {d}\n", .{n}),
|
||||
.i32 => |n| std.debug.print("i32: {d}\n", .{n}),
|
||||
.i64 => |n| std.debug.print("i64: {d}\n", .{n}),
|
||||
.bytes => |s| std.debug.print("string: {s}\n", .{s}),
|
||||
else => {}
|
||||
}
|
||||
|
||||
const e = try shared.protocol.Soldier_v1.decode(&r);
|
||||
_ = e;
|
||||
}
|
||||
|
||||
fn connect() !void {
|
||||
|
||||
@ -54,34 +54,161 @@ pub const Soldier_v1 = struct {
|
||||
pos: zm.Vec,
|
||||
vel: zm.Vec,
|
||||
|
||||
we: struct {
|
||||
hell: i32,
|
||||
},
|
||||
|
||||
pub fn init(soldier: entity.Soldier) Soldier_v1 {
|
||||
return .{
|
||||
.id = soldier.id,
|
||||
.hp = soldier.hp,
|
||||
.pos = soldier.pos,
|
||||
.vel = soldier.vel,
|
||||
.we = .{ .hell = 666 },
|
||||
};
|
||||
}
|
||||
|
||||
// pub fn encode(self: Soldier_v1, w: *std.Io.Writer) !void {
|
||||
// try w.writeInt(u64, self.id, .little);
|
||||
// try writeVec4(w, self.pos);
|
||||
// try writeVec4(w, self.vel);
|
||||
// }
|
||||
pub fn decode(r: *bufzilla.Reader(.{})) !Soldier_v1 {
|
||||
var soldier_v1 : Soldier_v1 = .{
|
||||
.id = 0,
|
||||
.hp = 0,
|
||||
.pos = .{0, 0, 0, 0},
|
||||
.vel = .{0, 0, 0, 0},
|
||||
};
|
||||
|
||||
// pub fn decode(r: *bufzilla.Reader) !Soldier_v1 {
|
||||
// _ = r;
|
||||
// return .{
|
||||
// // .id = try r.readInt(u64, .little),
|
||||
// // .pos = try readVec4(r),
|
||||
// // .vel = try readVec4(r),
|
||||
// };
|
||||
// }
|
||||
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) {
|
||||
// .i32 => |val| {
|
||||
// if (std.mem.eql(u8, kv.key.bytes, "hp")) soldier_v1.hp = val;
|
||||
// },
|
||||
// else => {}
|
||||
// }
|
||||
}
|
||||
|
||||
return soldier_v1;
|
||||
}
|
||||
};
|
||||
|
||||
pub const Alien_v1 = struct {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user