summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/engine.cpp1
-rw-r--r--core/global_constants.cpp16
-rw-r--r--core/hash_map.h19
-rw-r--r--core/io/config_file.cpp4
-rw-r--r--core/math/a_star.cpp28
-rw-r--r--core/math/a_star.h1
-rw-r--r--core/math/random_number_generator.h5
-rw-r--r--core/math/random_pcg.cpp8
-rw-r--r--core/math/random_pcg.h62
-rw-r--r--core/math/vector3.h2
-rw-r--r--core/os/input_event.h16
-rw-r--r--core/os/os.h2
-rw-r--r--core/project_settings.cpp4
-rw-r--r--core/ustring.cpp26
14 files changed, 137 insertions, 57 deletions
diff --git a/core/engine.cpp b/core/engine.cpp
index 9607dedb3c..50822244cf 100644
--- a/core/engine.cpp
+++ b/core/engine.cpp
@@ -38,6 +38,7 @@
void Engine::set_iterations_per_second(int p_ips) {
+ ERR_FAIL_COND(p_ips <= 0);
ips = p_ips;
}
int Engine::get_iterations_per_second() const {
diff --git a/core/global_constants.cpp b/core/global_constants.cpp
index fb90403226..671b3c545b 100644
--- a/core/global_constants.cpp
+++ b/core/global_constants.cpp
@@ -425,6 +425,16 @@ void register_global_constants() {
BIND_GLOBAL_ENUM_CONSTANT(JOY_DS_X);
BIND_GLOBAL_ENUM_CONSTANT(JOY_DS_Y);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_VR_GRIP);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_VR_PAD);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_VR_TRIGGER);
+
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_OCULUS_AX);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_OCULUS_BY);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_OCULUS_MENU);
+
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_OPENVR_MENU);
+
BIND_GLOBAL_ENUM_CONSTANT(JOY_SELECT);
BIND_GLOBAL_ENUM_CONSTANT(JOY_START);
BIND_GLOBAL_ENUM_CONSTANT(JOY_DPAD_UP);
@@ -459,6 +469,12 @@ void register_global_constants() {
BIND_GLOBAL_ENUM_CONSTANT(JOY_ANALOG_L2);
BIND_GLOBAL_ENUM_CONSTANT(JOY_ANALOG_R2);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_VR_ANALOG_TRIGGER);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_VR_ANALOG_GRIP);
+
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_OPENVR_TOUCHPADX);
+ BIND_GLOBAL_ENUM_CONSTANT(JOY_OPENVR_TOUCHPADY);
+
// midi
BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_NOTE_OFF);
BIND_GLOBAL_ENUM_CONSTANT(MIDI_MESSAGE_NOTE_ON);
diff --git a/core/hash_map.h b/core/hash_map.h
index 44459a3080..31332991de 100644
--- a/core/hash_map.h
+++ b/core/hash_map.h
@@ -162,20 +162,21 @@ private:
new_hash_table[i] = 0;
}
- for (int i = 0; i < (1 << hash_table_power); i++) {
+ if (hash_table) {
+ for (int i = 0; i < (1 << hash_table_power); i++) {
- while (hash_table[i]) {
+ while (hash_table[i]) {
- Element *se = hash_table[i];
- hash_table[i] = se->next;
- int new_pos = se->hash & ((1 << new_hash_table_power) - 1);
- se->next = new_hash_table[new_pos];
- new_hash_table[new_pos] = se;
+ Element *se = hash_table[i];
+ hash_table[i] = se->next;
+ int new_pos = se->hash & ((1 << new_hash_table_power) - 1);
+ se->next = new_hash_table[new_pos];
+ new_hash_table[new_pos] = se;
+ }
}
- }
- if (hash_table)
memdelete_arr(hash_table);
+ }
hash_table = new_hash_table;
hash_table_power = new_hash_table_power;
}
diff --git a/core/io/config_file.cpp b/core/io/config_file.cpp
index 414742deeb..871e21df3e 100644
--- a/core/io/config_file.cpp
+++ b/core/io/config_file.cpp
@@ -198,10 +198,6 @@ Error ConfigFile::load(const String &p_path) {
section = next_tag.name;
}
}
-
- memdelete(f);
-
- return OK;
}
void ConfigFile::_bind_methods() {
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp
index 3d71e66f80..0b6e9ae929 100644
--- a/core/math/a_star.cpp
+++ b/core/math/a_star.cpp
@@ -99,14 +99,22 @@ void AStar::remove_point(int p_id) {
Point *p = points[p_id];
- Map<int, Point *>::Element *PE = points.front();
- while (PE) {
- for (Set<Point *>::Element *E = PE->get()->neighbours.front(); E; E = E->next()) {
- Segment s(p_id, E->get()->id);
- segments.erase(s);
- E->get()->neighbours.erase(p);
- }
- PE = PE->next();
+ for (Set<Point *>::Element *E = p->neighbours.front(); E; E = E->next()) {
+
+ Segment s(p_id, E->get()->id);
+ segments.erase(s);
+
+ E->get()->neighbours.erase(p);
+ E->get()->unlinked_neighbours.erase(p);
+ }
+
+ for (Set<Point *>::Element *E = p->unlinked_neighbours.front(); E; E = E->next()) {
+
+ Segment s(p_id, E->get()->id);
+ segments.erase(s);
+
+ E->get()->neighbours.erase(p);
+ E->get()->unlinked_neighbours.erase(p);
}
memdelete(p);
@@ -125,6 +133,8 @@ void AStar::connect_points(int p_id, int p_with_id, bool bidirectional) {
if (bidirectional)
b->neighbours.insert(a);
+ else
+ b->unlinked_neighbours.insert(a);
Segment s(p_id, p_with_id);
if (s.from == p_id) {
@@ -147,7 +157,9 @@ void AStar::disconnect_points(int p_id, int p_with_id) {
Point *a = points[p_id];
Point *b = points[p_with_id];
a->neighbours.erase(b);
+ a->unlinked_neighbours.erase(b);
b->neighbours.erase(a);
+ b->unlinked_neighbours.erase(a);
}
bool AStar::has_point(int p_id) const {
diff --git a/core/math/a_star.h b/core/math/a_star.h
index fac8a9d312..ba35d929b3 100644
--- a/core/math/a_star.h
+++ b/core/math/a_star.h
@@ -54,6 +54,7 @@ class AStar : public Reference {
bool enabled;
Set<Point *> neighbours;
+ Set<Point *> unlinked_neighbours;
// Used for pathfinding
Point *prev_point;
diff --git a/core/math/random_number_generator.h b/core/math/random_number_generator.h
index 6b6bcdd2cd..a6182a4b33 100644
--- a/core/math/random_number_generator.h
+++ b/core/math/random_number_generator.h
@@ -59,7 +59,10 @@ public:
_FORCE_INLINE_ int randi_range(int from, int to) {
unsigned int ret = randbase.rand();
- return ret % (to - from + 1) + from;
+ if (to < from)
+ return ret % (from - to + 1) + to;
+ else
+ return ret % (to - from + 1) + from;
}
RandomNumberGenerator();
diff --git a/core/math/random_pcg.cpp b/core/math/random_pcg.cpp
index 8351bd138e..00c0af515d 100644
--- a/core/math/random_pcg.cpp
+++ b/core/math/random_pcg.cpp
@@ -43,13 +43,9 @@ void RandomPCG::randomize() {
}
double RandomPCG::random(double p_from, double p_to) {
- unsigned int r = rand();
- double ret = (double)r / (double)RANDOM_MAX;
- return (ret) * (p_to - p_from) + p_from;
+ return randd() * (p_to - p_from) + p_from;
}
float RandomPCG::random(float p_from, float p_to) {
- unsigned int r = rand();
- float ret = (float)r / (float)RANDOM_MAX;
- return (ret) * (p_to - p_from) + p_from;
+ return randf() * (p_to - p_from) + p_from;
}
diff --git a/core/math/random_pcg.h b/core/math/random_pcg.h
index 0d1b311c0d..aa25914638 100644
--- a/core/math/random_pcg.h
+++ b/core/math/random_pcg.h
@@ -37,6 +37,28 @@
#include "thirdparty/misc/pcg.h"
+#if defined(__GNUC__) || (_llvm_has_builtin(__builtin_clz))
+#define CLZ32(x) __builtin_clz(x)
+#elif defined(_MSC_VER)
+#include "intrin.h"
+static int __bsr_clz32(uint32_t x) {
+ unsigned long index;
+ _BitScanReverse(&index, x);
+ return 31 - index;
+}
+#define CLZ32(x) __bsr_clz32(x)
+#else
+#endif
+
+#if defined(__GNUC__) || (_llvm_has_builtin(__builtin_ldexp) && _llvm_has_builtin(__builtin_ldexpf))
+#define LDEXP(s, e) __builtin_ldexp(s, e)
+#define LDEXPF(s, e) __builtin_ldexpf(s, e)
+#else
+#include "math.h"
+#define LDEXP(s, e) ldexp(s, e)
+#define LDEXPF(s, e) ldexp(s, e)
+#endif
+
class RandomPCG {
pcg32_random_t pcg;
uint64_t current_seed; // seed with this to get the same state
@@ -60,8 +82,44 @@ public:
current_seed = pcg.state;
return pcg32_random_r(&pcg);
}
- _FORCE_INLINE_ double randd() { return (double)rand() / (double)RANDOM_MAX; }
- _FORCE_INLINE_ float randf() { return (float)rand() / (float)RANDOM_MAX; }
+
+ // Obtaining floating point numbers in [0, 1] range with "good enough" uniformity.
+ // These functions sample the output of rand() as the fraction part of an infinite binary number,
+ // with some tricks applied to reduce ops and branching:
+ // 1. Instead of shifting to the first 1 and connecting random bits, we simply set the MSB and LSB to 1.
+ // Provided that the RNG is actually uniform bit by bit, this should have the exact same effect.
+ // 2. In order to compensate for exponent info loss, we count zeros from another random number,
+ // and just add that to the initial offset.
+ // This has the same probability as counting and shifting an actual bit stream: 2^-n for n zeroes.
+ // For all numbers above 2^-96 (2^-64 for floats), the functions should be uniform.
+ // However, all numbers below that threshold are floored to 0.
+ // The thresholds are chosen to minimize rand() calls while keeping the numbers within a totally subjective quality standard.
+ // If clz or ldexp isn't available, fall back to bit truncation for performance, sacrificing uniformity.
+ _FORCE_INLINE_ double randd() {
+#if defined(CLZ32)
+ uint32_t proto_exp_offset = rand();
+ if (unlikely(proto_exp_offset == 0)) {
+ return 0;
+ }
+ uint64_t significand = (((uint64_t)rand()) << 32) | rand() | 0x8000000000000001U;
+ return LDEXP((double)significand, -64 - CLZ32(proto_exp_offset));
+#else
+#pragma message("RandomPCG::randd - intrinsic clz is not available, falling back to bit truncation")
+ return (double)(((((uint64_t)rand()) << 32) | rand()) & 0x1FFFFFFFFFFFFFU) / (double)0x1FFFFFFFFFFFFFU;
+#endif
+ }
+ _FORCE_INLINE_ float randf() {
+#if defined(CLZ32)
+ uint32_t proto_exp_offset = rand();
+ if (unlikely(proto_exp_offset == 0)) {
+ return 0;
+ }
+ return LDEXPF((float)(rand() | 0x80000001), -32 - CLZ32(proto_exp_offset));
+#else
+#pragma message("RandomPCG::randf - intrinsic clz is not available, falling back to bit truncation")
+ return (float)(rand() & 0xFFFFFF) / (float)0xFFFFFF;
+#endif
+ }
_FORCE_INLINE_ double randfn(double p_mean, double p_deviation) {
return p_mean + p_deviation * (cos(Math_TAU * randd()) * sqrt(-2.0 * log(randd()))); // Box-Muller transform
diff --git a/core/math/vector3.h b/core/math/vector3.h
index 6423147282..811a207138 100644
--- a/core/math/vector3.h
+++ b/core/math/vector3.h
@@ -224,7 +224,7 @@ Vector3 Vector3::slerp(const Vector3 &p_b, real_t p_t) const {
#endif
real_t theta = angle_to(p_b);
- return rotated(cross(p_b), theta * p_t);
+ return rotated(cross(p_b).normalized(), theta * p_t);
}
real_t Vector3::distance_to(const Vector3 &p_b) const {
diff --git a/core/os/input_event.h b/core/os/input_event.h
index 7a9a1f71c3..2eb321f134 100644
--- a/core/os/input_event.h
+++ b/core/os/input_event.h
@@ -117,6 +117,16 @@ enum JoystickList {
JOY_WII_MINUS = JOY_BUTTON_10,
JOY_WII_PLUS = JOY_BUTTON_11,
+ JOY_VR_GRIP = JOY_BUTTON_2,
+ JOY_VR_PAD = JOY_BUTTON_14,
+ JOY_VR_TRIGGER = JOY_BUTTON_15,
+
+ JOY_OCULUS_AX = JOY_BUTTON_7,
+ JOY_OCULUS_BY = JOY_BUTTON_1,
+ JOY_OCULUS_MENU = JOY_BUTTON_3,
+
+ JOY_OPENVR_MENU = JOY_BUTTON_1,
+
// end of history
JOY_AXIS_0 = 0,
@@ -139,6 +149,12 @@ enum JoystickList {
JOY_ANALOG_L2 = JOY_AXIS_6,
JOY_ANALOG_R2 = JOY_AXIS_7,
+
+ JOY_VR_ANALOG_TRIGGER = JOY_AXIS_2,
+ JOY_VR_ANALOG_GRIP = JOY_AXIS_4,
+
+ JOY_OPENVR_TOUCHPADX = JOY_AXIS_0,
+ JOY_OPENVR_TOUCHPADY = JOY_AXIS_1,
};
enum MidiMessageList {
diff --git a/core/os/os.h b/core/os/os.h
index 4f6a539e78..b128e6424c 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -104,7 +104,6 @@ public:
bool maximized;
bool always_on_top;
bool use_vsync;
- bool layered_splash;
bool layered;
float get_aspect() const { return (float)width / (float)height; }
VideoMode(int p_width = 1024, int p_height = 600, bool p_fullscreen = false, bool p_resizable = true, bool p_borderless_window = false, bool p_maximized = false, bool p_always_on_top = false, bool p_use_vsync = false) {
@@ -117,7 +116,6 @@ public:
always_on_top = p_always_on_top;
use_vsync = p_use_vsync;
layered = false;
- layered_splash = false;
}
};
diff --git a/core/project_settings.cpp b/core/project_settings.cpp
index 76fbd636d1..0508806a35 100644
--- a/core/project_settings.cpp
+++ b/core/project_settings.cpp
@@ -579,10 +579,6 @@ Error ProjectSettings::_load_settings_text(const String p_path) {
section = next_tag.name;
}
}
-
- memdelete(f);
-
- return OK;
}
Error ProjectSettings::_load_settings_text_or_binary(const String p_text_path, const String p_bin_path) {
diff --git a/core/ustring.cpp b/core/ustring.cpp
index 88b758e883..35b817b1d2 100644
--- a/core/ustring.cpp
+++ b/core/ustring.cpp
@@ -2956,26 +2956,12 @@ String String::replace(const char *p_key, const char *p_with) const {
String String::replace_first(const String &p_key, const String &p_with) const {
- String new_string;
- int search_from = 0;
- int result = 0;
-
- while ((result = find(p_key, search_from)) >= 0) {
-
- new_string += substr(search_from, result - search_from);
- new_string += p_with;
- search_from = result + p_key.length();
- break;
+ int pos = find(p_key);
+ if (pos >= 0) {
+ return substr(0, pos) + p_with + substr(pos + p_key.length(), length());
}
- if (search_from == 0) {
-
- return *this;
- }
-
- new_string += substr(search_from, length() - search_from);
-
- return new_string;
+ return *this;
}
String String::replacen(const String &p_key, const String &p_with) const {
@@ -3235,7 +3221,7 @@ static int _humanize_digits(int p_num) {
String String::humanize_size(size_t p_size) {
uint64_t _div = 1;
- static const char *prefix[] = { " Bytes", " KB", " MB", " GB", "TB", " PB", "HB", "" };
+ static const char *prefix[] = { " Bytes", " KB", " MB", " GB", " TB", " PB", " EB", "" };
int prefix_idx = 0;
while (p_size > (_div * 1024) && prefix[prefix_idx][0]) {
@@ -3246,7 +3232,7 @@ String String::humanize_size(size_t p_size) {
int digits = prefix_idx > 0 ? _humanize_digits(p_size / _div) : 0;
double divisor = prefix_idx > 0 ? _div : 1;
- return String::num(p_size / divisor, digits) + prefix[prefix_idx];
+ return String::num(p_size / divisor).pad_decimals(digits) + prefix[prefix_idx];
}
bool String::is_abs_path() const {