mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-08-03 11:17:05 -04:00
Send updated biome information instantly back to the player, but only when the biome actually changed
fixes #478
This commit is contained in:
parent
ffab4407e9
commit
ed99d940d2
@ -1019,7 +1019,8 @@ pub const Protocols = struct {
|
|||||||
gamemode = 0,
|
gamemode = 0,
|
||||||
teleport = 1,
|
teleport = 1,
|
||||||
worldEditPos = 2,
|
worldEditPos = 2,
|
||||||
timeAndBiome = 3,
|
time = 3,
|
||||||
|
biome = 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
const WorldEditPosition = enum(u2) {
|
const WorldEditPosition = enum(u2) {
|
||||||
@ -1063,10 +1064,9 @@ pub const Protocols = struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.timeAndBiome => {
|
.time => {
|
||||||
if(conn.manager.world) |world| {
|
if(conn.manager.world) |world| {
|
||||||
const expectedTime = try reader.readInt(i64);
|
const expectedTime = try reader.readInt(i64);
|
||||||
const biomeId = try reader.readInt(u32);
|
|
||||||
|
|
||||||
var curTime = world.gameTime.load(.monotonic);
|
var curTime = world.gameTime.load(.monotonic);
|
||||||
if(@abs(curTime -% expectedTime) >= 10) {
|
if(@abs(curTime -% expectedTime) >= 10) {
|
||||||
@ -1080,6 +1080,11 @@ pub const Protocols = struct {
|
|||||||
curTime = actualTime;
|
curTime = actualTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
.biome => {
|
||||||
|
if(conn.manager.world) |world| {
|
||||||
|
const biomeId = try reader.readInt(u32);
|
||||||
|
|
||||||
const newBiome = main.server.terrain.biomes.getByIndex(biomeId) orelse return error.MissingBiome;
|
const newBiome = main.server.terrain.biomes.getByIndex(biomeId) orelse return error.MissingBiome;
|
||||||
const oldBiome = world.playerBiome.swap(newBiome, .monotonic);
|
const oldBiome = world.playerBiome.swap(newBiome, .monotonic);
|
||||||
@ -1118,15 +1123,22 @@ pub const Protocols = struct {
|
|||||||
conn.send(.fast, id, writer.data.items);
|
conn.send(.fast, id, writer.data.items);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sendTimeAndBiome(conn: *Connection, world: *const main.server.ServerWorld) void {
|
pub fn sendBiome(conn: *Connection, biomeIndex: u32) void {
|
||||||
var writer = utils.BinaryWriter.initCapacity(main.stackAllocator, 13);
|
var writer = utils.BinaryWriter.initCapacity(main.stackAllocator, 13);
|
||||||
defer writer.deinit();
|
defer writer.deinit();
|
||||||
|
|
||||||
writer.writeEnum(UpdateType, .timeAndBiome);
|
writer.writeEnum(UpdateType, .biome);
|
||||||
writer.writeInt(i64, world.gameTime);
|
writer.writeInt(u32, biomeIndex);
|
||||||
|
|
||||||
const pos = @as(Vec3i, @intFromFloat(conn.user.?.player.pos));
|
conn.send(.fast, id, writer.data.items);
|
||||||
writer.writeInt(u32, world.getBiome(pos[0], pos[1], pos[2]).paletteId);
|
}
|
||||||
|
|
||||||
|
pub fn sendTime(conn: *Connection, world: *const main.server.ServerWorld) void {
|
||||||
|
var writer = utils.BinaryWriter.initCapacity(main.stackAllocator, 13);
|
||||||
|
defer writer.deinit();
|
||||||
|
|
||||||
|
writer.writeEnum(UpdateType, .time);
|
||||||
|
writer.writeInt(i64, world.gameTime);
|
||||||
|
|
||||||
conn.send(.fast, id, writer.data.items);
|
conn.send(.fast, id, writer.data.items);
|
||||||
}
|
}
|
||||||
|
@ -105,6 +105,8 @@ pub const User = struct { // MARK: User
|
|||||||
gamemode: std.atomic.Value(main.game.Gamemode) = .init(.creative),
|
gamemode: std.atomic.Value(main.game.Gamemode) = .init(.creative),
|
||||||
worldEditData: WorldEditData = undefined,
|
worldEditData: WorldEditData = undefined,
|
||||||
|
|
||||||
|
lastSentBiomeId: u32 = 0xffffffff,
|
||||||
|
|
||||||
inventoryClientToServerIdMap: std.AutoHashMap(u32, u32) = undefined,
|
inventoryClientToServerIdMap: std.AutoHashMap(u32, u32) = undefined,
|
||||||
|
|
||||||
connected: Atomic(bool) = .init(true),
|
connected: Atomic(bool) = .init(true),
|
||||||
@ -406,6 +408,15 @@ fn update() void { // MARK: update()
|
|||||||
main.network.Protocols.entityPosition.send(user.conn, user.player.pos, entityData.items, itemData);
|
main.network.Protocols.entityPosition.send(user.conn, user.player.pos, entityData.items, itemData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(userList) |user| {
|
||||||
|
const pos = @as(Vec3i, @intFromFloat(user.player.pos));
|
||||||
|
const biomeId = world.?.getBiome(user.lastPos[0], pos[1], pos[2]).paletteId;
|
||||||
|
if(biomeId != user.lastSentBiomeId) {
|
||||||
|
user.lastSentBiomeId = biomeId;
|
||||||
|
main.network.Protocols.genericUpdate.sendBiome(user.conn, biomeId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while(userDeinitList.dequeue()) |user| {
|
while(userDeinitList.dequeue()) |user| {
|
||||||
user.decreaseRefCount();
|
user.decreaseRefCount();
|
||||||
}
|
}
|
||||||
|
@ -946,7 +946,7 @@ pub const ServerWorld = struct { // MARK: ServerWorld
|
|||||||
const userList = server.getUserListAndIncreaseRefCount(main.stackAllocator);
|
const userList = server.getUserListAndIncreaseRefCount(main.stackAllocator);
|
||||||
defer server.freeUserListAndDecreaseRefCount(main.stackAllocator, userList);
|
defer server.freeUserListAndDecreaseRefCount(main.stackAllocator, userList);
|
||||||
for(userList) |user| {
|
for(userList) |user| {
|
||||||
main.network.Protocols.genericUpdate.sendTimeAndBiome(user.conn, self);
|
main.network.Protocols.genericUpdate.sendTime(user.conn, self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: Entities
|
// TODO: Entities
|
||||||
|
Loading…
x
Reference in New Issue
Block a user