I've created a Naive approach Nbody simulation just to test performance in godot, with gdscript it can run with about 200 rigid bodies, cool, i recreated the nbody part of the code in a GDnative C++ library, and it can run about 600 rigid bodies, better, but with a few optimizations and basic multithreading within the C++ code, i was able to get it running smoothly with 1200 bodies.
However, I would like to find the best method of rendering all these bodies, currently im passing in a reference to each rigidbody to the gdnative library where it keeps a list of all them.
I noticed that with no gravity, just rigidbodies sitting there doing nothing, godot will start lagging once i spawn around 5000 of them, each of these instances have 2 nodes to them, so thats 10000 nodes.
I've looked into the "optimization using servers" and have attempted to recreate first part of rendering a sprite in C++ to no avail, it works fine it gdscript. I've researched as much as i could to find out what im doing wrong but idk, it will just crash every time i try running my game, this is what i have so far:
//create canvas item, child of node
RID canvasitemrid = Visual->canvas_item_create();
RID thisID = get_canvas_item();
//made this node parent
img = ReLo->load("res://red.bmp","res//red.bmp");
//draw sprite on it
//this is a reference!
//add it centered
Visual->canvas_item_add_texture_rect(canvasitemrid, Rect2(sprite->get_texture()->get_size(), sprite->get_texture()->get_size()),sprite);
//add the item 45 degress rotated
//translated (should be down right)
And in my header file here are the variable for this class:
//physics server is an interface for low level 2d physics access.
//handle for resources unique ID (doesn't grant access to resource by itself, need a server to do stuff.)
I've tried many variations of that, i hope its a simple fix, Is it even recommended to do this? how much faster would this be than using gdscript to run it? i guess even just running this in gdscript would be much faster than instancing all my rigidbodies in gdscript, but i would like it to run as fast as possible, but still be easy to develop. from what i understand i'd essentially have to replace the scene system for the objects i don't in it.
btw i was unable to use Ref for many things because i got the error
Ref.hpp:180:31: error: 'class godot::ResourceLoader' has no member named 'unreference'
thank you for reading