summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/class_db.cpp9
-rw-r--r--core/hash_map.h17
-rw-r--r--core/os/file_access.cpp55
-rw-r--r--core/os/os.cpp11
-rw-r--r--core/os/os.h13
5 files changed, 89 insertions, 16 deletions
diff --git a/core/class_db.cpp b/core/class_db.cpp
index edd49fe95f..b18e3d2b65 100644
--- a/core/class_db.cpp
+++ b/core/class_db.cpp
@@ -348,10 +348,11 @@ uint64_t ClassDB::get_api_hash(APIType p_api) {
hash = hash_djb2_one_64(mb->get_argument_type(-1), hash); //return
for (int i = 0; i < mb->get_argument_count(); i++) {
- hash = hash_djb2_one_64(mb->get_argument_info(i).type, hash);
- hash = hash_djb2_one_64(mb->get_argument_info(i).name.hash(), hash);
- hash = hash_djb2_one_64(mb->get_argument_info(i).hint, hash);
- hash = hash_djb2_one_64(mb->get_argument_info(i).hint_string.hash(), hash);
+ const PropertyInfo info = mb->get_argument_info(i);
+ hash = hash_djb2_one_64(info.type, hash);
+ hash = hash_djb2_one_64(info.name.hash(), hash);
+ hash = hash_djb2_one_64(info.hint, hash);
+ hash = hash_djb2_one_64(info.hint_string.hash(), hash);
}
hash = hash_djb2_one_64(mb->get_default_argument_count(), hash);
diff --git a/core/hash_map.h b/core/hash_map.h
index a53cb53c84..3ec3961d73 100644
--- a/core/hash_map.h
+++ b/core/hash_map.h
@@ -313,7 +313,7 @@ public:
_FORCE_INLINE_ TData *getptr(const TKey &p_key) {
- if (!hash_table)
+ if (unlikely(!hash_table))
return NULL;
Element *e = const_cast<Element *>(get_element(p_key));
@@ -326,7 +326,7 @@ public:
_FORCE_INLINE_ const TData *getptr(const TKey &p_key) const {
- if (!hash_table)
+ if (unlikely(!hash_table))
return NULL;
const Element *e = const_cast<Element *>(get_element(p_key));
@@ -345,7 +345,7 @@ public:
template <class C>
_FORCE_INLINE_ TData *custom_getptr(C p_custom_key, uint32_t p_custom_hash) {
- if (!hash_table)
+ if (unlikely(!hash_table))
return NULL;
uint32_t hash = p_custom_hash;
@@ -371,7 +371,7 @@ public:
template <class C>
_FORCE_INLINE_ const TData *custom_getptr(C p_custom_key, uint32_t p_custom_hash) const {
- if (!hash_table)
+ if (unlikely(!hash_table))
return NULL;
uint32_t hash = p_custom_hash;
@@ -400,7 +400,7 @@ public:
bool erase(const TKey &p_key) {
- if (!hash_table)
+ if (unlikely(!hash_table))
return false;
uint32_t hash = Hasher::hash(p_key);
@@ -478,7 +478,8 @@ public:
*/
const TKey *next(const TKey *p_key) const {
- if (!hash_table) return NULL;
+ if (unlikely(!hash_table))
+ return NULL;
if (!p_key) { /* get the first key */
@@ -559,7 +560,7 @@ public:
}
void get_key_value_ptr_array(const Pair **p_pairs) const {
- if (!hash_table)
+ if (unlikely(!hash_table))
return;
for (int i = 0; i < (1 << hash_table_power); i++) {
@@ -573,7 +574,7 @@ public:
}
void get_key_list(List<TKey> *p_keys) const {
- if (!hash_table)
+ if (unlikely(!hash_table))
return;
for (int i = 0; i < (1 << hash_table_power); i++) {
diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp
index 7b2062936b..20c1221f2b 100644
--- a/core/os/file_access.cpp
+++ b/core/os/file_access.cpp
@@ -273,9 +273,62 @@ String FileAccess::get_token() const {
return String::utf8(token.get_data());
}
+class CharBuffer {
+ Vector<char> vector;
+ char stack_buffer[256];
+
+ char *buffer;
+ int capacity;
+ int written;
+
+ bool grow() {
+
+ if (vector.resize(next_power_of_2(1 + written)) != OK) {
+
+ return false;
+ }
+
+ if (buffer == stack_buffer) { // first chunk?
+
+ for (int i = 0; i < written; i++) {
+
+ vector[i] = stack_buffer[i];
+ }
+ }
+
+ buffer = vector.ptrw();
+ capacity = vector.size();
+ ERR_FAIL_COND_V(written >= capacity, false);
+
+ return true;
+ }
+
+public:
+ _FORCE_INLINE_ CharBuffer() :
+ buffer(stack_buffer),
+ capacity(sizeof(stack_buffer) / sizeof(char)),
+ written(0) {
+ }
+
+ _FORCE_INLINE_ void push_back(char c) {
+
+ if (written >= capacity) {
+
+ ERR_FAIL_COND(!grow());
+ }
+
+ buffer[written++] = c;
+ }
+
+ _FORCE_INLINE_ const char *get_data() const {
+
+ return buffer;
+ }
+};
+
String FileAccess::get_line() const {
- CharString line;
+ CharBuffer line;
CharType c = get_8();
diff --git a/core/os/os.cpp b/core/os/os.cpp
index d81e70e612..7010d44930 100644
--- a/core/os/os.cpp
+++ b/core/os/os.cpp
@@ -536,12 +536,21 @@ String OS::get_joy_guid(int p_device) const {
void OS::set_context(int p_context) {
}
+
+OS::SwitchVSyncCallbackInThread OS::switch_vsync_function = NULL;
+
void OS::set_use_vsync(bool p_enable) {
+ _use_vsync = p_enable;
+ if (switch_vsync_function) { //if a function was set, use function
+ switch_vsync_function(p_enable);
+ } else { //otherwise just call here
+ _set_use_vsync(p_enable);
+ }
}
bool OS::is_vsync_enabled() const {
- return true;
+ return _use_vsync;
}
OS::PowerState OS::get_power_state() {
diff --git a/core/os/os.h b/core/os/os.h
index d9f7b91daa..2faaa6ab8f 100644
--- a/core/os/os.h
+++ b/core/os/os.h
@@ -58,6 +58,7 @@ class OS {
int _exit_code;
int _orientation;
bool _allow_hidpi;
+ bool _use_vsync;
char *last_error;
@@ -435,8 +436,16 @@ public:
virtual void set_context(int p_context);
- virtual void set_use_vsync(bool p_enable);
- virtual bool is_vsync_enabled() const;
+ //amazing hack because OpenGL needs this to be set on a separate thread..
+ //also core can't access servers, so a callback must be used
+ typedef void (*SwitchVSyncCallbackInThread)(bool);
+
+ static SwitchVSyncCallbackInThread switch_vsync_function;
+ void set_use_vsync(bool p_enable);
+ bool is_vsync_enabled() const;
+
+ //real, actual overridable function to switch vsync, which needs to be called from graphics thread if needed
+ virtual void _set_use_vsync(bool p_enable) {}
virtual OS::PowerState get_power_state();
virtual int get_power_seconds_left();