Introduce a testing mode for developers which doesn't reload LODs on biome changes and doesn't save maps either.

fixes #1489
This commit is contained in:
IntegratedQuantum 2025-05-31 14:20:02 +02:00
parent b9a43284c6
commit 4b3e5aebf2
2 changed files with 22 additions and 3 deletions

View File

@ -29,6 +29,8 @@ var gamemodeInput: *Button = undefined;
var allowCheats: bool = true;
var testingMode: bool = false;
fn gamemodeCallback(_: usize) void {
gamemode = std.meta.intToEnum(main.game.Gamemode, @intFromEnum(gamemode) + 1) catch @enumFromInt(0);
gamemodeInput.child.label.updateText(@tagName(gamemode));
@ -38,6 +40,10 @@ fn allowCheatsCallback(allow: bool) void {
allowCheats = allow;
}
fn testingModeCallback(enabled: bool) void {
testingMode = enabled;
}
fn createWorld(_: usize) void {
flawedCreateWorld() catch |err| {
std.log.err("Error while creating new world: {s}", .{@errorName(err)});
@ -121,6 +127,7 @@ fn flawedCreateWorld() !void {
gamerules.put("default_gamemode", @tagName(gamemode));
gamerules.put("cheats", allowCheats);
gamerules.put("testingMode", testingMode);
try main.files.writeZon(gamerulePath, gamerules);
}
@ -156,6 +163,8 @@ pub fn onOpen() void {
list.add(CheckBox.init(.{0, 0}, 128, "Allow Cheats", true, &allowCheatsCallback));
list.add(CheckBox.init(.{0, 0}, 128, "Testing mode (for developers)", false, &testingModeCallback));
list.add(Button.initText(.{0, 0}, 128, "Create World", .{.callback = &createWorld}));
list.finish(.center);

View File

@ -434,6 +434,7 @@ pub const ServerWorld = struct { // MARK: ServerWorld
defaultGamemode: main.game.Gamemode = undefined,
allowCheats: bool = undefined,
testingMode: bool = undefined,
seed: u64,
path: []const u8,
@ -543,6 +544,7 @@ pub const ServerWorld = struct { // MARK: ServerWorld
self.defaultGamemode = std.meta.stringToEnum(main.game.Gamemode, gamerules.get([]const u8, "default_gamemode", "creative")) orelse .creative;
self.allowCheats = gamerules.get(bool, "cheats", true);
self.testingMode = gamerules.get(bool, "testingMode", false);
self.chunkManager = try ChunkManager.init(self, generatorSettings);
errdefer self.chunkManager.deinit();
@ -821,9 +823,17 @@ pub const ServerWorld = struct { // MARK: ServerWorld
}
const newBiomeCheckSum: i64 = @bitCast(terrain.biomes.getBiomeCheckSum(self.seed));
if(newBiomeCheckSum != self.biomeChecksum) {
self.regenerateLOD(newBiomeCheckSum) catch |err| {
std.log.err("Error while trying to regenerate LODs: {s}", .{@errorName(err)});
};
if(self.testingMode) {
const dir = std.fmt.allocPrint(main.stackAllocator.allocator, "saves/{s}", .{self.path}) catch unreachable;
defer main.stackAllocator.free(dir);
main.files.deleteDir(dir, "maps") catch |err| {
std.log.err("Error while trying to remove maps folder of testingMode world: {s}", .{@errorName(err)});
};
} else {
self.regenerateLOD(newBiomeCheckSum) catch |err| {
std.log.err("Error while trying to regenerate LODs: {s}", .{@errorName(err)});
};
}
}
try self.wio.saveWorldData();
const itemsPath = std.fmt.allocPrint(main.stackAllocator.allocator, "saves/{s}/items.zig.zon", .{self.path}) catch unreachable;