[Godot 4.4 dev6] (relatively) low-frametime-spike infinite chunk generation

Описание к видео [Godot 4.4 dev6] (relatively) low-frametime-spike infinite chunk generation

Some demonstration of relatively frametime spike-free (more like low enough to be unnoticible) infinite chunk generation using threads + thread safe queue to control amount of add_child() call per frame.

-- Trivia

This was some sort of testbed for add_child call optimization for my space game thingy - but maybe I'll take thruster/turret from that to this and make game of highspeed hovercraft maneuvering in desert.

Surprisingly enough - this concept was the very first ever game I was thinking of back in early 2023 - which was abandoned after I was trying to modeling it which looked like this: https://x.com/jupiterbjy/status/14759...

idk why I tried to use twitter back then lmao, guess I'm not the SNS guy!


Below are some rambles so feel free to ignore beyond this.


-- Struggle with threads

Using thread is such a pain in godot, as most of methods that reports itself as thread safe (checkable via Node.call_thread_safe()) yet it IS NOT.

When built-in function's error happens in thread - there's no good way to know what the heck went wrong - and since this isn't easily reproducible when intentionally trying to make MRE out of it, it's not even easy to create issue in repo.

In theory - according to docs you should be able to safely create MyClass.new(), do all necessary steps, like creating new mesh & collision in runtime in thread (because docs say you can add to detached tree freely as long as it's not active) then calling add_child.call_deferred() should work fine.

In reality - so many various things will just freeze whatever you try to do with seemingly no reason without any log or output even when running godot in terminal. After spending days on this, I landed on conclusion that:

A: Trying to either instantiate a scene or new() then build scene inside without adding to active tree almost always freezes with WorkerThreadPool.

B: Instead adding empty scene (which then become from PackedScene init to class.new() operation) immediately in main thread, then adding same thread-safe setup func as task in scene's _ready() call works just fine.

Hence this is demo of it. Even if I managed to make A method work half-decently speed is so bad there's visible lag spike everywhere. And this video is how plan B looks like.

Комментарии

Информация по комментариям в разработке