summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorancarola <raffaele.ancarola@epfl.ch>2019-01-19 20:31:46 +0100
committerancarola <raffaele.ancarola@epfl.ch>2019-01-19 20:31:46 +0100
commitba86c8245484279ed7e78912b1ecd9ff4ac82e1e (patch)
tree7f3a04a92b862c4d145f2e79b87d524f98b54eed
parentTest two completed successfully (diff)
downloadflatland-ba86c8245484279ed7e78912b1ecd9ff4ac82e1e.tar.gz
flatland-ba86c8245484279ed7e78912b1ecd9ff4ac82e1e.zip
minor fixes
-rw-r--r--engine/.flatexception.cpp.swpbin0 -> 12288 bytes
-rw-r--r--engine/.flatland.cpp.swpbin0 -> 16384 bytes
-rw-r--r--engine/flatexception.cpp16
-rw-r--r--engine/flatland.cpp40
-rw-r--r--engine/include/.flatexception.h.swpbin0 -> 12288 bytes
-rw-r--r--engine/include/.flatwindow.h.swpbin0 -> 12288 bytes
-rw-r--r--engine/include/exceptions/forcequit.h11
-rw-r--r--engine/include/flatexception.h22
-rw-r--r--test/main.cpp3
-rwxr-xr-xtest/testbin14248 -> 14656 bytes
10 files changed, 87 insertions, 5 deletions
diff --git a/engine/.flatexception.cpp.swp b/engine/.flatexception.cpp.swp
new file mode 100644
index 0000000..7862392
--- /dev/null
+++ b/engine/.flatexception.cpp.swp
Binary files differ
diff --git a/engine/.flatland.cpp.swp b/engine/.flatland.cpp.swp
new file mode 100644
index 0000000..cad6ddc
--- /dev/null
+++ b/engine/.flatland.cpp.swp
Binary files differ
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
new file mode 100644
index 0000000..4189a06
--- /dev/null
+++ b/engine/include/.flatexception.h.swp
Binary files differ
diff --git a/engine/include/.flatwindow.h.swp b/engine/include/.flatwindow.h.swp
new file mode 100644
index 0000000..fd85b59
--- /dev/null
+++ b/engine/include/.flatwindow.h.swp
Binary files differ
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;
}
diff --git a/test/test b/test/test
index 337002c..0f34b3c 100755
--- a/test/test
+++ b/test/test
Binary files differ