added raylib, enet

This commit is contained in:
vfs committed 2026-01-06 16:35:56 +01:00
1 parent 99061337dd
commit 5dad7572b7
11 files changed
+500 -283

No files matched your search

+57 -2
View File
@@ -1,15 +1,70 @@
const std = @import("std");
const entity = @import("entity.zig");
const zm = @import("zmath");
pub const SERVER_PORT: u16 = 1337;
pub const MessageType = enum(u8) {
spawn_entity = 1,
// later: despawn_entity, update_entity, snapshot, etc.
};
pub const SpawnEntity = struct {
id: entity.entity_id,
kind: EntityKind,
payload: []const u8, // serialized entity data
};
pub fn write_message(writer: *std.Io.Writer, msg_type: MessageType, payload: []const u8) !void {
try writer.writeByte(@intFromEnum(msg_type));
try writer.writeInt(u32, @intCast(payload.len), .little);
try writer.writeAll(payload);
}
pub fn read_message(reader: *std.Io.Reader, allocator: std.mem.Allocator) !struct {
msg_type: MessageType,
payload: []u8,
} {
const msg_type = try reader.readByte();
const size = try reader.readInt(u32, .little);
const payload = try allocator.alloc(u8, size);
errdefer allocator.free(payload);
try reader.readNoEof(payload);
return .{
.msg_type = @enumFromInt(msg_type),
.payload = payload,
};
}
pub const EntityKind = enum(u8) {
Player,
Monster,
Projectile,
};
pub const Hello = struct {
msg: []const u8,
};
pub fn sendHello(writer: *std.io.Writer, hello: Hello) !void {
try writer.print("{s}\n", .{hello.msg});
try writer.flush();
}
pub fn recvLine(reader: *std.io.Reader) ![]u8 {
return try reader.takeDelimiterExclusive('\n');
fn writeVec4(w: *std.Io.Writer, v: zm.Vec4) !void {
const a = zm.vecToArray(v);
inline for (a) |f| {
try w.writeFloat(f32, f, .little);
}
}
fn readVec4(r: *std.Io.Reader) !zm.Vec4 {
var a: [4]f32 = undefined;
inline for (&a) |*f| {
f.* = try r.readFloat(f32, .little);
}
return zm.loadArr4(a);
}