Skip to content

Commit dfb266a

Browse files
committed
fix renderglitches when changing render distance ingame
1 parent 82dd317 commit dfb266a

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/ui/GameScreen.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public override void onKeyDown(IKeyboard keyboard, Key key, int scancode) {
181181

182182
// reload chunks
183183
if (key == Key.A && keyboard.IsKeyPressed(Key.F3)) {
184-
remeshWorld();
184+
remeshWorld(Settings.instance.renderDistance);
185185
}
186186

187187
if (key == Key.F) {
@@ -229,12 +229,18 @@ public override void onKeyDown(IKeyboard keyboard, Key key, int scancode) {
229229
}
230230
}
231231

232-
public void remeshWorld() {
232+
public void remeshWorld(int oldRenderDist) {
233233
setUniforms();
234234
foreach (var chunk in world.chunks.Values) {
235235
// don't set chunk if not loaded yet, else we will have broken chunkgen/lighting errors
236236
if (chunk.status >= ChunkStatus.MESHED) {
237-
chunk.meshChunk();
237+
if (oldRenderDist < Settings.instance.renderDistance) {
238+
// just unload everything
239+
chunk.status = ChunkStatus.MESHED - 1;
240+
}
241+
else {
242+
chunk.meshChunk();
243+
}
238244
}
239245
}
240246
world.player.loadChunksAroundThePlayer(Settings.instance.renderDistance);

src/ui/SettingsMenu.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public SettingsMenu() {
4444
AO.topCentre();
4545
AO.clicked += () => {
4646
settings.AO = AO.getIndex() == 1;
47-
remeshIfRequired();
47+
remeshIfRequired(settings.renderDistance);
4848
};
4949
AO.tooltip = "Ambient Occlusion makes block corners darker to simulate shadows.";
5050
settingElements.Add(AO);
@@ -55,7 +55,7 @@ public SettingsMenu() {
5555
smoothLighting.topCentre();
5656
smoothLighting.clicked += () => {
5757
settings.smoothLighting = smoothLighting.getIndex() == 1;
58-
remeshIfRequired();
58+
remeshIfRequired(settings.renderDistance);
5959
};
6060
smoothLighting.tooltip = "Smooth Lighting improves the game's look by smoothing the lighting between blocks.";
6161
settingElements.Add(smoothLighting);
@@ -92,7 +92,7 @@ public SettingsMenu() {
9292
renderDistance.tooltip = "The maximum distance at which blocks are rendered.\nHigher values may reduce performance.";
9393
renderDistance.applied += () => {
9494
settings.renderDistance = (int)renderDistance.value;
95-
remeshIfRequired();
95+
remeshIfRequired((int)renderDistance.value);
9696
};
9797
renderDistance.getText = value => "Render Distance: " + value;
9898
settingElements.Add(renderDistance);
@@ -127,9 +127,9 @@ public SettingsMenu() {
127127
layoutSettingsTwoCols(settingElements, new Vector2D<int>(0, 16), vsync.GUIbounds.Width);
128128
}
129129

130-
private void remeshIfRequired() {
130+
private void remeshIfRequired(int oldRenderDist) {
131131
if (Game.instance.currentScreen == Screen.GAME_SCREEN) {
132-
Screen.GAME_SCREEN.remeshWorld();
132+
Screen.GAME_SCREEN.remeshWorld(oldRenderDist);
133133
}
134134
}
135135

0 commit comments

Comments
 (0)