aboutsummaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-03-02 21:23:39 +0100
committertomsmeding <tom.smeding@gmail.com>2017-03-02 21:23:39 +0100
commitfb0cdfe743869f6592090e441a071f0904a80634 (patch)
tree60a6caee28ab702efb2a3e72b6cf5644ca1949c1 /main.cpp
parent39dbc1934d506f4b1da32621a8ff7e2e165a0bb0 (diff)
Optimize terminal usage
The ^C-catching stuff will not work on windows; need to look into that
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;
}