aboutsummaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/main.cpp b/main.cpp
index 3d4a048..d75c253 100644
--- a/main.cpp
+++ b/main.cpp
@@ -8,6 +8,7 @@
#include <tuple>
#include <cctype>
#include <cassert>
+#include <signal.h>
#include <sys/time.h>
#include "params.h"
#include "world.h"
@@ -210,6 +211,16 @@ string preprocess(istream &file){
}
+static ScreenBuffer *sb;
+
+static void signalHandler(int sig){
+ if(sig==SIGINT){
+ sb->emergencyDeinit();
+ _exit(130);
+ }
+}
+
+
int main(int argc,char **argv){
struct timeval tv;
gettimeofday(&tv,nullptr);
@@ -249,11 +260,14 @@ int main(int argc,char **argv){
}
}
- world.print();
+ sb=new ScreenBuffer(SIZE*3,SIZE);
+ signal(SIGINT,signalHandler);
+ world.print(*sb);
for(int i=0;i<C::autoTimeout;i++){
- world.tick();
usleep(3000);
- cout<<"\x1B[2J\x1B[H";
- world.print();
+ world.tick();
+ world.print(*sb);
+ sb->draw();
}
+ delete sb;
}