Skip to content

Commit

Permalink
Optimize lightmap complexity initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
PhiProven committed Dec 18, 2021
1 parent f436725 commit 6a62651
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ protected int getLightmapComplexityChange(final long blockPos, final int oldVal,

@Override
protected int getInitialLightmapComplexity(final long sectionPos, final ChunkNibbleArray lightmap) {
if (lightmap.isUninitialized()) {
return 0;
}

int complexity = 0;

for (int y = 0; y < 16; ++y) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,13 @@ protected void beforeLightmapChange(final long sectionPos, final ChunkNibbleArra

@Override
protected int getInitialLightmapComplexity(final long sectionPos, final ChunkNibbleArray lightmap) {
final long sectionPosAbove = this.getSectionAbove(sectionPos);
final int skyLight = this.getDirectSkylight(sectionPos);

if (lightmap.isUninitialized()) {
return sectionPosAbove == Long.MAX_VALUE ? 256 * skyLight : this.vanillaLightmapComplexities.get(sectionPosAbove);
}

int complexity = 0;

for (int y = 0; y < 15; ++y) {
Expand All @@ -953,8 +960,7 @@ protected int getInitialLightmapComplexity(final long sectionPos, final ChunkNib
}
}

final ChunkNibbleArray lightmapAbove = this.getLightmapAbove(sectionPos);
final int skyLight = this.getDirectSkylight(sectionPos);
final ChunkNibbleArray lightmapAbove = sectionPosAbove == Long.MAX_VALUE ? null : this.getLightSection(sectionPosAbove, true);

for (int z = 0; z < 16; ++z) {
for (int x = 0; x < 16; ++x) {
Expand Down Expand Up @@ -1074,9 +1080,11 @@ public void onLoadSection(final long sectionPos) {
private int initializeVanillaLightmapComplexity(final long sectionPos, final ChunkNibbleArray lightmap) {
int complexity = 0;

for (int z = 0; z < 16; ++z) {
for (int x = 0; x < 16; ++x) {
complexity += lightmap.get(x, 0, z);
if (!lightmap.isUninitialized()) {
for (int z = 0; z < 16; ++z) {
for (int x = 0; x < 16; ++x) {
complexity += lightmap.get(x, 0, z);
}
}
}

Expand Down

0 comments on commit 6a62651

Please sign in to comment.