diff options
author | rodri <rgl@antares-labs.eu> | 2023-04-13 11:09:13 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2023-04-13 11:09:13 +0000 |
commit | 00f7d8dd3dc47ed3cfa951325e809a92c37341b7 (patch) | |
tree | bfe2916f4c3d4f0b5f659563bb61586633e7578b /sprite.c | |
parent | 42ea627853d79a54ef956a831e2f8badff5bfdb8 (diff) | |
download | musw-00f7d8dd3dc47ed3cfa951325e809a92c37341b7.tar.gz musw-00f7d8dd3dc47ed3cfa951325e809a92c37341b7.tar.bz2 musw-00f7d8dd3dc47ed3cfa951325e809a92c37341b7.zip |
now using PNG files instead of image(6)s. bullet TTL taken into account during stepping.
Diffstat (limited to 'sprite.c')
-rw-r--r-- | sprite.c | 40 |
1 files changed, 40 insertions, 0 deletions
@@ -3,6 +3,7 @@ #include <ip.h> #include <mp.h> #include <libsec.h> +#include <thread.h> #include <draw.h> #include <geometry.h> #include "dat.h" @@ -68,6 +69,45 @@ readsprite(char *sheetfile, Point sp, Rectangle r, int nframes, ulong period) return newsprite(sheet, sp, r, nframes, period); } +static void +decproc(void *arg) +{ + int fd, *pfd; + + pfd = arg; + fd = pfd[2]; + + close(pfd[0]); + dup(fd, 0); + close(fd); + dup(pfd[1], 1); + close(pfd[1]); + + execl("/bin/png", "png", "-t9", nil); + threadexitsall("execl: %r"); +} + +Sprite * +readpngsprite(char *sheetfile, Point sp, Rectangle r, int nframes, ulong period) +{ + Image *sheet; + int fd, pfd[3]; + + if(pipe(pfd) < 0) + sysfatal("pipe: %r"); + fd = open(sheetfile, OREAD); + if(fd < 0) + sysfatal("readpngsprite: %r"); + pfd[2] = fd; + procrfork(decproc, pfd, mainstacksize, RFFDG|RFNAMEG|RFNOTEG); + close(pfd[1]); + sheet = readimage(display, pfd[0], 1); + close(pfd[0]); + close(fd); + + return newsprite(sheet, sp, r, nframes, period); +} + void delsprite(Sprite *spr) { |