godot-kotlin-jvm icon indicating copy to clipboard operation
godot-kotlin-jvm copied to clipboard

[PROPOSAL] Write reload logic in cpp

Open chippmann opened this issue 2 years ago • 8 comments

Currently we have the bootstrap class which handles file system changes and reloads classes accordingly. It basically is the sole reason why we have to ship the godot-bootstrap.jar alongside the engine executable.

I propose that we implement this filewatching and reloading logic completely in cpp. Looking at the impl of some other cpp filewatching libs (like https://github.com/apetrone/simplefilewatcher/) we should be able to to this kind of filewatching ourselves pretty easily as well even if we have to implement it platform specific. Maybe even godot has some platform independent way of watching filesystem changes.

Also now that we use a buildLock file instead of watching the build dir directly, the file watching logic is greatly simplified. So we would in fact only need to watch one file which further simplifies things a lot.

This would pave the way for better/simpler editor builds and would completely remove the need for two jar files as we could pack everything into one jar. Which would also simplify export targets like android a lot.

chippmann avatar Jul 29 '21 09:07 chippmann

I agree on this one. But for me we should rely on engine implementation and avoid creating our own FileAccess.

piiertho avatar Jul 29 '21 09:07 piiertho

But does godot have a file watching functionality? I'd rather not have some kind of service routine that periodically polls for changes. This creates unnecessary load on the system.

chippmann avatar Jul 29 '21 09:07 chippmann

I back this, although I advise against using a third party library - hopefully godot provide something in a platform agnostic way. This exist https://docs.godotengine.org/en/stable/classes/class_editorfilesystem.html - although I'm not sure if it will serve our requirement.

raniejade avatar Jul 29 '21 09:07 raniejade

I definitely agree. I wouldn't want a third party lib for this. This was just an implementation example if we have to do it ourselves in the end

chippmann avatar Jul 29 '21 09:07 chippmann

I back this, although I advise against using a third party library - hopefully godot provide something in a platform agnostic way. This exist https://docs.godotengine.org/en/stable/classes/class_editorfilesystem.html - although I'm not sure if it will serve our requirement.

I don't think we can use this. As our buildLock file is not a imported resource. It resides in the tmp dir. Also i would not change this. I think this is a far more stable location than the project dir

chippmann avatar Jul 29 '21 09:07 chippmann

It looks to me that C# is using a timer node for this: https://github.com/godotengine/godot/blob/8f7f5846397297fff6e8a08f89bc60ce658699cc/modules/mono/editor/GodotTools/GodotTools/HotReloadAssemblyWatcher.cs

Searching the godot source didn't yield in any watching functionality so far.

chippmann avatar Jul 29 '21 09:07 chippmann

I'm pretty sure that Godot got some thread running in the editor to check if a file in the project was changed recently: https://github.com/godotengine/godot/blob/d5bd8a704f096043174af7994ef3de055a36cf45/editor/editor_file_system.cpp#L209. Need to investigate that more in details.

CedNaru avatar Jul 29 '21 13:07 CedNaru

This issue is postponed until https://github.com/utopia-rise/godot-kotlin-jvm/milestone/9 is done

chippmann avatar Mar 13 '22 11:03 chippmann