-
Notifications
You must be signed in to change notification settings - Fork 187
Add Structure Building Blocks based Generator #1227
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
Merged
Merged
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
52ec760
Revert "Remove SBBGen"
Argmaster 388e3fc
Revert "Remove example SBB"
Argmaster 3e17dd5
Revert "Remove blueprint code"
Argmaster dfeb882
Merge remote-tracking branch 'origin/master' into feature/SBBGen
Argmaster c12c62c
Fix compilation errors
Argmaster 3eae3a9
Fix compilation errors #2
Argmaster 89f5674
Fix test errors
Argmaster 992d7a0
Fix rotateZ
Argmaster 09f8542
Resolve structure reference while instantiating SBBGen
Argmaster 7524338
Fix formatting issues
Argmaster 2e1125f
Merge remote-tracking branch 'origin/master' into feature/SBBGen
Argmaster 62e7850
Add new trees to forest
Argmaster 2b632c2
Add new trees to grassland
Argmaster 5a9143f
Decrease forest density so you can find new trees
Argmaster b534531
Add degradable paste mode
Argmaster fea832e
Remove substitutions
Argmaster 71c03e3
Apply review suggestions
Argmaster 21f46e2
Use lookup table for alignment
Argmaster a5d3ca9
Apply suggestions from code review
Argmaster 1c0f0b5
Update src/server/terrain/simple_structures/_list.zig
Argmaster 7c85c52
Merge remote-tracking branch 'upstream/master' into feature/SBBGen
Argmaster 1bb2642
Fix inital SBB offset
Argmaster 642ae5b
Never place air in placeInGeneration
Argmaster 1ed8d52
Integrate void block with paste
Argmaster 5499d1a
Merge remote-tracking branch 'origin/master' into feature/SBBGen
Argmaster 9482d4b
Revert "Move hashInt and hashCombine to utils"
Argmaster 27a6307
Merge branch 'feature/paste-void' into feature/SBBGen
Argmaster 4817f87
Make PasteMode comptime
Argmaster 7689b36
Merge remote-tracking branch 'origin/master' into feature/SBBGen
Argmaster 629b20b
Fix remaining issues with void block integration
Argmaster 49c565d
Fix formatting
Argmaster 0bdf687
Merge remote-tracking branch 'origin/master' into feature/SBBGen
Argmaster 2fbcd50
Apply review change requests
Argmaster 948c941
Remove origin and child blocks while resolving sbbs
Argmaster d17b5cb
Apply review change requests
Argmaster adaf49e
I hate indexing
Argmaster cba7a16
Fix example tree models
Argmaster 17b2309
Merge remote-tracking branch 'upstream/master' into feature/SBBGen
Argmaster bd8d67b
Use single index for chunk and blueprint in pasteInGeneration
Argmaster 6a9298d
Fix formatting
Argmaster 9118579
Extract blueprintOffset
Argmaster abca432
Fix formatting
Argmaster 73551f0
Apply suggestions from code review
Argmaster 5de9483
Apply Quantums suggestion for Y and Z
Argmaster 20827e7
No cast
Argmaster 6961d4f
Use pos instead of chunkOffset
Argmaster cdcf5b1
Remove test tree
Argmaster e31a469
Apply suggestions from code review
Argmaster 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| const std = @import("std"); | ||
|
|
||
| const main = @import("main"); | ||
| const terrain = main.server.terrain; | ||
| const Vec3i = main.vec.Vec3i; | ||
| const GenerationMode = terrain.biomes.SimpleStructureModel.GenerationMode; | ||
| const CaveMapView = terrain.CaveMap.CaveMapView; | ||
| const CaveBiomeMapView = terrain.CaveBiomeMap.CaveBiomeMapView; | ||
| const sbb = terrain.structure_building_blocks; | ||
| const Blueprint = main.blueprint.Blueprint; | ||
| const ZonElement = main.ZonElement; | ||
| const Neighbor = main.chunk.Neighbor; | ||
| const ServerChunk = main.chunk.ServerChunk; | ||
| const NeverFailingAllocator = main.heap.NeverFailingAllocator; | ||
|
|
||
| pub const id = "cubyz:sbb"; | ||
| pub const generationMode = .floor; | ||
|
|
||
| const SbbGen = @This(); | ||
|
|
||
| structureRef: *const sbb.StructureBuildingBlock, | ||
| placeMode: Blueprint.PasteMode, | ||
|
|
||
| pub fn getHash(self: SbbGen) u64 { | ||
| return std.hash.Wyhash.hash(@intFromEnum(self.placeMode), self.structureRef.id); | ||
| } | ||
|
|
||
| pub fn loadModel(arenaAllocator: NeverFailingAllocator, parameters: ZonElement) *SbbGen { | ||
| const structureId = parameters.get(?[]const u8, "structure", null) orelse unreachable; | ||
| const structureRef = sbb.getByStringId(structureId) orelse { | ||
| std.log.err("Could not find structure building block with id '{s}'", .{structureId}); | ||
| unreachable; | ||
| }; | ||
| const self = arenaAllocator.create(SbbGen); | ||
| self.* = .{ | ||
| .structureRef = structureRef, | ||
| .placeMode = std.meta.stringToEnum(Blueprint.PasteMode, parameters.get([]const u8, "placeMode", "degradable")) orelse Blueprint.PasteMode.degradable, | ||
| }; | ||
| return self; | ||
| } | ||
|
|
||
| pub fn generate(self: *SbbGen, _: GenerationMode, x: i32, y: i32, z: i32, chunk: *ServerChunk, _: CaveMapView, _: CaveBiomeMapView, seed: *u64, _: bool) void { | ||
Argmaster marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| placeSbb(self, self.structureRef, Vec3i{x, y, z}, Neighbor.dirUp, chunk, seed); | ||
| } | ||
|
|
||
| fn placeSbb(self: *SbbGen, structure: *const sbb.StructureBuildingBlock, placementPosition: Vec3i, placementDirection: Neighbor, chunk: *ServerChunk, seed: *u64) void { | ||
| const origin = structure.blueprints[0].originBlock; | ||
| const rotationCount = alignDirections(origin.direction(), placementDirection) catch |err| { | ||
| std.log.err("Could not align directions for structure '{s}' for directions '{s}'' and '{s}', error: {s}", .{structure.id, @tagName(origin.direction()), @tagName(placementDirection), @errorName(err)}); | ||
| return; | ||
| }; | ||
| const rotated = &structure.blueprints[rotationCount]; | ||
| const rotatedOrigin = rotated.originBlock.pos(); | ||
| const pastePosition = placementPosition - rotatedOrigin - placementDirection.relPos(); | ||
|
|
||
| rotated.blueprint.pasteInGeneration(pastePosition, chunk, self.placeMode); | ||
|
|
||
| for(rotated.childBlocks) |childBlock| { | ||
| const child = structure.pickChild(childBlock, seed); | ||
| placeSbb(self, child, pastePosition + childBlock.pos(), childBlock.direction(), chunk, seed); | ||
| } | ||
| } | ||
|
|
||
| fn alignDirections(input: Neighbor, desired: Neighbor) !usize { | ||
| const Rotation = enum(u3) { | ||
| @"0" = 0, | ||
| @"90" = 1, | ||
| @"180" = 2, | ||
| @"270" = 3, | ||
| NotPossibleToAlign = 4, | ||
| }; | ||
| comptime var alignTable: [6][6]Rotation = undefined; | ||
| comptime for(Neighbor.iterable) |in| { | ||
| for(Neighbor.iterable) |out| blk: { | ||
| var current = in; | ||
| for(0..4) |i| { | ||
| if(current == out) { | ||
| alignTable[in.toInt()][out.toInt()] = @enumFromInt(i); | ||
| break :blk; | ||
| } | ||
| current = current.rotateZ(); | ||
| } | ||
| alignTable[in.toInt()][out.toInt()] = Rotation.NotPossibleToAlign; | ||
| } | ||
| }; | ||
| switch(alignTable[input.toInt()][desired.toInt()]) { | ||
| .NotPossibleToAlign => return error.NotPossibleToAlign, | ||
| else => |v| return @intFromEnum(v), | ||
| } | ||
| } | ||
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
Oops, something went wrong.
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.