diff options
author | ancarola <raffaele.ancarola@epfl.ch> | 2019-01-19 20:31:46 +0100 |
---|---|---|
committer | ancarola <raffaele.ancarola@epfl.ch> | 2019-01-19 20:31:46 +0100 |
commit | ba86c8245484279ed7e78912b1ecd9ff4ac82e1e (patch) | |
tree | 7f3a04a92b862c4d145f2e79b87d524f98b54eed | |
parent | Test two completed successfully (diff) | |
download | flatland-ba86c8245484279ed7e78912b1ecd9ff4ac82e1e.tar.gz flatland-ba86c8245484279ed7e78912b1ecd9ff4ac82e1e.zip |
minor fixes
-rw-r--r-- | engine/.flatexception.cpp.swp | bin | 0 -> 12288 bytes | |||
-rw-r--r-- | engine/.flatland.cpp.swp | bin | 0 -> 16384 bytes | |||
-rw-r--r-- | engine/flatexception.cpp | 16 | ||||
-rw-r--r-- | engine/flatland.cpp | 40 | ||||
-rw-r--r-- | engine/include/.flatexception.h.swp | bin | 0 -> 12288 bytes | |||
-rw-r--r-- | engine/include/.flatwindow.h.swp | bin | 0 -> 12288 bytes | |||
-rw-r--r-- | engine/include/exceptions/forcequit.h | 11 | ||||
-rw-r--r-- | engine/include/flatexception.h | 22 | ||||
-rw-r--r-- | test/main.cpp | 3 | ||||
-rwxr-xr-x | test/test | bin | 14248 -> 14656 bytes |
10 files changed, 87 insertions, 5 deletions
diff --git a/engine/.flatexception.cpp.swp b/engine/.flatexception.cpp.swp Binary files differnew file mode 100644 index 0000000..7862392 --- /dev/null +++ b/engine/.flatexception.cpp.swp diff --git a/engine/.flatland.cpp.swp b/engine/.flatland.cpp.swp Binary files differnew file mode 100644 index 0000000..cad6ddc --- /dev/null +++ b/engine/.flatland.cpp.swp diff --git a/engine/flatexception.cpp b/engine/flatexception.cpp new file mode 100644 index 0000000..0216dd5 --- /dev/null +++ b/engine/flatexception.cpp @@ -0,0 +1,16 @@ +#include "flatexception.h" +#include <stdio.h> + +FlatException::FlatException(const char* error) : error(error) {} + +FlatException::~FlatException() {} + +char buffer[256]; + +const char* FlatException::what() const throw() +{ + sprintf(buffer, "%s thrown: %s", specific(), error); + + return &buffer[0]; +} + diff --git a/engine/flatland.cpp b/engine/flatland.cpp index 531d42c..cbb9842 100644 --- a/engine/flatland.cpp +++ b/engine/flatland.cpp @@ -12,6 +12,8 @@ using namespace std; #include "flattask.h" #include "flatsignal.h" #include "flatwindow.h" +#include "flatexception.h" +#include "exceptions/forcequit.h" float flatland_dt; @@ -125,11 +127,37 @@ int init_flatland(FlatWindow* w, gameloop loop, const flat_status& s, float _fps delay = clock(); - /* Execute loop function */ - loop_function(flatland_dt); + try { - /* Execute tasks */ - task_s::executeAll(); + try { + + /* Execute loop function */ + loop_function(flatland_dt); + + } catch (const exception &e) { + + cerr << "Flatland: exception thrown while executing loop" << endl; + cerr << e.what() << endl; + } + + try { + + /* Execute tasks */ + task_s::executeAll(); + + } catch (const exception &e) { + + cerr << "Flatland: exception thrown while executing tasks" << endl; + cerr << e.what() << endl; + } + + } catch (const ForceQuit& f) { + + cerr << "Flatland: a force quit call was thrown" << endl; + cerr << "Possible reason: " << f.reason << endl; + + quit_flatland(); + } SDL_Delay((Uint32) (1000.0f / fps)); @@ -141,6 +169,10 @@ int init_flatland(FlatWindow* w, gameloop loop, const flat_status& s, float _fps } while(status.running); + cout << "Flatland: closing window" << endl; + + window->close(); + cout << "Flatland: destroying core channel" << endl; delete core; diff --git a/engine/include/.flatexception.h.swp b/engine/include/.flatexception.h.swp Binary files differnew file mode 100644 index 0000000..4189a06 --- /dev/null +++ b/engine/include/.flatexception.h.swp diff --git a/engine/include/.flatwindow.h.swp b/engine/include/.flatwindow.h.swp Binary files differnew file mode 100644 index 0000000..fd85b59 --- /dev/null +++ b/engine/include/.flatwindow.h.swp diff --git a/engine/include/exceptions/forcequit.h b/engine/include/exceptions/forcequit.h new file mode 100644 index 0000000..7b2b324 --- /dev/null +++ b/engine/include/exceptions/forcequit.h @@ -0,0 +1,11 @@ +#ifndef __FORCE_QUIT_H__ +#define __FORCE_QUIT_H__ + +struct ForceQuit +{ + const char * reason; + + ForceQuit(const char *reason) : reason(reason) {} +}; + +#endif diff --git a/engine/include/flatexception.h b/engine/include/flatexception.h new file mode 100644 index 0000000..47eb272 --- /dev/null +++ b/engine/include/flatexception.h @@ -0,0 +1,22 @@ +#ifndef __FLAT_ERROR_H__ +#define __FLAT_ERROR_H__ + +#include <exception> + +class FlatException : public std::exception +{ + const char * error; + +protected: + + virtual const char * specific() const = 0; + +public: + + FlatException(const char* error); + virtual ~FlatException(); + + virtual const char* what() const throw() override; +}; + +#endif diff --git a/test/main.cpp b/test/main.cpp index 5a441a7..2b16838 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -1,5 +1,6 @@ #include "flatland.h" #include "flatwindow.h" +#include "exceptions/forcequit.h" int count = 0; @@ -24,7 +25,7 @@ void loop(float dt) ++count; if (count == 1000) - quit_flatland(); + throw ForceQuit("1000 steps reached"); cout << "Loop number: " << count << endl; } Binary files differ |