diff --git a/docs/rh-log.txt b/docs/rh-log.txt index d482056f4..839b7e4eb 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,3 +1,17 @@ +June 1, 2008 (Changes by Graf Zahl) +- Made all the basic texture classes local to their implementation. + They are not needed anywhere else. +- Changed the HackHack hack for corrupt 256 pixel high textures that + FMultiPatchTexture only calls a virtual function instead of doing any + type checks of the patch itself. +- Cleaned up the constant definitions in doomdata.h. +- Moved the TEXTUREx structures from doomdata.h to multipatchtexture.cpp + because they are used only in this one file. +- Removed some more typedefs from r_defs.h and doomdata.h +- Moved local polyobject data definitions from p_local.h to po_man.cpp. +- Renamed player_s to player_t globally to get rid of the duplicate names + for this class. + May 31, 2008 - Added coordinate range checking to DCanvas::ParseDrawTextureTags() to avoid potential crashes in the situation that con_scaletext is 2 and somebody diff --git a/src/actor.h b/src/actor.h index 4e35e82c2..d3871789d 100644 --- a/src/actor.h +++ b/src/actor.h @@ -706,7 +706,7 @@ public: angle_t LookExFOV; // Field of Vision // a linked list of sectors where this object appears - struct msecnode_s *touching_sectorlist; // phares 3/14/98 + struct msecnode_t *touching_sectorlist; // phares 3/14/98 TObjPtr Inventory; // [RH] This actor's inventory DWORD InventoryID; // A unique ID to keep track of inventory items diff --git a/src/configfile.h b/src/configfile.h index 05dfd406e..e34489b37 100644 --- a/src/configfile.h +++ b/src/configfile.h @@ -34,6 +34,9 @@ #ifndef __CONFIGFILE_H__ #define __CONFIGFILE_H__ +#include +#include "zstring.h" + class FConfigFile { public: diff --git a/src/d_net.h b/src/d_net.h index 30fa2bcff..c10238282 100644 --- a/src/d_net.h +++ b/src/d_net.h @@ -23,7 +23,7 @@ #ifndef __D_NET__ #define __D_NET__ -//#include "d_player.h" +#include "doomtype.h" // diff --git a/src/doomdata.h b/src/doomdata.h index b1ef43682..ef3e793fd 100644 --- a/src/doomdata.h +++ b/src/doomdata.h @@ -70,14 +70,14 @@ enum // A single Vertex. -typedef struct +struct mapvertex_t { short x, y; -} mapvertex_t; +}; // A SideDef, defining the visual appearance of a wall, // by setting textures and offsets. -typedef struct +struct mapsidedef_t { short textureoffset; short rowoffset; @@ -85,7 +85,7 @@ typedef struct char bottomtexture[8]; char midtexture[8]; short sector; // Front sector, towards viewer. -} mapsidedef_t; +}; // A LineDef, as used for editing, and as input to the BSP builder. struct maplinedef_t @@ -115,50 +115,45 @@ struct maplinedef2_t // LineDef attributes. // -#define ML_BLOCKING 0x0001 // solid, is an obstacle -#define ML_BLOCKMONSTERS 0x0002 // blocks monsters only -#define ML_TWOSIDED 0x0004 // backside will not be present at all if not two sided - -// If a texture is pegged, the texture will have -// the end exposed to air held constant at the -// top or bottom of the texture (stairs or pulled -// down things) and will move with a height change -// of one of the neighbor sectors. -// Unpegged textures always have the first row of -// the texture at the top pixel of the line for both -// top and bottom textures (use next to windows). - -#define ML_DONTPEGTOP 0x0008 // upper texture unpegged -#define ML_DONTPEGBOTTOM 0x0010 // lower texture unpegged -#define ML_SECRET 0x0020 // don't map as two sided: IT'S A SECRET! -#define ML_SOUNDBLOCK 0x0040 // don't let sound cross two of these -#define ML_DONTDRAW 0x0080 // don't draw on the automap -#define ML_MAPPED 0x0100 // set if already drawn in automap -#define ML_REPEAT_SPECIAL 0x0200 // special is repeatable - -#define ML_SPAC_SHIFT 10 -#define ML_SPAC_MASK 0x1c00 // Hexen's activator mask. These flags are no longer used. - -#define ML_ADDTRANS 0x400 // additive translucency (can only be set internally) - -// Extended flags -#define ML_MONSTERSCANACTIVATE 0x00002000 // [RH] Monsters (as well as players) can active the line -#define ML_BLOCK_PLAYERS 0x00004000 -#define ML_BLOCKEVERYTHING 0x00008000 // [RH] Line blocks everything -#define ML_ZONEBOUNDARY 0x00010000 -#define ML_RAILING 0x00020000 -#define ML_BLOCK_FLOATERS 0x00040000 -#define ML_CLIP_MIDTEX 0x00080000 // Automatic for every Strife line -#define ML_WRAP_MIDTEX 0x00100000 -#define ML_3DMIDTEX 0x00200000 -#define ML_CHECKSWITCHRANGE 0x00400000 -#define ML_FIRSTSIDEONLY 0x00800000 // activated only when crossed from front side - - -static inline int GET_SPAC (int flags) +enum ELineFlags { - return (flags&ML_SPAC_MASK) >> ML_SPAC_SHIFT; -} + ML_BLOCKING =0x00000001, // solid, is an obstacle + ML_BLOCKMONSTERS =0x00000002, // blocks monsters only + ML_TWOSIDED =0x00000004, // backside will not be present at all if not two sided + + // If a texture is pegged, the texture will have + // the end exposed to air held constant at the + // top or bottom of the texture (stairs or pulled + // down things) and will move with a height change + // of one of the neighbor sectors. + // Unpegged textures always have the first row of + // the texture at the top pixel of the line for both + // top and bottom textures (use next to windows). + + ML_DONTPEGTOP = 0x00000008, // upper texture unpegged + ML_DONTPEGBOTTOM = 0x00000010, // lower texture unpegged + ML_SECRET = 0x00000020, // don't map as two sided: IT'S A SECRET! + ML_SOUNDBLOCK = 0x00000040, // don't let sound cross two of these + ML_DONTDRAW = 0x00000080, // don't draw on the automap + ML_MAPPED = 0x00000100, // set if already drawn in automap + ML_REPEAT_SPECIAL = 0x00000200, // special is repeatable + + ML_ADDTRANS = 0x00000400, // additive translucency (can only be set internally) + + // Extended flags + ML_MONSTERSCANACTIVATE = 0x00002000, // [RH] Monsters (as well as players) can active the line + ML_BLOCK_PLAYERS = 0x00004000, + ML_BLOCKEVERYTHING = 0x00008000, // [RH] Line blocks everything + ML_ZONEBOUNDARY = 0x00010000, + ML_RAILING = 0x00020000, + ML_BLOCK_FLOATERS = 0x00040000, + ML_CLIP_MIDTEX = 0x00080000, // Automatic for every Strife line + ML_WRAP_MIDTEX = 0x00100000, + ML_3DMIDTEX = 0x00200000, + ML_CHECKSWITCHRANGE = 0x00400000, + ML_FIRSTSIDEONLY = 0x00800000, // activated only when crossed from front side +}; + // Special activation types enum SPAC @@ -178,24 +173,37 @@ enum SPAC SPAC_PlayerActivate = (SPAC_Cross|SPAC_Use|SPAC_Impact|SPAC_Push|SPAC_AnyCross|SPAC_UseThrough), }; -// [RH] BOOM's ML_PASSUSE flag (conflicts with ML_REPEATSPECIAL) -#define ML_PASSUSE_BOOM 0x0200 +enum EMapLineFlags // These are flags that use different values internally +{ + // For Hexen format maps + ML_SPAC_SHIFT = 10, + ML_SPAC_MASK = 0x1c00, // Hexen's activator mask. -#define ML_3DMIDTEX_ETERNITY 0x0400 + // [RH] BOOM's ML_PASSUSE flag (conflicts with ML_REPEATSPECIAL) + ML_PASSUSE_BOOM = 0x0200, + ML_3DMIDTEX_ETERNITY = 0x0400, -// If this bit is set, then all non-original-Doom bits are cleared when -// translating the line. Only applies when playing Doom with Doom-format maps. -// Hexen format maps and the other games are not affected by this. -#define ML_RESERVED_ETERNITY 0x0800 + // If this bit is set, then all non-original-Doom bits are cleared when + // translating the line. Only applies when playing Doom with Doom-format maps. + // Hexen format maps and the other games are not affected by this. + ML_RESERVED_ETERNITY = 0x0800, + + // [RH] Extra flags for Strife + ML_TRANSLUCENT_STRIFE = 0x1000, + ML_RAILING_STRIFE = 0x0200, + ML_BLOCK_FLOATERS_STRIFE = 0x0400, +}; + + +static inline int GET_SPAC (int flags) +{ + return (flags&ML_SPAC_MASK) >> ML_SPAC_SHIFT; +} -// [RH] Extra flags for Strife compatibility -#define ML_TRANSLUCENT_STRIFE 0x1000 -#define ML_RAILING_STRIFE 0x0200 -#define ML_BLOCK_FLOATERS_STRIFE 0x0400 // Sector definition, from editing -typedef struct +struct mapsector_t { short floorheight; short ceilingheight; @@ -204,19 +212,19 @@ typedef struct short lightlevel; short special; short tag; -} mapsector_t; +}; // SubSector, as generated by BSP -typedef struct +struct mapsubsector_t { WORD numsegs; WORD firstseg; // index of first one, segs are stored sequentially -} mapsubsector_t; +}; // LineSeg, generated by splitting LineDefs // using partition lines selected by BSP builder. -typedef struct +struct mapseg_t { WORD v1; WORD v2; @@ -224,7 +232,7 @@ typedef struct WORD linedef; short side; short offset; -} mapseg_t; +}; @@ -233,31 +241,31 @@ typedef struct // Indicate a leaf. #define NF_SUBSECTOR 0x8000 -typedef struct +struct mapnode_t { short x,y,dx,dy; // partition line short bbox[2][4]; // bounding box for each child // If NF_SUBSECTOR is or'ed in, it's a subsector, // else it's a node of another subtree. unsigned short children[2]; -} mapnode_t; +}; // Thing definition, position, orientation and type, // plus skill/visibility flags and attributes. -typedef struct +struct mapthing_t { short x; short y; short angle; short type; short options; -} mapthing_t; +}; // [RH] Hexen-compatible MapThing. -typedef struct +struct mapthinghexen_t { unsigned short thingid; short x; @@ -268,7 +276,9 @@ typedef struct short flags; BYTE special; BYTE args[5]; -} mapthinghexen_t; +}; + +class FArchive; // Internal representation of a mapthing struct FMapThing @@ -291,112 +301,54 @@ struct FMapThing // [RH] MapThing flags. -/* -#define MTF_EASY 0x0001 // Thing will appear on easy skill setting -#define MTF_MEDIUM 0x0002 // Thing will appear on medium skill setting -#define MTF_HARD 0x0004 // Thing will appear on hard skill setting -#define MTF_AMBUSH 0x0008 // Thing is deaf -*/ -#define MTF_DORMANT 0x0010 // Thing is dormant (use Thing_Activate) -/* -#define MTF_FIGHTER 0x0020 -#define MTF_CLERIC 0x0040 -#define MTF_MAGE 0x0080 -*/ -#define MTF_CLASS_MASK 0x00e0 -#define MTF_CLASS_SHIFT 5 - -#define MTF_SINGLE 0x0100 // Thing appears in single-player games -#define MTF_COOPERATIVE 0x0200 // Thing appears in cooperative games -#define MTF_DEATHMATCH 0x0400 // Thing appears in deathmatch games - -#define MTF_SHADOW 0x0800 -#define MTF_ALTSHADOW 0x1000 -#define MTF_FRIENDLY 0x2000 -#define MTF_STANDSTILL 0x4000 -#define MTF_STRIFESOMETHING 0x8000 - -// BOOM and DOOM compatible versions of some of the above - -#define BTF_NOTSINGLE 0x0010 // (TF_COOPERATIVE|TF_DEATHMATCH) -#define BTF_NOTDEATHMATCH 0x0020 // (TF_SINGLE|TF_COOPERATIVE) -#define BTF_NOTCOOPERATIVE 0x0040 // (TF_SINGLE|TF_DEATHMATCH) -#define BTF_FRIENDLY 0x0080 // MBF friendly monsters -#define BTF_BADEDITORCHECK 0x0100 // for detecting bad (Mac) editors - -// Strife thing flags - -#define STF_STANDSTILL 0x0008 -#define STF_AMBUSH 0x0020 -#define STF_FRIENDLY 0x0040 -#define STF_SHADOW 0x0100 -#define STF_ALTSHADOW 0x0200 - -//-------------------------------------------------------------------------- -// -// Texture definition -// -//-------------------------------------------------------------------------- - -// -// Each texture is composed of one or more patches, with patches being lumps -// stored in the WAD. The lumps are referenced by number, and patched into -// the rectangular texture space using origin and possibly other attributes. -// -typedef struct +enum EMapThingFlags { - SWORD originx; - SWORD originy; - SWORD patch; - SWORD stepdir; - SWORD colormap; -} mappatch_t; + /* + MTF_EASY = 0x0001, // The skill flags are no longer used directly. + MTF_MEDIUM = 0x0002, + MTF_HARD = 0x0004, + */ -// -// A wall texture is a list of patches which are to be combined in a -// predefined order. -// -typedef struct -{ - BYTE name[8]; - WORD Flags; // [RH] Was unused - BYTE ScaleX; // [RH] Scaling (8 is normal) - BYTE ScaleY; // [RH] Same as above - SWORD width; - SWORD height; - BYTE columndirectory[4]; // OBSOLETE - SWORD patchcount; - mappatch_t patches[1]; -} maptexture_t; + MTF_SKILLMASK = 0x0007, + MTF_SKILLSHIFT = 1, // Skill bits will be shifted 1 bit to the left to make room + // for a bit representing the lowest skill (sk_baby) -#define MAPTEXF_WORLDPANNING 0x8000 + MTF_AMBUSH = 0x0008, // Thing is deaf + MTF_DORMANT = 0x0010, // Thing is dormant (use Thing_Activate) + /* + MTF_FIGHTER = 0x0020, // The class flags are no longer used directly. + MTF_CLERIC = 0x0040, + MTF_MAGE = 0x0080, + */ + MTF_CLASS_MASK = 0x00e0, + MTF_CLASS_SHIFT = 5, -// [RH] Just for documentation purposes, here's what I think the -// Strife versions of the above two structures are: + MTF_SINGLE = 0x0100, // Thing appears in single-player games + MTF_COOPERATIVE = 0x0200, // Thing appears in cooperative games + MTF_DEATHMATCH = 0x0400, // Thing appears in deathmatch games -typedef struct -{ - SWORD originx; - SWORD originy; - SWORD patch; -} strifemappatch_t; + MTF_SHADOW = 0x0800, + MTF_ALTSHADOW = 0x1000, + MTF_FRIENDLY = 0x2000, + MTF_STANDSTILL = 0x4000, + MTF_STRIFESOMETHING = 0x8000, -// -// A wall texture is a list of patches which are to be combined in a -// predefined order. -// -typedef struct -{ - BYTE name[8]; - WORD Flags; // [RH] Was unused - BYTE ScaleX; // [RH] Scaling (8 is normal) - BYTE ScaleY; // [RH] Same as above - SWORD width; - SWORD height; - SWORD patchcount; - strifemappatch_t patches[1]; -} strifemaptexture_t; + // BOOM and DOOM compatible versions of some of the above + BTF_NOTSINGLE = 0x0010, // (TF_COOPERATIVE|TF_DEATHMATCH) + BTF_NOTDEATHMATCH = 0x0020, // (TF_SINGLE|TF_COOPERATIVE) + BTF_NOTCOOPERATIVE = 0x0040, // (TF_SINGLE|TF_DEATHMATCH) + BTF_FRIENDLY = 0x0080, // MBF friendly monsters + BTF_BADEDITORCHECK = 0x0100, // for detecting bad (Mac) editors + + // Strife thing flags + + STF_STANDSTILL = 0x0008, + STF_AMBUSH = 0x0020, + STF_FRIENDLY = 0x0040, + STF_SHADOW = 0x0100, + STF_ALTSHADOW = 0x0200, +}; #endif // __DOOMDATA__ diff --git a/src/doomdef.h b/src/doomdef.h index 760de632c..510f6bbe1 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -26,8 +26,6 @@ #include #include -#include "farchive.h" - // // Global parameters/defines. // @@ -90,21 +88,6 @@ typedef enum GS_FORCEWIPEFADE = -2 } gamestate_t; -// -// Difficulty/skill settings/filters. -// - -// Skill flags. -/* -#define MTF_EASY 1 -#define MTF_NORMAL 2 -#define MTF_HARD 4 -*/ -#define MTF_SKILLMASK 7 -#define MTF_SKILLSHIFT 1 - -// Deaf monsters/do not react to sound. -#define MTF_AMBUSH 8 typedef float skill_t; diff --git a/src/g_level.h b/src/g_level.h index 6673bb355..31178ddfc 100644 --- a/src/g_level.h +++ b/src/g_level.h @@ -132,6 +132,9 @@ struct FSpecialAction FSpecialAction *Next; }; +class FCompressedMemFile; +class DScroller; + struct level_info_t { char mapname[9]; diff --git a/src/m_menu.cpp b/src/m_menu.cpp index ff4c3cab4..2cdf6d773 100644 --- a/src/m_menu.cpp +++ b/src/m_menu.cpp @@ -1038,7 +1038,7 @@ static void M_ExtractSaveData (const FSaveGameNode *node) } // Extract pic - SavePic = FPNGTexture::CreateFromFile(png, node->Filename); + SavePic = PNGTexture_CreateFromFile(png, node->Filename); delete png; } diff --git a/src/m_png.h b/src/m_png.h index f49583ed6..56b73f650 100644 --- a/src/m_png.h +++ b/src/m_png.h @@ -105,3 +105,8 @@ bool M_GetPNGText (PNGHandle *png, const char *keyword, char *buffer, size_t buf // image data into the provided buffer. Returns true on success. bool M_ReadIDAT (FileReader *file, BYTE *buffer, int width, int height, int pitch, BYTE bitdepth, BYTE colortype, BYTE interlace, unsigned int idatlen); + + +class FTexture; + +FTexture *PNGTexture_CreateFromFile(PNGHandle *png, const FString &filename); diff --git a/src/p_local.h b/src/p_local.h index 07afe057a..9abd5270d 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -454,92 +454,12 @@ typedef enum PODOOR_SWING, } podoortype_t; -inline FArchive &operator<< (FArchive &arc, podoortype_t &type) -{ - BYTE val = (BYTE)type; - arc << val; - type = (podoortype_t)val; - return arc; -} - -class DPolyAction : public DThinker -{ - DECLARE_CLASS (DPolyAction, DThinker) -public: - DPolyAction (int polyNum); - ~DPolyAction (); - void Serialize (FArchive &arc); - - void StopInterpolation (); -protected: - DPolyAction (); - int m_PolyObj; - int m_Speed; - int m_Dist; - - void SetInterpolation (); - - friend void ThrustMobj (AActor *actor, seg_t *seg, polyobj_t *po); -}; - -void ThrustMobj (AActor *actor, seg_t *seg, polyobj_t *po); - -class DRotatePoly : public DPolyAction -{ - DECLARE_CLASS (DRotatePoly, DPolyAction) -public: - DRotatePoly (int polyNum); - void Tick (); -private: - DRotatePoly (); - - friend bool EV_RotatePoly (line_t *line, int polyNum, int speed, int byteAngle, int direction, bool overRide); -}; - bool EV_RotatePoly (line_t *line, int polyNum, int speed, int byteAngle, int direction, bool overRide); - -bool EV_RotatePoly (line_t *line, int polyNum, int speed, int byteAngle, int direction, bool overRide); - -class DMovePoly : public DPolyAction -{ - DECLARE_CLASS (DMovePoly, DPolyAction) -public: - DMovePoly (int polyNum); - void Serialize (FArchive &arc); - void Tick (); -protected: - DMovePoly (); - int m_Angle; - fixed_t m_xSpeed; // for sliding walls - fixed_t m_ySpeed; - - friend bool EV_MovePoly (line_t *line, int polyNum, int speed, angle_t angle, fixed_t dist, bool overRide); -}; - bool EV_MovePoly (line_t *line, int polyNum, int speed, angle_t angle, fixed_t dist, bool overRide); - -class DPolyDoor : public DMovePoly -{ - DECLARE_CLASS (DPolyDoor, DMovePoly) -public: - DPolyDoor (int polyNum, podoortype_t type); - void Serialize (FArchive &arc); - void Tick (); -protected: - int m_Direction; - int m_TotalDist; - int m_Tics; - int m_WaitTics; - podoortype_t m_Type; - bool m_Close; - - friend bool EV_OpenPolyDoor (line_t *line, int polyNum, int speed, angle_t angle, int delay, int distance, podoortype_t type); -private: - DPolyDoor (); -}; - bool EV_OpenPolyDoor (line_t *line, int polyNum, int speed, angle_t angle, int delay, int distance, podoortype_t type); + + // [RH] Data structure for P_SpawnMapThing() to keep track // of polyobject-related things. typedef struct polyspawns_s @@ -564,7 +484,7 @@ enum PO_SPAWNHURT_TYPE }; -extern polyobj_t *polyobjs; // list of all poly-objects on the level +extern FPolyObj *polyobjs; // list of all poly-objects on the level extern int po_NumPolyobjs; extern polyspawns_t *polyspawns; // [RH] list of polyobject things to spawn diff --git a/src/p_saveg.cpp b/src/p_saveg.cpp index 8e990c9a6..63b2d1bd8 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -459,7 +459,7 @@ void P_SerializeSounds (FArchive &arc) void P_SerializePolyobjs (FArchive &arc) { int i; - polyobj_t *po; + FPolyObj *po; if (arc.IsStoring ()) { diff --git a/src/po_man.cpp b/src/po_man.cpp index 4ac6a12c8..bbacc73f1 100644 --- a/src/po_man.cpp +++ b/src/po_man.cpp @@ -31,6 +31,84 @@ // TYPES ------------------------------------------------------------------- +inline FArchive &operator<< (FArchive &arc, podoortype_t &type) +{ + BYTE val = (BYTE)type; + arc << val; + type = (podoortype_t)val; + return arc; +} + +class DPolyAction : public DThinker +{ + DECLARE_CLASS (DPolyAction, DThinker) +public: + DPolyAction (int polyNum); + ~DPolyAction (); + void Serialize (FArchive &arc); + + void StopInterpolation (); +protected: + DPolyAction (); + int m_PolyObj; + int m_Speed; + int m_Dist; + + void SetInterpolation (); + + friend void ThrustMobj (AActor *actor, seg_t *seg, FPolyObj *po); +}; + +class DRotatePoly : public DPolyAction +{ + DECLARE_CLASS (DRotatePoly, DPolyAction) +public: + DRotatePoly (int polyNum); + void Tick (); +private: + DRotatePoly (); + + friend bool EV_RotatePoly (line_t *line, int polyNum, int speed, int byteAngle, int direction, bool overRide); +}; + + +class DMovePoly : public DPolyAction +{ + DECLARE_CLASS (DMovePoly, DPolyAction) +public: + DMovePoly (int polyNum); + void Serialize (FArchive &arc); + void Tick (); +protected: + DMovePoly (); + int m_Angle; + fixed_t m_xSpeed; // for sliding walls + fixed_t m_ySpeed; + + friend bool EV_MovePoly (line_t *line, int polyNum, int speed, angle_t angle, fixed_t dist, bool overRide); +}; + + +class DPolyDoor : public DMovePoly +{ + DECLARE_CLASS (DPolyDoor, DMovePoly) +public: + DPolyDoor (int polyNum, podoortype_t type); + void Serialize (FArchive &arc); + void Tick (); +protected: + int m_Direction; + int m_TotalDist; + int m_Tics; + int m_WaitTics; + podoortype_t m_Type; + bool m_Close; + + friend bool EV_OpenPolyDoor (line_t *line, int polyNum, int speed, angle_t angle, int delay, int distance, podoortype_t type); +private: + DPolyDoor (); +}; + // EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- bool PO_RotatePolyobj (int num, angle_t angle); @@ -38,19 +116,19 @@ void PO_Init (void); // PRIVATE FUNCTION PROTOTYPES --------------------------------------------- -static polyobj_t *GetPolyobj (int polyNum); +static FPolyObj *GetPolyobj (int polyNum); static int GetPolyobjMirror (int poly); static void UpdateSegBBox (seg_t *seg); static void RotatePt (int an, fixed_t *x, fixed_t *y, fixed_t startSpotX, fixed_t startSpotY); -static void UnLinkPolyobj (polyobj_t *po); -static void LinkPolyobj (polyobj_t *po); -static bool CheckMobjBlocking (seg_t *seg, polyobj_t *po); +static void UnLinkPolyobj (FPolyObj *po); +static void LinkPolyobj (FPolyObj *po); +static bool CheckMobjBlocking (seg_t *seg, FPolyObj *po); static void InitBlockMap (void); static void IterFindPolySegs (vertex_t *v1, vertex_t *v2, seg_t **segList); static void SpawnPolyobj (int index, int tag, int type); static void TranslateToStartSpot (int tag, int originX, int originY); -static void DoMovePolyobj (polyobj_t *po, int x, int y); +static void DoMovePolyobj (FPolyObj *po, int x, int y); static void InitSegLists (); static void KillSegLists (); @@ -61,7 +139,7 @@ extern seg_t *segs; // PUBLIC DATA DEFINITIONS ------------------------------------------------- polyblock_t **PolyBlockMap; -polyobj_t *polyobjs; // list of all poly-objects on the level +FPolyObj *polyobjs; // list of all poly-objects on the level int po_NumPolyobjs; polyspawns_t *polyspawns; // [RH] Let P_SpawnMapThings() find our thingies for us @@ -99,7 +177,7 @@ DPolyAction::DPolyAction (int polyNum) DPolyAction::~DPolyAction () { - polyobj_t *poly = GetPolyobj (m_PolyObj); + FPolyObj *poly = GetPolyobj (m_PolyObj); if (poly->specialdata == NULL || poly->specialdata == this) { @@ -110,7 +188,7 @@ DPolyAction::~DPolyAction () void DPolyAction::SetInterpolation () { - polyobj_t *poly = GetPolyobj (m_PolyObj); + FPolyObj *poly = GetPolyobj (m_PolyObj); for (int i = 0; i < poly->numsegs; ++i) { setinterpolation (INTERP_Vertex, poly->segs[i]->v1); @@ -120,7 +198,7 @@ void DPolyAction::SetInterpolation () void DPolyAction::StopInterpolation () { - polyobj_t *poly = GetPolyobj (m_PolyObj); + FPolyObj *poly = GetPolyobj (m_PolyObj); for (int i = 0; i < poly->numsegs; ++i) { stopinterpolation (INTERP_Vertex, poly->segs[i]->v1); @@ -196,7 +274,7 @@ void DRotatePoly::Tick () m_Dist -= absSpeed; if (m_Dist == 0) { - polyobj_t *poly = GetPolyobj (m_PolyObj); + FPolyObj *poly = GetPolyobj (m_PolyObj); if (poly->specialdata == this) { poly->specialdata = NULL; @@ -223,7 +301,7 @@ bool EV_RotatePoly (line_t *line, int polyNum, int speed, int byteAngle, { int mirror; DRotatePoly *pe; - polyobj_t *poly; + FPolyObj *poly; if ( (poly = GetPolyobj(polyNum)) ) { @@ -300,7 +378,7 @@ bool EV_RotatePoly (line_t *line, int polyNum, int speed, int byteAngle, void DMovePoly::Tick () { - polyobj_t *poly; + FPolyObj *poly; if (PO_MovePolyobj (m_PolyObj, m_xSpeed, m_ySpeed)) { @@ -336,7 +414,7 @@ bool EV_MovePoly (line_t *line, int polyNum, int speed, angle_t angle, { int mirror; DMovePoly *pe; - polyobj_t *poly; + FPolyObj *poly; angle_t an; if ( (poly = GetPolyobj(polyNum)) ) @@ -405,7 +483,7 @@ bool EV_MovePoly (line_t *line, int polyNum, int speed, angle_t angle, void DPolyDoor::Tick () { int absSpeed; - polyobj_t *poly; + FPolyObj *poly; if (m_Tics) { @@ -530,7 +608,7 @@ bool EV_OpenPolyDoor (line_t *line, int polyNum, int speed, angle_t angle, { int mirror; DPolyDoor *pd; - polyobj_t *poly; + FPolyObj *poly; if( (poly = GetPolyobj(polyNum)) ) { @@ -605,7 +683,7 @@ bool EV_OpenPolyDoor (line_t *line, int polyNum, int speed, angle_t angle, // //========================================================================== -static polyobj_t *GetPolyobj (int polyNum) +static FPolyObj *GetPolyobj (int polyNum) { int i; @@ -645,7 +723,7 @@ static int GetPolyobjMirror(int poly) // //========================================================================== -void ThrustMobj (AActor *actor, seg_t *seg, polyobj_t *po) +void ThrustMobj (AActor *actor, seg_t *seg, FPolyObj *po) { int thrustAngle; int thrustX; @@ -759,7 +837,7 @@ static void UpdateSegBBox (seg_t *seg) bool PO_MovePolyobj (int num, int x, int y, bool force) { - polyobj_t *po; + FPolyObj *po; if (!(po = GetPolyobj (num))) { @@ -801,7 +879,7 @@ bool PO_MovePolyobj (int num, int x, int y, bool force) // //========================================================================== -void DoMovePolyobj (polyobj_t *po, int x, int y) +void DoMovePolyobj (FPolyObj *po, int x, int y) { int count; seg_t **segList; @@ -868,7 +946,7 @@ bool PO_RotatePolyobj (int num, angle_t angle) vertex_t *originalPts; vertex_t *prevPts; int an; - polyobj_t *po; + FPolyObj *po; bool blocked; if(!(po = GetPolyobj(num))) @@ -941,7 +1019,7 @@ bool PO_RotatePolyobj (int num, angle_t angle) // //========================================================================== -static void UnLinkPolyobj (polyobj_t *po) +static void UnLinkPolyobj (FPolyObj *po) { polyblock_t *link; int i, j; @@ -976,7 +1054,7 @@ static void UnLinkPolyobj (polyobj_t *po) // //========================================================================== -static void LinkPolyobj (polyobj_t *po) +static void LinkPolyobj (FPolyObj *po) { int leftX, rightX; int topY, bottomY; @@ -1062,7 +1140,7 @@ static void LinkPolyobj (polyobj_t *po) // //========================================================================== -static bool CheckMobjBlocking (seg_t *seg, polyobj_t *po) +static bool CheckMobjBlocking (seg_t *seg, FPolyObj *po) { static TArray checker; FBlockNode *block; @@ -1388,7 +1466,7 @@ static void TranslateToStartSpot (int tag, int originX, int originY) seg_t **veryTempSeg; vertex_t *tempPt; subsector_t *sub; - polyobj_t *po; + FPolyObj *po; int deltaX; int deltaY; vertex_t avg; // used to find a polyobj's center, and hence subsector @@ -1480,8 +1558,8 @@ void PO_Init (void) // [RH] Make this faster InitSegLists (); - polyobjs = new polyobj_t[po_NumPolyobjs]; - memset (polyobjs, 0, po_NumPolyobjs*sizeof(polyobj_t)); + polyobjs = new FPolyObj[po_NumPolyobjs]; + memset (polyobjs, 0, po_NumPolyobjs*sizeof(FPolyObj)); polyIndex = 0; // index polyobj number // Find the startSpot points, and spawn each polyobj @@ -1539,7 +1617,7 @@ void PO_Init (void) bool PO_Busy (int polyobj) { - polyobj_t *poly; + FPolyObj *poly; poly = GetPolyobj (polyobj); if (poly == NULL || poly->specialdata == NULL) diff --git a/src/r_data.h b/src/r_data.h index 890061314..3ad6adc77 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -42,446 +42,6 @@ public: void SetSize (int width, int height); }; - -// A texture that is just a single patch -class FPatchTexture : public FTexture -{ -public: - ~FPatchTexture (); - - const BYTE *GetColumn (unsigned int column, const Span **spans_out); - const BYTE *GetPixels (); - void Unload (); - - int GetSourceLump() { return SourceLump; } - -protected: - int SourceLump; - BYTE *Pixels; - Span **Spans; - bool hackflag; - - static bool Check(FileReader & file); - static FTexture *Create(FileReader & file, int lumpnum); - FPatchTexture (int lumpnum, patch_t *header); - - virtual void MakeTexture (); - void HackHack (int newheight); - - friend class FTexture; - friend class FMultiPatchTexture; -}; - -// In-memory representation of a single PNAMES lump entry -struct FPatchLookup -{ - char Name[9]; - FTexture *Texture; -}; - -// A texture defined in a TEXTURE1 or TEXTURE2 lump -class FMultiPatchTexture : public FTexture -{ -public: - FMultiPatchTexture (const void *texdef, FPatchLookup *patchlookup, int maxpatchnum, bool strife, int deflump); - FMultiPatchTexture (FScanner &sc, int usetype); - ~FMultiPatchTexture (); - - const BYTE *GetColumn (unsigned int column, const Span **spans_out); - const BYTE *GetPixels (); - FTextureFormat GetFormat(); - bool UseBasePalette() ; - void Unload (); - virtual void SetFrontSkyLayer (); - - int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL); - int GetSourceLump() { return DefinitionLump; } - -protected: - BYTE *Pixels; - Span **Spans; - int DefinitionLump; - - struct TexPart - { - SWORD OriginX, OriginY; - BYTE Rotate; - bool textureOwned; - BYTE op; - FRemapTable *Translation; - PalEntry Blend; - FTexture *Texture; - fixed_t Alpha; - - TexPart(); - }; - - int NumParts; - TexPart *Parts; - bool bRedirect:1; - bool bTranslucentPatches:1; - - void MakeTexture (); - -private: - void CheckForHacks (); - void ParsePatch(FScanner &sc, TexPart & part); -}; - -// A texture defined between F_START and F_END markers -class FFlatTexture : public FTexture -{ -public: - ~FFlatTexture (); - - const BYTE *GetColumn (unsigned int column, const Span **spans_out); - const BYTE *GetPixels (); - void Unload (); - - int GetSourceLump() { return SourceLump; } - -protected: - int SourceLump; - BYTE *Pixels; - Span DummySpans[2]; - - static bool Check(FileReader & file); - static FTexture *Create(FileReader & file, int lumpnum); - FFlatTexture (int lumpnum); - - void MakeTexture (); - - friend class FTexture; -}; - -// A texture defined in a Build TILESxxx.ART file -class FBuildTexture : public FTexture -{ -public: - FBuildTexture (int tilenum, const BYTE *pixels, int width, int height, int left, int top); - ~FBuildTexture (); - - const BYTE *GetColumn (unsigned int column, const Span **spans_out); - const BYTE *GetPixels (); - void Unload (); - -protected: - const BYTE *Pixels; - Span **Spans; -}; - - -// A raw 320x200 graphic used by Heretic and Hexen fullscreen images -class FRawPageTexture : public FTexture -{ -public: - ~FRawPageTexture (); - - const BYTE *GetColumn (unsigned int column, const Span **spans_out); - const BYTE *GetPixels (); - void Unload (); - - int GetSourceLump() { return SourceLump; } - -protected: - static bool Check(FileReader & file); - static FTexture *Create(FileReader & file, int lumpnum); - FRawPageTexture (int lumpnum); - - int SourceLump; - BYTE *Pixels; - static const Span DummySpans[2]; - - void MakeTexture (); - - friend class FTexture; -}; - -// A raw 320x? graphic used by Heretic and Hexen for the automap parchment -class FAutomapTexture : public FTexture -{ -public: - ~FAutomapTexture (); - - const BYTE *GetColumn (unsigned int column, const Span **spans_out); - const BYTE *GetPixels (); - void Unload (); - void MakeTexture (); - - int GetSourceLump() { return LumpNum; } - -private: - - static bool Check(FileReader & file); - static FTexture *Create(FileReader & file, int lumpnum); - FAutomapTexture (int lumpnum); - - - BYTE *Pixels; - Span DummySpan[2]; - int LumpNum; - - friend class FTexture; -}; - - - -// An IMGZ image (mostly just crosshairs) -class FIMGZTexture : public FTexture -{ -public: - ~FIMGZTexture (); - - const BYTE *GetColumn (unsigned int column, const Span **spans_out); - const BYTE *GetPixels (); - void Unload (); - - int GetSourceLump() { return SourceLump; } - -protected: - - static bool Check(FileReader & file); - static FTexture *Create(FileReader & file, int lumpnum); - FIMGZTexture (int lumpnum, WORD w, WORD h, SWORD l, SWORD t); - - int SourceLump; - BYTE *Pixels; - Span **Spans; - - void MakeTexture (); - - struct ImageHeader; - friend class FTexture; -}; - - -// A PNG image -class FPNGTexture : public FTexture -{ -public: - ~FPNGTexture (); - - const BYTE *GetColumn (unsigned int column, const Span **spans_out); - const BYTE *GetPixels (); - void Unload (); - FTextureFormat GetFormat (); - int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL); - bool UseBasePalette(); - int GetSourceLump() { return SourceLump; } - - static FTexture *CreateFromFile (PNGHandle *png, const FString &filename); - -protected: - static bool Check (FileReader &file); - static FTexture *Create (FileReader &file, int lumpnum); - FPNGTexture (FileReader &lump, int lumpnum, const FString &filename, int width, int height, BYTE bitdepth, BYTE colortype, BYTE interlace); - - int SourceLump; - FString SourceFile; - BYTE *Pixels; - Span **Spans; - - BYTE BitDepth; - BYTE ColorType; - BYTE Interlace; - - BYTE *PaletteMap; - int PaletteSize; - DWORD StartOfIDAT; - - void MakeTexture (); - - friend class FTexture; -}; - - -// A DDS image, with DXTx compression -class FDDSTexture : public FTexture -{ -public: - ~FDDSTexture (); - - const BYTE *GetColumn (unsigned int column, const Span **spans_out); - const BYTE *GetPixels (); - void Unload (); - FTextureFormat GetFormat (); - int GetSourceLump() { return SourceLump; } - -protected: - static bool Check (FileReader &file); - static FTexture *Create (FileReader &file, int lumpnum); - FDDSTexture (FileReader &lump, int lumpnum, void *surfdesc); - - int SourceLump; - BYTE *Pixels; - Span **Spans; - - DWORD Format; - - DWORD RMask, GMask, BMask, AMask; - BYTE RShiftL, GShiftL, BShiftL, AShiftL; - BYTE RShiftR, GShiftR, BShiftR, AShiftR; - - SDWORD Pitch; - DWORD LinearSize; - - static void CalcBitShift (DWORD mask, BYTE *lshift, BYTE *rshift); - - void MakeTexture (); - void ReadRGB (FWadLump &lump, BYTE *tcbuf = NULL); - void DecompressDXT1 (FWadLump &lump, BYTE *tcbuf = NULL); - void DecompressDXT3 (FWadLump &lump, bool premultiplied, BYTE *tcbuf = NULL); - void DecompressDXT5 (FWadLump &lump, bool premultiplied, BYTE *tcbuf = NULL); - - int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL); - bool UseBasePalette(); - - friend class FTexture; -}; - -// A JPEG image -class FJPEGTexture : public FTexture -{ -public: - ~FJPEGTexture (); - - const BYTE *GetColumn (unsigned int column, const Span **spans_out); - const BYTE *GetPixels (); - void Unload (); - FTextureFormat GetFormat (); - int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL); - bool UseBasePalette(); - int GetSourceLump() { return SourceLump; } - -protected: - - static bool Check (FileReader &file); - static FTexture *Create (FileReader &file, int lumpnum); - FJPEGTexture (int lumpnum, int width, int height); - - int SourceLump; - BYTE *Pixels; - Span DummySpans[2]; - - void MakeTexture (); - - friend class FTexture; -}; - -// A TGA texture - -#pragma pack(1) - -struct TGAHeader -{ - BYTE id_len; - BYTE has_cm; - BYTE img_type; - SWORD cm_first; - SWORD cm_length; - BYTE cm_size; - - SWORD x_origin; - SWORD y_origin; - SWORD width; - SWORD height; - BYTE bpp; - BYTE img_desc; -}; - -#pragma pack() - -class FTGATexture : public FTexture -{ -public: - ~FTGATexture (); - - const BYTE *GetColumn (unsigned int column, const Span **spans_out); - const BYTE *GetPixels (); - void Unload (); - FTextureFormat GetFormat (); - - int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL); - bool UseBasePalette(); - int GetSourceLump() { return SourceLump; } - -protected: - int SourceLump; - BYTE *Pixels; - Span **Spans; - - static bool Check(FileReader & file); - static FTexture *Create(FileReader & file, int lumpnum); - FTGATexture (int lumpnum, TGAHeader *); - void ReadCompressed(FileReader &lump, BYTE * buffer, int bytesperpixel); - - virtual void MakeTexture (); - - friend class FTexture; -}; - -// A PCX texture - -#pragma pack(1) - -struct PCXHeader -{ - BYTE manufacturer; - BYTE version; - BYTE encoding; - BYTE bitsPerPixel; - - WORD xmin, ymin; - WORD xmax, ymax; - WORD horzRes, vertRes; - - BYTE palette[48]; - BYTE reserved; - BYTE numColorPlanes; - - WORD bytesPerScanLine; - WORD paletteType; - WORD horzSize, vertSize; - - BYTE padding[54]; - -}; -#pragma pack() - -class FPCXTexture : public FTexture -{ -public: - ~FPCXTexture (); - - const BYTE *GetColumn (unsigned int column, const Span **spans_out); - const BYTE *GetPixels (); - void Unload (); - FTextureFormat GetFormat (); - - int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL); - bool UseBasePalette(); - int GetSourceLump() { return SourceLump; } - -protected: - int SourceLump; - BYTE *Pixels; - Span DummySpans[2]; - - static bool Check(FileReader & file); - static FTexture *Create(FileReader & file, int lumpnum); - FPCXTexture (int lumpnum, PCXHeader &); - void ReadPCX1bit (BYTE *dst, FileReader & lump, PCXHeader *hdr); - void ReadPCX4bits (BYTE *dst, FileReader & lump, PCXHeader *hdr); - void ReadPCX8bits (BYTE *dst, FileReader & lump, PCXHeader *hdr); - void ReadPCX24bits (BYTE *dst, FileReader & lump, PCXHeader *hdr, int planes); - - virtual void MakeTexture (); - - friend class FTexture; -}; - - - // A texture that returns a wiggly version of another texture. class FWarpTexture : public FTexture { diff --git a/src/r_defs.h b/src/r_defs.h index eb4fec1b6..157c8826c 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -417,7 +417,7 @@ struct sector_t // list of mobjs that are at least partially in the sector // thinglist is a subset of touching_thinglist - struct msecnode_s *touching_thinglist; // phares 3/14/98 + struct msecnode_t *touching_thinglist; // phares 3/14/98 float gravity; // [RH] Sector gravity (1.0 is normal) short damage; // [RH] Damage to do while standing on floor @@ -600,16 +600,16 @@ struct line_t // // For the links, NULL means top or end of list. -typedef struct msecnode_s +struct msecnode_t { sector_t *m_sector; // a sector containing this object AActor *m_thing; // this object - struct msecnode_s *m_tprev; // prev msecnode_t for this thing - struct msecnode_s *m_tnext; // next msecnode_t for this thing - struct msecnode_s *m_sprev; // prev msecnode_t for this sector - struct msecnode_s *m_snext; // next msecnode_t for this sector + struct msecnode_t *m_tprev; // prev msecnode_t for this thing + struct msecnode_t *m_tnext; // next msecnode_t for this thing + struct msecnode_t *m_sprev; // prev msecnode_t for this sector + struct msecnode_t *m_snext; // next msecnode_t for this sector bool visited; // killough 4/4/98, 4/7/98: used in search algorithms -} msecnode_t; +}; // // A SubSector. @@ -618,7 +618,7 @@ typedef struct msecnode_s // define (all or some) sides of a convex BSP leaf. // struct FPolyObj; -typedef struct subsector_s +struct subsector_t { sector_t *sector; DWORD numlines; @@ -626,12 +626,12 @@ typedef struct subsector_s FPolyObj *poly; int validcount; fixed_t CenterX, CenterY; -} subsector_t; +}; // // The LineSeg. // -struct seg_s +struct seg_t { vertex_t* v1; vertex_t* v2; @@ -644,14 +644,13 @@ struct seg_s sector_t* backsector; // NULL for one-sided lines subsector_t* Subsector; - seg_s* PartnerSeg; + seg_t* PartnerSeg; BITFIELD bPolySeg:1; }; -typedef struct seg_s seg_t; // ===== Polyobj data ===== -typedef struct FPolyObj +struct FPolyObj { int numsegs; seg_t **segs; @@ -667,12 +666,12 @@ typedef struct FPolyObj int seqType; fixed_t size; // polyobj size (area of POLY_AREAUNIT == size of FRACUNIT) DThinker *specialdata; // pointer to a thinker, if the poly is moving -} polyobj_t; +}; // // BSP node. // -struct node_s +struct node_t { // Partition line. fixed_t x; @@ -686,28 +685,23 @@ struct node_s int intchildren[2]; // Used by nodebuilder. }; }; -typedef struct node_s node_t; -typedef struct polyblock_s +struct polyblock_t { - polyobj_t *polyobj; - struct polyblock_s *prev; - struct polyblock_s *next; -} polyblock_t; + FPolyObj *polyobj; + struct polyblock_t *prev; + struct polyblock_t *next; +}; // posts are runs of non masked source pixels -struct post_s +struct column_t { BYTE topdelta; // -1 is the last post in a column BYTE length; // length data bytes follows }; -typedef struct post_s post_t; - -// column_t is a list of 0 or more post_t, (byte)-1 terminated -typedef post_t column_t; @@ -773,7 +767,6 @@ public: BYTE bAlphaTexture:1; // Texture is an alpha channel without color information BYTE bHasCanvas:1; // Texture is based off FCanvasTexture BYTE bWarped:2; // This is a warped texture. Used to avoid multiple warps on one texture - BYTE bIsPatch:1; // 1 if an FPatchTexture. Required to fix FMultipatchTexture::CheckForHacks BYTE bComplex:1; // Will be used to mark extended MultipatchTextures that have to be // fully composited before subjected to any kinf of postprocessing instead of // doing it per patch. @@ -876,6 +869,8 @@ public: if (MulScale16(yScale, fitheight) != Height) yScale++; } + void HackHack (int newheight); // called by FMultipatchTexture to discover corrupt patches. + protected: WORD Width, Height, WidthMask; static BYTE GrayMap[256]; diff --git a/src/r_draw.cpp b/src/r_draw.cpp index 3ec52210a..a59888a59 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -153,6 +153,8 @@ const FRenderStyle LegacyRenderStyles[STYLE_Count] = /* STYLE_TranslucentStencil */{{ STYLEOP_Add, STYLEALPHA_Src, STYLEALPHA_InvSrc, STYLEF_ColorIsFixed }}, }; +EXTERN_CVAR (Int, r_columnmethod) + /************************************/ /* */ /* Palettized drawers (C versions) */ diff --git a/src/r_segs.h b/src/r_segs.h index 4dbca84a4..f92663ee0 100644 --- a/src/r_segs.h +++ b/src/r_segs.h @@ -23,8 +23,6 @@ #ifndef __R_SEGS_H__ #define __R_SEGS_H__ -#include "c_cvars.h" - void R_RenderMaskedSegRange (drawseg_t *ds, int x1, int x2); extern short *openings; @@ -41,9 +39,6 @@ inline ptrdiff_t R_NewOpening (ptrdiff_t len) void R_CheckOpenings (size_t need); void R_CheckDrawSegs (); -// [RH] Selects how to draw masked columns. -EXTERN_CVAR (Int, r_columnmethod) - void R_RenderSegLoop (); #endif diff --git a/src/r_sky.h b/src/r_sky.h index 675385d4e..f266632b1 100644 --- a/src/r_sky.h +++ b/src/r_sky.h @@ -22,8 +22,6 @@ #ifndef __R_SKY_H__ #define __R_SKY_H__ -#include "c_cvars.h" - extern int sky1shift, sky2shift; extern int sky1texture, sky2texture; @@ -34,8 +32,6 @@ extern fixed_t skyiscale; extern fixed_t skyscale; extern fixed_t skyheight; -EXTERN_CVAR (Bool, r_stretchsky) - // Called whenever the sky changes. void R_InitSkyMap (); diff --git a/src/s_sndseq.cpp b/src/s_sndseq.cpp index e487c9d54..8fcf446e2 100644 --- a/src/s_sndseq.cpp +++ b/src/s_sndseq.cpp @@ -115,7 +115,7 @@ class DSeqPolyNode : public DSeqNode { DECLARE_CLASS (DSeqPolyNode, DSeqNode) public: - DSeqPolyNode (polyobj_t *poly, int sequence, int modenum); + DSeqPolyNode (FPolyObj *poly, int sequence, int modenum); void Destroy (); void Serialize (FArchive &arc); void MakeSound (int loop) { S_SoundID (&m_Poly->startSpot[0], CHAN_BODY|loop, m_CurrentSoundID, clamp(m_Volume, 0.f, 1.f), m_Atten); } @@ -124,7 +124,7 @@ public: DSeqNode *SpawnChild (int seqnum) { return SN_StartSequence (m_Poly, seqnum, SEQ_NOTRANS, m_ModeNum, true); } private: DSeqPolyNode () {} - polyobj_t *m_Poly; + FPolyObj *m_Poly; }; class DSeqSectorNode : public DSeqNode @@ -747,7 +747,7 @@ DSeqActorNode::DSeqActorNode (AActor *actor, int sequence, int modenum) { } -DSeqPolyNode::DSeqPolyNode (polyobj_t *poly, int sequence, int modenum) +DSeqPolyNode::DSeqPolyNode (FPolyObj *poly, int sequence, int modenum) : DSeqNode (sequence, modenum), m_Poly (poly) { @@ -815,7 +815,7 @@ DSeqNode *SN_StartSequence (sector_t *sector, int sequence, seqtype_t type, int return NULL; } -DSeqNode *SN_StartSequence (polyobj_t *poly, int sequence, seqtype_t type, int modenum, bool nostop) +DSeqNode *SN_StartSequence (FPolyObj *poly, int sequence, seqtype_t type, int modenum, bool nostop) { if (!nostop) { @@ -864,7 +864,7 @@ DSeqNode *SN_StartSequence (sector_t *sec, const char *seqname, int modenum, boo return NULL; } -DSeqNode *SN_StartSequence (polyobj_t *poly, const char *seqname, int modenum) +DSeqNode *SN_StartSequence (FPolyObj *poly, const char *seqname, int modenum) { int seqnum = FindSequence (seqname); if (seqnum >= 0) @@ -915,7 +915,7 @@ void SN_StopSequence (sector_t *sector) SN_DoStop (sector); } -void SN_StopSequence (polyobj_t *poly) +void SN_StopSequence (FPolyObj *poly) { SN_DoStop (poly); } diff --git a/src/s_sndseq.h b/src/s_sndseq.h index 0395e2843..77625cd57 100644 --- a/src/s_sndseq.h +++ b/src/s_sndseq.h @@ -85,11 +85,11 @@ DSeqNode *SN_StartSequence (AActor *mobj, const char *name, int modenum); DSeqNode *SN_StartSequence (AActor *mobj, FName seqname, int modenum); DSeqNode *SN_StartSequence (sector_t *sector, int sequence, seqtype_t type, int modenum, bool full3d, bool nostop=false); DSeqNode *SN_StartSequence (sector_t *sector, const char *name, int modenum, bool full3d); -DSeqNode *SN_StartSequence (polyobj_t *poly, int sequence, seqtype_t type, int modenum, bool nostop=false); -DSeqNode *SN_StartSequence (polyobj_t *poly, const char *name, int modenum); +DSeqNode *SN_StartSequence (FPolyObj *poly, int sequence, seqtype_t type, int modenum, bool nostop=false); +DSeqNode *SN_StartSequence (FPolyObj *poly, const char *name, int modenum); void SN_StopSequence (AActor *mobj); void SN_StopSequence (sector_t *sector); -void SN_StopSequence (polyobj_t *poly); +void SN_StopSequence (FPolyObj *poly); void SN_UpdateActiveSequences (void); ptrdiff_t SN_GetSequenceOffset (int sequence, SDWORD *sequencePtr); void SN_DoStop (void *); diff --git a/src/textures/automaptexture.cpp b/src/textures/automaptexture.cpp index 519df2648..5980aaa38 100644 --- a/src/textures/automaptexture.cpp +++ b/src/textures/automaptexture.cpp @@ -40,17 +40,52 @@ #include "r_data.h" #include "w_wad.h" -bool FAutomapTexture::Check(FileReader & data) -{ - if (data.GetLength() < 320) return false; - return true; -} +//========================================================================== +// +// A raw 320x? graphic used by Heretic and Hexen for the automap parchment +// +//========================================================================== -FTexture *FAutomapTexture::Create(FileReader &, int lumpnum) +class FAutomapTexture : public FTexture { +public: + ~FAutomapTexture (); + + const BYTE *GetColumn (unsigned int column, const Span **spans_out); + const BYTE *GetPixels (); + void Unload (); + void MakeTexture (); + + int GetSourceLump() { return LumpNum; } + + FAutomapTexture (int lumpnum); + +private: + BYTE *Pixels; + Span DummySpan[2]; + int LumpNum; +}; + + + +//========================================================================== +// +// +// +//========================================================================== + +FTexture *AutomapTexture_TryCreate(FileReader &data, int lumpnum) +{ + if (data.GetLength() < 320) return NULL; return new FAutomapTexture(lumpnum); } +//========================================================================== +// +// +// +//========================================================================== + FAutomapTexture::FAutomapTexture (int lumpnum) : Pixels(NULL), LumpNum(lumpnum) { @@ -64,11 +99,23 @@ FAutomapTexture::FAutomapTexture (int lumpnum) DummySpan[1].Length = 0; } +//========================================================================== +// +// +// +//========================================================================== + FAutomapTexture::~FAutomapTexture () { Unload (); } +//========================================================================== +// +// +// +//========================================================================== + void FAutomapTexture::Unload () { if (Pixels != NULL) @@ -78,6 +125,12 @@ void FAutomapTexture::Unload () } } +//========================================================================== +// +// +// +//========================================================================== + void FAutomapTexture::MakeTexture () { int x, y; @@ -95,6 +148,12 @@ void FAutomapTexture::MakeTexture () } } +//========================================================================== +// +// +// +//========================================================================== + const BYTE *FAutomapTexture::GetPixels () { if (Pixels == NULL) @@ -104,6 +163,12 @@ const BYTE *FAutomapTexture::GetPixels () return Pixels; } +//========================================================================== +// +// +// +//========================================================================== + const BYTE *FAutomapTexture::GetColumn (unsigned int column, const Span **spans_out) { if (Pixels == NULL) diff --git a/src/textures/buildtexture.cpp b/src/textures/buildtexture.cpp index 330aca51d..68cf7f04e 100644 --- a/src/textures/buildtexture.cpp +++ b/src/textures/buildtexture.cpp @@ -43,6 +43,34 @@ static TArray BuildTileFiles; +//========================================================================== +// +// A texture defined in a Build TILESxxx.ART file +// +//========================================================================== + +class FBuildTexture : public FTexture +{ +public: + FBuildTexture (int tilenum, const BYTE *pixels, int width, int height, int left, int top); + ~FBuildTexture (); + + const BYTE *GetColumn (unsigned int column, const Span **spans_out); + const BYTE *GetPixels (); + void Unload (); + +protected: + const BYTE *Pixels; + Span **Spans; +}; + + +//========================================================================== +// +// +// +//========================================================================== + FBuildTexture::FBuildTexture (int tilenum, const BYTE *pixels, int width, int height, int left, int top) : Pixels (pixels), Spans (NULL) { @@ -55,6 +83,12 @@ FBuildTexture::FBuildTexture (int tilenum, const BYTE *pixels, int width, int he UseType = TEX_Build; } +//========================================================================== +// +// +// +//========================================================================== + FBuildTexture::~FBuildTexture () { if (Spans != NULL) @@ -64,16 +98,34 @@ FBuildTexture::~FBuildTexture () } } +//========================================================================== +// +// +// +//========================================================================== + void FBuildTexture::Unload () { // Nothing to do, since the pixels are accessed from memory-mapped files directly } +//========================================================================== +// +// +// +//========================================================================== + const BYTE *FBuildTexture::GetPixels () { return Pixels; } +//========================================================================== +// +// +// +//========================================================================== + const BYTE *FBuildTexture::GetColumn (unsigned int column, const Span **spans_out) { if (column >= Width) diff --git a/src/textures/ddstexture.cpp b/src/textures/ddstexture.cpp index 76ee6759d..ec268b9e9 100644 --- a/src/textures/ddstexture.cpp +++ b/src/textures/ddstexture.cpp @@ -95,6 +95,12 @@ #define DDSCAPS2_CUBEMAP_NEGATIZEZ 0x00008000 #define DDSCAPS2_VOLUME 0x00200000 +//========================================================================== +// +// +// +//========================================================================== + struct DDPIXELFORMAT { DWORD Size; // Must be 32 @@ -136,7 +142,62 @@ struct DDSFileHeader DDSURFACEDESC2 Desc; }; -bool FDDSTexture::Check (FileReader &file) + +//========================================================================== +// +// A DDS image, with DXTx compression +// +//========================================================================== + +class FDDSTexture : public FTexture +{ +public: + FDDSTexture (FileReader &lump, int lumpnum, void *surfdesc); + ~FDDSTexture (); + + const BYTE *GetColumn (unsigned int column, const Span **spans_out); + const BYTE *GetPixels (); + void Unload (); + FTextureFormat GetFormat (); + int GetSourceLump() { return SourceLump; } + +protected: + + int SourceLump; + BYTE *Pixels; + Span **Spans; + + DWORD Format; + + DWORD RMask, GMask, BMask, AMask; + BYTE RShiftL, GShiftL, BShiftL, AShiftL; + BYTE RShiftR, GShiftR, BShiftR, AShiftR; + + SDWORD Pitch; + DWORD LinearSize; + + static void CalcBitShift (DWORD mask, BYTE *lshift, BYTE *rshift); + + void MakeTexture (); + void ReadRGB (FWadLump &lump, BYTE *tcbuf = NULL); + void DecompressDXT1 (FWadLump &lump, BYTE *tcbuf = NULL); + void DecompressDXT3 (FWadLump &lump, bool premultiplied, BYTE *tcbuf = NULL); + void DecompressDXT5 (FWadLump &lump, bool premultiplied, BYTE *tcbuf = NULL); + + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL); + bool UseBasePalette(); + + friend class FTexture; +}; + + +//========================================================================== +// +// +// +//========================================================================== + +static bool CheckDDS (FileReader &file) { DDSFileHeader Header; @@ -153,7 +214,13 @@ bool FDDSTexture::Check (FileReader &file) Header.Desc.Height != 0; } -FTexture *FDDSTexture::Create (FileReader &data, int lumpnum) +//========================================================================== +// +// +// +//========================================================================== + +FTexture *DDSTexture_TryCreate (FileReader &data, int lumpnum) { union { @@ -161,6 +228,8 @@ FTexture *FDDSTexture::Create (FileReader &data, int lumpnum) DWORD byteswapping[sizeof(DDSURFACEDESC2) / 4]; }; + if (!CheckDDS(data)) return NULL; + data.Seek (4, SEEK_SET); data.Read (&surfdesc, sizeof(surfdesc)); @@ -209,6 +278,12 @@ FTexture *FDDSTexture::Create (FileReader &data, int lumpnum) return new FDDSTexture (data, lumpnum, &surfdesc); } +//========================================================================== +// +// +// +//========================================================================== + FDDSTexture::FDDSTexture (FileReader &lump, int lumpnum, void *vsurfdesc) : SourceLump(lumpnum), Pixels(0), Spans(0) { @@ -259,6 +334,8 @@ FDDSTexture::FDDSTexture (FileReader &lump, int lumpnum, void *vsurfdesc) } } +//========================================================================== +// // Returns the number of bits the color must be shifted to produce // an 8-bit value, as in: // @@ -269,6 +346,9 @@ FDDSTexture::FDDSTexture (FileReader &lump, int lumpnum, void *vsurfdesc) // For any color of at least 4 bits, this ensures that the result // of the calculation for c will be fully saturated, given a maximum // value for the input bit mask. +// +//========================================================================== + void FDDSTexture::CalcBitShift (DWORD mask, BYTE *lshiftp, BYTE *rshiftp) { BYTE shift; @@ -296,6 +376,12 @@ void FDDSTexture::CalcBitShift (DWORD mask, BYTE *lshiftp, BYTE *rshiftp) *rshiftp = shift; } +//========================================================================== +// +// +// +//========================================================================== + FDDSTexture::~FDDSTexture () { Unload (); @@ -306,6 +392,12 @@ FDDSTexture::~FDDSTexture () } } +//========================================================================== +// +// +// +//========================================================================== + void FDDSTexture::Unload () { if (Pixels != NULL) @@ -315,6 +407,12 @@ void FDDSTexture::Unload () } } +//========================================================================== +// +// +// +//========================================================================== + FTextureFormat FDDSTexture::GetFormat() { #if 0 @@ -333,6 +431,12 @@ FTextureFormat FDDSTexture::GetFormat() #endif } +//========================================================================== +// +// +// +//========================================================================== + const BYTE *FDDSTexture::GetColumn (unsigned int column, const Span **spans_out) { if (Pixels == NULL) @@ -361,6 +465,12 @@ const BYTE *FDDSTexture::GetColumn (unsigned int column, const Span **spans_out) return Pixels + column*Height; } +//========================================================================== +// +// +// +//========================================================================== + const BYTE *FDDSTexture::GetPixels () { if (Pixels == NULL) @@ -370,6 +480,12 @@ const BYTE *FDDSTexture::GetPixels () return Pixels; } +//========================================================================== +// +// +// +//========================================================================== + void FDDSTexture::MakeTexture () { FWadLump lump = Wads.OpenLumpNum (SourceLump); @@ -396,6 +512,12 @@ void FDDSTexture::MakeTexture () } } +//========================================================================== +// +// +// +//========================================================================== + void FDDSTexture::ReadRGB (FWadLump &lump, BYTE *tcbuf) { DWORD x, y; @@ -459,6 +581,12 @@ void FDDSTexture::ReadRGB (FWadLump &lump, BYTE *tcbuf) delete[] linebuff; } +//========================================================================== +// +// +// +//========================================================================== + void FDDSTexture::DecompressDXT1 (FWadLump &lump, BYTE *tcbuf) { const long blocklinelen = ((Width + 3) >> 2) << 3; @@ -550,8 +678,12 @@ void FDDSTexture::DecompressDXT1 (FWadLump &lump, BYTE *tcbuf) delete[] blockbuff; } +//========================================================================== +// // DXT3: Decompression is identical to DXT1, except every 64-bit block is // preceded by another 64-bit block with explicit alpha values. +// +//========================================================================== void FDDSTexture::DecompressDXT3 (FWadLump &lump, bool premultiplied, BYTE *tcbuf) { @@ -628,8 +760,12 @@ void FDDSTexture::DecompressDXT3 (FWadLump &lump, bool premultiplied, BYTE *tcbu delete[] blockbuff; } +//========================================================================== +// // DXT5: Decompression is identical to DXT3, except every 64-bit alpha block // contains interpolated alpha values, similar to the 64-bit color block. +// +//========================================================================== void FDDSTexture::DecompressDXT5 (FWadLump &lump, bool premultiplied, BYTE *tcbuf) { diff --git a/src/textures/flattexture.cpp b/src/textures/flattexture.cpp index 271c47119..b63823979 100644 --- a/src/textures/flattexture.cpp +++ b/src/textures/flattexture.cpp @@ -38,17 +38,55 @@ #include "r_data.h" #include "w_wad.h" +//========================================================================== +// +// A texture defined between F_START and F_END markers +// +//========================================================================== -bool FFlatTexture::Check(FileReader & file) +class FFlatTexture : public FTexture { - return true; -} +public: + FFlatTexture (int lumpnum); + ~FFlatTexture (); -FTexture *FFlatTexture::Create(FileReader & file, int lumpnum) + const BYTE *GetColumn (unsigned int column, const Span **spans_out); + const BYTE *GetPixels (); + void Unload (); + + int GetSourceLump() { return SourceLump; } + +protected: + int SourceLump; + BYTE *Pixels; + Span DummySpans[2]; + + + void MakeTexture (); + + friend class FTexture; +}; + + + +//========================================================================== +// +// Since there is no way to detect the validity of a flat +// they can't be used anywhere else but between F_START and F_END +// +//========================================================================== + +FTexture *FlatTexture_TryCreate(FileReader & file, int lumpnum) { return new FFlatTexture(lumpnum); } +//========================================================================== +// +// +// +//========================================================================== + FFlatTexture::FFlatTexture (int lumpnum) : SourceLump(lumpnum), Pixels(0) { @@ -78,24 +116,25 @@ FFlatTexture::FFlatTexture (int lumpnum) DummySpans[0].Length = Height; DummySpans[1].TopOffset = 0; DummySpans[1].Length = 0; - - /* - if (bits > 6) - { - ScaleX = ScaleY = 8 << (bits - 6); - } - else - { - ScaleX = ScaleY = 8; - } - */ } +//========================================================================== +// +// +// +//========================================================================== + FFlatTexture::~FFlatTexture () { Unload (); } +//========================================================================== +// +// +// +//========================================================================== + void FFlatTexture::Unload () { if (Pixels != NULL) @@ -105,6 +144,12 @@ void FFlatTexture::Unload () } } +//========================================================================== +// +// +// +//========================================================================== + const BYTE *FFlatTexture::GetColumn (unsigned int column, const Span **spans_out) { if (Pixels == NULL) @@ -129,6 +174,12 @@ const BYTE *FFlatTexture::GetColumn (unsigned int column, const Span **spans_out return Pixels + column*Height; } +//========================================================================== +// +// +// +//========================================================================== + const BYTE *FFlatTexture::GetPixels () { if (Pixels == NULL) @@ -138,6 +189,12 @@ const BYTE *FFlatTexture::GetPixels () return Pixels; } +//========================================================================== +// +// +// +//========================================================================== + void FFlatTexture::MakeTexture () { FWadLump lump = Wads.OpenLumpNum (SourceLump); diff --git a/src/textures/imgztexture.cpp b/src/textures/imgztexture.cpp index 0d4a75e76..f3ba48810 100644 --- a/src/textures/imgztexture.cpp +++ b/src/textures/imgztexture.cpp @@ -38,39 +38,74 @@ #include "r_data.h" #include "w_wad.h" + +//========================================================================== +// +// An IMGZ image (mostly just crosshairs) // [RH] Just a format I invented to avoid WinTex's palette remapping // when I wanted to insert some alpha maps. +// +//========================================================================== -struct FIMGZTexture::ImageHeader +class FIMGZTexture : public FTexture { - BYTE Magic[4]; - WORD Width; - WORD Height; - SWORD LeftOffset; - SWORD TopOffset; - BYTE Compression; - BYTE Reserved[11]; + struct ImageHeader + { + BYTE Magic[4]; + WORD Width; + WORD Height; + SWORD LeftOffset; + SWORD TopOffset; + BYTE Compression; + BYTE Reserved[11]; + }; + +public: + FIMGZTexture (int lumpnum, WORD w, WORD h, SWORD l, SWORD t); + ~FIMGZTexture (); + + const BYTE *GetColumn (unsigned int column, const Span **spans_out); + const BYTE *GetPixels (); + void Unload (); + + int GetSourceLump() { return SourceLump; } + +protected: + + + int SourceLump; + BYTE *Pixels; + Span **Spans; + + void MakeTexture (); }; -bool FIMGZTexture::Check(FileReader & file) -{ - DWORD id; - file.Seek(0, SEEK_SET); - return file.Read(&id, 4) == 4 && id == MAKE_ID('I','M','G','Z'); -} +//========================================================================== +// +// +// +//========================================================================== -FTexture *FIMGZTexture::Create(FileReader & file, int lumpnum) +FTexture *IMGZTexture_TryCreate(FileReader & file, int lumpnum) { - DWORD magic; + DWORD magic = 0; WORD w, h; SWORD l, t; file.Seek(0, SEEK_SET); - file >> magic >> w >> h >> l >> t; + if (file.Read(&magic, 4) != 4) return NULL; + if (magic != MAKE_ID('I','M','G','Z')) return NULL; + file >> w >> h >> l >> t; return new FIMGZTexture(lumpnum, w, h, l, t); } +//========================================================================== +// +// +// +//========================================================================== + FIMGZTexture::FIMGZTexture (int lumpnum, WORD w, WORD h, SWORD l, SWORD t) : SourceLump(lumpnum), Pixels(0), Spans(0) { @@ -83,6 +118,12 @@ FIMGZTexture::FIMGZTexture (int lumpnum, WORD w, WORD h, SWORD l, SWORD t) CalcBitSize (); } +//========================================================================== +// +// +// +//========================================================================== + FIMGZTexture::~FIMGZTexture () { Unload (); @@ -93,6 +134,12 @@ FIMGZTexture::~FIMGZTexture () } } +//========================================================================== +// +// +// +//========================================================================== + void FIMGZTexture::Unload () { if (Pixels != NULL) @@ -102,6 +149,12 @@ void FIMGZTexture::Unload () } } +//========================================================================== +// +// +// +//========================================================================== + const BYTE *FIMGZTexture::GetColumn (unsigned int column, const Span **spans_out) { if (Pixels == NULL) @@ -130,6 +183,12 @@ const BYTE *FIMGZTexture::GetColumn (unsigned int column, const Span **spans_out return Pixels + column*Height; } +//========================================================================== +// +// +// +//========================================================================== + const BYTE *FIMGZTexture::GetPixels () { if (Pixels == NULL) @@ -139,6 +198,12 @@ const BYTE *FIMGZTexture::GetPixels () return Pixels; } +//========================================================================== +// +// +// +//========================================================================== + void FIMGZTexture::MakeTexture () { FMemLump lump = Wads.ReadLump (SourceLump); diff --git a/src/textures/jpegtexture.cpp b/src/textures/jpegtexture.cpp index 599e70eed..674723b2e 100644 --- a/src/textures/jpegtexture.cpp +++ b/src/textures/jpegtexture.cpp @@ -41,11 +41,23 @@ #include "v_text.h" #include "bitmap.h" +//========================================================================== +// +// +// +//========================================================================== + void FLumpSourceMgr::InitSource (j_decompress_ptr cinfo) { ((FLumpSourceMgr *)(cinfo->src))->StartOfFile = true; } +//========================================================================== +// +// +// +//========================================================================== + boolean FLumpSourceMgr::FillInputBuffer (j_decompress_ptr cinfo) { FLumpSourceMgr *me = (FLumpSourceMgr *)(cinfo->src); @@ -63,6 +75,12 @@ boolean FLumpSourceMgr::FillInputBuffer (j_decompress_ptr cinfo) return TRUE; } +//========================================================================== +// +// +// +//========================================================================== + void FLumpSourceMgr::SkipInputData (j_decompress_ptr cinfo, long num_bytes) { FLumpSourceMgr *me = (FLumpSourceMgr *)(cinfo->src); @@ -79,16 +97,53 @@ void FLumpSourceMgr::SkipInputData (j_decompress_ptr cinfo, long num_bytes) } } +//========================================================================== +// +// +// +//========================================================================== + void FLumpSourceMgr::TermSource (j_decompress_ptr cinfo) { } +//========================================================================== +// +// +// +//========================================================================== + +FLumpSourceMgr::FLumpSourceMgr (FileReader *lump, j_decompress_ptr cinfo) +: Lump (lump) +{ + cinfo->src = this; + init_source = InitSource; + fill_input_buffer = FillInputBuffer; + skip_input_data = SkipInputData; + resync_to_restart = jpeg_resync_to_restart; + term_source = TermSource; + bytes_in_buffer = 0; + next_input_byte = NULL; +} + +//========================================================================== +// +// +// +//========================================================================== + void JPEG_ErrorExit (j_common_ptr cinfo) { (*cinfo->err->output_message) (cinfo); throw -1; } +//========================================================================== +// +// +// +//========================================================================== + void JPEG_OutputMessage (j_common_ptr cinfo) { char buffer[JMSG_LENGTH_MAX]; @@ -97,14 +152,44 @@ void JPEG_OutputMessage (j_common_ptr cinfo) Printf (TEXTCOLOR_ORANGE "JPEG failure: %s\n", buffer); } -bool FJPEGTexture::Check(FileReader & file) -{ - BYTE hdr[3]; - file.Seek(0, SEEK_SET); - return file.Read(hdr, 3) == 3 && hdr[0] == 0xFF && hdr[1] == 0xD8 && hdr[2] == 0xFF; -} +//========================================================================== +// +// A JPEG texture +// +//========================================================================== -FTexture *FJPEGTexture::Create(FileReader & data, int lumpnum) +class FJPEGTexture : public FTexture +{ +public: + FJPEGTexture (int lumpnum, int width, int height); + ~FJPEGTexture (); + + const BYTE *GetColumn (unsigned int column, const Span **spans_out); + const BYTE *GetPixels (); + void Unload (); + FTextureFormat GetFormat (); + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL); + bool UseBasePalette(); + int GetSourceLump() { return SourceLump; } + +protected: + + int SourceLump; + BYTE *Pixels; + Span DummySpans[2]; + + void MakeTexture (); + + friend class FTexture; +}; + +//========================================================================== +// +// +// +//========================================================================== + +FTexture *JPEGTexture_TryCreate(FileReader & data, int lumpnum) { union { @@ -114,7 +199,10 @@ FTexture *FJPEGTexture::Create(FileReader & data, int lumpnum) } first4bytes; data.Seek(0, SEEK_SET); - data.Read(&first4bytes, 4); + if (data.Read(&first4bytes, 4) < 4) return NULL; + + if (first4bytes.b[0] != 0xFF || first4bytes.b[1] != 0xD8 || first4bytes.b[2] != 0xFF) + return NULL; // Find the SOFn marker to extract the image dimensions, // where n is 0, 1, or 2 (other types are unsupported). @@ -145,18 +233,11 @@ FTexture *FJPEGTexture::Create(FileReader & data, int lumpnum) return new FJPEGTexture (lumpnum, BigShort(first4bytes.w[1]), BigShort(first4bytes.w[0])); } -FLumpSourceMgr::FLumpSourceMgr (FileReader *lump, j_decompress_ptr cinfo) -: Lump (lump) -{ - cinfo->src = this; - init_source = InitSource; - fill_input_buffer = FillInputBuffer; - skip_input_data = SkipInputData; - resync_to_restart = jpeg_resync_to_restart; - term_source = TermSource; - bytes_in_buffer = 0; - next_input_byte = NULL; -} +//========================================================================== +// +// +// +//========================================================================== FJPEGTexture::FJPEGTexture (int lumpnum, int width, int height) : SourceLump(lumpnum), Pixels(0) @@ -179,11 +260,23 @@ FJPEGTexture::FJPEGTexture (int lumpnum, int width, int height) DummySpans[1].Length = 0; } +//========================================================================== +// +// +// +//========================================================================== + FJPEGTexture::~FJPEGTexture () { Unload (); } +//========================================================================== +// +// +// +//========================================================================== + void FJPEGTexture::Unload () { if (Pixels != NULL) @@ -193,11 +286,23 @@ void FJPEGTexture::Unload () } } +//========================================================================== +// +// +// +//========================================================================== + FTextureFormat FJPEGTexture::GetFormat() { return TEX_RGB; } +//========================================================================== +// +// +// +//========================================================================== + const BYTE *FJPEGTexture::GetColumn (unsigned int column, const Span **spans_out) { if (Pixels == NULL) @@ -222,6 +327,12 @@ const BYTE *FJPEGTexture::GetColumn (unsigned int column, const Span **spans_out return Pixels + column*Height; } +//========================================================================== +// +// +// +//========================================================================== + const BYTE *FJPEGTexture::GetPixels () { if (Pixels == NULL) @@ -231,6 +342,12 @@ const BYTE *FJPEGTexture::GetPixels () return Pixels; } +//========================================================================== +// +// +// +//========================================================================== + void FJPEGTexture::MakeTexture () { FWadLump lump = Wads.OpenLumpNum (SourceLump); diff --git a/src/textures/multipatchtexture.cpp b/src/textures/multipatchtexture.cpp index ffa0806d7..98068b25d 100644 --- a/src/textures/multipatchtexture.cpp +++ b/src/textures/multipatchtexture.cpp @@ -59,6 +59,138 @@ +//-------------------------------------------------------------------------- +// +// Data structures for the TEXTUREx lumps +// +//-------------------------------------------------------------------------- + +// +// Each texture is composed of one or more patches, with patches being lumps +// stored in the WAD. The lumps are referenced by number, and patched into +// the rectangular texture space using origin and possibly other attributes. +// +struct mappatch_t +{ + SWORD originx; + SWORD originy; + SWORD patch; + SWORD stepdir; + SWORD colormap; +}; + +// +// A wall texture is a list of patches which are to be combined in a +// predefined order. +// +struct maptexture_t +{ + BYTE name[8]; + WORD Flags; // [RH] Was unused + BYTE ScaleX; // [RH] Scaling (8 is normal) + BYTE ScaleY; // [RH] Same as above + SWORD width; + SWORD height; + BYTE columndirectory[4]; // OBSOLETE + SWORD patchcount; + mappatch_t patches[1]; +}; + +#define MAPTEXF_WORLDPANNING 0x8000 + +// Strife uses versions of the above structures that remove all unused fields + +struct strifemappatch_t +{ + SWORD originx; + SWORD originy; + SWORD patch; +}; + +// +// A wall texture is a list of patches which are to be combined in a +// predefined order. +// +struct strifemaptexture_t +{ + BYTE name[8]; + WORD Flags; // [RH] Was unused + BYTE ScaleX; // [RH] Scaling (8 is normal) + BYTE ScaleY; // [RH] Same as above + SWORD width; + SWORD height; + SWORD patchcount; + strifemappatch_t patches[1]; +}; + + +//========================================================================== +// +// In-memory representation of a single PNAMES lump entry +// +//========================================================================== + +struct FPatchLookup +{ + char Name[9]; + FTexture *Texture; +}; + + +//========================================================================== +// +// A texture defined in a TEXTURE1 or TEXTURE2 lump +// +//========================================================================== + +class FMultiPatchTexture : public FTexture +{ +public: + FMultiPatchTexture (const void *texdef, FPatchLookup *patchlookup, int maxpatchnum, bool strife, int deflump); + FMultiPatchTexture (FScanner &sc, int usetype); + ~FMultiPatchTexture (); + + const BYTE *GetColumn (unsigned int column, const Span **spans_out); + const BYTE *GetPixels (); + FTextureFormat GetFormat(); + bool UseBasePalette() ; + void Unload (); + virtual void SetFrontSkyLayer (); + + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL); + int GetSourceLump() { return DefinitionLump; } + +protected: + BYTE *Pixels; + Span **Spans; + int DefinitionLump; + + struct TexPart + { + SWORD OriginX, OriginY; + BYTE Rotate; + bool textureOwned; + BYTE op; + FRemapTable *Translation; + PalEntry Blend; + FTexture *Texture; + fixed_t Alpha; + + TexPart(); + }; + + int NumParts; + TexPart *Parts; + bool bRedirect:1; + bool bTranslucentPatches:1; + + void MakeTexture (); + +private: + void CheckForHacks (); + void ParsePatch(FScanner &sc, TexPart & part); +}; + //========================================================================== // // FMultiPatchTexture :: FMultiPatchTexture @@ -605,7 +737,7 @@ void FMultiPatchTexture::CheckForHacks () // All patches must be at the top of the texture for this fix for (i = 0; i < NumParts; ++i) { - if (Parts[i].OriginX != 0) + if (Parts[i].OriginY != 0) { break; } @@ -613,39 +745,9 @@ void FMultiPatchTexture::CheckForHacks () if (i == NumParts) { - // This really must check whether the texture in question is - // actually an FPatchTexture before casting the pointer. - for (i = 0; i < NumParts; ++i) if (Parts[i].Texture->bIsPatch) + for (i = 0; i < NumParts; ++i) { - FPatchTexture *tex = (FPatchTexture *)Parts[i].Texture; - // Check if this patch is likely to be a problem. - // It must be 256 pixels tall, and all its columns must have exactly - // one post, where each post has a supposed length of 0. - FMemLump lump = Wads.ReadLump (tex->SourceLump); - const patch_t *realpatch = (patch_t *)lump.GetMem(); - const DWORD *cofs = realpatch->columnofs; - int x, x2 = LittleShort(realpatch->width); - - if (LittleShort(realpatch->height) == 256) - { - for (x = 0; x < x2; ++x) - { - const column_t *col = (column_t*)((BYTE*)realpatch+LittleLong(cofs[x])); - if (col->topdelta != 0 || col->length != 0) - { - break; // It's not bad! - } - col = (column_t *)((BYTE *)col + 256 + 4); - if (col->topdelta != 0xFF) - { - break; // More than one post in a column! - } - } - if (x == x2) - { // If all the columns were checked, it needs fixing. - tex->HackHack (Height); - } - } + Parts[i].Texture->HackHack(256); } } } diff --git a/src/textures/patchtexture.cpp b/src/textures/patchtexture.cpp index ebfc76476..4369e5ad0 100644 --- a/src/textures/patchtexture.cpp +++ b/src/textures/patchtexture.cpp @@ -40,7 +40,42 @@ #include "templates.h" -bool FPatchTexture::Check(FileReader & file) +//========================================================================== +// +// A texture that is just a single Doom format patch +// +//========================================================================== + +class FPatchTexture : public FTexture +{ +public: + FPatchTexture (int lumpnum, patch_t *header); + ~FPatchTexture (); + + const BYTE *GetColumn (unsigned int column, const Span **spans_out); + const BYTE *GetPixels (); + void Unload (); + + int GetSourceLump() { return SourceLump; } + +protected: + int SourceLump; + BYTE *Pixels; + Span **Spans; + bool hackflag; + + + virtual void MakeTexture (); + void HackHack (int newheight); +}; + +//========================================================================== +// +// Checks if the currently open lump can be a Doom patch +// +//========================================================================== + +static bool CheckIfPatch(FileReader & file) { if (file.GetLength() < 13) return false; // minimum length of a valid Doom patch @@ -82,21 +117,33 @@ bool FPatchTexture::Check(FileReader & file) return false; } -FTexture *FPatchTexture::Create(FileReader & file, int lumpnum) +//========================================================================== +// +// +// +//========================================================================== + +FTexture *PatchTexture_TryCreate(FileReader & file, int lumpnum) { patch_t header; + if (!CheckIfPatch(file)) return NULL; file.Seek(0, SEEK_SET); file >> header.width >> header.height >> header.leftoffset >> header.topoffset; return new FPatchTexture(lumpnum, &header); } +//========================================================================== +// +// +// +//========================================================================== + FPatchTexture::FPatchTexture (int lumpnum, patch_t * header) : SourceLump(lumpnum), Pixels(0), Spans(0), hackflag(false) { Wads.GetLumpName (Name, lumpnum); Name[8] = 0; - bIsPatch = true; Width = header->width; Height = header->height; LeftOffset = header->leftoffset; @@ -104,6 +151,12 @@ FPatchTexture::FPatchTexture (int lumpnum, patch_t * header) CalcBitSize (); } +//========================================================================== +// +// +// +//========================================================================== + FPatchTexture::~FPatchTexture () { Unload (); @@ -114,6 +167,12 @@ FPatchTexture::~FPatchTexture () } } +//========================================================================== +// +// +// +//========================================================================== + void FPatchTexture::Unload () { if (Pixels != NULL) @@ -123,6 +182,12 @@ void FPatchTexture::Unload () } } +//========================================================================== +// +// +// +//========================================================================== + const BYTE *FPatchTexture::GetPixels () { if (Pixels == NULL) @@ -132,6 +197,12 @@ const BYTE *FPatchTexture::GetPixels () return Pixels; } +//========================================================================== +// +// +// +//========================================================================== + const BYTE *FPatchTexture::GetColumn (unsigned int column, const Span **spans_out) { if (Pixels == NULL) @@ -161,6 +232,12 @@ const BYTE *FPatchTexture::GetColumn (unsigned int column, const Span **spans_ou } +//========================================================================== +// +// +// +//========================================================================== + void FPatchTexture::MakeTexture () { BYTE *remap, remaptable[256]; @@ -174,6 +251,7 @@ void FPatchTexture::MakeTexture () maxcol = (const column_t *)((const BYTE *)patch + Wads.LumpLength (SourceLump) - 3); // Check for badly-sized patches +#if 0 // Such textures won't be created so there's no need to check here if (LittleShort(patch->width) <= 0 || LittleShort(patch->height) <= 0) { lump = Wads.ReadLump ("-BADPATC"); @@ -186,6 +264,7 @@ void FPatchTexture::MakeTexture () patch = (const patch_t *)lump.GetMem(); Printf (PRINT_BOLD, "Patch %s is too big.\n", Name); } +#endif if (bNoRemap0) { @@ -271,19 +350,52 @@ void FPatchTexture::MakeTexture () } +//========================================================================== +// // Fix for certain special patches on single-patch textures. +// +//========================================================================== + void FPatchTexture::HackHack (int newheight) { - Unload (); - if (Spans != NULL) + // Check if this patch is likely to be a problem. + // It must be 256 pixels tall, and all its columns must have exactly + // one post, where each post has a supposed length of 0. + FMemLump lump = Wads.ReadLump (SourceLump); + const patch_t *realpatch = (patch_t *)lump.GetMem(); + const DWORD *cofs = realpatch->columnofs; + int x, x2 = LittleShort(realpatch->width); + + if (LittleShort(realpatch->height) == 256) { - FreeSpans (Spans); + for (x = 0; x < x2; ++x) + { + const column_t *col = (column_t*)((BYTE*)realpatch+LittleLong(cofs[x])); + if (col->topdelta != 0 || col->length != 0) + { + break; // It's not bad! + } + col = (column_t *)((BYTE *)col + 256 + 4); + if (col->topdelta != 0xFF) + { + break; // More than one post in a column! + } + } + if (x == x2) + { + // If all the columns were checked, it needs fixing. + Unload (); + if (Spans != NULL) + { + FreeSpans (Spans); + } + + Height = newheight; + LeftOffset = 0; + TopOffset = 0; + + hackflag = true; + bMasked = false; // Hacked textures don't have transparent parts. + } } - - Height = newheight; - LeftOffset = 0; - TopOffset = 0; - - hackflag = true; - bMasked = false; // Hacked textures don't have transparent parts. } diff --git a/src/textures/pcxtexture.cpp b/src/textures/pcxtexture.cpp index 0a710a423..dfe04df3b 100644 --- a/src/textures/pcxtexture.cpp +++ b/src/textures/pcxtexture.cpp @@ -41,15 +41,89 @@ #include "templates.h" #include "bitmap.h" +//========================================================================== +// +// PCX file header +// +//========================================================================== -bool FPCXTexture::Check(FileReader & file) +#pragma pack(1) + +struct PCXHeader +{ + BYTE manufacturer; + BYTE version; + BYTE encoding; + BYTE bitsPerPixel; + + WORD xmin, ymin; + WORD xmax, ymax; + WORD horzRes, vertRes; + + BYTE palette[48]; + BYTE reserved; + BYTE numColorPlanes; + + WORD bytesPerScanLine; + WORD paletteType; + WORD horzSize, vertSize; + + BYTE padding[54]; + +}; +#pragma pack() + +//========================================================================== +// +// a PCX texture +// +//========================================================================== + +class FPCXTexture : public FTexture +{ +public: + FPCXTexture (int lumpnum, PCXHeader &); + ~FPCXTexture (); + + const BYTE *GetColumn (unsigned int column, const Span **spans_out); + const BYTE *GetPixels (); + void Unload (); + FTextureFormat GetFormat (); + + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL); + bool UseBasePalette(); + int GetSourceLump() { return SourceLump; } + +protected: + int SourceLump; + BYTE *Pixels; + Span DummySpans[2]; + + void ReadPCX1bit (BYTE *dst, FileReader & lump, PCXHeader *hdr); + void ReadPCX4bits (BYTE *dst, FileReader & lump, PCXHeader *hdr); + void ReadPCX8bits (BYTE *dst, FileReader & lump, PCXHeader *hdr); + void ReadPCX24bits (BYTE *dst, FileReader & lump, PCXHeader *hdr, int planes); + + virtual void MakeTexture (); + + friend class FTexture; +}; + + +//========================================================================== +// +// +// +//========================================================================== + +FTexture * PCXTexture_TryCreate(FileReader & file, int lumpnum) { PCXHeader hdr; file.Seek(0, SEEK_SET); if (file.Read(&hdr, sizeof(hdr)) != sizeof(hdr)) { - return false; + return NULL; } #ifdef WORDS_BIGENDIAN @@ -58,22 +132,16 @@ bool FPCXTexture::Check(FileReader & file) hdr.bytesPerScanLine = LittleShort(hdr.bytesPerScanLine); #endif - if (hdr.manufacturer != 10 || hdr.encoding != 1) return false; - if (hdr.version != 0 && hdr.version != 2 && hdr.version != 3 && hdr.version != 4 && hdr.version != 5) return false; - if (hdr.bitsPerPixel != 1 && hdr.bitsPerPixel != 8) return false; - if (hdr.bitsPerPixel == 1 && hdr.numColorPlanes !=1 && hdr.numColorPlanes != 4) return false; - if (hdr.bitsPerPixel == 8 && hdr.bytesPerScanLine != ((hdr.xmax - hdr.xmin + 2)&~1)) return false; + if (hdr.manufacturer != 10 || hdr.encoding != 1) return NULL; + if (hdr.version != 0 && hdr.version != 2 && hdr.version != 3 && hdr.version != 4 && hdr.version != 5) return NULL; + if (hdr.bitsPerPixel != 1 && hdr.bitsPerPixel != 8) return NULL; + if (hdr.bitsPerPixel == 1 && hdr.numColorPlanes !=1 && hdr.numColorPlanes != 4) return NULL; + if (hdr.bitsPerPixel == 8 && hdr.bytesPerScanLine != ((hdr.xmax - hdr.xmin + 2)&~1)) return NULL; for (int i = 0; i < 54; i++) { - if (hdr.padding[i] != 0) return false; + if (hdr.padding[i] != 0) return NULL; } - return true; -} - -FTexture * FPCXTexture::Create(FileReader & file, int lumpnum) -{ - PCXHeader hdr; file.Seek(0, SEEK_SET); file.Read(&hdr, sizeof(hdr)); @@ -81,6 +149,12 @@ FTexture * FPCXTexture::Create(FileReader & file, int lumpnum) return new FPCXTexture(lumpnum, hdr); } +//========================================================================== +// +// +// +//========================================================================== + FPCXTexture::FPCXTexture(int lumpnum, PCXHeader & hdr) : SourceLump(lumpnum), Pixels(0) { @@ -97,11 +171,22 @@ FPCXTexture::FPCXTexture(int lumpnum, PCXHeader & hdr) DummySpans[1].Length = 0; } +//========================================================================== +// +// +// +//========================================================================== + FPCXTexture::~FPCXTexture () { Unload (); } +//========================================================================== +// +// +// +//========================================================================== void FPCXTexture::Unload () { @@ -112,11 +197,22 @@ void FPCXTexture::Unload () } } +//========================================================================== +// +// +// +//========================================================================== + FTextureFormat FPCXTexture::GetFormat() { return TEX_RGB; } +//========================================================================== +// +// +// +//========================================================================== const BYTE *FPCXTexture::GetColumn (unsigned int column, const Span **spans_out) { @@ -142,6 +238,12 @@ const BYTE *FPCXTexture::GetColumn (unsigned int column, const Span **spans_out) return Pixels + column*Height; } +//========================================================================== +// +// +// +//========================================================================== + const BYTE *FPCXTexture::GetPixels () { if (Pixels == NULL) @@ -151,6 +253,12 @@ const BYTE *FPCXTexture::GetPixels () return Pixels; } +//========================================================================== +// +// +// +//========================================================================== + void FPCXTexture::ReadPCX1bit (BYTE *dst, FileReader & lump, PCXHeader *hdr) { int y, i, bytes; @@ -193,6 +301,11 @@ void FPCXTexture::ReadPCX1bit (BYTE *dst, FileReader & lump, PCXHeader *hdr) delete [] srcp; } +//========================================================================== +// +// +// +//========================================================================== void FPCXTexture::ReadPCX4bits (BYTE *dst, FileReader & lump, PCXHeader *hdr) { @@ -251,6 +364,11 @@ void FPCXTexture::ReadPCX4bits (BYTE *dst, FileReader & lump, PCXHeader *hdr) delete [] srcp; } +//========================================================================== +// +// +// +//========================================================================== void FPCXTexture::ReadPCX8bits (BYTE *dst, FileReader & lump, PCXHeader *hdr) { @@ -288,6 +406,11 @@ void FPCXTexture::ReadPCX8bits (BYTE *dst, FileReader & lump, PCXHeader *hdr) delete [] srcp; } +//========================================================================== +// +// +// +//========================================================================== void FPCXTexture::ReadPCX24bits (BYTE *dst, FileReader & lump, PCXHeader *hdr, int planes) { @@ -331,6 +454,12 @@ void FPCXTexture::ReadPCX24bits (BYTE *dst, FileReader & lump, PCXHeader *hdr, i delete [] srcp; } +//========================================================================== +// +// +// +//========================================================================== + void FPCXTexture::MakeTexture() { BYTE PaletteMap[256]; diff --git a/src/textures/pngtexture.cpp b/src/textures/pngtexture.cpp index 55f1908f4..34351a752 100644 --- a/src/textures/pngtexture.cpp +++ b/src/textures/pngtexture.cpp @@ -41,15 +41,54 @@ #include "m_png.h" #include "bitmap.h" +//========================================================================== +// +// A PNG texture +// +//========================================================================== -bool FPNGTexture::Check(FileReader & file) +class FPNGTexture : public FTexture { - DWORD id; - file.Seek(0, SEEK_SET); - return file.Read(&id, 4) == 4 && id == MAKE_ID(137,'P','N','G'); -} +public: + FPNGTexture (FileReader &lump, int lumpnum, const FString &filename, int width, int height, BYTE bitdepth, BYTE colortype, BYTE interlace); + ~FPNGTexture (); -FTexture *FPNGTexture::Create(FileReader & data, int lumpnum) + const BYTE *GetColumn (unsigned int column, const Span **spans_out); + const BYTE *GetPixels (); + void Unload (); + FTextureFormat GetFormat (); + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL); + bool UseBasePalette(); + int GetSourceLump() { return SourceLump; } + +protected: + + int SourceLump; + FString SourceFile; + BYTE *Pixels; + Span **Spans; + + BYTE BitDepth; + BYTE ColorType; + BYTE Interlace; + + BYTE *PaletteMap; + int PaletteSize; + DWORD StartOfIDAT; + + void MakeTexture (); + + friend class FTexture; +}; + + +//========================================================================== +// +// +// +//========================================================================== + +FTexture *PNGTexture_TryCreate(FileReader & data, int lumpnum) { union { @@ -64,12 +103,15 @@ FTexture *FPNGTexture::Create(FileReader & data, int lumpnum) // This is most likely a PNG, but make sure. (Note that if the // first 4 bytes match, but later bytes don't, we assume it's // a corrupt PNG.) - data.Seek(4, SEEK_SET); - data.Read (first4bytes.b, 4); + + data.Seek(0, SEEK_SET); + if (data.Read (first4bytes.b, 4) != 4) return NULL; + if (first4bytes.dw != MAKE_ID(137,'P','N','G')) return NULL; + if (data.Read (first4bytes.b, 4) != 4) return NULL; if (first4bytes.dw != MAKE_ID(13,10,26,10)) return NULL; - data.Read (first4bytes.b, 4); + if (data.Read (first4bytes.b, 4) != 4) return NULL; if (first4bytes.dw != MAKE_ID(0,0,0,13)) return NULL; - data.Read (first4bytes.b, 4); + if (data.Read (first4bytes.b, 4) != 4) return NULL; if (first4bytes.dw != MAKE_ID('I','H','D','R')) return NULL; // The PNG looks valid so far. Check the IHDR to make sure it's a @@ -106,7 +148,13 @@ FTexture *FPNGTexture::Create(FileReader & data, int lumpnum) bitdepth, colortype, interlace); } -FTexture *FPNGTexture::CreateFromFile(PNGHandle *png, const FString &filename) +//========================================================================== +// +// +// +//========================================================================== + +FTexture *PNGTexture_CreateFromFile(PNGHandle *png, const FString &filename) { DWORD width, height; BYTE bitdepth, colortype, compression, filter, interlace; @@ -137,6 +185,12 @@ FTexture *FPNGTexture::CreateFromFile(PNGHandle *png, const FString &filename) bitdepth, colortype, interlace); } +//========================================================================== +// +// +// +//========================================================================== + FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename, int width, int height, BYTE depth, BYTE colortype, BYTE interlace) : SourceLump(lumpnum), SourceFile(filename), Pixels(0), Spans(0), @@ -276,6 +330,12 @@ FPNGTexture::FPNGTexture (FileReader &lump, int lumpnum, const FString &filename } } +//========================================================================== +// +// +// +//========================================================================== + FPNGTexture::~FPNGTexture () { Unload (); @@ -291,6 +351,12 @@ FPNGTexture::~FPNGTexture () } } +//========================================================================== +// +// +// +//========================================================================== + void FPNGTexture::Unload () { if (Pixels != NULL) @@ -300,6 +366,12 @@ void FPNGTexture::Unload () } } +//========================================================================== +// +// +// +//========================================================================== + FTextureFormat FPNGTexture::GetFormat() { #if 0 @@ -315,6 +387,12 @@ FTextureFormat FPNGTexture::GetFormat() #endif } +//========================================================================== +// +// +// +//========================================================================== + const BYTE *FPNGTexture::GetColumn (unsigned int column, const Span **spans_out) { if (Pixels == NULL) @@ -343,6 +421,12 @@ const BYTE *FPNGTexture::GetColumn (unsigned int column, const Span **spans_out) return Pixels + column*Height; } +//========================================================================== +// +// +// +//========================================================================== + const BYTE *FPNGTexture::GetPixels () { if (Pixels == NULL) @@ -352,6 +436,12 @@ const BYTE *FPNGTexture::GetPixels () return Pixels; } +//========================================================================== +// +// +// +//========================================================================== + void FPNGTexture::MakeTexture () { FileReader *lump; diff --git a/src/textures/rawpagetexture.cpp b/src/textures/rawpagetexture.cpp index 5ff6f69fb..04f3c1793 100644 --- a/src/textures/rawpagetexture.cpp +++ b/src/textures/rawpagetexture.cpp @@ -39,8 +39,40 @@ #include "w_wad.h" +//========================================================================== +// +// A raw 320x200 graphic used by Heretic and Hexen fullscreen images +// +//========================================================================== -bool FRawPageTexture::Check(FileReader & data) +class FRawPageTexture : public FTexture +{ +public: + FRawPageTexture (int lumpnum); + ~FRawPageTexture (); + + const BYTE *GetColumn (unsigned int column, const Span **spans_out); + const BYTE *GetPixels (); + void Unload (); + + int GetSourceLump() { return SourceLump; } + +protected: + int SourceLump; + BYTE *Pixels; + static const Span DummySpans[2]; + + void MakeTexture (); +}; + +//========================================================================== +// +// RAW textures must be exactly 64000 bytes long and not be identifiable +// as Doom patch +// +//========================================================================== + +static bool CheckIfRaw(FileReader & data) { if (data.GetLength() != 64000) return false; @@ -112,17 +144,36 @@ bool FRawPageTexture::Check(FileReader & data) } } -FTexture *FRawPageTexture::Create(FileReader & file, int lumpnum) +//========================================================================== +// +// +// +//========================================================================== + +FTexture *RawPageTexture_TryCreate(FileReader & file, int lumpnum) { + if (!CheckIfRaw(file)) return NULL; return new FRawPageTexture(lumpnum); } +//========================================================================== +// +// +// +//========================================================================== + const FTexture::Span FRawPageTexture::DummySpans[2] = { { 0, 200 }, { 0, 0 } }; +//========================================================================== +// +// +// +//========================================================================== + FRawPageTexture::FRawPageTexture (int lumpnum) : SourceLump(lumpnum), Pixels(0) { @@ -136,11 +187,23 @@ FRawPageTexture::FRawPageTexture (int lumpnum) WidthMask = 255; } +//========================================================================== +// +// +// +//========================================================================== + FRawPageTexture::~FRawPageTexture () { Unload (); } +//========================================================================== +// +// +// +//========================================================================== + void FRawPageTexture::Unload () { if (Pixels != NULL) @@ -150,6 +213,12 @@ void FRawPageTexture::Unload () } } +//========================================================================== +// +// +// +//========================================================================== + const BYTE *FRawPageTexture::GetColumn (unsigned int column, const Span **spans_out) { if (Pixels == NULL) @@ -167,6 +236,12 @@ const BYTE *FRawPageTexture::GetColumn (unsigned int column, const Span **spans_ return Pixels + column*Height; } +//========================================================================== +// +// +// +//========================================================================== + const BYTE *FRawPageTexture::GetPixels () { if (Pixels == NULL) @@ -176,6 +251,12 @@ const BYTE *FRawPageTexture::GetPixels () return Pixels; } +//========================================================================== +// +// +// +//========================================================================== + void FRawPageTexture::MakeTexture () { FMemLump lump = Wads.ReadLump (SourceLump); diff --git a/src/textures/texture.cpp b/src/textures/texture.cpp index 3e03fa785..9bff37b44 100644 --- a/src/textures/texture.cpp +++ b/src/textures/texture.cpp @@ -47,8 +47,7 @@ typedef FTexture * (*CreateFunc)(FileReader & file, int lumpnum); struct TexCreateInfo { - CheckFunc Check; - CreateFunc Create; + CreateFunc TryCreate; int usetype; }; @@ -62,22 +61,33 @@ void FTexture::InitGrayMap() } } +FTexture *IMGZTexture_TryCreate(FileReader &, int lumpnum); +FTexture *PNGTexture_TryCreate(FileReader &, int lumpnum); +FTexture *JPEGTexture_TryCreate(FileReader &, int lumpnum); +FTexture *DDSTexture_TryCreate(FileReader &, int lumpnum); +FTexture *PCXTexture_TryCreate(FileReader &, int lumpnum); +FTexture *TGATexture_TryCreate(FileReader &, int lumpnum); +FTexture *RawPageTexture_TryCreate(FileReader &, int lumpnum); +FTexture *FlatTexture_TryCreate(FileReader &, int lumpnum); +FTexture *PatchTexture_TryCreate(FileReader &, int lumpnum); +FTexture *AutomapTexture_TryCreate(FileReader &, int lumpnum); + // Examines the lump contents to decide what type of texture to create, // and creates the texture. FTexture * FTexture::CreateTexture (int lumpnum, int usetype) { static TexCreateInfo CreateInfo[]={ - { FIMGZTexture::Check, FIMGZTexture::Create, TEX_Any }, - { FPNGTexture::Check, FPNGTexture::Create, TEX_Any }, - { FJPEGTexture::Check, FJPEGTexture::Create, TEX_Any }, - { FDDSTexture::Check, FDDSTexture::Create, TEX_Any }, - { FPCXTexture::Check, FPCXTexture::Create, TEX_Any }, - { FTGATexture::Check, FTGATexture::Create, TEX_Any }, - { FRawPageTexture::Check, FRawPageTexture::Create, TEX_MiscPatch }, - { FFlatTexture::Check, FFlatTexture::Create, TEX_Flat }, - { FPatchTexture::Check, FPatchTexture::Create, TEX_Any }, - { FAutomapTexture::Check, FAutomapTexture::Create, TEX_Autopage }, + { IMGZTexture_TryCreate, TEX_Any }, + { PNGTexture_TryCreate, TEX_Any }, + { JPEGTexture_TryCreate, TEX_Any }, + { DDSTexture_TryCreate, TEX_Any }, + { PCXTexture_TryCreate, TEX_Any }, + { TGATexture_TryCreate, TEX_Any }, + { RawPageTexture_TryCreate, TEX_MiscPatch }, + { FlatTexture_TryCreate, TEX_Flat }, + { PatchTexture_TryCreate, TEX_Any }, + { AutomapTexture_TryCreate, TEX_Autopage }, }; if (lumpnum == -1) return NULL; @@ -86,10 +96,9 @@ FTexture * FTexture::CreateTexture (int lumpnum, int usetype) for(size_t i = 0; i < countof(CreateInfo); i++) { - if ((CreateInfo[i].usetype == usetype || CreateInfo[i].usetype == TEX_Any) && - CreateInfo[i].Check(data)) + if ((CreateInfo[i].usetype == usetype || CreateInfo[i].usetype == TEX_Any)) { - FTexture * tex = CreateInfo[i].Create(data, lumpnum); + FTexture * tex = CreateInfo[i].TryCreate(data, lumpnum); if (tex != NULL) { tex->UseType = usetype; @@ -121,7 +130,7 @@ FTexture::FTexture () : LeftOffset(0), TopOffset(0), WidthBits(0), HeightBits(0), xScale(FRACUNIT), yScale(FRACUNIT), UseType(TEX_Any), bNoDecals(false), bNoRemap0(false), bWorldPanning(false), - bMasked(true), bAlphaTexture(false), bHasCanvas(false), bWarped(0), bIsPatch(false), bComplex(false), + bMasked(true), bAlphaTexture(false), bHasCanvas(false), bWarped(0), bComplex(false), Rotations(0xFFFF), Width(0), Height(0), WidthMask(0), Native(NULL) { *Name = 0; @@ -173,6 +182,10 @@ void FTexture::CalcBitSize () HeightBits = i; } +void FTexture::HackHack (int newheight) +{ +} + FTexture::Span **FTexture::CreateSpans (const BYTE *pixels) const { Span **spans, *span; diff --git a/src/textures/texturemanager.cpp b/src/textures/texturemanager.cpp index 27bb56c1e..daa85a215 100644 --- a/src/textures/texturemanager.cpp +++ b/src/textures/texturemanager.cpp @@ -338,7 +338,7 @@ int FTextureManager::CreateTexture (int lumpnum, int usetype) if (out != NULL) return AddTexture (out); else { - Printf (TEXTCOLOR_ORANGE "Invalid data encountered for texture %s\n", Wads.GetLumpFullName(lumpnum)); + Printf (TEXTCOLOR_ORANGE "Invalid data encountered for texture %s\n", Wads.GetLumpFullPath(lumpnum).GetChars()); return -1; } } diff --git a/src/textures/tgatexture.cpp b/src/textures/tgatexture.cpp index 97fe0455e..0758075ad 100644 --- a/src/textures/tgatexture.cpp +++ b/src/textures/tgatexture.cpp @@ -41,14 +41,80 @@ #include "bitmap.h" -bool FTGATexture::Check(FileReader & data) +//========================================================================== +// +// TGA file header +// +//========================================================================== + +#pragma pack(1) + +struct TGAHeader +{ + BYTE id_len; + BYTE has_cm; + BYTE img_type; + SWORD cm_first; + SWORD cm_length; + BYTE cm_size; + + SWORD x_origin; + SWORD y_origin; + SWORD width; + SWORD height; + BYTE bpp; + BYTE img_desc; +}; + +#pragma pack() + +//========================================================================== +// +// a TGA texture +// +//========================================================================== + +class FTGATexture : public FTexture +{ +public: + FTGATexture (int lumpnum, TGAHeader *); + ~FTGATexture (); + + const BYTE *GetColumn (unsigned int column, const Span **spans_out); + const BYTE *GetPixels (); + void Unload (); + FTextureFormat GetFormat (); + + int CopyTrueColorPixels(FBitmap *bmp, int x, int y, int rotate, FCopyInfo *inf = NULL); + bool UseBasePalette(); + int GetSourceLump() { return SourceLump; } + +protected: + int SourceLump; + BYTE *Pixels; + Span **Spans; + + void ReadCompressed(FileReader &lump, BYTE * buffer, int bytesperpixel); + + virtual void MakeTexture (); + + friend class FTexture; +}; + +//========================================================================== +// +// +// +//========================================================================== + +FTexture *TGATexture_TryCreate(FileReader & file, int lumpnum) { TGAHeader hdr; + + if (file.GetLength() < (long)sizeof(hdr)) return NULL; - if (data.GetLength() < (long)sizeof(hdr)) return false; - - data.Seek(0, SEEK_SET); - data.Read(&hdr, sizeof(hdr)); + file.Seek(0, SEEK_SET); + file.Read(&hdr, sizeof(hdr)); #ifdef WORDS_BIGENDIAN hdr.width = LittleShort(hdr.width); hdr.height = LittleShort(hdr.height); @@ -56,18 +122,13 @@ bool FTGATexture::Check(FileReader & data) // Not much that can be done here because TGA does not have a proper // header to be identified with. - if (hdr.has_cm != 0 && hdr.has_cm != 1) return false; - if (hdr.width <=0 || hdr.height <=0 || hdr.width > 2048 || hdr.height > 2048) return false; - if (hdr.bpp != 8 && hdr.bpp != 15 && hdr.bpp != 16 && hdr.bpp !=24 && hdr.bpp !=32) return false; - if (hdr.img_type <= 0 || hdr.img_type > 11) return false; - if (hdr.img_type >=4 && hdr.img_type <= 8) return false; - if ((hdr.img_desc & 16) != 0) return false; - return true; -} + if (hdr.has_cm != 0 && hdr.has_cm != 1) return NULL; + if (hdr.width <=0 || hdr.height <=0 || hdr.width > 2048 || hdr.height > 2048) return NULL; + if (hdr.bpp != 8 && hdr.bpp != 15 && hdr.bpp != 16 && hdr.bpp !=24 && hdr.bpp !=32) return NULL; + if (hdr.img_type <= 0 || hdr.img_type > 11) return NULL; + if (hdr.img_type >=4 && hdr.img_type <= 8) return NULL; + if ((hdr.img_desc & 16) != 0) return NULL; -FTexture *FTGATexture::Create(FileReader & file, int lumpnum) -{ - TGAHeader hdr; file.Seek(0, SEEK_SET); file.Read(&hdr, sizeof(hdr)); #ifdef WORDS_BIGENDIAN @@ -78,6 +139,11 @@ FTexture *FTGATexture::Create(FileReader & file, int lumpnum) return new FTGATexture(lumpnum, &hdr); } +//========================================================================== +// +// +// +//========================================================================== FTGATexture::FTGATexture (int lumpnum, TGAHeader * hdr) : SourceLump(lumpnum), Pixels(0), Spans(0) @@ -91,6 +157,12 @@ FTGATexture::FTGATexture (int lumpnum, TGAHeader * hdr) CalcBitSize(); } +//========================================================================== +// +// +// +//========================================================================== + FTGATexture::~FTGATexture () { Unload (); @@ -101,6 +173,11 @@ FTGATexture::~FTGATexture () } } +//========================================================================== +// +// +// +//========================================================================== void FTGATexture::Unload () { @@ -111,11 +188,23 @@ void FTGATexture::Unload () } } +//========================================================================== +// +// +// +//========================================================================== + FTextureFormat FTGATexture::GetFormat() { return TEX_RGB; } +//========================================================================== +// +// +// +//========================================================================== + const BYTE *FTGATexture::GetColumn (unsigned int column, const Span **spans_out) { if (Pixels == NULL) @@ -144,6 +233,12 @@ const BYTE *FTGATexture::GetColumn (unsigned int column, const Span **spans_out) return Pixels + column*Height; } +//========================================================================== +// +// +// +//========================================================================== + const BYTE *FTGATexture::GetPixels () { if (Pixels == NULL) @@ -153,6 +248,12 @@ const BYTE *FTGATexture::GetPixels () return Pixels; } +//========================================================================== +// +// +// +//========================================================================== + void FTGATexture::ReadCompressed(FileReader &lump, BYTE * buffer, int bytesperpixel) { BYTE b; @@ -184,6 +285,12 @@ void FTGATexture::ReadCompressed(FileReader &lump, BYTE * buffer, int bytesperpi } } +//========================================================================== +// +// +// +//========================================================================== + void FTGATexture::MakeTexture () { BYTE PaletteMap[256]; diff --git a/zdoom.vcproj b/zdoom.vcproj index 0de14641e..49ff6e3cd 100644 --- a/zdoom.vcproj +++ b/zdoom.vcproj @@ -1,7 +1,7 @@ + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - @@ -950,6 +940,16 @@ Outputs=""src/$(InputName).h"" /> + + + @@ -1544,6 +1544,16 @@ Outputs="$(IntDir)\$(InputName).obj" /> + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - - - - @@ -1932,6 +1924,14 @@ Outputs="$(IntDir)\$(InputName).obj" /> + + + - - - @@ -2814,6 +2806,14 @@ AdditionalIncludeDirectories="src\win32;$(NoInherit)" /> + + + @@ -3084,7 +3084,7 @@ />