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鈥檒l 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 all 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.c.glfwSetWindowShouldClose(main.Window.window,main.Window.c.GLFW_TRUE);
}
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, "Touch Grass", .{.callback = &exitGame}));
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
13 changes: 7 additions & 6 deletions src/renderer/mesh_storage.zig
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,26 @@ 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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

reintroduced the line, just 4u!

fn getNodePointer(pos: chunk.ChunkPosition) *ChunkMeshNode {
Expand Down
Loading