9front - general discussion about 9front
 help / color / mirror / Atom feed
From: qux <qu7uux@gmail.com>
To: 9front@9front.org
Subject: games/doom: implement filelength()
Date: Wed, 29 Jul 2015 15:14:06 +0300	[thread overview]
Message-ID: <CAAGZaiLfOrKeW0dACKkqRyGzSpjXn+yC7yTQqcdgg-2LeJ0Pqg@mail.gmail.com> (raw)

games/doom: implement filelength()

this function is used when playing demos from external lumps. the game just
exits without this patch.
to test this, download a demo lump from somewhere, and play it with -playdemo %s
where %s is the file's name, without the .lmp extension:

(note that this one is a doom 2 demo, so it requires doom2.wad)
% hget http://doomedsda.us/lmps/945/3/30nm2939.zip | unzip -sv
extracting 30nm2939.LMP
extracting 30nm2939.txt
% mv 30nm2939.LMP 30nm2939.lmp	# checking for a lump filename is case sensitive
% games/doom -playdemo 30nm2939

the game exits when the demo ends. also, note that this demo will desync on
map06 (the crusher), because of an unrelated bug (that's another patch :>)

note: filelength() returns vlong, but file lengths for doom lumps are ints.
however, this might be used elsewhere (networking), so i'd leave it this way.

diff -r f584d10d086b sys/src/games/doom/w_wad.c
--- a/sys/src/games/doom/w_wad.c	Sun Jul 26 13:55:51 2015 +0200
+++ b/sys/src/games/doom/w_wad.c	Wed Jul 29 14:17:03 2015 +0300
@@ -64,19 +64,18 @@
     while (*s) { *s = toupper(*s); s++; }
 }

-int filelength (int handle)
+vlong
+filelength(int fd)
 {
-	USED(handle);
-	I_Error ("PORTME w_wad.c filelength");
-	return -1;
-/*
-    struct stat	fileinfo;
-
-    if (fstat (handle,&fileinfo) == -1)
-	I_Error ("Error fstating");
+	vlong l;
+	Dir *d;

-    return fileinfo.st_size;
-*/
+	d = dirfstat(fd);
+	if(d == nil)
+		sysfatal("dirfstat: %r");
+	l = d->length;
+	free(d);
+	return l;	/* lump file lenghts in doom are ints */
 }


diff -r f584d10d086b sys/src/games/doom/w_wad.h
--- a/sys/src/games/doom/w_wad.h	Sun Jul 26 13:55:51 2015 +0200
+++ b/sys/src/games/doom/w_wad.h	Wed Jul 29 14:17:03 2015 +0300
@@ -67,6 +67,7 @@
 void*	W_CacheLumpNum (int lump, int tag);
 void*	W_CacheLumpName (char* name, int tag);

+vlong	filelength (int);


             reply	other threads:[~2015-07-29 12:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-29 12:14 qux [this message]
2015-07-29 12:53 ` [9front] " cinap_lenrek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAAGZaiLfOrKeW0dACKkqRyGzSpjXn+yC7yTQqcdgg-2LeJ0Pqg@mail.gmail.com \
    --to=qu7uux@gmail.com \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).