From 4cba91a93645922aa977f5c6583c0c1414ce8cf2 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 11 Apr 2008 10:16:29 +0000 Subject: [PATCH] - Added a Gets function to the FileReader class which I planned to use to enable Timidity to read its config from Zips. I put this on hold though after finding out that the sound quality isn't even near that of Timidity++. - GCC-Fixes (FString::GetChars() for Printf calls) - Added a dummy Weapon.NOLMS flag so that Skulltag weapons using this flag can be loaded SVN r901 (trunk) --- src/d_main.cpp | 2 +- src/files.cpp | 38 ++++++++++++++++++++++++++++ src/files.h | 5 ++++ src/p_local.h | 2 -- src/thingdef/thingdef_properties.cpp | 18 ++++++++----- src/w_wad.cpp | 21 +++++++++++++++ src/w_wad.h | 1 + 7 files changed, 77 insertions(+), 10 deletions(-) diff --git a/src/d_main.cpp b/src/d_main.cpp index d78b6dd580..20592b63cc 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -1861,7 +1861,7 @@ static const char *BaseFileSearch (const char *file, const char *ext, bool lookf if (lookfirstinprogdir) { - sprintf (wad, "%s%s%s", progdir, progdir[strlen (progdir) - 1] != '/' ? "/" : "", file); + sprintf (wad, "%s%s%s", progdir.GetChars(), progdir[progdir.Len() - 1] != '/' ? "/" : "", file); if (FileExists (wad)) { return wad; diff --git a/src/files.cpp b/src/files.cpp index 2acdd16c0e..80d966acf2 100644 --- a/src/files.cpp +++ b/src/files.cpp @@ -132,6 +132,38 @@ long FileReader::Read (void *buffer, long len) return len; } +char *FileReader::Gets(char *strbuf, int len) +{ + if (FilePos + len > StartPos + Length) + { + len = Length - FilePos + StartPos; + } + if (len <= 0) return 0; + char *p = fgets(strbuf, len, File); + FilePos += len; + return p; +} + +char *FileReader::GetsFromBuffer(const char * bufptr, char *strbuf, int len) +{ + if (len>Length-FilePos) len=Length-FilePos; + if (len <= 0) return NULL; + + char *p = strbuf; + while (len > 1 && bufptr[FilePos] != 0) + { + if (bufptr[FilePos] != '\r') + { + *p++ = bufptr[FilePos]; + len--; + if (bufptr[FilePos] == '\n') break; + } + FilePos++; + } + *p++=0; + return strbuf; +} + long FileReader::CalcFileLen() const { long endpos; @@ -265,3 +297,9 @@ long MemoryReader::Read (void *buffer, long len) FilePos+=len; return len; } + +char *MemoryReader::Gets(char *strbuf, int len) +{ + return GetsFromBuffer(bufptr, strbuf, len); +} + diff --git a/src/files.h b/src/files.h index e238c98193..5786169109 100644 --- a/src/files.h +++ b/src/files.h @@ -17,6 +17,7 @@ public: virtual long Tell () const; virtual long Seek (long offset, int origin); virtual long Read (void *buffer, long len); + virtual char *Gets(char *strbuf, int len); long GetLength () const { return Length; } // If you use the underlying FILE without going through this class, @@ -58,10 +59,13 @@ public: return *this; } + protected: FileReader (const FileReader &other, long length); FileReader (); + char *GetsFromBuffer(const char * bufptr, char *strbuf, int len); + FILE *File; long Length; long StartPos; @@ -145,6 +149,7 @@ public: virtual long Tell () const; virtual long Seek (long offset, int origin); virtual long Read (void *buffer, long len); + virtual char *Gets(char *strbuf, int len); protected: const char * bufptr; diff --git a/src/p_local.h b/src/p_local.h index 0358118a0d..4578d8c769 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -167,8 +167,6 @@ typedef struct } d; } intercept_t; -extern TArray intercepts; - typedef bool (*traverser_t) (intercept_t *in); fixed_t P_AproxDistance (fixed_t dx, fixed_t dy); diff --git a/src/thingdef/thingdef_properties.cpp b/src/thingdef/thingdef_properties.cpp index 4f91cee16b..14fc537cf3 100644 --- a/src/thingdef/thingdef_properties.cpp +++ b/src/thingdef/thingdef_properties.cpp @@ -80,7 +80,8 @@ // [RH] Keep GCC quiet by not using offsetof on Actor types. #define DEFINE_FLAG(prefix, name, type, variable) { prefix##_##name, #name, (int)(size_t)&((type*)1)->variable - 1 } #define DEFINE_FLAG2(symbol, name, type, variable) { symbol, #name, (int)(size_t)&((type*)1)->variable - 1 } -#define DEFINE_DEPRECATED_FLAG(name, type) { DEPF_##name, #name, -1 } +#define DEFINE_DEPRECATED_FLAG(name) { DEPF_##name, #name, -1 } +#define DEFINE_DUMMY_FLAG(name) { DEPF_UNUSED, #name, -1 } struct flagdef { @@ -91,6 +92,7 @@ struct flagdef enum { + DEPF_UNUSED, DEPF_FIREDAMAGE, DEPF_ICEDAMAGE, DEPF_LOWGRAVITY, @@ -248,11 +250,11 @@ static flagdef ActorFlags[]= DEFINE_FLAG(RF, FORCEXYBILLBOARD, AActor, renderflags), // Deprecated flags. Handling must be performed in HandleDeprecatedFlags - DEFINE_DEPRECATED_FLAG(FIREDAMAGE, AActor), - DEFINE_DEPRECATED_FLAG(ICEDAMAGE, AActor), - DEFINE_DEPRECATED_FLAG(LOWGRAVITY, AActor), - DEFINE_DEPRECATED_FLAG(SHORTMISSILERANGE, AActor), - DEFINE_DEPRECATED_FLAG(LONGMELEERANGE, AActor), + DEFINE_DEPRECATED_FLAG(FIREDAMAGE), + DEFINE_DEPRECATED_FLAG(ICEDAMAGE), + DEFINE_DEPRECATED_FLAG(LOWGRAVITY), + DEFINE_DEPRECATED_FLAG(SHORTMISSILERANGE), + DEFINE_DEPRECATED_FLAG(LONGMELEERANGE), }; static flagdef InventoryFlags[] = @@ -271,7 +273,7 @@ static flagdef InventoryFlags[] = DEFINE_FLAG(IF, IGNORESKILL, AInventory, ItemFlags), DEFINE_FLAG(IF, ADDITIVETIME, AInventory, ItemFlags), - DEFINE_DEPRECATED_FLAG(PICKUPFLASH, AInventory), + DEFINE_DEPRECATED_FLAG(PICKUPFLASH), }; @@ -296,6 +298,8 @@ static flagdef WeaponFlags[] = DEFINE_FLAG(WIF, CHEATNOTWEAPON, AWeapon, WeaponFlags), DEFINE_FLAG(WIF, NO_AUTO_SWITCH, AWeapon, WeaponFlags), //WIF_BOT_REACTION_SKILL_THING = 1<<31, // I don't understand this + + DEFINE_DUMMY_FLAG(NOLMS), }; static const struct { const PClass *Type; flagdef *Defs; int NumDefs; } FlagLists[] = diff --git a/src/w_wad.cpp b/src/w_wad.cpp index 8bd452e268..dabce28326 100644 --- a/src/w_wad.cpp +++ b/src/w_wad.cpp @@ -2274,6 +2274,27 @@ long FWadLump::Read (void *buffer, long len) return numread; } +char *FWadLump::Gets(char *strbuf, int len) +{ + // Blood, you are so mean to me with your encryption. + // ... and since this function will never read from Blood + // files let's just return an error here. + if (Encrypted && FilePos - StartPos < 256) + { + return NULL; + } + + if (SourceData != NULL) + { + return GetsFromBuffer(SourceData, strbuf, len); + } + else + { + return FileReader::Gets(strbuf, len); + } + return strbuf; +} + // FMemLump ----------------------------------------------------------------- FMemLump::FMemLump () diff --git a/src/w_wad.h b/src/w_wad.h index 7d84a4dda3..70c2302fa4 100644 --- a/src/w_wad.h +++ b/src/w_wad.h @@ -119,6 +119,7 @@ public: long Seek (long offset, int origin); long Read (void *buffer, long len); + char *Gets(char *strbuf, int len); private: FWadLump (const FileReader &reader, long length, bool encrypted);