0 votes

Hello fellow programmers,

I am new to Godot. I am trying to integrate a c++ library that is lgplv3.

I am looking at the new developments to Godot such as GDNative. I am not really sure what to use.

I am just trying to figure out how to write a plugin so I can integrate callback events. I want to be able to rebuild the library as it uses cmake and i want to do modifications to it.

Thank You
Noobie Godot User

https://godotengine.org/article/dlscript-here

http://docs.godotengine.org/en/stable/development/cpp/custom_modules_in_cpp.html

https://github.com/slomkowski/mumlib

asked Sep 29, 2017 in Engine by hungrymonkey (419 points)

You mostly need C++ knowledge here.

It's possible to integrate a library as a module (statically compiled with the engine then) if you are able to understand how it gets built with CMake (what it links, what it includes, which defines are needed), because it needs to be integrated with the Godot build system (SCons). I'm not aware of any module in Godot that depends on CMake, since I'm able to build the engine without it, so they might have been adapted a little.

GDNative sounds more flexible because it uses dynamic libraries that you can build the way you want, however it's more recent and a bit more unstable so there are bugs and docs might be lacking. You can ask for help on Discord though, there is a channel dedicated to GDNative and people already managed to bind entire language libraries like Python or D.

I got things working by nuking cmake from the library depends. I can build from pure scons. I am trying to figure out how to use signal or other events to stream data right now.

Thanks

1 Answer

0 votes
Best answer

If you want to create call back events from within godot.

You essentially take advantage that GDscript signals implements the observer pattern

https://en.wikipedia.org/wiki/Observer_pattern

To implement signal you basically add it bindmethods

 //something like this
 ADD_SIGNAL(MethodInfo("get_pcm", PropertyInfo(Variant::POOL_BYTE_ARRAY, "audio_frame")));

}

If you wish to implement the module on a single thread so that it is basically a godot server.

You must write all of this boilerplate

https://godotengine.org/article/why-does-godot-use-servers-and-rids

https://github.com/hungrymonkey/godot/blob/mymic/modules/dummy_audiostream/sdl2_audiocapture.h

https://github.com/hungrymonkey/godot/blob/mymic/modules/dummy_audiostream/sdl2_audiocapture.cpp

If you want the server to be visible to GDScript, then you must create a seperate dummy class and register it to the engine. The dummy class will access resources via the get_singleton()->method?() interface

here is the _OS example

https://github.com/godotengine/godot/blob/e0f43e06785ea1b05a5d7c4be32b74a9995be8fe/core/bind/core_bind.h#L93

here is the example on how to bind the class

https://github.com/godotengine/godot/blob/e0f43e06785ea1b05a5d7c4be32b74a9995be8fe/core/bind/core_bind.cpp

the pseudo code is something like this.

 _mymodules * mymodules_instance = nullptr
 register_mymodules_types(){
    mymodules_instance = memnew(_mymodules);
    ClassDB::register_class<_mymodules>();
    Engine::get_singleton()->add_singleton(Engine::Singleton("mymodules", _mymodules::get_singleton()));
 }
answered Feb 14, 2018 by hungrymonkey (419 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.