diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/bind/core_bind.cpp | 12 | ||||
| -rw-r--r-- | core/bind/core_bind.h | 2 | ||||
| -rw-r--r-- | core/dictionary.cpp | 103 | ||||
| -rw-r--r-- | core/global_constants.cpp | 2 | ||||
| -rw-r--r-- | core/io/config_file.cpp | 10 | ||||
| -rw-r--r-- | core/io/config_file.h | 2 | ||||
| -rw-r--r-- | core/math/a_star.cpp | 17 | ||||
| -rw-r--r-- | core/math/a_star.h | 1 | ||||
| -rw-r--r-- | core/math/math_funcs.h | 2 | ||||
| -rw-r--r-- | core/ordered_hash_map.h | 40 | ||||
| -rw-r--r-- | core/os/input_event.h | 4 | ||||
| -rw-r--r-- | core/os/os.h | 2 | ||||
| -rw-r--r-- | core/translation.cpp | 4 | ||||
| -rw-r--r-- | core/variant_call.cpp | 2 |
14 files changed, 94 insertions, 109 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 12b892d87..c369f4bff 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -1316,6 +1316,16 @@ Vector<int> _Geometry::triangulate_polygon(const Vector<Vector2> &p_polygon) { return Geometry::triangulate_polygon(p_polygon); } +Vector<Point2> _Geometry::convex_hull_2d(const Vector<Point2> &p_points) { + + return Geometry::convex_hull_2d(p_points); +} + +Vector<Vector3> _Geometry::clip_polygon(const Vector<Vector3> &p_points, const Plane &p_plane) { + + return Geometry::clip_polygon(p_points, p_plane); +} + Dictionary _Geometry::make_atlas(const Vector<Size2> &p_rects) { Dictionary ret; @@ -1376,6 +1386,8 @@ void _Geometry::_bind_methods() { ClassDB::bind_method(D_METHOD("point_is_inside_triangle", "point", "a", "b", "c"), &_Geometry::point_is_inside_triangle); ClassDB::bind_method(D_METHOD("triangulate_polygon", "polygon"), &_Geometry::triangulate_polygon); + ClassDB::bind_method(D_METHOD("convex_hull_2d", "points"), &_Geometry::convex_hull_2d); + ClassDB::bind_method(D_METHOD("clip_polygon", "points", "plane"), &_Geometry::clip_polygon); ClassDB::bind_method(D_METHOD("make_atlas", "sizes"), &_Geometry::make_atlas); } diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h index 7f8c734e3..bbbb40d92 100644 --- a/core/bind/core_bind.h +++ b/core/bind/core_bind.h @@ -363,6 +363,8 @@ public: int get_uv84_normal_bit(const Vector3 &p_vector); Vector<int> triangulate_polygon(const Vector<Vector2> &p_polygon); + Vector<Point2> convex_hull_2d(const Vector<Point2> &p_points); + Vector<Vector3> clip_polygon(const Vector<Vector3> &p_points, const Plane &p_plane); Dictionary make_atlas(const Vector<Size2> &p_rects); diff --git a/core/dictionary.cpp b/core/dictionary.cpp index bb2e89295..48e65c734 100644 --- a/core/dictionary.cpp +++ b/core/dictionary.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "dictionary.h" +#include "ordered_hash_map.h" #include "safe_refcount.h" #include "variant.h" @@ -39,22 +40,8 @@ struct _DictionaryVariantHash { struct DictionaryPrivate { - struct Data { - Variant variant; - int order; - }; - SafeRefCount refcount; - HashMap<Variant, Data, _DictionaryVariantHash> variant_map; - int counter; -}; - -struct DictionaryPrivateSort { - - bool operator()(const HashMap<Variant, DictionaryPrivate::Data, _DictionaryVariantHash>::Pair *A, const HashMap<Variant, DictionaryPrivate::Data, _DictionaryVariantHash>::Pair *B) const { - - return A->data.order < B->data.order; - } + OrderedHashMap<Variant, Variant, _DictionaryVariantHash> variant_map; }; void Dictionary::get_key_list(List<Variant> *p_keys) const { @@ -62,61 +49,45 @@ void Dictionary::get_key_list(List<Variant> *p_keys) const { if (_p->variant_map.empty()) return; - int count = _p->variant_map.size(); - const HashMap<Variant, DictionaryPrivate::Data, _DictionaryVariantHash>::Pair **pairs = (const HashMap<Variant, DictionaryPrivate::Data, _DictionaryVariantHash>::Pair **)alloca(count * sizeof(HashMap<Variant, DictionaryPrivate::Data, _DictionaryVariantHash>::Pair *)); - _p->variant_map.get_key_value_ptr_array(pairs); - - SortArray<const HashMap<Variant, DictionaryPrivate::Data, _DictionaryVariantHash>::Pair *, DictionaryPrivateSort> sort; - sort.sort(pairs, count); - - for (int i = 0; i < count; i++) { - p_keys->push_back(pairs[i]->key); + for (OrderedHashMap<Variant, Variant, _DictionaryVariantHash>::Element E = _p->variant_map.front(); E; E = E.next()) { + p_keys->push_back(E.key()); } } Variant &Dictionary::operator[](const Variant &p_key) { - DictionaryPrivate::Data *v = _p->variant_map.getptr(p_key); - - if (!v) { - - DictionaryPrivate::Data d; - d.order = _p->counter++; - _p->variant_map[p_key] = d; - v = _p->variant_map.getptr(p_key); - } - return v->variant; + return _p->variant_map[p_key]; } const Variant &Dictionary::operator[](const Variant &p_key) const { - return _p->variant_map[p_key].variant; + return _p->variant_map[p_key]; } const Variant *Dictionary::getptr(const Variant &p_key) const { - const DictionaryPrivate::Data *v = _p->variant_map.getptr(p_key); - if (!v) + OrderedHashMap<Variant, Variant, _DictionaryVariantHash>::ConstElement E = ((const OrderedHashMap<Variant, Variant, _DictionaryVariantHash> *)&_p->variant_map)->find(p_key); + + if (!E) return NULL; - else - return &v->variant; + return &E.get(); } Variant *Dictionary::getptr(const Variant &p_key) { - DictionaryPrivate::Data *v = _p->variant_map.getptr(p_key); - if (!v) + OrderedHashMap<Variant, Variant, _DictionaryVariantHash>::Element E = _p->variant_map.find(p_key); + + if (!E) return NULL; - else - return &v->variant; + return &E.get(); } Variant Dictionary::get_valid(const Variant &p_key) const { - DictionaryPrivate::Data *v = _p->variant_map.getptr(p_key); - if (!v) + OrderedHashMap<Variant, Variant, _DictionaryVariantHash>::ConstElement E = ((const OrderedHashMap<Variant, Variant, _DictionaryVariantHash> *)&_p->variant_map)->find(p_key); + + if (!E) return Variant(); - else - return v->variant; + return E.get(); } int Dictionary::size() const { @@ -171,7 +142,6 @@ void Dictionary::_ref(const Dictionary &p_from) const { void Dictionary::clear() { _p->variant_map.clear(); - _p->counter = 0; } void Dictionary::_unref() const { @@ -205,15 +175,10 @@ Array Dictionary::keys() const { if (_p->variant_map.empty()) return varr; - int count = _p->variant_map.size(); - const HashMap<Variant, DictionaryPrivate::Data, _DictionaryVariantHash>::Pair **pairs = (const HashMap<Variant, DictionaryPrivate::Data, _DictionaryVariantHash>::Pair **)alloca(count * sizeof(HashMap<Variant, DictionaryPrivate::Data, _DictionaryVariantHash>::Pair *)); - _p->variant_map.get_key_value_ptr_array(pairs); - - SortArray<const HashMap<Variant, DictionaryPrivate::Data, _DictionaryVariantHash>::Pair *, DictionaryPrivateSort> sort; - sort.sort(pairs, count); - - for (int i = 0; i < count; i++) { - varr[i] = pairs[i]->key; + int i = 0; + for (OrderedHashMap<Variant, Variant, _DictionaryVariantHash>::Element E = _p->variant_map.front(); E; E = E.next()) { + varr[i] = E.key(); + i++; } return varr; @@ -226,15 +191,10 @@ Array Dictionary::values() const { if (_p->variant_map.empty()) return varr; - int count = _p->variant_map.size(); - const HashMap<Variant, DictionaryPrivate::Data, _DictionaryVariantHash>::Pair **pairs = (const HashMap<Variant, DictionaryPrivate::Data, _DictionaryVariantHash>::Pair **)alloca(count * sizeof(HashMap<Variant, DictionaryPrivate::Data, _DictionaryVariantHash>::Pair *)); - _p->variant_map.get_key_value_ptr_array(pairs); - - SortArray<const HashMap<Variant, DictionaryPrivate::Data, _DictionaryVariantHash>::Pair *, DictionaryPrivateSort> sort; - sort.sort(pairs, count); - - for (int i = 0; i < count; i++) { - varr[i] = pairs[i]->data.variant; + int i = 0; + for (OrderedHashMap<Variant, Variant, _DictionaryVariantHash>::Element E = _p->variant_map.front(); E; E = E.next()) { + varr[i] = E.get(); + i++; } return varr; @@ -242,7 +202,15 @@ Array Dictionary::values() const { const Variant *Dictionary::next(const Variant *p_key) const { - return _p->variant_map.next(p_key); + if (p_key == NULL) { + // caller wants to get the first element + return &_p->variant_map.front().key(); + } + OrderedHashMap<Variant, Variant, _DictionaryVariantHash>::Element E = _p->variant_map.find(*p_key); + + if (E && E.next()) + return &E.next().key(); + return NULL; } Dictionary Dictionary::copy() const { @@ -273,7 +241,6 @@ Dictionary::Dictionary() { _p = memnew(DictionaryPrivate); _p->refcount.init(); - _p->counter = 0; } Dictionary::~Dictionary() { diff --git a/core/global_constants.cpp b/core/global_constants.cpp index 8bddeae69..7854f342b 100644 --- a/core/global_constants.cpp +++ b/core/global_constants.cpp @@ -435,6 +435,8 @@ void register_global_constants() { BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_5); BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_6); BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_7); + BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_8); + BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_9); BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_MAX); BIND_GLOBAL_ENUM_CONSTANT(JOY_ANALOG_LX); diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp index b5d41bacb..2b6015083 100644 --- a/core/io/config_file.cpp +++ b/core/io/config_file.cpp @@ -106,8 +106,8 @@ bool ConfigFile::has_section_key(const String &p_section, const String &p_key) c void ConfigFile::get_sections(List<String> *r_sections) const { - for (const Map<String, OrderedHashMap<String, Variant> >::Element *E = values.front(); E; E = E->next()) { - r_sections->push_back(E->key()); + for (OrderedHashMap<String, OrderedHashMap<String, Variant> >::ConstElement E = values.front(); E; E = E.next()) { + r_sections->push_back(E.key()); } } void ConfigFile::get_section_keys(const String &p_section, List<String> *r_keys) const { @@ -135,13 +135,13 @@ Error ConfigFile::save(const String &p_path) { return err; } - for (Map<String, OrderedHashMap<String, Variant> >::Element *E = values.front(); E; E = E->next()) { + for (OrderedHashMap<String, OrderedHashMap<String, Variant> >::Element E = values.front(); E; E = E.next()) { if (E != values.front()) file->store_string("\n"); - file->store_string("[" + E->key() + "]\n\n"); + file->store_string("[" + E.key() + "]\n\n"); - for (OrderedHashMap<String, Variant>::Element F = E->get().front(); F; F = F.next()) { + for (OrderedHashMap<String, Variant>::Element F = E.get().front(); F; F = F.next()) { String vstr; VariantWriter::write_to_string(F.get(), vstr); diff --git a/core/io/config_file.h b/core/io/config_file.h index 2be196faa..29bd369a2 100644 --- a/core/io/config_file.h +++ b/core/io/config_file.h @@ -37,7 +37,7 @@ class ConfigFile : public Reference { GDCLASS(ConfigFile, Reference); - Map<String, OrderedHashMap<String, Variant> > values; + OrderedHashMap<String, OrderedHashMap<String, Variant> > values; PoolStringArray _get_sections() const; PoolStringArray _get_section_keys(const String &p_section) const; diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp index f43af4975..7e26761ab 100644 --- a/core/math/a_star.cpp +++ b/core/math/a_star.cpp @@ -159,6 +159,21 @@ Array AStar::get_points() { return point_list; } +PoolVector<int> AStar::get_point_connections(int p_id) { + + ERR_FAIL_COND_V(!points.has(p_id), PoolVector<int>()); + + PoolVector<int> point_list; + + Point *p = points[p_id]; + + for (int i = 0; i < p->neighbours.size(); i++) { + point_list.push_back(p->neighbours[i]->id); + } + + return point_list; +} + bool AStar::are_points_connected(int p_id, int p_with_id) const { Segment s(p_id, p_with_id); @@ -444,6 +459,8 @@ void AStar::_bind_methods() { ClassDB::bind_method(D_METHOD("has_point", "id"), &AStar::has_point); ClassDB::bind_method(D_METHOD("get_points"), &AStar::get_points); + ClassDB::bind_method(D_METHOD("get_point_connections"), &AStar::get_point_connections); + ClassDB::bind_method(D_METHOD("connect_points", "id", "to_id", "bidirectional"), &AStar::connect_points, DEFVAL(true)); ClassDB::bind_method(D_METHOD("disconnect_points", "id", "to_id"), &AStar::disconnect_points); ClassDB::bind_method(D_METHOD("are_points_connected", "id", "to_id"), &AStar::are_points_connected); diff --git a/core/math/a_star.h b/core/math/a_star.h index 23773e82e..b7b7e5412 100644 --- a/core/math/a_star.h +++ b/core/math/a_star.h @@ -109,6 +109,7 @@ public: void set_point_weight_scale(int p_id, real_t p_weight_scale); void remove_point(int p_id); bool has_point(int p_id) const; + PoolVector<int> get_point_connections(int p_id); Array get_points(); void connect_points(int p_id, int p_with_id, bool bidirectional = true); diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 7715e5d6e..d5135fe41 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -271,7 +271,7 @@ public: #elif defined(_MSC_VER) && _MSC_VER < 1800 __asm fld a __asm fistp b - /*#elif defined( __GNUC__ ) && ( defined( __i386__ ) || defined( __x86_64__ ) ) +/*#elif defined( __GNUC__ ) && ( defined( __i386__ ) || defined( __x86_64__ ) ) // use AT&T inline assembly style, document that // we use memory as output (=m) and input (m) __asm__ __volatile__ ( diff --git a/core/ordered_hash_map.h b/core/ordered_hash_map.h index 62eeedb43..1ed5a5d36 100644 --- a/core/ordered_hash_map.h +++ b/core/ordered_hash_map.h @@ -93,8 +93,12 @@ public: return *this; } - friend bool operator==(const Element &, const Element &); - friend bool operator!=(const Element &, const Element &); + _FORCE_INLINE_ bool operator==(const Element &p_other) const { + return this->list_element == p_other.list_element; + } + _FORCE_INLINE_ bool operator!=(const Element &p_other) const { + return this->list_element != p_other.list_element; + } operator bool() const { return (list_element != NULL); @@ -157,8 +161,12 @@ public: return ConstElement(list_element ? list_element->prev() : NULL); } - friend bool operator==(const ConstElement &, const ConstElement &); - friend bool operator!=(const ConstElement &, const ConstElement &); + _FORCE_INLINE_ bool operator==(const ConstElement &p_other) const { + return this->list_element == p_other.list_element; + } + _FORCE_INLINE_ bool operator!=(const ConstElement &p_other) const { + return this->list_element != p_other.list_element; + } operator bool() const { return (list_element != NULL); @@ -288,28 +296,4 @@ public: } }; -template <class K, class V, class Hasher, class Comparator, uint8_t MIN_HASH_TABLE_POWER, uint8_t RELATIONSHIP> -bool operator==(const typename OrderedHashMap<K, V, Hasher, Comparator, MIN_HASH_TABLE_POWER, RELATIONSHIP>::Element &first, - const typename OrderedHashMap<K, V, Hasher, Comparator, MIN_HASH_TABLE_POWER, RELATIONSHIP>::Element &second) { - return (first.list_element == second.list_element); -} - -template <class K, class V, class Hasher, class Comparator, uint8_t MIN_HASH_TABLE_POWER, uint8_t RELATIONSHIP> -bool operator!=(const typename OrderedHashMap<K, V, Hasher, Comparator, MIN_HASH_TABLE_POWER, RELATIONSHIP>::Element &first, - const typename OrderedHashMap<K, V, Hasher, Comparator, MIN_HASH_TABLE_POWER, RELATIONSHIP>::Element &second) { - return (first.list_element != second.list_element); -} - -template <class K, class V, class Hasher, class Comparator, uint8_t MIN_HASH_TABLE_POWER, uint8_t RELATIONSHIP> -bool operator==(const typename OrderedHashMap<K, V, Hasher, Comparator, MIN_HASH_TABLE_POWER, RELATIONSHIP>::ConstElement &first, - const typename OrderedHashMap<K, V, Hasher, Comparator, MIN_HASH_TABLE_POWER, RELATIONSHIP>::ConstElement &second) { - return (first.list_element == second.list_element); -} - -template <class K, class V, class Hasher, class Comparator, uint8_t MIN_HASH_TABLE_POWER, uint8_t RELATIONSHIP> -bool operator!=(const typename OrderedHashMap<K, V, Hasher, Comparator, MIN_HASH_TABLE_POWER, RELATIONSHIP>::ConstElement &first, - const typename OrderedHashMap<K, V, Hasher, Comparator, MIN_HASH_TABLE_POWER, RELATIONSHIP>::ConstElement &second) { - return (first.list_element != second.list_element); -} - #endif // ORDERED_HASH_MAP_H diff --git a/core/os/input_event.h b/core/os/input_event.h index f2c8cc802..de3c0232f 100644 --- a/core/os/input_event.h +++ b/core/os/input_event.h @@ -122,7 +122,9 @@ enum JoystickList { JOY_AXIS_5 = 5, JOY_AXIS_6 = 6, JOY_AXIS_7 = 7, - JOY_AXIS_MAX = 8, + JOY_AXIS_8 = 8, + JOY_AXIS_9 = 9, + JOY_AXIS_MAX = 10, JOY_ANALOG_LX = JOY_AXIS_0, JOY_ANALOG_LY = JOY_AXIS_1, diff --git a/core/os/os.h b/core/os/os.h index f5e479ac0..faecdb0e0 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -109,8 +109,6 @@ protected: virtual int get_video_driver_count() const = 0; virtual const char *get_video_driver_name(int p_driver) const = 0; - virtual VideoMode get_default_video_mode() const = 0; - virtual int get_audio_driver_count() const = 0; virtual const char *get_audio_driver_name(int p_driver) const = 0; diff --git a/core/translation.cpp b/core/translation.cpp index 058db956e..7e4d4feb8 100644 --- a/core/translation.cpp +++ b/core/translation.cpp @@ -966,7 +966,7 @@ Vector<String> TranslationServer::get_all_locale_names() { const char **ptr = locale_names; while (*ptr) { - locales.push_back(*ptr); + locales.push_back(String::utf8(*ptr)); ptr++; } @@ -1168,6 +1168,6 @@ TranslationServer::TranslationServer() for (int i = 0; locale_list[i]; ++i) { - locale_name_map.insert(locale_list[i], locale_names[i]); + locale_name_map.insert(locale_list[i], String::utf8(locale_names[i])); } } diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 1a29b9281..05f047800 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -1458,7 +1458,7 @@ void register_variant_methods() { ADDFUNC0R(STRING, STRING, String, get_basename, varray()); ADDFUNC1R(STRING, STRING, String, plus_file, STRING, "file", varray()); ADDFUNC1R(STRING, INT, String, ord_at, INT, "at", varray()); - ADDFUNC0(STRING, STRING, String, dedent, varray()); + ADDFUNC0R(STRING, STRING, String, dedent, varray()); ADDFUNC2(STRING, NIL, String, erase, INT, "position", INT, "chars", varray()); ADDFUNC0R(STRING, INT, String, hash, varray()); ADDFUNC0R(STRING, STRING, String, md5_text, varray()); |
