summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/input_map.cpp2
-rw-r--r--core/io/compression.cpp2
-rw-r--r--core/io/file_access_memory.cpp2
-rw-r--r--core/io/file_access_network.cpp2
-rw-r--r--core/io/packet_peer.cpp2
-rw-r--r--core/io/resource_format_binary.cpp2
-rw-r--r--core/io/resource_saver.cpp2
-rw-r--r--core/math/camera_matrix.cpp124
-rw-r--r--core/math/camera_matrix.h2
-rw-r--r--core/math/face3.h24
-rw-r--r--core/os/dir_access.cpp2
-rw-r--r--core/os/file_access.cpp2
-rw-r--r--core/os/input.cpp2
-rw-r--r--core/os/memory.cpp40
-rw-r--r--core/os/memory.h12
-rw-r--r--core/register_core_types.cpp2
-rw-r--r--core/safe_refcount.cpp56
-rw-r--r--core/safe_refcount.h2
-rw-r--r--core/script_debugger_remote.cpp2
-rw-r--r--core/translation.cpp2
20 files changed, 215 insertions, 71 deletions
diff --git a/core/input_map.cpp b/core/input_map.cpp
index 1abe019167..24d0624e98 100644
--- a/core/input_map.cpp
+++ b/core/input_map.cpp
@@ -29,8 +29,8 @@
/*************************************************************************/
#include "input_map.h"
-#include "project_settings.h"
#include "os/keyboard.h"
+#include "project_settings.h"
InputMap *InputMap::singleton = NULL;
diff --git a/core/io/compression.cpp b/core/io/compression.cpp
index ca35ece8f5..139383710c 100644
--- a/core/io/compression.cpp
+++ b/core/io/compression.cpp
@@ -28,8 +28,8 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "compression.h"
-#include "project_settings.h"
#include "os/copymem.h"
+#include "project_settings.h"
#include "zip_io.h"
#include "thirdparty/misc/fastlz.h"
diff --git a/core/io/file_access_memory.cpp b/core/io/file_access_memory.cpp
index 2197b187eb..8e719568e5 100644
--- a/core/io/file_access_memory.cpp
+++ b/core/io/file_access_memory.cpp
@@ -29,10 +29,10 @@
/*************************************************************************/
#include "file_access_memory.h"
-#include "project_settings.h"
#include "map.h"
#include "os/copymem.h"
#include "os/dir_access.h"
+#include "project_settings.h"
static Map<String, Vector<uint8_t> > *files = NULL;
diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp
index 46457d1425..aa67479d7e 100644
--- a/core/io/file_access_network.cpp
+++ b/core/io/file_access_network.cpp
@@ -28,10 +28,10 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "file_access_network.h"
-#include "project_settings.h"
#include "io/ip.h"
#include "marshalls.h"
#include "os/os.h"
+#include "project_settings.h"
//#define DEBUG_PRINT(m_p) print_line(m_p)
//#define DEBUG_TIME(m_what) printf("MS: %s - %lli\n",m_what,OS::get_singleton()->get_ticks_usec());
diff --git a/core/io/packet_peer.cpp b/core/io/packet_peer.cpp
index 81446a3886..a3d33593dd 100644
--- a/core/io/packet_peer.cpp
+++ b/core/io/packet_peer.cpp
@@ -29,8 +29,8 @@
/*************************************************************************/
#include "packet_peer.h"
-#include "project_settings.h"
#include "io/marshalls.h"
+#include "project_settings.h"
/* helpers / binders */
PacketPeer::PacketPeer() {
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index 602cbe6f30..9aa16ed7e7 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -28,11 +28,11 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "resource_format_binary.h"
-#include "project_settings.h"
#include "image.h"
#include "io/file_access_compressed.h"
#include "io/marshalls.h"
#include "os/dir_access.h"
+#include "project_settings.h"
#include "version.h"
//#define print_bl(m_what) print_line(m_what)
#define print_bl(m_what)
diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp
index 58913b80cc..314259b2e9 100644
--- a/core/io/resource_saver.cpp
+++ b/core/io/resource_saver.cpp
@@ -28,8 +28,8 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "resource_saver.h"
-#include "project_settings.h"
#include "os/file_access.h"
+#include "project_settings.h"
#include "resource_loader.h"
#include "script_language.h"
diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp
index 33ad522315..a1666ccd8b 100644
--- a/core/math/camera_matrix.cpp
+++ b/core/math/camera_matrix.cpp
@@ -91,6 +91,72 @@ void CameraMatrix::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_
matrix[3][3] = 0;
}
+void CameraMatrix::set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov, int p_eye, real_t p_intraocular_dist, real_t p_convergence_dist) {
+ if (p_flip_fov) {
+ p_fovy_degrees = get_fovy(p_fovy_degrees, 1.0 / p_aspect);
+ }
+
+ real_t left, right, modeltranslation, ymax, xmax, frustumshift;
+
+ ymax = p_z_near * tan(p_fovy_degrees * Math_PI / 360.0f);
+ xmax = ymax * p_aspect;
+ frustumshift = (p_intraocular_dist / 2.0) * p_z_near / p_convergence_dist;
+
+ switch (p_eye) {
+ case 1: { // left eye
+ left = -xmax + frustumshift;
+ right = xmax + frustumshift;
+ modeltranslation = p_intraocular_dist / 2.0;
+ }; break;
+ case 2: { // right eye
+ left = -xmax - frustumshift;
+ right = xmax - frustumshift;
+ modeltranslation = -p_intraocular_dist / 2.0;
+ }; break;
+ default: { // mono, should give the same result as set_perspective(p_fovy_degrees,p_aspect,p_z_near,p_z_far,p_flip_fov)
+ left = -xmax;
+ right = xmax;
+ modeltranslation = 0.0;
+ }; break;
+ };
+
+ set_frustum(left, right, -ymax, ymax, p_z_near, p_z_far);
+
+ // translate matrix by (modeltranslation, 0.0, 0.0)
+ CameraMatrix cm;
+ cm.set_identity();
+ cm.matrix[3][0] = modeltranslation;
+ *this = *this * cm;
+}
+
+void CameraMatrix::set_for_hmd(int p_eye, real_t p_aspect, real_t p_intraocular_dist, real_t p_display_width, real_t p_display_to_lens, real_t p_oversample, real_t p_z_near, real_t p_z_far) {
+ // we first calculate our base frustum on our values without taking our lens magnification into account.
+ real_t display_to_eye = 2.0 * p_display_to_lens;
+ real_t f1 = (p_intraocular_dist * 0.5) / p_display_to_lens;
+ real_t f2 = ((p_display_width - p_intraocular_dist) * 0.5) / p_display_to_lens;
+ real_t f3 = (p_display_width / 4.0) / p_display_to_lens;
+
+ // now we apply our oversample factor to increase our FOV. how much we oversample is always a balance we strike between performance and how much
+ // we're willing to sacrifice in FOV.
+ real_t add = ((f1 + f2) * (p_oversample - 1.0)) / 2.0;
+ f1 += add;
+ f2 += add;
+
+ // always apply KEEP_WIDTH aspect ratio
+ f3 *= p_aspect;
+
+ switch (p_eye) {
+ case 1: { // left eye
+ set_frustum(-f2 * p_z_near, f1 * p_z_near, -f3 * p_z_near, f3 * p_z_near, p_z_near, p_z_far);
+ }; break;
+ case 2: { // right eye
+ set_frustum(-f1 * p_z_near, f2 * p_z_near, -f3 * p_z_near, f3 * p_z_near, p_z_near, p_z_far);
+ }; break;
+ default: { // mono, does not apply here!
+ }; break;
+ };
+};
+
void CameraMatrix::set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_znear, real_t p_zfar) {
set_identity();
@@ -243,23 +309,44 @@ bool CameraMatrix::get_endpoints(const Transform &p_transform, Vector3 *p_8point
-matrix[15] + matrix[13]);
top_plane.normalize();
- Vector3 near_endpoint;
- Vector3 far_endpoint;
+ Vector3 near_endpoint_left, near_endpoint_right;
+ Vector3 far_endpoint_left, far_endpoint_right;
- bool res = near_plane.intersect_3(right_plane, top_plane, &near_endpoint);
+ bool res = near_plane.intersect_3(right_plane, top_plane, &near_endpoint_right);
ERR_FAIL_COND_V(!res, false);
- res = far_plane.intersect_3(right_plane, top_plane, &far_endpoint);
+ res = far_plane.intersect_3(right_plane, top_plane, &far_endpoint_right);
ERR_FAIL_COND_V(!res, false);
- p_8points[0] = p_transform.xform(Vector3(near_endpoint.x, near_endpoint.y, near_endpoint.z));
- p_8points[1] = p_transform.xform(Vector3(near_endpoint.x, -near_endpoint.y, near_endpoint.z));
- p_8points[2] = p_transform.xform(Vector3(-near_endpoint.x, near_endpoint.y, near_endpoint.z));
- p_8points[3] = p_transform.xform(Vector3(-near_endpoint.x, -near_endpoint.y, near_endpoint.z));
- p_8points[4] = p_transform.xform(Vector3(far_endpoint.x, far_endpoint.y, far_endpoint.z));
- p_8points[5] = p_transform.xform(Vector3(far_endpoint.x, -far_endpoint.y, far_endpoint.z));
- p_8points[6] = p_transform.xform(Vector3(-far_endpoint.x, far_endpoint.y, far_endpoint.z));
- p_8points[7] = p_transform.xform(Vector3(-far_endpoint.x, -far_endpoint.y, far_endpoint.z));
+ if ((matrix[8] == 0) && (matrix[9] == 0)) {
+ near_endpoint_left = near_endpoint_right;
+ near_endpoint_left.x = -near_endpoint_left.x;
+
+ far_endpoint_left = far_endpoint_right;
+ far_endpoint_left.x = -far_endpoint_left.x;
+ } else {
+ ///////--- Left Plane ---///////
+ Plane left_plane = Plane(matrix[0] + matrix[3],
+ matrix[4] + matrix[7],
+ matrix[8] + matrix[11],
+ -matrix[15] - matrix[12]);
+ left_plane.normalize();
+
+ res = near_plane.intersect_3(left_plane, top_plane, &near_endpoint_left);
+ ERR_FAIL_COND_V(!res, false);
+
+ res = far_plane.intersect_3(left_plane, top_plane, &far_endpoint_left);
+ ERR_FAIL_COND_V(!res, false);
+ }
+
+ p_8points[0] = p_transform.xform(Vector3(near_endpoint_right.x, near_endpoint_right.y, near_endpoint_right.z));
+ p_8points[1] = p_transform.xform(Vector3(near_endpoint_right.x, -near_endpoint_right.y, near_endpoint_right.z));
+ p_8points[2] = p_transform.xform(Vector3(near_endpoint_left.x, near_endpoint_left.y, near_endpoint_left.z));
+ p_8points[3] = p_transform.xform(Vector3(near_endpoint_left.x, -near_endpoint_left.y, near_endpoint_left.z));
+ p_8points[4] = p_transform.xform(Vector3(far_endpoint_right.x, far_endpoint_right.y, far_endpoint_right.z));
+ p_8points[5] = p_transform.xform(Vector3(far_endpoint_right.x, -far_endpoint_right.y, far_endpoint_right.z));
+ p_8points[6] = p_transform.xform(Vector3(far_endpoint_left.x, far_endpoint_left.y, far_endpoint_left.z));
+ p_8points[7] = p_transform.xform(Vector3(far_endpoint_left.x, -far_endpoint_left.y, far_endpoint_left.z));
return true;
}
@@ -546,7 +633,18 @@ real_t CameraMatrix::get_fov() const {
-matrix[15] + matrix[12]);
right_plane.normalize();
- return Math::rad2deg(Math::acos(Math::abs(right_plane.normal.x))) * 2.0;
+ if ((matrix[8] == 0) && (matrix[9] == 0)) {
+ return Math::rad2deg(Math::acos(Math::abs(right_plane.normal.x))) * 2.0;
+ } else {
+ // our frustum is asymetrical need to calculate the left planes angle seperately..
+ Plane left_plane = Plane(matrix[3] + matrix[0],
+ matrix[7] + matrix[4],
+ matrix[11] + matrix[8],
+ matrix[15] + matrix[12]);
+ left_plane.normalize();
+
+ return Math::rad2deg(Math::acos(Math::abs(left_plane.normal.x))) + Math::rad2deg(Math::acos(Math::abs(right_plane.normal.x)));
+ }
}
void CameraMatrix::make_scale(const Vector3 &p_scale) {
diff --git a/core/math/camera_matrix.h b/core/math/camera_matrix.h
index af61e35993..4be8ffab8c 100644
--- a/core/math/camera_matrix.h
+++ b/core/math/camera_matrix.h
@@ -54,6 +54,8 @@ struct CameraMatrix {
void set_light_bias();
void set_light_atlas_rect(const Rect2 &p_rect);
void set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov = false);
+ void set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov, int p_eye, real_t p_intraocular_dist, real_t p_convergence_dist);
+ void set_for_hmd(int p_eye, real_t p_aspect, real_t p_intraocular_dist, real_t p_display_width, real_t p_display_to_lens, real_t p_oversample, real_t p_z_near, real_t p_z_far);
void set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_znear, real_t p_zfar);
void set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear, real_t p_zfar, bool p_flip_fov = false);
void set_frustum(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_near, real_t p_far);
diff --git a/core/math/face3.h b/core/math/face3.h
index 1cc94321c3..3d02ae4014 100644
--- a/core/math/face3.h
+++ b/core/math/face3.h
@@ -115,20 +115,20 @@ bool Face3::intersects_aabb2(const Rect3 &p_aabb) const {
if (dist_a * dist_b > 0)
return false; //does not intersect the plane
-#define TEST_AXIS(m_ax) \
- { \
+#define TEST_AXIS(m_ax) \
+ { \
real_t aabb_min = p_aabb.position.m_ax; \
real_t aabb_max = p_aabb.position.m_ax + p_aabb.size.m_ax; \
- real_t tri_min, tri_max; \
- for (int i = 0; i < 3; i++) { \
- if (i == 0 || vertex[i].m_ax > tri_max) \
- tri_max = vertex[i].m_ax; \
- if (i == 0 || vertex[i].m_ax < tri_min) \
- tri_min = vertex[i].m_ax; \
- } \
- \
- if (tri_max < aabb_min || aabb_max < tri_min) \
- return false; \
+ real_t tri_min, tri_max; \
+ for (int i = 0; i < 3; i++) { \
+ if (i == 0 || vertex[i].m_ax > tri_max) \
+ tri_max = vertex[i].m_ax; \
+ if (i == 0 || vertex[i].m_ax < tri_min) \
+ tri_min = vertex[i].m_ax; \
+ } \
+ \
+ if (tri_max < aabb_min || aabb_max < tri_min) \
+ return false; \
}
TEST_AXIS(x);
diff --git a/core/os/dir_access.cpp b/core/os/dir_access.cpp
index 484942bad5..391ae78c85 100644
--- a/core/os/dir_access.cpp
+++ b/core/os/dir_access.cpp
@@ -28,10 +28,10 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "dir_access.h"
-#include "project_settings.h"
#include "os/file_access.h"
#include "os/memory.h"
#include "os/os.h"
+#include "project_settings.h"
String DirAccess::_get_root_path() const {
diff --git a/core/os/file_access.cpp b/core/os/file_access.cpp
index 7f5a84843c..3bd5ac3f41 100644
--- a/core/os/file_access.cpp
+++ b/core/os/file_access.cpp
@@ -31,8 +31,8 @@
#include "core/io/file_access_pack.h"
#include "core/io/marshalls.h"
-#include "project_settings.h"
#include "os/os.h"
+#include "project_settings.h"
#include "thirdparty/misc/md5.h"
#include "thirdparty/misc/sha256.h"
diff --git a/core/os/input.cpp b/core/os/input.cpp
index 18d644668c..a90a552d1d 100644
--- a/core/os/input.cpp
+++ b/core/os/input.cpp
@@ -28,9 +28,9 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "input.h"
-#include "project_settings.h"
#include "input_map.h"
#include "os/os.h"
+#include "project_settings.h"
Input *Input::singleton = NULL;
Input *Input::get_singleton() {
diff --git a/core/os/memory.cpp b/core/os/memory.cpp
index 069ee48fae..acc960acd9 100644
--- a/core/os/memory.cpp
+++ b/core/os/memory.cpp
@@ -29,6 +29,7 @@
/*************************************************************************/
#include "memory.h"
#include "copymem.h"
+#include "core/safe_refcount.h"
#include "error_macros.h"
#include <stdio.h>
#include <stdlib.h>
@@ -43,14 +44,12 @@ void *operator new(size_t p_size, void *(*p_allocfunc)(size_t p_size)) {
return p_allocfunc(p_size);
}
-#include <stdio.h>
-
#ifdef DEBUG_ENABLED
-size_t Memory::mem_usage = 0;
-size_t Memory::max_usage = 0;
+uint64_t Memory::mem_usage = 0;
+uint64_t Memory::max_usage = 0;
#endif
-size_t Memory::alloc_count = 0;
+uint64_t Memory::alloc_count = 0;
void *Memory::alloc_static(size_t p_bytes, bool p_pad_align) {
@@ -62,10 +61,10 @@ void *Memory::alloc_static(size_t p_bytes, bool p_pad_align) {
void *mem = malloc(p_bytes + (prepad ? PAD_ALIGN : 0));
- alloc_count++;
-
ERR_FAIL_COND_V(!mem, NULL);
+ atomic_increment(&alloc_count);
+
if (prepad) {
uint64_t *s = (uint64_t *)mem;
*s = p_bytes;
@@ -73,10 +72,8 @@ void *Memory::alloc_static(size_t p_bytes, bool p_pad_align) {
uint8_t *s8 = (uint8_t *)mem;
#ifdef DEBUG_ENABLED
- mem_usage += p_bytes;
- if (mem_usage > max_usage) {
- max_usage = mem_usage;
- }
+ atomic_add(&mem_usage, p_bytes);
+ atomic_exchange_if_greater(&max_usage, mem_usage);
#endif
return s8 + PAD_ALIGN;
} else {
@@ -103,8 +100,12 @@ void *Memory::realloc_static(void *p_memory, size_t p_bytes, bool p_pad_align) {
uint64_t *s = (uint64_t *)mem;
#ifdef DEBUG_ENABLED
- mem_usage -= *s;
- mem_usage += p_bytes;
+ if (p_bytes > *s) {
+ atomic_add(&mem_usage, p_bytes - *s);
+ atomic_exchange_if_greater(&max_usage, mem_usage);
+ } else {
+ atomic_sub(&mem_usage, *s - p_bytes);
+ }
#endif
if (p_bytes == 0) {
@@ -144,14 +145,14 @@ void Memory::free_static(void *p_ptr, bool p_pad_align) {
bool prepad = p_pad_align;
#endif
- alloc_count--;
+ atomic_decrement(&alloc_count);
if (prepad) {
mem -= PAD_ALIGN;
uint64_t *s = (uint64_t *)mem;
#ifdef DEBUG_ENABLED
- mem_usage -= *s;
+ atomic_sub(&mem_usage, *s);
#endif
free(mem);
@@ -161,19 +162,20 @@ void Memory::free_static(void *p_ptr, bool p_pad_align) {
}
}
-size_t Memory::get_mem_available() {
+uint64_t Memory::get_mem_available() {
- return 0xFFFFFFFFFFFFF;
+ return -1; // 0xFFFF...
}
-size_t Memory::get_mem_usage() {
+uint64_t Memory::get_mem_usage() {
#ifdef DEBUG_ENABLED
return mem_usage;
#else
return 0;
#endif
}
-size_t Memory::get_mem_max_usage() {
+
+uint64_t Memory::get_mem_max_usage() {
#ifdef DEBUG_ENABLED
return max_usage;
#else
diff --git a/core/os/memory.h b/core/os/memory.h
index b3eb599955..e1d7138ad5 100644
--- a/core/os/memory.h
+++ b/core/os/memory.h
@@ -45,20 +45,20 @@ class Memory {
Memory();
#ifdef DEBUG_ENABLED
- static size_t mem_usage;
- static size_t max_usage;
+ static uint64_t mem_usage;
+ static uint64_t max_usage;
#endif
- static size_t alloc_count;
+ static uint64_t alloc_count;
public:
static void *alloc_static(size_t p_bytes, bool p_pad_align = false);
static void *realloc_static(void *p_memory, size_t p_bytes, bool p_pad_align = false);
static void free_static(void *p_ptr, bool p_pad_align = false);
- static size_t get_mem_available();
- static size_t get_mem_usage();
- static size_t get_mem_max_usage();
+ static uint64_t get_mem_available();
+ static uint64_t get_mem_usage();
+ static uint64_t get_mem_max_usage();
};
class DefaultAllocator {
diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp
index 07715f9718..43f781af55 100644
--- a/core/register_core_types.cpp
+++ b/core/register_core_types.cpp
@@ -36,7 +36,6 @@
#include "core_string_names.h"
#include "func_ref.h"
#include "geometry.h"
-#include "project_settings.h"
#include "input_map.h"
#include "io/config_file.h"
#include "io/http_client.h"
@@ -54,6 +53,7 @@
#include "os/main_loop.h"
#include "packed_data_container.h"
#include "path_remap.h"
+#include "project_settings.h"
#include "translation.h"
#include "undo_redo.h"
diff --git a/core/safe_refcount.cpp b/core/safe_refcount.cpp
index d7e5297321..971e9ad1d5 100644
--- a/core/safe_refcount.cpp
+++ b/core/safe_refcount.cpp
@@ -78,6 +78,15 @@ static _ALWAYS_INLINE_ T _atomic_add_impl(register T *pw, register T val) {
return *pw;
}
+template <class T>
+static _ALWAYS_INLINE_ T _atomic_exchange_if_greater_impl(register T *pw, register T val) {
+
+ if (val > *pw)
+ *pw = val;
+
+ return *pw;
+}
+
#elif defined(__GNUC__)
/* Implementation for GCC & Clang */
@@ -121,6 +130,18 @@ static _ALWAYS_INLINE_ T _atomic_add_impl(register T *pw, register T val) {
return __sync_add_and_fetch(pw, val);
}
+template <class T>
+static _ALWAYS_INLINE_ T _atomic_exchange_if_greater_impl(register T *pw, register T val) {
+
+ while (true) {
+ T tmp = static_cast<T const volatile &>(*pw);
+ if (tmp >= val)
+ return tmp; // already greater, or equal
+ if (__sync_val_compare_and_swap(pw, tmp, val) == tmp)
+ return val;
+ }
+}
+
#elif defined(_MSC_VER)
/* Implementation for MSVC-Windows */
@@ -139,6 +160,15 @@ static _ALWAYS_INLINE_ T _atomic_add_impl(register T *pw, register T val) {
return tmp + 1; \
}
+#define ATOMIC_EXCHANGE_IF_GREATER_BODY(m_pw, m_val, m_win_type, m_win_cmpxchg, m_cpp_type) \
+ while (true) { \
+ m_cpp_type tmp = static_cast<m_cpp_type const volatile &>(*(m_pw)); \
+ if (tmp >= m_val) \
+ return tmp; /* already greater, or equal */ \
+ if (m_win_cmpxchg((m_win_type volatile *)(m_pw), m_val, tmp) == tmp) \
+ return m_val; \
+ }
+
static _ALWAYS_INLINE_ uint32_t _atomic_conditional_increment_impl(register uint32_t *pw) {
ATOMIC_CONDITIONAL_INCREMENT_BODY(pw, LONG, InterlockedCompareExchange, uint32_t)
@@ -156,11 +186,7 @@ static _ALWAYS_INLINE_ uint32_t _atomic_increment_impl(register uint32_t *pw) {
static _ALWAYS_INLINE_ uint32_t _atomic_sub_impl(register uint32_t *pw, register uint32_t val) {
-#if _WIN32_WINNT >= 0x0601 // Windows 7+
- return InterlockedExchangeSubtract(pw, val) - val;
-#else
return InterlockedExchangeAdd((LONG volatile *)pw, -(int32_t)val) - val;
-#endif
}
static _ALWAYS_INLINE_ uint32_t _atomic_add_impl(register uint32_t *pw, register uint32_t val) {
@@ -168,6 +194,11 @@ static _ALWAYS_INLINE_ uint32_t _atomic_add_impl(register uint32_t *pw, register
return InterlockedAdd((LONG volatile *)pw, val);
}
+static _ALWAYS_INLINE_ uint32_t _atomic_exchange_if_greater_impl(register uint32_t *pw, register uint32_t val) {
+
+ ATOMIC_EXCHANGE_IF_GREATER_BODY(pw, val, LONG, InterlockedCompareExchange, uint32_t)
+}
+
static _ALWAYS_INLINE_ uint64_t _atomic_conditional_increment_impl(register uint64_t *pw) {
ATOMIC_CONDITIONAL_INCREMENT_BODY(pw, LONGLONG, InterlockedCompareExchange64, uint64_t)
@@ -185,11 +216,7 @@ static _ALWAYS_INLINE_ uint64_t _atomic_increment_impl(register uint64_t *pw) {
static _ALWAYS_INLINE_ uint64_t _atomic_sub_impl(register uint64_t *pw, register uint64_t val) {
-#if _WIN32_WINNT >= 0x0601 && !defined(UWP_ENABLED) // Windows 7+ except UWP
- return InterlockedExchangeSubtract64(pw, val) - val;
-#else
return InterlockedExchangeAdd64((LONGLONG volatile *)pw, -(int64_t)val) - val;
-#endif
}
static _ALWAYS_INLINE_ uint64_t _atomic_add_impl(register uint64_t *pw, register uint64_t val) {
@@ -197,6 +224,11 @@ static _ALWAYS_INLINE_ uint64_t _atomic_add_impl(register uint64_t *pw, register
return InterlockedAdd64((LONGLONG volatile *)pw, val);
}
+static _ALWAYS_INLINE_ uint64_t _atomic_exchange_if_greater_impl(register uint64_t *pw, register uint64_t val) {
+
+ ATOMIC_EXCHANGE_IF_GREATER_BODY(pw, val, LONGLONG, InterlockedCompareExchange64, uint64_t)
+}
+
#else
//no threads supported?
@@ -226,6 +258,10 @@ uint32_t atomic_add(register uint32_t *pw, register uint32_t val) {
return _atomic_add_impl(pw, val);
}
+uint32_t atomic_exchange_if_greater(register uint32_t *pw, register uint32_t val) {
+ return _atomic_exchange_if_greater_impl(pw, val);
+}
+
uint64_t atomic_conditional_increment(register uint64_t *counter) {
return _atomic_conditional_increment_impl(counter);
}
@@ -245,3 +281,7 @@ uint64_t atomic_sub(register uint64_t *pw, register uint64_t val) {
uint64_t atomic_add(register uint64_t *pw, register uint64_t val) {
return _atomic_add_impl(pw, val);
}
+
+uint64_t atomic_exchange_if_greater(register uint64_t *pw, register uint64_t val) {
+ return _atomic_exchange_if_greater_impl(pw, val);
+}
diff --git a/core/safe_refcount.h b/core/safe_refcount.h
index a2d2b5e127..ed0620c777 100644
--- a/core/safe_refcount.h
+++ b/core/safe_refcount.h
@@ -41,12 +41,14 @@ uint32_t atomic_decrement(register uint32_t *pw);
uint32_t atomic_increment(register uint32_t *pw);
uint32_t atomic_sub(register uint32_t *pw, register uint32_t val);
uint32_t atomic_add(register uint32_t *pw, register uint32_t val);
+uint32_t atomic_exchange_if_greater(register uint32_t *pw, register uint32_t val);
uint64_t atomic_conditional_increment(register uint64_t *counter);
uint64_t atomic_decrement(register uint64_t *pw);
uint64_t atomic_increment(register uint64_t *pw);
uint64_t atomic_sub(register uint64_t *pw, register uint64_t val);
uint64_t atomic_add(register uint64_t *pw, register uint64_t val);
+uint64_t atomic_exchange_if_greater(register uint64_t *pw, register uint64_t val);
struct SafeRefCount {
diff --git a/core/script_debugger_remote.cpp b/core/script_debugger_remote.cpp
index dec41e7976..d19fe213f6 100644
--- a/core/script_debugger_remote.cpp
+++ b/core/script_debugger_remote.cpp
@@ -29,10 +29,10 @@
/*************************************************************************/
#include "script_debugger_remote.h"
-#include "project_settings.h"
#include "io/ip.h"
#include "os/input.h"
#include "os/os.h"
+#include "project_settings.h"
void ScriptDebuggerRemote::_send_video_memory() {
diff --git a/core/translation.cpp b/core/translation.cpp
index d782006ddc..50694e4a2d 100644
--- a/core/translation.cpp
+++ b/core/translation.cpp
@@ -29,9 +29,9 @@
/*************************************************************************/
#include "translation.h"
-#include "project_settings.h"
#include "io/resource_loader.h"
#include "os/os.h"
+#include "project_settings.h"
static const char *locale_list[] = {
"aa", // Afar