summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/math/a_star.cpp2
-rw-r--r--core/math/math_2d.h3
-rw-r--r--core/os/input_event.cpp18
-rw-r--r--core/os/input_event.h4
-rw-r--r--core/os/threaded_array_processor.cpp2
-rw-r--r--core/os/threaded_array_processor.h80
6 files changed, 85 insertions, 24 deletions
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp
index 4498efeb41..7c5dbc895a 100644
--- a/core/math/a_star.cpp
+++ b/core/math/a_star.cpp
@@ -459,7 +459,7 @@ void AStar::_bind_methods() {
ClassDB::bind_method(D_METHOD("has_point", "id"), &AStar::has_point);
ClassDB::bind_method(D_METHOD("get_points"), &AStar::get_points);
- ClassDB::bind_method(D_METHOD("get_point_connections"), &AStar::get_point_connections);
+ ClassDB::bind_method(D_METHOD("get_point_connections", "id"), &AStar::get_point_connections);
ClassDB::bind_method(D_METHOD("connect_points", "id", "to_id", "bidirectional"), &AStar::connect_points, DEFVAL(true));
ClassDB::bind_method(D_METHOD("disconnect_points", "id", "to_id"), &AStar::disconnect_points);
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/input_event.cpp b/core/os/input_event.cpp
index 9b2bd30868..0cab8c10ef 100644
--- a/core/os/input_event.cpp
+++ b/core/os/input_event.cpp
@@ -32,14 +32,6 @@
#include "input_map.h"
#include "os/keyboard.h"
-void InputEvent::set_id(uint32_t p_id) {
- id = p_id;
-}
-
-uint32_t InputEvent::get_id() const {
- return id;
-}
-
void InputEvent::set_device(int p_device) {
device = p_device;
}
@@ -99,9 +91,6 @@ bool InputEvent::is_action_type() const {
void InputEvent::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_id", "id"), &InputEvent::set_id);
- ClassDB::bind_method(D_METHOD("get_id"), &InputEvent::get_id);
-
ClassDB::bind_method(D_METHOD("set_device", "device"), &InputEvent::set_device);
ClassDB::bind_method(D_METHOD("get_device"), &InputEvent::get_device);
@@ -125,7 +114,6 @@ void InputEvent::_bind_methods() {
InputEvent::InputEvent() {
- id = 0;
device = 0;
}
@@ -441,7 +429,6 @@ Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, co
Ref<InputEventMouseButton> mb;
mb.instance();
- mb->set_id(get_id());
mb->set_device(get_device());
mb->set_modifiers_from_event(this);
@@ -557,7 +544,6 @@ Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, co
Ref<InputEventMouseMotion> mm;
mm.instance();
- mm->set_id(get_id());
mm->set_device(get_device());
mm->set_modifiers_from_event(this);
@@ -764,7 +750,6 @@ Ref<InputEvent> InputEventScreenTouch::xformed_by(const Transform2D &p_xform, co
Ref<InputEventScreenTouch> st;
st.instance();
- st->set_id(get_id());
st->set_device(get_device());
st->set_index(index);
st->set_position(p_xform.xform(pos + p_local_ofs));
@@ -845,7 +830,6 @@ Ref<InputEvent> InputEventScreenDrag::xformed_by(const Transform2D &p_xform, con
sd.instance();
- sd->set_id(get_id());
sd->set_device(get_device());
sd->set_index(index);
@@ -968,7 +952,6 @@ Ref<InputEvent> InputEventMagnifyGesture::xformed_by(const Transform2D &p_xform,
Ref<InputEventMagnifyGesture> ev;
ev.instance();
- ev->set_id(get_id());
ev->set_device(get_device());
ev->set_modifiers_from_event(this);
@@ -1006,7 +989,6 @@ Ref<InputEvent> InputEventPanGesture::xformed_by(const Transform2D &p_xform, con
Ref<InputEventPanGesture> ev;
ev.instance();
- ev->set_id(get_id());
ev->set_device(get_device());
ev->set_modifiers_from_event(this);
diff --git a/core/os/input_event.h b/core/os/input_event.h
index 614a3289ba..9b1a2736b1 100644
--- a/core/os/input_event.h
+++ b/core/os/input_event.h
@@ -144,16 +144,12 @@ enum JoystickList {
class InputEvent : public Resource {
GDCLASS(InputEvent, Resource)
- uint32_t id;
int device;
protected:
static void _bind_methods();
public:
- void set_id(uint32_t p_id);
- uint32_t get_id() const;
-
void set_device(int p_device);
int get_device() const;
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