From fb0cdfe743869f6592090e441a071f0904a80634 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Thu, 2 Mar 2017 21:23:39 +0100 Subject: Optimize terminal usage The ^C-catching stuff will not work on windows; need to look into that --- main.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'main.cpp') diff --git a/main.cpp b/main.cpp index 3d4a048..d75c253 100644 --- a/main.cpp +++ b/main.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #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;idraw(); } + delete sb; } -- cgit v1.2.3-70-g09d2