From 844926711489c4f87c68ceab3ea245161228ad78 Mon Sep 17 00:00:00 2001 From: ancarola Date: Tue, 22 Jan 2019 01:56:51 +0100 Subject: Fin qui tutto bene --- engine/flatcomponent.cpp | 4 +- engine/flatland.cpp | 6 +- engine/flatsurface.cpp | 6 +- engine/flatwindow.cpp | 4 +- engine/include/flatbound.h | 4 +- engine/include/flatcollector.h | 4 +- engine/include/flatcomponent.h | 4 +- engine/include/flatevolvable.h | 4 +- engine/include/flatsurface.h | 4 +- engine/include/flatwindow.h | 4 +- engine/include/object.h | 42 ------------ engine/include/object.hpp | 42 ++++++++++++ engine/include/serial/focusable.h | 4 +- engine/include/signal.h | 138 -------------------------------------- engine/include/signal.hpp | 138 ++++++++++++++++++++++++++++++++++++++ engine/include/types.h | 37 ---------- engine/include/types.hpp | 37 ++++++++++ engine/object.cpp | 2 +- engine/signal.cpp | 2 +- 19 files changed, 243 insertions(+), 243 deletions(-) delete mode 100644 engine/include/object.h create mode 100644 engine/include/object.hpp delete mode 100644 engine/include/signal.h create mode 100644 engine/include/signal.hpp delete mode 100644 engine/include/types.h create mode 100644 engine/include/types.hpp (limited to 'engine') diff --git a/engine/flatcomponent.cpp b/engine/flatcomponent.cpp index 33cfbbc..06b558c 100644 --- a/engine/flatcomponent.cpp +++ b/engine/flatcomponent.cpp @@ -1,5 +1,5 @@ #include "flatcomponent.h" -#include "flatsignal.h" +#include "signal.h" Component::Component(Component *parent, const std::string& id) : parent(parent) @@ -7,7 +7,7 @@ Component::Component(Component *parent, const std::string& id) // TODO, check flatland initialization if (id.empty()) - setID(FlatObject::randomID()); + setID(flat::core::object::randomID()); if (parent == 0) { diff --git a/engine/flatland.cpp b/engine/flatland.cpp index 2f1c920..b53f8e4 100644 --- a/engine/flatland.cpp +++ b/engine/flatland.cpp @@ -10,14 +10,14 @@ using namespace std; #include "flattask.h" -#include "flatsignal.h" +#include "signal.h" #include "flatwindow.h" #include "flatexception.h" #include "exceptions/forcequit.h" float flatland_dt; -set objects; +set objects; FlatWindow * window = 0; SignalChannel * core = 0; @@ -60,7 +60,7 @@ Uint32 status_to_flags(const flat_status& s) /* Listen to simple quit calls */ class QuitListener : public FlatListener { - virtual void callback(FlatObject*, void*) override + virtual void callback(flat::core::object*, void*) override { /* Order to quit */ quit_flatland(); diff --git a/engine/flatsurface.cpp b/engine/flatsurface.cpp index 1970b71..7b1ee5a 100644 --- a/engine/flatsurface.cpp +++ b/engine/flatsurface.cpp @@ -6,7 +6,7 @@ using namespace std; FlatSurface::FlatSurface(const char *filename, Uint32 format, SDL_Surface *parent) - : FlatObject(), parent(parent), hide(false) + : flat::core::object(), parent(parent), hide(false) { setID(filename); @@ -35,7 +35,7 @@ FlatSurface::FlatSurface(const char *filename, Uint32 format, SDL_Surface *paren FlatSurface::FlatSurface(SDL_Surface *surface, SDL_Surface *parent) - : FlatObject(), parent(parent), hide(false) + : flat::core::object(), parent(parent), hide(false) { this->surface = new SDL_Surface(*surface); @@ -56,7 +56,7 @@ FlatSurface::FlatSurface(SDL_Surface *surface, SDL_Surface *parent) FlatSurface::FlatSurface(const FlatSurface &sprite) - : FlatObject(sprite), parent(sprite.parent), + : flat::core::object(sprite), parent(sprite.parent), hide(sprite.hide) { offset = new SDL_Rect(*sprite.offset); diff --git a/engine/flatwindow.cpp b/engine/flatwindow.cpp index ff17274..2ff99dc 100644 --- a/engine/flatwindow.cpp +++ b/engine/flatwindow.cpp @@ -3,7 +3,7 @@ #include #include #include "flatlayer.h" -#include "flatsignal.h" +#include "signal.h" using namespace std; @@ -47,7 +47,7 @@ FlatWindow::FlatWindow( int width, int height, FlatWindow::FlatWindow(const FlatWindow& win) - : FlatObject(win), + : flat::core::object(win), title(win.title), status(win.status), sdl_window(0), screen(0) { diff --git a/engine/include/flatbound.h b/engine/include/flatbound.h index a80cd6e..5028acc 100644 --- a/engine/include/flatbound.h +++ b/engine/include/flatbound.h @@ -1,12 +1,12 @@ #ifndef __FLATBOUND_H__ #define __FLATBOUND_H__ -#include "flatobject.h" +#include "object.h" #include "svector.h" typedef SVector pixel; -class FlatBound : virtual public FlatObject +class FlatBound : virtual public flat::core::object { pixel location; diff --git a/engine/include/flatcollector.h b/engine/include/flatcollector.h index ed9a824..cef49db 100644 --- a/engine/include/flatcollector.h +++ b/engine/include/flatcollector.h @@ -1,10 +1,10 @@ #ifndef __FLATCOLLECTOR_H__ #define __FLATCOLLECTOR_H__ -#include "flatobject.h" +#include "object.h" #include -class FlatCollector : virtual public FlatObject +class FlatCollector : virtual public flat::core::object { FlatCollector * parent; diff --git a/engine/include/flatcomponent.h b/engine/include/flatcomponent.h index 8a14d90..9e596bf 100644 --- a/engine/include/flatcomponent.h +++ b/engine/include/flatcomponent.h @@ -1,10 +1,10 @@ #ifndef __FLAT_COMPONENT_H__ #define __FLAT_COMPONENT_H__ -#include "flatobject.h" +#include "object.h" #include -class Component : virtual public FlatObject +class Component : virtual public flat::core::object { Component * parent; diff --git a/engine/include/flatevolvable.h b/engine/include/flatevolvable.h index 71aaf0f..a9cc102 100644 --- a/engine/include/flatevolvable.h +++ b/engine/include/flatevolvable.h @@ -1,11 +1,11 @@ #ifndef __FLATEVOLVABLE_H__ #define __FLATEVOLVABLE_H__ -#include "flatobject.h" +#include "object.h" class task_s; -class FlatEvolvable : virtual public FlatObject +class FlatEvolvable : virtual public flat::core::object { task_s * task; diff --git a/engine/include/flatsurface.h b/engine/include/flatsurface.h index bc04385..4c6ee1b 100644 --- a/engine/include/flatsurface.h +++ b/engine/include/flatsurface.h @@ -1,10 +1,10 @@ #ifndef __FLATSURFACE_H__ #define __FLATSURFACE_H__ -#include "flatobject.h" +#include "object.h" #include -class FlatSurface : public FlatObject +class FlatSurface : public flat::core::object { SDL_Surface * surface; SDL_Surface * parent; diff --git a/engine/include/flatwindow.h b/engine/include/flatwindow.h index 11d7134..b3734f4 100644 --- a/engine/include/flatwindow.h +++ b/engine/include/flatwindow.h @@ -26,7 +26,7 @@ struct window_status unsigned char focus:1; }; -#include "flatobject.h" +#include "object.h" #include "serial/keyfocusable.h" class SDL_Window; @@ -34,7 +34,7 @@ class FlatLayer; class SDL_KeyEvent; -class FlatWindow : virtual public FlatObject, public KeyFocusable +class FlatWindow : virtual public flat::core::object, public KeyFocusable { std::string title; window_status status; diff --git a/engine/include/object.h b/engine/include/object.h deleted file mode 100644 index cb7ef36..0000000 --- a/engine/include/object.h +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -#include "types.h" - -namespace flat -{ - namespace core - { - class object; - } -} - -class flat::core::object -{ - std::string id; - - /* Common list of objects */ - static std::list all_objects; - -public: - - object(); - ~object(); - - void set_id(const std::string&); - - const std::string& get_id() const; - - /* Static accessors to allObject */ - - static bool is_allocated(object*); - - static std::vector& get_by_id(const std::string& id, std::vector&); - - static std::string random_id(uint8_t length = 8); -}; - diff --git a/engine/include/object.hpp b/engine/include/object.hpp new file mode 100644 index 0000000..cb7ef36 --- /dev/null +++ b/engine/include/object.hpp @@ -0,0 +1,42 @@ +#pragma once + +#include +#include +#include +#include + +#include "types.h" + +namespace flat +{ + namespace core + { + class object; + } +} + +class flat::core::object +{ + std::string id; + + /* Common list of objects */ + static std::list all_objects; + +public: + + object(); + ~object(); + + void set_id(const std::string&); + + const std::string& get_id() const; + + /* Static accessors to allObject */ + + static bool is_allocated(object*); + + static std::vector& get_by_id(const std::string& id, std::vector&); + + static std::string random_id(uint8_t length = 8); +}; + diff --git a/engine/include/serial/focusable.h b/engine/include/serial/focusable.h index 6478ed4..a334e79 100644 --- a/engine/include/serial/focusable.h +++ b/engine/include/serial/focusable.h @@ -1,13 +1,13 @@ #ifndef __FOCUSABLE_H__ #define __FOCUSABLE_H__ -#include "flatobject.h" +#include "object.h" #include "types.h" class task_s; union SDL_Event; -class Focusable : virtual public FlatObject +class Focusable : virtual public flat::core::object { bool focused; diff --git a/engine/include/signal.h b/engine/include/signal.h deleted file mode 100644 index 0f16726..0000000 --- a/engine/include/signal.h +++ /dev/null @@ -1,138 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include "object.hpp" -#include "task.hpp" -#include "types.h" - -namespace flat -{ - namespace core - { - class signal; - class channel; - } -} - -class flat::core::signal : virtual public flat::core::object -{ - -public: - - flat::core::object * sender; - void * data; - priority prior; - - signal( flat::core::object * sender, - const std::string& id = "", - void *data = 0, - priority prior = 5); - - /* Alias to flat::core::channel::emit() */ - bool emit(const std::string& channel) const; - - enum class priority : uint8_t - { - instant = 0, - highest, - high, - none, - low, - lowest - }; -}; - - -/* Channel class */ -class flat::core::channel : virtual public flat::core::object -{ - /* Post processing signal stacking */ - stack_t stack; - - /* Listeners list */ - std::list listeners; - - /* Synchronous task checking for signals */ - task_s * checker; - - /* Channel mapping */ - static std::map channels; - -public: - - flat::core::channel(const std::string& id = "", flat::core::task::priority prior = flat::core::task::priority::none); - ~flat::core::channel(); - - void emit(const flat::core::signal&); - - void connect(flat::core::listener_s*); - void disconnect(flat::core::listener_s*); - - static flat::core::channel * find_channel(const std::string&); - - void post_processing(void*); - - /* Functor for order comparison */ - struct sig_prior_cmp { - - bool operator()(const flat::core::signal&, const flat::core::signal&) const; - }; - - typedef std::set stack_t; -}; - -/* Listener class */ -class flat::core::listener_s : virtual public flat::core::object -{ - std::list filters; - - bool check_in_filters(const std::string&) const; - -public: - - flat::core::listener(const std::initializer_list& filters = {}); - virtual ~flat::core::listener() {} - - virtual void execute(const flat::core::signal&) = 0; - - void add_filter(const std::string&); - void remove_filter(const std::string&); - - bool connect(const std::string&); - bool disconnect(const std::string&); -}; - -template -class flat::core::listener : public flat::core::listener_s -{ - typedef void (T::*callback_t)(void*); - - T * object; - callback_t callback; - - void *args; - -public: - - listener( T *object, - callback_t callback, - const std::initializer_list& filters = {}, - void *args = 0) - - : flat::core::listener_s(filters), - object(object), - callback(callback), - args(args) {} - - virtual void execute(const flat::core::signal&) override - { - if ((!sig.get_id().empty() && check_in_filters(sig.get_id())) || - (sig.get_id().empty() && filters.empty())) - (object->*callback)(sig.sender, sig.data); - } -}; - - diff --git a/engine/include/signal.hpp b/engine/include/signal.hpp new file mode 100644 index 0000000..24d240d --- /dev/null +++ b/engine/include/signal.hpp @@ -0,0 +1,138 @@ +#pragma once + +#include +#include +#include +#include +#include "object.hpp" +#include "task.hpp" +#include "types.hpp" + +namespace flat +{ + namespace core + { + class signal; + class channel; + } +} + +class flat::core::signal : virtual public flat::core::object +{ + +public: + + flat::core::object * sender; + void * data; + priority prior; + + signal( flat::core::object * sender, + const std::string& id = "", + void *data = 0, + priority prior = 5); + + /* Alias to flat::core::channel::emit() */ + bool emit(const std::string& channel) const; + + enum class priority : uint8_t + { + instant = 0, + highest, + high, + none, + low, + lowest + }; +}; + + +/* Channel class */ +class flat::core::channel : virtual public flat::core::object +{ + /* Post processing signal stacking */ + stack_t stack; + + /* Listeners list */ + std::list listeners; + + /* Synchronous task checking for signals */ + task_s * checker; + + /* Channel mapping */ + static std::map channels; + +public: + + flat::core::channel(const std::string& id = "", flat::core::task::priority prior = flat::core::task::priority::none); + ~flat::core::channel(); + + void emit(const flat::core::signal&); + + void connect(flat::core::listener_s*); + void disconnect(flat::core::listener_s*); + + static flat::core::channel * find_channel(const std::string&); + + void post_processing(void*); + + /* Functor for order comparison */ + struct sig_prior_cmp { + + bool operator()(const flat::core::signal&, const flat::core::signal&) const; + }; + + typedef std::set stack_t; +}; + +/* Listener class */ +class flat::core::listener_s : virtual public flat::core::object +{ + std::list filters; + + bool check_in_filters(const std::string&) const; + +public: + + flat::core::listener(const std::initializer_list& filters = {}); + virtual ~flat::core::listener() {} + + virtual void execute(const flat::core::signal&) = 0; + + void add_filter(const std::string&); + void remove_filter(const std::string&); + + bool connect(const std::string&); + bool disconnect(const std::string&); +}; + +template +class flat::core::listener : public flat::core::listener_s +{ + typedef void (T::*callback_t)(void*); + + T * object; + callback_t callback; + + void *args; + +public: + + listener( T *object, + callback_t callback, + const std::initializer_list& filters = {}, + void *args = 0) + + : flat::core::listener_s(filters), + object(object), + callback(callback), + args(args) {} + + virtual void execute(const flat::core::signal&) override + { + if ((!sig.get_id().empty() && check_in_filters(sig.get_id())) || + (sig.get_id().empty() && filters.empty())) + (object->*callback)(sig.sender, sig.data); + } +}; + + diff --git a/engine/include/types.h b/engine/include/types.h deleted file mode 100644 index 9482a46..0000000 --- a/engine/include/types.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef __TYPES_H__ -#define __TYPES_H__ - -/* Flatland types */ - -class FlatObject; - -class FlatActor; -class FlatSprite; - -class Focusable; - -class KeyFocusable; -class MouseFocusable; - -class FlatEvent; -class EventListener; -class Eventrigger; - -class FlatWindow; - -class FlatSpriter; -class FlatMultiSpriter; - -class task_s; - -/* SDL types */ - -typedef unsigned char uint8_t; -typedef unsigned int uint32_t; - -struct SDL_Surface; -struct SDL_Rect; - -union SDL_Event; - -#endif diff --git a/engine/include/types.hpp b/engine/include/types.hpp new file mode 100644 index 0000000..87c4d26 --- /dev/null +++ b/engine/include/types.hpp @@ -0,0 +1,37 @@ +#ifndef __TYPES_H__ +#define __TYPES_H__ + +/* Flatland types */ + +class flat::core::object; + +class FlatActor; +class FlatSprite; + +class Focusable; + +class KeyFocusable; +class MouseFocusable; + +class FlatEvent; +class EventListener; +class Eventrigger; + +class FlatWindow; + +class FlatSpriter; +class FlatMultiSpriter; + +class task_s; + +/* SDL types */ + +typedef unsigned char uint8_t; +typedef unsigned int uint32_t; + +struct SDL_Surface; +struct SDL_Rect; + +union SDL_Event; + +#endif diff --git a/engine/object.cpp b/engine/object.cpp index eb74e1a..abaf6cd 100644 --- a/engine/object.cpp +++ b/engine/object.cpp @@ -1,4 +1,4 @@ -#include "flatobject.h" +#include "object.h" #include diff --git a/engine/signal.cpp b/engine/signal.cpp index 0a3d887..d20d840 100644 --- a/engine/signal.cpp +++ b/engine/signal.cpp @@ -100,7 +100,7 @@ void channel::post_processing(void*) /* signal class */ -signal::signal(FlatObject *sender, const string& id, void *data, Uint8 priority) +signal::signal(flat::core::object *sender, const string& id, void *data, Uint8 priority) : sender(sender), data(data), priority(priority) { set_id(id); -- cgit v1.2.1