diff options
author | ancarola <raffaele.ancarola@epfl.ch> | 2019-01-25 23:47:41 +0100 |
---|---|---|
committer | ancarola <raffaele.ancarola@epfl.ch> | 2019-01-25 23:47:41 +0100 |
commit | 351f83b6d331eef1fb5e1cbfa8bed25da8f96a57 (patch) | |
tree | 2a7ac7dc499f5b764caba981002e7a17bc1687d0 | |
parent | Core channel in flatland and signal test (diff) | |
download | flatland-351f83b6d331eef1fb5e1cbfa8bed25da8f96a57.tar.gz flatland-351f83b6d331eef1fb5e1cbfa8bed25da8f96a57.zip |
Template error on compile signal test
-rw-r--r-- | engine/flatland.cpp | 18 | ||||
-rw-r--r-- | engine/include/bound.hpp | 2 | ||||
-rw-r--r-- | engine/include/collector.hpp | 4 | ||||
-rw-r--r-- | engine/include/component.hpp | 4 | ||||
-rw-r--r-- | engine/include/core/signal.hpp | 7 | ||||
-rw-r--r-- | engine/include/flatland.hpp | 2 | ||||
-rw-r--r-- | engine/include/serial/focusable.hpp | 4 | ||||
-rw-r--r-- | engine/include/surface.hpp | 4 | ||||
-rw-r--r-- | engine/include/types.hpp | 5 | ||||
-rw-r--r-- | engine/include/window.hpp | 4 | ||||
-rw-r--r-- | engine/surface.cpp | 4 | ||||
-rw-r--r-- | engine/window.cpp | 2 | ||||
-rw-r--r-- | test/signal_test.cpp | 35 |
13 files changed, 47 insertions, 48 deletions
diff --git a/engine/flatland.cpp b/engine/flatland.cpp index fdfa6fc..62cdfd1 100644 --- a/engine/flatland.cpp +++ b/engine/flatland.cpp @@ -37,13 +37,13 @@ core::listener::ptr print_listener; /* channels listeners callback */ -void quit_callback(object *sender, signal::package) +void quit_callback(const object *sender, core::signal::package) { cout << "Flatland: quit request attempted" << endl; flat::quit(); } -void print_callback(object *sender, signal::package p) +void print_callback(const object *sender, core::signal::package p) { const char * out = p.get<const char>(); string * sout = p.get<string>(); @@ -88,19 +88,19 @@ uint32_t status_to_flags(const flat_status& s) /* Accessors */ -channel& core_channel() +core::channel& core_channel() { return core_chan; } -job& main_job() +core::job& main_job() { return mainsync_job; } /* Main loop */ -int init_flatland(FlatWindow* w, gameloop loop, const flat_status& s, float _fps) +int init_flatland(FlatWindow* w, const flat_status& s, float _fps) { cout << "Flatland: Initializing flatland" << endl; @@ -108,7 +108,7 @@ int init_flatland(FlatWindow* w, gameloop loop, const flat_status& s, float _fps cout << "Flatland: Initializing core channel" << endl; - core_chan.start(priority_t::max); + core_chan.start(core::priority_t::max); if (!core_chan.map()) { @@ -120,7 +120,7 @@ int init_flatland(FlatWindow* w, gameloop loop, const flat_status& s, float _fps // bind listeners - quit_listener = core_chan.connect(&quit_callback, {"quit"}); + quit_listener = core_chan.connect(quit_callback, initializer_list<string>({string("quit")})); // control if quit was not already connected if (!quit_listener) { @@ -131,7 +131,7 @@ int init_flatland(FlatWindow* w, gameloop loop, const flat_status& s, float _fps return -1; } - print_listener = core_chan.connect(&print_callback, {"print"}); + print_listener = core_chan.connect(print_callback, initializer_list<string>({string("print")})); // control if print was not already connected if (!print_listener) { @@ -194,7 +194,7 @@ int init_flatland(FlatWindow* w, gameloop loop, const flat_status& s, float _fps cerr << "Flatland: a force quit call was thrown" << endl; cerr << "Possible reason: " << f.reason << endl; - quit_flatland(); + quit(); } SDL_Delay((uint32_t) (1000.0f / fps)); diff --git a/engine/include/bound.hpp b/engine/include/bound.hpp index 9b7b755..a924e90 100644 --- a/engine/include/bound.hpp +++ b/engine/include/bound.hpp @@ -8,7 +8,7 @@ namespace flat { typedef SVector<int, 2> pixel; -class FlatBound : virtual public flat::core::object +class FlatBound : virtual public flat::object { pixel location; diff --git a/engine/include/collector.hpp b/engine/include/collector.hpp index bc50f4d..45a3e74 100644 --- a/engine/include/collector.hpp +++ b/engine/include/collector.hpp @@ -1,12 +1,12 @@ #ifndef __FLATCOLLECTOR_H__ #define __FLATCOLLECTOR_H__ -#include "core/object.hpp" +#include "object.hpp" #include <set> namespace flat { -class FlatCollector : virtual public flat::core::object +class FlatCollector : virtual public flat::object { FlatCollector * parent; diff --git a/engine/include/component.hpp b/engine/include/component.hpp index 4ad99c8..fdde28d 100644 --- a/engine/include/component.hpp +++ b/engine/include/component.hpp @@ -1,13 +1,13 @@ #ifndef __FLAT_COMPONENT_H__ #define __FLAT_COMPONENT_H__ -#include "core/object.hpp" +#include "object.hpp" #include "core/labelled.hpp" #include <string> namespace flat { -class component : virtual public core::object, virtual public core::labelled +class component : virtual public object, virtual public core::labelled { component * m_parent; diff --git a/engine/include/core/signal.hpp b/engine/include/core/signal.hpp index 7d91150..a420989 100644 --- a/engine/include/core/signal.hpp +++ b/engine/include/core/signal.hpp @@ -6,6 +6,7 @@ #include <initializer_list> #include "task.hpp" #include "types.hpp" +#include "object.hpp" #include <functional> #include <memory> #include "priority.hpp" @@ -13,7 +14,7 @@ namespace flat { - class object; + //class object; namespace core { @@ -30,7 +31,7 @@ namespace flat template<class T> T * get() { - return dynamic_cast<T>(data); + return reinterpret_cast<T*>(data); } void * data; @@ -123,7 +124,7 @@ namespace flat template<typename R, typename T> inline listener::ptr connect(R T::*mf, T& obj, const std::initializer_list<std::string>& filters = {}) { - return connect(std::bind(mf, obj)); + return connect(std::bind(mf, obj), filters); } static ptr find(const std::string&); diff --git a/engine/include/flatland.hpp b/engine/include/flatland.hpp index c0216d8..0ccf59c 100644 --- a/engine/include/flatland.hpp +++ b/engine/include/flatland.hpp @@ -36,7 +36,7 @@ struct flat_status }; int init_flatland(FlatWindow*, const flat_status&, float fps = 60); -void quit_flatland(); +void quit(); namespace core { diff --git a/engine/include/serial/focusable.hpp b/engine/include/serial/focusable.hpp index f139577..8a05051 100644 --- a/engine/include/serial/focusable.hpp +++ b/engine/include/serial/focusable.hpp @@ -1,14 +1,14 @@ #ifndef __FOCUSABLE_H__ #define __FOCUSABLE_H__ -#include "core/object.hpp" +#include "object.hpp" #include "types.hpp" union SDL_Event; namespace flat { -class Focusable : virtual public flat::core::object +class Focusable : virtual public flat::object { bool focused; diff --git a/engine/include/surface.hpp b/engine/include/surface.hpp index 5364e8e..6e9026a 100644 --- a/engine/include/surface.hpp +++ b/engine/include/surface.hpp @@ -1,13 +1,13 @@ #ifndef __FLATSURFACE_H__ #define __FLATSURFACE_H__ -#include "core/object.hpp" +#include "object.hpp" #include "core/labelled.hpp" #include <SDL2/SDL.h> namespace flat { -class surface : virtual public core::object, virtual public core::labelled +class surface : virtual public object, virtual public core::labelled { SDL_Surface * sdl_surface; SDL_Surface * parent; diff --git a/engine/include/types.hpp b/engine/include/types.hpp index e7a1d3a..31596c9 100644 --- a/engine/include/types.hpp +++ b/engine/include/types.hpp @@ -5,10 +5,7 @@ namespace flat { - namespace core - { - class object; - } + class object; class FlatActor; class FlatSprite; diff --git a/engine/include/window.hpp b/engine/include/window.hpp index 98e8e04..48e8cb0 100644 --- a/engine/include/window.hpp +++ b/engine/include/window.hpp @@ -1,7 +1,7 @@ #ifndef __FLATWINDOW_H__ #define __FLATWINDOW_H__ -#include "core/object.hpp" +#include "object.hpp" #include "serial/keyfocusable.hpp" #include <string> @@ -37,7 +37,7 @@ struct window_status class FlatLayer; -class FlatWindow : virtual public core::object, public KeyFocusable +class FlatWindow : virtual public object, public KeyFocusable { std::string title; window_status status; diff --git a/engine/surface.cpp b/engine/surface.cpp index 31f6388..f4729a5 100644 --- a/engine/surface.cpp +++ b/engine/surface.cpp @@ -34,7 +34,7 @@ surface::surface(const char *filename, uint32_t format, SDL_Surface *parent) surface::surface(SDL_Surface *sdl_surface, SDL_Surface *parent) - : flat::core::object(), parent(parent), hide(false) + : flat::object(), parent(parent), hide(false) { this->sdl_surface = new SDL_Surface(*sdl_surface); @@ -55,7 +55,7 @@ surface::surface(SDL_Surface *sdl_surface, SDL_Surface *parent) surface::surface(const surface &sprite) - : flat::core::object(sprite), parent(sprite.parent), + : flat::object(sprite), parent(sprite.parent), hide(sprite.hide) { offset = new SDL_Rect(*sprite.offset); diff --git a/engine/window.cpp b/engine/window.cpp index 4f22310..20da675 100644 --- a/engine/window.cpp +++ b/engine/window.cpp @@ -46,7 +46,7 @@ FlatWindow::FlatWindow( int width, int height, FlatWindow::FlatWindow(const FlatWindow& win) - : flat::core::object(win), + : flat::object(win), title(win.title), status(win.status), sdl_window(0), screen(0) { diff --git a/test/signal_test.cpp b/test/signal_test.cpp index 2e17747..39d7e0f 100644 --- a/test/signal_test.cpp +++ b/test/signal_test.cpp @@ -1,10 +1,11 @@ #include "core/signal.hpp" #include "core/task.hpp" -#include "object.h" +#include "object.hpp" #include "flatland.hpp" #include <iostream> using namespace std; +using namespace flat; using namespace flat::core; @@ -26,24 +27,24 @@ public: } }; -void function_listener(const object*, signal::package msg) +void function_listener(const object*, core::signal::package msg) { cout << "Funzione: " << msg.get<const char>() << endl; -}; +} -class class_listener +class c_listener { listener::ptr lis; public: - class_listener(channel::ptr chan) + c_listener(channel::ptr chan) { - lis = chan->connect(&class_listener::listen, *this); + lis = chan->connect(&c_listener::method_listener, *this); } - void listen(const object*, signal::package) + void method_listener(const object *o, signal::package msg) { cout << "Metodo" << msg.get<const char>() << endl; } @@ -53,20 +54,20 @@ public: channel::ptr alpha; sender * m_sender; -class_listener * m_listener; +c_listener * m_listener; listener::ptr f_listener; -int count = 0; +int steps = 0; void lifeloop() { - if (!(count % 10)) - cout << "Step: " << count << endl; + if (!(steps % 10)) + cout << "Step: " << steps << endl; - if (!(count % 40)) - m_sender.send(); + if (!(steps % 40)) + m_sender->send(); - if (++count > 2000) + if (++steps > 2000) { signal quit(0, "quit"); @@ -84,13 +85,13 @@ int main() // create sender m_sender = new sender("Ciao", alpha); - m_listener = new class_listener(alpha); + m_listener = new c_listener(alpha); // Connect listener to alpha channel - f_listener = alpha.connect(&function_listener); + f_listener = alpha->connect(&function_listener); // bind counter task - task::ptr looptask = flat::main_job().delegate_task(&lifeloop); + task::ptr looptask = flat::main_job().delegate_task(lifeloop); init_flatland(&win, status, 60); |