diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/basis_universal/register_types.cpp | 11 | ||||
-rw-r--r-- | modules/gdnavigation/gd_navigation_server.cpp | 36 | ||||
-rw-r--r-- | modules/gdnavigation/gd_navigation_server.h | 5 | ||||
-rw-r--r-- | modules/gdnavigation/nav_map.cpp | 138 | ||||
-rw-r--r-- | modules/gdnavigation/nav_map.h | 4 | ||||
-rw-r--r-- | modules/gdscript/gdscript.cpp | 1 | ||||
-rw-r--r-- | modules/gdscript/gdscript.h | 1 | ||||
-rw-r--r-- | modules/gdscript/gdscript_function.cpp | 15 | ||||
-rw-r--r-- | modules/gdscript/gdscript_function.h | 2 | ||||
-rw-r--r-- | modules/glslang/SCsub | 6 |
10 files changed, 196 insertions, 23 deletions
diff --git a/modules/basis_universal/register_types.cpp b/modules/basis_universal/register_types.cpp index 13f4d5fc48..062b5b59f8 100644 --- a/modules/basis_universal/register_types.cpp +++ b/modules/basis_universal/register_types.cpp @@ -52,12 +52,11 @@ enum BasisDecompressFormat { basist::etc1_global_selector_codebook *sel_codebook = nullptr; +#ifdef TOOLS_ENABLED static Vector<uint8_t> basis_universal_packer(const Ref<Image> &p_image, Image::UsedChannels p_channels) { Vector<uint8_t> budata; -#ifdef TOOLS_ENABLED - { Ref<Image> image = p_image->duplicate(); @@ -117,14 +116,10 @@ static Vector<uint8_t> basis_universal_packer(const Ref<Image> &p_image, Image:: #ifdef USE_RG_AS_RGBA image->convert_rg_to_ra_rgba8(); decompress_format = BASIS_DECOMPRESS_RG_AS_RA; - #else - params.m_seperate_rg_to_color_alpha = true; decompress_format = BASIS_DECOMPRESS_RG; - #endif - } break; case Image::USED_CHANNELS_RGB: { decompress_format = BASIS_DECOMPRESS_RGB; @@ -152,9 +147,9 @@ static Vector<uint8_t> basis_universal_packer(const Ref<Image> &p_image, Image:: } } -#endif return budata; } +#endif // TOOLS_ENABLED static Ref<Image> basis_universal_unpacker(const Vector<uint8_t> &p_buffer) { Ref<Image> image; @@ -286,7 +281,7 @@ void unregister_basis_universal_types() { #ifdef TOOLS_ENABLED delete sel_codebook; -#endif Image::basis_universal_packer = NULL; +#endif Image::basis_universal_unpacker = NULL; } diff --git a/modules/gdnavigation/gd_navigation_server.cpp b/modules/gdnavigation/gd_navigation_server.cpp index 5bafa5507c..1f1783802d 100644 --- a/modules/gdnavigation/gd_navigation_server.cpp +++ b/modules/gdnavigation/gd_navigation_server.cpp @@ -170,7 +170,7 @@ COMMAND_2(map_set_up, RID, p_map, Vector3, p_up) { } Vector3 GdNavigationServer::map_get_up(RID p_map) const { - NavMap *map = map_owner.getornull(p_map); + const NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND_V(map == NULL, Vector3()); return map->get_up(); @@ -184,7 +184,7 @@ COMMAND_2(map_set_cell_size, RID, p_map, real_t, p_cell_size) { } real_t GdNavigationServer::map_get_cell_size(RID p_map) const { - NavMap *map = map_owner.getornull(p_map); + const NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND_V(map == NULL, 0); return map->get_cell_size(); @@ -198,19 +198,47 @@ COMMAND_2(map_set_edge_connection_margin, RID, p_map, real_t, p_connection_margi } real_t GdNavigationServer::map_get_edge_connection_margin(RID p_map) const { - NavMap *map = map_owner.getornull(p_map); + const NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND_V(map == NULL, 0); return map->get_edge_connection_margin(); } Vector<Vector3> GdNavigationServer::map_get_path(RID p_map, Vector3 p_origin, Vector3 p_destination, bool p_optimize) const { - NavMap *map = map_owner.getornull(p_map); + const NavMap *map = map_owner.getornull(p_map); ERR_FAIL_COND_V(map == NULL, Vector<Vector3>()); return map->get_path(p_origin, p_destination, p_optimize); } +Vector3 GdNavigationServer::map_get_closest_point_to_segment(RID p_map, const Vector3 &p_from, const Vector3 &p_to, const bool p_use_collision) const { + const NavMap *map = map_owner.getornull(p_map); + ERR_FAIL_COND_V(map == NULL, Vector3()); + + return map->get_closest_point_to_segment(p_from, p_to, p_use_collision); +} + +Vector3 GdNavigationServer::map_get_closest_point(RID p_map, const Vector3 &p_point) const { + const NavMap *map = map_owner.getornull(p_map); + ERR_FAIL_COND_V(map == NULL, Vector3()); + + return map->get_closest_point(p_point); +} + +Vector3 GdNavigationServer::map_get_closest_point_normal(RID p_map, const Vector3 &p_point) const { + const NavMap *map = map_owner.getornull(p_map); + ERR_FAIL_COND_V(map == NULL, Vector3()); + + return map->get_closest_point_normal(p_point); +} + +RID GdNavigationServer::map_get_closest_point_owner(RID p_map, const Vector3 &p_point) const { + const NavMap *map = map_owner.getornull(p_map); + ERR_FAIL_COND_V(map == NULL, RID()); + + return map->get_closest_point_owner(p_point); +} + RID GdNavigationServer::region_create() const { auto mut_this = const_cast<GdNavigationServer *>(this); mut_this->operations_mutex->lock(); diff --git a/modules/gdnavigation/gd_navigation_server.h b/modules/gdnavigation/gd_navigation_server.h index 564e9870a0..7fa5979c31 100644 --- a/modules/gdnavigation/gd_navigation_server.h +++ b/modules/gdnavigation/gd_navigation_server.h @@ -103,6 +103,11 @@ public: virtual Vector<Vector3> map_get_path(RID p_map, Vector3 p_origin, Vector3 p_destination, bool p_optimize) const; + virtual Vector3 map_get_closest_point_to_segment(RID p_map, const Vector3 &p_from, const Vector3 &p_to, const bool p_use_collision = false) const; + virtual Vector3 map_get_closest_point(RID p_map, const Vector3 &p_point) const; + virtual Vector3 map_get_closest_point_normal(RID p_map, const Vector3 &p_point) const; + virtual RID map_get_closest_point_owner(RID p_map, const Vector3 &p_point) const; + virtual RID region_create() const; COMMAND_2(region_set_map, RID, p_region, RID, p_map); COMMAND_2(region_set_transform, RID, p_region, Transform, p_transform); diff --git a/modules/gdnavigation/nav_map.cpp b/modules/gdnavigation/nav_map.cpp index d1765f4da9..d3e2f8f388 100644 --- a/modules/gdnavigation/nav_map.cpp +++ b/modules/gdnavigation/nav_map.cpp @@ -401,6 +401,144 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p return Vector<Vector3>(); } +Vector3 NavMap::get_closest_point_to_segment(const Vector3 &p_from, const Vector3 &p_to, const bool p_use_collision) const { + + bool use_collision = p_use_collision; + Vector3 closest_point; + real_t closest_point_d = 1e20; + + // Find the initial poly and the end poly on this map. + for (size_t i(0); i < polygons.size(); i++) { + const gd::Polygon &p = polygons[i]; + + // For each point cast a face and check the distance to the segment + for (size_t point_id = 2; point_id < p.points.size(); point_id += 1) { + + const Face3 f(p.points[point_id - 2].pos, p.points[point_id - 1].pos, p.points[point_id].pos); + Vector3 inters; + if (f.intersects_segment(p_from, p_to, &inters)) { + const real_t d = closest_point_d = p_from.distance_to(inters); + if (use_collision == false) { + closest_point = inters; + use_collision = true; + closest_point_d = d; + } else if (closest_point_d > d) { + + closest_point = inters; + closest_point_d = d; + } + } + } + + if (use_collision == false) { + + for (size_t point_id = 0; point_id < p.points.size(); point_id += 1) { + + Vector3 a, b; + + Geometry::get_closest_points_between_segments( + p_from, + p_to, + p.points[point_id].pos, + p.points[(point_id + 1) % p.points.size()].pos, + a, + b); + + const real_t d = a.distance_to(b); + if (d < closest_point_d) { + + closest_point_d = d; + closest_point = b; + } + } + } + } + + return closest_point; +} + +Vector3 NavMap::get_closest_point(const Vector3 &p_point) const { + // TODO this is really not optimal, please redesign the API to directly return all this data + + Vector3 closest_point; + real_t closest_point_d = 1e20; + + // Find the initial poly and the end poly on this map. + for (size_t i(0); i < polygons.size(); i++) { + const gd::Polygon &p = polygons[i]; + + // For each point cast a face and check the distance to the point + for (size_t point_id = 2; point_id < p.points.size(); point_id += 1) { + + const Face3 f(p.points[point_id - 2].pos, p.points[point_id - 1].pos, p.points[point_id].pos); + const Vector3 inters = f.get_closest_point_to(p_point); + const real_t d = inters.distance_to(p_point); + if (d < closest_point_d) { + closest_point = inters; + closest_point_d = d; + } + } + } + + return closest_point; +} + +Vector3 NavMap::get_closest_point_normal(const Vector3 &p_point) const { + // TODO this is really not optimal, please redesign the API to directly return all this data + + Vector3 closest_point; + Vector3 closest_point_normal; + real_t closest_point_d = 1e20; + + // Find the initial poly and the end poly on this map. + for (size_t i(0); i < polygons.size(); i++) { + const gd::Polygon &p = polygons[i]; + + // For each point cast a face and check the distance to the point + for (size_t point_id = 2; point_id < p.points.size(); point_id += 1) { + + const Face3 f(p.points[point_id - 2].pos, p.points[point_id - 1].pos, p.points[point_id].pos); + const Vector3 inters = f.get_closest_point_to(p_point); + const real_t d = inters.distance_to(p_point); + if (d < closest_point_d) { + closest_point = inters; + closest_point_normal = f.get_plane().normal; + closest_point_d = d; + } + } + } + + return closest_point_normal; +} + +RID NavMap::get_closest_point_owner(const Vector3 &p_point) const { + // TODO this is really not optimal, please redesign the API to directly return all this data + + Vector3 closest_point; + RID closest_point_owner; + real_t closest_point_d = 1e20; + + // Find the initial poly and the end poly on this map. + for (size_t i(0); i < polygons.size(); i++) { + const gd::Polygon &p = polygons[i]; + + // For each point cast a face and check the distance to the point + for (size_t point_id = 2; point_id < p.points.size(); point_id += 1) { + + const Face3 f(p.points[point_id - 2].pos, p.points[point_id - 1].pos, p.points[point_id].pos); + const Vector3 inters = f.get_closest_point_to(p_point); + const real_t d = inters.distance_to(p_point); + if (d < closest_point_d) { + closest_point = inters; + closest_point_owner = p.owner->get_self(); + closest_point_d = d; + } + } + } + + return closest_point_owner; +} + void NavMap::add_region(NavRegion *p_region) { regions.push_back(p_region); regenerate_links = true; diff --git a/modules/gdnavigation/nav_map.h b/modules/gdnavigation/nav_map.h index 128a82580c..4543f00926 100644 --- a/modules/gdnavigation/nav_map.h +++ b/modules/gdnavigation/nav_map.h @@ -104,6 +104,10 @@ public: gd::PointKey get_point_key(const Vector3 &p_pos) const; Vector<Vector3> get_path(Vector3 p_origin, Vector3 p_destination, bool p_optimize) const; + Vector3 get_closest_point_to_segment(const Vector3 &p_from, const Vector3 &p_to, const bool p_use_collision) const; + Vector3 get_closest_point(const Vector3 &p_point) const; + Vector3 get_closest_point_normal(const Vector3 &p_point) const; + RID get_closest_point_owner(const Vector3 &p_point) const; void add_region(NavRegion *p_region); void remove_region(NavRegion *p_region); diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index a73276dda2..6d926fb88d 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -995,7 +995,6 @@ void GDScript::get_script_signal_list(List<MethodInfo> *r_signals) const { GDScript::GDScript() : script_list(this) { - _static_ref = this; valid = false; subclass_count = 0; initializer = NULL; diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h index 103de3304e..3e60028281 100644 --- a/modules/gdscript/gdscript.h +++ b/modules/gdscript/gdscript.h @@ -73,7 +73,6 @@ class GDScript : public Script { friend class GDScriptFunctions; friend class GDScriptLanguage; - Variant _static_ref; //used for static call Ref<GDScriptNativeClass> native; Ref<GDScript> base; GDScript *_base; //fast pointer access diff --git a/modules/gdscript/gdscript_function.cpp b/modules/gdscript/gdscript_function.cpp index cbf7d81a61..1931d5f160 100644 --- a/modules/gdscript/gdscript_function.cpp +++ b/modules/gdscript/gdscript_function.cpp @@ -34,7 +34,7 @@ #include "gdscript.h" #include "gdscript_functions.h" -Variant *GDScriptFunction::_get_variant(int p_address, GDScriptInstance *p_instance, GDScript *p_script, Variant &self, Variant *p_stack, String &r_error) const { +Variant *GDScriptFunction::_get_variant(int p_address, GDScriptInstance *p_instance, GDScript *p_script, Variant &self, Variant &static_ref, Variant *p_stack, String &r_error) const { int address = p_address & ADDR_MASK; @@ -52,7 +52,7 @@ Variant *GDScriptFunction::_get_variant(int p_address, GDScriptInstance *p_insta } break; case ADDR_TYPE_CLASS: { - return &p_script->_static_ref; + return &static_ref; } break; case ADDR_TYPE_MEMBER: { #ifdef DEBUG_ENABLED @@ -270,6 +270,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a r_err.error = Variant::CallError::CALL_OK; Variant self; + Variant static_ref; Variant retvalue; Variant *stack = NULL; Variant **call_args; @@ -404,10 +405,10 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a #define CHECK_SPACE(m_space) \ GD_ERR_BREAK((ip + m_space) > _code_size) -#define GET_VARIANT_PTR(m_v, m_code_ofs) \ - Variant *m_v; \ - m_v = _get_variant(_code_ptr[ip + m_code_ofs], p_instance, script, self, stack, err_text); \ - if (unlikely(!m_v)) \ +#define GET_VARIANT_PTR(m_v, m_code_ofs) \ + Variant *m_v; \ + m_v = _get_variant(_code_ptr[ip + m_code_ofs], p_instance, script, self, static_ref, stack, err_text); \ + if (unlikely(!m_v)) \ OPCODE_BREAK; #else @@ -415,7 +416,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a #define CHECK_SPACE(m_space) #define GET_VARIANT_PTR(m_v, m_code_ofs) \ Variant *m_v; \ - m_v = _get_variant(_code_ptr[ip + m_code_ofs], p_instance, script, self, stack, err_text); + m_v = _get_variant(_code_ptr[ip + m_code_ofs], p_instance, script, self, static_ref, stack, err_text); #endif diff --git a/modules/gdscript/gdscript_function.h b/modules/gdscript/gdscript_function.h index 7b7bcbaac9..2c432360ba 100644 --- a/modules/gdscript/gdscript_function.h +++ b/modules/gdscript/gdscript_function.h @@ -265,7 +265,7 @@ private: List<StackDebug> stack_debug; - _FORCE_INLINE_ Variant *_get_variant(int p_address, GDScriptInstance *p_instance, GDScript *p_script, Variant &self, Variant *p_stack, String &r_error) const; + _FORCE_INLINE_ Variant *_get_variant(int p_address, GDScriptInstance *p_instance, GDScript *p_script, Variant &self, Variant &static_ref, Variant *p_stack, String &r_error) const; _FORCE_INLINE_ String _get_call_error(const Variant::CallError &p_err, const String &p_where, const Variant **argptrs) const; friend class GDScriptLanguage; diff --git a/modules/glslang/SCsub b/modules/glslang/SCsub index 8c9445436e..ae102238f2 100644 --- a/modules/glslang/SCsub +++ b/modules/glslang/SCsub @@ -58,7 +58,11 @@ if env['builtin_glslang']: thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] - env_glslang.Prepend(CPPPATH=[thirdparty_dir]) + # Treat glslang headers as system headers to avoid raising warnings. Not supported on MSVC. + if not env.msvc: + env_glslang.Append(CPPFLAGS=['-isystem', Dir(thirdparty_dir).path]) + else: + env_glslang.Prepend(CPPPATH=[thirdparty_dir]) env_thirdparty = env_glslang.Clone() env_thirdparty.disable_warnings() |