mirror of
https://github.com/Relintai/sfw.git
synced 2025-03-11 23:39:09 +01:00
Fix connecting class methods to Signal.
This commit is contained in:
parent
703411a91e
commit
7cfe9a22ee
@ -10,9 +10,9 @@
|
|||||||
#include "render_core/app_window.h"
|
#include "render_core/app_window.h"
|
||||||
#include "render_core/keyboard.h"
|
#include "render_core/keyboard.h"
|
||||||
#include "render_core/mesh_utils.h"
|
#include "render_core/mesh_utils.h"
|
||||||
#include "render_immediate/renderer.h"
|
|
||||||
#include "render_gui/gui.h"
|
#include "render_gui/gui.h"
|
||||||
#include "render_gui/imgui.h"
|
#include "render_gui/imgui.h"
|
||||||
|
#include "render_immediate/renderer.h"
|
||||||
//#include "render_core/font.h"
|
//#include "render_core/font.h"
|
||||||
#include "core/sub_process.h"
|
#include "core/sub_process.h"
|
||||||
|
|
||||||
@ -88,6 +88,15 @@ void GameScene::input_event(const Ref<InputEvent> &event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (k->get_physical_scancode() == KEY_S) {
|
||||||
|
if (pressed) {
|
||||||
|
ERR_PRINT("Sending test signal");
|
||||||
|
test_signal.emit(this);
|
||||||
|
test_signal.emit(this, 12);
|
||||||
|
test_signal.emit(this, 33, "Test String");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -440,7 +449,6 @@ void GameScene::render_gui_manual(bool clear_screen) {
|
|||||||
|
|
||||||
GUI::new_frame();
|
GUI::new_frame();
|
||||||
|
|
||||||
|
|
||||||
ImGuiIO &io = ImGui::GetIO();
|
ImGuiIO &io = ImGui::GetIO();
|
||||||
(void)io;
|
(void)io;
|
||||||
|
|
||||||
@ -608,6 +616,21 @@ void GameScene::socket_thread_func(void *data) {
|
|||||||
self->_server_socket = NULL;
|
self->_server_socket = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameScene::signal_member(Signal *emitter) {
|
||||||
|
LOG_MSG("signal_member Params:");
|
||||||
|
for (int i = 0; i < emitter->params.size(); ++i) {
|
||||||
|
LOG_MSG(String(emitter->params[i]));
|
||||||
|
}
|
||||||
|
LOG_MSG("signal_member Params End.");
|
||||||
|
}
|
||||||
|
void GameScene::signal_static(Signal *emitter) {
|
||||||
|
LOG_MSG("signal_static Params:");
|
||||||
|
for (int i = 0; i < emitter->params.size(); ++i) {
|
||||||
|
LOG_MSG(String(emitter->params[i]));
|
||||||
|
}
|
||||||
|
LOG_MSG("signal_static Params End.");
|
||||||
|
}
|
||||||
|
|
||||||
GameScene::GameScene() {
|
GameScene::GameScene() {
|
||||||
render_type = 0;
|
render_type = 0;
|
||||||
|
|
||||||
@ -792,6 +815,9 @@ GameScene::GameScene() {
|
|||||||
|
|
||||||
_render_tex.instance();
|
_render_tex.instance();
|
||||||
_render_tex->set_frame_buffer(_frame_buffer);
|
_render_tex->set_frame_buffer(_frame_buffer);
|
||||||
|
|
||||||
|
test_signal.connect(this, &GameScene::signal_member);
|
||||||
|
test_signal.connect_static(&GameScene::signal_static);
|
||||||
}
|
}
|
||||||
|
|
||||||
GameScene::~GameScene() {
|
GameScene::~GameScene() {
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "render_core/color_material.h"
|
#include "render_core/color_material.h"
|
||||||
#include "render_core/colored_material.h"
|
#include "render_core/colored_material.h"
|
||||||
#include "render_core/font.h"
|
#include "render_core/font.h"
|
||||||
|
#include "render_core/frame_buffer.h"
|
||||||
#include "render_core/image.h"
|
#include "render_core/image.h"
|
||||||
#include "render_core/mesh.h"
|
#include "render_core/mesh.h"
|
||||||
#include "render_core/texture.h"
|
#include "render_core/texture.h"
|
||||||
@ -18,7 +19,8 @@
|
|||||||
#include "render_objects/sprite.h"
|
#include "render_objects/sprite.h"
|
||||||
#include "render_objects/text_2d.h"
|
#include "render_objects/text_2d.h"
|
||||||
#include "render_objects/tile_map.h"
|
#include "render_objects/tile_map.h"
|
||||||
#include "render_core/frame_buffer.h"
|
|
||||||
|
#include "object/psignal.h"
|
||||||
|
|
||||||
class Thread;
|
class Thread;
|
||||||
class Socket;
|
class Socket;
|
||||||
@ -46,6 +48,9 @@ public:
|
|||||||
void toggle_socket();
|
void toggle_socket();
|
||||||
static void socket_thread_func(void *d);
|
static void socket_thread_func(void *d);
|
||||||
|
|
||||||
|
void signal_member(Signal *emitter);
|
||||||
|
static void signal_static(Signal *emitter);
|
||||||
|
|
||||||
GameScene();
|
GameScene();
|
||||||
~GameScene();
|
~GameScene();
|
||||||
|
|
||||||
@ -92,6 +97,8 @@ public:
|
|||||||
Ref<FrameBuffer> _frame_buffer;
|
Ref<FrameBuffer> _frame_buffer;
|
||||||
Ref<RenderTexture> _render_tex;
|
Ref<RenderTexture> _render_tex;
|
||||||
|
|
||||||
|
Signal test_signal;
|
||||||
|
|
||||||
//ColoredMaterial *cmaterial;
|
//ColoredMaterial *cmaterial;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -4,11 +4,11 @@
|
|||||||
//--STRIP
|
//--STRIP
|
||||||
|
|
||||||
//--STRIP
|
//--STRIP
|
||||||
#include "core/vector.h"
|
|
||||||
#include "core/ustring.h"
|
#include "core/ustring.h"
|
||||||
|
#include "core/vector.h"
|
||||||
|
|
||||||
#include "object/variant.h"
|
|
||||||
#include "object/reference.h"
|
#include "object/reference.h"
|
||||||
|
#include "object/variant.h"
|
||||||
//--STRIP
|
//--STRIP
|
||||||
|
|
||||||
class Signal {
|
class Signal {
|
||||||
@ -18,11 +18,11 @@ public:
|
|||||||
Vector<Variant> static_data;
|
Vector<Variant> static_data;
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void connect(T *obj, void (*func)(T*, Signal *));
|
void connect(T *obj, void (T::*func)(Signal *));
|
||||||
template <class T>
|
template <class T>
|
||||||
void disconnect(T *obj, void (*func)(T*, Signal *));
|
void disconnect(T *obj, void (T::*func)(Signal *));
|
||||||
template <class T>
|
template <class T>
|
||||||
bool is_connected(T *obj, void (*func)(T*, Signal *));
|
bool is_connected(T *obj, void (T::*func)(Signal *));
|
||||||
|
|
||||||
void connect_static(void (*func)(Signal *));
|
void connect_static(void (*func)(Signal *));
|
||||||
void disconnect_static(void (*func)(Signal *));
|
void disconnect_static(void (*func)(Signal *));
|
||||||
@ -70,12 +70,11 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct ClassSignalEntry : public SignalEntry {
|
struct ClassSignalEntry : public SignalEntry {
|
||||||
|
virtual void *get_obj_ptr() {
|
||||||
virtual void* get_obj_ptr() {
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void* get_func_ptr() {
|
virtual void *get_func_ptr() {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,26 +83,26 @@ protected:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template <typename T>
|
||||||
struct ClassSignalEntrySpec : public ClassSignalEntry {
|
struct ClassSignalEntrySpec : public ClassSignalEntry {
|
||||||
union {
|
union {
|
||||||
T* obj;
|
T *obj;
|
||||||
void* obj_ptr;
|
void *obj_ptr;
|
||||||
};
|
};
|
||||||
union {
|
union {
|
||||||
void (*func)(T*, Signal *);
|
void (T::*func)(Signal *);
|
||||||
void* func_ptr;
|
void *func_ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual void call(Signal *s) {
|
virtual void call(Signal *s) {
|
||||||
func(obj, s);
|
(obj->*func)(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* get_obj_ptr() {
|
void *get_obj_ptr() {
|
||||||
return obj_ptr;
|
return obj_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* get_func_ptr() {
|
void *get_func_ptr() {
|
||||||
return func_ptr;
|
return func_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +117,7 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void Signal::connect(T *obj, void (*func)(T*, Signal *)) {
|
void Signal::connect(T *obj, void (T::*func)(Signal *)) {
|
||||||
ClassSignalEntrySpec<T> *ce = memnew(ClassSignalEntrySpec<T>());
|
ClassSignalEntrySpec<T> *ce = memnew(ClassSignalEntrySpec<T>());
|
||||||
ce->obj = obj;
|
ce->obj = obj;
|
||||||
ce->func = func;
|
ce->func = func;
|
||||||
@ -127,13 +126,13 @@ void Signal::connect(T *obj, void (*func)(T*, Signal *)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void Signal::disconnect(T *obj, void (*func)(T*, Signal *)) {
|
void Signal::disconnect(T *obj, void (T::*func)(Signal *)) {
|
||||||
ClassSignalEntrySpec<T> t;
|
ClassSignalEntrySpec<T> t;
|
||||||
t.obj = obj;
|
t.obj = obj;
|
||||||
t.func = func;
|
t.func = func;
|
||||||
|
|
||||||
void* obj_ptr = t.obj_ptr;
|
void *obj_ptr = t.obj_ptr;
|
||||||
void* func_ptr = t.func_ptr;
|
void *func_ptr = t.func_ptr;
|
||||||
|
|
||||||
for (int i = 0; i < entries.size(); ++i) {
|
for (int i = 0; i < entries.size(); ++i) {
|
||||||
SignalEntry *e = entries[i];
|
SignalEntry *e = entries[i];
|
||||||
@ -150,13 +149,13 @@ void Signal::disconnect(T *obj, void (*func)(T*, Signal *)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool Signal::is_connected(T *obj, void (*func)(T*, Signal *)) {
|
bool Signal::is_connected(T *obj, void (T::*func)(Signal *)) {
|
||||||
ClassSignalEntrySpec<T> t;
|
ClassSignalEntrySpec<T> t;
|
||||||
t.obj = obj;
|
t.obj = obj;
|
||||||
t.func = func;
|
t.func = func;
|
||||||
|
|
||||||
void* obj_ptr = t.obj_ptr;
|
void *obj_ptr = t.obj_ptr;
|
||||||
void* func_ptr = t.func_ptr;
|
void *func_ptr = t.func_ptr;
|
||||||
|
|
||||||
for (int i = 0; i < entries.size(); ++i) {
|
for (int i = 0; i < entries.size(); ++i) {
|
||||||
SignalEntry *e = entries[i];
|
SignalEntry *e = entries[i];
|
||||||
|
@ -4,11 +4,11 @@
|
|||||||
//--STRIP
|
//--STRIP
|
||||||
|
|
||||||
//--STRIP
|
//--STRIP
|
||||||
#include "core/vector.h"
|
|
||||||
#include "core/ustring.h"
|
#include "core/ustring.h"
|
||||||
|
#include "core/vector.h"
|
||||||
|
|
||||||
#include "object/variant.h"
|
|
||||||
#include "object/reference.h"
|
#include "object/reference.h"
|
||||||
|
#include "object/variant.h"
|
||||||
//--STRIP
|
//--STRIP
|
||||||
|
|
||||||
class Signal {
|
class Signal {
|
||||||
@ -18,11 +18,11 @@ public:
|
|||||||
Vector<Variant> static_data;
|
Vector<Variant> static_data;
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void connect(T *obj, void (*func)(T*, Signal *));
|
void connect(T *obj, void (T::*func)(Signal *));
|
||||||
template <class T>
|
template <class T>
|
||||||
void disconnect(T *obj, void (*func)(T*, Signal *));
|
void disconnect(T *obj, void (T::*func)(Signal *));
|
||||||
template <class T>
|
template <class T>
|
||||||
bool is_connected(T *obj, void (*func)(T*, Signal *));
|
bool is_connected(T *obj, void (T::*func)(Signal *));
|
||||||
|
|
||||||
void connect_static(void (*func)(Signal *));
|
void connect_static(void (*func)(Signal *));
|
||||||
void disconnect_static(void (*func)(Signal *));
|
void disconnect_static(void (*func)(Signal *));
|
||||||
@ -70,12 +70,11 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct ClassSignalEntry : public SignalEntry {
|
struct ClassSignalEntry : public SignalEntry {
|
||||||
|
virtual void *get_obj_ptr() {
|
||||||
virtual void* get_obj_ptr() {
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void* get_func_ptr() {
|
virtual void *get_func_ptr() {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,26 +83,26 @@ protected:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template <typename T>
|
||||||
struct ClassSignalEntrySpec : public ClassSignalEntry {
|
struct ClassSignalEntrySpec : public ClassSignalEntry {
|
||||||
union {
|
union {
|
||||||
T* obj;
|
T *obj;
|
||||||
void* obj_ptr;
|
void *obj_ptr;
|
||||||
};
|
};
|
||||||
union {
|
union {
|
||||||
void (*func)(T*, Signal *);
|
void (T::*func)(Signal *);
|
||||||
void* func_ptr;
|
void *func_ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual void call(Signal *s) {
|
virtual void call(Signal *s) {
|
||||||
func(obj, s);
|
(obj->*func)(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* get_obj_ptr() {
|
void *get_obj_ptr() {
|
||||||
return obj_ptr;
|
return obj_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* get_func_ptr() {
|
void *get_func_ptr() {
|
||||||
return func_ptr;
|
return func_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +117,7 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void Signal::connect(T *obj, void (*func)(T*, Signal *)) {
|
void Signal::connect(T *obj, void (T::*func)(Signal *)) {
|
||||||
ClassSignalEntrySpec<T> *ce = memnew(ClassSignalEntrySpec<T>());
|
ClassSignalEntrySpec<T> *ce = memnew(ClassSignalEntrySpec<T>());
|
||||||
ce->obj = obj;
|
ce->obj = obj;
|
||||||
ce->func = func;
|
ce->func = func;
|
||||||
@ -127,13 +126,13 @@ void Signal::connect(T *obj, void (*func)(T*, Signal *)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void Signal::disconnect(T *obj, void (*func)(T*, Signal *)) {
|
void Signal::disconnect(T *obj, void (T::*func)(Signal *)) {
|
||||||
ClassSignalEntrySpec<T> t;
|
ClassSignalEntrySpec<T> t;
|
||||||
t.obj = obj;
|
t.obj = obj;
|
||||||
t.func = func;
|
t.func = func;
|
||||||
|
|
||||||
void* obj_ptr = t.obj_ptr;
|
void *obj_ptr = t.obj_ptr;
|
||||||
void* func_ptr = t.func_ptr;
|
void *func_ptr = t.func_ptr;
|
||||||
|
|
||||||
for (int i = 0; i < entries.size(); ++i) {
|
for (int i = 0; i < entries.size(); ++i) {
|
||||||
SignalEntry *e = entries[i];
|
SignalEntry *e = entries[i];
|
||||||
@ -150,13 +149,13 @@ void Signal::disconnect(T *obj, void (*func)(T*, Signal *)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool Signal::is_connected(T *obj, void (*func)(T*, Signal *)) {
|
bool Signal::is_connected(T *obj, void (T::*func)(Signal *)) {
|
||||||
ClassSignalEntrySpec<T> t;
|
ClassSignalEntrySpec<T> t;
|
||||||
t.obj = obj;
|
t.obj = obj;
|
||||||
t.func = func;
|
t.func = func;
|
||||||
|
|
||||||
void* obj_ptr = t.obj_ptr;
|
void *obj_ptr = t.obj_ptr;
|
||||||
void* func_ptr = t.func_ptr;
|
void *func_ptr = t.func_ptr;
|
||||||
|
|
||||||
for (int i = 0; i < entries.size(); ++i) {
|
for (int i = 0; i < entries.size(); ++i) {
|
||||||
SignalEntry *e = entries[i];
|
SignalEntry *e = entries[i];
|
||||||
|
Loading…
Reference in New Issue
Block a user