summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/image.cpp37
-rw-r--r--core/image.h3
-rw-r--r--core/math/math_2d.h3
-rw-r--r--core/os/threaded_array_processor.cpp2
-rw-r--r--core/os/threaded_array_processor.h80
-rw-r--r--core/script_language.cpp2
6 files changed, 126 insertions, 1 deletions
diff --git a/core/image.cpp b/core/image.cpp
index 422c0e407b..ba6848eecf 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -2287,6 +2287,9 @@ void Image::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_pixel", "x", "y", "color"), &Image::set_pixel);
ClassDB::bind_method(D_METHOD("get_pixel", "x", "y"), &Image::get_pixel);
+ ClassDB::bind_method(D_METHOD("load_png_from_buffer", "buffer"), &Image::load_png_from_buffer);
+ ClassDB::bind_method(D_METHOD("load_jpg_from_buffer", "buffer"), &Image::load_jpg_from_buffer);
+
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "_set_data", "_get_data");
BIND_ENUM_CONSTANT(FORMAT_L8); //luminance
@@ -2505,6 +2508,40 @@ String Image::get_format_name(Format p_format) {
return format_names[p_format];
}
+Error Image::load_png_from_buffer(const PoolVector<uint8_t> &p_array) {
+
+ int buffer_size = p_array.size();
+
+ ERR_FAIL_COND_V(buffer_size == 0, ERR_INVALID_PARAMETER);
+ ERR_FAIL_COND_V(!_png_mem_loader_func, ERR_INVALID_PARAMETER);
+
+ PoolVector<uint8_t>::Read r = p_array.read();
+
+ Ref<Image> image = _png_mem_loader_func(r.ptr(), buffer_size);
+ ERR_FAIL_COND_V(!image.is_valid(), ERR_PARSE_ERROR);
+
+ copy_internals_from(image);
+
+ return OK;
+}
+
+Error Image::load_jpg_from_buffer(const PoolVector<uint8_t> &p_array) {
+
+ int buffer_size = p_array.size();
+
+ ERR_FAIL_COND_V(buffer_size == 0, ERR_INVALID_PARAMETER);
+ ERR_FAIL_COND_V(!_jpg_mem_loader_func, ERR_INVALID_PARAMETER);
+
+ PoolVector<uint8_t>::Read r = p_array.read();
+
+ Ref<Image> image = _jpg_mem_loader_func(r.ptr(), buffer_size);
+ ERR_FAIL_COND_V(!image.is_valid(), ERR_PARSE_ERROR);
+
+ copy_internals_from(image);
+
+ return OK;
+}
+
Image::Image(const uint8_t *p_mem_png_jpg, int p_len) {
width = 0;
diff --git a/core/image.h b/core/image.h
index 24693aa706..cf7632a1f1 100644
--- a/core/image.h
+++ b/core/image.h
@@ -296,6 +296,9 @@ public:
static void set_compress_bc_func(void (*p_compress_func)(Image *, CompressSource));
static String get_format_name(Format p_format);
+ Error load_png_from_buffer(const PoolVector<uint8_t> &p_array);
+ Error load_jpg_from_buffer(const PoolVector<uint8_t> &p_array);
+
Image(const uint8_t *p_mem_png_jpg, int p_len = -1);
Image(const char **p_xpm);
diff --git a/core/math/math_2d.h b/core/math/math_2d.h
index 60351445c0..bbef19de7a 100644
--- a/core/math/math_2d.h
+++ b/core/math/math_2d.h
@@ -336,9 +336,10 @@ struct Rect2 {
g.size.height += p_by * 2;
return g;
}
+
inline Rect2 grow_margin(Margin p_margin, real_t p_amount) const {
Rect2 g = *this;
- g.grow_individual((MARGIN_LEFT == p_margin) ? p_amount : 0,
+ g = g.grow_individual((MARGIN_LEFT == p_margin) ? p_amount : 0,
(MARGIN_TOP == p_margin) ? p_amount : 0,
(MARGIN_RIGHT == p_margin) ? p_amount : 0,
(MARGIN_BOTTOM == p_margin) ? p_amount : 0);
diff --git a/core/os/threaded_array_processor.cpp b/core/os/threaded_array_processor.cpp
new file mode 100644
index 0000000000..8e92508ea5
--- /dev/null
+++ b/core/os/threaded_array_processor.cpp
@@ -0,0 +1,2 @@
+#include "threaded_array_processor.h"
+
diff --git a/core/os/threaded_array_processor.h b/core/os/threaded_array_processor.h
new file mode 100644
index 0000000000..e584fbb193
--- /dev/null
+++ b/core/os/threaded_array_processor.h
@@ -0,0 +1,80 @@
+#ifndef THREADED_ARRAY_PROCESSOR_H
+#define THREADED_ARRAY_PROCESSOR_H
+
+#include "os/mutex.h"
+#include "os/os.h"
+#include "os/thread.h"
+#include "safe_refcount.h"
+#include "thread_safe.h"
+
+template <class C, class U>
+struct ThreadArrayProcessData {
+ uint32_t elements;
+ uint32_t index;
+ C *instance;
+ U userdata;
+ void (C::*method)(uint32_t, U);
+
+ void process(uint32_t p_index) {
+ (instance->*method)(p_index, userdata);
+ }
+};
+
+#ifndef NO_THREADS
+
+template <class T>
+void process_array_thread(void *ud) {
+
+ T &data = *(T *)ud;
+ while (true) {
+ uint32_t index = atomic_increment(&data.index);
+ if (index >= data.elements)
+ break;
+ data.process(index);
+ }
+}
+
+template <class C, class M, class U>
+void thread_process_array(uint32_t p_elements, C *p_instance, M p_method, U p_userdata) {
+
+ ThreadArrayProcessData<C, U> data;
+ data.method = p_method;
+ data.instance = p_instance;
+ data.userdata = p_userdata;
+ data.index = 0;
+ data.elements = p_elements;
+ data.process(data.index); //process first, let threads increment for next
+
+ Vector<Thread *> threads;
+
+ threads.resize(OS::get_singleton()->get_processor_count());
+
+ for (int i = 0; i < threads.size(); i++) {
+ threads[i] = Thread::create(process_array_thread<ThreadArrayProcessData<C, U> >, &data);
+ }
+
+ for (int i = 0; i < threads.size(); i++) {
+ Thread::wait_to_finish(threads[i]);
+ memdelete(threads[i]);
+ }
+}
+
+#else
+
+template <class C, class M, class U>
+void thread_process_array(uint32_t p_elements, C *p_instance, M p_method, U p_userdata) {
+
+ ThreadArrayProcessData<C, U> data;
+ data.method = p_method;
+ data.instance = p_instance;
+ data.userdata = p_userdata;
+ data.index = 0;
+ data.elements = p_elements;
+ for (uint32_t i = 0; i < p_elements; i++) {
+ data.process(i);
+ }
+}
+
+#endif
+
+#endif // THREADED_ARRAY_PROCESSOR_H
diff --git a/core/script_language.cpp b/core/script_language.cpp
index c1e9d55872..2c32054e77 100644
--- a/core/script_language.cpp
+++ b/core/script_language.cpp
@@ -54,6 +54,8 @@ void Script::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_source_code"), &Script::get_source_code);
ClassDB::bind_method(D_METHOD("set_source_code", "source"), &Script::set_source_code);
ClassDB::bind_method(D_METHOD("reload", "keep_state"), &Script::reload, DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("get_base_script"), &Script::get_base_script);
+ ClassDB::bind_method(D_METHOD("get_instance_base_type"), &Script::get_instance_base_type);
ClassDB::bind_method(D_METHOD("has_script_signal", "signal_name"), &Script::has_script_signal);