mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-09-09 03:59:53 -04:00
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:
parent
b9a43284c6
commit
4b3e5aebf2
@ -29,6 +29,8 @@ var gamemodeInput: *Button = undefined;
|
|||||||
|
|
||||||
var allowCheats: bool = true;
|
var allowCheats: bool = true;
|
||||||
|
|
||||||
|
var testingMode: bool = false;
|
||||||
|
|
||||||
fn gamemodeCallback(_: usize) void {
|
fn gamemodeCallback(_: usize) void {
|
||||||
gamemode = std.meta.intToEnum(main.game.Gamemode, @intFromEnum(gamemode) + 1) catch @enumFromInt(0);
|
gamemode = std.meta.intToEnum(main.game.Gamemode, @intFromEnum(gamemode) + 1) catch @enumFromInt(0);
|
||||||
gamemodeInput.child.label.updateText(@tagName(gamemode));
|
gamemodeInput.child.label.updateText(@tagName(gamemode));
|
||||||
@ -38,6 +40,10 @@ fn allowCheatsCallback(allow: bool) void {
|
|||||||
allowCheats = allow;
|
allowCheats = allow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn testingModeCallback(enabled: bool) void {
|
||||||
|
testingMode = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
fn createWorld(_: usize) void {
|
fn createWorld(_: usize) void {
|
||||||
flawedCreateWorld() catch |err| {
|
flawedCreateWorld() catch |err| {
|
||||||
std.log.err("Error while creating new world: {s}", .{@errorName(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("default_gamemode", @tagName(gamemode));
|
||||||
gamerules.put("cheats", allowCheats);
|
gamerules.put("cheats", allowCheats);
|
||||||
|
gamerules.put("testingMode", testingMode);
|
||||||
|
|
||||||
try main.files.writeZon(gamerulePath, gamerules);
|
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, "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.add(Button.initText(.{0, 0}, 128, "Create World", .{.callback = &createWorld}));
|
||||||
|
|
||||||
list.finish(.center);
|
list.finish(.center);
|
||||||
|
@ -434,6 +434,7 @@ pub const ServerWorld = struct { // MARK: ServerWorld
|
|||||||
|
|
||||||
defaultGamemode: main.game.Gamemode = undefined,
|
defaultGamemode: main.game.Gamemode = undefined,
|
||||||
allowCheats: bool = undefined,
|
allowCheats: bool = undefined,
|
||||||
|
testingMode: bool = undefined,
|
||||||
|
|
||||||
seed: u64,
|
seed: u64,
|
||||||
path: []const u8,
|
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.defaultGamemode = std.meta.stringToEnum(main.game.Gamemode, gamerules.get([]const u8, "default_gamemode", "creative")) orelse .creative;
|
||||||
self.allowCheats = gamerules.get(bool, "cheats", true);
|
self.allowCheats = gamerules.get(bool, "cheats", true);
|
||||||
|
self.testingMode = gamerules.get(bool, "testingMode", false);
|
||||||
|
|
||||||
self.chunkManager = try ChunkManager.init(self, generatorSettings);
|
self.chunkManager = try ChunkManager.init(self, generatorSettings);
|
||||||
errdefer self.chunkManager.deinit();
|
errdefer self.chunkManager.deinit();
|
||||||
@ -821,10 +823,18 @@ pub const ServerWorld = struct { // MARK: ServerWorld
|
|||||||
}
|
}
|
||||||
const newBiomeCheckSum: i64 = @bitCast(terrain.biomes.getBiomeCheckSum(self.seed));
|
const newBiomeCheckSum: i64 = @bitCast(terrain.biomes.getBiomeCheckSum(self.seed));
|
||||||
if(newBiomeCheckSum != self.biomeChecksum) {
|
if(newBiomeCheckSum != self.biomeChecksum) {
|
||||||
|
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| {
|
self.regenerateLOD(newBiomeCheckSum) catch |err| {
|
||||||
std.log.err("Error while trying to regenerate LODs: {s}", .{@errorName(err)});
|
std.log.err("Error while trying to regenerate LODs: {s}", .{@errorName(err)});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
try self.wio.saveWorldData();
|
try self.wio.saveWorldData();
|
||||||
const itemsPath = std.fmt.allocPrint(main.stackAllocator.allocator, "saves/{s}/items.zig.zon", .{self.path}) catch unreachable;
|
const itemsPath = std.fmt.allocPrint(main.stackAllocator.allocator, "saves/{s}/items.zig.zon", .{self.path}) catch unreachable;
|
||||||
defer main.stackAllocator.free(itemsPath);
|
defer main.stackAllocator.free(itemsPath);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user