-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Pass light updates to LightStorage so that we don't have to re-upload every tracked section every frame - Slightly optimize light section writing, still room for improvement - Remove dead code in LightStorage
- Loading branch information
Showing
4 changed files
with
105 additions
and
50 deletions.
There are no files selected for viewing
This file contains 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
32 changes: 32 additions & 0 deletions
32
common/src/backend/java/dev/engine_room/flywheel/backend/engine/embed/LightUpdateHolder.java
This file contains 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.engine_room.flywheel.backend.engine.embed; | ||
|
||
import dev.engine_room.flywheel.lib.util.LevelAttached; | ||
import it.unimi.dsi.fastutil.longs.LongArraySet; | ||
import it.unimi.dsi.fastutil.longs.LongSet; | ||
import net.minecraft.world.level.LevelAccessor; | ||
|
||
/** | ||
* Stores the set of updates light sections for LightStorage to poll in its frame plan. | ||
*/ | ||
public class LightUpdateHolder { | ||
private static final LevelAttached<LightUpdateHolder> HOLDERS = new LevelAttached<>(level -> new LightUpdateHolder()); | ||
|
||
public static LightUpdateHolder get(LevelAccessor level) { | ||
return HOLDERS.get(level); | ||
} | ||
|
||
private final LongSet updatedSections = new LongArraySet(); | ||
|
||
public LongSet getUpdatedSections() { | ||
var out = new LongArraySet(updatedSections); | ||
updatedSections.clear(); | ||
return out; | ||
} | ||
|
||
public void add(long section) { | ||
updatedSections.add(section); | ||
} | ||
|
||
private LightUpdateHolder() { | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
common/src/backend/java/dev/engine_room/flywheel/backend/mixin/ClientChunkCacheMixin.java
This file contains 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,29 @@ | ||
package dev.engine_room.flywheel.backend.mixin; | ||
|
||
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; | ||
|
||
import dev.engine_room.flywheel.backend.engine.embed.LightUpdateHolder; | ||
import net.minecraft.client.multiplayer.ClientChunkCache; | ||
import net.minecraft.client.multiplayer.ClientLevel; | ||
import net.minecraft.core.SectionPos; | ||
import net.minecraft.world.level.LightLayer; | ||
|
||
@Mixin(ClientChunkCache.class) | ||
abstract class ClientChunkCacheMixin { | ||
@Shadow | ||
@Final | ||
ClientLevel level; | ||
|
||
@Inject(method = "onLightUpdate", at = @At("HEAD")) | ||
private void flywheel$backend$onLightUpdate(LightLayer layer, SectionPos pos, CallbackInfo ci) { | ||
// This is duplicated from code in impl, but I'm not sure that it | ||
// makes sense to be generically passed to backends. | ||
LightUpdateHolder.get(level) | ||
.add(pos.asLong()); | ||
} | ||
} |
This file contains 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