1 /* 2 ** decallib.h 3 ** 4 **--------------------------------------------------------------------------- 5 ** Copyright 1998-2006 Randy Heit 6 ** All rights reserved. 7 ** 8 ** Redistribution and use in source and binary forms, with or without 9 ** modification, are permitted provided that the following conditions 10 ** are met: 11 ** 12 ** 1. Redistributions of source code must retain the above copyright 13 ** notice, this list of conditions and the following disclaimer. 14 ** 2. Redistributions in binary form must reproduce the above copyright 15 ** notice, this list of conditions and the following disclaimer in the 16 ** documentation and/or other materials provided with the distribution. 17 ** 3. The name of the author may not be used to endorse or promote products 18 ** derived from this software without specific prior written permission. 19 ** 20 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 **--------------------------------------------------------------------------- 31 ** 32 */ 33 34 #ifndef __DECALLIB_H__ 35 #define __DECALLIB_H__ 36 37 #include <string.h> 38 39 #include "doomtype.h" 40 #include "r_data/renderstyle.h" 41 #include "textures/textures.h" 42 43 class FScanner; 44 class FDecalTemplate; 45 struct FDecalAnimator; 46 struct PClass; 47 class DBaseDecal; 48 struct side_t; 49 50 class FDecalBase 51 { 52 friend class FDecalLib; 53 public: 54 virtual const FDecalTemplate *GetDecal () const; 55 virtual void ReplaceDecalRef (FDecalBase *from, FDecalBase *to) = 0; 56 57 protected: 58 FDecalBase (); 59 virtual ~FDecalBase (); 60 61 FDecalBase *Left, *Right; 62 FName Name; 63 WORD SpawnID; 64 TArray<const PClass *> Users; // Which actors generate this decal 65 }; 66 67 class FDecalTemplate : public FDecalBase 68 { 69 friend class FDecalLib; 70 public: FDecalTemplate()71 FDecalTemplate () : Translation (0) {} 72 73 void ApplyToDecal (DBaseDecal *actor, side_t *wall) const; 74 const FDecalTemplate *GetDecal () const; 75 void ReplaceDecalRef (FDecalBase *from, FDecalBase *to); 76 77 fixed_t ScaleX, ScaleY; 78 DWORD ShadeColor; 79 DWORD Translation; 80 FRenderStyle RenderStyle; 81 FTextureID PicNum; 82 WORD RenderFlags; 83 WORD Alpha; // same as (actor->alpha >> 1) 84 const FDecalAnimator *Animator; 85 const FDecalBase *LowerDecal; 86 87 enum { DECAL_RandomFlipX = 0x100, DECAL_RandomFlipY = 0x200 }; 88 }; 89 90 class FDecalLib 91 { 92 public: 93 FDecalLib (); 94 ~FDecalLib (); 95 96 void Clear (); 97 void ReadDecals (FScanner &sc); 98 void ReadAllDecals (); 99 100 const FDecalTemplate *GetDecalByNum (WORD num) const; 101 const FDecalTemplate *GetDecalByName (const char *name) const; 102 103 private: 104 struct FTranslation; 105 106 static void DelTree (FDecalBase *root); 107 static FDecalBase *ScanTreeForNum (const WORD num, FDecalBase *root); 108 static FDecalBase *ScanTreeForName (const char *name, FDecalBase *root); 109 static void ReplaceDecalRef (FDecalBase *from, FDecalBase *to, FDecalBase *root); 110 FTranslation *GenerateTranslation (DWORD start, DWORD end); 111 void AddDecal (const char *name, WORD num, const FDecalTemplate &decal); 112 void AddDecal (FDecalBase *decal); 113 FDecalAnimator *FindAnimator (const char *name); 114 115 WORD GetDecalID (FScanner &sc); 116 void ParseDecal (FScanner &sc); 117 void ParseDecalGroup (FScanner &sc); 118 void ParseGenerator (FScanner &sc); 119 void ParseFader (FScanner &sc); 120 void ParseStretcher (FScanner &sc); 121 void ParseSlider (FScanner &sc); 122 void ParseCombiner (FScanner &sc); 123 void ParseColorchanger (FScanner &sc); 124 125 FDecalBase *Root; 126 FTranslation *Translations; 127 }; 128 129 extern FDecalLib DecalLibrary; 130 131 #endif //__DECALLIB_H__ 132