-
Notifications
You must be signed in to change notification settings - Fork 116
feature/light propagation #916
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
izekblz
wants to merge
14
commits into
ryanhcode:main
Choose a base branch
from
izekblz:main
base: main
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
14 commits
Select commit
Hold shift + click to select a range
6f50ae6
Replace @Overwrite on getPackedLightCoords with @Inject + @Redirect t…
izekblz bf8cc12
Light-emitting blocks on sub-levels now illuminate nearby world block…
izekblz 527033d
Add world → sub-level light propagation. World light sources now illu…
izekblz a2b821a
Light-emitting blocks on sub-levels now illuminate nearby world block…
izekblz 978f7c1
Add sub-level to sub-level light propagation
izekblz 90dcb45
Fabric compatibility
izekblz 8fd8a18
fix/prevent chunk deadlock from synchronous loads during physics tick…
izekblz 012ac36
Automated build rust natives
github-actions[bot] fe1b57b
Fix world-light not propagating to newly created sub-levels until the…
izekblz 53865b4
Manual pass to rewrite and remove obsolete code
izekblz d28d871
Move all lighting logic to server side, optimize light source scans a…
izekblz 116c173
Resolve merge conflict
izekblz a9c9819
Delete dead client-side virtual light overlay
izekblz 23ba43a
Comment and formatting update
izekblz 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
41 changes: 41 additions & 0 deletions
41
...src/main/java/dev/ryanhcode/sable/mixin/plot/lighting/server/LightEngineOpacityMixin.java
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,41 @@ | ||
| package dev.ryanhcode.sable.mixin.plot.lighting.server; | ||
|
|
||
| import dev.ryanhcode.sable.render.light_bridge.ServerSubLevelLightInjector; | ||
| import dev.ryanhcode.sable.render.light_bridge.ServerSubLevelWorldInjector; | ||
| import net.minecraft.core.BlockPos; | ||
| import net.minecraft.core.Direction; | ||
| import net.minecraft.world.level.block.state.BlockState; | ||
| import net.minecraft.world.level.lighting.LightEngine; | ||
| import org.spongepowered.asm.mixin.Mixin; | ||
| import org.spongepowered.asm.mixin.injection.At; | ||
| import org.spongepowered.asm.mixin.injection.Inject; | ||
| import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
|
||
| @Mixin(LightEngine.class) | ||
| public abstract class LightEngineOpacityMixin { | ||
|
|
||
| @Inject(method = "getOpacity", at = @At("HEAD"), cancellable = true) | ||
| private void sable$blockLightAtOpaquePositions(final BlockState state, final BlockPos pos, final CallbackInfoReturnable<Integer> cir) { | ||
| final long packed = pos.asLong(); | ||
| if (ServerSubLevelWorldInjector.isOpaqueAt(packed)) { | ||
| cir.setReturnValue(16); | ||
| return; | ||
| } | ||
| if (ServerSubLevelLightInjector.isWorldOpaqueInPlot(packed)) { | ||
| cir.setReturnValue(16); | ||
| } | ||
| } | ||
|
|
||
| @Inject(method = "shapeOccludes", at = @At("HEAD"), cancellable = true) | ||
| private void sable$shapeOccludesSubLevel(final long sourcePos, final BlockState sourceState, final long targetPos, final BlockState targetState, final Direction direction, final CallbackInfoReturnable<Boolean> cir) { | ||
| final byte targetMask = ServerSubLevelWorldInjector.getShapeOcclusion(targetPos); | ||
| if (targetMask != 0 && (targetMask & (1 << direction.getOpposite().ordinal())) != 0) { | ||
| cir.setReturnValue(true); | ||
| return; | ||
| } | ||
| final byte sourceMask = ServerSubLevelWorldInjector.getShapeOcclusion(sourcePos); | ||
| if (sourceMask != 0 && (sourceMask & (1 << direction.ordinal())) != 0) { | ||
| cir.setReturnValue(true); | ||
| } | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
.../main/java/dev/ryanhcode/sable/mixin/plot/lighting/server/ServerChunkCacheLightMixin.java
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,32 @@ | ||
| package dev.ryanhcode.sable.mixin.plot.lighting.server; | ||
|
|
||
| import dev.ryanhcode.sable.render.light_bridge.ServerSubLevelLightInjector; | ||
| import net.minecraft.core.SectionPos; | ||
| import net.minecraft.server.level.ServerChunkCache; | ||
| import net.minecraft.server.level.ServerLevel; | ||
| import net.minecraft.world.level.LightLayer; | ||
| import org.spongepowered.asm.mixin.Final; | ||
| import org.spongepowered.asm.mixin.Mixin; | ||
| import org.spongepowered.asm.mixin.Shadow; | ||
| import org.spongepowered.asm.mixin.injection.At; | ||
| import org.spongepowered.asm.mixin.injection.Inject; | ||
| import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
|
||
| /** | ||
| * Forwards server-side block-light updates to the {@link ServerSubLevelLightInjector} so plots | ||
| * can be re-scanned and reinjected if the change occurred near a sub-level. | ||
| */ | ||
| @Mixin(ServerChunkCache.class) | ||
| public class ServerChunkCacheLightMixin { | ||
|
|
||
| @Shadow @Final private ServerLevel level; | ||
|
|
||
| @Inject(method = "onLightUpdate", at = @At("RETURN")) | ||
| private void sable$forwardBlockLightUpdate(final LightLayer layer, final SectionPos pos, final CallbackInfo ci) { | ||
| if (layer != LightLayer.BLOCK) { | ||
| return; | ||
| } | ||
|
|
||
| ServerSubLevelLightInjector.onServerLightUpdate(this.level, pos.getX(), pos.getY(), pos.getZ()); | ||
| } | ||
| } |
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
33 changes: 33 additions & 0 deletions
33
common/src/main/java/dev/ryanhcode/sable/render/light_bridge/PlotLocalLightData.java
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,33 @@ | ||
| package dev.ryanhcode.sable.render.light_bridge; | ||
|
|
||
| /** | ||
| * Cached plot-local block data for a sub-level's light-relevant blocks. | ||
| * Populated once on block change, re-projected to world space on movement. | ||
| */ | ||
| public final class PlotLocalLightData { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be a record |
||
|
|
||
| /** Plot-local packed positions of fully opaque blocks (canOcclude && !useShapeForLightOcclusion). */ | ||
| public final long[] opaquePositions; | ||
|
|
||
| /** Plot-local packed positions of light-emitting blocks. */ | ||
| public final long[] emitterPositions; | ||
|
|
||
| /** Emission level (1-15) parallel to emitterPositions. */ | ||
| public final byte[] emitterLevels; | ||
|
|
||
| /** Plot-local packed positions of shape-occluding blocks (useShapeForLightOcclusion). */ | ||
| public final long[] shapePositions; | ||
|
|
||
| /** Face occlusion mask (6 bits) parallel to shapePositions. */ | ||
| public final byte[] shapeMasks; | ||
|
|
||
| public PlotLocalLightData(final long[] opaquePositions, final long[] emitterPositions, final byte[] emitterLevels, final long[] shapePositions, final byte[] shapeMasks) { | ||
| this.opaquePositions = opaquePositions; | ||
| this.emitterPositions = emitterPositions; | ||
| this.emitterLevels = emitterLevels; | ||
| this.shapePositions = shapePositions; | ||
| this.shapeMasks = shapeMasks; | ||
| } | ||
|
|
||
| public static final PlotLocalLightData EMPTY = new PlotLocalLightData(new long[0], new long[0], new byte[0], new long[0], new byte[0]); | ||
| } | ||
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.
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.
Whats the reason for this? As far as i can see accelerator.getChunk is nonnull
Uh oh!
There was an error while loading. Please reload this page.
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.
For some reason got crashes on my server on world load, logs suggested possible chunk load before it initialized (even with base Sable build), didn't dig too deep there. Although I was supposed to remove that before doing a PR, whoops