Overview
SHA1 Hash: | 95915ac93f82adcb9d9201c084e7d6103fb360b9 |
---|---|
Date: | 2012-07-14 23:41:22 |
User: | kinaba |
Comment: | n*m limitter. |
Timelines: | family | ancestors | descendants | both | trunk |
Diffs: | redesign |
Downloads: | Tarball | ZIP archive |
Other Links: | files | file ages | manifest |
Tags And Properties
- branch=trunk inherited from [16f0b5784f]
- sym-trunk inherited from [16f0b5784f]
Changes
Modified src/output.d from [3f9e2911ee63dc4e] to [62e6040714438eff].
21 21 22 class GuardedOutput : GameObserver 22 class GuardedOutput : GameObserver 23 { 23 { 24 this(in Game g) 24 this(in Game g) 25 { 25 { 26 setup_sigint_handling(); 26 setup_sigint_handling(); 27 ideal_log ~= g.score_if_abort_now; 27 ideal_log ~= g.score_if_abort_now; > 28 flushed = false; 28 } 29 } 29 30 30 override void on_game_changed(char c, in Game g, bool finished) 31 override void on_game_changed(char c, in Game g, bool finished) 31 { 32 { > 33 if(flushed) > 34 return; > 35 32 log ~= c; 36 log ~= c; 33 score_log ~= g.score; 37 score_log ~= g.score; 34 ideal_log ~= g.score_if_abort_now; 38 ideal_log ~= g.score_if_abort_now; 35 if(finished) | 39 if(finished || log.length+1==g.map.W*g.map.H) 36 flush(); 40 flush(); 37 } 41 } 38 42 39 private: 43 private: 40 string log; 44 string log; 41 long[] score_log; 45 long[] score_log; 42 long[] ideal_log; 46 long[] ideal_log; > 47 bool flushed; 43 48 44 void flush() 49 void flush() 45 { 50 { 46 Tuple!(long, int, int) cand; 51 Tuple!(long, int, int) cand; 47 cand[0] = long.min; 52 cand[0] = long.min; 48 53 49 for(int i=0; i<score_log.length; ++i) 54 for(int i=0; i<score_log.length; ++i) ................................................................................................................................................................................ 57 string str = log[0..cand[1]+1]; 62 string str = log[0..cand[1]+1]; 58 std.c.stdio.printf("%.*s\n", str.length, str.ptr); 63 std.c.stdio.printf("%.*s\n", str.length, str.ptr); 59 } else { 64 } else { 60 string str = log[0..cand[1]]; 65 string str = log[0..cand[1]]; 61 std.c.stdio.printf("%.*sA\n", str.length, str.ptr); 66 std.c.stdio.printf("%.*sA\n", str.length, str.ptr); 62 } 67 } 63 std.c.stdio.fflush(std.c.stdio.stdout); 68 std.c.stdio.fflush(std.c.stdio.stdout); > 69 flushed = true; 64 } 70 } 65 71 66 private: 72 private: 67 static __gshared GuardedOutput g_output; 73 static __gshared GuardedOutput g_output; 68 74 69 void setup_sigint_handling() 75 void setup_sigint_handling() 70 { 76 { 71 assert(g_output is null); 77 assert(g_output is null); 72 g_output = this; 78 g_output = this; 73 extern(C) static void catch_sigint(int) { g_output.flush(); appl 79 extern(C) static void catch_sigint(int) { g_output.flush(); appl 74 core.stdc.signal.signal(SIGINT, &catch_sigint); 80 core.stdc.signal.signal(SIGINT, &catch_sigint); 75 } 81 } 76 } 82 }