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

Add list palettes and item palette #1190

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

Argmaster
Copy link
Contributor

@Argmaster Argmaster commented Mar 11, 2025

This pull request:

  • Changes palette storage format from hash map to list
  • Adds item palette storage in item_palette.zig.zon

Unfortunately I have developed both features at once sort of my mistake, but they are kind of small so maybe its even better.

Migration for older saves is done by supporting loading from old format and saving only in new format.

Resolves: #1146

Related to: #1125
Related to: #1157

@Argmaster Argmaster marked this pull request as ready for review March 11, 2025 00:38
This was referenced Mar 11, 2025
if(self.palette.items.len == 0) {
self.palette.append(allocator.dupe(u8, elem));
}
std.debug.assert(std.mem.eql(u8, self.palette.items[0], elem));
Copy link
Member

Choose a reason for hiding this comment

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

Since you touched this code anyways:
This should probably return an error instead of silently failing in ReleaseFast.

const self = allocator.create(Palette);
self.* = Palette{
.palette = .init(allocator),
.palette = .initCapacity(allocator, @max(items.len, 128)),
Copy link
Member

Choose a reason for hiding this comment

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

I think you can just use items.len here, the max seems to just adds additional complexity without even giving a clear performance benefit.
I do agree though that it makes sense to use initCapacity when the length is known.

const translationPalette = main.stackAllocator.alloc(?[]const u8, paletteLength);
defer main.stackAllocator.free(translationPalette);

for(translationPalette) |*elem| elem.* = null;
Copy link
Member

Choose a reason for hiding this comment

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

Could use @memset

if(!zon.get(bool, "hasItem", true)) continue;
try registerItem(assetFolder, stringId, zon.getChild("item"));
continue;
}
Copy link
Member

Choose a reason for hiding this comment

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

How difficult would it be to handle id conflicts? (item exists in the blocks folder and in the item folder)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change how the block and biome palettes are stored.
2 participants