diff options
Diffstat (limited to 'servers')
35 files changed, 322 insertions, 288 deletions
diff --git a/servers/arvr/arvr_interface.cpp b/servers/arvr/arvr_interface.cpp index 0705df17b1..55707def7c 100644 --- a/servers/arvr/arvr_interface.cpp +++ b/servers/arvr/arvr_interface.cpp @@ -31,29 +31,49 @@ void ARVRInterface::_bind_methods() { ClassDB::bind_method(D_METHOD("get_name"), &ARVRInterface::get_name); + ClassDB::bind_method(D_METHOD("get_capabilities"), &ARVRInterface::get_capabilities); ClassDB::bind_method(D_METHOD("is_primary"), &ARVRInterface::is_primary); ClassDB::bind_method(D_METHOD("set_is_primary", "enable"), &ARVRInterface::set_is_primary); - ClassDB::bind_method(D_METHOD("is_installed"), &ARVRInterface::is_installed); - ClassDB::bind_method(D_METHOD("hmd_is_present"), &ARVRInterface::hmd_is_present); - ClassDB::bind_method(D_METHOD("supports_hmd"), &ARVRInterface::supports_hmd); ClassDB::bind_method(D_METHOD("is_initialized"), &ARVRInterface::is_initialized); + ClassDB::bind_method(D_METHOD("set_is_initialized", "initialized"), &ARVRInterface::set_is_initialized); ClassDB::bind_method(D_METHOD("initialize"), &ARVRInterface::initialize); ClassDB::bind_method(D_METHOD("uninitialize"), &ARVRInterface::uninitialize); + ClassDB::bind_method(D_METHOD("get_tracking_status"), &ARVRInterface::get_tracking_status); + ClassDB::bind_method(D_METHOD("get_recommended_render_targetsize"), &ARVRInterface::get_recommended_render_targetsize); + ClassDB::bind_method(D_METHOD("is_stereo"), &ARVRInterface::is_stereo); + + ADD_GROUP("Interface", "interface_"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interface_is_primary"), "set_is_primary", "is_primary"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interface_is_initialized"), "set_is_initialized", "is_initialized"); + + // we don't have any properties specific to VR yet.... - // These are now purely used internally, we may expose them again if we expose CameraMatrix through Variant but reduz is not a fan for good reasons :) - // ClassDB::bind_method(D_METHOD("get_transform_for_eye", "eye", "cam_transform"), &ARVRInterface::get_transform_for_eye); - // ClassDB::bind_method(D_METHOD("get_projection_for_eye", "eye"), &ARVRInterface::get_projection_for_eye); - // ClassDB::bind_method(D_METHOD("commit_for_eye", "node:viewport"), &ARVRInterface::commit_for_eye); + // but we do have properties specific to AR.... + ClassDB::bind_method(D_METHOD("get_anchor_detection_is_enabled"), &ARVRInterface::get_anchor_detection_is_enabled); + ClassDB::bind_method(D_METHOD("set_anchor_detection_is_enabled", "enable"), &ARVRInterface::set_anchor_detection_is_enabled); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "primary"), "set_is_primary", "is_primary"); + ADD_GROUP("AR", "ar_"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ar_is_anchor_detection_enabled"), "set_anchor_detection_is_enabled", "get_anchor_detection_is_enabled"); + + BIND_ENUM_CONSTANT(ARVR_NONE); + BIND_ENUM_CONSTANT(ARVR_MONO); + BIND_ENUM_CONSTANT(ARVR_STEREO); + BIND_ENUM_CONSTANT(ARVR_AR); + BIND_ENUM_CONSTANT(ARVR_EXTERNAL); BIND_ENUM_CONSTANT(EYE_MONO); BIND_ENUM_CONSTANT(EYE_LEFT); BIND_ENUM_CONSTANT(EYE_RIGHT); + + BIND_ENUM_CONSTANT(ARVR_NORMAL_TRACKING); + BIND_ENUM_CONSTANT(ARVR_EXCESSIVE_MOTION); + BIND_ENUM_CONSTANT(ARVR_INSUFFICIENT_FEATURES); + BIND_ENUM_CONSTANT(ARVR_UNKNOWN_TRACKING); + BIND_ENUM_CONSTANT(ARVR_NOT_TRACKING); }; StringName ARVRInterface::get_name() const { @@ -73,10 +93,40 @@ void ARVRInterface::set_is_primary(bool p_is_primary) { if (p_is_primary) { ERR_FAIL_COND(!is_initialized()); - ERR_FAIL_COND(!supports_hmd()); arvr_server->set_primary_interface(this); } else { arvr_server->clear_primary_interface_if(this); }; }; + +void ARVRInterface::set_is_initialized(bool p_initialized) { + if (p_initialized) { + if (!is_initialized()) { + initialize(); + }; + } else { + if (is_initialized()) { + uninitialize(); + }; + }; +}; + +ARVRInterface::Tracking_status ARVRInterface::get_tracking_status() const { + return tracking_state; +}; + +ARVRInterface::ARVRInterface() { + tracking_state = ARVR_UNKNOWN_TRACKING; +}; + +ARVRInterface::~ARVRInterface(){}; + +/** these will only be implemented on AR interfaces, so we want dummies for VR **/ +bool ARVRInterface::get_anchor_detection_is_enabled() const { + return false; +}; + +void ARVRInterface::set_anchor_detection_is_enabled(bool p_enable){ + // don't do anything here, this needs to be implemented on AR interface to enable/disable things like plane detection etc. +}; diff --git a/servers/arvr/arvr_interface.h b/servers/arvr/arvr_interface.h index d4fb383bbc..880f6e4595 100644 --- a/servers/arvr/arvr_interface.h +++ b/servers/arvr/arvr_interface.h @@ -50,31 +50,59 @@ class ARVRInterface : public Reference { GDCLASS(ARVRInterface, Reference); -protected: - _THREAD_SAFE_CLASS_ - - static void _bind_methods(); - public: + enum Capabilities { /* purely meta data, provides some info about what this interface supports */ + ARVR_NONE = 0, /* no capabilities */ + ARVR_MONO = 1, /* can be used with mono output */ + ARVR_STEREO = 2, /* can be used with stereo output */ + ARVR_AR = 4, /* offers a camera feed for AR */ + ARVR_EXTERNAL = 8 /* renders to external device */ + }; + enum Eyes { EYE_MONO, /* my son says we should call this EYE_CYCLOPS */ EYE_LEFT, EYE_RIGHT }; + enum Tracking_status { /* tracking status currently based on AR but we can start doing more with this for VR as well */ + ARVR_NORMAL_TRACKING, + ARVR_EXCESSIVE_MOTION, + ARVR_INSUFFICIENT_FEATURES, + ARVR_UNKNOWN_TRACKING, + ARVR_NOT_TRACKING + }; + +protected: + _THREAD_SAFE_CLASS_ + + Tracking_status tracking_state; + static void _bind_methods(); + +public: + /** general interface information **/ virtual StringName get_name() const; + virtual int get_capabilities() const = 0; bool is_primary(); void set_is_primary(bool p_is_primary); - virtual bool is_installed() = 0; /* returns true if the middle ware related to this interface has been installed */ - virtual bool hmd_is_present() = 0; /* returns true if our HMD is connected */ - virtual bool supports_hmd() = 0; /* returns true is this interface handles output to an HMD or only handles positioning */ - virtual bool is_initialized() = 0; /* returns true if we've initialized this interface */ + void set_is_initialized(bool p_initialized); /* helper function, will call initialize or uninitialize */ virtual bool initialize() = 0; /* initialize this interface, if this has an HMD it becomes the primary interface */ virtual void uninitialize() = 0; /* deinitialize this interface */ + Tracking_status get_tracking_status() const; /* get the status of our current tracking */ + + /** specific to VR **/ + // nothing yet + + /** specific to AR **/ + virtual bool get_anchor_detection_is_enabled() const; + virtual void set_anchor_detection_is_enabled(bool p_enable); + + /** rendering and internal **/ + virtual Size2 get_recommended_render_targetsize() = 0; /* returns the recommended render target size per eye for this device */ virtual bool is_stereo() = 0; /* returns true if this interface requires stereo rendering (for VR HMDs) or mono rendering (for mobile AR) */ virtual Transform get_transform_for_eye(ARVRInterface::Eyes p_eye, const Transform &p_cam_transform) = 0; /* get each eyes camera transform, also implement EYE_MONO */ @@ -82,8 +110,13 @@ public: virtual void commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) = 0; /* output the left or right eye */ virtual void process() = 0; + + ARVRInterface(); + ~ARVRInterface(); }; +VARIANT_ENUM_CAST(ARVRInterface::Capabilities); VARIANT_ENUM_CAST(ARVRInterface::Eyes); +VARIANT_ENUM_CAST(ARVRInterface::Tracking_status); #endif diff --git a/servers/arvr/arvr_script_interface.cpp b/servers/arvr/arvr_script_interface.cpp deleted file mode 100644 index 16e607920e..0000000000 --- a/servers/arvr/arvr_script_interface.cpp +++ /dev/null @@ -1,127 +0,0 @@ -#include "arvr_script_interface.h" - -ARVRScriptInterface::ARVRScriptInterface() { - // testing - printf("Construct script interface"); -} - -ARVRScriptInterface::~ARVRScriptInterface() { - if (is_initialized()) { - uninitialize(); - }; - - // testing - printf("Destruct script interface"); -} - -StringName ARVRScriptInterface::get_name() const { - if (get_script_instance() && get_script_instance()->has_method("get_name")) { - return get_script_instance()->call("get_name"); - } else { - // just return something for now - return "ARVR Script interface"; - } -} - -bool ARVRScriptInterface::is_installed() { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("is_installed")), false); - return get_script_instance()->call("is_installed"); -} - -bool ARVRScriptInterface::hmd_is_present() { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("hmd_is_present")), false); - return get_script_instance()->call("hmd_is_present"); -} - -bool ARVRScriptInterface::supports_hmd() { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("supports_hmd")), false); - return get_script_instance()->call("supports_hmd"); -} - -bool ARVRScriptInterface::is_stereo() { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("is_stereo")), false); - return get_script_instance()->call("is_stereo"); -} - -bool ARVRScriptInterface::is_initialized() { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("is_initialized")), false); - return get_script_instance()->call("is_initialized"); -} - -bool ARVRScriptInterface::initialize() { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("initialize")), false); - return get_script_instance()->call("initialize"); -} - -void ARVRScriptInterface::uninitialize() { - ARVRServer *arvr_server = ARVRServer::get_singleton(); - if (arvr_server != NULL) { - // Whatever happens, make sure this is no longer our primary interface - arvr_server->clear_primary_interface_if(this); - } - - ERR_FAIL_COND(!(get_script_instance() && get_script_instance()->has_method("uninitialize"))); - get_script_instance()->call("uninitialize"); -} - -Size2 ARVRScriptInterface::get_recommended_render_targetsize() { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("get_recommended_render_targetsize")), Size2()); - return get_script_instance()->call("get_recommended_render_targetsize"); -} - -Transform ARVRScriptInterface::get_transform_for_eye(Eyes p_eye, const Transform &p_cam_transform) { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("get_transform_for_eye")), Transform()); - return get_script_instance()->call("get_transform_for_eye", p_eye, p_cam_transform); -} - -// Suggestion from Reduz, as we can't return a CameraMatrix, return a PoolVector with our 16 floats -PoolVector<float> ARVRScriptInterface::_get_projection_for_eye(Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far) { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_projection_for_eye")), PoolVector<float>()); - return get_script_instance()->call("_get_projection_for_eye", p_eye, p_aspect, p_z_near, p_z_far); -} - -CameraMatrix ARVRScriptInterface::get_projection_for_eye(Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far) { - CameraMatrix cm; - int i = 0; - int j = 0; - - PoolVector<float> cm_as_floats = _get_projection_for_eye(p_eye, p_aspect, p_z_near, p_z_far); - - for (int k = 0; k < cm_as_floats.size() && i < 4; k++) { - cm.matrix[i][j] = cm_as_floats[k]; - j++; - if (j == 4) { - j = 0; - i++; - }; - }; - - return cm; -} - -void ARVRScriptInterface::commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) { - ERR_FAIL_COND(!(get_script_instance() && get_script_instance()->has_method("commit_for_eye"))); - get_script_instance()->call("commit_for_eye"); -} - -void ARVRScriptInterface::process() { - ERR_FAIL_COND(!(get_script_instance() && get_script_instance()->has_method("process"))); - get_script_instance()->call("process"); -} - -void ARVRScriptInterface::_bind_methods() { - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "is_installed")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "hmd_is_present")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "supports_hmd")); - - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "is_initialized")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "initialize")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo("uninitialize")); - - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "is_stereo")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::VECTOR2, "get_recommended_render_targetsize")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::TRANSFORM, "get_transform_for_eye", PropertyInfo(Variant::INT, "eye"), PropertyInfo(Variant::TRANSFORM, "cam_transform"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo("_get_projection_for_eye")); - ClassDB::add_virtual_method(get_class_static(), MethodInfo("commit_for_eye", PropertyInfo(Variant::INT, "eye"), PropertyInfo(Variant::_RID, "render_target"))); - ClassDB::add_virtual_method(get_class_static(), MethodInfo("process")); -} diff --git a/servers/arvr/arvr_script_interface.h b/servers/arvr/arvr_script_interface.h deleted file mode 100644 index 04ca33901a..0000000000 --- a/servers/arvr/arvr_script_interface.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef SCRIPT_INTERFACE_H -#define SCRIPT_INTERFACE_H - -#include "arvr_interface.h" - -/** - @authors Hinsbart & Karroffel - - This subclass of our AR/VR interface forms a bridge to GDNative. -*/ - -class ARVRScriptInterface : public ARVRInterface { - GDCLASS(ARVRScriptInterface, ARVRInterface); - -protected: - static void _bind_methods(); - -public: - ARVRScriptInterface(); - ~ARVRScriptInterface(); - - virtual StringName get_name() const; - - virtual bool is_installed(); - virtual bool hmd_is_present(); - virtual bool supports_hmd(); - - virtual bool is_initialized(); - virtual bool initialize(); - virtual void uninitialize(); - - virtual Size2 get_recommended_render_targetsize(); - virtual bool is_stereo(); - virtual Transform get_transform_for_eye(ARVRInterface::Eyes p_eye, const Transform &p_cam_transform); - - // we expose a PoolVector<float> version of this function to GDNative - PoolVector<float> _get_projection_for_eye(Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far); - - // and a CameraMatrix version to ARVRServer - virtual CameraMatrix get_projection_for_eye(ARVRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far); - - virtual void commit_for_eye(ARVRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect); - - virtual void process(); -}; - -#endif // SCRIPT_INTERFACE_H diff --git a/servers/arvr_server.cpp b/servers/arvr_server.cpp index 5d8cf20c92..4dfc40e9e4 100644 --- a/servers/arvr_server.cpp +++ b/servers/arvr_server.cpp @@ -43,7 +43,7 @@ void ARVRServer::_bind_methods() { ClassDB::bind_method(D_METHOD("get_world_scale"), &ARVRServer::get_world_scale); ClassDB::bind_method(D_METHOD("set_world_scale"), &ARVRServer::set_world_scale); ClassDB::bind_method(D_METHOD("get_reference_frame"), &ARVRServer::get_reference_frame); - ClassDB::bind_method(D_METHOD("request_reference_frame", "ignore_tilt", "keep_height"), &ARVRServer::request_reference_frame); + ClassDB::bind_method(D_METHOD("center_on_hmd", "ignore_tilt", "keep_height"), &ARVRServer::center_on_hmd); ADD_PROPERTY(PropertyInfo(Variant::REAL, "world_scale"), "set_world_scale", "get_world_scale"); @@ -53,10 +53,10 @@ void ARVRServer::_bind_methods() { ClassDB::bind_method(D_METHOD("get_tracker_count"), &ARVRServer::get_tracker_count); ClassDB::bind_method(D_METHOD("get_tracker", "idx"), &ARVRServer::get_tracker); - ClassDB::bind_method(D_METHOD("set_primary_interface"), &ARVRServer::set_primary_interface); + ClassDB::bind_method(D_METHOD("set_primary_interface", "interface"), &ARVRServer::set_primary_interface); - ClassDB::bind_method(D_METHOD("add_interface"), &ARVRServer::add_interface); - ClassDB::bind_method(D_METHOD("remove_interface"), &ARVRServer::remove_interface); + ClassDB::bind_method(D_METHOD("add_interface", "interface"), &ARVRServer::add_interface); + ClassDB::bind_method(D_METHOD("remove_interface", "interface"), &ARVRServer::remove_interface); BIND_ENUM_CONSTANT(TRACKER_CONTROLLER); BIND_ENUM_CONSTANT(TRACKER_BASESTATION); @@ -98,7 +98,7 @@ Transform ARVRServer::get_reference_frame() const { return reference_frame; }; -void ARVRServer::request_reference_frame(bool p_ignore_tilt, bool p_keep_height) { +void ARVRServer::center_on_hmd(bool p_ignore_tilt, bool p_keep_height) { if (primary_interface != NULL) { // clear our current reference frame or we'll end up double adjusting it reference_frame = Transform(); diff --git a/servers/arvr_server.h b/servers/arvr_server.h index 2645637ad5..948895cb27 100644 --- a/servers/arvr_server.h +++ b/servers/arvr_server.h @@ -117,14 +117,17 @@ public: void set_world_origin(const Transform p_world_origin); /* - Requesting a reference frame results in a matrix being calculated that ensures the HMD is positioned to 0,0,0 facing 0,0,-1 (need to verify this direction) + center_on_hmd calculates a new reference frame. This ensures the HMD is positioned to 0,0,0 facing 0,0,-1 (need to verify this direction) in the virtual world. + You can ignore the tilt of the device ensuring you're looking straight forward even if the player is looking down or sideways. + You can chose to keep the height the tracking provides which is important for room scale capable tracking. + Note: this should not be used in AR and should be ignored by an AR based interface as it would throw what you're looking at in the real world and in the virtual world out of sync */ Transform get_reference_frame() const; - void request_reference_frame(bool p_ignore_tilt, bool p_keep_height); + void center_on_hmd(bool p_ignore_tilt, bool p_keep_height); /* Interfaces are objects that 'glue' Godot to an AR or VR SDK such as the Oculus SDK, OpenVR, OpenHMD, etc. diff --git a/servers/audio/audio_stream.cpp b/servers/audio/audio_stream.cpp index dd4240f028..0e3d5824d9 100644 --- a/servers/audio/audio_stream.cpp +++ b/servers/audio/audio_stream.cpp @@ -178,16 +178,16 @@ int AudioStreamPlaybackRandomPitch::get_loop_count() const { return 0; } -float AudioStreamPlaybackRandomPitch::get_pos() const { +float AudioStreamPlaybackRandomPitch::get_playback_position() const { if (playing.is_valid()) { - return playing->get_pos(); + return playing->get_playback_position(); } return 0; } -void AudioStreamPlaybackRandomPitch::seek_pos(float p_time) { +void AudioStreamPlaybackRandomPitch::seek(float p_time) { if (playing.is_valid()) { - playing->seek_pos(p_time); + playing->seek(p_time); } } diff --git a/servers/audio/audio_stream.h b/servers/audio/audio_stream.h index c7cb63ef2c..3324597b41 100644 --- a/servers/audio/audio_stream.h +++ b/servers/audio/audio_stream.h @@ -45,8 +45,8 @@ public: virtual int get_loop_count() const = 0; //times it looped - virtual float get_pos() const = 0; - virtual void seek_pos(float p_time) = 0; + virtual float get_playback_position() const = 0; + virtual void seek(float p_time) = 0; virtual void mix(AudioFrame *p_bufer, float p_rate_scale, int p_frames) = 0; @@ -133,8 +133,8 @@ public: virtual int get_loop_count() const; //times it looped - virtual float get_pos() const; - virtual void seek_pos(float p_time); + virtual float get_playback_position() const; + virtual void seek(float p_time); virtual void mix(AudioFrame *p_bufer, float p_rate_scale, int p_frames); diff --git a/servers/audio/effects/audio_effect_chorus.cpp b/servers/audio/effects/audio_effect_chorus.cpp index 76dd585ffa..32631beb2c 100644 --- a/servers/audio/effects/audio_effect_chorus.cpp +++ b/servers/audio/effects/audio_effect_chorus.cpp @@ -182,9 +182,8 @@ Ref<AudioEffectInstance> AudioEffectChorus::instance() { void AudioEffectChorus::set_voice_count(int p_voices) { - ERR_FAIL_COND(p_voices < 1 || p_voices >= MAX_VOICES); + ERR_FAIL_COND(p_voices < 1 || p_voices > MAX_VOICES); voice_count = p_voices; - _change_notify(); } int AudioEffectChorus::get_voice_count() const { diff --git a/servers/audio/effects/audio_effect_limiter.cpp b/servers/audio/effects/audio_effect_limiter.cpp index 9787ba8109..c50dd804f2 100644 --- a/servers/audio/effects/audio_effect_limiter.cpp +++ b/servers/audio/effects/audio_effect_limiter.cpp @@ -110,7 +110,7 @@ void AudioEffectLimiter::set_soft_clip_ratio(float p_soft_clip) { } float AudioEffectLimiter::get_soft_clip_ratio() const { - return soft_clip; + return soft_clip_ratio; } void AudioEffectLimiter::_bind_methods() { diff --git a/servers/audio_server.cpp b/servers/audio_server.cpp index 78efe85e16..18b7014595 100644 --- a/servers/audio_server.cpp +++ b/servers/audio_server.cpp @@ -1088,7 +1088,7 @@ void AudioServer::_bind_methods() { ClassDB::bind_method(D_METHOD("get_bus_count"), &AudioServer::get_bus_count); ClassDB::bind_method(D_METHOD("remove_bus", "index"), &AudioServer::remove_bus); - ClassDB::bind_method(D_METHOD("add_bus", "at_pos"), &AudioServer::add_bus, DEFVAL(-1)); + ClassDB::bind_method(D_METHOD("add_bus", "at_position"), &AudioServer::add_bus, DEFVAL(-1)); ClassDB::bind_method(D_METHOD("move_bus", "index", "to_index"), &AudioServer::move_bus); ClassDB::bind_method(D_METHOD("set_bus_name", "bus_idx", "name"), &AudioServer::set_bus_name); @@ -1110,7 +1110,7 @@ void AudioServer::_bind_methods() { ClassDB::bind_method(D_METHOD("set_bus_bypass_effects", "bus_idx", "enable"), &AudioServer::set_bus_bypass_effects); ClassDB::bind_method(D_METHOD("is_bus_bypassing_effects", "bus_idx"), &AudioServer::is_bus_bypassing_effects); - ClassDB::bind_method(D_METHOD("add_bus_effect", "bus_idx", "effect", "at_pos"), &AudioServer::add_bus_effect, DEFVAL(-1)); + ClassDB::bind_method(D_METHOD("add_bus_effect", "bus_idx", "effect", "at_position"), &AudioServer::add_bus_effect, DEFVAL(-1)); ClassDB::bind_method(D_METHOD("remove_bus_effect", "bus_idx", "effect_idx"), &AudioServer::remove_bus_effect); ClassDB::bind_method(D_METHOD("get_bus_effect_count", "bus_idx"), &AudioServer::get_bus_effect_count); diff --git a/servers/physics/body_sw.h b/servers/physics/body_sw.h index 7e8d31f8eb..782bf14a4b 100644 --- a/servers/physics/body_sw.h +++ b/servers/physics/body_sw.h @@ -399,7 +399,7 @@ public: virtual int get_contact_count() const { return body->contact_count; } - virtual Vector3 get_contact_local_pos(int p_contact_idx) const { + virtual Vector3 get_contact_local_position(int p_contact_idx) const { ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector3()); return body->contacts[p_contact_idx].local_pos; } @@ -416,7 +416,7 @@ public: ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, RID()); return body->contacts[p_contact_idx].collider; } - virtual Vector3 get_contact_collider_pos(int p_contact_idx) const { + virtual Vector3 get_contact_collider_position(int p_contact_idx) const { ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector3()); return body->contacts[p_contact_idx].collider_pos; } @@ -428,7 +428,7 @@ public: ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, 0); return body->contacts[p_contact_idx].collider_shape; } - virtual Vector3 get_contact_collider_velocity_at_pos(int p_contact_idx) const { + virtual Vector3 get_contact_collider_velocity_at_position(int p_contact_idx) const { ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector3()); return body->contacts[p_contact_idx].collider_velocity_at_pos; } diff --git a/servers/physics/joints/pin_joint_sw.h b/servers/physics/joints/pin_joint_sw.h index 670c1ab61f..f6c11c49b0 100644 --- a/servers/physics/joints/pin_joint_sw.h +++ b/servers/physics/joints/pin_joint_sw.h @@ -86,8 +86,8 @@ public: void set_pos_a(const Vector3 &p_pos) { m_pivotInA = p_pos; } void set_pos_b(const Vector3 &p_pos) { m_pivotInB = p_pos; } - Vector3 get_pos_a() { return m_pivotInB; } - Vector3 get_pos_b() { return m_pivotInA; } + Vector3 get_position_a() { return m_pivotInA; } + Vector3 get_position_b() { return m_pivotInB; } PinJointSW(BodySW *p_body_a, const Vector3 &p_pos_a, BodySW *p_body_b, const Vector3 &p_pos_b); ~PinJointSW(); diff --git a/servers/physics/physics_server_sw.cpp b/servers/physics/physics_server_sw.cpp index 2d46770924..a7c31cf16c 100644 --- a/servers/physics/physics_server_sw.cpp +++ b/servers/physics/physics_server_sw.cpp @@ -183,7 +183,7 @@ PhysicsDirectSpaceState *PhysicsServerSW::space_get_direct_state(RID p_space) { ERR_FAIL_COND_V(!space, NULL); if (!doing_sync || space->is_locked()) { - ERR_EXPLAIN("Space state is inaccessible right now, wait for iteration or fixed process notification."); + ERR_EXPLAIN("Space state is inaccessible right now, wait for iteration or physics process notification."); ERR_FAIL_V(NULL); } @@ -914,6 +914,21 @@ bool PhysicsServerSW::body_test_motion(RID p_body, const Transform &p_from, cons return body->get_space()->test_body_motion(body, p_from, p_motion, p_margin, r_result); } +PhysicsDirectBodyState *PhysicsServerSW::body_get_direct_state(RID p_body) { + + BodySW *body = body_owner.get(p_body); + ERR_FAIL_COND_V(!body, NULL); + + if (!doing_sync || body->get_space()->is_locked()) { + + ERR_EXPLAIN("Body state is inaccessible right now, wait for iteration or physics process notification."); + ERR_FAIL_V(NULL); + } + + direct_state->body = body; + return direct_state; +} + /* JOINT API */ RID PhysicsServerSW::joint_create_pin(RID p_body_A, const Vector3 &p_local_A, RID p_body_B, const Vector3 &p_local_B) { @@ -968,7 +983,7 @@ Vector3 PhysicsServerSW::pin_joint_get_local_a(RID p_joint) const { ERR_FAIL_COND_V(!joint, Vector3()); ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, Vector3()); PinJointSW *pin_joint = static_cast<PinJointSW *>(joint); - return pin_joint->get_pos_a(); + return pin_joint->get_position_a(); } void PhysicsServerSW::pin_joint_set_local_b(RID p_joint, const Vector3 &p_B) { @@ -985,7 +1000,7 @@ Vector3 PhysicsServerSW::pin_joint_get_local_b(RID p_joint) const { ERR_FAIL_COND_V(!joint, Vector3()); ERR_FAIL_COND_V(joint->get_type() != JOINT_PIN, Vector3()); PinJointSW *pin_joint = static_cast<PinJointSW *>(joint); - return pin_joint->get_pos_b(); + return pin_joint->get_position_b(); } RID PhysicsServerSW::joint_create_hinge(RID p_body_A, const Transform &p_frame_A, RID p_body_B, const Transform &p_frame_B) { diff --git a/servers/physics/physics_server_sw.h b/servers/physics/physics_server_sw.h index 99ba302acd..f9eb8fa454 100644 --- a/servers/physics/physics_server_sw.h +++ b/servers/physics/physics_server_sw.h @@ -95,7 +95,7 @@ public: virtual void space_set_param(RID p_space, SpaceParameter p_param, real_t p_value); virtual real_t space_get_param(RID p_space, SpaceParameter p_param) const; - // this function only works on fixed process, errors and returns null otherwise + // this function only works on physics process, errors and returns null otherwise virtual PhysicsDirectSpaceState *space_get_direct_state(RID p_space); virtual void space_set_debug_contacts(RID p_space, int p_max_contacts); @@ -223,6 +223,9 @@ public: virtual bool body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, float p_margin = 0.001, MotionResult *r_result = NULL); + // this function only works on physics process, errors and returns null otherwise + virtual PhysicsDirectBodyState *body_get_direct_state(RID p_body); + /* JOINT API */ virtual RID joint_create_pin(RID p_body_A, const Vector3 &p_local_A, RID p_body_B, const Vector3 &p_local_B); diff --git a/servers/physics_2d/body_2d_sw.h b/servers/physics_2d/body_2d_sw.h index 0ffad62f45..f7c717a5c6 100644 --- a/servers/physics_2d/body_2d_sw.h +++ b/servers/physics_2d/body_2d_sw.h @@ -353,7 +353,7 @@ public: virtual int get_contact_count() const { return body->contact_count; } - virtual Vector2 get_contact_local_pos(int p_contact_idx) const { + virtual Vector2 get_contact_local_position(int p_contact_idx) const { ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector2()); return body->contacts[p_contact_idx].local_pos; } @@ -370,7 +370,7 @@ public: ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, RID()); return body->contacts[p_contact_idx].collider; } - virtual Vector2 get_contact_collider_pos(int p_contact_idx) const { + virtual Vector2 get_contact_collider_position(int p_contact_idx) const { ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector2()); return body->contacts[p_contact_idx].collider_pos; } @@ -384,7 +384,7 @@ public: } virtual Variant get_contact_collider_shape_metadata(int p_contact_idx) const; - virtual Vector2 get_contact_collider_velocity_at_pos(int p_contact_idx) const { + virtual Vector2 get_contact_collider_velocity_at_position(int p_contact_idx) const { ERR_FAIL_INDEX_V(p_contact_idx, body->contact_count, Vector2()); return body->contacts[p_contact_idx].collider_velocity_at_pos; } diff --git a/servers/physics_2d/collision_object_2d_sw.h b/servers/physics_2d/collision_object_2d_sw.h index db1270633f..627ba8ea15 100644 --- a/servers/physics_2d/collision_object_2d_sw.h +++ b/servers/physics_2d/collision_object_2d_sw.h @@ -110,21 +110,48 @@ public: void set_shape_metadata(int p_index, const Variant &p_metadata); _FORCE_INLINE_ int get_shape_count() const { return shapes.size(); } - _FORCE_INLINE_ Shape2DSW *get_shape(int p_index) const { return shapes[p_index].shape; } - _FORCE_INLINE_ const Transform2D &get_shape_transform(int p_index) const { return shapes[p_index].xform; } - _FORCE_INLINE_ const Transform2D &get_shape_inv_transform(int p_index) const { return shapes[p_index].xform_inv; } - _FORCE_INLINE_ const Rect2 &get_shape_aabb(int p_index) const { return shapes[p_index].aabb_cache; } - _FORCE_INLINE_ const Variant &get_shape_metadata(int p_index) const { return shapes[p_index].metadata; } + _FORCE_INLINE_ Shape2DSW *get_shape(int p_index) const { + ERR_FAIL_INDEX_V(p_index, shapes.size(), NULL); + return shapes[p_index].shape; + } + _FORCE_INLINE_ const Transform2D &get_shape_transform(int p_index) const { + ERR_FAIL_INDEX_V(p_index, shapes.size(), Transform2D()); + return shapes[p_index].xform; + } + _FORCE_INLINE_ const Transform2D &get_shape_inv_transform(int p_index) const { + ERR_FAIL_INDEX_V(p_index, shapes.size(), Transform2D()); + return shapes[p_index].xform_inv; + } + _FORCE_INLINE_ const Rect2 &get_shape_aabb(int p_index) const { + ERR_FAIL_INDEX_V(p_index, shapes.size(), Rect2()); + return shapes[p_index].aabb_cache; + } + _FORCE_INLINE_ const Variant &get_shape_metadata(int p_index) const { + ERR_FAIL_INDEX_V(p_index, shapes.size(), Variant()); + return shapes[p_index].metadata; + } _FORCE_INLINE_ Transform2D get_transform() const { return transform; } _FORCE_INLINE_ Transform2D get_inv_transform() const { return inv_transform; } _FORCE_INLINE_ Space2DSW *get_space() const { return space; } - _FORCE_INLINE_ void set_shape_as_disabled(int p_idx, bool p_disabled) { shapes[p_idx].disabled = p_disabled; } - _FORCE_INLINE_ bool is_shape_set_as_disabled(int p_idx) const { return shapes[p_idx].disabled; } + _FORCE_INLINE_ void set_shape_as_disabled(int p_idx, bool p_disabled) { + ERR_FAIL_INDEX(p_idx, shapes.size()); + shapes[p_idx].disabled = p_disabled; + } + _FORCE_INLINE_ bool is_shape_set_as_disabled(int p_idx) const { + ERR_FAIL_INDEX_V(p_idx, shapes.size(), false); + return shapes[p_idx].disabled; + } - _FORCE_INLINE_ void set_shape_as_one_way_collision(int p_idx, bool p_one_way_collision) { shapes[p_idx].one_way_collision = p_one_way_collision; } - _FORCE_INLINE_ bool is_shape_set_as_one_way_collision(int p_idx) const { return shapes[p_idx].one_way_collision; } + _FORCE_INLINE_ void set_shape_as_one_way_collision(int p_idx, bool p_one_way_collision) { + ERR_FAIL_INDEX(p_idx, shapes.size()); + shapes[p_idx].one_way_collision = p_one_way_collision; + } + _FORCE_INLINE_ bool is_shape_set_as_one_way_collision(int p_idx) const { + ERR_FAIL_INDEX_V(p_idx, shapes.size(), false); + return shapes[p_idx].one_way_collision; + } void set_collision_mask(uint32_t p_mask) { collision_mask = p_mask; } _FORCE_INLINE_ uint32_t get_collision_mask() const { return collision_mask; } diff --git a/servers/physics_2d/physics_2d_server_sw.cpp b/servers/physics_2d/physics_2d_server_sw.cpp index e9e7122af3..df3bf72a31 100644 --- a/servers/physics_2d/physics_2d_server_sw.cpp +++ b/servers/physics_2d/physics_2d_server_sw.cpp @@ -270,7 +270,7 @@ Physics2DDirectSpaceState *Physics2DServerSW::space_get_direct_state(RID p_space ERR_FAIL_COND_V(!space, NULL); if ((using_threads && !doing_sync) || space->is_locked()) { - ERR_EXPLAIN("Space state is inaccessible right now, wait for iteration or fixed process notification."); + ERR_EXPLAIN("Space state is inaccessible right now, wait for iteration or physics process notification."); ERR_FAIL_V(NULL); } @@ -954,6 +954,21 @@ bool Physics2DServerSW::body_test_motion(RID p_body, const Transform2D &p_from, return body->get_space()->test_body_motion(body, p_from, p_motion, p_margin, r_result); } +Physics2DDirectBodyState *Physics2DServerSW::body_get_direct_state(RID p_body) { + + Body2DSW *body = body_owner.get(p_body); + ERR_FAIL_COND_V(!body, NULL); + + if ((using_threads && !doing_sync) || body->get_space()->is_locked()) { + + ERR_EXPLAIN("Body state is inaccessible right now, wait for iteration or physics process notification."); + ERR_FAIL_V(NULL); + } + + direct_state->body = body; + return direct_state; +} + /* JOINT API */ void Physics2DServerSW::joint_set_param(RID p_joint, JointParam p_param, real_t p_value) { diff --git a/servers/physics_2d/physics_2d_server_sw.h b/servers/physics_2d/physics_2d_server_sw.h index dd310d7a93..c40cf0e3e0 100644 --- a/servers/physics_2d/physics_2d_server_sw.h +++ b/servers/physics_2d/physics_2d_server_sw.h @@ -103,7 +103,7 @@ public: virtual Vector<Vector2> space_get_contacts(RID p_space) const; virtual int space_get_contact_count(RID p_space) const; - // this function only works on fixed process, errors and returns null otherwise + // this function only works on physics process, errors and returns null otherwise virtual Physics2DDirectSpaceState *space_get_direct_state(RID p_space); /* AREA API */ @@ -222,6 +222,9 @@ public: virtual bool body_test_motion(RID p_body, const Transform2D &p_from, const Vector2 &p_motion, real_t p_margin = 0.001, MotionResult *r_result = NULL); + // this function only works on physics process, errors and returns null otherwise + virtual Physics2DDirectBodyState *body_get_direct_state(RID p_body); + /* JOINT API */ virtual void joint_set_param(RID p_joint, JointParam p_param, real_t p_value); diff --git a/servers/physics_2d/physics_2d_server_wrap_mt.cpp b/servers/physics_2d/physics_2d_server_wrap_mt.cpp index a4e6abfd45..f8f3b620d4 100644 --- a/servers/physics_2d/physics_2d_server_wrap_mt.cpp +++ b/servers/physics_2d/physics_2d_server_wrap_mt.cpp @@ -109,16 +109,13 @@ void Physics2DServerWrapMT::init() { if (create_thread) { step_sem = Semaphore::create(); - print_line("CREATING PHYSICS 2D THREAD"); //OS::get_singleton()->release_rendering_thread(); if (create_thread) { thread = Thread::create(_thread_callback, this); - print_line("STARTING PHYISICS 2D THREAD"); } while (!step_thread_up) { OS::get_singleton()->delay_usec(1000); } - print_line("DONE PHYSICS 2D THREAD"); } else { physics_2d_server->init(); diff --git a/servers/physics_2d/physics_2d_server_wrap_mt.h b/servers/physics_2d/physics_2d_server_wrap_mt.h index 189419e8e4..50e9ab1005 100644 --- a/servers/physics_2d/physics_2d_server_wrap_mt.h +++ b/servers/physics_2d/physics_2d_server_wrap_mt.h @@ -111,7 +111,7 @@ public: FUNC3(space_set_param, RID, SpaceParameter, real_t); FUNC2RC(real_t, space_get_param, RID, SpaceParameter); - // this function only works on fixed process, errors and returns null otherwise + // this function only works on physics process, errors and returns null otherwise Physics2DDirectSpaceState *space_get_direct_state(RID p_space) { ERR_FAIL_COND_V(main_thread != Thread::get_caller_id(), NULL); @@ -253,6 +253,13 @@ public: return physics_2d_server->body_test_motion(p_body, p_from, p_motion, p_margin, r_result); } + // this function only works on physics process, errors and returns null otherwise + Physics2DDirectBodyState *body_get_direct_state(RID p_body) { + + ERR_FAIL_COND_V(main_thread != Thread::get_caller_id(), NULL); + return physics_2d_server->body_get_direct_state(p_body); + } + /* JOINT API */ FUNC3(joint_set_param, RID, JointParam, real_t); diff --git a/servers/physics_2d_server.cpp b/servers/physics_2d_server.cpp index 06966e2452..671c31e6a3 100644 --- a/servers/physics_2d_server.cpp +++ b/servers/physics_2d_server.cpp @@ -92,16 +92,16 @@ void Physics2DDirectBodyState::_bind_methods() { ClassDB::bind_method(D_METHOD("get_contact_count"), &Physics2DDirectBodyState::get_contact_count); - ClassDB::bind_method(D_METHOD("get_contact_local_pos", "contact_idx"), &Physics2DDirectBodyState::get_contact_local_pos); + ClassDB::bind_method(D_METHOD("get_contact_local_position", "contact_idx"), &Physics2DDirectBodyState::get_contact_local_position); ClassDB::bind_method(D_METHOD("get_contact_local_normal", "contact_idx"), &Physics2DDirectBodyState::get_contact_local_normal); ClassDB::bind_method(D_METHOD("get_contact_local_shape", "contact_idx"), &Physics2DDirectBodyState::get_contact_local_shape); ClassDB::bind_method(D_METHOD("get_contact_collider", "contact_idx"), &Physics2DDirectBodyState::get_contact_collider); - ClassDB::bind_method(D_METHOD("get_contact_collider_pos", "contact_idx"), &Physics2DDirectBodyState::get_contact_collider_pos); + ClassDB::bind_method(D_METHOD("get_contact_collider_position", "contact_idx"), &Physics2DDirectBodyState::get_contact_collider_position); ClassDB::bind_method(D_METHOD("get_contact_collider_id", "contact_idx"), &Physics2DDirectBodyState::get_contact_collider_id); ClassDB::bind_method(D_METHOD("get_contact_collider_object", "contact_idx"), &Physics2DDirectBodyState::get_contact_collider_object); ClassDB::bind_method(D_METHOD("get_contact_collider_shape", "contact_idx"), &Physics2DDirectBodyState::get_contact_collider_shape); ClassDB::bind_method(D_METHOD("get_contact_collider_shape_metadata", "contact_idx"), &Physics2DDirectBodyState::get_contact_collider_shape_metadata); - ClassDB::bind_method(D_METHOD("get_contact_collider_velocity_at_pos", "contact_idx"), &Physics2DDirectBodyState::get_contact_collider_velocity_at_pos); + ClassDB::bind_method(D_METHOD("get_contact_collider_velocity_at_position", "contact_idx"), &Physics2DDirectBodyState::get_contact_collider_velocity_at_position); ClassDB::bind_method(D_METHOD("get_step"), &Physics2DDirectBodyState::get_step); ClassDB::bind_method(D_METHOD("integrate_forces"), &Physics2DDirectBodyState::integrate_forces); ClassDB::bind_method(D_METHOD("get_space_state"), &Physics2DDirectBodyState::get_space_state); @@ -561,7 +561,7 @@ void Physics2DServer::_bind_methods() { ClassDB::bind_method(D_METHOD("body_set_state", "body", "state", "value"), &Physics2DServer::body_set_state); ClassDB::bind_method(D_METHOD("body_get_state", "body", "state"), &Physics2DServer::body_get_state); - ClassDB::bind_method(D_METHOD("body_apply_impulse", "body", "pos", "impulse"), &Physics2DServer::body_apply_impulse); + ClassDB::bind_method(D_METHOD("body_apply_impulse", "body", "position", "impulse"), &Physics2DServer::body_apply_impulse); ClassDB::bind_method(D_METHOD("body_add_force", "body", "offset", "force"), &Physics2DServer::body_add_force); ClassDB::bind_method(D_METHOD("body_set_axis_velocity", "body", "axis_velocity"), &Physics2DServer::body_set_axis_velocity); @@ -579,6 +579,8 @@ void Physics2DServer::_bind_methods() { ClassDB::bind_method(D_METHOD("body_test_motion", "body", "from", "motion", "margin", "result"), &Physics2DServer::_body_test_motion, DEFVAL(0.08), DEFVAL(Variant())); + ClassDB::bind_method(D_METHOD("body_get_direct_state", "body"), &Physics2DServer::body_get_direct_state); + /* JOINT API */ ClassDB::bind_method(D_METHOD("joint_set_param", "joint", "param", "value"), &Physics2DServer::joint_set_param); diff --git a/servers/physics_2d_server.h b/servers/physics_2d_server.h index cd6a20e6b8..18f4f460b6 100644 --- a/servers/physics_2d_server.h +++ b/servers/physics_2d_server.h @@ -65,17 +65,17 @@ public: virtual int get_contact_count() const = 0; - virtual Vector2 get_contact_local_pos(int p_contact_idx) const = 0; + virtual Vector2 get_contact_local_position(int p_contact_idx) const = 0; virtual Vector2 get_contact_local_normal(int p_contact_idx) const = 0; virtual int get_contact_local_shape(int p_contact_idx) const = 0; virtual RID get_contact_collider(int p_contact_idx) const = 0; - virtual Vector2 get_contact_collider_pos(int p_contact_idx) const = 0; + virtual Vector2 get_contact_collider_position(int p_contact_idx) const = 0; virtual ObjectID get_contact_collider_id(int p_contact_idx) const = 0; virtual Object *get_contact_collider_object(int p_contact_idx) const; virtual int get_contact_collider_shape(int p_contact_idx) const = 0; virtual Variant get_contact_collider_shape_metadata(int p_contact_idx) const = 0; - virtual Vector2 get_contact_collider_velocity_at_pos(int p_contact_idx) const = 0; + virtual Vector2 get_contact_collider_velocity_at_position(int p_contact_idx) const = 0; virtual real_t get_step() const = 0; virtual void integrate_forces(); @@ -283,7 +283,7 @@ public: virtual void space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) = 0; virtual real_t space_get_param(RID p_space, SpaceParameter p_param) const = 0; - // this function only works on fixed process, errors and returns null otherwise + // this function only works on physics process, errors and returns null otherwise virtual Physics2DDirectSpaceState *space_get_direct_state(RID p_space) = 0; virtual void space_set_debug_contacts(RID p_space, int p_max_contacts) = 0; @@ -468,6 +468,9 @@ public: virtual void body_set_pickable(RID p_body, bool p_pickable) = 0; + // this function only works on physics process, errors and returns null otherwise + virtual Physics2DDirectBodyState *body_get_direct_state(RID p_body) = 0; + struct MotionResult { Vector2 motion; diff --git a/servers/physics_server.cpp b/servers/physics_server.cpp index 28ab31b8f6..6d192886a5 100644 --- a/servers/physics_server.cpp +++ b/servers/physics_server.cpp @@ -89,8 +89,8 @@ void PhysicsDirectBodyState::_bind_methods() { ClassDB::bind_method(D_METHOD("set_transform", "transform"), &PhysicsDirectBodyState::set_transform); ClassDB::bind_method(D_METHOD("get_transform"), &PhysicsDirectBodyState::get_transform); - ClassDB::bind_method(D_METHOD("add_force", "force", "pos"), &PhysicsDirectBodyState::add_force); - ClassDB::bind_method(D_METHOD("apply_impulse", "pos", "j"), &PhysicsDirectBodyState::apply_impulse); + ClassDB::bind_method(D_METHOD("add_force", "force", "position"), &PhysicsDirectBodyState::add_force); + ClassDB::bind_method(D_METHOD("apply_impulse", "position", "j"), &PhysicsDirectBodyState::apply_impulse); ClassDB::bind_method(D_METHOD("apply_torqe_impulse", "j"), &PhysicsDirectBodyState::apply_torque_impulse); ClassDB::bind_method(D_METHOD("set_sleep_state", "enabled"), &PhysicsDirectBodyState::set_sleep_state); @@ -98,15 +98,15 @@ void PhysicsDirectBodyState::_bind_methods() { ClassDB::bind_method(D_METHOD("get_contact_count"), &PhysicsDirectBodyState::get_contact_count); - ClassDB::bind_method(D_METHOD("get_contact_local_pos", "contact_idx"), &PhysicsDirectBodyState::get_contact_local_pos); + ClassDB::bind_method(D_METHOD("get_contact_local_position", "contact_idx"), &PhysicsDirectBodyState::get_contact_local_position); ClassDB::bind_method(D_METHOD("get_contact_local_normal", "contact_idx"), &PhysicsDirectBodyState::get_contact_local_normal); ClassDB::bind_method(D_METHOD("get_contact_local_shape", "contact_idx"), &PhysicsDirectBodyState::get_contact_local_shape); ClassDB::bind_method(D_METHOD("get_contact_collider", "contact_idx"), &PhysicsDirectBodyState::get_contact_collider); - ClassDB::bind_method(D_METHOD("get_contact_collider_pos", "contact_idx"), &PhysicsDirectBodyState::get_contact_collider_pos); + ClassDB::bind_method(D_METHOD("get_contact_collider_position", "contact_idx"), &PhysicsDirectBodyState::get_contact_collider_position); ClassDB::bind_method(D_METHOD("get_contact_collider_id", "contact_idx"), &PhysicsDirectBodyState::get_contact_collider_id); ClassDB::bind_method(D_METHOD("get_contact_collider_object", "contact_idx"), &PhysicsDirectBodyState::get_contact_collider_object); ClassDB::bind_method(D_METHOD("get_contact_collider_shape", "contact_idx"), &PhysicsDirectBodyState::get_contact_collider_shape); - ClassDB::bind_method(D_METHOD("get_contact_collider_velocity_at_pos", "contact_idx"), &PhysicsDirectBodyState::get_contact_collider_velocity_at_pos); + ClassDB::bind_method(D_METHOD("get_contact_collider_velocity_at_position", "contact_idx"), &PhysicsDirectBodyState::get_contact_collider_velocity_at_position); ClassDB::bind_method(D_METHOD("get_step"), &PhysicsDirectBodyState::get_step); ClassDB::bind_method(D_METHOD("integrate_forces"), &PhysicsDirectBodyState::integrate_forces); ClassDB::bind_method(D_METHOD("get_space_state"), &PhysicsDirectBodyState::get_space_state); @@ -482,7 +482,7 @@ void PhysicsServer::_bind_methods() { ClassDB::bind_method(D_METHOD("body_set_state", "body", "state", "value"), &PhysicsServer::body_set_state); ClassDB::bind_method(D_METHOD("body_get_state", "body", "state"), &PhysicsServer::body_get_state); - ClassDB::bind_method(D_METHOD("body_apply_impulse", "body", "pos", "impulse"), &PhysicsServer::body_apply_impulse); + ClassDB::bind_method(D_METHOD("body_apply_impulse", "body", "position", "impulse"), &PhysicsServer::body_apply_impulse); ClassDB::bind_method(D_METHOD("body_apply_torque_impulse", "body", "impulse"), &PhysicsServer::body_apply_torque_impulse); ClassDB::bind_method(D_METHOD("body_set_axis_velocity", "body", "axis_velocity"), &PhysicsServer::body_set_axis_velocity); @@ -504,6 +504,8 @@ void PhysicsServer::_bind_methods() { ClassDB::bind_method(D_METHOD("body_set_ray_pickable", "body", "enable"), &PhysicsServer::body_set_ray_pickable); ClassDB::bind_method(D_METHOD("body_is_ray_pickable", "body"), &PhysicsServer::body_is_ray_pickable); + ClassDB::bind_method(D_METHOD("body_get_direct_state", "body"), &PhysicsServer::body_get_direct_state); + /* JOINT API */ BIND_ENUM_CONSTANT(JOINT_PIN); diff --git a/servers/physics_server.h b/servers/physics_server.h index c6d312e0fe..8cec125646 100644 --- a/servers/physics_server.h +++ b/servers/physics_server.h @@ -71,16 +71,16 @@ public: virtual int get_contact_count() const = 0; - virtual Vector3 get_contact_local_pos(int p_contact_idx) const = 0; + virtual Vector3 get_contact_local_position(int p_contact_idx) const = 0; virtual Vector3 get_contact_local_normal(int p_contact_idx) const = 0; virtual int get_contact_local_shape(int p_contact_idx) const = 0; virtual RID get_contact_collider(int p_contact_idx) const = 0; - virtual Vector3 get_contact_collider_pos(int p_contact_idx) const = 0; + virtual Vector3 get_contact_collider_position(int p_contact_idx) const = 0; virtual ObjectID get_contact_collider_id(int p_contact_idx) const = 0; virtual Object *get_contact_collider_object(int p_contact_idx) const; virtual int get_contact_collider_shape(int p_contact_idx) const = 0; - virtual Vector3 get_contact_collider_velocity_at_pos(int p_contact_idx) const = 0; + virtual Vector3 get_contact_collider_velocity_at_position(int p_contact_idx) const = 0; virtual real_t get_step() const = 0; virtual void integrate_forces(); @@ -276,7 +276,7 @@ public: virtual void space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) = 0; virtual real_t space_get_param(RID p_space, SpaceParameter p_param) const = 0; - // this function only works on fixed process, errors and returns null otherwise + // this function only works on physics process, errors and returns null otherwise virtual PhysicsDirectSpaceState *space_get_direct_state(RID p_space) = 0; virtual void space_set_debug_contacts(RID p_space, int p_max_contacts) = 0; @@ -464,6 +464,9 @@ public: virtual void body_set_ray_pickable(RID p_body, bool p_enable) = 0; virtual bool body_is_ray_pickable(RID p_body) const = 0; + // this function only works on physics process, errors and returns null otherwise + virtual PhysicsDirectBodyState *body_get_direct_state(RID p_body) = 0; + struct MotionResult { Vector3 motion; diff --git a/servers/register_server_types.cpp b/servers/register_server_types.cpp index 845a3443b7..7a9328e30f 100644 --- a/servers/register_server_types.cpp +++ b/servers/register_server_types.cpp @@ -32,7 +32,6 @@ #include "arvr/arvr_interface.h" #include "arvr/arvr_positional_tracker.h" -#include "arvr/arvr_script_interface.h" #include "arvr_server.h" #include "audio/audio_effect.h" #include "audio/audio_stream.h" @@ -74,10 +73,14 @@ static void _debugger_get_resource_usage(List<ScriptDebuggerRemote::ResourceUsag } ShaderTypes *shader_types = NULL; -ARVRServer *arvr_server = NULL; void register_server_types() { - arvr_server = memnew(ARVRServer); + + ClassDB::register_virtual_class<VisualServer>(); + ClassDB::register_class<AudioServer>(); + ClassDB::register_virtual_class<PhysicsServer>(); + ClassDB::register_virtual_class<Physics2DServer>(); + ClassDB::register_class<ARVRServer>(); ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("VisualServer", VisualServer::get_singleton())); ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("AudioServer", AudioServer::get_singleton())); @@ -89,12 +92,13 @@ void register_server_types() { ClassDB::register_virtual_class<ARVRInterface>(); ClassDB::register_class<ARVRPositionalTracker>(); - ClassDB::register_class<ARVRScriptInterface>(); ClassDB::register_virtual_class<AudioStream>(); ClassDB::register_virtual_class<AudioStreamPlayback>(); ClassDB::register_class<AudioStreamRandomPitch>(); ClassDB::register_virtual_class<AudioEffect>(); + ClassDB::register_class<AudioEffectEQ>(); + ClassDB::register_class<AudioEffectFilter>(); ClassDB::register_class<AudioBusLayout>(); { @@ -144,9 +148,5 @@ void register_server_types() { void unregister_server_types() { - //@TODO move this into iPhone/Android implementation? just have this here for testing... - // mobile_interface = NULL; - memdelete(shader_types); - memdelete(arvr_server); } diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index 344c10089a..b3f6b243de 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -53,7 +53,7 @@ public: virtual void environment_set_background(RID p_env, VS::EnvironmentBG p_bg) = 0; virtual void environment_set_sky(RID p_env, RID p_sky) = 0; - virtual void environment_set_sky_scale(RID p_env, float p_scale) = 0; + virtual void environment_set_sky_custom_fov(RID p_env, float p_scale) = 0; virtual void environment_set_bg_color(RID p_env, const Color &p_color) = 0; virtual void environment_set_bg_energy(RID p_env, float p_energy) = 0; virtual void environment_set_canvas_max_layer(RID p_env, int p_max_layer) = 0; diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index 6ad433268f..b2a11deea1 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -267,6 +267,7 @@ const ShaderLanguage::KeyWord ShaderLanguage::keyword_list[] = { { TK_CF_BREAK, "break" }, { TK_CF_CONTINUE, "continue" }, { TK_CF_RETURN, "return" }, + { TK_CF_DISCARD, "discard" }, { TK_UNIFORM, "uniform" }, { TK_VARYING, "varying" }, { TK_ARG_IN, "in" }, @@ -1377,6 +1378,10 @@ const ShaderLanguage::BuiltinFuncDef ShaderLanguage::builtin_func_defs[] = { { "sqrt", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "sqrt", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, { "sqrt", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, + { "inversesqrt", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, + { "inversesqrt", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, + { "inversesqrt", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, + { "inversesqrt", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } }, //builtins - common { "abs", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "abs", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, @@ -1740,8 +1745,6 @@ const ShaderLanguage::BuiltinFuncDef ShaderLanguage::builtin_func_defs[] = { { "textureGrad", TYPE_UVEC4, { TYPE_USAMPLER2D, TYPE_VEC2, TYPE_VEC2, TYPE_VEC2, TYPE_VOID } }, { "textureGrad", TYPE_VEC4, { TYPE_SAMPLERCUBE, TYPE_VEC3, TYPE_VEC3, TYPE_VEC3, TYPE_VOID } }, - { "textureScreen", TYPE_VEC4, { TYPE_VEC2, TYPE_VOID } }, - { "dFdx", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } }, { "dFdx", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } }, { "dFdx", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } }, @@ -3800,6 +3803,10 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct func_node->return_type = type; func_node->return_precision = precision; + if (p_functions.has(name)) { + func_node->can_discard = p_functions[name].can_discard; + } + func_node->body = alloc_node<BlockNode>(); func_node->body->parent_function = func_node; diff --git a/servers/visual/shader_types.cpp b/servers/visual/shader_types.cpp index 91c5d430f5..7489ca7e3e 100644 --- a/servers/visual/shader_types.cpp +++ b/servers/visual/shader_types.cpp @@ -50,12 +50,6 @@ ShaderTypes::ShaderTypes() { /*************** SPATIAL ***********************/ - shader_modes[VS::SHADER_SPATIAL].functions["vertex"].built_ins["SRC_VERTEX"] = ShaderLanguage::TYPE_VEC3; - shader_modes[VS::SHADER_SPATIAL].functions["vertex"].built_ins["SRC_NORMAL"] = ShaderLanguage::TYPE_VEC3; - shader_modes[VS::SHADER_SPATIAL].functions["vertex"].built_ins["SRC_BONES"] = ShaderLanguage::TYPE_IVEC4; - shader_modes[VS::SHADER_SPATIAL].functions["vertex"].built_ins["SRC_WEIGHTS"] = ShaderLanguage::TYPE_VEC4; - - shader_modes[VS::SHADER_SPATIAL].functions["vertex"].built_ins["POSITION"] = ShaderLanguage::TYPE_VEC4; shader_modes[VS::SHADER_SPATIAL].functions["vertex"].built_ins["VERTEX"] = ShaderLanguage::TYPE_VEC3; shader_modes[VS::SHADER_SPATIAL].functions["vertex"].built_ins["NORMAL"] = ShaderLanguage::TYPE_VEC3; shader_modes[VS::SHADER_SPATIAL].functions["vertex"].built_ins["TANGENT"] = ShaderLanguage::TYPE_VEC3; @@ -75,6 +69,7 @@ ShaderTypes::ShaderTypes() { shader_modes[VS::SHADER_SPATIAL].functions["vertex"].built_ins["CAMERA_MATRIX"] = ShaderLanguage::TYPE_MAT4; shader_modes[VS::SHADER_SPATIAL].functions["vertex"].built_ins["PROJECTION_MATRIX"] = ShaderLanguage::TYPE_MAT4; shader_modes[VS::SHADER_SPATIAL].functions["vertex"].built_ins["MODELVIEW_MATRIX"] = ShaderLanguage::TYPE_MAT4; + shader_modes[VS::SHADER_SPATIAL].functions["vertex"].built_ins["INV_PROJECTION_MATRIX"] = ShaderLanguage::TYPE_MAT4; shader_modes[VS::SHADER_SPATIAL].functions["vertex"].built_ins["TIME"] = ShaderLanguage::TYPE_FLOAT; shader_modes[VS::SHADER_SPATIAL].functions["vertex"].built_ins["VIEWPORT_SIZE"] = ShaderLanguage::TYPE_VEC2; @@ -89,7 +84,6 @@ ShaderTypes::ShaderTypes() { shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["UV"] = ShaderLanguage::TYPE_VEC2; shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["UV2"] = ShaderLanguage::TYPE_VEC2; shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["COLOR"] = ShaderLanguage::TYPE_VEC4; - shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["NORMAL"] = ShaderLanguage::TYPE_VEC3; shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["ALBEDO"] = ShaderLanguage::TYPE_VEC3; shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["ALPHA"] = ShaderLanguage::TYPE_FLOAT; shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["METALLIC"] = ShaderLanguage::TYPE_FLOAT; @@ -104,6 +98,7 @@ ShaderTypes::ShaderTypes() { shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["SSS_STRENGTH"] = ShaderLanguage::TYPE_FLOAT; shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["TRANSMISSION"] = ShaderLanguage::TYPE_VEC3; shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["AO"] = ShaderLanguage::TYPE_FLOAT; + shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["AO_LIGHT_AFFECT"] = ShaderLanguage::TYPE_FLOAT; shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["EMISSION"] = ShaderLanguage::TYPE_VEC3; shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["SCREEN_TEXTURE"] = ShaderLanguage::TYPE_SAMPLER2D; shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["DEPTH_TEXTURE"] = ShaderLanguage::TYPE_SAMPLER2D; @@ -115,10 +110,31 @@ ShaderTypes::ShaderTypes() { shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["WORLD_MATRIX"] = ShaderLanguage::TYPE_MAT4; shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["INV_CAMERA_MATRIX"] = ShaderLanguage::TYPE_MAT4; shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["PROJECTION_MATRIX"] = ShaderLanguage::TYPE_MAT4; + shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["INV_PROJECTION_MATRIX"] = ShaderLanguage::TYPE_MAT4; shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["TIME"] = ShaderLanguage::TYPE_FLOAT; shader_modes[VS::SHADER_SPATIAL].functions["fragment"].built_ins["VIEWPORT_SIZE"] = ShaderLanguage::TYPE_VEC2; shader_modes[VS::SHADER_SPATIAL].functions["fragment"].can_discard = true; + shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["WORLD_MATRIX"] = ShaderLanguage::TYPE_MAT4; + shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["INV_CAMERA_MATRIX"] = ShaderLanguage::TYPE_MAT4; + shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["PROJECTION_MATRIX"] = ShaderLanguage::TYPE_MAT4; + shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["INV_PROJECTION_MATRIX"] = ShaderLanguage::TYPE_MAT4; + shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["TIME"] = ShaderLanguage::TYPE_FLOAT; + shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["VIEWPORT_SIZE"] = ShaderLanguage::TYPE_VEC2; + + shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["NORMAL"] = ShaderLanguage::TYPE_VEC3; + shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["VIEW"] = ShaderLanguage::TYPE_VEC3; + shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["LIGHT"] = ShaderLanguage::TYPE_VEC3; + shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["LIGHT_COLOR"] = ShaderLanguage::TYPE_VEC3; + shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["ATTENUATION"] = ShaderLanguage::TYPE_VEC3; + shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["ALBEDO"] = ShaderLanguage::TYPE_VEC3; + shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["TRANSMISSION"] = ShaderLanguage::TYPE_VEC3; + shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["ROUGHNESS"] = ShaderLanguage::TYPE_FLOAT; + shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["DIFFUSE_LIGHT"] = ShaderLanguage::TYPE_VEC3; + shader_modes[VS::SHADER_SPATIAL].functions["light"].built_ins["SPECULAR_LIGHT"] = ShaderLanguage::TYPE_VEC3; + + shader_modes[VS::SHADER_SPATIAL].functions["light"].can_discard = true; + shader_modes[VS::SHADER_SPATIAL].modes.insert("blend_mix"); shader_modes[VS::SHADER_SPATIAL].modes.insert("blend_add"); shader_modes[VS::SHADER_SPATIAL].modes.insert("blend_sub"); @@ -156,21 +172,19 @@ ShaderTypes::ShaderTypes() { /************ CANVAS ITEM **************************/ - shader_modes[VS::SHADER_CANVAS_ITEM].functions["vertex"].built_ins["SRC_VERTEX"] = ShaderLanguage::TYPE_VEC2; shader_modes[VS::SHADER_CANVAS_ITEM].functions["vertex"].built_ins["VERTEX"] = ShaderLanguage::TYPE_VEC2; shader_modes[VS::SHADER_CANVAS_ITEM].functions["vertex"].built_ins["UV"] = ShaderLanguage::TYPE_VEC2; - shader_modes[VS::SHADER_CANVAS_ITEM].functions["vertex"].built_ins["VERTEX_COLOR"] = ShaderLanguage::TYPE_VEC4; + shader_modes[VS::SHADER_CANVAS_ITEM].functions["vertex"].built_ins["COLOR"] = ShaderLanguage::TYPE_VEC4; shader_modes[VS::SHADER_CANVAS_ITEM].functions["vertex"].built_ins["POINT_SIZE"] = ShaderLanguage::TYPE_FLOAT; shader_modes[VS::SHADER_CANVAS_ITEM].functions["vertex"].built_ins["WORLD_MATRIX"] = ShaderLanguage::TYPE_MAT4; shader_modes[VS::SHADER_CANVAS_ITEM].functions["vertex"].built_ins["PROJECTION_MATRIX"] = ShaderLanguage::TYPE_MAT4; shader_modes[VS::SHADER_CANVAS_ITEM].functions["vertex"].built_ins["EXTRA_MATRIX"] = ShaderLanguage::TYPE_MAT4; shader_modes[VS::SHADER_CANVAS_ITEM].functions["vertex"].built_ins["TIME"] = ShaderLanguage::TYPE_FLOAT; - shader_modes[VS::SHADER_CANVAS_ITEM].functions["vertex"].built_ins["PARTICLE_CUSTOM"] = ShaderLanguage::TYPE_VEC4; + shader_modes[VS::SHADER_CANVAS_ITEM].functions["vertex"].built_ins["INSTANCE_CUSTOM"] = ShaderLanguage::TYPE_VEC4; shader_modes[VS::SHADER_CANVAS_ITEM].functions["vertex"].built_ins["AT_LIGHT_PASS"] = ShaderLanguage::TYPE_BOOL; shader_modes[VS::SHADER_CANVAS_ITEM].functions["vertex"].can_discard = false; - shader_modes[VS::SHADER_CANVAS_ITEM].functions["fragment"].built_ins["SRC_COLOR"] = ShaderLanguage::TYPE_VEC4; shader_modes[VS::SHADER_CANVAS_ITEM].functions["fragment"].built_ins["FRAGCOORD"] = ShaderLanguage::TYPE_VEC4; shader_modes[VS::SHADER_CANVAS_ITEM].functions["fragment"].built_ins["NORMAL"] = ShaderLanguage::TYPE_VEC3; shader_modes[VS::SHADER_CANVAS_ITEM].functions["fragment"].built_ins["NORMALMAP"] = ShaderLanguage::TYPE_VEC3; @@ -179,13 +193,13 @@ ShaderTypes::ShaderTypes() { shader_modes[VS::SHADER_CANVAS_ITEM].functions["fragment"].built_ins["COLOR"] = ShaderLanguage::TYPE_VEC4; shader_modes[VS::SHADER_CANVAS_ITEM].functions["fragment"].built_ins["TEXTURE"] = ShaderLanguage::TYPE_SAMPLER2D; shader_modes[VS::SHADER_CANVAS_ITEM].functions["fragment"].built_ins["TEXTURE_PIXEL_SIZE"] = ShaderLanguage::TYPE_VEC2; + shader_modes[VS::SHADER_CANVAS_ITEM].functions["fragment"].built_ins["NORMAL_TEXTURE"] = ShaderLanguage::TYPE_SAMPLER2D; shader_modes[VS::SHADER_CANVAS_ITEM].functions["fragment"].built_ins["SCREEN_UV"] = ShaderLanguage::TYPE_VEC2; shader_modes[VS::SHADER_CANVAS_ITEM].functions["fragment"].built_ins["SCREEN_PIXEL_SIZE"] = ShaderLanguage::TYPE_VEC2; shader_modes[VS::SHADER_CANVAS_ITEM].functions["fragment"].built_ins["POINT_COORD"] = ShaderLanguage::TYPE_VEC2; shader_modes[VS::SHADER_CANVAS_ITEM].functions["fragment"].built_ins["TIME"] = ShaderLanguage::TYPE_FLOAT; shader_modes[VS::SHADER_CANVAS_ITEM].functions["fragment"].built_ins["AT_LIGHT_PASS"] = ShaderLanguage::TYPE_BOOL; shader_modes[VS::SHADER_CANVAS_ITEM].functions["fragment"].built_ins["SCREEN_TEXTURE"] = ShaderLanguage::TYPE_SAMPLER2D; - shader_modes[VS::SHADER_CANVAS_ITEM].functions["fragment"].built_ins["SCREEN_UV"] = ShaderLanguage::TYPE_VEC2; shader_modes[VS::SHADER_CANVAS_ITEM].functions["fragment"].can_discard = true; shader_modes[VS::SHADER_CANVAS_ITEM].functions["light"].built_ins["POSITION"] = ShaderLanguage::TYPE_VEC2; diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index 7c7ce46268..888fb29f93 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -589,11 +589,29 @@ class VisualServerRaster : public VisualServer { #endif void _draw_margins(); + static void _changes_changed() {} public: +//if editor is redrawing when it shouldn't, enable this and put a breakpoint in _changes_changed() +//#define DEBUG_CHANGES + +#ifdef DEBUG_CHANGES + _FORCE_INLINE_ static void redraw_request() { + changes++; + _changes_changed(); + } + +#define DISPLAY_CHANGED \ + changes++; \ + _changes_changed(); + +#else _FORCE_INLINE_ static void redraw_request() { changes++; } -#define DISPLAY_CHANGED changes++; +#define DISPLAY_CHANGED \ + changes++; +#endif +// print_line(String("CHANGED: ") + __FUNCTION__); #define BIND0R(m_r, m_name) \ m_r m_name() { return BINDBASE->m_name(); } @@ -950,7 +968,7 @@ public: BIND2(environment_set_background, RID, EnvironmentBG) BIND2(environment_set_sky, RID, RID) - BIND2(environment_set_sky_scale, RID, float) + BIND2(environment_set_sky_custom_fov, RID, float) BIND2(environment_set_bg_color, RID, const Color &) BIND2(environment_set_bg_energy, RID, float) BIND2(environment_set_canvas_max_layer, RID, int) diff --git a/servers/visual/visual_server_scene.cpp b/servers/visual/visual_server_scene.cpp index 9fb4dc524d..e49baf0763 100644 --- a/servers/visual/visual_server_scene.cpp +++ b/servers/visual/visual_server_scene.cpp @@ -2348,7 +2348,7 @@ void VisualServerScene::_bake_gi_probe(Instance *p_gi_probe) { RID rid = E->key(); const InstanceGIProbeData::LightCache &lc = E->get(); - if (!probe_data->dynamic.light_cache_changes.has(rid) || !(probe_data->dynamic.light_cache_changes[rid] == lc)) { + if ((!probe_data->dynamic.light_cache_changes.has(rid) || !(probe_data->dynamic.light_cache_changes[rid] == lc)) && lc.visible) { //erase light data _bake_gi_probe_light(header, cells, local_data, leaves, leaf_count, lc, -1); @@ -2361,7 +2361,7 @@ void VisualServerScene::_bake_gi_probe(Instance *p_gi_probe) { RID rid = E->key(); const InstanceGIProbeData::LightCache &lc = E->get(); - if (!probe_data->dynamic.light_cache.has(rid) || !(probe_data->dynamic.light_cache[rid] == lc)) { + if ((!probe_data->dynamic.light_cache.has(rid) || !(probe_data->dynamic.light_cache[rid] == lc)) && lc.visible) { //add light data _bake_gi_probe_light(header, cells, local_data, leaves, leaf_count, lc, 1); @@ -2568,6 +2568,7 @@ bool VisualServerScene::_check_gi_probe(Instance *p_gi_probe) { lc.spot_angle = VSG::storage->light_get_param(E->get()->base, VS::LIGHT_PARAM_SPOT_ANGLE); lc.spot_attenuation = VSG::storage->light_get_param(E->get()->base, VS::LIGHT_PARAM_SPOT_ATTENUATION); lc.transform = probe_data->dynamic.light_to_cell_xform * E->get()->transform; + lc.visible = E->get()->visible; if (!probe_data->dynamic.light_cache.has(E->get()->self) || !(probe_data->dynamic.light_cache[E->get()->self] == lc)) { all_equal = false; @@ -2587,6 +2588,7 @@ bool VisualServerScene::_check_gi_probe(Instance *p_gi_probe) { lc.spot_angle = VSG::storage->light_get_param(E->get()->base, VS::LIGHT_PARAM_SPOT_ANGLE); lc.spot_attenuation = VSG::storage->light_get_param(E->get()->base, VS::LIGHT_PARAM_SPOT_ATTENUATION); lc.transform = probe_data->dynamic.light_to_cell_xform * E->get()->transform; + lc.visible = E->get()->visible; if (!probe_data->dynamic.light_cache.has(E->get()->self) || !(probe_data->dynamic.light_cache[E->get()->self] == lc)) { all_equal = false; diff --git a/servers/visual/visual_server_scene.h b/servers/visual/visual_server_scene.h index ac771030cf..d30a2108a5 100644 --- a/servers/visual/visual_server_scene.h +++ b/servers/visual/visual_server_scene.h @@ -359,6 +359,7 @@ public: float attenuation; float spot_angle; float spot_attenuation; + bool visible; bool operator==(const LightCache &p_cache) { @@ -369,7 +370,8 @@ public: radius == p_cache.radius && attenuation == p_cache.attenuation && spot_angle == p_cache.spot_angle && - spot_attenuation == p_cache.spot_attenuation); + spot_attenuation == p_cache.spot_attenuation && + visible == p_cache.visible); } LightCache() { @@ -380,6 +382,7 @@ public: attenuation = 1.0; spot_angle = 1.0; spot_attenuation = 1.0; + visible = true; } }; diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h index 5cf941b93d..caec890217 100644 --- a/servers/visual/visual_server_wrap_mt.h +++ b/servers/visual/visual_server_wrap_mt.h @@ -381,7 +381,7 @@ public: FUNC2(environment_set_background, RID, EnvironmentBG) FUNC2(environment_set_sky, RID, RID) - FUNC2(environment_set_sky_scale, RID, float) + FUNC2(environment_set_sky_custom_fov, RID, float) FUNC2(environment_set_bg_color, RID, const Color &) FUNC2(environment_set_bg_energy, RID, float) FUNC2(environment_set_canvas_max_layer, RID, int) diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp index 47a5f4c7f3..979b2ed8ec 100644 --- a/servers/visual_server.cpp +++ b/servers/visual_server.cpp @@ -1445,7 +1445,9 @@ Array VisualServer::mesh_surface_get_blend_shape_arrays(RID p_mesh, int p_surfac void VisualServer::_bind_methods() { + ClassDB::bind_method(D_METHOD("force_sync"), &VisualServer::sync); ClassDB::bind_method(D_METHOD("force_draw"), &VisualServer::draw); + ClassDB::bind_method(D_METHOD("request_frame_drawn_callback", "where", "method", "userdata"), &VisualServer::request_frame_drawn_callback); ClassDB::bind_method(D_METHOD("texture_create"), &VisualServer::texture_create); ClassDB::bind_method(D_METHOD("texture_create_from_image", "image", "flags"), &VisualServer::texture_create_from_image, DEFVAL(TEXTURE_FLAGS_DEFAULT)); //ClassDB::bind_method(D_METHOD("texture_allocate"),&VisualServer::texture_allocate,DEFVAL( TEXTURE_FLAGS_DEFAULT ) ); diff --git a/servers/visual_server.h b/servers/visual_server.h index 72f36f6b65..1cc097f50e 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -85,7 +85,7 @@ public: enum TextureFlags { TEXTURE_FLAG_MIPMAPS = 1, /// Enable automatic mipmap generation - when available TEXTURE_FLAG_REPEAT = 2, /// Repeat texture (Tiling), otherwise Clamping - TEXTURE_FLAG_FILTER = 4, /// Create texure with linear (or available) filter + TEXTURE_FLAG_FILTER = 4, /// Create texture with linear (or available) filter TEXTURE_FLAG_ANISOTROPIC_FILTER = 8, TEXTURE_FLAG_CONVERT_TO_LINEAR = 16, TEXTURE_FLAG_MIRRORED_REPEAT = 32, /// Repeat texture, with alternate sections mirrored @@ -637,7 +637,7 @@ public: virtual void environment_set_background(RID p_env, EnvironmentBG p_bg) = 0; virtual void environment_set_sky(RID p_env, RID p_sky) = 0; - virtual void environment_set_sky_scale(RID p_env, float p_scale) = 0; + virtual void environment_set_sky_custom_fov(RID p_env, float p_scale) = 0; virtual void environment_set_bg_color(RID p_env, const Color &p_color) = 0; virtual void environment_set_bg_energy(RID p_env, float p_energy) = 0; virtual void environment_set_canvas_max_layer(RID p_env, int p_max_layer) = 0; |