summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/image.cpp176
-rw-r--r--core/image.h4
-rw-r--r--editor/editor_run.cpp17
-rw-r--r--editor/editor_settings.cpp2
-rw-r--r--editor/plugins/mesh_library_editor_plugin.cpp44
-rw-r--r--editor/plugins/mesh_library_editor_plugin.h6
-rw-r--r--modules/gdnative/gdnative_api.json8
-rw-r--r--modules/gdnative/include/nativescript/godot_nativescript.h2
-rw-r--r--modules/gdnative/nativescript/godot_nativescript.cpp4
-rw-r--r--modules/gdnative/nativescript/nativescript.cpp110
-rw-r--r--modules/gdnative/nativescript/nativescript.h18
-rw-r--r--modules/gridmap/grid_map.cpp72
-rw-r--r--modules/gridmap/grid_map.h7
-rw-r--r--modules/gridmap/grid_map_editor_plugin.cpp98
-rw-r--r--modules/gridmap/grid_map_editor_plugin.h9
-rw-r--r--modules/mono/glue/cs_files/Rect2.cs121
-rw-r--r--modules/squish/image_compress_squish.cpp8
-rw-r--r--modules/squish/image_compress_squish.h2
-rw-r--r--platform/android/SCsub6
-rw-r--r--platform/android/detect.py37
-rw-r--r--platform/windows/os_windows.cpp94
-rw-r--r--platform/windows/os_windows.h1
22 files changed, 625 insertions, 221 deletions
diff --git a/core/image.cpp b/core/image.cpp
index e4573c5ebb..7778169995 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -37,6 +37,7 @@
#include "print_string.h"
#include "io/resource_loader.h"
+#include "math_funcs.h"
#include "thirdparty/misc/hq2x.h"
#include <stdio.h>
@@ -525,7 +526,7 @@ static double _bicubic_interp_kernel(double x) {
return bc;
}
-template <int CC>
+template <int CC, class T>
static void _scale_cubic(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) {
// get source image size
@@ -556,7 +557,7 @@ static void _scale_cubic(const uint8_t *__restrict p_src, uint8_t *__restrict p_
// initial pixel value
- uint8_t *__restrict dst = p_dst + (y * p_dst_width + x) * CC;
+ T *__restrict dst = ((T *)p_dst) + (y * p_dst_width + x) * CC;
double color[CC];
for (int i = 0; i < CC; i++) {
@@ -584,23 +585,32 @@ static void _scale_cubic(const uint8_t *__restrict p_src, uint8_t *__restrict p_
ox2 = xmax;
// get pixel of original image
- const uint8_t *__restrict p = p_src + (oy2 * p_src_width + ox2) * CC;
+ const T *__restrict p = ((T *)p_src) + (oy2 * p_src_width + ox2) * CC;
for (int i = 0; i < CC; i++) {
-
- color[i] += p[i] * k2;
+ if (sizeof(T) == 2) { //half float
+ color[i] = Math::half_to_float(p[i]);
+ } else {
+ color[i] += p[i] * k2;
+ }
}
}
}
for (int i = 0; i < CC; i++) {
- dst[i] = CLAMP(Math::fast_ftoi(color[i]), 0, 255);
+ if (sizeof(T) == 1) { //byte
+ dst[i] = CLAMP(Math::fast_ftoi(color[i]), 0, 255);
+ } else if (sizeof(T) == 2) { //half float
+ dst[i] = Math::make_half_float(color[i]);
+ } else {
+ dst[i] = color[i];
+ }
}
}
}
}
-template <int CC>
+template <int CC, class T>
static void _scale_bilinear(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) {
enum {
@@ -640,22 +650,58 @@ static void _scale_bilinear(const uint8_t *__restrict p_src, uint8_t *__restrict
for (uint32_t l = 0; l < CC; l++) {
- uint32_t p00 = p_src[y_ofs_up + src_xofs_left + l] << FRAC_BITS;
- uint32_t p10 = p_src[y_ofs_up + src_xofs_right + l] << FRAC_BITS;
- uint32_t p01 = p_src[y_ofs_down + src_xofs_left + l] << FRAC_BITS;
- uint32_t p11 = p_src[y_ofs_down + src_xofs_right + l] << FRAC_BITS;
-
- uint32_t interp_up = p00 + (((p10 - p00) * src_xofs_frac) >> FRAC_BITS);
- uint32_t interp_down = p01 + (((p11 - p01) * src_xofs_frac) >> FRAC_BITS);
- uint32_t interp = interp_up + (((interp_down - interp_up) * src_yofs_frac) >> FRAC_BITS);
- interp >>= FRAC_BITS;
- p_dst[i * p_dst_width * CC + j * CC + l] = interp;
+ if (sizeof(T) == 1) { //uint8
+ uint32_t p00 = p_src[y_ofs_up + src_xofs_left + l] << FRAC_BITS;
+ uint32_t p10 = p_src[y_ofs_up + src_xofs_right + l] << FRAC_BITS;
+ uint32_t p01 = p_src[y_ofs_down + src_xofs_left + l] << FRAC_BITS;
+ uint32_t p11 = p_src[y_ofs_down + src_xofs_right + l] << FRAC_BITS;
+
+ uint32_t interp_up = p00 + (((p10 - p00) * src_xofs_frac) >> FRAC_BITS);
+ uint32_t interp_down = p01 + (((p11 - p01) * src_xofs_frac) >> FRAC_BITS);
+ uint32_t interp = interp_up + (((interp_down - interp_up) * src_yofs_frac) >> FRAC_BITS);
+ interp >>= FRAC_BITS;
+ p_dst[i * p_dst_width * CC + j * CC + l] = interp;
+ } else if (sizeof(T) == 2) { //half float
+
+ float xofs_frac = float(src_xofs_frac) / (1 << FRAC_BITS);
+ float yofs_frac = float(src_yofs_frac) / (1 << FRAC_BITS);
+ const T *src = ((const T *)p_src);
+ T *dst = ((T *)p_dst);
+
+ float p00 = Math::half_to_float(src[y_ofs_up + src_xofs_left + l]);
+ float p10 = Math::half_to_float(src[y_ofs_up + src_xofs_right + l]);
+ float p01 = Math::half_to_float(src[y_ofs_down + src_xofs_left + l]);
+ float p11 = Math::half_to_float(src[y_ofs_down + src_xofs_right + l]);
+
+ float interp_up = p00 + (p10 - p00) * xofs_frac;
+ float interp_down = p01 + (p11 - p01) * xofs_frac;
+ float interp = interp_up + ((interp_down - interp_up) * yofs_frac);
+
+ dst[i * p_dst_width * CC + j * CC + l] = Math::make_half_float(interp);
+ } else if (sizeof(T) == 4) { //float
+
+ float xofs_frac = float(src_xofs_frac) / (1 << FRAC_BITS);
+ float yofs_frac = float(src_yofs_frac) / (1 << FRAC_BITS);
+ const T *src = ((const T *)p_src);
+ T *dst = ((T *)p_dst);
+
+ float p00 = src[y_ofs_up + src_xofs_left + l];
+ float p10 = src[y_ofs_up + src_xofs_right + l];
+ float p01 = src[y_ofs_down + src_xofs_left + l];
+ float p11 = src[y_ofs_down + src_xofs_right + l];
+
+ float interp_up = p00 + (p10 - p00) * xofs_frac;
+ float interp_down = p01 + (p11 - p01) * xofs_frac;
+ float interp = interp_up + ((interp_down - interp_up) * yofs_frac);
+
+ dst[i * p_dst_width * CC + j * CC + l] = interp;
+ }
}
}
}
}
-template <int CC>
+template <int CC, class T>
static void _scale_nearest(const uint8_t *__restrict p_src, uint8_t *__restrict p_dst, uint32_t p_src_width, uint32_t p_src_height, uint32_t p_dst_width, uint32_t p_dst_height) {
for (uint32_t i = 0; i < p_dst_height; i++) {
@@ -670,8 +716,11 @@ static void _scale_nearest(const uint8_t *__restrict p_src, uint8_t *__restrict
for (uint32_t l = 0; l < CC; l++) {
- uint32_t p = p_src[y_ofs + src_xofs + l];
- p_dst[i * p_dst_width * CC + j * CC + l] = p;
+ const T *src = ((const T *)p_src);
+ T *dst = ((T *)p_dst);
+
+ T p = src[y_ofs + src_xofs + l];
+ dst[i * p_dst_width * CC + j * CC + l] = p;
}
}
}
@@ -766,12 +815,30 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) {
case INTERPOLATE_NEAREST: {
- switch (get_format_pixel_size(format)) {
- case 1: _scale_nearest<1>(r_ptr, w_ptr, width, height, p_width, p_height); break;
- case 2: _scale_nearest<2>(r_ptr, w_ptr, width, height, p_width, p_height); break;
- case 3: _scale_nearest<3>(r_ptr, w_ptr, width, height, p_width, p_height); break;
- case 4: _scale_nearest<4>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ if (format >= FORMAT_L8 && format <= FORMAT_RGBA8) {
+ switch (get_format_pixel_size(format)) {
+ case 1: _scale_nearest<1, uint8_t>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ case 2: _scale_nearest<2, uint8_t>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ case 3: _scale_nearest<3, uint8_t>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ case 4: _scale_nearest<4, uint8_t>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ }
+ } else if (format >= FORMAT_RF && format <= FORMAT_RGBAF) {
+ switch (get_format_pixel_size(format)) {
+ case 4: _scale_nearest<1, float>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ case 8: _scale_nearest<2, float>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ case 12: _scale_nearest<3, float>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ case 16: _scale_nearest<4, float>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ }
+
+ } else if (format >= FORMAT_RH && format <= FORMAT_RGBAH) {
+ switch (get_format_pixel_size(format)) {
+ case 2: _scale_nearest<1, uint16_t>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ case 4: _scale_nearest<2, uint16_t>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ case 6: _scale_nearest<3, uint16_t>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ case 8: _scale_nearest<4, uint16_t>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ }
}
+
} break;
case INTERPOLATE_BILINEAR:
case INTERPOLATE_TRILINEAR: {
@@ -812,11 +879,27 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) {
}
}
- switch (get_format_pixel_size(format)) {
- case 1: _scale_bilinear<1>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break;
- case 2: _scale_bilinear<2>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break;
- case 3: _scale_bilinear<3>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break;
- case 4: _scale_bilinear<4>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break;
+ if (format >= FORMAT_L8 && format <= FORMAT_RGBA8) {
+ switch (get_format_pixel_size(format)) {
+ case 1: _scale_bilinear<1, uint8_t>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break;
+ case 2: _scale_bilinear<2, uint8_t>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break;
+ case 3: _scale_bilinear<3, uint8_t>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break;
+ case 4: _scale_bilinear<4, uint8_t>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break;
+ }
+ } else if (format >= FORMAT_RF && format <= FORMAT_RGBAF) {
+ switch (get_format_pixel_size(format)) {
+ case 4: _scale_bilinear<1, float>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break;
+ case 8: _scale_bilinear<2, float>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break;
+ case 12: _scale_bilinear<3, float>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break;
+ case 16: _scale_bilinear<4, float>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break;
+ }
+ } else if (format >= FORMAT_RH && format <= FORMAT_RGBAH) {
+ switch (get_format_pixel_size(format)) {
+ case 2: _scale_bilinear<1, uint16_t>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break;
+ case 4: _scale_bilinear<2, uint16_t>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break;
+ case 6: _scale_bilinear<3, uint16_t>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break;
+ case 8: _scale_bilinear<4, uint16_t>(src_ptr, w_ptr, src_width, src_height, p_width, p_height); break;
+ }
}
}
@@ -829,13 +912,28 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) {
} break;
case INTERPOLATE_CUBIC: {
- switch (get_format_pixel_size(format)) {
- case 1: _scale_cubic<1>(r_ptr, w_ptr, width, height, p_width, p_height); break;
- case 2: _scale_cubic<2>(r_ptr, w_ptr, width, height, p_width, p_height); break;
- case 3: _scale_cubic<3>(r_ptr, w_ptr, width, height, p_width, p_height); break;
- case 4: _scale_cubic<4>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ if (format >= FORMAT_L8 && format <= FORMAT_RGBA8) {
+ switch (get_format_pixel_size(format)) {
+ case 1: _scale_cubic<1, uint8_t>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ case 2: _scale_cubic<2, uint8_t>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ case 3: _scale_cubic<3, uint8_t>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ case 4: _scale_cubic<4, uint8_t>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ }
+ } else if (format >= FORMAT_RF && format <= FORMAT_RGBAF) {
+ switch (get_format_pixel_size(format)) {
+ case 4: _scale_cubic<1, float>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ case 8: _scale_cubic<2, float>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ case 12: _scale_cubic<3, float>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ case 16: _scale_cubic<4, float>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ }
+ } else if (format >= FORMAT_RH && format <= FORMAT_RGBAH) {
+ switch (get_format_pixel_size(format)) {
+ case 2: _scale_cubic<1, uint16_t>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ case 4: _scale_cubic<2, uint16_t>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ case 6: _scale_cubic<3, uint16_t>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ case 8: _scale_cubic<4, uint16_t>(r_ptr, w_ptr, width, height, p_width, p_height); break;
+ }
}
-
} break;
}
@@ -1685,7 +1783,7 @@ Error Image::compress(CompressMode p_mode, CompressSource p_source, float p_loss
case COMPRESS_S3TC: {
ERR_FAIL_COND_V(!_image_compress_bc_func, ERR_UNAVAILABLE);
- _image_compress_bc_func(this, p_source);
+ _image_compress_bc_func(this, p_lossy_quality, p_source);
} break;
case COMPRESS_PVRTC2: {
@@ -2048,7 +2146,7 @@ ImageMemLoadFunc Image::_png_mem_loader_func = NULL;
ImageMemLoadFunc Image::_jpg_mem_loader_func = NULL;
ImageMemLoadFunc Image::_webp_mem_loader_func = NULL;
-void (*Image::_image_compress_bc_func)(Image *, Image::CompressSource) = NULL;
+void (*Image::_image_compress_bc_func)(Image *, float, Image::CompressSource) = NULL;
void (*Image::_image_compress_bptc_func)(Image *, float, Image::CompressSource) = NULL;
void (*Image::_image_compress_pvrtc2_func)(Image *) = NULL;
void (*Image::_image_compress_pvrtc4_func)(Image *) = NULL;
@@ -2569,7 +2667,7 @@ void Image::_bind_methods() {
BIND_ENUM_CONSTANT(COMPRESS_SOURCE_NORMAL);
}
-void Image::set_compress_bc_func(void (*p_compress_func)(Image *, CompressSource)) {
+void Image::set_compress_bc_func(void (*p_compress_func)(Image *, float, CompressSource)) {
_image_compress_bc_func = p_compress_func;
}
diff --git a/core/image.h b/core/image.h
index 854096b773..6af55ca8d9 100644
--- a/core/image.h
+++ b/core/image.h
@@ -126,7 +126,7 @@ public:
static ImageMemLoadFunc _jpg_mem_loader_func;
static ImageMemLoadFunc _webp_mem_loader_func;
- static void (*_image_compress_bc_func)(Image *, CompressSource p_source);
+ static void (*_image_compress_bc_func)(Image *, float, CompressSource p_source);
static void (*_image_compress_bptc_func)(Image *, float p_lossy_quality, CompressSource p_source);
static void (*_image_compress_pvrtc2_func)(Image *);
static void (*_image_compress_pvrtc4_func)(Image *);
@@ -316,7 +316,7 @@ public:
Rect2 get_used_rect() const;
Ref<Image> get_rect(const Rect2 &p_area) const;
- static void set_compress_bc_func(void (*p_compress_func)(Image *, CompressSource));
+ static void set_compress_bc_func(void (*p_compress_func)(Image *, float, CompressSource));
static void set_compress_bptc_func(void (*p_compress_func)(Image *, float, CompressSource));
static String get_format_name(Format p_format);
diff --git a/editor/editor_run.cpp b/editor/editor_run.cpp
index 072bd948e1..bbd18306a2 100644
--- a/editor/editor_run.cpp
+++ b/editor/editor_run.cpp
@@ -68,9 +68,24 @@ Error EditorRun::run(const String &p_scene, const String p_custom_args, const Li
int screen = EditorSettings::get_singleton()->get("run/window_placement/screen");
if (screen == 0) {
+ // Same as editor
screen = OS::get_singleton()->get_current_screen();
+ } else if (screen == 1) {
+ // Previous monitor (wrap to the other end if needed)
+ screen = Math::wrapi(
+ OS::get_singleton()->get_current_screen() - 1,
+ 0,
+ OS::get_singleton()->get_screen_count());
+ } else if (screen == 2) {
+ // Next monitor (wrap to the other end if needed)
+ screen = Math::wrapi(
+ OS::get_singleton()->get_current_screen() + 1,
+ 0,
+ OS::get_singleton()->get_screen_count());
} else {
- screen--;
+ // Fixed monitor ID
+ // There are 3 special options, so decrement the option ID by 3 to get the monitor ID
+ screen -= 3;
}
if (OS::get_singleton()->is_disable_crash_handler()) {
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp
index 85186440ab..9278d7676a 100644
--- a/editor/editor_settings.cpp
+++ b/editor/editor_settings.cpp
@@ -494,7 +494,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
_initial_set("run/window_placement/rect", 1);
hints["run/window_placement/rect"] = PropertyInfo(Variant::INT, "run/window_placement/rect", PROPERTY_HINT_ENUM, "Top Left,Centered,Custom Position,Force Maximized,Force Fullscreen");
- String screen_hints = TTR("Default (Same as Editor)");
+ String screen_hints = "Same as Editor,Previous Monitor,Next Monitor";
for (int i = 0; i < OS::get_singleton()->get_screen_count(); i++) {
screen_hints += ",Monitor " + itos(i + 1);
}
diff --git a/editor/plugins/mesh_library_editor_plugin.cpp b/editor/plugins/mesh_library_editor_plugin.cpp
index a4d2905c0e..99a28be555 100644
--- a/editor/plugins/mesh_library_editor_plugin.cpp
+++ b/editor/plugins/mesh_library_editor_plugin.cpp
@@ -40,11 +40,11 @@
#include "scene/resources/packed_scene.h"
#include "spatial_editor_plugin.h"
-void MeshLibraryEditor::edit(const Ref<MeshLibrary> &p_theme) {
+void MeshLibraryEditor::edit(const Ref<MeshLibrary> &p_mesh_library) {
- theme = p_theme;
- if (theme.is_valid())
- menu->get_popup()->set_item_disabled(menu->get_popup()->get_item_index(MENU_OPTION_UPDATE_FROM_SCENE), !theme->has_meta("_editor_source_scene"));
+ mesh_library = p_mesh_library;
+ if (mesh_library.is_valid())
+ menu->get_popup()->set_item_disabled(menu->get_popup()->get_item_index(MENU_OPTION_UPDATE_FROM_SCENE), !mesh_library->has_meta("_editor_source_scene"));
}
void MeshLibraryEditor::_menu_confirm() {
@@ -53,10 +53,10 @@ void MeshLibraryEditor::_menu_confirm() {
case MENU_OPTION_REMOVE_ITEM: {
- theme->remove_item(to_erase);
+ mesh_library->remove_item(to_erase);
} break;
case MENU_OPTION_UPDATE_FROM_SCENE: {
- String existing = theme->get_meta("_editor_source_scene");
+ String existing = mesh_library->get_meta("_editor_source_scene");
ERR_FAIL_COND(existing == "");
_import_scene_cbk(existing);
@@ -175,10 +175,10 @@ void MeshLibraryEditor::_import_scene_cbk(const String &p_str) {
ERR_FAIL_COND(ps.is_null());
Node *scene = ps->instance();
- _import_scene(scene, theme, option == MENU_OPTION_UPDATE_FROM_SCENE);
+ _import_scene(scene, mesh_library, option == MENU_OPTION_UPDATE_FROM_SCENE);
memdelete(scene);
- theme->set_meta("_editor_source_scene", p_str);
+ mesh_library->set_meta("_editor_source_scene", p_str);
menu->get_popup()->set_item_disabled(menu->get_popup()->get_item_index(MENU_OPTION_UPDATE_FROM_SCENE), false);
}
@@ -195,7 +195,7 @@ void MeshLibraryEditor::_menu_cbk(int p_option) {
case MENU_OPTION_ADD_ITEM: {
- theme->create_item(theme->get_last_unused_item_id());
+ mesh_library->create_item(mesh_library->get_last_unused_item_id());
} break;
case MENU_OPTION_REMOVE_ITEM: {
@@ -213,7 +213,7 @@ void MeshLibraryEditor::_menu_cbk(int p_option) {
} break;
case MENU_OPTION_UPDATE_FROM_SCENE: {
- cd->set_text("Update from existing scene?:\n" + String(theme->get_meta("_editor_source_scene")));
+ cd->set_text("Update from existing scene?:\n" + String(mesh_library->get_meta("_editor_source_scene")));
cd->popup_centered(Size2(500, 60));
} break;
}
@@ -265,10 +265,10 @@ MeshLibraryEditor::MeshLibraryEditor(EditorNode *p_editor) {
void MeshLibraryEditorPlugin::edit(Object *p_node) {
if (Object::cast_to<MeshLibrary>(p_node)) {
- theme_editor->edit(Object::cast_to<MeshLibrary>(p_node));
- theme_editor->show();
+ mesh_library_editor->edit(Object::cast_to<MeshLibrary>(p_node));
+ mesh_library_editor->show();
} else
- theme_editor->hide();
+ mesh_library_editor->hide();
}
bool MeshLibraryEditorPlugin::handles(Object *p_node) const {
@@ -279,21 +279,21 @@ bool MeshLibraryEditorPlugin::handles(Object *p_node) const {
void MeshLibraryEditorPlugin::make_visible(bool p_visible) {
if (p_visible) {
- theme_editor->show();
- theme_editor->get_menu_button()->show();
+ mesh_library_editor->show();
+ mesh_library_editor->get_menu_button()->show();
} else {
- theme_editor->hide();
- theme_editor->get_menu_button()->hide();
+ mesh_library_editor->hide();
+ mesh_library_editor->get_menu_button()->hide();
}
}
MeshLibraryEditorPlugin::MeshLibraryEditorPlugin(EditorNode *p_node) {
EDITOR_DEF("editors/grid_map/preview_size", 64);
- theme_editor = memnew(MeshLibraryEditor(p_node));
+ mesh_library_editor = memnew(MeshLibraryEditor(p_node));
- p_node->get_viewport()->add_child(theme_editor);
- theme_editor->set_anchors_and_margins_preset(Control::PRESET_TOP_WIDE);
- theme_editor->set_end(Point2(0, 22));
- theme_editor->hide();
+ p_node->get_viewport()->add_child(mesh_library_editor);
+ mesh_library_editor->set_anchors_and_margins_preset(Control::PRESET_TOP_WIDE);
+ mesh_library_editor->set_end(Point2(0, 22));
+ mesh_library_editor->hide();
}
diff --git a/editor/plugins/mesh_library_editor_plugin.h b/editor/plugins/mesh_library_editor_plugin.h
index dc2d488bd6..be33b5324d 100644
--- a/editor/plugins/mesh_library_editor_plugin.h
+++ b/editor/plugins/mesh_library_editor_plugin.h
@@ -38,7 +38,7 @@ class MeshLibraryEditor : public Control {
GDCLASS(MeshLibraryEditor, Control);
- Ref<MeshLibrary> theme;
+ Ref<MeshLibrary> mesh_library;
EditorNode *editor;
MenuButton *menu;
@@ -67,7 +67,7 @@ protected:
public:
MenuButton *get_menu_button() const { return menu; }
- void edit(const Ref<MeshLibrary> &p_theme);
+ void edit(const Ref<MeshLibrary> &p_mesh_library);
static Error update_library_file(Node *p_base_scene, Ref<MeshLibrary> ml, bool p_merge = true);
MeshLibraryEditor(EditorNode *p_editor);
@@ -77,7 +77,7 @@ class MeshLibraryEditorPlugin : public EditorPlugin {
GDCLASS(MeshLibraryEditorPlugin, EditorPlugin);
- MeshLibraryEditor *theme_editor;
+ MeshLibraryEditor *mesh_library_editor;
EditorNode *editor;
public:
diff --git a/modules/gdnative/gdnative_api.json b/modules/gdnative/gdnative_api.json
index 217fd87c3e..e326d11a84 100644
--- a/modules/gdnative/gdnative_api.json
+++ b/modules/gdnative/gdnative_api.json
@@ -5876,6 +5876,14 @@
["int", "p_idx"],
["godot_object *", "p_object"]
]
+ },
+ {
+ "name": "godot_nativescript_profiling_add_data",
+ "return_type": "void",
+ "arguments": [
+ ["const char *", "p_signature"],
+ ["uint64_t", "p_line"]
+ ]
}
]
},
diff --git a/modules/gdnative/include/nativescript/godot_nativescript.h b/modules/gdnative/include/nativescript/godot_nativescript.h
index 1c5422d723..29bd9eec5a 100644
--- a/modules/gdnative/include/nativescript/godot_nativescript.h
+++ b/modules/gdnative/include/nativescript/godot_nativescript.h
@@ -238,6 +238,8 @@ void GDAPI godot_nativescript_unregister_instance_binding_data_functions(int p_i
void GDAPI *godot_nativescript_get_instance_binding_data(int p_idx, godot_object *p_object);
+void GDAPI godot_nativescript_profiling_add_data(const char *p_signature, uint64_t p_time);
+
#ifdef __cplusplus
}
#endif
diff --git a/modules/gdnative/nativescript/godot_nativescript.cpp b/modules/gdnative/nativescript/godot_nativescript.cpp
index ace2ecac5c..72606c8340 100644
--- a/modules/gdnative/nativescript/godot_nativescript.cpp
+++ b/modules/gdnative/nativescript/godot_nativescript.cpp
@@ -365,6 +365,10 @@ void GDAPI *godot_nativescript_get_instance_binding_data(int p_idx, godot_object
return NativeScriptLanguage::get_singleton()->get_instance_binding_data(p_idx, (Object *)p_object);
}
+void GDAPI godot_nativescript_profiling_add_data(const char *p_signature, uint64_t p_time) {
+ NativeScriptLanguage::get_singleton()->profiling_add_data(StringName(p_signature), p_time);
+}
+
#ifdef __cplusplus
}
#endif
diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp
index 24264c4256..608c7aa4a5 100644
--- a/modules/gdnative/nativescript/nativescript.cpp
+++ b/modules/gdnative/nativescript/nativescript.cpp
@@ -1010,6 +1010,10 @@ NativeScriptLanguage::NativeScriptLanguage() {
has_objects_to_register = false;
mutex = Mutex::create();
#endif
+
+#ifdef DEBUG_ENABLED
+ profiling = false;
+#endif
}
NativeScriptLanguage::~NativeScriptLanguage() {
@@ -1152,17 +1156,105 @@ void NativeScriptLanguage::get_public_constants(List<Pair<String, Variant> > *p_
}
void NativeScriptLanguage::profiling_start() {
+#ifdef DEBUG_ENABLED
+#ifndef NO_THREADS
+ MutexLock lock(mutex);
+#endif
+
+ profile_data.clear();
+ profiling = true;
+#endif
}
void NativeScriptLanguage::profiling_stop() {
+#ifdef DEBUG_ENABLED
+#ifndef NO_THREADS
+ MutexLock lock(mutex);
+#endif
+
+ profiling = false;
+#endif
}
int NativeScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max) {
+#ifdef DEBUG_ENABLED
+#ifndef NO_THREADS
+ MutexLock lock(mutex);
+#endif
+ int current = 0;
+
+ for (Map<StringName, ProfileData>::Element *d = profile_data.front(); d; d = d->next()) {
+ if (current >= p_info_max)
+ break;
+
+ p_info_arr[current].call_count = d->get().call_count;
+ p_info_arr[current].self_time = d->get().self_time;
+ p_info_arr[current].total_time = d->get().total_time;
+ p_info_arr[current].signature = d->get().signature;
+ current++;
+ }
+
+ return current;
+#else
return 0;
+#endif
}
int NativeScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) {
+#ifdef DEBUG_ENABLED
+#ifndef NO_THREADS
+ MutexLock lock(mutex);
+#endif
+ int current = 0;
+
+ for (Map<StringName, ProfileData>::Element *d = profile_data.front(); d; d = d->next()) {
+ if (current >= p_info_max)
+ break;
+
+ if (d->get().last_frame_call_count) {
+ p_info_arr[current].call_count = d->get().last_frame_call_count;
+ p_info_arr[current].self_time = d->get().last_frame_self_time;
+ p_info_arr[current].total_time = d->get().last_frame_total_time;
+ p_info_arr[current].signature = d->get().signature;
+ current++;
+ }
+ }
+
+ return current;
+#else
return 0;
+#endif
+}
+
+void NativeScriptLanguage::profiling_add_data(StringName p_signature, uint64_t p_time) {
+#ifdef DEBUG_ENABLED
+#ifndef NO_THREADS
+ MutexLock lock(mutex);
+#endif
+
+ Map<StringName, ProfileData>::Element *d = profile_data.find(p_signature);
+ if (d) {
+ d->get().call_count += 1;
+ d->get().total_time += p_time;
+ d->get().frame_call_count += 1;
+ d->get().frame_total_time += p_time;
+ } else {
+ ProfileData data;
+
+ data.signature = p_signature;
+ data.call_count = 1;
+ data.self_time = 0;
+ data.total_time = p_time;
+ data.frame_call_count = 1;
+ data.frame_self_time = 0;
+ data.frame_total_time = p_time;
+ data.last_frame_call_count = 0;
+ data.last_frame_self_time = 0;
+ data.last_frame_total_time = 0;
+
+ profile_data.insert(p_signature, data);
+ }
+#endif
}
int NativeScriptLanguage::register_binding_functions(godot_instance_binding_functions p_binding_functions) {
@@ -1405,6 +1497,24 @@ void NativeScriptLanguage::frame() {
has_objects_to_register = false;
}
#endif
+
+#ifdef DEBUG_ENABLED
+ {
+#ifndef NO_THREADS
+ MutexLock lock(mutex);
+#endif
+
+ for (Map<StringName, ProfileData>::Element *d = profile_data.front(); d; d = d->next()) {
+ d->get().last_frame_call_count = d->get().frame_call_count;
+ d->get().last_frame_self_time = d->get().frame_self_time;
+ d->get().last_frame_total_time = d->get().frame_total_time;
+ d->get().frame_call_count = 0;
+ d->get().frame_self_time = 0;
+ d->get().frame_total_time = 0;
+ }
+ }
+#endif
+
call_libraries_cb(_frame_call_name);
}
diff --git a/modules/gdnative/nativescript/nativescript.h b/modules/gdnative/nativescript/nativescript.h
index c1f11646b0..6f18e2db27 100644
--- a/modules/gdnative/nativescript/nativescript.h
+++ b/modules/gdnative/nativescript/nativescript.h
@@ -254,6 +254,22 @@ private:
Map<int, HashMap<StringName, const void *> > global_type_tags;
+ struct ProfileData {
+ StringName signature;
+ uint64_t call_count;
+ uint64_t self_time;
+ uint64_t total_time;
+ uint64_t frame_call_count;
+ uint64_t frame_self_time;
+ uint64_t frame_total_time;
+ uint64_t last_frame_call_count;
+ uint64_t last_frame_self_time;
+ uint64_t last_frame_total_time;
+ };
+
+ Map<StringName, ProfileData> profile_data;
+ bool profiling;
+
public:
// These two maps must only be touched on the main thread
Map<String, Map<StringName, NativeScriptDesc> > library_classes;
@@ -343,6 +359,8 @@ public:
virtual bool handles_global_class_type(const String &p_type) const;
virtual String get_global_class_name(const String &p_path, String *r_base_type, String *r_icon_path) const;
+
+ void profiling_add_data(StringName p_signature, uint64_t p_time);
};
inline NativeScriptDesc *NativeScript::get_script_desc() const {
diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp
index 0c5df57d49..8b63987cde 100644
--- a/modules/gridmap/grid_map.cpp
+++ b/modules/gridmap/grid_map.cpp
@@ -208,21 +208,35 @@ bool GridMap::get_collision_layer_bit(int p_bit) const {
return get_collision_layer() & (1 << p_bit);
}
+#ifndef DISABLE_DEPRECATED
void GridMap::set_theme(const Ref<MeshLibrary> &p_theme) {
- if (!theme.is_null())
- theme->unregister_owner(this);
- theme = p_theme;
- if (!theme.is_null())
- theme->register_owner(this);
+ WARN_PRINTS("GridMap.theme/set_theme() is deprecated and will be removed in a future version. Use GridMap.mesh_library/set_mesh_library() instead.");
+ set_mesh_library(p_theme);
+}
+
+Ref<MeshLibrary> GridMap::get_theme() const {
+
+ WARN_PRINTS("GridMap.theme/get_theme() is deprecated and will be removed in a future version. Use GridMap.mesh_library/get_mesh_library() instead.");
+ return get_mesh_library();
+}
+#endif // DISABLE_DEPRECATED
+
+void GridMap::set_mesh_library(const Ref<MeshLibrary> &p_mesh_library) {
+
+ if (!mesh_library.is_null())
+ mesh_library->unregister_owner(this);
+ mesh_library = p_mesh_library;
+ if (!mesh_library.is_null())
+ mesh_library->register_owner(this);
_recreate_octant_data();
- _change_notify("theme");
+ _change_notify("mesh_library");
}
-Ref<MeshLibrary> GridMap::get_theme() const {
+Ref<MeshLibrary> GridMap::get_mesh_library() const {
- return theme;
+ return mesh_library;
}
void GridMap::set_cell_size(const Vector3 &p_size) {
@@ -469,7 +483,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
ERR_CONTINUE(!cell_map.has(E->get()));
const Cell &c = cell_map[E->get()];
- if (!theme.is_valid() || !theme->has_item(c.item))
+ if (!mesh_library.is_valid() || !mesh_library->has_item(c.item))
continue;
//print_line("OCTANT, CELLS: "+itos(ii.cells.size()));
@@ -488,7 +502,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
xform.set_origin(cellpos * cell_size + ofs);
xform.basis.scale(Vector3(cell_scale, cell_scale, cell_scale));
if (baked_meshes.size() == 0) {
- if (theme->get_item_mesh(c.item).is_valid()) {
+ if (mesh_library->get_item_mesh(c.item).is_valid()) {
if (!multimesh_items.has(c.item)) {
multimesh_items[c.item] = List<Pair<Transform, IndexKey> >();
}
@@ -500,7 +514,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
}
}
- Vector<MeshLibrary::ShapeData> shapes = theme->get_item_shapes(c.item);
+ Vector<MeshLibrary::ShapeData> shapes = mesh_library->get_item_shapes(c.item);
// add the item's shape at given xform to octant's static_body
for (int i = 0; i < shapes.size(); i++) {
// add the item's shape
@@ -515,7 +529,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
}
// add the item's navmesh at given xform to GridMap's Navigation ancestor
- Ref<NavigationMesh> navmesh = theme->get_item_navmesh(c.item);
+ Ref<NavigationMesh> navmesh = mesh_library->get_item_navmesh(c.item);
if (navmesh.is_valid()) {
Octant::NavMesh nm;
nm.xform = xform;
@@ -537,7 +551,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
RID mm = VS::get_singleton()->multimesh_create();
VS::get_singleton()->multimesh_allocate(mm, E->get().size(), VS::MULTIMESH_TRANSFORM_3D, VS::MULTIMESH_COLOR_NONE);
- VS::get_singleton()->multimesh_set_mesh(mm, theme->get_item_mesh(E->key())->get_rid());
+ VS::get_singleton()->multimesh_set_mesh(mm, mesh_library->get_item_mesh(E->key())->get_rid());
int idx = 0;
for (List<Pair<Transform, IndexKey> >::Element *F = E->get().front(); F; F = F->next()) {
@@ -612,11 +626,11 @@ void GridMap::_octant_enter_world(const OctantKey &p_key) {
VS::get_singleton()->instance_set_transform(g.multimesh_instances[i].instance, get_global_transform());
}
- if (navigation && theme.is_valid()) {
+ if (navigation && mesh_library.is_valid()) {
for (Map<IndexKey, Octant::NavMesh>::Element *F = g.navmesh_ids.front(); F; F = F->next()) {
if (cell_map.has(F->key()) && F->get().id < 0) {
- Ref<NavigationMesh> nm = theme->get_item_navmesh(cell_map[F->key()].item);
+ Ref<NavigationMesh> nm = mesh_library->get_item_navmesh(cell_map[F->key()].item);
if (nm.is_valid()) {
F->get().id = navigation->navmesh_add(nm, F->get().xform, this);
}
@@ -846,8 +860,13 @@ void GridMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_collision_layer_bit", "bit", "value"), &GridMap::set_collision_layer_bit);
ClassDB::bind_method(D_METHOD("get_collision_layer_bit", "bit"), &GridMap::get_collision_layer_bit);
+#ifndef DISABLE_DEPRECATED
ClassDB::bind_method(D_METHOD("set_theme", "theme"), &GridMap::set_theme);
ClassDB::bind_method(D_METHOD("get_theme"), &GridMap::get_theme);
+#endif // DISABLE_DEPRECATED
+
+ ClassDB::bind_method(D_METHOD("set_mesh_library", "mesh_library"), &GridMap::set_mesh_library);
+ ClassDB::bind_method(D_METHOD("get_mesh_library"), &GridMap::get_mesh_library);
ClassDB::bind_method(D_METHOD("set_cell_size", "size"), &GridMap::set_cell_size);
ClassDB::bind_method(D_METHOD("get_cell_size"), &GridMap::get_cell_size);
@@ -865,7 +884,6 @@ void GridMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("world_to_map", "pos"), &GridMap::world_to_map);
ClassDB::bind_method(D_METHOD("map_to_world", "x", "y", "z"), &GridMap::map_to_world);
- //ClassDB::bind_method(D_METHOD("_recreate_octants"),&GridMap::_recreate_octants);
ClassDB::bind_method(D_METHOD("_update_octants_callback"), &GridMap::_update_octants_callback);
ClassDB::bind_method(D_METHOD("resource_changed", "resource"), &GridMap::resource_changed);
@@ -889,7 +907,11 @@ void GridMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("clear_baked_meshes"), &GridMap::clear_baked_meshes);
ClassDB::bind_method(D_METHOD("make_baked_meshes", "gen_lightmap_uv", "lightmap_uv_texel_size"), &GridMap::make_baked_meshes, DEFVAL(false), DEFVAL(0.1));
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "MeshLibrary"), "set_theme", "get_theme");
+#ifndef DISABLE_DEPRECATED
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "MeshLibrary", PROPERTY_USAGE_NOEDITOR), "set_theme", "get_theme");
+#endif // DISABLE_DEPRECATED
+
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh_library", PROPERTY_HINT_RESOURCE_TYPE, "MeshLibrary"), "set_mesh_library", "get_mesh_library");
ADD_GROUP("Cell", "cell_");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "cell_size"), "set_cell_size", "get_cell_size");
ADD_PROPERTY(PropertyInfo(Variant::INT, "cell_octant_size", PROPERTY_HINT_RANGE, "1,1024,1"), "set_octant_size", "get_octant_size");
@@ -952,7 +974,7 @@ Array GridMap::get_used_cells() const {
Array GridMap::get_meshes() {
- if (theme.is_null())
+ if (mesh_library.is_null())
return Array();
Vector3 ofs = _get_offset();
@@ -961,9 +983,9 @@ Array GridMap::get_meshes() {
for (Map<IndexKey, Cell>::Element *E = cell_map.front(); E; E = E->next()) {
int id = E->get().item;
- if (!theme->has_item(id))
+ if (!mesh_library->has_item(id))
continue;
- Ref<Mesh> mesh = theme->get_item_mesh(id);
+ Ref<Mesh> mesh = mesh_library->get_item_mesh(id);
if (mesh.is_null())
continue;
@@ -1004,7 +1026,7 @@ void GridMap::clear_baked_meshes() {
void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texel_size) {
- if (!theme.is_valid())
+ if (!mesh_library.is_valid())
return;
//generate
@@ -1015,10 +1037,10 @@ void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texe
IndexKey key = E->key();
int item = E->get().item;
- if (!theme->has_item(item))
+ if (!mesh_library->has_item(item))
continue;
- Ref<Mesh> mesh = theme->get_item_mesh(item);
+ Ref<Mesh> mesh = mesh_library->get_item_mesh(item);
if (!mesh.is_valid())
continue;
@@ -1137,8 +1159,8 @@ GridMap::GridMap() {
GridMap::~GridMap() {
- if (!theme.is_null())
- theme->unregister_owner(this);
+ if (!mesh_library.is_null())
+ mesh_library->unregister_owner(this);
clear();
}
diff --git a/modules/gridmap/grid_map.h b/modules/gridmap/grid_map.h
index ed36751fc8..3d8be5c9c7 100644
--- a/modules/gridmap/grid_map.h
+++ b/modules/gridmap/grid_map.h
@@ -157,7 +157,7 @@ class GridMap : public Spatial {
Vector3::Axis clip_axis;
- Ref<MeshLibrary> theme;
+ Ref<MeshLibrary> mesh_library;
Map<OctantKey, Octant *> octant_map;
Map<IndexKey, Cell> cell_map;
@@ -227,8 +227,13 @@ public:
void set_collision_mask_bit(int p_bit, bool p_value);
bool get_collision_mask_bit(int p_bit) const;
+#ifndef DISABLE_DEPRECATED
void set_theme(const Ref<MeshLibrary> &p_theme);
Ref<MeshLibrary> get_theme() const;
+#endif // DISABLE_DEPRECATED
+
+ void set_mesh_library(const Ref<MeshLibrary> &p_mesh_library);
+ Ref<MeshLibrary> get_mesh_library() const;
void set_cell_size(const Vector3 &p_size);
Vector3 get_cell_size() const;
diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp
index fc5972c810..7d38a8b748 100644
--- a/modules/gridmap/grid_map_editor_plugin.cpp
+++ b/modules/gridmap/grid_map_editor_plugin.cpp
@@ -43,7 +43,7 @@ void GridMapEditor::_node_removed(Node *p_node) {
if (p_node == node) {
node = NULL;
hide();
- theme_pallete->hide();
+ mesh_library_palette->hide();
}
}
@@ -320,12 +320,12 @@ bool GridMapEditor::do_input_action(Camera *p_camera, const Point2 &p_point, boo
if (!spatial_editor)
return false;
- if (selected_pallete < 0 && input_action != INPUT_COPY && input_action != INPUT_SELECT && input_action != INPUT_DUPLICATE)
+ if (selected_palette < 0 && input_action != INPUT_COPY && input_action != INPUT_SELECT && input_action != INPUT_DUPLICATE)
return false;
- Ref<MeshLibrary> theme = node->get_theme();
- if (theme.is_null())
+ Ref<MeshLibrary> mesh_library = node->get_mesh_library();
+ if (mesh_library.is_null())
return false;
- if (input_action != INPUT_COPY && input_action != INPUT_SELECT && input_action != INPUT_DUPLICATE && !theme->has_item(selected_pallete))
+ if (input_action != INPUT_COPY && input_action != INPUT_SELECT && input_action != INPUT_DUPLICATE && !mesh_library->has_item(selected_palette))
return false;
Camera *camera = p_camera;
@@ -407,9 +407,9 @@ bool GridMapEditor::do_input_action(Camera *p_camera, const Point2 &p_point, boo
int item = node->get_cell_item(cell[0], cell[1], cell[2]);
if (item >= 0) {
- selected_pallete = item;
- theme_pallete->set_current(item);
- update_pallete();
+ selected_palette = item;
+ mesh_library_palette->set_current(item);
+ update_palette();
_update_cursor_instance();
}
return true;
@@ -417,12 +417,12 @@ bool GridMapEditor::do_input_action(Camera *p_camera, const Point2 &p_point, boo
if (input_action == INPUT_PAINT) {
SetItem si;
si.pos = Vector3(cell[0], cell[1], cell[2]);
- si.new_value = selected_pallete;
+ si.new_value = selected_palette;
si.new_orientation = cursor_rot;
si.old_value = node->get_cell_item(cell[0], cell[1], cell[2]);
si.old_orientation = node->get_cell_item_orientation(cell[0], cell[1], cell[2]);
set_items.push_back(si);
- node->set_cell_item(cell[0], cell[1], cell[2], selected_pallete, cursor_rot);
+ node->set_cell_item(cell[0], cell[1], cell[2], selected_palette, cursor_rot);
return true;
} else if (input_action == INPUT_ERASE) {
SetItem si;
@@ -474,7 +474,7 @@ void GridMapEditor::_fill_selection() {
for (int k = selection.begin.z; k <= selection.end.z; k++) {
- undo_redo->add_do_method(node, "set_cell_item", i, j, k, selected_pallete, cursor_rot);
+ undo_redo->add_do_method(node, "set_cell_item", i, j, k, selected_palette, cursor_rot);
undo_redo->add_undo_method(node, "set_cell_item", i, j, k, node->get_cell_item(i, j, k), node->get_cell_item_orientation(i, j, k));
}
}
@@ -712,42 +712,42 @@ void GridMapEditor::_set_display_mode(int p_mode) {
display_mode = p_mode;
- update_pallete();
+ update_palette();
}
-void GridMapEditor::update_pallete() {
- int selected = theme_pallete->get_current();
+void GridMapEditor::update_palette() {
+ int selected = mesh_library_palette->get_current();
- theme_pallete->clear();
+ mesh_library_palette->clear();
if (display_mode == DISPLAY_THUMBNAIL) {
- theme_pallete->set_max_columns(0);
- theme_pallete->set_icon_mode(ItemList::ICON_MODE_TOP);
+ mesh_library_palette->set_max_columns(0);
+ mesh_library_palette->set_icon_mode(ItemList::ICON_MODE_TOP);
} else if (display_mode == DISPLAY_LIST) {
- theme_pallete->set_max_columns(1);
- theme_pallete->set_icon_mode(ItemList::ICON_MODE_LEFT);
+ mesh_library_palette->set_max_columns(1);
+ mesh_library_palette->set_icon_mode(ItemList::ICON_MODE_LEFT);
}
float min_size = EDITOR_DEF("editors/grid_map/preview_size", 64);
- theme_pallete->set_fixed_icon_size(Size2(min_size, min_size));
- theme_pallete->set_fixed_column_width(min_size * 3 / 2);
- theme_pallete->set_max_text_lines(2);
+ mesh_library_palette->set_fixed_icon_size(Size2(min_size, min_size));
+ mesh_library_palette->set_fixed_column_width(min_size * 3 / 2);
+ mesh_library_palette->set_max_text_lines(2);
- Ref<MeshLibrary> theme = node->get_theme();
+ Ref<MeshLibrary> mesh_library = node->get_mesh_library();
- if (theme.is_null()) {
- last_theme = NULL;
+ if (mesh_library.is_null()) {
+ last_mesh_library = NULL;
return;
}
Vector<int> ids;
- ids = theme->get_item_list();
+ ids = mesh_library->get_item_list();
List<_CGMEItemSort> il;
for (int i = 0; i < ids.size(); i++) {
_CGMEItemSort is;
is.id = ids[i];
- is.name = theme->get_item_name(ids[i]);
+ is.name = mesh_library->get_item_name(ids[i]);
il.push_back(is);
}
il.sort();
@@ -757,28 +757,28 @@ void GridMapEditor::update_pallete() {
for (List<_CGMEItemSort>::Element *E = il.front(); E; E = E->next()) {
int id = E->get().id;
- theme_pallete->add_item("");
+ mesh_library_palette->add_item("");
- String name = theme->get_item_name(id);
- Ref<Texture> preview = theme->get_item_preview(id);
+ String name = mesh_library->get_item_name(id);
+ Ref<Texture> preview = mesh_library->get_item_preview(id);
if (!preview.is_null()) {
- theme_pallete->set_item_icon(item, preview);
- theme_pallete->set_item_tooltip(item, name);
+ mesh_library_palette->set_item_icon(item, preview);
+ mesh_library_palette->set_item_tooltip(item, name);
}
if (name != "") {
- theme_pallete->set_item_text(item, name);
+ mesh_library_palette->set_item_text(item, name);
}
- theme_pallete->set_item_metadata(item, id);
+ mesh_library_palette->set_item_metadata(item, id);
item++;
}
if (selected != -1) {
- theme_pallete->select(selected);
+ mesh_library_palette->select(selected);
}
- last_theme = theme.operator->();
+ last_mesh_library = mesh_library.operator->();
}
void GridMapEditor::edit(GridMap *p_gridmap) {
@@ -805,7 +805,7 @@ void GridMapEditor::edit(GridMap *p_gridmap) {
return;
}
- update_pallete();
+ update_palette();
set_process(true);
@@ -914,7 +914,7 @@ void GridMapEditor::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
- theme_pallete->connect("item_selected", this, "_item_selected_cbk");
+ mesh_library_palette->connect("item_selected", this, "_item_selected_cbk");
for (int i = 0; i < 3; i++) {
grid[i] = VS::get_singleton()->mesh_create();
@@ -959,9 +959,9 @@ void GridMapEditor::_notification(int p_what) {
}
grid_xform = xf;
}
- Ref<MeshLibrary> cgmt = node->get_theme();
- if (cgmt.operator->() != last_theme)
- update_pallete();
+ Ref<MeshLibrary> cgmt = node->get_mesh_library();
+ if (cgmt.operator->() != last_mesh_library)
+ update_palette();
if (lock_view) {
@@ -994,10 +994,10 @@ void GridMapEditor::_update_cursor_instance() {
VisualServer::get_singleton()->free(cursor_instance);
cursor_instance = RID();
- if (selected_pallete >= 0) {
+ if (selected_palette >= 0) {
- if (node && !node->get_theme().is_null()) {
- Ref<Mesh> mesh = node->get_theme()->get_item_mesh(selected_pallete);
+ if (node && !node->get_mesh_library().is_null()) {
+ Ref<Mesh> mesh = node->get_mesh_library()->get_item_mesh(selected_palette);
if (!mesh.is_null() && mesh->get_rid().is_valid()) {
cursor_instance = VisualServer::get_singleton()->instance_create2(mesh->get_rid(), get_tree()->get_root()->get_world()->get_scenario());
@@ -1008,7 +1008,7 @@ void GridMapEditor::_update_cursor_instance() {
}
void GridMapEditor::_item_selected_cbk(int idx) {
- selected_pallete = theme_pallete->get_item_metadata(idx);
+ selected_palette = mesh_library_palette->get_item_metadata(idx);
_update_cursor_instance();
}
@@ -1146,9 +1146,9 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
display_mode = DISPLAY_THUMBNAIL;
- theme_pallete = memnew(ItemList);
- add_child(theme_pallete);
- theme_pallete->set_v_size_flags(SIZE_EXPAND_FILL);
+ mesh_library_palette = memnew(ItemList);
+ add_child(mesh_library_palette);
+ mesh_library_palette->set_v_size_flags(SIZE_EXPAND_FILL);
edit_axis = Vector3::AXIS_Y;
edit_floor[0] = -1;
@@ -1156,7 +1156,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
edit_floor[2] = -1;
cursor_visible = false;
- selected_pallete = -1;
+ selected_palette = -1;
lock_view = false;
cursor_rot = 0;
last_mouseover = Vector3(-1, -1, -1);
diff --git a/modules/gridmap/grid_map_editor_plugin.h b/modules/gridmap/grid_map_editor_plugin.h
index 7c5feda125..c6e3eb87e5 100644
--- a/modules/gridmap/grid_map_editor_plugin.h
+++ b/modules/gridmap/grid_map_editor_plugin.h
@@ -97,7 +97,7 @@ class GridMapEditor : public VBoxContainer {
List<SetItem> set_items;
GridMap *node;
- MeshLibrary *last_theme;
+ MeshLibrary *last_mesh_library;
ClipMode clip_mode;
bool lock_view;
@@ -141,7 +141,7 @@ class GridMapEditor : public VBoxContainer {
Vector3 last_mouseover;
int display_mode;
- int selected_pallete;
+ int selected_palette;
int cursor_rot;
enum Menu {
@@ -185,9 +185,9 @@ class GridMapEditor : public VBoxContainer {
void update_grid();
void _configure();
void _menu_option(int);
- void update_pallete();
+ void update_palette();
void _set_display_mode(int p_mode);
- ItemList *theme_pallete;
+ ItemList *mesh_library_palette;
void _item_selected_cbk(int idx);
void _update_cursor_transform();
void _update_cursor_instance();
@@ -207,7 +207,6 @@ class GridMapEditor : public VBoxContainer {
bool do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click);
friend class GridMapEditorPlugin;
- Panel *theme_panel;
protected:
void _notification(int p_what);
diff --git a/modules/mono/glue/cs_files/Rect2.cs b/modules/mono/glue/cs_files/Rect2.cs
index 6f16656573..e772665009 100644
--- a/modules/mono/glue/cs_files/Rect2.cs
+++ b/modules/mono/glue/cs_files/Rect2.cs
@@ -11,24 +11,24 @@ namespace Godot
[StructLayout(LayoutKind.Sequential)]
public struct Rect2 : IEquatable<Rect2>
{
- private Vector2 position;
- private Vector2 size;
+ private Vector2 _position;
+ private Vector2 _size;
public Vector2 Position
{
- get { return position; }
- set { position = value; }
+ get { return _position; }
+ set { _position = value; }
}
public Vector2 Size
{
- get { return size; }
- set { size = value; }
+ get { return _size; }
+ set { _size = value; }
}
public Vector2 End
{
- get { return position + size; }
+ get { return _position + _size; }
}
public real_t Area
@@ -36,6 +36,13 @@ namespace Godot
get { return GetArea(); }
}
+ public Rect2 Abs()
+ {
+ Vector2 end = End;
+ Vector2 topLeft = new Vector2(Mathf.Min(_position.x, end.x), Mathf.Min(_position.y, end.y));
+ return new Rect2(topLeft, _size.Abs());
+ }
+
public Rect2 Clip(Rect2 b)
{
var newRect = b;
@@ -43,31 +50,31 @@ namespace Godot
if (!Intersects(newRect))
return new Rect2();
- newRect.position.x = Mathf.Max(b.position.x, position.x);
- newRect.position.y = Mathf.Max(b.position.y, position.y);
+ newRect._position.x = Mathf.Max(b._position.x, _position.x);
+ newRect._position.y = Mathf.Max(b._position.y, _position.y);
- Vector2 bEnd = b.position + b.size;
- Vector2 end = position + size;
+ Vector2 bEnd = b._position + b._size;
+ Vector2 end = _position + _size;
- newRect.size.x = Mathf.Min(bEnd.x, end.x) - newRect.position.x;
- newRect.size.y = Mathf.Min(bEnd.y, end.y) - newRect.position.y;
+ newRect._size.x = Mathf.Min(bEnd.x, end.x) - newRect._position.x;
+ newRect._size.y = Mathf.Min(bEnd.y, end.y) - newRect._position.y;
return newRect;
}
public bool Encloses(Rect2 b)
{
- return b.position.x >= position.x && b.position.y >= position.y &&
- b.position.x + b.size.x < position.x + size.x &&
- b.position.y + b.size.y < position.y + size.y;
+ return b._position.x >= _position.x && b._position.y >= _position.y &&
+ b._position.x + b._size.x < _position.x + _size.x &&
+ b._position.y + b._size.y < _position.y + _size.y;
}
public Rect2 Expand(Vector2 to)
{
var expanded = this;
- Vector2 begin = expanded.position;
- Vector2 end = expanded.position + expanded.size;
+ Vector2 begin = expanded._position;
+ Vector2 end = expanded._position + expanded._size;
if (to.x < begin.x)
begin.x = to.x;
@@ -79,25 +86,25 @@ namespace Godot
if (to.y > end.y)
end.y = to.y;
- expanded.position = begin;
- expanded.size = end - begin;
+ expanded._position = begin;
+ expanded._size = end - begin;
return expanded;
}
public real_t GetArea()
{
- return size.x * size.y;
+ return _size.x * _size.y;
}
public Rect2 Grow(real_t by)
{
var g = this;
- g.position.x -= by;
- g.position.y -= by;
- g.size.x += by * 2;
- g.size.y += by * 2;
+ g._position.x -= by;
+ g._position.y -= by;
+ g._size.x += by * 2;
+ g._size.y += by * 2;
return g;
}
@@ -106,10 +113,10 @@ namespace Godot
{
var g = this;
- g.position.x -= left;
- g.position.y -= top;
- g.size.x += left + right;
- g.size.y += top + bottom;
+ g._position.x -= left;
+ g._position.y -= top;
+ g._size.x += left + right;
+ g._size.y += top + bottom;
return g;
}
@@ -128,19 +135,19 @@ namespace Godot
public bool HasNoArea()
{
- return size.x <= 0 || size.y <= 0;
+ return _size.x <= 0 || _size.y <= 0;
}
public bool HasPoint(Vector2 point)
{
- if (point.x < position.x)
+ if (point.x < _position.x)
return false;
- if (point.y < position.y)
+ if (point.y < _position.y)
return false;
- if (point.x >= position.x + size.x)
+ if (point.x >= _position.x + _size.x)
return false;
- if (point.y >= position.y + size.y)
+ if (point.y >= _position.y + _size.y)
return false;
return true;
@@ -148,13 +155,13 @@ namespace Godot
public bool Intersects(Rect2 b)
{
- if (position.x > b.position.x + b.size.x)
+ if (_position.x > b._position.x + b._size.x)
return false;
- if (position.x + size.x < b.position.x)
+ if (_position.x + _size.x < b._position.x)
return false;
- if (position.y > b.position.y + b.size.y)
+ if (_position.y > b._position.y + b._size.y)
return false;
- if (position.y + size.y < b.position.y)
+ if (_position.y + _size.y < b._position.y)
return false;
return true;
@@ -164,13 +171,13 @@ namespace Godot
{
Rect2 newRect;
- newRect.position.x = Mathf.Min(b.position.x, position.x);
- newRect.position.y = Mathf.Min(b.position.y, position.y);
+ newRect._position.x = Mathf.Min(b._position.x, _position.x);
+ newRect._position.y = Mathf.Min(b._position.y, _position.y);
- newRect.size.x = Mathf.Max(b.position.x + b.size.x, position.x + size.x);
- newRect.size.y = Mathf.Max(b.position.y + b.size.y, position.y + size.y);
+ newRect._size.x = Mathf.Max(b._position.x + b._size.x, _position.x + _size.x);
+ newRect._size.y = Mathf.Max(b._position.y + b._size.y, _position.y + _size.y);
- newRect.size = newRect.size - newRect.position; // Make relative again
+ newRect._size = newRect._size - newRect._position; // Make relative again
return newRect;
}
@@ -178,23 +185,23 @@ namespace Godot
// Constructors
public Rect2(Vector2 position, Vector2 size)
{
- this.position = position;
- this.size = size;
+ _position = position;
+ _size = size;
}
public Rect2(Vector2 position, real_t width, real_t height)
{
- this.position = position;
- size = new Vector2(width, height);
+ _position = position;
+ _size = new Vector2(width, height);
}
public Rect2(real_t x, real_t y, Vector2 size)
{
- position = new Vector2(x, y);
- this.size = size;
+ _position = new Vector2(x, y);
+ _size = size;
}
public Rect2(real_t x, real_t y, real_t width, real_t height)
{
- position = new Vector2(x, y);
- size = new Vector2(width, height);
+ _position = new Vector2(x, y);
+ _size = new Vector2(width, height);
}
public static bool operator ==(Rect2 left, Rect2 right)
@@ -219,20 +226,20 @@ namespace Godot
public bool Equals(Rect2 other)
{
- return position.Equals(other.position) && size.Equals(other.size);
+ return _position.Equals(other._position) && _size.Equals(other._size);
}
public override int GetHashCode()
{
- return position.GetHashCode() ^ size.GetHashCode();
+ return _position.GetHashCode() ^ _size.GetHashCode();
}
public override string ToString()
{
return String.Format("({0}, {1})", new object[]
{
- position.ToString(),
- size.ToString()
+ _position.ToString(),
+ _size.ToString()
});
}
@@ -240,8 +247,8 @@ namespace Godot
{
return String.Format("({0}, {1})", new object[]
{
- position.ToString(format),
- size.ToString(format)
+ _position.ToString(format),
+ _size.ToString(format)
});
}
}
diff --git a/modules/squish/image_compress_squish.cpp b/modules/squish/image_compress_squish.cpp
index 6aaabb9d9b..25fc897146 100644
--- a/modules/squish/image_compress_squish.cpp
+++ b/modules/squish/image_compress_squish.cpp
@@ -75,7 +75,7 @@ void image_decompress_squish(Image *p_image) {
p_image->create(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data);
}
-void image_compress_squish(Image *p_image, Image::CompressSource p_source) {
+void image_compress_squish(Image *p_image, float p_lossy_quality, Image::CompressSource p_source) {
if (p_image->get_format() >= Image::FORMAT_DXT1)
return; //do not compress, already compressed
@@ -86,6 +86,12 @@ void image_compress_squish(Image *p_image, Image::CompressSource p_source) {
if (p_image->get_format() <= Image::FORMAT_RGBA8) {
int squish_comp = squish::kColourRangeFit;
+
+ if (p_lossy_quality > 0.85)
+ squish_comp = squish::kColourIterativeClusterFit;
+ else if (p_lossy_quality > 0.75)
+ squish_comp = squish::kColourClusterFit;
+
Image::Format target_format = Image::FORMAT_RGBA8;
Image::DetectChannels dc = p_image->get_detected_channels();
diff --git a/modules/squish/image_compress_squish.h b/modules/squish/image_compress_squish.h
index c022063fe5..6da947beea 100644
--- a/modules/squish/image_compress_squish.h
+++ b/modules/squish/image_compress_squish.h
@@ -33,7 +33,7 @@
#include "image.h"
-void image_compress_squish(Image *p_image, Image::CompressSource p_source);
+void image_compress_squish(Image *p_image, float p_lossy_quality, Image::CompressSource p_source);
void image_decompress_squish(Image *p_image);
#endif // IMAGE_COMPRESS_SQUISH_H
diff --git a/platform/android/SCsub b/platform/android/SCsub
index a65dab9668..31fee5722c 100644
--- a/platform/android/SCsub
+++ b/platform/android/SCsub
@@ -2,6 +2,8 @@
import shutil
from compat import open_utf8
+from distutils.version import LooseVersion
+from detect import get_ndk_version
Import('env')
@@ -169,3 +171,7 @@ if lib_arch_dir != '':
out_dir = '#platform/android/java/libs/' + lib_type_dir + '/' + lib_arch_dir
env_android.Command(out_dir + '/libgodot_android.so', '#bin/libgodot' + env['SHLIBSUFFIX'], Move("$TARGET", "$SOURCE"))
+ ndk_version = get_ndk_version(env["ANDROID_NDK_ROOT"])
+ if ndk_version != None and LooseVersion(ndk_version) >= LooseVersion("15.0.4075724"):
+ stl_lib_path = str(env['ANDROID_NDK_ROOT']) + '/sources/cxx-stl/llvm-libc++/libs/' + lib_arch_dir + '/libc++_shared.so'
+ env_android.Command(out_dir + '/libc++_shared.so', stl_lib_path, Copy("$TARGET", "$SOURCE")) \ No newline at end of file
diff --git a/platform/android/detect.py b/platform/android/detect.py
index 0c6c9fdca3..b22e85b2c1 100644
--- a/platform/android/detect.py
+++ b/platform/android/detect.py
@@ -204,18 +204,26 @@ def configure(env):
## Compile flags
+ if env['android_stl']:
+ env.Append(CPPFLAGS=["-isystem", env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/llvm-libc++/include"])
+ env.Append(CPPFLAGS=["-isystem", env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/llvm-libc++abi/include"])
+ env.Append(CXXFLAGS=['-frtti',"-std=gnu++14"])
+ else:
+ env.Append(CXXFLAGS=['-fno-rtti', '-fno-exceptions', '-DNO_SAFE_CAST'])
+
ndk_version = get_ndk_version(env["ANDROID_NDK_ROOT"])
if ndk_version != None and LooseVersion(ndk_version) >= LooseVersion("15.0.4075724"):
print("Using NDK unified headers")
sysroot = env["ANDROID_NDK_ROOT"] + "/sysroot"
- env.Append(CPPFLAGS=["-isystem", sysroot + "/usr/include"])
+ env.Append(CPPFLAGS=["--sysroot="+sysroot])
env.Append(CPPFLAGS=["-isystem", sysroot + "/usr/include/" + abi_subpath])
+ env.Append(CPPFLAGS=["-isystem", env["ANDROID_NDK_ROOT"] + "/sources/android/support/include"])
# For unified headers this define has to be set manually
env.Append(CPPFLAGS=["-D__ANDROID_API__=" + str(get_platform(env['ndk_platform']))])
else:
print("Using NDK deprecated headers")
env.Append(CPPFLAGS=["-isystem", lib_sysroot + "/usr/include"])
-
+
env.Append(CPPFLAGS='-fpic -ffunction-sections -funwind-tables -fstack-protector-strong -fvisibility=hidden -fno-strict-aliasing'.split())
env.Append(CPPFLAGS='-DNO_STATVFS -DGLES_ENABLED'.split())
@@ -246,23 +254,24 @@ def configure(env):
env.Append(CPPFLAGS=target_opts)
env.Append(CPPFLAGS=common_opts)
- if env['android_stl']:
- env.Append(CPPPATH=[env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/gnu-libstdc++/4.9/include"])
- env.Append(CPPPATH=[env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/gnu-libstdc++/4.9/libs/" + arch_subpath + "/include"])
- env.Append(LIBPATH=[env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/gnu-libstdc++/4.9/libs/" + arch_subpath])
- env.Append(LIBS=["gnustl_static"])
- else:
- env.Append(CXXFLAGS=['-fno-rtti', '-fno-exceptions', '-DNO_SAFE_CAST'])
-
## Link flags
-
- env['LINKFLAGS'] = ['-shared', '--sysroot=' + lib_sysroot, '-Wl,--warn-shared-textrel']
+ if ndk_version != None and LooseVersion(ndk_version) >= LooseVersion("15.0.4075724"):
+ if LooseVersion(ndk_version) >= LooseVersion("17.1.4828580"):
+ env.Append(LINKFLAGS=['-Wl,--exclude-libs,libgcc.a','-Wl,--exclude-libs,libatomic.a','-nostdlib++'])
+ env.Append(LINKFLAGS=['-shared', '--sysroot=' + lib_sysroot, '-Wl,--warn-shared-textrel'])
+ env.Append(LIBPATH=[env["ANDROID_NDK_ROOT"] + "/sources/cxx-stl/llvm-libc++/libs/"+arch_subpath+"/"])
+ env.Append(LINKFLAGS=[env["ANDROID_NDK_ROOT"] +"/sources/cxx-stl/llvm-libc++/libs/"+arch_subpath+"/libandroid_support.a"])
+ env.Append(LINKFLAGS=[env["ANDROID_NDK_ROOT"] +"/sources/cxx-stl/llvm-libc++/libs/"+arch_subpath+"/libc++_shared.so"])
+ else:
+ env.Append(LINKFLAGS=['-shared', '--sysroot=' + lib_sysroot, '-Wl,--warn-shared-textrel'])
+ if mt_link:
+ env.Append(LINKFLAGS=['-Wl,--threads'])
+
if env["android_arch"] == "armv7":
env.Append(LINKFLAGS='-Wl,--fix-cortex-a8'.split())
env.Append(LINKFLAGS='-Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now'.split())
env.Append(LINKFLAGS='-Wl,-soname,libgodot_android.so -Wl,--gc-sections'.split())
- if mt_link:
- env.Append(LINKFLAGS=['-Wl,--threads'])
+
env.Append(LINKFLAGS=target_opts)
env.Append(LINKFLAGS=common_opts)
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index c6a651bc7d..56ac467dc6 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -409,7 +409,87 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
input->set_mouse_in_window(false);
} break;
+ case WM_INPUT: {
+ if (mouse_mode != MOUSE_MODE_CAPTURED || !use_raw_input) {
+ break;
+ }
+
+ UINT dwSize;
+
+ GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &dwSize, sizeof(RAWINPUTHEADER));
+ LPBYTE lpb = new BYTE[dwSize];
+ if (lpb == NULL) {
+ return 0;
+ }
+
+ if (GetRawInputData((HRAWINPUT)lParam, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER)) != dwSize)
+ OutputDebugString(TEXT("GetRawInputData does not return correct size !\n"));
+
+ RAWINPUT *raw = (RAWINPUT *)lpb;
+
+ if (raw->header.dwType == RIM_TYPEMOUSE) {
+ Ref<InputEventMouseMotion> mm;
+ mm.instance();
+
+ mm->set_control(control_mem);
+ mm->set_shift(shift_mem);
+ mm->set_alt(alt_mem);
+
+ mm->set_button_mask(last_button_state);
+
+ Point2i c(video_mode.width / 2, video_mode.height / 2);
+
+ // centering just so it works as before
+ POINT pos = { (int)c.x, (int)c.y };
+ ClientToScreen(hWnd, &pos);
+ SetCursorPos(pos.x, pos.y);
+
+ mm->set_position(c);
+ mm->set_global_position(c);
+ input->set_mouse_position(c);
+ mm->set_speed(Vector2(0, 0));
+
+ if (raw->data.mouse.usFlags ==MOUSE_MOVE_RELATIVE) {
+ mm->set_relative(Vector2(raw->data.mouse.lLastX, raw->data.mouse.lLastY));
+
+ } else if (raw->data.mouse.usFlags == MOUSE_MOVE_ABSOLUTE) {
+
+ int nScreenWidth = GetSystemMetrics(SM_CXVIRTUALSCREEN);
+ int nScreenHeight = GetSystemMetrics(SM_CYVIRTUALSCREEN);
+ int nScreenLeft = GetSystemMetrics(SM_XVIRTUALSCREEN);
+ int nScreenTop = GetSystemMetrics(SM_YVIRTUALSCREEN);
+
+ Vector2 abs_pos(
+ (double(raw->data.mouse.lLastX) - 65536.0 / (nScreenWidth) ) * nScreenWidth / 65536.0 + nScreenLeft,
+ (double(raw->data.mouse.lLastY) - 65536.0 / (nScreenHeight) ) * nScreenHeight / 65536.0 + nScreenTop
+ );
+
+ POINT coords; //client coords
+ coords.x = abs_pos.x;
+ coords.y = abs_pos.y;
+
+ ScreenToClient(hWnd, &coords);
+
+
+ mm->set_relative(Vector2(coords.x - old_x, coords.y - old_y ));
+ old_x = coords.x;
+ old_y = coords.y;
+
+ /*Input.mi.dx = (int)((((double)(pos.x)-nScreenLeft) * 65536) / nScreenWidth + 65536 / (nScreenWidth));
+ Input.mi.dy = (int)((((double)(pos.y)-nScreenTop) * 65536) / nScreenHeight + 65536 / (nScreenHeight));
+ */
+
+ }
+
+ if (window_has_focus && main_loop)
+ input->parse_input_event(mm);
+ }
+ delete[] lpb;
+ } break;
case WM_MOUSEMOVE: {
+ if (mouse_mode == MOUSE_MODE_CAPTURED && use_raw_input) {
+ break;
+ }
if (input->is_emulating_mouse_from_touch()) {
// Universal translation enabled; ignore OS translation
@@ -1088,6 +1168,20 @@ Error OS_Windows::initialize(const VideoMode &p_desired, int p_video_driver, int
return ERR_UNAVAILABLE;
}
+ use_raw_input = true;
+
+ RAWINPUTDEVICE Rid[1];
+
+ Rid[0].usUsagePage = 0x01;
+ Rid[0].usUsage = 0x02;
+ Rid[0].dwFlags = 0;
+ Rid[0].hwndTarget = 0;
+
+ if (RegisterRawInputDevices(Rid, 1, sizeof(Rid[0])) == FALSE) {
+ //registration failed.
+ use_raw_input = false;
+ }
+
pre_fs_valid = true;
if (video_mode.fullscreen) {
diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h
index 8e39e4c990..243d4bb328 100644
--- a/platform/windows/os_windows.h
+++ b/platform/windows/os_windows.h
@@ -125,6 +125,7 @@ class OS_Windows : public OS {
bool force_quit;
bool window_has_focus;
uint32_t last_button_state;
+ bool use_raw_input;
HCURSOR cursors[CURSOR_MAX] = { NULL };
CursorShape cursor_shape;