Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 12 additions & 20 deletions include/godot_cpp/core/class_db.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,9 @@
#include <list>
#include <mutex>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

// Needed to use StringName as key in `std::unordered_map`
template <>
struct std::hash<godot::StringName> {
std::size_t operator()(godot::StringName const &s) const noexcept {
return s.hash();
}
};
#include <godot_cpp/templates/a_hash_map.hpp>

namespace godot {

Expand Down Expand Up @@ -95,9 +87,9 @@ class ClassDB {
StringName name;
StringName parent_name;
GDExtensionInitializationLevel level = GDEXTENSION_INITIALIZATION_SCENE;
std::unordered_map<StringName, MethodBind *> method_map;
AHashMap<StringName, MethodBind *> method_map;
std::set<StringName> signal_names;
std::unordered_map<StringName, VirtualMethod> virtual_methods;
AHashMap<StringName, VirtualMethod> virtual_methods;
std::set<StringName> property_names;
std::set<StringName> constant_names;
// Pointer to the parent custom class, if any. Will be null if the parent class is a Godot class.
Expand All @@ -106,11 +98,11 @@ class ClassDB {

private:
// This may only contain custom classes, not Godot classes
static std::unordered_map<StringName, ClassInfo> classes;
static std::unordered_map<StringName, const GDExtensionInstanceBindingCallbacks *> instance_binding_callbacks;
static AHashMap<StringName, ClassInfo> classes;
static AHashMap<StringName, const GDExtensionInstanceBindingCallbacks *> instance_binding_callbacks;
// Used to remember the custom class registration order.
static std::vector<StringName> class_register_order;
static std::unordered_map<StringName, Object *> engine_singletons;
static AHashMap<StringName, Object *> engine_singletons;
static std::mutex engine_singletons_mutex;

static MethodBind *bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const MethodDefinition &method_name, const void **p_defs, int p_defcount);
Expand Down Expand Up @@ -171,9 +163,9 @@ class ClassDB {

static void _register_engine_singleton(const StringName &p_class_name, Object *p_singleton) {
std::lock_guard<std::mutex> lock(engine_singletons_mutex);
std::unordered_map<StringName, Object *>::const_iterator i = engine_singletons.find(p_class_name);
AHashMap<StringName, Object *>::ConstIterator i = engine_singletons.find(p_class_name);
if (i != engine_singletons.end()) {
ERR_FAIL_COND((*i).second != p_singleton);
ERR_FAIL_COND((*i).value != p_singleton);
Comment on lines +166 to +168
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

		AHashMap<StringName, Object *>::ConstIterator singleton_it = engine_singletons.find(p_class_name);
		if (singleton_it != engine_singletons.end()) {
			ERR_FAIL_COND((*singleton_it).value != p_singleton);

To match the rest of the file, and for readability. i usually used for integer iterators.

return;
}
engine_singletons[p_class_name] = p_singleton;
Expand Down Expand Up @@ -243,10 +235,10 @@ void ClassDB::_register_class(bool p_virtual, bool p_exposed, bool p_runtime) {
cl.name = T::get_class_static();
cl.parent_name = T::get_parent_class_static();
cl.level = current_level;
std::unordered_map<StringName, ClassInfo>::iterator parent_it = classes.find(cl.parent_name);
AHashMap<StringName, ClassInfo>::Iterator parent_it = classes.find(cl.parent_name);
if (parent_it != classes.end()) {
// Assign parent if it is also a custom class
cl.parent_ptr = &parent_it->second;
cl.parent_ptr = &parent_it->value;
}
classes[cl.name] = cl;
class_register_order.push_back(cl.name);
Expand Down Expand Up @@ -340,13 +332,13 @@ MethodBind *ClassDB::bind_vararg_method(uint32_t p_flags, StringName p_name, M p

StringName instance_type = bind->get_instance_class();

std::unordered_map<StringName, ClassInfo>::iterator type_it = classes.find(instance_type);
AHashMap<StringName, ClassInfo>::Iterator type_it = classes.find(instance_type);
if (type_it == classes.end()) {
memdelete(bind);
ERR_FAIL_V_MSG(nullptr, String("Class '{0}' doesn't exist.").format(Array::make(instance_type)));
}

ClassInfo &type = type_it->second;
ClassInfo &type = type_it->value;

if (type.method_map.find(p_name) != type.method_map.end()) {
memdelete(bind);
Expand Down
Loading
Loading