Skip to content

Buffer Backed Terrain (for Bullet physics optimization)#303

Open
yahel-ck wants to merge 4 commits into
JamesTKhan:masterfrom
yahel-ck:feature/buffer_backed_terrain
Open

Buffer Backed Terrain (for Bullet physics optimization)#303
yahel-ck wants to merge 4 commits into
JamesTKhan:masterfrom
yahel-ck:feature/buffer_backed_terrain

Conversation

@yahel-ck

@yahel-ck yahel-ck commented Apr 12, 2025

Copy link
Copy Markdown

This change adds a BufferTerrain class which is exactly the same as the current Terrain class but stores the height data in a FloatBuffer rather than an array.

I use this to share the height data with the physics library (LibGDX's Bullet wrapper) instead of copying the height data which can cost a lot of CPU and RAM usage.
Sharing the height data with the current Terrain class is impossible because Bullet needs the data to be stored in a direct buffer, which the java array cannot be converted into.

I chose to implement this in a new class and not change the current Terrain class because that would be too big of a change.

The changes I made in summary:

  • added a TerrainInfo interface to expose the relevant information for the TerrainMaterial without relaying on a specific terrain implementation.
  • added a BaseTerrain class which is a copy of the current Terrain with an abstract getHeight method instead of a heightData array.
  • made Terrain and BufferTerrain implement BaseTerrain with a backing float array/buffer.

I haven't changed anything editor related, so the editor still uses the original Terrain class and behavior is exactly the same.
I personally use this optimization for in-game procedural generation.
Using this optimization in the editor and in asset loading can be implemented in a separate PR, this change is mostly useful for direct use with the Mundus runtime/commons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant