survivor

graphical action game for the linux terminal
git clone https://git.ce9e.org/survivor.git

commit
d04291f51accf6743aaf2327ecbc6847cdefc89d
parent
e777a08ce40785e65efd487b5d367ad3a0dbcd10
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2023-03-30 03:42
refactor: handle signals before keys

Diffstat

M src/main.rs 44 ++++++++++++++++++++++----------------------

1 files changed, 22 insertions, 22 deletions


diff --git a/src/main.rs b/src/main.rs

@@ -77,27 +77,6 @@ fn main() {
   77    77     let mut time0 = time::Instant::now();
   78    78 
   79    79     while !NEED_QUIT.load(Ordering::Relaxed) {
   80    -1         let mut time1 = time::Instant::now();
   81    -1         let dt = (time1 - time0).as_secs_f32();
   82    -1 
   83    -1         while let Some(c) = input.getch() {
   84    -1             match c {
   85    -1                 b'w' | b'A' => game.player.dir = Some(game::Dir::Up),
   86    -1                 b'a' | b'D' => {
   87    -1                     game.player.dir = Some(game::Dir::Left);
   88    -1                     game.player.face = game::Dir::Left
   89    -1                 }
   90    -1                 b's' | b'B' => game.player.dir = Some(game::Dir::Down),
   91    -1                 b'd' | b'C' => {
   92    -1                     game.player.dir = Some(game::Dir::Right);
   93    -1                     game.player.face = game::Dir::Right
   94    -1                 }
   95    -1                 b' ' => game.player.dir = None,
   96    -1                 b'q' => NEED_QUIT.store(true, Ordering::Relaxed),
   97    -1                 _ => {}
   98    -1             }
   99    -1         }
  100    -1 
  101    80         if NEED_STOP.load(Ordering::Relaxed) {
  102    81             screen.restore();
  103    82             input.restore();
@@ -110,7 +89,7 @@ fn main() {
  110    89             screen.init();
  111    90             input.cbreak();
  112    91             signal(libc::SIGTSTP, handle_signal as libc::sighandler_t);
  113    -1             time1 = time::Instant::now();
   -1    92             time0 = time::Instant::now();
  114    93             NEED_STOP.store(false, Ordering::Relaxed);
  115    94         }
  116    95 
@@ -119,6 +98,27 @@ fn main() {
  119    98             NEED_RESIZE.store(false, Ordering::Relaxed);
  120    99         }
  121   100 
   -1   101         let time1 = time::Instant::now();
   -1   102         let dt = (time1 - time0).as_secs_f32();
   -1   103 
   -1   104         while let Some(c) = input.getch() {
   -1   105             match c {
   -1   106                 b'w' | b'A' => game.player.dir = Some(game::Dir::Up),
   -1   107                 b'a' | b'D' => {
   -1   108                     game.player.dir = Some(game::Dir::Left);
   -1   109                     game.player.face = game::Dir::Left
   -1   110                 }
   -1   111                 b's' | b'B' => game.player.dir = Some(game::Dir::Down),
   -1   112                 b'd' | b'C' => {
   -1   113                     game.player.dir = Some(game::Dir::Right);
   -1   114                     game.player.face = game::Dir::Right
   -1   115                 }
   -1   116                 b' ' => game.player.dir = None,
   -1   117                 b'q' => NEED_QUIT.store(true, Ordering::Relaxed),
   -1   118                 _ => {}
   -1   119             }
   -1   120         }
   -1   121 
  122   122         let mut win = win::Window {
  123   123             width: screen.width,
  124   124             height: screen.height - 6,