godot-cpp: [GDExtension] Missing methods, classes and API discrepancies.

godot-cpp: ad11bbb5845a454551d490812631922c33b7601c godot: https://github.com/godotengine/godot/pull/52192

Some missing API functions and discrepancies found during attempt to port TextServerAdvanced to the GDExtension (as part of https://github.com/godotengine/godot/pull/52192):

  • ~String:~
    • ~missing ptr, ptrw methods.~
    • ~missing +, += operators.~
  • ~StringName do not expose < and > operators, and unusable as map key.~
  • Packed*Arrray:
    • ~missing ptr, ptrw methods.~
    • [] operator API difference with the engine ([] vs .write[]).
  • ~Dictionary:~
    • ~missing [] operator.~
    • ~seems to have no methods to write value at all.~
  • ~Char*String:~
    • ~no public constructors.~
  • RID:
    • ~no is_valid method.~
    • ~no RID_*_Owner implementation, can be copy-pasted locally from the engine with minimal changes, but probably should be part of godot-cpp.~ Included in #701.
  • Mutex and Semaphore:
    • lock and unlock methods aren’t const.
    • ~no MutexLock class and _THREAD_SAFE_ macros defined (can be added locally, but probably should be part of godot-cpp).~ Included in #701.
  • ~memnew, memdelete aren’t working with non-Godot classes.~
  • ~no memalloc, memfree macros defined (can be added locally):~
    #define memalloc(m_size) Memory::alloc_static(m_size)
    #define memrealloc(m_mem, m_size) Memory::realloc_static(m_mem, m_size)
    #define memfree(m_mem) Memory::free_static(m_mem)
    
  • ~Enum type return values can’t be bound on the engine side.~
  • ~Enum type argument types can’t be bound, unless conversion macros is added manually~ - MAKE_PTRARGCONV(TextServer::Direction, int64_t);.
  • ~Missing math defines, MAX, MIN, CLAMP etc.~
  • ~No conversion for custom native pointer types, can be fixed locally by adding GDVIRTUAL_NATIVE_PTR(Glyph *); macro.~
  • ~No templates for Vector, Map, List, HashMap, Set, not a critical issue, but would be convenient to have for better module <-> GDExtension portability.~ Included in #701.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 1
  • Comments: 20 (14 by maintainers)

Most upvoted comments

The ClassDB object allows for registering but doesn’t give access to any of its methods as defined in the version GDscript has access to: https://docs.godotengine.org/en/latest/classes/class_classdb.html

In Godot’s source code, that method also takes an int, and in practice if you need more than INT_MAX then you’d need a bit more than 64 Gb of RAM to hold such an array in memory (Variant is around 32 bytes).

One reason I know int64_t is used in many places is because Variant stores integers as such. Otherwise, I don’t know.

For consistency however it would be valid to use int64_t here instead, or size_t. I dont think it’s using int for any other reason than “it’s the same in core”.

Missing math defines, MAX, MIN, CLAMP etc.

For these ones I believe they should stop being used. In C++ max/min/clamp already exist as inline templates in Math:: and in STL so I see no reason to use macros for that stuff.

RS alias for RenderingServer is not defined (might be worth considering whether we should still use it at all upstream).

Such shortcuts shouldn’t need to exist IMO, at least not globally. It’s a 2-letter macro whose sole purpose is shortening something that isn’t that long and not used often (depends of the area of course), and being explicit would be much better. If the singleton is repeated a lot then it can be placed in a local reference.

It means “done”, but it’s done it the https://github.com/godotengine/godot/pull/58233, which is not merged.

Dont the strokes mean “done”?

Another method of String that went missing in GDExtension: alloc_c_string()

There’s no such method in the Godot ether, what’s it supposed to do?

Also, I can’t seem to find an equivalent to the String::num_int64()-method in the new GDExtension API.

This is fixed.


Updated the first comment, most of the stuff in the original issue is already fixed, or (in case of templates) will be added by #701

  • No templates for Vector, Map, List, HashMap, Set, not a critical issue, but would be convenient to have for better module <-> GDExtension portability.

I use those all the time in https://github.com/goostengine/goost, even templates like LocalVector.

I also had issues with a class extending Texture2D. It’s an abstract virtual class upstream, and my derived class is still seen as abstract in Godot so it can’t be instantiated. That’s probably the same cause as godotengine/godot#35484 for GDScript/C# custom nodes.

See godotengine/godot#42830.