Diff
Not logged in

Differences From Artifact [3f9e2911ee63dc4e]:

To Artifact [62e6040714438eff]:


21 21 22 22 class GuardedOutput : GameObserver 23 23 { 24 24 this(in Game g) 25 25 { 26 26 setup_sigint_handling(); 27 27 ideal_log ~= g.score_if_abort_now; 28 + flushed = false; 28 29 } 29 30 30 31 override void on_game_changed(char c, in Game g, bool finished) 31 32 { 33 + if(flushed) 34 + return; 35 + 32 36 log ~= c; 33 37 score_log ~= g.score; 34 38 ideal_log ~= g.score_if_abort_now; 35 - if(finished) 39 + if(finished || log.length+1==g.map.W*g.map.H) 36 40 flush(); 37 41 } 38 42 39 43 private: 40 44 string log; 41 45 long[] score_log; 42 46 long[] ideal_log; 47 + bool flushed; 43 48 44 49 void flush() 45 50 { 46 51 Tuple!(long, int, int) cand; 47 52 cand[0] = long.min; 48 53 49 54 for(int i=0; i<score_log.length; ++i) ................................................................................ 57 62 string str = log[0..cand[1]+1]; 58 63 std.c.stdio.printf("%.*s\n", str.length, str.ptr); 59 64 } else { 60 65 string str = log[0..cand[1]]; 61 66 std.c.stdio.printf("%.*sA\n", str.length, str.ptr); 62 67 } 63 68 std.c.stdio.fflush(std.c.stdio.stdout); 69 + flushed = true; 64 70 } 65 71 66 72 private: 67 73 static __gshared GuardedOutput g_output; 68 74 69 75 void setup_sigint_handling() 70 76 { 71 77 assert(g_output is null); 72 78 g_output = this; 73 79 extern(C) static void catch_sigint(int) { g_output.flush(); application_exit(); } 74 80 core.stdc.signal.signal(SIGINT, &catch_sigint); 75 81 } 76 82 }