-
Notifications
You must be signed in to change notification settings - Fork 67
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
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: IntegratedQuantum <43880493+IntegratedQuantum@users.noreply.github.com>
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)); |
There was a problem hiding this comment.
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)), |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; | ||
} |
There was a problem hiding this comment.
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)
This pull request:
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