Hopson97 / open-builder

Open "Minecraft-like" game with multiplayer support and Lua scripting support for the both client and server
https://github.com/Hopson97/open-builder/projects/3
GNU General Public License v3.0
700 stars 80 forks source link

Render Distance #185

Closed gml16 closed 4 years ago

gml16 commented 4 years ago

This addresses issue #146. I have not implemented fog, only render distance (using Manhattan distance). By default the render distance is set to 5 chunks away.

Implementation

In chunk_renderer.cpp, the runderChunks method now goes through unrendered chunks and render them if in range at each tick and then goes through all rendered chunks and unrenders those not in range anymore (this means at each tick the client has to loop through all rendered chunks, hopefully that's not impacting performance). Render distance is set by default in chunk_renderer.h but should prob be added in the config files (was not entirely sure the best way to go about this, don't hesitate to let me know and I'll make further commits). I'm new to OpenGl and will look into good ways to create a fog effect.

gml16 commented 4 years ago

Thank you for pointing it out, will comment next time. Just to clarify, if we were to call isChunkInRenderDistance function directly from the other renderChunks, close chunks would load but once we get further away they would not "despawn". Is this the intended behaviour? At the moment chunks stop being rendered once the player gets far away enough.

gml16 commented 4 years ago

I've updated the PR so that the code is cleaner now (using Euclidean distance as well).