9front - general discussion about 9front
 help / color / mirror / Atom feed
* games/doom: implement filelength()
@ 2015-07-29 12:14 qux
  2015-07-29 12:53 ` [9front] " cinap_lenrek
  0 siblings, 1 reply; 2+ messages in thread
From: qux @ 2015-07-29 12:14 UTC (permalink / raw)
  To: 9front

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);


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [9front] games/doom: implement filelength()
  2015-07-29 12:14 games/doom: implement filelength() qux
@ 2015-07-29 12:53 ` cinap_lenrek
  0 siblings, 0 replies; 2+ messages in thread
From: cinap_lenrek @ 2015-07-29 12:53 UTC (permalink / raw)
  To: 9front

also pushed, except the addition to w_wad.h as that can be done
once the function is actually used from another place.

--
cinap


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-07-29 12:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-29 12:14 games/doom: implement filelength() qux
2015-07-29 12:53 ` [9front] " cinap_lenrek

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).