A gdextension that draws tiles efficiently

Hello everyone,
Over the last few weeks I’ve been concentrating on developing an extension that uses a quadtree to automatically group tiles so that they draw efficiently. I have very little knowledge of C++ and Godot so I am proud of it from my status as a sporadic amateur programmer.


The screenshot shows a test bench where I have randomly added 1 million tiles and it still works great. Note that the sample text generates more than 90 draw calls and uses about 0.3 ms to draw it.
The whole system is running from static memory hosted at the start of the program. There are two types of branches in the tree. The first one manages the data needed to build the MultiMeshInstance2D and the second one hosts the concrete data of each tile. In such a way that the tilemap is subdivided, as more tiles are added, and as few instances as possible are created while allowing access to each specific data as if it were a normal quadtree. I have also made the root of the tree to be extended as needed.
Thanks for reading!

1 Like

Hi all,
I plan to move a lot of agents (and hopefully will) over those rails. I have been experimenting with compute shaders. I have been able to setup 65535 agents that move through paths defined by points with their own max speed. I pass the agents position in a texture to a multimesh instance. The computation takes less than 2 ms and the drawing around 1.5 ms. I still have to add collision avoidance but I think I have got the key. Stay tunned :wink:

1 Like

Hi all,
It has been easier than spected:

The video shows a close look into 65408 moving dots with collision avoidance in an average of around 3.2 ms. Sometimes 2 ms, sometimes 4 ms.

2 Likes

How should your plugin be called using GDScript?

No name in sight… it’s all part of the game I have in mind. The extension is built as TiledRails but it could have been any other name.

edited:
omg, i do undertand your question now :flushed:
All works from _init, _ready an _process functions of the extended node2d. It is not designed to work from gdscript. It stands alone.

Hi all,
sorry for the spam, but it’s just so brute…
600K agents in ~8 ms.