diff options
Diffstat (limited to 'scene/main/viewport.cpp')
-rw-r--r-- | scene/main/viewport.cpp | 249 |
1 files changed, 100 insertions, 149 deletions
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index a22d897669..02da926e50 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -28,28 +28,23 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "viewport.h" + #include "os/input.h" #include "os/os.h" -#include "scene/3d/spatial.h" -#include "servers/physics_2d_server.h" -//#include "scene/3d/camera.h" - +#include "project_settings.h" +#include "scene/2d/collision_object_2d.h" #include "scene/3d/camera.h" #include "scene/3d/collision_object.h" #include "scene/3d/listener.h" -#include "scene/3d/spatial_indexer.h" +#include "scene/3d/scenario_fx.h" +#include "scene/3d/spatial.h" #include "scene/gui/control.h" -#include "scene/resources/mesh.h" - -#include "scene/2d/collision_object_2d.h" - #include "scene/gui/label.h" #include "scene/gui/panel.h" #include "scene/main/timer.h" +#include "scene/resources/mesh.h" #include "scene/scene_string_names.h" - -#include "project_settings.h" -#include "scene/3d/scenario_fx.h" +#include "servers/physics_2d_server.h" void ViewportTexture::setup_local_to_scene() { @@ -68,7 +63,7 @@ void ViewportTexture::setup_local_to_scene() { ERR_EXPLAIN("ViewportTexture: Path to node is invalid"); ERR_FAIL_COND(!vpn); - vp = vpn->cast_to<Viewport>(); + vp = Object::cast_to<Viewport>(vpn); ERR_EXPLAIN("ViewportTexture: Path to node does not point to a viewport"); ERR_FAIL_COND(!vp); @@ -337,22 +332,18 @@ void Viewport::_test_new_mouseover(ObjectID new_collider) { if (new_collider != physics_object_over) { if (physics_object_over) { - Object *obj = ObjectDB::get_instance(physics_object_over); - if (obj) { - CollisionObject *co = obj->cast_to<CollisionObject>(); - if (co) { - co->_mouse_exit(); - } + + CollisionObject *co = Object::cast_to<CollisionObject>(ObjectDB::get_instance(physics_object_over)); + if (co) { + co->_mouse_exit(); } } if (new_collider) { - Object *obj = ObjectDB::get_instance(new_collider); - if (obj) { - CollisionObject *co = obj->cast_to<CollisionObject>(); - if (co) { - co->_mouse_enter(); - } + + CollisionObject *co = Object::cast_to<CollisionObject>(ObjectDB::get_instance(new_collider)); + if (co) { + co->_mouse_enter(); } } @@ -399,7 +390,7 @@ void Viewport::_notification(int p_what) { contact_3d_debug_instance = VisualServer::get_singleton()->instance_create(); VisualServer::get_singleton()->instance_set_base(contact_3d_debug_instance, contact_3d_debug_multimesh); VisualServer::get_singleton()->instance_set_scenario(contact_3d_debug_instance, find_world()->get_scenario()); - VisualServer::get_singleton()->instance_geometry_set_flag(contact_3d_debug_instance, VS::INSTANCE_FLAG_VISIBLE_IN_ALL_ROOMS, true); + //VisualServer::get_singleton()->instance_geometry_set_flag(contact_3d_debug_instance, VS::INSTANCE_FLAG_VISIBLE_IN_ALL_ROOMS, true); } VS::get_singleton()->viewport_set_active(viewport, true); @@ -552,7 +543,7 @@ void Viewport::_notification(int p_what) { for (int i = 0; i < rc; i++) { if (res[i].collider_id && res[i].collider) { - CollisionObject2D *co = res[i].collider->cast_to<CollisionObject2D>(); + CollisionObject2D *co = Object::cast_to<CollisionObject2D>(res[i].collider); if (co) { Map<ObjectID, uint64_t>::Element *E = physics_2d_mouseover.find(res[i].collider_id); @@ -575,7 +566,7 @@ void Viewport::_notification(int p_what) { Object *o = ObjectDB::get_instance(E->key()); if (o) { - CollisionObject2D *co = o->cast_to<CollisionObject2D>(); + CollisionObject2D *co = Object::cast_to<CollisionObject2D>(o); if (co) { co->_mouse_exit(); } @@ -595,19 +586,14 @@ void Viewport::_notification(int p_what) { if (physics_object_capture != 0) { - Object *obj = ObjectDB::get_instance(physics_object_capture); - if (obj) { - CollisionObject *co = obj->cast_to<CollisionObject>(); - if (co) { - co->_input_event(camera, ev, Vector3(), Vector3(), 0); - captured = true; - if (mb.is_valid() && mb->get_button_index() == 1 && !mb->is_pressed()) { - physics_object_capture = 0; - } - - } else { + CollisionObject *co = Object::cast_to<CollisionObject>(ObjectDB::get_instance(physics_object_capture)); + if (co) { + co->_input_event(camera, ev, Vector3(), Vector3(), 0); + captured = true; + if (mb.is_valid() && mb->get_button_index() == 1 && !mb->is_pressed()) { physics_object_capture = 0; } + } else { physics_object_capture = 0; } @@ -640,18 +626,15 @@ void Viewport::_notification(int p_what) { ObjectID new_collider = 0; if (col) { - if (result.collider) { - - CollisionObject *co = result.collider->cast_to<CollisionObject>(); - if (co) { + CollisionObject *co = Object::cast_to<CollisionObject>(result.collider); + if (co) { - co->_input_event(camera, ev, result.position, result.normal, result.shape); - last_object = co; - last_id = result.collider_id; - new_collider = last_id; - if (co->get_capture_input_on_drag() && mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed()) { - physics_object_capture = last_id; - } + co->_input_event(camera, ev, result.position, result.normal, result.shape); + last_object = co; + last_id = result.collider_id; + new_collider = last_id; + if (co->get_capture_input_on_drag() && mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed()) { + physics_object_capture = last_id; } } } @@ -678,11 +661,9 @@ void Viewport::_notification(int p_what) { bool col = space->intersect_ray(from, from + dir * 10000, result, Set<RID>(), 0xFFFFFFFF, 0xFFFFFFFF, true); ObjectID new_collider = 0; if (col) { - if (result.collider) { - CollisionObject *co = result.collider->cast_to<CollisionObject>(); - if (co) { - new_collider = result.collider_id; - } + CollisionObject *co = Object::cast_to<CollisionObject>(result.collider); + if (co) { + new_collider = result.collider_id; } } @@ -750,7 +731,7 @@ Size2 Viewport::get_size() const { void Viewport::_update_listener() { /* - if (is_inside_tree() && audio_listener && (camera || listener) && (!get_parent() || (get_parent()->cast_to<Control>() && get_parent()->cast_to<Control>()->is_visible_in_tree()))) { + if (is_inside_tree() && audio_listener && (camera || listener) && (!get_parent() || (Object::cast_to<Control>(get_parent()) && Object::cast_to<Control>(get_parent())->is_visible_in_tree()))) { SpatialSoundServer::get_singleton()->listener_set_space(internal_listener, find_world()->get_sound_space()); } else { SpatialSoundServer::get_singleton()->listener_set_space(internal_listener, RID()); @@ -761,7 +742,7 @@ void Viewport::_update_listener() { void Viewport::_update_listener_2d() { /* - if (is_inside_tree() && audio_listener && (!get_parent() || (get_parent()->cast_to<Control>() && get_parent()->cast_to<Control>()->is_visible_in_tree()))) + if (is_inside_tree() && audio_listener && (!get_parent() || (Object::cast_to<Control>(get_parent()) && Object::cast_to<Control>(get_parent())->is_visible_in_tree()))) SpatialSound2DServer::get_singleton()->listener_set_space(internal_listener_2d, find_world_2d()->get_sound_space()); else SpatialSound2DServer::get_singleton()->listener_set_space(internal_listener_2d, RID()); @@ -1029,11 +1010,11 @@ void Viewport::_propagate_enter_world(Node *p_node) { if (!p_node->is_inside_tree()) //may not have entered scene yet return; - if (p_node->cast_to<Spatial>() || p_node->cast_to<WorldEnvironment>()) { + if (Object::cast_to<Spatial>(p_node) || Object::cast_to<WorldEnvironment>(p_node)) { p_node->notification(Spatial::NOTIFICATION_ENTER_WORLD); } else { - Viewport *v = p_node->cast_to<Viewport>(); + Viewport *v = Object::cast_to<Viewport>(p_node); if (v) { if (v->world.is_valid()) @@ -1053,7 +1034,7 @@ void Viewport::_propagate_viewport_notification(Node *p_node, int p_what) { p_node->notification(p_what); for (int i = 0; i < p_node->get_child_count(); i++) { Node *c = p_node->get_child(i); - if (c->cast_to<Viewport>()) + if (Object::cast_to<Viewport>(c)) continue; _propagate_viewport_notification(c, p_what); } @@ -1066,11 +1047,11 @@ void Viewport::_propagate_exit_world(Node *p_node) { if (!p_node->is_inside_tree()) //may have exited scene already return; - if (p_node->cast_to<Spatial>() || p_node->cast_to<WorldEnvironment>()) { + if (Object::cast_to<Spatial>(p_node) || Object::cast_to<WorldEnvironment>(p_node)) { p_node->notification(Spatial::NOTIFICATION_EXIT_WORLD); } else { - Viewport *v = p_node->cast_to<Viewport>(); + Viewport *v = Object::cast_to<Viewport>(p_node); if (v) { if (v->world.is_valid()) @@ -1194,44 +1175,7 @@ bool Viewport::is_size_override_stretch_enabled() const { return size_override_stretch; } -#if 0 -void Viewport::set_as_render_target(bool p_enable){ - -/* if (render_target==p_enable) - return; - - render_target=p_enable; - - VS::get_singleton()->viewport_set_as_render_target(viewport,p_enable); - if (is_inside_tree()) { - - if (p_enable) - _vp_exit_tree(); - else - _vp_enter_tree(); - } - - if (p_enable) { - - texture_rid = VS::get_singleton()->viewport_get_texture(viewport); - } else { - - texture_rid=RID(); - } - - texture->set_flags(texture->flags); - texture->emit_changed(); - - update_configuration_warning(); - */ -} - -bool Viewport::is_set_as_render_target() const{ - return render_target; - -} -#endif void Viewport::set_update_mode(UpdateMode p_mode) { update_mode = p_mode; @@ -1241,7 +1185,6 @@ Viewport::UpdateMode Viewport::get_update_mode() const { return update_mode; } -//RID get_texture() const; Ref<ViewportTexture> Viewport::get_texture() const { @@ -1354,7 +1297,7 @@ void Viewport::_vp_input(const Ref<InputEvent> &p_ev) { return; #ifdef TOOLS_ENABLED - if (get_tree()->is_editor_hint() && get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root()->is_a_parent_of(this)) { + if (Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root()->is_a_parent_of(this)) { return; } #endif @@ -1374,7 +1317,7 @@ void Viewport::_vp_unhandled_input(const Ref<InputEvent> &p_ev) { if (disable_input) return; #ifdef TOOLS_ENABLED - if (get_tree()->is_editor_hint() && get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root()->is_a_parent_of(this)) { + if (Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root()->is_a_parent_of(this)) { return; } #endif @@ -1456,6 +1399,10 @@ void Viewport::_gui_show_tooltip() { gui.tooltip_popup = NULL; } + if (!gui.tooltip) { + return; + } + Control *rp = gui.tooltip->get_root_parent_control(); if (!rp) return; @@ -1510,12 +1457,12 @@ void Viewport::_gui_call_input(Control *p_control, const Ref<InputEvent> &p_inpu mb->get_button_index() == BUTTON_WHEEL_LEFT || mb->get_button_index() == BUTTON_WHEEL_RIGHT)); - bool ismouse = ev.is_valid() || p_input->cast_to<InputEventMouseMotion>() != NULL; + bool ismouse = ev.is_valid() || Object::cast_to<InputEventMouseMotion>(*p_input) != NULL; CanvasItem *ci = p_control; while (ci) { - Control *control = ci->cast_to<Control>(); + Control *control = Object::cast_to<Control>(ci); if (control) { control->call_multilevel(SceneStringNames::get_singleton()->_gui_input, ev); if (gui.key_event_accepted) @@ -1588,10 +1535,10 @@ Control *Viewport::_gui_find_control(const Point2 &p_global) { Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_global, const Transform2D &p_xform, Transform2D &r_inv_xform) { - if (p_node->cast_to<Viewport>()) + if (Object::cast_to<Viewport>(p_node)) return NULL; - Control *c = p_node->cast_to<Control>(); + Control *c = Object::cast_to<Control>(p_node); if (c) { //print_line("at "+String(c->get_path())+" POS "+c->get_position()+" bt "+p_xform); @@ -1616,7 +1563,7 @@ Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_ if (p_node == gui.tooltip_popup) continue; - CanvasItem *ci = p_node->get_child(i)->cast_to<CanvasItem>(); + CanvasItem *ci = Object::cast_to<CanvasItem>(p_node->get_child(i)); if (!ci || ci->is_set_as_toplevel()) continue; @@ -1645,7 +1592,7 @@ bool Viewport::_gui_drop(Control *p_at_control, Point2 p_at_pos, bool p_just_che CanvasItem *ci = p_at_control; while (ci) { - Control *control = ci->cast_to<Control>(); + Control *control = Object::cast_to<Control>(ci); if (control) { if (control->can_drop_data(p_at_pos, gui.drag_data)) { @@ -1770,7 +1717,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { CanvasItem *ci = gui.mouse_focus; while (ci) { - Control *control = ci->cast_to<Control>(); + Control *control = Object::cast_to<Control>(ci); if (control) { if (control->get_focus_mode() != Control::FOCUS_NONE) { if (control != gui.key_focus) { @@ -1891,7 +1838,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { CanvasItem *ci = gui.mouse_focus; while (ci) { - Control *control = ci->cast_to<Control>(); + Control *control = Object::cast_to<Control>(ci); if (control) { gui.drag_data = control->get_drag_data(control->get_global_transform_with_canvas().affine_inverse().xform(mpos) - gui.drag_accum); @@ -2236,7 +2183,7 @@ void Viewport::_gui_remove_from_modal_stack(List<Control *>::Element *MI, Object if (!next) { //top of stack Object *pfo = ObjectDB::get_instance(p_prev_focus_owner); - Control *pfoc = pfo->cast_to<Control>(); + Control *pfoc = Object::cast_to<Control>(pfo); if (!pfoc) return; @@ -2266,7 +2213,7 @@ void Viewport::_gui_force_drag(Control *p_base, const Variant &p_data, Control * void Viewport::_gui_set_drag_preview(Control *p_base, Control *p_control) { ERR_FAIL_NULL(p_control); - ERR_FAIL_COND(!((Object *)p_control)->cast_to<Control>()); + ERR_FAIL_COND(!Object::cast_to<Control>((Object *)p_control)); ERR_FAIL_COND(p_control->is_inside_tree()); ERR_FAIL_COND(p_control->get_parent() != NULL); @@ -2441,14 +2388,18 @@ void Viewport::unhandled_input(const Ref<InputEvent> &p_event) { get_tree()->_call_input_pause(unhandled_input_group, "_unhandled_input", p_event); //call_group(GROUP_CALL_REVERSE|GROUP_CALL_REALTIME|GROUP_CALL_MULIILEVEL,"unhandled_input","_unhandled_input",ev); - if (!get_tree()->input_handled && p_event->cast_to<InputEventKey>() != NULL) { + if (!get_tree()->input_handled && Object::cast_to<InputEventKey>(*p_event) != NULL) { get_tree()->_call_input_pause(unhandled_key_input_group, "_unhandled_key_input", p_event); //call_group(GROUP_CALL_REVERSE|GROUP_CALL_REALTIME|GROUP_CALL_MULIILEVEL,"unhandled_key_input","_unhandled_key_input",ev); } if (physics_object_picking && !get_tree()->input_handled) { - if (Input::get_singleton()->get_mouse_mode() != Input::MOUSE_MODE_CAPTURED && (p_event->cast_to<InputEventMouseButton>() || p_event->cast_to<InputEventMouseMotion>() || p_event->cast_to<InputEventScreenDrag>() || p_event->cast_to<InputEventScreenTouch>())) { + if (Input::get_singleton()->get_mouse_mode() != Input::MOUSE_MODE_CAPTURED && + (Object::cast_to<InputEventMouseButton>(*p_event) || + Object::cast_to<InputEventMouseMotion>(*p_event) || + Object::cast_to<InputEventScreenDrag>(*p_event) || + Object::cast_to<InputEventScreenTouch>(*p_event))) { physics_picking_events.push_back(p_event); } } @@ -2563,7 +2514,7 @@ Control *Viewport::get_modal_stack_top() const { String Viewport::get_configuration_warning() const { - /*if (get_parent() && !get_parent()->cast_to<Control>() && !render_target) { + /*if (get_parent() && !Object::cast_to<Control>(get_parent()) && !render_target) { return TTR("This viewport is not set as render target. If you intend for it to display its contents directly to the screen, make it a child of a Control so it can obtain a size. Otherwise, make it a RenderTarget and assign its internal texture to some node for display."); }*/ @@ -2741,7 +2692,7 @@ void Viewport::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "arvr"), "set_use_arvr", "use_arvr"); - ADD_PROPERTY(PropertyInfo(Variant::RECT2, "size"), "set_size", "get_size"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "own_world"), "set_use_own_world", "is_using_own_world"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "world", PROPERTY_HINT_RESOURCE_TYPE, "World"), "set_world", "get_world"); //ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"world_2d",PROPERTY_HINT_RESOURCE_TYPE,"World2D"), "set_world_2d", "get_world_2d") ; @@ -2772,38 +2723,38 @@ void Viewport::_bind_methods() { ADD_SIGNAL(MethodInfo("size_changed")); - BIND_CONSTANT(UPDATE_DISABLED); - BIND_CONSTANT(UPDATE_ONCE); - BIND_CONSTANT(UPDATE_WHEN_VISIBLE); - BIND_CONSTANT(UPDATE_ALWAYS); - - BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_DISABLED); - BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_1); - BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_4); - BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_16); - BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_64); - BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_256); - BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_1024); - BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_MAX); - - BIND_CONSTANT(RENDER_INFO_OBJECTS_IN_FRAME); - BIND_CONSTANT(RENDER_INFO_VERTICES_IN_FRAME); - BIND_CONSTANT(RENDER_INFO_MATERIAL_CHANGES_IN_FRAME); - BIND_CONSTANT(RENDER_INFO_SHADER_CHANGES_IN_FRAME); - BIND_CONSTANT(RENDER_INFO_SURFACE_CHANGES_IN_FRAME); - BIND_CONSTANT(RENDER_INFO_DRAW_CALLS_IN_FRAME); - BIND_CONSTANT(RENDER_INFO_MAX); - - BIND_CONSTANT(DEBUG_DRAW_DISABLED); - BIND_CONSTANT(DEBUG_DRAW_UNSHADED); - BIND_CONSTANT(DEBUG_DRAW_OVERDRAW); - BIND_CONSTANT(DEBUG_DRAW_WIREFRAME); - - BIND_CONSTANT(MSAA_DISABLED); - BIND_CONSTANT(MSAA_2X); - BIND_CONSTANT(MSAA_4X); - BIND_CONSTANT(MSAA_8X); - BIND_CONSTANT(MSAA_16X); + BIND_ENUM_CONSTANT(UPDATE_DISABLED); + BIND_ENUM_CONSTANT(UPDATE_ONCE); + BIND_ENUM_CONSTANT(UPDATE_WHEN_VISIBLE); + BIND_ENUM_CONSTANT(UPDATE_ALWAYS); + + BIND_ENUM_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_DISABLED); + BIND_ENUM_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_1); + BIND_ENUM_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_4); + BIND_ENUM_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_16); + BIND_ENUM_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_64); + BIND_ENUM_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_256); + BIND_ENUM_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_1024); + BIND_ENUM_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_MAX); + + BIND_ENUM_CONSTANT(RENDER_INFO_OBJECTS_IN_FRAME); + BIND_ENUM_CONSTANT(RENDER_INFO_VERTICES_IN_FRAME); + BIND_ENUM_CONSTANT(RENDER_INFO_MATERIAL_CHANGES_IN_FRAME); + BIND_ENUM_CONSTANT(RENDER_INFO_SHADER_CHANGES_IN_FRAME); + BIND_ENUM_CONSTANT(RENDER_INFO_SURFACE_CHANGES_IN_FRAME); + BIND_ENUM_CONSTANT(RENDER_INFO_DRAW_CALLS_IN_FRAME); + BIND_ENUM_CONSTANT(RENDER_INFO_MAX); + + BIND_ENUM_CONSTANT(DEBUG_DRAW_DISABLED); + BIND_ENUM_CONSTANT(DEBUG_DRAW_UNSHADED); + BIND_ENUM_CONSTANT(DEBUG_DRAW_OVERDRAW); + BIND_ENUM_CONSTANT(DEBUG_DRAW_WIREFRAME); + + BIND_ENUM_CONSTANT(MSAA_DISABLED); + BIND_ENUM_CONSTANT(MSAA_2X); + BIND_ENUM_CONSTANT(MSAA_4X); + BIND_ENUM_CONSTANT(MSAA_8X); + BIND_ENUM_CONSTANT(MSAA_16X); } Viewport::Viewport() { |