Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/MC_1.17_lighting' into MC_1.17_Jar
Browse files Browse the repository at this point in the history
  • Loading branch information
CorgiTaco committed Jun 15, 2021
2 parents 5e8e430 + c9575d5 commit 7268a55
Show file tree
Hide file tree
Showing 55 changed files with 1,450 additions and 349 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ minecraft {
"-Dcubicchunks.debug.window=false",
"-Dcubicchunks.debug.statusrenderer=false",
"-Dcubicchunks.debug.biomes=false",
"-ea"
]

runConfigs {
Expand Down
2 changes: 1 addition & 1 deletion config/checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<!-- we are not fixing setBlockState -->
<suppress checks="CyclomaticComplexity" files="BigCube.java|CubePrimer.java"/>
<!-- TODO: These probably need refactoring -->
<suppress checks="CyclomaticComplexity" files="CubicWorldLoadScreen.java|CubeSerializer.java|DebugVisualization.java"/>
<suppress checks="CyclomaticComplexity" files="CubicWorldLoadScreen.java|CubeSerializer.java|DebugVisualization.java|LightSurfaceTrackerSection.java"/>
<!-- TODO: DebugVulkan doesn't work yet anyway, and this requires some refactoring -->
<suppress checks="NPathComplexity" files="DebugVulkan.java"/>
<!-- Mixins don't count for now until ASM is done -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.github.opencubicchunks.cubicchunks.chunk;

import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

public class CubeMap {
private final ConcurrentHashMap.KeySetView<Integer, Boolean> loadedCubes = ConcurrentHashMap.newKeySet();

public boolean isLoaded(int cubeY) {
return loadedCubes.contains(cubeY);
}

public void markLoaded(int cubeY) {
loadedCubes.add(cubeY);
}

public void markUnloaded(int cubeY) {
loadedCubes.remove(cubeY);
}

public Set<Integer> getLoaded() {
return loadedCubes;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.github.opencubicchunks.cubicchunks.chunk;

public interface CubeMapGetter {
CubeMap getCubeMap();
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import javax.annotation.Nullable;

import io.github.opencubicchunks.cubicchunks.chunk.heightmap.LightSurfaceTrackerSection;
import io.github.opencubicchunks.cubicchunks.chunk.heightmap.SurfaceTrackerSection;
import io.github.opencubicchunks.cubicchunks.chunk.util.CubePos;
import io.github.opencubicchunks.cubicchunks.meta.EarlyConfig;
Expand Down Expand Up @@ -88,4 +89,7 @@ default void setCubeBlockEntity(CompoundTag nbt) {

default void loadHeightmapSection(SurfaceTrackerSection section, int localSectionX, int localSectionZZ) {
}

default void setLightHeightmapSection(LightSurfaceTrackerSection section, int localSectionX, int localSectionZZ) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public interface IChunkManager {
@Nullable
ChunkHolder updateCubeScheduling(long cubePosIn, int newLevel, @Nullable ChunkHolder holder, int oldLevel);

void setServerChunkCache(ServerChunkCache cache);
LongSet getCubesToDrop();

@Nullable
Expand Down Expand Up @@ -121,6 +122,4 @@ static int getCubeDistanceXZ(CubePos cubePosIn, int x, int z) {
void releaseLightTicket(CubePos cubePos);

boolean noPlayersCloseForSpawning(CubePos cubePos);

void setServerChunkCache(ServerChunkCache cache);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ static ChunkStatus getCubeStatusFromLevel(int cubeLevel) {
return cubeLevel < 33 ? ChunkStatus.FULL : CubeStatus.getStatus(cubeLevel - 33);
}

void setChunkHolders(ChunkHolder[] chunkHolders);

ChunkHolder[] getChunkHolders();

@Nullable
BigCube getCubeIfComplete();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.github.opencubicchunks.cubicchunks.chunk;

import io.github.opencubicchunks.cubicchunks.chunk.heightmap.ClientLightSurfaceTracker;
import io.github.opencubicchunks.cubicchunks.chunk.heightmap.LightSurfaceTrackerWrapper;
import net.minecraft.world.level.levelgen.Heightmap;

public interface LightHeightmapGetter {
Heightmap getLightHeightmap();

// Do not override this
default ClientLightSurfaceTracker getClientLightHeightmap() {
Heightmap lightHeightmap = this.getLightHeightmap();
if (!(lightHeightmap instanceof ClientLightSurfaceTracker)) {
throw new IllegalStateException("Attempted to get client light heightmap on server");
}
return (ClientLightSurfaceTracker) lightHeightmap;
}

// Do not override this
default LightSurfaceTrackerWrapper getServerLightHeightmap() {
Heightmap lightHeightmap = this.getLightHeightmap();
if (!(lightHeightmap instanceof LightSurfaceTrackerWrapper)) {
throw new IllegalStateException("Attempted to get server light heightmap on client");
}
return (LightSurfaceTrackerWrapper) lightHeightmap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import io.github.opencubicchunks.cubicchunks.CubicChunks;
import io.github.opencubicchunks.cubicchunks.chunk.CubeMapGetter;
import io.github.opencubicchunks.cubicchunks.chunk.IBigCube;
import io.github.opencubicchunks.cubicchunks.chunk.ImposterChunkPos;
import io.github.opencubicchunks.cubicchunks.chunk.LightHeightmapGetter;
import io.github.opencubicchunks.cubicchunks.chunk.heightmap.LightSurfaceTrackerSection;
import io.github.opencubicchunks.cubicchunks.chunk.heightmap.SurfaceTrackerSection;
import io.github.opencubicchunks.cubicchunks.chunk.heightmap.SurfaceTrackerWrapper;
import io.github.opencubicchunks.cubicchunks.chunk.util.CubePos;
Expand Down Expand Up @@ -110,6 +113,7 @@ public String getType() {
private final Map<StructureFeature<?>, LongSet> structuresRefences;

private final Map<Heightmap.Types, SurfaceTrackerSection[]> heightmaps;
private final LightSurfaceTrackerSection[] lightHeightmaps = new LightSurfaceTrackerSection[4];

private ChunkBiomeContainer cubeBiomeContainer;

Expand Down Expand Up @@ -218,10 +222,26 @@ public BigCube(Level worldIn, CubePrimer cubePrimer, @Nullable Consumer<BigCube>
this.setAllReferences(cubePrimer.getAllReferences());
// var4 = protoChunk.getHeightmaps().iterator();

LightSurfaceTrackerSection[] primerLightHeightmaps = cubePrimer.getLightHeightmaps();
for (int i = 0; i < IBigCube.DIAMETER_IN_SECTIONS * IBigCube.DIAMETER_IN_SECTIONS; i++) {
this.lightHeightmaps[i] = primerLightHeightmaps[i];
if (this.lightHeightmaps[i] == null) {
System.out.println("Got a null light heightmap while upgrading from CubePrimer at " + this.cubePos);
} else {
this.lightHeightmaps[i].upgradeCube(this);
}
}

this.setCubeLight(cubePrimer.hasCubeLight());
this.dirty = true;
}

@Override public void setLightHeightmapSection(LightSurfaceTrackerSection section, int localSectionX, int localSectionZ) {
int idx = localSectionX + localSectionZ * DIAMETER_IN_SECTIONS;

this.lightHeightmaps[idx] = section;
}

@Deprecated @Override public ChunkPos getPos() {
throw new UnsupportedOperationException("Not implemented");
}
Expand Down Expand Up @@ -983,14 +1003,20 @@ public void postLoad() {
ChunkPos pos = this.cubePos.asChunkPos();
for (int x = 0; x < IBigCube.DIAMETER_IN_SECTIONS; x++) {
for (int z = 0; z < IBigCube.DIAMETER_IN_SECTIONS; z++) {
// TODO we really, *really* shouldn't be force-loading columns here.
// probably the easiest approach until we get a "columns before cubes" invariant though.

// TODO force-loading columns is questionable, until we get load order
LevelChunk chunk = this.level.getChunk(pos.x + x, pos.z + z);
((CubeMapGetter) chunk).getCubeMap().markLoaded(this.cubePos.getY());
for (Map.Entry<Heightmap.Types, Heightmap> entry : chunk.getHeightmaps()) {
Heightmap heightmap = entry.getValue();
SurfaceTrackerWrapper tracker = (SurfaceTrackerWrapper) heightmap;
tracker.loadCube(this);
}

if (!this.level.isClientSide) {
// TODO probably don't want to do this if the cube was already loaded as a CubePrimer
((LightHeightmapGetter) chunk).getServerLightHeightmap().loadCube(this);
}
}
}
}
Expand Down
Loading

0 comments on commit 7268a55

Please sign in to comment.