.
This commit is contained in:
parent
ee790cf700
commit
c6fdd68afe
@ -5,7 +5,7 @@ const shared = @import("shared");
|
||||
const server = @import("server.zig");
|
||||
const enet = @import("c.zig").enet;
|
||||
|
||||
pub fn spawn(chunk: *shared.chunk.Chunk, comptime T: type, allocator: std.mem.Allocator, value: T) !void {
|
||||
pub fn spawn(allocator: std.mem.Allocator, chunk: *shared.chunk.Chunk, comptime T: type, value: T) !void {
|
||||
std.debug.assert(value.id == shared.entity.INVALID_ID);
|
||||
|
||||
const id = server.next_entity_id;
|
||||
@ -21,7 +21,7 @@ pub fn spawn(chunk: *shared.chunk.Chunk, comptime T: type, allocator: std.mem.Al
|
||||
}
|
||||
}
|
||||
|
||||
std.log.info("{}", .{entity.to_message()});
|
||||
// std.log.info("{}", .{shared.protocol.makeSpawnMessage(T, entity)});
|
||||
|
||||
// serialize entity
|
||||
var buffer: [128]u8 = undefined;
|
||||
@ -32,6 +32,18 @@ pub fn spawn(chunk: *shared.chunk.Chunk, comptime T: type, allocator: std.mem.Al
|
||||
var writer = bufzilla.Writer.init(&fixed);
|
||||
try writer.writeAny(msg);
|
||||
|
||||
// std.log.info("{s}", .{fixed.buffered()});
|
||||
|
||||
var buffer2: [4096]u8 = undefined;
|
||||
var fixed2 = std.io.Writer.fixed(&buffer2);
|
||||
|
||||
var inspector = bufzilla.Inspect(.{}).init(fixed.buffered(), &fixed2, .{});
|
||||
try inspector.inspect();
|
||||
|
||||
std.log.info("{}", .{msg});
|
||||
|
||||
std.debug.print("{s}\n", .{fixed2.buffered()});
|
||||
|
||||
// const encoded = fixed.buffered();
|
||||
|
||||
// const packet = try znet.Packet.init(encoded, 0, .reliable);
|
||||
|
||||
@ -47,12 +47,16 @@ pub fn main() !void {
|
||||
var the_chunk = try shared.chunk.initChunk(allocator);
|
||||
defer shared.chunk.deinitChunk(&the_chunk, allocator);
|
||||
|
||||
try chunk.spawn(&the_chunk, shared.entity.Soldier, allocator, .{
|
||||
try chunk.spawn(
|
||||
allocator,
|
||||
&the_chunk,
|
||||
shared.entity.Soldier,
|
||||
.{
|
||||
.hp = 10,
|
||||
.pos = zm.f32x4(1, 0, 0, 0),
|
||||
.vel = zm.f32x4(0, 0, 0, 0),
|
||||
.hp = 10,
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
var old_time = std.time.nanoTimestamp();
|
||||
|
||||
|
||||
@ -13,9 +13,9 @@ pub const EntityKinds = .{
|
||||
|
||||
pub const Soldier = struct {
|
||||
id: id = INVALID_ID,
|
||||
hp: i32,
|
||||
pos: zm.Vec,
|
||||
vel: zm.Vec,
|
||||
hp: i32,
|
||||
|
||||
pub fn update(self: *Soldier) void {
|
||||
self.pos += self.pos + self.vel;
|
||||
|
||||
@ -50,31 +50,38 @@ pub fn makeSpawnMessage(comptime T: type, e: T) Message {
|
||||
|
||||
pub const Soldier_v1 = struct {
|
||||
id: entity.id = entity.INVALID_ID,
|
||||
pos: zm.Vec,
|
||||
hp: i32,
|
||||
pos: zm.Vec,
|
||||
vel: zm.Vec,
|
||||
|
||||
we: struct {
|
||||
hell: i32,
|
||||
},
|
||||
|
||||
pub fn init(soldier: entity.Soldier) Soldier_v1 {
|
||||
return .{
|
||||
.id = soldier.id,
|
||||
.pos = soldier.pos,
|
||||
.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 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 {
|
||||
_ = r;
|
||||
return .{
|
||||
// .id = try r.readInt(u64, .little),
|
||||
// .pos = try readVec4(r),
|
||||
// .vel = try readVec4(r),
|
||||
};
|
||||
}
|
||||
// pub fn decode(r: *bufzilla.Reader) !Soldier_v1 {
|
||||
// _ = r;
|
||||
// return .{
|
||||
// // .id = try r.readInt(u64, .little),
|
||||
// // .pos = try readVec4(r),
|
||||
// // .vel = try readVec4(r),
|
||||
// };
|
||||
// }
|
||||
};
|
||||
|
||||
pub const Alien_v1 = struct {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user