Rename instance()->instantiate() when it's a verb

This commit is contained in:
Lightning_A 2021-06-17 16:03:09 -06:00
parent 60dcc4f39c
commit e28fd07b2b
371 changed files with 1318 additions and 1318 deletions

View file

@ -1850,12 +1850,12 @@ bool _ClassDB::is_parent_class(const StringName &p_class, const StringName &p_in
return ClassDB::is_parent_class(p_class, p_inherits);
}
bool _ClassDB::can_instance(const StringName &p_class) const {
return ClassDB::can_instance(p_class);
bool _ClassDB::can_instantiate(const StringName &p_class) const {
return ClassDB::can_instantiate(p_class);
}
Variant _ClassDB::instance(const StringName &p_class) const {
Object *obj = ClassDB::instance(p_class);
Variant _ClassDB::instantiate(const StringName &p_class) const {
Object *obj = ClassDB::instantiate(p_class);
if (!obj) {
return Variant();
}
@ -1984,8 +1984,8 @@ void _ClassDB::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_parent_class", "class"), &_ClassDB::get_parent_class);
ClassDB::bind_method(D_METHOD("class_exists", "class"), &_ClassDB::class_exists);
ClassDB::bind_method(D_METHOD("is_parent_class", "class", "inherits"), &_ClassDB::is_parent_class);
ClassDB::bind_method(D_METHOD("can_instance", "class"), &_ClassDB::can_instance);
ClassDB::bind_method(D_METHOD("instance", "class"), &_ClassDB::instance);
ClassDB::bind_method(D_METHOD("can_instantiate", "class"), &_ClassDB::can_instantiate);
ClassDB::bind_method(D_METHOD("instantiate", "class"), &_ClassDB::instantiate);
ClassDB::bind_method(D_METHOD("class_has_signal", "class", "signal"), &_ClassDB::has_signal);
ClassDB::bind_method(D_METHOD("class_get_signal", "class", "signal"), &_ClassDB::get_signal);

View file

@ -585,8 +585,8 @@ public:
StringName get_parent_class(const StringName &p_class) const;
bool class_exists(const StringName &p_class) const;
bool is_parent_class(const StringName &p_class, const StringName &p_inherits) const;
bool can_instance(const StringName &p_class) const;
Variant instance(const StringName &p_class) const;
bool can_instantiate(const StringName &p_class) const;
Variant instantiate(const StringName &p_class) const;
bool has_signal(StringName p_class, StringName p_signal) const;
Dictionary get_signal(StringName p_class, StringName p_signal) const;

View file

@ -84,7 +84,7 @@ RemoteDebuggerPeerTCP::RemoteDebuggerPeerTCP(Ref<StreamPeerTCP> p_tcp) {
thread.start(_thread_func, this);
#endif
} else {
tcp_client.instance();
tcp_client.instantiate();
}
}

View file

@ -500,7 +500,7 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
if (event_dispatch_function && emulate_touch_from_mouse && !p_is_emulated && mb->get_button_index() == 1) {
Ref<InputEventScreenTouch> touch_event;
touch_event.instance();
touch_event.instantiate();
touch_event->set_pressed(mb->is_pressed());
touch_event->set_position(mb->get_position());
event_dispatch_function(touch_event);
@ -517,7 +517,7 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
if (event_dispatch_function && emulate_touch_from_mouse && !p_is_emulated && mm->get_button_mask() & 1) {
Ref<InputEventScreenDrag> drag_event;
drag_event.instance();
drag_event.instantiate();
drag_event->set_position(mm->get_position());
drag_event->set_relative(mm->get_relative());
@ -555,7 +555,7 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
if (translate) {
Ref<InputEventMouseButton> button_event;
button_event.instance();
button_event.instantiate();
button_event->set_device(InputEvent::DEVICE_ID_TOUCH_MOUSE);
button_event->set_position(st->get_position());
@ -582,7 +582,7 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em
if (emulate_mouse_from_touch && sd->get_index() == mouse_from_touch_index) {
Ref<InputEventMouseMotion> motion_event;
motion_event.instance();
motion_event.instantiate();
motion_event->set_device(InputEvent::DEVICE_ID_TOUCH_MOUSE);
motion_event->set_position(sd->get_position());
@ -787,7 +787,7 @@ void Input::ensure_touch_mouse_raised() {
mouse_from_touch_index = -1;
Ref<InputEventMouseButton> button_event;
button_event.instance();
button_event.instantiate();
button_event->set_device(InputEvent::DEVICE_ID_TOUCH_MOUSE);
button_event->set_position(mouse_pos);
@ -821,7 +821,7 @@ void Input::set_default_cursor_shape(CursorShape p_shape) {
// The default shape is set in Viewport::_gui_input_event. To instantly
// see the shape in the viewport we need to trigger a mouse motion event.
Ref<InputEventMouseMotion> mm;
mm.instance();
mm.instantiate();
mm->set_position(mouse_pos);
mm->set_global_position(mouse_pos);
parse_input_event(mm);
@ -1031,7 +1031,7 @@ void Input::joy_hat(int p_device, int p_val) {
void Input::_button_event(int p_device, int p_index, bool p_pressed) {
Ref<InputEventJoypadButton> ievent;
ievent.instance();
ievent.instantiate();
ievent->set_device(p_device);
ievent->set_button_index(p_index);
ievent->set_pressed(p_pressed);
@ -1041,7 +1041,7 @@ void Input::_button_event(int p_device, int p_index, bool p_pressed) {
void Input::_axis_event(int p_device, int p_axis, float p_value) {
Ref<InputEventJoypadMotion> ievent;
ievent.instance();
ievent.instantiate();
ievent->set_device(p_device);
ievent->set_axis(p_axis);
ievent->set_axis_value(p_value);

View file

@ -375,7 +375,7 @@ String InputEventKey::to_string() {
Ref<InputEventKey> InputEventKey::create_reference(uint32_t p_keycode) {
Ref<InputEventKey> ie;
ie.instance();
ie.instantiate();
ie->set_keycode(p_keycode & KEY_CODE_MASK);
ie->set_unicode(p_keycode & KEY_CODE_MASK);
@ -545,7 +545,7 @@ Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, co
Vector2 l = p_xform.xform(get_position() + p_local_ofs);
Ref<InputEventMouseButton> mb;
mb.instance();
mb.instantiate();
mb->set_device(get_device());
mb->set_window_id(get_window_id());
@ -731,7 +731,7 @@ Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, co
Vector2 s = p_xform.basis_xform(get_speed());
Ref<InputEventMouseMotion> mm;
mm.instance();
mm.instantiate();
mm->set_device(get_device());
mm->set_window_id(get_window_id());
@ -1048,7 +1048,7 @@ String InputEventJoypadButton::to_string() {
Ref<InputEventJoypadButton> InputEventJoypadButton::create_reference(int p_btn_index) {
Ref<InputEventJoypadButton> ie;
ie.instance();
ie.instantiate();
ie->set_button_index(p_btn_index);
return ie;
@ -1097,7 +1097,7 @@ bool InputEventScreenTouch::is_pressed() const {
Ref<InputEvent> InputEventScreenTouch::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
Ref<InputEventScreenTouch> st;
st.instance();
st.instantiate();
st->set_device(get_device());
st->set_window_id(get_window_id());
st->set_index(index);
@ -1170,7 +1170,7 @@ Vector2 InputEventScreenDrag::get_speed() const {
Ref<InputEvent> InputEventScreenDrag::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
Ref<InputEventScreenDrag> sd;
sd.instance();
sd.instantiate();
sd->set_device(get_device());
sd->set_window_id(get_window_id());
@ -1325,7 +1325,7 @@ real_t InputEventMagnifyGesture::get_factor() const {
Ref<InputEvent> InputEventMagnifyGesture::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
Ref<InputEventMagnifyGesture> ev;
ev.instance();
ev.instantiate();
ev->set_device(get_device());
ev->set_window_id(get_window_id());
@ -1365,7 +1365,7 @@ Vector2 InputEventPanGesture::get_delta() const {
Ref<InputEvent> InputEventPanGesture::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
Ref<InputEventPanGesture> ev;
ev.instance();
ev.instantiate();
ev->set_device(get_device());
ev->set_window_id(get_window_id());

View file

@ -210,7 +210,7 @@ FileAccessNetworkClient *FileAccessNetworkClient::singleton = nullptr;
FileAccessNetworkClient::FileAccessNetworkClient() {
singleton = this;
client.instance();
client.instantiate();
}
FileAccessNetworkClient::~FileAccessNetworkClient() {

View file

@ -730,7 +730,7 @@ int HTTPClient::get_read_chunk_size() const {
}
HTTPClient::HTTPClient() {
tcp_connection.instance();
tcp_connection.instantiate();
}
HTTPClient::~HTTPClient() {}

View file

@ -1945,7 +1945,7 @@ Error Image::generate_mipmap_roughness(RoughnessChannel p_roughness_channel, con
memcpy(wr.ptr(), ptr, size);
wr = uint8_t*();
Ref<Image> im;
im.instance();
im.instantiate();
im->create(w, h, false, format, imgdata);
im->save_png("res://mipmap_" + itos(i) + ".png");
}
@ -3280,7 +3280,7 @@ Ref<Image> Image::rgbe_to_srgb() {
ERR_FAIL_COND_V(format != FORMAT_RGBE9995, Ref<Image>());
Ref<Image> new_image;
new_image.instance();
new_image.instantiate();
new_image->create(width, height, false, Image::FORMAT_RGB8);
for (int row = 0; row < height; row++) {
@ -3310,7 +3310,7 @@ Ref<Image> Image::get_image_from_mipmap(int p_mipamp) const {
}
Ref<Image> image;
image.instance();
image.instantiate();
image->width = w;
image->height = h;
image->format = format;
@ -3627,7 +3627,7 @@ Image::Image(const uint8_t *p_mem_png_jpg, int p_len) {
Ref<Resource> Image::duplicate(bool p_subresources) const {
Ref<Image> copy;
copy.instance();
copy.instantiate();
copy->_copy_internals_from(*this);
return copy;
}

View file

@ -163,7 +163,7 @@ RES ResourceFormatLoaderImage::load(const String &p_path, const String &p_origin
}
Ref<Image> image;
image.instance();
image.instantiate();
Error err = ImageLoader::loader[idx]->load_image(image, f, false, 1.0);

View file

@ -547,7 +547,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
r_variant = (Object *)nullptr;
} else {
Ref<EncodedObjectAsID> obj_as_id;
obj_as_id.instance();
obj_as_id.instantiate();
obj_as_id->set_object_id(val);
r_variant = obj_as_id;
@ -565,7 +565,7 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
if (str == String()) {
r_variant = (Object *)nullptr;
} else {
Object *obj = ClassDB::instance(str);
Object *obj = ClassDB::instantiate(str);
ERR_FAIL_COND_V(!obj, ERR_UNAVAILABLE);
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);

View file

@ -164,7 +164,7 @@ Ref<Resource> Resource::duplicate_for_local_scene(Node *p_for_scene, Map<Ref<Res
List<PropertyInfo> plist;
get_property_list(&plist);
Ref<Resource> r = Object::cast_to<Resource>(ClassDB::instance(get_class()));
Ref<Resource> r = Object::cast_to<Resource>(ClassDB::instantiate(get_class()));
ERR_FAIL_COND_V(r.is_null(), Ref<Resource>());
r->local_scene = p_for_scene;
@ -224,7 +224,7 @@ Ref<Resource> Resource::duplicate(bool p_subresources) const {
List<PropertyInfo> plist;
get_property_list(&plist);
Ref<Resource> r = (Resource *)ClassDB::instance(get_class());
Ref<Resource> r = (Resource *)ClassDB::instantiate(get_class());
ERR_FAIL_COND_V(r.is_null(), Ref<Resource>());
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {

View file

@ -704,7 +704,7 @@ Error ResourceLoaderBinary::load() {
if (res.is_null()) {
//did not replace
Object *obj = ClassDB::instance(t);
Object *obj = ClassDB::instantiate(t);
if (!obj) {
error = ERR_FILE_CORRUPT;
ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, local_path + ":Resource of unrecognized type in file: " + t + ".");

View file

@ -1045,7 +1045,7 @@ bool ResourceLoader::add_custom_resource_format_loader(String script_path) {
bool valid_type = ClassDB::is_parent_class(ibt, "ResourceFormatLoader");
ERR_FAIL_COND_V_MSG(!valid_type, false, "Script does not inherit a CustomResourceLoader: " + script_path + ".");
Object *obj = ClassDB::instance(ibt);
Object *obj = ClassDB::instantiate(ibt);
ERR_FAIL_COND_V_MSG(obj == nullptr, false, "Cannot instance script as custom resource loader, expected 'ResourceFormatLoader' inheritance, got: " + String(ibt) + ".");

View file

@ -210,7 +210,7 @@ bool ResourceSaver::add_custom_resource_format_saver(String script_path) {
bool valid_type = ClassDB::is_parent_class(ibt, "ResourceFormatSaver");
ERR_FAIL_COND_V_MSG(!valid_type, false, "Script does not inherit a CustomResourceSaver: " + script_path + ".");
Object *obj = ClassDB::instance(ibt);
Object *obj = ClassDB::instantiate(ibt);
ERR_FAIL_COND_V_MSG(obj == nullptr, false, "Cannot instance script as custom resource saver, expected 'ResourceFormatSaver' inheritance, got: " + String(ibt) + ".");

View file

@ -512,7 +512,7 @@ void StreamPeerBuffer::clear() {
Ref<StreamPeerBuffer> StreamPeerBuffer::duplicate() const {
Ref<StreamPeerBuffer> spb;
spb.instance();
spb.instantiate();
spb->data = data;
return spb;
}

View file

@ -516,7 +516,7 @@ void ClassDB::instance_get_native_extension_data(ObjectNativeExtension **r_exten
}
}
Object *ClassDB::instance(const StringName &p_class) {
Object *ClassDB::instantiate(const StringName &p_class) {
ClassInfo *ti;
{
OBJTYPE_RLOCK;
@ -544,7 +544,7 @@ Object *ClassDB::instance(const StringName &p_class) {
return ti->creation_func();
}
bool ClassDB::can_instance(const StringName &p_class) {
bool ClassDB::can_instantiate(const StringName &p_class) {
OBJTYPE_RLOCK;
ClassInfo *ti = classes.getptr(p_class);
@ -1522,8 +1522,8 @@ Variant ClassDB::class_get_default_property_value(const StringName &p_class, con
if (Engine::get_singleton()->has_singleton(p_class)) {
c = Engine::get_singleton()->get_singleton_object(p_class);
cleanup_c = false;
} else if (ClassDB::can_instance(p_class)) {
c = ClassDB::instance(p_class);
} else if (ClassDB::can_instantiate(p_class)) {
c = ClassDB::instantiate(p_class);
cleanup_c = true;
}

View file

@ -230,8 +230,8 @@ public:
static StringName get_compatibility_remapped_class(const StringName &p_class);
static bool class_exists(const StringName &p_class);
static bool is_parent_class(const StringName &p_class, const StringName &p_inherits);
static bool can_instance(const StringName &p_class);
static Object *instance(const StringName &p_class);
static bool can_instantiate(const StringName &p_class);
static Object *instantiate(const StringName &p_class);
static void instance_get_native_extension_data(ObjectNativeExtension **r_extension, void **r_extension_instance);
static APIType get_api_type(const StringName &p_class);

View file

@ -871,7 +871,7 @@ void Object::set_script(const Variant &p_script) {
Ref<Script> s = script;
if (!s.is_null()) {
if (s->can_instance()) {
if (s->can_instantiate()) {
OBJ_DEBUG_LOCK
script_instance = s->instance_create(this);
} else if (Engine::get_singleton()->is_editor_hint()) {

View file

@ -213,7 +213,7 @@ public:
inline bool is_null() const { return reference == nullptr; }
void unref() {
//TODO this should be moved to mutexes, since this engine does not really
// TODO: this should be moved to mutexes, since this engine does not really
// do a lot of referencing on references and stuff
// mutexes will avoid more crashes?
@ -223,7 +223,7 @@ public:
reference = nullptr;
}
void instance() {
void instantiate() {
ref(memnew(T));
}

View file

@ -100,7 +100,7 @@ Dictionary Script::_get_script_constant_map() {
}
void Script::_bind_methods() {
ClassDB::bind_method(D_METHOD("can_instance"), &Script::can_instance);
ClassDB::bind_method(D_METHOD("can_instantiate"), &Script::can_instantiate);
//ClassDB::bind_method(D_METHOD("instance_create","base_object"),&Script::instance_create);
ClassDB::bind_method(D_METHOD("instance_has", "base_object"), &Script::instance_has);
ClassDB::bind_method(D_METHOD("has_source_code"), &Script::has_source_code);

View file

@ -115,7 +115,7 @@ protected:
Dictionary _get_script_constant_map();
public:
virtual bool can_instance() const = 0;
virtual bool can_instantiate() const = 0;
virtual Ref<Script> get_base_script() const = 0; //for script inheritance

View file

@ -45,7 +45,7 @@ void MIDIDriver::set_singleton() {
void MIDIDriver::receive_input_packet(uint64_t timestamp, uint8_t *data, uint32_t length) {
Ref<InputEventMIDI> event;
event.instance();
event.instantiate();
uint32_t param_position = 1;
if (length >= 1) {

View file

@ -113,18 +113,18 @@ void register_core_types() {
CoreStringNames::create();
resource_format_po.instance();
resource_format_po.instantiate();
ResourceLoader::add_resource_format_loader(resource_format_po);
resource_saver_binary.instance();
resource_saver_binary.instantiate();
ResourceSaver::add_resource_format_saver(resource_saver_binary);
resource_loader_binary.instance();
resource_loader_binary.instantiate();
ResourceLoader::add_resource_format_loader(resource_loader_binary);
resource_format_importer.instance();
resource_format_importer.instantiate();
ResourceLoader::add_resource_format_loader(resource_format_importer);
resource_format_image.instance();
resource_format_image.instantiate();
ResourceLoader::add_resource_format_loader(resource_format_image);
ClassDB::register_class<Object>();
@ -171,9 +171,9 @@ void register_core_types() {
ClassDB::register_custom_instance_class<Crypto>();
ClassDB::register_custom_instance_class<StreamPeerSSL>();
resource_format_saver_crypto.instance();
resource_format_saver_crypto.instantiate();
ResourceSaver::add_resource_format_saver(resource_format_saver_crypto);
resource_format_loader_crypto.instance();
resource_format_loader_crypto.instantiate();
ResourceLoader::add_resource_format_loader(resource_format_loader_crypto);
ClassDB::register_virtual_class<IP>();

View file

@ -188,7 +188,7 @@ void TranslationPO::set_plural_rule(const String &p_plural_rule) {
plural_rule = plural_rule.replacen("(", "");
plural_rule = plural_rule.replacen(")", "");
_cache_plural_tests(plural_rule);
expr.instance();
expr.instantiate();
input_name.push_back("n");
}

View file

@ -738,10 +738,10 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
String type = token.value;
Object *obj = ClassDB::instance(type);
Object *obj = ClassDB::instantiate(type);
if (!obj) {
r_err_str = "Can't instance Object() of type: " + type;
r_err_str = "Can't instantiate Object() of type: " + type;
return ERR_PARSE_ERROR;
}