Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qol shortcuts #382

Merged
merged 7 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/blocks.zig
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,11 @@ pub fn finishBlocks(jsonElements: std.StringHashMap(JsonElement)) void {

pub fn reset() void {
size = 0;
ores.clearAndFree();
meshes.reset();
_ = arena.reset(.free_all);
reverseIndices = std.StringHashMap(u16).init(arena.allocator().allocator);
std.debug.assert(unfinishedOreSourceBlockIds.items.len == 0);
ores.clearRetainingCapacity();
}

pub fn getByID(id: []const u8) u16 {
Expand Down
7 changes: 6 additions & 1 deletion src/game.zig
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,24 @@ pub const World = struct {

pub fn deinit(self: *World) void {
// TODO: Close all world related guis.
main.gui.deinit();
main.gui.init();

main.threadPool.clear();
self.conn.deinit();
self.itemDrops.deinit();
self.blockPalette.deinit();
Player.inventory__SEND_CHANGES_TO_SERVER.deinit(main.globalAllocator);
self.manager.deinit();
main.server.stop();
if(main.server.thread) |serverThread| {
serverThread.join();
main.server.thread = null;
}
main.threadPool.clear();
renderer.mesh_storage.deinit();
renderer.mesh_storage.init();
assets.unloadAssets();
Player.inventory__SEND_CHANGES_TO_SERVER.deinit(main.globalAllocator);
}

pub fn finishHandshake(self: *World, json: JsonElement) !void {
Expand Down
5 changes: 4 additions & 1 deletion src/gui/windows/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ pub var window = GuiWindow {

const padding: f32 = 8;

fn exitGame(_:usize) void {
main.Window.deinit();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solution does not seem to work.
When I press the exit button it crashes with:

Segmentation fault at address 0x88
???:?:?: 0x163c44a in _glfwPollEventsX11 (/home/mint/.cache/zig/p/1220c46ebcac607065f942193b82a21b87213fca4b0d50c83461f8f5e22955fcb88f/src/x11_window.c)
/home/mint/Desktop/Cubyz/src/graphics/Window.zig:343:18: 0x1312194 in handleEvents (Cubyzig)
 c.glfwPollEvents();
                 ^
/home/mint/Desktop/Cubyz/src/main.zig:416:22: 0x130ae68 in main (Cubyzig)
  Window.handleEvents();
                     ^
/home/mint/Cubyz/compiler/zig/lib/std/start.zig:501:22: 0x130a579 in main (Cubyzig)
            root.main();
                     ^
../sysdeps/nptl/libc_start_call_main.h:58:16: 0x7fd96cd9ed8f in __libc_start_call_main (../sysdeps/x86/libc-start.c)
../csu/libc-start.c:392:3: 0x7fd96cd9ee3f in __libc_start_main_impl (../sysdeps/x86/libc-start.c)
???:?:?: 0x130a224 in ??? (???)
???:?:?: 0x0 in ??? (???)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah oops, didnt see the segfault under all of the thread sanitizers stuff.

}
pub fn onOpen() void {
const list = VerticalList.init(.{padding, 16 + padding}, 300, 16);
list.add(Button.initText(.{0, 0}, 128, "Singleplayer", gui.openWindowCallback("save_selection")));
list.add(Button.initText(.{0, 0}, 128, "Multiplayer", gui.openWindowCallback("multiplayer")));
list.add(Button.initText(.{0, 0}, 128, "Settings", gui.openWindowCallback("settings")));
list.add(Button.initText(.{0, 0}, 128, "Exit TODO", .{}));
list.add(Button.initText(.{0, 0}, 128, "TODO", .{.callback = &exitGame}));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the wrong word xD

list.finish(.center);
window.rootComponent = list.toComponent();
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @as(Vec2f, @splat(padding));
Expand Down
11 changes: 10 additions & 1 deletion src/gui/windows/pause.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,20 @@ pub var window = GuiWindow {

const padding: f32 = 8;

fn exitMenuCallbackFunction(_: usize) void {
if(main.game.world) |world| {
world.deinit();
main.game.world = null;
}
gui.openWindow("main");
}
pub fn onOpen() void {
const list = VerticalList.init(.{padding, 16 + padding}, 300, 16);
list.add(Button.initText(.{0, 0}, 128, "Invite Player", gui.openWindowCallback("invite")));
list.add(Button.initText(.{0, 0}, 128, "Settings", gui.openWindowCallback("settings")));
list.add(Button.initText(.{0, 0}, 128, "Exit to Menu TODO", .{}));
list.add(Button.initText(.{0, 0}, 128, "Exit to Menu TODO", .{
.callback = &exitMenuCallbackFunction,
}));
list.finish(.center);
window.rootComponent = list.toComponent();
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @as(Vec2f, @splat(padding));
Expand Down
10 changes: 5 additions & 5 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,17 @@ fn ungrabMouse() void {
}
fn openInventory() void {
if(game.world == null) return;
ungrabMouse();
gui.toggleGameMenu();
gui.openWindow("inventory");
}
fn openWorkbench() void {
if(game.world == null) return;
ungrabMouse();
gui.toggleGameMenu();
gui.openWindow("workbench");
}
fn openCreativeInventory() void {
if(game.world == null) return;
ungrabMouse();
gui.toggleGameMenu();
gui.openWindow("creative_inventory");
}
fn takeBackgroundImageFn() void {
Expand Down Expand Up @@ -280,8 +280,8 @@ pub const KeyBoard = struct {

// Gui:
.{.name = "escape", .key = c.GLFW_KEY_ESCAPE, .releaseAction = &escape},
.{.name = "openInventory", .key = c.GLFW_KEY_I, .releaseAction = &openInventory},
.{.name = "openWorkbench", .key = c.GLFW_KEY_K, .releaseAction = &openWorkbench}, // TODO: Remove
.{.name = "openInventory", .key = c.GLFW_KEY_E, .releaseAction = &openInventory},
.{.name = "openWorkbench", .key = c.GLFW_KEY_R, .releaseAction = &openWorkbench}, // TODO: Remove
.{.name = "openCreativeInventory(aka cheat inventory)", .key = c.GLFW_KEY_C, .releaseAction = &openCreativeInventory},
.{.name = "mainGuiButton", .mouseButton = c.GLFW_MOUSE_BUTTON_LEFT, .pressAction = &gui.mainButtonPressed, .releaseAction = &gui.mainButtonReleased},
.{.name = "secondaryGuiButton", .mouseButton = c.GLFW_MOUSE_BUTTON_RIGHT, .pressAction = &gui.secondaryButtonPressed, .releaseAction = &gui.secondaryButtonReleased},
Expand Down
14 changes: 7 additions & 7 deletions src/renderer/mesh_storage.zig
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,27 @@ pub fn deinit() void {
for(mapStorageLists) |mapStorageList| {
main.globalAllocator.destroy(mapStorageList);
}

for(updatableList.items) |mesh| {
mesh.decreaseRefCount();
}
updatableList.deinit();
updatableList.clearAndFree();
for(mapUpdatableList.items) |map| {
map.decreaseRefCount();
}
mapUpdatableList.deinit();
mapUpdatableList.clearAndFree();
for(priorityMeshUpdateList.items) |mesh| {
mesh.decreaseRefCount();
}
priorityMeshUpdateList.deinit();
blockUpdateList.deinit();
meshList.deinit();
priorityMeshUpdateList.clearAndFree();
blockUpdateList.clearAndFree();
meshList.clearAndFree();
for(clearList.items) |mesh| {
mesh.deinit();
main.globalAllocator.destroy(mesh);
}
clearList.deinit();
clearList.clearAndFree();
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unintended line removal?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an empty line, does it matter?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, just looked like it was unintentionally removed. If you made this change intentionally then I would like to know the intention though.

Copy link
Contributor Author

@tillpp tillpp May 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah i remember, that was when i made the "reset" function, but then we decided to just make the already existing deinit function use clearAndFree() , thus removing the need for the reset function
while deleting the reset() function, i also deleted one line to much

fn getNodePointer(pos: chunk.ChunkPosition) *ChunkMeshNode {
const lod = std.math.log2_int(u31, pos.voxelSize);
var xIndex = pos.wx >> lod+chunk.chunkShift;
Expand Down
Loading