summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/etc/image_etc.cpp14
-rw-r--r--modules/gdnative/gdnative/array.cpp11
-rw-r--r--modules/gdnative/gdnative_api.json20
-rw-r--r--modules/gdnative/include/gdnative/array.h4
-rw-r--r--modules/gdnative/include/gdnative/gdnative.h2
-rw-r--r--modules/gdscript/gdscript_functions.cpp30
-rw-r--r--modules/gdscript/gdscript_functions.h2
-rw-r--r--modules/gridmap/grid_map_editor_plugin.cpp10
-rw-r--r--modules/mono/glue/cs_files/Mathf.cs10
-rw-r--r--modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml50
-rw-r--r--modules/visual_script/visual_script_builtin_funcs.cpp38
-rw-r--r--modules/visual_script/visual_script_builtin_funcs.h2
12 files changed, 164 insertions, 29 deletions
diff --git a/modules/etc/image_etc.cpp b/modules/etc/image_etc.cpp
index dc7d23bbd7..941df41694 100644
--- a/modules/etc/image_etc.cpp
+++ b/modules/etc/image_etc.cpp
@@ -129,7 +129,7 @@ static void _compress_etc(Image *p_img, float p_lossy_quality, bool force_etc1_f
PoolVector<uint8_t>::Read r = img->get_data().read();
int target_size = Image::get_image_data_size(imgw, imgh, etc_format, p_img->has_mipmaps() ? -1 : 0);
- int mmc = p_img->has_mipmaps() ? Image::get_image_required_mipmaps(imgw, imgh, etc_format) : 0;
+ int mmc = 1 + (p_img->has_mipmaps() ? Image::get_image_required_mipmaps(imgw, imgh, etc_format) : 0);
PoolVector<uint8_t> dst_data;
dst_data.resize(target_size);
@@ -155,7 +155,7 @@ static void _compress_etc(Image *p_img, float p_lossy_quality, bool force_etc1_f
print_line("begin encoding, format: " + Image::get_format_name(etc_format));
uint64_t t = OS::get_singleton()->get_ticks_msec();
- for (int i = 0; i < mmc + 1; i++) {
+ for (int i = 0; i < mmc; i++) {
// convert source image to internal etc2comp format (which is equivalent to Image::FORMAT_RGBAF)
// NOTE: We can alternatively add a case to Image::convert to handle Image::FORMAT_RGBAF conversion.
int mipmap_ofs = 0, mipmap_size = 0, mipmap_w = 0, mipmap_h = 0;
@@ -163,9 +163,9 @@ static void _compress_etc(Image *p_img, float p_lossy_quality, bool force_etc1_f
const uint8_t *src = &r[mipmap_ofs];
Etc::ColorFloatRGBA *src_rgba_f = new Etc::ColorFloatRGBA[mipmap_w * mipmap_h];
- for (int i = 0; i < mipmap_w * mipmap_h; i++) {
- int si = i * 4; // RGBA8
- src_rgba_f[i] = Etc::ColorFloatRGBA::ConvertFromRGBA8(src[si], src[si + 1], src[si + 2], src[si + 3]);
+ for (int j = 0; j < mipmap_w * mipmap_h; j++) {
+ int si = j * 4; // RGBA8
+ src_rgba_f[j] = Etc::ColorFloatRGBA::ConvertFromRGBA8(src[si], src[si + 1], src[si + 2], src[si + 3]);
}
unsigned char *etc_data = NULL;
@@ -173,15 +173,17 @@ static void _compress_etc(Image *p_img, float p_lossy_quality, bool force_etc1_f
unsigned int extended_width = 0, extended_height = 0;
Etc::Encode((float *)src_rgba_f, mipmap_w, mipmap_h, etc2comp_etc_format, error_metric, effort, num_cpus, num_cpus, &etc_data, &etc_data_len, &extended_width, &extended_height, &encoding_time);
+ CRASH_COND(wofs + etc_data_len > target_size);
memcpy(&w[wofs], etc_data, etc_data_len);
wofs += etc_data_len;
delete[] etc_data;
delete[] src_rgba_f;
}
+
print_line("time encoding: " + rtos(OS::get_singleton()->get_ticks_msec() - t));
- p_img->create(imgw, imgh, mmc > 1 ? true : false, etc_format, dst_data);
+ p_img->create(imgw, imgh, p_img->has_mipmaps(), etc_format, dst_data);
}
static void _compress_etc1(Image *p_img, float p_lossy_quality) {
diff --git a/modules/gdnative/gdnative/array.cpp b/modules/gdnative/gdnative/array.cpp
index e0d9514985..8351c43574 100644
--- a/modules/gdnative/gdnative/array.cpp
+++ b/modules/gdnative/gdnative/array.cpp
@@ -302,6 +302,17 @@ void GDAPI godot_array_sort_custom(godot_array *p_self, godot_object *p_obj, con
self->sort_custom((Object *)p_obj, *func);
}
+godot_int GDAPI godot_array_bsearch(godot_array *p_self, const godot_variant *p_value, const godot_bool p_before) {
+ Array *self = (Array *)p_self;
+ return self->bsearch((const Variant *)p_value, p_before);
+}
+
+godot_int GDAPI godot_array_bsearch_custom(godot_array *p_self, const godot_variant *p_value, godot_object *p_obj, const godot_string *p_func, const godot_bool p_before) {
+ Array *self = (Array *)p_self;
+ const String *func = (const String *)p_func;
+ return self->bsearch_custom((const Variant *)p_value, (Object *)p_obj, *func, p_before);
+}
+
void GDAPI godot_array_destroy(godot_array *p_self) {
((Array *)p_self)->~Array();
}
diff --git a/modules/gdnative/gdnative_api.json b/modules/gdnative/gdnative_api.json
index 007c7955d4..0438a196cf 100644
--- a/modules/gdnative/gdnative_api.json
+++ b/modules/gdnative/gdnative_api.json
@@ -2680,6 +2680,26 @@
]
},
{
+ "name": "godot_array_bsearch",
+ "return_type": "godot_int",
+ "arguments": [
+ ["godot_array *", "p_self"],
+ ["const godot_variant *", "p_value"],
+ ["const godot_bool", "p_before"]
+ ]
+ },
+ {
+ "name": "godot_array_bsearch_custom",
+ "return_type": "godot_int",
+ "arguments": [
+ ["godot_array *", "p_self"],
+ ["const godot_variant *", "p_value"],
+ ["godot_object *", "p_obj"],
+ ["const godot_string *", "p_func"],
+ ["const godot_bool", "p_before"]
+ ]
+ },
+ {
"name": "godot_array_destroy",
"return_type": "void",
"arguments": [
diff --git a/modules/gdnative/include/gdnative/array.h b/modules/gdnative/include/gdnative/array.h
index 01ae61e280..484ffd10ba 100644
--- a/modules/gdnative/include/gdnative/array.h
+++ b/modules/gdnative/include/gdnative/array.h
@@ -124,6 +124,10 @@ void GDAPI godot_array_sort(godot_array *p_self);
void GDAPI godot_array_sort_custom(godot_array *p_self, godot_object *p_obj, const godot_string *p_func);
+godot_int GDAPI godot_array_bsearch(godot_array *p_self, const godot_variant *p_value, const godot_bool p_before);
+
+godot_int GDAPI godot_array_bsearch_custom(godot_array *p_self, const godot_variant *p_value, godot_object *p_obj, const godot_string *p_func, const godot_bool p_before);
+
void GDAPI godot_array_destroy(godot_array *p_self);
#ifdef __cplusplus
diff --git a/modules/gdnative/include/gdnative/gdnative.h b/modules/gdnative/include/gdnative/gdnative.h
index 0a884e6106..6e69d43469 100644
--- a/modules/gdnative/include/gdnative/gdnative.h
+++ b/modules/gdnative/include/gdnative/gdnative.h
@@ -53,7 +53,7 @@ extern "C" {
// This is for libraries *using* the header, NOT GODOT EXPOSING STUFF!!
#ifdef _WIN32
-#define GDN_EXPORT
+#define GDN_EXPORT __declspec(dllexport)
#else
#define GDN_EXPORT
#endif
diff --git a/modules/gdscript/gdscript_functions.cpp b/modules/gdscript/gdscript_functions.cpp
index c6066ceefb..ca0a9582a7 100644
--- a/modules/gdscript/gdscript_functions.cpp
+++ b/modules/gdscript/gdscript_functions.cpp
@@ -84,6 +84,8 @@ const char *GDScriptFunctions::get_func_name(Function p_func) {
"rad2deg",
"linear2db",
"db2linear",
+ "polar2cartesian",
+ "cartesian2polar",
"wrapi",
"wrapf",
"max",
@@ -408,6 +410,22 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_
VALIDATE_ARG_NUM(0);
r_ret = Math::db2linear((double)*p_args[0]);
} break;
+ case MATH_POLAR2CARTESIAN: {
+ VALIDATE_ARG_COUNT(2);
+ VALIDATE_ARG_NUM(0);
+ VALIDATE_ARG_NUM(1);
+ double r = *p_args[0];
+ double th = *p_args[1];
+ r_ret = Vector2(r * Math::cos(th), r * Math::sin(th));
+ } break;
+ case MATH_CARTESIAN2POLAR: {
+ VALIDATE_ARG_COUNT(2);
+ VALIDATE_ARG_NUM(0);
+ VALIDATE_ARG_NUM(1);
+ double x = *p_args[0];
+ double y = *p_args[1];
+ r_ret = Vector2(Math::sqrt(x * x + y * y), Math::atan2(y, x));
+ } break;
case MATH_WRAP: {
VALIDATE_ARG_COUNT(3);
r_ret = Math::wrapi((int64_t)*p_args[0], (int64_t)*p_args[1], (int64_t)*p_args[2]);
@@ -1296,6 +1314,8 @@ bool GDScriptFunctions::is_deterministic(Function p_func) {
case MATH_RAD2DEG:
case MATH_LINEAR2DB:
case MATH_DB2LINEAR:
+ case MATH_POLAR2CARTESIAN:
+ case MATH_CARTESIAN2POLAR:
case MATH_WRAP:
case MATH_WRAPF:
case LOGIC_MAX:
@@ -1526,6 +1546,16 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) {
mi.return_val.type = Variant::REAL;
return mi;
} break;
+ case MATH_POLAR2CARTESIAN: {
+ MethodInfo mi("polar2cartesian", PropertyInfo(Variant::REAL, "r"), PropertyInfo(Variant::REAL, "th"));
+ mi.return_val.type = Variant::VECTOR2;
+ return mi;
+ } break;
+ case MATH_CARTESIAN2POLAR: {
+ MethodInfo mi("cartesian2polar", PropertyInfo(Variant::REAL, "x"), PropertyInfo(Variant::REAL, "y"));
+ mi.return_val.type = Variant::VECTOR2;
+ return mi;
+ } break;
case MATH_WRAP: {
MethodInfo mi("wrapi", PropertyInfo(Variant::INT, "value"), PropertyInfo(Variant::INT, "min"), PropertyInfo(Variant::INT, "max"));
mi.return_val.type = Variant::INT;
diff --git a/modules/gdscript/gdscript_functions.h b/modules/gdscript/gdscript_functions.h
index ecbede83a8..d1c5815cec 100644
--- a/modules/gdscript/gdscript_functions.h
+++ b/modules/gdscript/gdscript_functions.h
@@ -75,6 +75,8 @@ public:
MATH_RAD2DEG,
MATH_LINEAR2DB,
MATH_DB2LINEAR,
+ MATH_POLAR2CARTESIAN,
+ MATH_CARTESIAN2POLAR,
MATH_WRAP,
MATH_WRAPF,
LOGIC_MAX,
diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp
index 491adb31ee..3a5d0fd3fc 100644
--- a/modules/gridmap/grid_map_editor_plugin.cpp
+++ b/modules/gridmap/grid_map_editor_plugin.cpp
@@ -623,6 +623,16 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu
return do_input_action(p_camera, mm->get_position(), false);
}
+ Ref<InputEventPanGesture> pan_gesture = p_event;
+ if (pan_gesture.is_valid()) {
+
+ if (pan_gesture->get_command() || pan_gesture->get_shift()) {
+ const real_t delta = pan_gesture->get_delta().y;
+ floor->set_value(floor->get_value() + SGN(delta));
+ return true;
+ }
+ }
+
return false;
}
diff --git a/modules/mono/glue/cs_files/Mathf.cs b/modules/mono/glue/cs_files/Mathf.cs
index cb0eb1acdd..37e6e5bbe3 100644
--- a/modules/mono/glue/cs_files/Mathf.cs
+++ b/modules/mono/glue/cs_files/Mathf.cs
@@ -35,6 +35,11 @@ namespace Godot
return (float)Math.Atan2(x, y);
}
+ public static Vector2 cartesian2polar(float x, float y)
+ {
+ return new Vector2(sqrt(x * x + y * y), atan2(y, x));
+ }
+
public static float ceil(float s)
{
return (float)Math.Ceiling(s);
@@ -176,6 +181,11 @@ namespace Godot
return val;
}
+ public static Vector2 polar2cartesian(float r, float th)
+ {
+ return new Vector2(r * cos(th), r * sin(th));
+ }
+
public static float pow(float x, float y)
{
return (float)Math.Pow(x, y);
diff --git a/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml b/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml
index 27231574d7..c45c8d2b64 100644
--- a/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml
+++ b/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml
@@ -151,68 +151,74 @@
<constant name="MATH_DB2LINEAR" value="39">
Convert the input from decibel volume to linear volume.
</constant>
- <constant name="MATH_WRAP" value="40">
+ <constant name="MATH_POLAR2CARTESIAN" value="40">
+ Converts a 2D point expressed in the polar coordinate system (a distance from the origin [code]r[/code] and an angle [code]th[/code]) to the cartesian coordinate system (x and y axis).
</constant>
- <constant name="MATH_WRAPF" value="41">
+ <constant name="MATH_CARTESIAN2POLAR" value="41">
+ Converts a 2D point expressed in the cartesian coordinate system (x and y axis) to the polar coordinate system (a distance from the origin and an angle).
</constant>
- <constant name="LOGIC_MAX" value="42">
+ <constant name="MATH_WRAP" value="42">
+ </constant>
+ <constant name="MATH_WRAPF" value="43">
+ </constant>
+ <constant name="LOGIC_MAX" value="44">
Return the greater of the two numbers, also known as their maximum.
</constant>
- <constant name="LOGIC_MIN" value="43">
+ <constant name="LOGIC_MIN" value="45">
Return the lesser of the two numbers, also known as their minimum.
</constant>
- <constant name="LOGIC_CLAMP" value="44">
+ <constant name="LOGIC_CLAMP" value="46">
Return the input clamped inside the given range, ensuring the result is never outside it. Equivalent to `min(max(input, range_low), range_high)`
</constant>
- <constant name="LOGIC_NEAREST_PO2" value="45">
+ <constant name="LOGIC_NEAREST_PO2" value="46">
Return the nearest power of 2 to the input.
</constant>
- <constant name="OBJ_WEAKREF" value="46">
+ <constant name="OBJ_WEAKREF" value="47">
Create a [WeakRef] from the input.
</constant>
- <constant name="FUNC_FUNCREF" value="47">
+ <constant name="FUNC_FUNCREF" value="48">
Create a [FuncRef] from the input.
</constant>
- <constant name="TYPE_CONVERT" value="48">
+ <constant name="TYPE_CONVERT" value="49">
Convert between types.
</constant>
- <constant name="TYPE_OF" value="49">
+ <constant name="TYPE_OF" value="50">
Return the type of the input as an integer. Check [enum Variant.Type] for the integers that might be returned.
</constant>
- <constant name="TYPE_EXISTS" value="50">
+ <constant name="TYPE_EXISTS" value="51">
Checks if a type is registered in the [ClassDB].
</constant>
- <constant name="TEXT_CHAR" value="51">
+ <constant name="TEXT_CHAR" value="52">
Return a character with the given ascii value.
</constant>
- <constant name="TEXT_STR" value="52">
+ <constant name="TEXT_STR" value="53">
Convert the input to a string.
</constant>
- <constant name="TEXT_PRINT" value="53">
+ <constant name="TEXT_PRINT" value="54">
Print the given string to the output window.
</constant>
- <constant name="TEXT_PRINTERR" value="54">
+ <constant name="TEXT_PRINTERR" value="55">
Print the given string to the standard error output.
</constant>
- <constant name="TEXT_PRINTRAW" value="55">
+ <constant name="TEXT_PRINTRAW" value="56">
Print the given string to the standard output, without adding a newline.
</constant>
- <constant name="VAR_TO_STR" value="56">
+ <constant name="VAR_TO_STR" value="57">
Serialize a [Variant] to a string.
</constant>
- <constant name="STR_TO_VAR" value="57">
+ <constant name="STR_TO_VAR" value="58">
Deserialize a [Variant] from a string serialized using [VAR_TO_STR].
</constant>
- <constant name="VAR_TO_BYTES" value="58">
+ <constant name="VAR_TO_BYTES" value="59">
Serialize a [Variant] to a [PoolByteArray].
</constant>
- <constant name="BYTES_TO_VAR" value="59">
+ <constant name="BYTES_TO_VAR" value="60">
Deserialize a [Variant] from a [PoolByteArray] serialized using [VAR_TO_BYTES].
</constant>
- <constant name="COLORN" value="60">
+ <constant name="COLORN" value="61">
Return the [Color] with the given name and alpha ranging from 0 to 1. Note: names are defined in color_names.inc.
</constant>
- <constant name="FUNC_MAX" value="61">
+ <constant name="FUNC_MAX" value="62">
The maximum value the [member function] property can have.
</constant>
</constants>
diff --git a/modules/visual_script/visual_script_builtin_funcs.cpp b/modules/visual_script/visual_script_builtin_funcs.cpp
index 8f7fe58bee..32f7519125 100644
--- a/modules/visual_script/visual_script_builtin_funcs.cpp
+++ b/modules/visual_script/visual_script_builtin_funcs.cpp
@@ -78,6 +78,8 @@ const char *VisualScriptBuiltinFunc::func_name[VisualScriptBuiltinFunc::FUNC_MAX
"rad2deg",
"linear2db",
"db2linear",
+ "polar2cartesian",
+ "cartesian2polar",
"wrapi",
"wrapf",
"max",
@@ -191,6 +193,8 @@ int VisualScriptBuiltinFunc::get_func_argument_count(BuiltinFunc p_func) {
case MATH_EASE:
case MATH_STEPIFY:
case MATH_RANDOM:
+ case MATH_POLAR2CARTESIAN:
+ case MATH_CARTESIAN2POLAR:
case LOGIC_MAX:
case LOGIC_MIN:
case FUNC_FUNCREF:
@@ -368,6 +372,18 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
case MATH_DB2LINEAR: {
return PropertyInfo(Variant::REAL, "db");
} break;
+ case MATH_POLAR2CARTESIAN: {
+ if (p_idx == 0)
+ return PropertyInfo(Variant::REAL, "r");
+ else
+ return PropertyInfo(Variant::REAL, "th");
+ } break;
+ case MATH_CARTESIAN2POLAR: {
+ if (p_idx == 0)
+ return PropertyInfo(Variant::REAL, "x");
+ else
+ return PropertyInfo(Variant::REAL, "y");
+ } break;
case MATH_WRAP: {
if (p_idx == 0)
return PropertyInfo(Variant::INT, "value");
@@ -573,6 +589,10 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons
case MATH_DB2LINEAR: {
t = Variant::REAL;
} break;
+ case MATH_POLAR2CARTESIAN:
+ case MATH_CARTESIAN2POLAR: {
+ t = Variant::VECTOR2;
+ } break;
case MATH_WRAP: {
t = Variant::INT;
} break;
@@ -922,6 +942,20 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in
VALIDATE_ARG_NUM(0);
*r_return = Math::db2linear((double)*p_inputs[0]);
} break;
+ case VisualScriptBuiltinFunc::MATH_POLAR2CARTESIAN: {
+ VALIDATE_ARG_NUM(0);
+ VALIDATE_ARG_NUM(1);
+ double r = *p_inputs[0];
+ double th = *p_inputs[1];
+ *r_return = Vector2(r * Math::cos(th), r * Math::sin(th));
+ } break;
+ case VisualScriptBuiltinFunc::MATH_CARTESIAN2POLAR: {
+ VALIDATE_ARG_NUM(0);
+ VALIDATE_ARG_NUM(1);
+ double x = *p_inputs[0];
+ double y = *p_inputs[1];
+ *r_return = Vector2(Math::sqrt(x * x + y * y), Math::atan2(y, x));
+ } break;
case VisualScriptBuiltinFunc::MATH_WRAP: {
VALIDATE_ARG_NUM(0);
VALIDATE_ARG_NUM(1);
@@ -1294,6 +1328,8 @@ void VisualScriptBuiltinFunc::_bind_methods() {
BIND_ENUM_CONSTANT(MATH_RAD2DEG);
BIND_ENUM_CONSTANT(MATH_LINEAR2DB);
BIND_ENUM_CONSTANT(MATH_DB2LINEAR);
+ BIND_ENUM_CONSTANT(MATH_POLAR2CARTESIAN);
+ BIND_ENUM_CONSTANT(MATH_CARTESIAN2POLAR);
BIND_ENUM_CONSTANT(MATH_WRAP);
BIND_ENUM_CONSTANT(MATH_WRAPF);
BIND_ENUM_CONSTANT(LOGIC_MAX);
@@ -1381,6 +1417,8 @@ void register_visual_script_builtin_func_node() {
VisualScriptLanguage::singleton->add_register_func("functions/built_in/rad2deg", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RAD2DEG>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/linear2db", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_LINEAR2DB>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/db2linear", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_DB2LINEAR>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/polar2cartesian", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_POLAR2CARTESIAN>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/cartesian2polar", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_CARTESIAN2POLAR>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/wrapi", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_WRAP>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/wrapf", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_WRAPF>);
diff --git a/modules/visual_script/visual_script_builtin_funcs.h b/modules/visual_script/visual_script_builtin_funcs.h
index 34a2825938..54dc997b38 100644
--- a/modules/visual_script/visual_script_builtin_funcs.h
+++ b/modules/visual_script/visual_script_builtin_funcs.h
@@ -77,6 +77,8 @@ public:
MATH_RAD2DEG,
MATH_LINEAR2DB,
MATH_DB2LINEAR,
+ MATH_POLAR2CARTESIAN,
+ MATH_CARTESIAN2POLAR,
MATH_WRAP,
MATH_WRAPF,
LOGIC_MAX,