From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ig0-f176.google.com ([209.85.213.176]) by ur; Wed Jul 29 08:14:08 EDT 2015 Received: by igbpg9 with SMTP id pg9so10920473igb.0 for <9front@9front.org>; Wed, 29 Jul 2015 05:14:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=Z2RUZioyGrlS0+neOzbmsgXnGb0rANXMA7dDDtnU1eA=; b=u2WXpPjwdVsv5pHcZ+Ohnjkjx5SZfXlJmw4WQL8KMaZuCgBIglvT7oSKLmIsjQETNk rqGRhs38zr5C/wVSXIDMU7GTyYisznJSG9VmR9I0IzZEtDahzLbdrbCG69XGH6sNLZTM 8m6RawLTAlJ2NSZSv/DT1Vjy8NA7XpGKY0nHmQRMYF/6gQ72b0kanwy1xaymI2xrAEUQ Z4mziv2x2nvTS/GytyEYBUmzJ2d/Ucv+CbgXzIRQhuX9LXFbbp90c/9vQJ5WRvCek9Nr 6fMko8NC8gRn9CQfQhkJqaB/OP5WDXvE0Zd/48zj1yX2PGX86x/88IyvzvDKeJi1Tx1J NLkw== MIME-Version: 1.0 X-Received: by 10.50.79.230 with SMTP id m6mr826601igx.86.1438172046411; Wed, 29 Jul 2015 05:14:06 -0700 (PDT) Received: by 10.107.56.68 with HTTP; Wed, 29 Jul 2015 05:14:06 -0700 (PDT) Date: Wed, 29 Jul 2015 15:14:06 +0300 Message-ID: List-ID: <9front.9front.org> X-Glyph: ➈ X-Bullshit: abstract high-performance callback framework Subject: games/doom: implement filelength() From: qux To: 9front@9front.org Content-Type: text/plain; charset=UTF-8 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);