Fix changes after ObjectTypeDB -> ClassDB renaming

This commit is contained in:
Rémi Verschelde 2017-07-04 13:31:19 +02:00 committed by GitHub
parent 9ba5414391
commit 5aceaeb86d
1 changed files with 27 additions and 28 deletions

View File

@ -15,7 +15,7 @@ macro like this.
class CustomObject : public Object { class CustomObject : public Object {
GDCLASS(CustomObject,Object); // this is required to inherit GDCLASS(CustomObject, Object); // this is required to inherit
}; };
This makes Objects gain a lot of functionality, like for example This makes Objects gain a lot of functionality, like for example
@ -23,9 +23,9 @@ This makes Objects gain a lot of functionality, like for example
.. code:: cpp .. code:: cpp
obj = memnew(CustomObject); obj = memnew(CustomObject);
print_line("Object Type: ",obj->get_type()); //print object type print_line("Object class: ", obj->get_class()); // print object class
obj2 = obj->cast_to<OtherType>(); // converting between types, this also works without RTTI enabled. obj2 = obj->cast_to<OtherClass>(); // converting between classes, this also works without RTTI enabled.
References: References:
~~~~~~~~~~~ ~~~~~~~~~~~
@ -43,16 +43,16 @@ Classes are registered by calling:
.. code:: cpp .. code:: cpp
ClassDB::register_type<MyCustomType>() ClassDB::register_class<MyCustomClass>()
Registering it will allow the type to be instanced by scripts, code, or Registering it will allow the class to be instanced by scripts, code, or
creating them again when deserializing. creating them again when deserializing.
Registering as virtual is the same but it can't be instanced. Registering as virtual is the same but it can't be instanced.
.. code:: cpp .. code:: cpp
ClassDB::register_virtual_type<MyCustomType>() ClassDB::register_virtual_class<MyCustomClass>()
Object-derived classes can override the static function Object-derived classes can override the static function
``static void _bind_methods()``. When one class is registered, this ``static void _bind_methods()``. When one class is registered, this
@ -66,13 +66,13 @@ Registering functions is one:
.. code:: cpp .. code:: cpp
ClassDB::register_method(D_METHOD("methodname","arg1name","arg2name"),&MyCustomMethod); ClassDB::register_method(D_METHOD("methodname", "arg1name", "arg2name"), &MyCustomMethod);
Default values for arguments can be passed in reverse order: Default values for arguments can be passed in reverse order:
.. code:: cpp .. code:: cpp
ClassDB::register_method(D_METHOD("methodname","arg1name","arg2name"),&MyCustomType::method,DEFVAL(-1)); //default value for arg2name ClassDB::register_method(D_METHOD("methodname", "arg1name", "arg2name"), &MyCustomType::method, DEFVAL(-1)); // default value for arg2name
``D_METHOD`` is a macro that converts "methodname" to a StringName for more ``D_METHOD`` is a macro that converts "methodname" to a StringName for more
efficiency. Argument names are used for introspection, but when efficiency. Argument names are used for introspection, but when
@ -88,7 +88,7 @@ string passing the name can be passed for brevity.
References: References:
~~~~~~~~~~~ ~~~~~~~~~~~
- `core/object_type_db.h <https://github.com/godotengine/godot/blob/master/core/object_type_db.h>`__ - `core/class_db.h <https://github.com/godotengine/godot/blob/master/core/class_db.h>`__
Constants Constants
--------- ---------
@ -107,14 +107,14 @@ convertible to int, for this a macro is provided:
.. code:: cpp .. code:: cpp
VARIANT_ENUM_CAST( MyClass::SomeMode ); // now functions that take SomeMode can be bound. VARIANT_ENUM_CAST(MyClass::SomeMode); // now functions that take SomeMode can be bound.
The constants can also be bound inside ``_bind_methods``, by using: The constants can also be bound inside ``_bind_methods``, by using:
.. code:: cpp .. code:: cpp
BIND_CONSTANT( MODE_FIRST ); BIND_CONSTANT(MODE_FIRST);
BIND_CONSTANT( MODE_SECOND ); BIND_CONSTANT(MODE_SECOND);
Properties (set/get) Properties (set/get)
-------------------- --------------------
@ -129,13 +129,13 @@ constructed as:
.. code:: cpp .. code:: cpp
PropertyInfo(type,name,hint,hint_string,usage_flags) PropertyInfo(type, name, hint, hint_string, usage_flags)
For example: For example:
.. code:: cpp .. code:: cpp
PropertyInfo(Variant::INT,"amount",PROPERTY_HINT_RANGE,"0,49,1",PROPERTY_USAGE_EDITOR) PropertyInfo(Variant::INT, "amount", PROPERTY_HINT_RANGE, "0,49,1", PROPERTY_USAGE_EDITOR)
This is an integer property, named "amount", hint is a range, range goes This is an integer property, named "amount", hint is a range, range goes
from 0 to 49 in steps of 1 (integers). It is only usable for the editor from 0 to 49 in steps of 1 (integers). It is only usable for the editor
@ -145,7 +145,7 @@ Another example:
.. code:: cpp .. code:: cpp
PropertyInfo(Variant::STRING,"modes",PROPERTY_HINT_ENUM,"Enabled,Disabled,Turbo") PropertyInfo(Variant::STRING, "modes", PROPERTY_HINT_ENUM, "Enabled,Disabled,Turbo")
This is a string property, can take any string but the editor will only This is a string property, can take any string but the editor will only
allow the defined hint ones. Since no usage flags were specified, the allow the defined hint ones. Since no usage flags were specified, the
@ -165,10 +165,9 @@ set/get functions exist. Example:
.. code:: cpp .. code:: cpp
ADD_PROPERTY( PropertyInfo(Variant::INT,"amount"), _SCS("set_amount"), _SCS("get_amount") ) ADD_PROPERTY(PropertyInfo(Variant::INT, "amount"), "set_amount", "get_amount")
This creates the property using the setter and the getter. ``_SCS`` is a This creates the property using the setter and the getter.
macro that creates a StringName efficiently.
Binding properties using ``_set``/``_get``/``_get_property_list`` Binding properties using ``_set``/``_get``/``_get_property_list``
----------------------------------------------------------------- -----------------------------------------------------------------
@ -183,9 +182,9 @@ call).
.. code:: cpp .. code:: cpp
void _get_property_info(List<PropertyInfo> *r_props); //return list of properties void _get_property_info(List<PropertyInfo> *r_props); // return list of properties
bool _get(const StringName& p_property, Variany& r_value) const; //return true if property was found bool _get(const StringName &p_property, Variant &r_value) const; // return true if property was found
bool _set(const StringName& p_property, const Variany& p_value); //return true if property was found bool _set(const StringName &p_property, const Variant &p_value); // return true if property was found
This is also a little less efficient since ``p_property`` must be This is also a little less efficient since ``p_property`` must be
compared against the desired names in serial order. compared against the desired names in serial order.
@ -216,9 +215,9 @@ languages). Connecting to them is rather easy:
.. code:: cpp .. code:: cpp
obj->connect(<signal>,target_instance,target_method) obj->connect(<signal>, target_instance, target_method)
//for example // for example:
obj->connect("enter_tree",this,"_node_entered_tree") obj->connect("enter_tree", this, "_node_entered_tree")
The method ``_node_entered_tree`` must be registered to the class using The method ``_node_entered_tree`` must be registered to the class using
``ClassDB::register_method`` (explained before). ``ClassDB::register_method`` (explained before).
@ -228,7 +227,7 @@ Adding signals to a class is done in ``_bind_methods``, using the
.. code:: cpp .. code:: cpp
ADD_SIGNAL( MethodInfo("been_killed") ) ADD_SIGNAL(MethodInfo("been_killed"))
References References
---------- ----------
@ -240,10 +239,10 @@ Declaring them must be done using Ref<> template. For example:
.. code:: cpp .. code:: cpp
class MyReference: public Reference { class MyReference: public Reference {
GDCLASS( MyReference,Reference ); GDCLASS(MyReference, Reference);
}; };
Ref<MyReference> myref = memnew( MyReference ); Ref<MyReference> myref = memnew(MyReference);
``myref`` is reference counted. It will be freed when no more Ref<> ``myref`` is reference counted. It will be freed when no more Ref<>
templates point to it. templates point to it.
@ -297,7 +296,7 @@ Saving a resource can be done with the resource saver API:
.. code:: cpp .. code:: cpp
ResourceSaver::save("res://someresource.res",instance) ResourceSaver::save("res://someresource.res", instance)
Instance will be saved. Sub resources that have a path to a file will be Instance will be saved. Sub resources that have a path to a file will be
saved as a reference to that resource. Sub resources without a path will saved as a reference to that resource. Sub resources without a path will