Skip to content

Commit

Permalink
Merge pull request #52900 from akien-mga/3.x-cherrypicks
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga committed Sep 21, 2021
2 parents 5b841c1 + d0a8e6d commit dd0ee48
Show file tree
Hide file tree
Showing 132 changed files with 21,655 additions and 12,415 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -2,7 +2,7 @@

<p align="center">
<a href="https://godotengine.org">
<img src="logo.svg" width="400" alt="Godot Engine logo">
<img src="logo_outlined.svg" width="400" alt="Godot Engine logo">
</a>
</p>

Expand Down
5 changes: 5 additions & 0 deletions core/bind/core_bind.cpp
Expand Up @@ -527,6 +527,10 @@ String _OS::get_locale() const {
return OS::get_singleton()->get_locale();
}

String _OS::get_locale_language() const {
return OS::get_singleton()->get_locale_language();
}

String _OS::get_latin_keyboard_variant() const {
switch (OS::get_singleton()->get_latin_keyboard_variant()) {
case OS::LATIN_KEYBOARD_QWERTY:
Expand Down Expand Up @@ -1333,6 +1337,7 @@ void _OS::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_ticks_usec"), &_OS::get_ticks_usec);
ClassDB::bind_method(D_METHOD("get_splash_tick_msec"), &_OS::get_splash_tick_msec);
ClassDB::bind_method(D_METHOD("get_locale"), &_OS::get_locale);
ClassDB::bind_method(D_METHOD("get_locale_language"), &_OS::get_locale_language);
ClassDB::bind_method(D_METHOD("get_latin_keyboard_variant"), &_OS::get_latin_keyboard_variant);
ClassDB::bind_method(D_METHOD("get_model_name"), &_OS::get_model_name);

Expand Down
1 change: 1 addition & 0 deletions core/bind/core_bind.h
Expand Up @@ -256,6 +256,7 @@ class _OS : public Object {
Vector<String> get_cmdline_args();

String get_locale() const;
String get_locale_language() const;
String get_latin_keyboard_variant() const;
int keyboard_get_layout_count() const;
int keyboard_get_current_layout() const;
Expand Down
18 changes: 9 additions & 9 deletions core/input_map.cpp
Expand Up @@ -59,7 +59,7 @@ void InputMap::_bind_methods() {
* Returns an nonexistent action error message with a suggestion of the closest
* matching action name (if possible).
*/
String InputMap::_suggest_actions(const StringName &p_action) const {
String InputMap::suggest_actions(const StringName &p_action) const {
List<StringName> actions = get_actions();
StringName closest_action;
float closest_similarity = 0.0;
Expand Down Expand Up @@ -93,7 +93,7 @@ void InputMap::add_action(const StringName &p_action, float p_deadzone) {
}

void InputMap::erase_action(const StringName &p_action) {
ERR_FAIL_COND_MSG(!input_map.has(p_action), _suggest_actions(p_action));
ERR_FAIL_COND_MSG(!input_map.has(p_action), suggest_actions(p_action));

input_map.erase(p_action);
}
Expand Down Expand Up @@ -152,20 +152,20 @@ bool InputMap::has_action(const StringName &p_action) const {
}

float InputMap::action_get_deadzone(const StringName &p_action) {
ERR_FAIL_COND_V_MSG(!input_map.has(p_action), 0.0f, _suggest_actions(p_action));
ERR_FAIL_COND_V_MSG(!input_map.has(p_action), 0.0f, suggest_actions(p_action));

return input_map[p_action].deadzone;
}

void InputMap::action_set_deadzone(const StringName &p_action, float p_deadzone) {
ERR_FAIL_COND_MSG(!input_map.has(p_action), _suggest_actions(p_action));
ERR_FAIL_COND_MSG(!input_map.has(p_action), suggest_actions(p_action));

input_map[p_action].deadzone = p_deadzone;
}

void InputMap::action_add_event(const StringName &p_action, const Ref<InputEvent> &p_event) {
ERR_FAIL_COND_MSG(p_event.is_null(), "It's not a reference to a valid InputEvent object.");
ERR_FAIL_COND_MSG(!input_map.has(p_action), _suggest_actions(p_action));
ERR_FAIL_COND_MSG(!input_map.has(p_action), suggest_actions(p_action));

if (_find_event(input_map[p_action], p_event, true)) {
return; // Already added.
Expand All @@ -175,13 +175,13 @@ void InputMap::action_add_event(const StringName &p_action, const Ref<InputEvent
}

bool InputMap::action_has_event(const StringName &p_action, const Ref<InputEvent> &p_event) {
ERR_FAIL_COND_V_MSG(!input_map.has(p_action), false, _suggest_actions(p_action));
ERR_FAIL_COND_V_MSG(!input_map.has(p_action), false, suggest_actions(p_action));

return (_find_event(input_map[p_action], p_event, true) != nullptr);
}

void InputMap::action_erase_event(const StringName &p_action, const Ref<InputEvent> &p_event) {
ERR_FAIL_COND_MSG(!input_map.has(p_action), _suggest_actions(p_action));
ERR_FAIL_COND_MSG(!input_map.has(p_action), suggest_actions(p_action));

List<Ref<InputEvent>>::Element *E = _find_event(input_map[p_action], p_event, true);
if (E) {
Expand All @@ -193,7 +193,7 @@ void InputMap::action_erase_event(const StringName &p_action, const Ref<InputEve
}

void InputMap::action_erase_events(const StringName &p_action) {
ERR_FAIL_COND_MSG(!input_map.has(p_action), _suggest_actions(p_action));
ERR_FAIL_COND_MSG(!input_map.has(p_action), suggest_actions(p_action));

input_map[p_action].inputs.clear();
}
Expand Down Expand Up @@ -225,7 +225,7 @@ bool InputMap::event_is_action(const Ref<InputEvent> &p_event, const StringName

bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const StringName &p_action, bool p_exact_match, bool *p_pressed, float *p_strength, float *p_raw_strength) const {
Map<StringName, Action>::Element *E = input_map.find(p_action);
ERR_FAIL_COND_V_MSG(!E, false, _suggest_actions(p_action));
ERR_FAIL_COND_V_MSG(!E, false, suggest_actions(p_action));

Ref<InputEventAction> input_event_action = p_event;
if (input_event_action.is_valid()) {
Expand Down
3 changes: 2 additions & 1 deletion core/input_map.h
Expand Up @@ -58,7 +58,6 @@ class InputMap : public Object {

Array _get_action_list(const StringName &p_action);
Array _get_actions();
String _suggest_actions(const StringName &p_action) const;

protected:
static void _bind_methods();
Expand Down Expand Up @@ -86,6 +85,8 @@ class InputMap : public Object {
void load_from_globals();
void load_default();

String suggest_actions(const StringName &p_action) const;

InputMap();
};

Expand Down
68 changes: 34 additions & 34 deletions core/math/a_star.cpp
Expand Up @@ -47,8 +47,8 @@ int AStar::get_available_point_id() const {
}

void AStar::add_point(int p_id, const Vector3 &p_pos, real_t p_weight_scale) {
ERR_FAIL_COND(p_id < 0);
ERR_FAIL_COND(p_weight_scale < 1);
ERR_FAIL_COND_MSG(p_id < 0, vformat("Can't add a point with negative id: %d.", p_id));
ERR_FAIL_COND_MSG(p_weight_scale < 1, vformat("Can't add a point with weight scale less than one: %f.", p_weight_scale));

Point *found_pt;
bool p_exists = points.lookup(p_id, found_pt);
Expand All @@ -72,40 +72,40 @@ void AStar::add_point(int p_id, const Vector3 &p_pos, real_t p_weight_scale) {
Vector3 AStar::get_point_position(int p_id) const {
Point *p;
bool p_exists = points.lookup(p_id, p);
ERR_FAIL_COND_V(!p_exists, Vector3());
ERR_FAIL_COND_V_MSG(!p_exists, Vector3(), vformat("Can't get point's position. Point with id: %d doesn't exist.", p_id));

return p->pos;
}

void AStar::set_point_position(int p_id, const Vector3 &p_pos) {
Point *p;
bool p_exists = points.lookup(p_id, p);
ERR_FAIL_COND(!p_exists);
ERR_FAIL_COND_MSG(!p_exists, vformat("Can't set point's position. Point with id: %d doesn't exist.", p_id));

p->pos = p_pos;
}

real_t AStar::get_point_weight_scale(int p_id) const {
Point *p;
bool p_exists = points.lookup(p_id, p);
ERR_FAIL_COND_V(!p_exists, 0);
ERR_FAIL_COND_V_MSG(!p_exists, 0, vformat("Can't get point's weight scale. Point with id: %d doesn't exist.", p_id));

return p->weight_scale;
}

void AStar::set_point_weight_scale(int p_id, real_t p_weight_scale) {
Point *p;
bool p_exists = points.lookup(p_id, p);
ERR_FAIL_COND(!p_exists);
ERR_FAIL_COND(p_weight_scale < 1);
ERR_FAIL_COND_MSG(!p_exists, vformat("Can't set point's weight scale. Point with id: %d doesn't exist.", p_id));
ERR_FAIL_COND_MSG(p_weight_scale < 1, vformat("Can't set point's weight scale less than one: %f.", p_weight_scale));

p->weight_scale = p_weight_scale;
}

void AStar::remove_point(int p_id) {
Point *p;
bool p_exists = points.lookup(p_id, p);
ERR_FAIL_COND(!p_exists);
ERR_FAIL_COND_MSG(!p_exists, vformat("Can't remove point. Point with id: %d doesn't exist.", p_id));

for (OAHashMap<int, Point *>::Iterator it = p->neighbours.iter(); it.valid; it = p->neighbours.next_iter(it)) {
Segment s(p_id, (*it.key));
Expand All @@ -129,15 +129,15 @@ void AStar::remove_point(int p_id) {
}

void AStar::connect_points(int p_id, int p_with_id, bool bidirectional) {
ERR_FAIL_COND(p_id == p_with_id);
ERR_FAIL_COND_MSG(p_id == p_with_id, vformat("Can't connect point with id: %d to itself.", p_id));

Point *a;
bool from_exists = points.lookup(p_id, a);
ERR_FAIL_COND(!from_exists);
ERR_FAIL_COND_MSG(!from_exists, vformat("Can't connect points. Point with id: %d doesn't exist.", p_id));

Point *b;
bool to_exists = points.lookup(p_with_id, b);
ERR_FAIL_COND(!to_exists);
ERR_FAIL_COND_MSG(!to_exists, vformat("Can't connect points. Point with id: %d doesn't exist.", p_with_id));

a->neighbours.set(b->id, b);

Expand Down Expand Up @@ -169,11 +169,11 @@ void AStar::connect_points(int p_id, int p_with_id, bool bidirectional) {
void AStar::disconnect_points(int p_id, int p_with_id, bool bidirectional) {
Point *a;
bool a_exists = points.lookup(p_id, a);
ERR_FAIL_COND(!a_exists);
ERR_FAIL_COND_MSG(!a_exists, vformat("Can't disconnect points. Point with id: %d doesn't exist.", p_id));

Point *b;
bool b_exists = points.lookup(p_with_id, b);
ERR_FAIL_COND(!b_exists);
ERR_FAIL_COND_MSG(!b_exists, vformat("Can't disconnect points. Point with id: %d doesn't exist.", p_with_id));

Segment s(p_id, p_with_id);
int remove_direction = bidirectional ? (int)Segment::BIDIRECTIONAL : s.direction;
Expand Down Expand Up @@ -223,7 +223,7 @@ Array AStar::get_points() {
PoolVector<int> AStar::get_point_connections(int p_id) {
Point *p;
bool p_exists = points.lookup(p_id, p);
ERR_FAIL_COND_V(!p_exists, PoolVector<int>());
ERR_FAIL_COND_V_MSG(!p_exists, PoolVector<int>(), vformat("Can't get point's connections. Point with id: %d doesn't exist.", p_id));

PoolVector<int> point_list;

Expand Down Expand Up @@ -260,8 +260,8 @@ int AStar::get_point_capacity() const {
}

void AStar::reserve_space(int p_num_nodes) {
ERR_FAIL_COND_MSG(p_num_nodes <= 0, "New capacity must be greater than 0, was: " + itos(p_num_nodes) + ".");
ERR_FAIL_COND_MSG((uint32_t)p_num_nodes < points.get_capacity(), "New capacity must be greater than current capacity: " + itos(points.get_capacity()) + ", new was: " + itos(p_num_nodes) + ".");
ERR_FAIL_COND_MSG(p_num_nodes <= 0, vformat("New capacity must be greater than 0, new was: %d.", p_num_nodes));
ERR_FAIL_COND_MSG((uint32_t)p_num_nodes < points.get_capacity(), vformat("New capacity must be greater than current capacity: %d, new was: %d.", points.get_capacity(), p_num_nodes));
points.reserve(p_num_nodes);
}

Expand Down Expand Up @@ -388,11 +388,11 @@ real_t AStar::_estimate_cost(int p_from_id, int p_to_id) {

Point *from_point;
bool from_exists = points.lookup(p_from_id, from_point);
ERR_FAIL_COND_V(!from_exists, 0);
ERR_FAIL_COND_V_MSG(!from_exists, 0, vformat("Can't estimate cost. Point with id: %d doesn't exist.", p_from_id));

Point *to_point;
bool to_exists = points.lookup(p_to_id, to_point);
ERR_FAIL_COND_V(!to_exists, 0);
ERR_FAIL_COND_V_MSG(!to_exists, 0, vformat("Can't estimate cost. Point with id: %d doesn't exist.", p_to_id));

return from_point->pos.distance_to(to_point->pos);
}
Expand All @@ -404,23 +404,23 @@ real_t AStar::_compute_cost(int p_from_id, int p_to_id) {

Point *from_point;
bool from_exists = points.lookup(p_from_id, from_point);
ERR_FAIL_COND_V(!from_exists, 0);
ERR_FAIL_COND_V_MSG(!from_exists, 0, vformat("Can't compute cost. Point with id: %d doesn't exist.", p_from_id));

Point *to_point;
bool to_exists = points.lookup(p_to_id, to_point);
ERR_FAIL_COND_V(!to_exists, 0);
ERR_FAIL_COND_V_MSG(!to_exists, 0, vformat("Can't compute cost. Point with id: %d doesn't exist.", p_to_id));

return from_point->pos.distance_to(to_point->pos);
}

PoolVector<Vector3> AStar::get_point_path(int p_from_id, int p_to_id) {
Point *a;
bool from_exists = points.lookup(p_from_id, a);
ERR_FAIL_COND_V(!from_exists, PoolVector<Vector3>());
ERR_FAIL_COND_V_MSG(!from_exists, PoolVector<Vector3>(), vformat("Can't get point path. Point with id: %d doesn't exist.", p_from_id));

Point *b;
bool to_exists = points.lookup(p_to_id, b);
ERR_FAIL_COND_V(!to_exists, PoolVector<Vector3>());
ERR_FAIL_COND_V_MSG(!to_exists, PoolVector<Vector3>(), vformat("Can't get point path. Point with id: %d doesn't exist.", p_to_id));

if (a == b) {
PoolVector<Vector3> ret;
Expand Down Expand Up @@ -465,11 +465,11 @@ PoolVector<Vector3> AStar::get_point_path(int p_from_id, int p_to_id) {
PoolVector<int> AStar::get_id_path(int p_from_id, int p_to_id) {
Point *a;
bool from_exists = points.lookup(p_from_id, a);
ERR_FAIL_COND_V(!from_exists, PoolVector<int>());
ERR_FAIL_COND_V_MSG(!from_exists, PoolVector<int>(), vformat("Can't get id path. Point with id: %d doesn't exist.", p_from_id));

Point *b;
bool to_exists = points.lookup(p_to_id, b);
ERR_FAIL_COND_V(!to_exists, PoolVector<int>());
ERR_FAIL_COND_V_MSG(!to_exists, PoolVector<int>(), vformat("Can't get id path. Point with id: %d doesn't exist.", p_to_id));

if (a == b) {
PoolVector<int> ret;
Expand Down Expand Up @@ -514,15 +514,15 @@ PoolVector<int> AStar::get_id_path(int p_from_id, int p_to_id) {
void AStar::set_point_disabled(int p_id, bool p_disabled) {
Point *p;
bool p_exists = points.lookup(p_id, p);
ERR_FAIL_COND(!p_exists);
ERR_FAIL_COND_MSG(!p_exists, vformat("Can't set if point is disabled. Point with id: %d doesn't exist.", p_id));

p->enabled = !p_disabled;
}

bool AStar::is_point_disabled(int p_id) const {
Point *p;
bool p_exists = points.lookup(p_id, p);
ERR_FAIL_COND_V(!p_exists, false);
ERR_FAIL_COND_V_MSG(!p_exists, false, vformat("Can't get if point is disabled. Point with id: %d doesn't exist.", p_id));

return !p->enabled;
}
Expand Down Expand Up @@ -665,11 +665,11 @@ real_t AStar2D::_estimate_cost(int p_from_id, int p_to_id) {

AStar::Point *from_point;
bool from_exists = astar.points.lookup(p_from_id, from_point);
ERR_FAIL_COND_V(!from_exists, 0);
ERR_FAIL_COND_V_MSG(!from_exists, 0, vformat("Can't estimate cost. Point with id: %d doesn't exist.", p_from_id));

AStar::Point *to_point;
bool to_exists = astar.points.lookup(p_to_id, to_point);
ERR_FAIL_COND_V(!to_exists, 0);
ERR_FAIL_COND_V_MSG(!to_exists, 0, vformat("Can't estimate cost. Point with id: %d doesn't exist.", p_to_id));

return from_point->pos.distance_to(to_point->pos);
}
Expand All @@ -681,23 +681,23 @@ real_t AStar2D::_compute_cost(int p_from_id, int p_to_id) {

AStar::Point *from_point;
bool from_exists = astar.points.lookup(p_from_id, from_point);
ERR_FAIL_COND_V(!from_exists, 0);
ERR_FAIL_COND_V_MSG(!from_exists, 0, vformat("Can't compute cost. Point with id: %d doesn't exist.", p_from_id));

AStar::Point *to_point;
bool to_exists = astar.points.lookup(p_to_id, to_point);
ERR_FAIL_COND_V(!to_exists, 0);
ERR_FAIL_COND_V_MSG(!to_exists, 0, vformat("Can't compute cost. Point with id: %d doesn't exist.", p_to_id));

return from_point->pos.distance_to(to_point->pos);
}

PoolVector<Vector2> AStar2D::get_point_path(int p_from_id, int p_to_id) {
AStar::Point *a;
bool from_exists = astar.points.lookup(p_from_id, a);
ERR_FAIL_COND_V(!from_exists, PoolVector<Vector2>());
ERR_FAIL_COND_V_MSG(!from_exists, PoolVector<Vector2>(), vformat("Can't get point path. Point with id: %d doesn't exist.", p_from_id));

AStar::Point *b;
bool to_exists = astar.points.lookup(p_to_id, b);
ERR_FAIL_COND_V(!to_exists, PoolVector<Vector2>());
ERR_FAIL_COND_V_MSG(!to_exists, PoolVector<Vector2>(), vformat("Can't get point path. Point with id: %d doesn't exist.", p_to_id));

if (a == b) {
PoolVector<Vector2> ret;
Expand Down Expand Up @@ -742,11 +742,11 @@ PoolVector<Vector2> AStar2D::get_point_path(int p_from_id, int p_to_id) {
PoolVector<int> AStar2D::get_id_path(int p_from_id, int p_to_id) {
AStar::Point *a;
bool from_exists = astar.points.lookup(p_from_id, a);
ERR_FAIL_COND_V(!from_exists, PoolVector<int>());
ERR_FAIL_COND_V_MSG(!from_exists, PoolVector<int>(), vformat("Can't get id path. Point with id: %d doesn't exist.", p_from_id));

AStar::Point *b;
bool to_exists = astar.points.lookup(p_to_id, b);
ERR_FAIL_COND_V(!to_exists, PoolVector<int>());
ERR_FAIL_COND_V_MSG(!to_exists, PoolVector<int>(), vformat("Can't get id path. Point with id: %d doesn't exist.", p_to_id));

if (a == b) {
PoolVector<int> ret;
Expand Down
6 changes: 6 additions & 0 deletions core/os/os.cpp
Expand Up @@ -284,6 +284,12 @@ String OS::get_locale() const {
return "en";
}

// Non-virtual helper to extract the 2 or 3-letter language code from
// `get_locale()` in a way that's consistent for all platforms.
String OS::get_locale_language() const {
return get_locale().left(3).replace("_", "");
}

// Helper function to ensure that a dir name/path will be valid on the OS
String OS::get_safe_dir_name(const String &p_dir_name, bool p_allow_dir_separator) const {
Vector<String> invalid_chars = String(": * ? \" < > |").split(" ");
Expand Down
1 change: 1 addition & 0 deletions core/os/os.h
Expand Up @@ -427,6 +427,7 @@ class OS {
RenderThreadMode get_render_thread_mode() const { return _render_thread_mode; }

virtual String get_locale() const;
String get_locale_language() const;

String get_safe_dir_name(const String &p_dir_name, bool p_allow_dir_separator = false) const;
virtual String get_godot_dir_name() const;
Expand Down

0 comments on commit dd0ee48

Please sign in to comment.