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

Allow the player to place and break voxels #317

Merged
merged 10 commits into from
Dec 18, 2023

Conversation

patowen
Copy link
Collaborator

@patowen patowen commented Oct 17, 2023

The main purpose of this PR is simple: allow the player to break blocks by left-clicking on them and allow them to place blocks by right-clicking on other blocks.

To enable this feature, there are several changes/additions (most important ones listed here):

  • Added a new ray tracing function to figure out what block is being clicked
  • Refactored collision checking code to allow some code-reuse by ray-tracing code
  • Removed use of chunk margins in collision-checking code and tried to adopt a consistent coordinate system of [u8; 3] without margins. Rendering code is unaffected by this change (margins were not removed entirely).
  • Added some methods to DualGraph to simplify common operations related to placing/breaking blocks
  • Added surface invalidation logic so that updating blocks reruns surface extraction
  • Partially implemented saving of voxel data (Loading logic doesn't yet exist, so this is not yet testable or useful).

There is also a minor cosmetic change, reducing ambient occlusion to make textures at the ends of 1x1 tunnels visible instead of being pitch black.

Fixes #292

@patowen patowen requested a review from Ralith October 17, 2023 03:27
@patowen patowen changed the title Block manipulation Allow the player to place and break blocks Oct 17, 2023
@patowen patowen changed the title Allow the player to place and break blocks Allow the player to place and break voxels Oct 17, 2023
@patowen
Copy link
Collaborator Author

patowen commented Oct 24, 2023

This PR is probably still worth reviewing, but I'll update it to a draft because it doesn't properly handle the case of Player B modifying a chunk that Player A has not generated and then Player A visiting that chunk later. I plan to address this later, and I'll check off the below task once I've done so:

  • TODO: Fix server-reported block updates in ungenerated chunks

Another issue is that for new clients that receive full chunk data from the server, there is no logic to remove the margins of chunks adjacent to any edited blocks, so this can result in visual bugs. Ideally, the solution to this does not involve the server in any way, since the server shouldn't need to care about margins. The solution to this doesn't need to be too efficient, as margin handling is still a work in progress to begin with.

  • TODO: Remove margins of all chunks adjacent to edited chunks, even those generated later.

@patowen patowen marked this pull request as draft October 24, 2023 04:01
@patowen patowen force-pushed the block-manipulation branch 3 times, most recently from 97420a9 to c371bc4 Compare October 27, 2023 23:34
@patowen patowen marked this pull request as ready for review October 27, 2023 23:45
@patowen patowen force-pushed the block-manipulation branch 2 times, most recently from 8db382c to dc0f45c Compare October 31, 2023 02:39
@patowen
Copy link
Collaborator Author

patowen commented Dec 7, 2023

I decided to remove the code that saves voxel edits in favor of putting that code in the PR that also loads voxel edits, since that way, the code will actually be tested.

common/src/node.rs Show resolved Hide resolved
common/src/node.rs Outdated Show resolved Hide resolved
client/src/sim.rs Show resolved Hide resolved
client/src/sim.rs Outdated Show resolved Hide resolved
common/src/chunk_ray_casting.rs Outdated Show resolved Hide resolved
common/src/node.rs Outdated Show resolved Hide resolved
common/src/node.rs Outdated Show resolved Hide resolved
common/src/node.rs Show resolved Hide resolved
client/src/sim.rs Outdated Show resolved Hide resolved
common/src/node.rs Outdated Show resolved Hide resolved
@patowen patowen force-pushed the block-manipulation branch 2 times, most recently from 9ab5c48 to 2ac704f Compare December 15, 2023 03:09
@patowen patowen requested a review from Ralith December 15, 2023 03:10
Copy link
Owner

@Ralith Ralith left a comment

Choose a reason for hiding this comment

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

Just a few cosmetic issues; otherwise LGTM!

common/src/node.rs Outdated Show resolved Hide resolved
common/src/chunk_ray_casting.rs Outdated Show resolved Hide resolved
common/src/node.rs Show resolved Hide resolved
common/src/node.rs Outdated Show resolved Hide resolved
@patowen patowen merged commit 664a2f4 into Ralith:master Dec 18, 2023
6 checks passed
@patowen patowen deleted the block-manipulation branch December 18, 2023 03:40
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.

Add voxel manipulation
2 participants