Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jun 20, 2021
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 6 additions & 6 deletions core/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions core/core_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,8 @@ class _ClassDB : public Object {
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;
Expand Down
2 changes: 1 addition & 1 deletion core/debugger/remote_debugger_peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ RemoteDebuggerPeerTCP::RemoteDebuggerPeerTCP(Ref<StreamPeerTCP> p_tcp) {
thread.start(_thread_func, this);
#endif
} else {
tcp_client.instance();
tcp_client.instantiate();
}
}

Expand Down
16 changes: 8 additions & 8 deletions core/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions core/input/input_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion core/io/file_access_network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ FileAccessNetworkClient *FileAccessNetworkClient::singleton = nullptr;

FileAccessNetworkClient::FileAccessNetworkClient() {
singleton = this;
client.instance();
client.instantiate();
}

FileAccessNetworkClient::~FileAccessNetworkClient() {
Expand Down
2 changes: 1 addition & 1 deletion core/io/http_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ int HTTPClient::get_read_chunk_size() const {
}

HTTPClient::HTTPClient() {
tcp_connection.instance();
tcp_connection.instantiate();
}

HTTPClient::~HTTPClient() {}
Expand Down
8 changes: 4 additions & 4 deletions core/io/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion core/io/image_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions core/io/marshalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions core/io/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion core/io/resource_format_binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 + ".");
Expand Down
2 changes: 1 addition & 1 deletion core/io/resource_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) + ".");

Expand Down
2 changes: 1 addition & 1 deletion core/io/resource_saver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) + ".");

Expand Down
2 changes: 1 addition & 1 deletion core/io/stream_peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ void StreamPeerBuffer::clear() {

Ref<StreamPeerBuffer> StreamPeerBuffer::duplicate() const {
Ref<StreamPeerBuffer> spb;
spb.instance();
spb.instantiate();
spb->data = data;
return spb;
}
8 changes: 4 additions & 4 deletions core/object/class_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions core/object/class_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ class ClassDB {
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);

Expand Down
2 changes: 1 addition & 1 deletion core/object/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
4 changes: 2 additions & 2 deletions core/object/ref_counted.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class Ref {
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?

Expand All @@ -223,7 +223,7 @@ class Ref {
reference = nullptr;
}

void instance() {
void instantiate() {
ref(memnew(T));
}

Expand Down
Loading