survivor

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

commit
a6c1ad4cf39e340db13cf155ef00c7cef18e2173
parent
0583e29df4d25592f6311137faca04dbcc14e82e
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2023-02-19 11:39
use libc for better portability (also use cargo)

Diffstat

M .gitignore 3 ---
A Cargo.toml 13 +++++++++++++
D Makefile 9 ---------
M README.md 2 +-
A ppm/Cargo.toml 7 +++++++
D src/libc.rs 40 ----------------------------------------

6 files changed, 21 insertions, 53 deletions


diff --git a/.gitignore b/.gitignore

@@ -1,4 +1 @@
    1     1 /target
    2    -1 survivor
    3    -1 *.rlib
    4    -1 *.so

diff --git a/Cargo.toml b/Cargo.toml

@@ -0,0 +1,13 @@
   -1     1 [package]
   -1     2 name = "survivor"
   -1     3 version = "0.1.0"
   -1     4 edition = "2021"
   -1     5 repository = "https://github.com/xi/survivor"
   -1     6 
   -1     7 [dependencies]
   -1     8 libc = "0.2"
   -1     9 ppm = { path = "ppm" }
   -1    10 
   -1    11 [profile.dev]
   -1    12 opt-level = 2
   -1    13 strip = true

diff --git a/Makefile b/Makefile

@@ -1,9 +0,0 @@
    1    -1 survivor: src/main.rs src/input.rs src/random.rs src/term.rs src/enemies.rs src/sprites.rs liblibc.rlib libppm.so
    2    -1 	rustc -O --crate-name $@ --extern libc=liblibc.rlib --extern ppm=libppm.so src/main.rs
    3    -1 	strip $@
    4    -1 
    5    -1 lib%.rlib: src/%.rs
    6    -1 	rustc $< --crate-type lib
    7    -1 
    8    -1 libppm.so: ppm/src/lib.rs
    9    -1 	rustc ppm/src/lib.rs --crate-type proc-macro --crate-name=ppm

diff --git a/README.md b/README.md

@@ -21,7 +21,7 @@ the player receives a random perk:
   21    21 ## Installation
   22    22 
   23    23 The game is written in rust and does not have any dependencies outside the
   24    -1 standard library and libc. You can run `make` to compile it.
   -1    24 standard library and libc. You can run `cargo run` to build and execute it.
   25    25 
   26    26 Note that the code is not very portable yet, so there might be issues on
   27    27 non-linux, non-glibc, or non-xterm environments.

diff --git a/ppm/Cargo.toml b/ppm/Cargo.toml

@@ -0,0 +1,7 @@
   -1     1 [package]
   -1     2 name = "ppm"
   -1     3 version = "0.1.0"
   -1     4 edition = "2021"
   -1     5 
   -1     6 [lib]
   -1     7 proc-macro = true

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

@@ -1,40 +0,0 @@
    1    -1 #![allow(non_camel_case_types)]
    2    -1 
    3    -1 pub type c_int = i32;
    4    -1 pub type c_uint = u32;
    5    -1 pub type c_ulong = u64;
    6    -1 pub type c_void = u8;
    7    -1 pub type c_uchar = u8;
    8    -1 pub type size_t = usize;
    9    -1 pub type ssize_t = isize;
   10    -1 pub type Ioctl = c_ulong;
   11    -1 pub type tcflag_t = c_uint;
   12    -1 
   13    -1 pub const SIGINT: c_int = 2;
   14    -1 pub const TIOCGWINSZ: Ioctl = 0x5413;
   15    -1 pub const ICANON: tcflag_t = 0x00000002;
   16    -1 pub const ECHO: tcflag_t = 0x00000008;
   17    -1 pub const TCSADRAIN: c_int = 1;
   18    -1 pub const VTIME: usize = 5;
   19    -1 pub const VMIN: usize = 6;
   20    -1 
   21    -1 #[repr(C)]
   22    -1 #[derive(Copy, Clone)]
   23    -1 pub struct termios {
   24    -1     pub c_iflag: tcflag_t,
   25    -1     pub c_oflag: tcflag_t,
   26    -1     pub c_cflag: tcflag_t,
   27    -1     pub c_lflag: tcflag_t,
   28    -1     pub c_line: c_uchar,
   29    -1     pub c_cc: [c_uchar; 32],
   30    -1     pub c_ispeed: c_uint,
   31    -1     pub c_ospeed: c_uint,
   32    -1 }
   33    -1 
   34    -1 extern "C" {
   35    -1     pub fn ioctl(fd: c_int, req: c_ulong, ...) -> c_int;
   36    -1     pub fn tcgetattr(fd: c_int, termios: *mut termios) -> c_int;
   37    -1     pub fn tcsetattr(fd: c_int, optional_actions: c_int, termios: *const termios) -> c_int;
   38    -1     pub fn signal(signum: c_int, handler: size_t) -> size_t;
   39    -1     pub fn getrandom(buf: *mut c_void, buflen: size_t, flags: c_uint) -> ssize_t;
   40    -1 }