diff options
author | ancarola <raffaele.ancarola@epfl.ch> | 2019-01-19 13:07:37 +0100 |
---|---|---|
committer | ancarola <raffaele.ancarola@epfl.ch> | 2019-01-19 13:07:37 +0100 |
commit | 3922c797671cdc23d9233ff76909489e45fd0006 (patch) | |
tree | d385754f00159b93a8966fb5080a51dc2d0eb4a0 /engine/flatland.cpp | |
parent | edas (diff) | |
download | flatland-3922c797671cdc23d9233ff76909489e45fd0006.tar.gz flatland-3922c797671cdc23d9233ff76909489e45fd0006.zip |
Test two completed successfully
Diffstat (limited to 'engine/flatland.cpp')
-rw-r--r-- | engine/flatland.cpp | 57 |
1 files changed, 50 insertions, 7 deletions
diff --git a/engine/flatland.cpp b/engine/flatland.cpp index d8c17f5..531d42c 100644 --- a/engine/flatland.cpp +++ b/engine/flatland.cpp @@ -10,6 +10,7 @@ using namespace std; #include "flattask.h" +#include "flatsignal.h" #include "flatwindow.h" float flatland_dt; @@ -17,6 +18,7 @@ float flatland_dt; set<FlatObject*> objects; FlatWindow * window = 0; +SignalChannel * core = 0; gameloop loop_function; @@ -53,17 +55,46 @@ Uint32 status_to_flags(const flat_status& s) return flags; } -int init_flatland(const FlatWindow& w, gameloop loop, const flat_status& s, float _fps) +/* Listen to simple quit calls */ +class QuitListener : public FlatListener { + virtual void callback(FlatObject*, void*) override + { + /* Order to quit */ + quit_flatland(); + } + +public: + + QuitListener() + { + addFilter("quit"); + core->connect(this); + } +}; + +int init_flatland(FlatWindow* w, gameloop loop, const flat_status& s, float _fps) +{ + cout << "Flatland: Initializing flatland" << endl; + + // Init core channel + + core = new SignalChannel("core"); + QuitListener quitter; + // init variables + + cout << "Flatland: Initializing window" << endl; - window = new FlatWindow(w); + window = w; loop_function = loop; status = s; fps = _fps; // init SDL + cout << "Flatland: Initializing SDL" << endl; + Uint32 flags = status_to_flags(s); if ( SDL_Init(flags | SDL_INIT_NOPARACHUTE) < 0) @@ -74,6 +105,7 @@ int init_flatland(const FlatWindow& w, gameloop loop, const flat_status& s, floa // init window + cout << "Flatland: Opening window" << endl; window->open(); /* Game loop */ @@ -83,6 +115,8 @@ int init_flatland(const FlatWindow& w, gameloop loop, const flat_status& s, floa clock_t delay = 0; + cout << "Flatland: Entering game-loop" << endl; + do { do { @@ -91,12 +125,12 @@ int init_flatland(const FlatWindow& w, gameloop loop, const flat_status& s, floa delay = clock(); - /* Execute tasks */ - task_s::executeAll(); - /* Execute loop function */ loop_function(flatland_dt); + /* Execute tasks */ + task_s::executeAll(); + SDL_Delay((Uint32) (1000.0f / fps)); delay -= clock(); @@ -107,8 +141,12 @@ int init_flatland(const FlatWindow& w, gameloop loop, const flat_status& s, floa } while(status.running); - delete window; - window = 0; + cout << "Flatland: destroying core channel" << endl; + + delete core; + core = 0; + + cout << "Flatland: quitting SDL" << endl; SDL_Quit(); @@ -126,3 +164,8 @@ flat_status flatland_status() return status; } +SignalChannel * getCoreChannel() +{ + return core; +} + |