aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/bind/core_bind.cpp25
-rw-r--r--core/bind/core_bind.h4
-rw-r--r--core/global_config.cpp74
-rw-r--r--core/global_config.h3
-rw-r--r--core/hashfuncs.h18
-rw-r--r--core/io/marshalls.cpp2
-rw-r--r--core/math/geometry.h21
-rw-r--r--core/math/math_funcs.cpp6
-rw-r--r--core/math/math_funcs.h2
-rw-r--r--core/os/input.cpp2
-rw-r--r--core/os/input.h2
-rw-r--r--core/os/os.cpp1
-rw-r--r--core/os/os.h2
-rw-r--r--core/variant.cpp2
14 files changed, 106 insertions, 58 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index 8c57f4906..bd41e48a3 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -163,9 +163,9 @@ _ResourceSaver::_ResourceSaver() {
/////////////////OS
-Point2 _OS::get_mouse_pos() const {
+Point2 _OS::get_mouse_position() const {
- return OS::get_singleton()->get_mouse_pos();
+ return OS::get_singleton()->get_mouse_position();
}
void _OS::set_window_title(const String &p_title) {
@@ -954,7 +954,7 @@ _OS *_OS::singleton = NULL;
void _OS::_bind_methods() {
- //ClassDB::bind_method(D_METHOD("get_mouse_pos"),&_OS::get_mouse_pos);
+ //ClassDB::bind_method(D_METHOD("get_mouse_position"),&_OS::get_mouse_position);
//ClassDB::bind_method(D_METHOD("is_mouse_grab_enabled"),&_OS::is_mouse_grab_enabled);
ClassDB::bind_method(D_METHOD("set_clipboard", "clipboard"), &_OS::set_clipboard);
@@ -2367,6 +2367,23 @@ Array _ClassDB::get_property_list(StringName p_class, bool p_no_inheritance) con
return ret;
}
+Variant _ClassDB::get_property(Object *p_object, const StringName &p_property) const {
+ Variant ret;
+ ClassDB::get_property(p_object, p_property, ret);
+ return ret;
+}
+
+Error _ClassDB::set_property(Object *p_object, const StringName &p_property, const Variant &p_value) const {
+ Variant ret;
+ bool valid;
+ if (!ClassDB::set_property(p_object, p_property, p_value, &valid)) {
+ return ERR_UNAVAILABLE;
+ } else if (!valid) {
+ return ERR_INVALID_DATA;
+ }
+ return OK;
+}
+
bool _ClassDB::has_method(StringName p_class, StringName p_method, bool p_no_inheritance) const {
return ClassDB::has_method(p_class, p_method, p_no_inheritance);
@@ -2439,6 +2456,8 @@ void _ClassDB::_bind_methods() {
ClassDB::bind_method(D_METHOD("class_get_signal_list", "class", "no_inheritance"), &_ClassDB::get_signal_list, DEFVAL(false));
ClassDB::bind_method(D_METHOD("class_get_property_list", "class", "no_inheritance"), &_ClassDB::get_property_list, DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("class_get_property:Variant", "object", "property"), &_ClassDB::get_property);
+ ClassDB::bind_method(D_METHOD("class_set_property:Error", "object", "property", "value"), &_ClassDB::set_property);
ClassDB::bind_method(D_METHOD("class_has_method", "class", "method", "no_inheritance"), &_ClassDB::has_method, DEFVAL(false));
diff --git a/core/bind/core_bind.h b/core/bind/core_bind.h
index 13956c337..222339bce 100644
--- a/core/bind/core_bind.h
+++ b/core/bind/core_bind.h
@@ -120,7 +120,7 @@ public:
MONTH_DECEMBER
};
- Point2 get_mouse_pos() const;
+ Point2 get_mouse_position() const;
void set_window_title(const String &p_title);
int get_mouse_button_state() const;
@@ -587,6 +587,8 @@ public:
Array get_signal_list(StringName p_class, bool p_no_inheritance = false) const;
Array get_property_list(StringName p_class, bool p_no_inheritance = false) const;
+ Variant get_property(Object *p_object, const StringName &p_property) const;
+ Error set_property(Object *p_object, const StringName &p_property, const Variant &p_value) const;
bool has_method(StringName p_class, StringName p_method, bool p_no_inheritance = false) const;
diff --git a/core/global_config.cpp b/core/global_config.cpp
index d37c67c84..f9a0877c2 100644
--- a/core/global_config.cpp
+++ b/core/global_config.cpp
@@ -53,6 +53,11 @@ String GlobalConfig::get_resource_path() const {
return resource_path;
};
+String GlobalConfig::get_project_file_name() const {
+
+ return project_file_name;
+}
+
String GlobalConfig::localize_path(const String &p_path) const {
if (resource_path == "")
@@ -236,13 +241,43 @@ bool GlobalConfig::_load_resource_pack(const String &p_pack) {
return true;
}
+static String _find_project_file(DirAccess *p_diraccess, bool p_res = false) {
+ p_diraccess->list_dir_begin();
+ String ret = "";
+ while (true) {
+ bool isdir;
+ String file = p_diraccess->get_next(&isdir);
+ if (file == "")
+ break;
+
+ if (!isdir) {
+ if (file.get_extension() == "godot") {
+
+ if (p_res) {
+ ret = "res://" + file;
+ } else {
+ ret = p_diraccess->get_current_dir() + "/" + file;
+ }
+ }
+ }
+ }
+ p_diraccess->list_dir_end();
+ return ret;
+}
+
+static String _find_project_file() {
+ DirAccess *dir = DirAccess::create(DirAccess::ACCESS_RESOURCES);
+ String ret = _find_project_file(dir, true);
+ memdelete(dir);
+ return ret;
+}
+
Error GlobalConfig::setup(const String &p_path, const String &p_main_pack) {
//If looking for files in network, just use network!
-
if (FileAccessNetworkClient::get_singleton()) {
-
- if (_load_settings("res://godot.cfg") == OK || _load_settings_binary("res://godot.cfb") == OK) {
+ String gdproj = _find_project_file();
+ if (_load_settings(gdproj) == OK || _load_settings_binary("res://godot.cfb") == OK) {
_load_settings("res://override.cfg");
}
@@ -258,8 +293,8 @@ Error GlobalConfig::setup(const String &p_path, const String &p_main_pack) {
bool ok = _load_resource_pack(p_main_pack);
ERR_FAIL_COND_V(!ok, ERR_CANT_OPEN);
-
- if (_load_settings("res://godot.cfg") == OK || _load_settings_binary("res://godot.cfb") == OK) {
+ String gdproj = _find_project_file();
+ if (_load_settings(gdproj) == OK || _load_settings_binary("res://godot.cfb") == OK) {
//load override from location of the main pack
_load_settings(p_main_pack.get_base_dir().plus_file("override.cfg"));
}
@@ -272,7 +307,8 @@ Error GlobalConfig::setup(const String &p_path, const String &p_main_pack) {
if (_load_resource_pack(exec_path.get_basename() + ".pck")) {
- if (_load_settings("res://godot.cfg") == OK || _load_settings_binary("res://godot.cfb") == OK) {
+ String gdproj = _find_project_file();
+ if (_load_settings(gdproj) == OK || _load_settings_binary("res://godot.cfb") == OK) {
//load override from location of executable
_load_settings(exec_path.get_base_dir().plus_file("override.cfg"));
}
@@ -292,15 +328,15 @@ Error GlobalConfig::setup(const String &p_path, const String &p_main_pack) {
// data.pck and data.zip are deprecated and no longer supported, apologies.
// make sure this is loaded from the resource path
-
- if (_load_settings("res://godot.cfg") == OK || _load_settings_binary("res://godot.cfb") == OK) {
+ String gdproj = _find_project_file();
+ if (_load_settings(gdproj) == OK || _load_settings_binary("res://godot.cfb") == OK) {
_load_settings("res://override.cfg");
}
return OK;
}
- //Nothing was found, try to find a godot.cfg somewhere!
+ //Nothing was found, try to find a *.godot somewhere!
DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
ERR_FAIL_COND_V(!d, ERR_CANT_CREATE);
@@ -313,8 +349,8 @@ Error GlobalConfig::setup(const String &p_path, const String &p_main_pack) {
while (true) {
//try to load settings in ascending through dirs shape!
-
- if (_load_settings(current_dir + "/godot.cfg") == OK || _load_settings_binary(current_dir + "/godot.cfb") == OK) {
+ String gdproj = _find_project_file(d);
+ if (_load_settings(gdproj) == OK || _load_settings_binary(current_dir + "/godot.cfb") == OK) {
_load_settings(current_dir + "/override.cfg");
candidate = current_dir;
@@ -428,6 +464,7 @@ Error GlobalConfig::_load_settings(const String p_path) {
err = VariantParser::parse_tag_assign_eof(&stream, lines, error_text, next_tag, assign, value, NULL, true);
if (err == ERR_FILE_EOF) {
memdelete(f);
+ project_file_name = p_path.get_file();
return OK;
} else if (err != OK) {
ERR_PRINTS("GlobalConfig::load - " + p_path + ":" + itos(lines) + " error: " + error_text);
@@ -449,6 +486,7 @@ Error GlobalConfig::_load_settings(const String p_path) {
}
}
+ project_file_name = p_path.get_file();
memdelete(f);
return OK;
@@ -474,7 +512,12 @@ void GlobalConfig::clear(const String &p_name) {
Error GlobalConfig::save() {
- return save_custom(get_resource_path() + "/godot.cfg");
+ if (project_file_name.empty()) {
+ String name = ((String)get("application/name")).replace(" ", "_");
+ return save_custom(get_resource_path() + "/" + name + ".godot");
+ } else {
+ return save_custom(get_resource_path() + "/" + project_file_name);
+ }
}
Error GlobalConfig::_save_settings_binary(const String &p_file, const Map<String, List<String> > &props, const CustomMap &p_custom) {
@@ -483,7 +526,7 @@ Error GlobalConfig::_save_settings_binary(const String &p_file, const Map<String
FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err);
if (err != OK) {
- ERR_EXPLAIN("Coudln't save godot.cfb at " + p_file);
+ ERR_EXPLAIN("Couldn't save godot.cfb at " + p_file);
ERR_FAIL_COND_V(err, err)
}
@@ -548,7 +591,7 @@ Error GlobalConfig::_save_settings_text(const String &p_file, const Map<String,
FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err);
if (err) {
- ERR_EXPLAIN("Coudln't save godot.cfg - " + p_file);
+ ERR_EXPLAIN("Couldn't save project file - " + p_file);
ERR_FAIL_COND_V(err, err)
}
@@ -658,7 +701,7 @@ Error GlobalConfig::save_custom(const String &p_path, const CustomMap &p_custom,
props[category].push_back(name);
}
- if (p_path.ends_with(".cfg"))
+ if (p_path.ends_with(".godot"))
return _save_settings_text(p_path, props, p_custom);
else if (p_path.ends_with(".cfb"))
return _save_settings_binary(p_path, props, p_custom);
@@ -828,6 +871,7 @@ void GlobalConfig::_bind_methods() {
ClassDB::bind_method(D_METHOD("clear", "name"), &GlobalConfig::clear);
ClassDB::bind_method(D_METHOD("localize_path", "path"), &GlobalConfig::localize_path);
ClassDB::bind_method(D_METHOD("globalize_path", "path"), &GlobalConfig::globalize_path);
+ ClassDB::bind_method(D_METHOD("get_project_file_name"), &GlobalConfig::get_project_file_name);
ClassDB::bind_method(D_METHOD("save"), &GlobalConfig::save);
ClassDB::bind_method(D_METHOD("has_singleton", "name"), &GlobalConfig::has_singleton);
ClassDB::bind_method(D_METHOD("get_singleton", "name"), &GlobalConfig::get_singleton_object);
diff --git a/core/global_config.h b/core/global_config.h
index d0f64dc23..5148c4377 100644
--- a/core/global_config.h
+++ b/core/global_config.h
@@ -111,6 +111,8 @@ protected:
void _add_property_info_bind(const Dictionary &p_info);
+ String project_file_name;
+
protected:
static void _bind_methods();
@@ -124,6 +126,7 @@ public:
Variant property_get_revert(const String &p_name);
String get_resource_path() const;
+ String get_project_file_name() const;
static GlobalConfig *get_singleton();
diff --git a/core/hashfuncs.h b/core/hashfuncs.h
index fbd2e161b..839298456 100644
--- a/core/hashfuncs.h
+++ b/core/hashfuncs.h
@@ -81,24 +81,6 @@ static inline uint32_t hash_one_uint64(const uint64_t p_int) {
return (int)v;
}
-static inline uint32_t hash_djb2_one_float(float p_in, uint32_t p_prev = 5381) {
- union {
- float f;
- uint32_t i;
- } u;
-
- // Normalize +/- 0.0 and NaN values so they hash the same.
- if (p_in == 0.0f)
- u.f = 0.0;
- else if (Math::is_nan(p_in))
- u.f = Math_NAN;
- else
- u.f = p_in;
-
- return ((p_prev << 5) + p_prev) + u.i;
-}
-
-// Overload for real_t size changes
static inline uint32_t hash_djb2_one_float(double p_in, uint32_t p_prev = 5381) {
union {
double d;
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp
index 3889c8f3a..5e66b7f7f 100644
--- a/core/io/marshalls.cpp
+++ b/core/io/marshalls.cpp
@@ -862,7 +862,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len) {
} else {
if (buf) {
- encode_double(p_variant.operator float(), buf);
+ encode_float(p_variant.operator float(), buf);
}
r_len += 4;
diff --git a/core/math/geometry.h b/core/math/geometry.h
index 2469e799a..909d8164c 100644
--- a/core/math/geometry.h
+++ b/core/math/geometry.h
@@ -105,23 +105,23 @@ public:
}
static void get_closest_points_between_segments(const Vector3 &p1, const Vector3 &p2, const Vector3 &q1, const Vector3 &q2, Vector3 &c1, Vector3 &c2) {
-#if 0
- //do the function 'd' as defined by pb. I think is is dot product of some sort
+#if 1
+//do the function 'd' as defined by pb. I think is is dot product of some sort
#define d_of(m, n, o, p) ((m.x - n.x) * (o.x - p.x) + (m.y - n.y) * (o.y - p.y) + (m.z - n.z) * (o.z - p.z))
//calculate the parametric position on the 2 curves, mua and mub
- real_t mua = ( d_of(p1,q1,q2,q1) * d_of(q2,q1,p2,p1) - d_of(p1,q1,p2,p1) * d_of(q2,q1,q2,q1) ) / ( d_of(p2,p1,p2,p1) * d_of(q2,q1,q2,q1) - d_of(q2,q1,p2,p1) * d_of(q2,q1,p2,p1) );
- real_t mub = ( d_of(p1,q1,q2,q1) + mua * d_of(q2,q1,p2,p1) ) / d_of(q2,q1,q2,q1);
+ real_t mua = (d_of(p1, q1, q2, q1) * d_of(q2, q1, p2, p1) - d_of(p1, q1, p2, p1) * d_of(q2, q1, q2, q1)) / (d_of(p2, p1, p2, p1) * d_of(q2, q1, q2, q1) - d_of(q2, q1, p2, p1) * d_of(q2, q1, p2, p1));
+ real_t mub = (d_of(p1, q1, q2, q1) + mua * d_of(q2, q1, p2, p1)) / d_of(q2, q1, q2, q1);
//clip the value between [0..1] constraining the solution to lie on the original curves
if (mua < 0) mua = 0;
if (mub < 0) mub = 0;
if (mua > 1) mua = 1;
if (mub > 1) mub = 1;
- c1 = p1.linear_interpolate(p2,mua);
- c2 = q1.linear_interpolate(q2,mub);
-#endif
-
+ c1 = p1.linear_interpolate(p2, mua);
+ c2 = q1.linear_interpolate(q2, mub);
+#else
+ //this is broken do not use
Vector3 u = p2 - p1;
Vector3 v = q2 - q1;
Vector3 w = p1 - q1;
@@ -144,8 +144,9 @@ public:
c1 = w + sc * u;
c2 = w + tc * v;
- // get the difference of the two closest points
- //Vector dP = w + (sc * u) - (tc * v); // = L1(sc) - L2(tc)
+// get the difference of the two closest points
+//Vector dP = w + (sc * u) - (tc * v); // = L1(sc) - L2(tc)
+#endif
}
static real_t get_closest_distance_between_segments(const Vector3 &p_from_a, const Vector3 &p_to_a, const Vector3 &p_from_b, const Vector3 &p_to_b) {
diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp
index 6a46b9fbe..9f5a9c193 100644
--- a/core/math/math_funcs.cpp
+++ b/core/math/math_funcs.cpp
@@ -30,7 +30,7 @@
#include "math_funcs.h"
#include "core/os/os.h"
-pcg32_random_t Math::default_pcg = { 1, PCG_DEFAULT_INC_64 };
+pcg32_random_t Math::default_pcg = { 12047754176567800795ULL, PCG_DEFAULT_INC_64 };
#define PHI 0x9e3779b9
@@ -51,9 +51,7 @@ void Math::seed(uint64_t x) {
}
void Math::randomize() {
-
- OS::Time time = OS::get_singleton()->get_time();
- seed(OS::get_singleton()->get_ticks_usec() * (time.hour + 1) * (time.min + 1) * (time.sec + 1) * rand()); // TODO: can be simplified.
+ seed(OS::get_singleton()->get_ticks_usec() * default_pcg.state + PCG_DEFAULT_INC_64);
}
uint32_t Math::rand() {
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index 10426c924..d71d9bd79 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -157,7 +157,7 @@ public:
static uint32_t larger_prime(uint32_t p_val);
- static void seed(uint64_t x = 0);
+ static void seed(uint64_t x);
static void randomize();
static uint32_t rand_from_seed(uint64_t *seed);
static uint32_t rand();
diff --git a/core/os/input.cpp b/core/os/input.cpp
index 6215ad373..bc388d0bc 100644
--- a/core/os/input.cpp
+++ b/core/os/input.cpp
@@ -75,7 +75,7 @@ void Input::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_accelerometer"), &Input::get_accelerometer);
ClassDB::bind_method(D_METHOD("get_magnetometer"), &Input::get_magnetometer);
ClassDB::bind_method(D_METHOD("get_gyroscope"), &Input::get_gyroscope);
- //ClassDB::bind_method(D_METHOD("get_mouse_pos"),&Input::get_mouse_pos); - this is not the function you want
+ //ClassDB::bind_method(D_METHOD("get_mouse_position"),&Input::get_mouse_position); - this is not the function you want
ClassDB::bind_method(D_METHOD("get_last_mouse_speed"), &Input::get_last_mouse_speed);
ClassDB::bind_method(D_METHOD("get_mouse_button_mask"), &Input::get_mouse_button_mask);
ClassDB::bind_method(D_METHOD("set_mouse_mode", "mode"), &Input::set_mouse_mode);
diff --git a/core/os/input.h b/core/os/input.h
index 4b297a7ee..4f26f097c 100644
--- a/core/os/input.h
+++ b/core/os/input.h
@@ -77,7 +77,7 @@ public:
virtual void start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration = 0) = 0;
virtual void stop_joy_vibration(int p_device) = 0;
- virtual Point2 get_mouse_pos() const = 0;
+ virtual Point2 get_mouse_position() const = 0;
virtual Point2 get_last_mouse_speed() const = 0;
virtual int get_mouse_button_mask() const = 0;
diff --git a/core/os/os.cpp b/core/os/os.cpp
index ab03bb801..e323e0382 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -507,7 +507,6 @@ OS::OS() {
_render_thread_mode = RENDER_THREAD_SAFE;
_allow_hidpi = true;
- Math::seed(1234567);
}
OS::~OS() {
diff --git a/core/os/os.h b/core/os/os.h
index 0abc91e35..ff2a24f40 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -144,7 +144,7 @@ public:
virtual MouseMode get_mouse_mode() const;
virtual void warp_mouse_pos(const Point2 &p_to) {}
- virtual Point2 get_mouse_pos() const = 0;
+ virtual Point2 get_mouse_position() const = 0;
virtual int get_mouse_button_state() const = 0;
virtual void set_window_title(const String &p_title) = 0;
diff --git a/core/variant.cpp b/core/variant.cpp
index 6e675d07d..67ce8af48 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -2839,7 +2839,7 @@ uint32_t Variant::hash() const {
}
#define hash_compare_scalar(p_lhs, p_rhs) \
- ((p_lhs) == (p_rhs)) || (Math::is_nan(p_lhs) == Math::is_nan(p_rhs))
+ ((p_lhs) == (p_rhs)) || (Math::is_nan(p_lhs) && Math::is_nan(p_rhs))
#define hash_compare_vector2(p_lhs, p_rhs) \
(hash_compare_scalar((p_lhs).x, (p_rhs).x)) && \