bit streaming
This commit is contained in:
parent
5864401129
commit
9a5c15e47e
@ -132,10 +132,39 @@ pub fn main() !void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn on_connect(allocator: std.mem.Allocator, host: *enet.ENetHost, peer: *enet.ENetPeer, the_chunk: *shared.chunk.Chunk) !void {
|
fn on_connect(allocator: std.mem.Allocator, host: *enet.ENetHost, peer: *enet.ENetPeer, the_chunk: *shared.chunk.Chunk) !void {
|
||||||
var aw = try std.io.Writer.Allocating.initCapacity(allocator, 128);
|
var aw = try std.ArrayList(u8).initCapacity(allocator, 128);
|
||||||
defer aw.deinit();
|
defer aw.deinit(allocator);
|
||||||
|
|
||||||
// var writer = bufzilla.Writer.init(&aw.writer);
|
_ = peer;
|
||||||
|
|
||||||
|
// var w = bufzilla.Writer.init(&aw.writer);
|
||||||
|
|
||||||
|
var writer = shared.bits.BitWriter.init(&aw);
|
||||||
|
|
||||||
|
// Write 3 bits (101)
|
||||||
|
try writer.write(allocator, @as(u3, 0x5));
|
||||||
|
// Write 1 bit (true = 1)
|
||||||
|
try writer.write(allocator, true);
|
||||||
|
// Write 4 bits (0000)
|
||||||
|
try writer.write(allocator, @as(u3, 0x1));
|
||||||
|
|
||||||
|
try writer.write(allocator, @as(u4, 0xE));
|
||||||
|
|
||||||
|
try writer.write(allocator, @as(u32, 0xFFFFFFFA));
|
||||||
|
|
||||||
|
var reader = shared.bits.BitReader.init(writer.written());
|
||||||
|
|
||||||
|
const _1 : u3 = reader.read(u3);
|
||||||
|
const _2 : bool = reader.read(bool);
|
||||||
|
const _3 : u3 = reader.read(u3);
|
||||||
|
const _4 : u4 = reader.read(u4);
|
||||||
|
const _5 : u32 = reader.read(u32);
|
||||||
|
|
||||||
|
std.log.info("_1: {}", .{_1});
|
||||||
|
std.log.info("_1: {}", .{_2});
|
||||||
|
std.log.info("_1: {}", .{_3});
|
||||||
|
std.log.info("_1: {}", .{_4});
|
||||||
|
std.log.info("_1: {}", .{_5});
|
||||||
|
|
||||||
const fields = @typeInfo(shared.chunk.Chunk).@"struct".fields;
|
const fields = @typeInfo(shared.chunk.Chunk).@"struct".fields;
|
||||||
|
|
||||||
@ -149,13 +178,15 @@ fn on_connect(allocator: std.mem.Allocator, host: *enet.ENetHost, peer: *enet.EN
|
|||||||
|
|
||||||
// const msg = shared.protocol.makeSpawnMessage(T, entity);
|
// const msg = shared.protocol.makeSpawnMessage(T, entity);
|
||||||
|
|
||||||
|
// w.write(entity);
|
||||||
|
|
||||||
std.log.info("{}", .{entity});
|
std.log.info("{}", .{entity});
|
||||||
|
|
||||||
// try writer.writeAny(msg);
|
// try writer.writeAny(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const encoded = aw.written();
|
// const encoded = aw.written();
|
||||||
|
|
||||||
// std.log.info("{d} bytes: {s}", .{encoded.len, encoded});
|
// std.log.info("{d} bytes: {s}", .{encoded.len, encoded});
|
||||||
|
|
||||||
@ -167,13 +198,13 @@ fn on_connect(allocator: std.mem.Allocator, host: *enet.ENetHost, peer: *enet.EN
|
|||||||
|
|
||||||
// std.log.info("{s}\n", .{fixed2.buffered()});
|
// std.log.info("{s}\n", .{fixed2.buffered()});
|
||||||
|
|
||||||
const packet = enet.enet_packet_create(encoded.ptr, encoded.len, enet.ENET_PACKET_FLAG_RELIABLE);
|
// const packet = enet.enet_packet_create(encoded.ptr, encoded.len, enet.ENET_PACKET_FLAG_RELIABLE);
|
||||||
|
|
||||||
// enet.enet_host_broadcast(host, 0, packet);
|
// enet.enet_host_broadcast(host, 0, packet);
|
||||||
_ = host;
|
_ = host;
|
||||||
if (enet.enet_peer_send(peer, 0, packet) != 0) {
|
// if (enet.enet_peer_send(peer, 0, packet) != 0) {
|
||||||
std.log.err("Could not send packet to peer.", .{});
|
// std.log.err("Could not send packet to peer.", .{});
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
//fn handle_connection(connection: std.net.Server.Connection) !void {}
|
//fn handle_connection(connection: std.net.Server.Connection) !void {}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ const zm = @import("zmath");
|
|||||||
// const bufzilla = @import("bufzilla");
|
// const bufzilla = @import("bufzilla");
|
||||||
|
|
||||||
const entity = @import("entity.zig");
|
const entity = @import("entity.zig");
|
||||||
|
const bits = @import("bits.zig");
|
||||||
|
|
||||||
pub const SERVER_PORT: u16 = 1337;
|
pub const SERVER_PORT: u16 = 1337;
|
||||||
|
|
||||||
|
|||||||
@ -2,3 +2,4 @@ pub const entity = @import("entity.zig");
|
|||||||
pub const chunk = @import("chunk.zig");
|
pub const chunk = @import("chunk.zig");
|
||||||
pub const misc = @import("misc.zig");
|
pub const misc = @import("misc.zig");
|
||||||
pub const protocol = @import("protocol.zig");
|
pub const protocol = @import("protocol.zig");
|
||||||
|
pub const bits = @import("bits.zig");
|
||||||
|
|||||||
1
vendor/enet/build.zig.zon
vendored
1
vendor/enet/build.zig.zon
vendored
@ -1,5 +1,6 @@
|
|||||||
.{
|
.{
|
||||||
.name = .enet,
|
.name = .enet,
|
||||||
|
.fingerprint = 0x201714c0933cd1fc,
|
||||||
.version = "0.1.0",
|
.version = "0.1.0",
|
||||||
.minimum_zig_version = "0.15.2",
|
.minimum_zig_version = "0.15.2",
|
||||||
.paths = .{
|
.paths = .{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user