-
Notifications
You must be signed in to change notification settings - Fork 188
Split structures out of biomes #2131
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
Open
BoySanic
wants to merge
7
commits into
PixelGuys:master
Choose a base branch
from
BoySanic:split-structures
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b4a26dd
Formatting mistakes
BoySanic 399fa04
Refactor my own refactor
BoySanic b22b8fd
Remove StructureTable struct temporarily as it's irrelevant to this PR
BoySanic 83c3e3d
Moving hash into terrain
BoySanic cf561be
Fix things after rebase
BoySanic c1fbab4
move hashing back to biomes
BoySanic c5ab8fc
Merge remote-tracking branch 'upstream/master' into split-structures
BoySanic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| const std = @import("std"); | ||
|
|
||
| const main = @import("main"); | ||
| const ZonElement = main.ZonElement; | ||
| const NeverFailingAllocator = main.heap.NeverFailingAllocator; | ||
| const ServerChunk = main.chunk.ServerChunk; | ||
| const terrain = main.server.terrain; | ||
| const Biome = main.server.terrain.biomes; | ||
|
|
||
| pub const SimpleStructureModel = struct { // MARK: SimpleStructureModel | ||
| pub const GenerationMode = enum { | ||
| floor, | ||
| ceiling, | ||
| floor_and_ceiling, | ||
| air, | ||
| underground, | ||
| water_surface, | ||
| }; | ||
| const VTable = struct { | ||
| loadModel: *const fn(parameters: ZonElement) ?*anyopaque, | ||
| generate: *const fn(self: *anyopaque, generationMode: GenerationMode, x: i32, y: i32, z: i32, chunk: *ServerChunk, caveMap: terrain.CaveMap.CaveMapView, biomeMap: terrain.CaveBiomeMap.CaveBiomeMapView, seed: *u64, isCeiling: bool) void, | ||
| hashFunction: *const fn(self: *anyopaque) u64, | ||
| generationMode: GenerationMode, | ||
| }; | ||
|
|
||
| vtable: VTable, | ||
| data: *anyopaque, | ||
| chance: f32, | ||
| priority: f32, | ||
| generationMode: GenerationMode, | ||
|
|
||
| pub fn initModel(parameters: ZonElement) ?SimpleStructureModel { | ||
| const id = parameters.get([]const u8, "id", ""); | ||
| const vtable = modelRegistry.get(id) orelse { | ||
| std.log.err("Couldn't find structure model with id {s}", .{id}); | ||
| return null; | ||
| }; | ||
| const vtableModel = vtable.loadModel(parameters) orelse { | ||
| std.log.err("Error occurred while loading structure with id '{s}'. Dropping model from biome.", .{id}); | ||
| return null; | ||
| }; | ||
| return SimpleStructureModel{ | ||
| .vtable = vtable, | ||
| .data = vtableModel, | ||
| .chance = parameters.get(f32, "chance", 0.1), | ||
| .priority = parameters.get(f32, "priority", 1), | ||
| .generationMode = std.meta.stringToEnum(GenerationMode, parameters.get([]const u8, "generationMode", "")) orelse vtable.generationMode, | ||
| }; | ||
| } | ||
|
|
||
| pub fn generate(self: SimpleStructureModel, x: i32, y: i32, z: i32, chunk: *ServerChunk, caveMap: terrain.CaveMap.CaveMapView, biomeMap: terrain.CaveBiomeMap.CaveBiomeMapView, seed: *u64, isCeiling: bool) void { | ||
| self.vtable.generate(self.data, self.generationMode, x, y, z, chunk, caveMap, biomeMap, seed, isCeiling); | ||
| } | ||
|
|
||
| var modelRegistry: std.StringHashMapUnmanaged(VTable) = .{}; | ||
|
|
||
| pub fn registerGenerator(comptime Generator: type) void { | ||
| var self: VTable = undefined; | ||
| self.loadModel = main.utils.castFunctionReturnToOptionalAnyopaque(Generator.loadModel); | ||
| self.generate = main.utils.castFunctionSelfToAnyopaque(Generator.generate); | ||
| self.hashFunction = main.utils.castFunctionSelfToAnyopaque(struct { | ||
| fn hash(ptr: *Generator) u64 { | ||
| return Biome.hashGeneric(ptr.*); | ||
| } | ||
| }.hash); | ||
| self.generationMode = Generator.generationMode; | ||
| modelRegistry.put(main.globalArena.allocator, Generator.id, self) catch unreachable; | ||
| } | ||
|
|
||
| fn getHash(self: SimpleStructureModel) u64 { | ||
| return self.vtable.hashFunction(self.data); | ||
| } | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.