1 //************************************************************************** 2 //** 3 //** ## ## ## ## ## #### #### ### ### 4 //** ## ## ## ## ## ## ## ## ## ## #### #### 5 //** ## ## ## ## ## ## ## ## ## ## ## ## ## ## 6 //** ## ## ######## ## ## ## ## ## ## ## ### ## 7 //** ### ## ## ### ## ## ## ## ## ## 8 //** # ## ## # #### #### ## ## 9 //** 10 //** $Id: r_public.h 4341 2010-12-15 22:20:42Z dj_jl $ 11 //** 12 //** Copyright (C) 1999-2006 Jānis Legzdiņš 13 //** 14 //** This program is free software; you can redistribute it and/or 15 //** modify it under the terms of the GNU General Public License 16 //** as published by the Free Software Foundation; either version 2 17 //** of the License, or (at your option) any later version. 18 //** 19 //** This program is distributed in the hope that it will be useful, 20 //** but WITHOUT ANY WARRANTY; without even the implied warranty of 21 //** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 //** GNU General Public License for more details. 23 //** 24 //************************************************************************** 25 26 struct particle_t; 27 struct dlight_t; 28 29 // Texture use types. 30 enum 31 { 32 TEXTYPE_Any, 33 TEXTYPE_WallPatch, 34 TEXTYPE_Wall, 35 TEXTYPE_Flat, 36 TEXTYPE_Overload, 37 TEXTYPE_Sprite, 38 TEXTYPE_SkyMap, 39 TEXTYPE_Skin, 40 TEXTYPE_Pic, 41 TEXTYPE_Autopage, 42 TEXTYPE_Null, 43 TEXTYPE_FontChar, 44 }; 45 46 // Texture data formats. 47 enum 48 { 49 TEXFMT_8, // Paletised texture in main palette. 50 TEXFMT_8Pal, // Paletised texture with custom palette. 51 TEXFMT_RGBA, // Truecolour texture. 52 }; 53 54 struct rgb_t 55 { 56 byte r; 57 byte g; 58 byte b; 59 }; 60 61 struct rgba_t 62 { 63 byte r; 64 byte g; 65 byte b; 66 byte a; 67 }; 68 69 struct picinfo_t 70 { 71 vint32 width; 72 vint32 height; 73 vint32 xoffset; 74 vint32 yoffset; 75 }; 76 77 struct TSwitchFrame 78 { 79 vint16 Texture; 80 vint16 BaseTime; 81 vint16 RandomRange; 82 }; 83 84 struct TSwitch 85 { 86 vint16 Tex; 87 vint16 PairIndex; 88 vint16 Sound; 89 vint16 NumFrames; 90 TSwitchFrame* Frames; 91 bool Quest; 92 TSwitchTSwitch93 TSwitch() 94 : Frames(NULL) 95 {} ~TSwitchTSwitch96 ~TSwitch() 97 { 98 if (Frames) 99 { 100 delete[] Frames; 101 Frames = NULL; 102 } 103 } 104 }; 105 106 struct VAnimDoorDef 107 { 108 vint32 Texture; 109 VName OpenSound; 110 VName CloseSound; 111 vint32 NumFrames; 112 vint32* Frames; 113 }; 114 115 class VRenderLevelPublic : public VInterface 116 { 117 public: 118 virtual void PreRender() = 0; 119 virtual void SegMoved(seg_t*) = 0; 120 virtual void SetupFakeFloors(sector_t*) = 0; 121 virtual void RenderPlayerView() = 0; 122 123 virtual void AddStaticLight(const TVec&, float, vuint32) = 0; 124 virtual dlight_t* AllocDlight(VThinker*) = 0; 125 virtual void DecayLights(float) = 0; 126 127 virtual particle_t* NewParticle() = 0; 128 }; 129 130 class VTextureTranslation 131 { 132 public: 133 vuint8 Table[256]; 134 rgba_t Palette[256]; 135 136 vuint16 Crc; 137 138 // Used to detect changed player translations. 139 vuint8 TranslStart; 140 vuint8 TranslEnd; 141 vint32 Colour; 142 143 // Used to replicate translation tables in more efficient way. 144 struct VTransCmd 145 { 146 vuint8 Type; 147 vuint8 Start; 148 vuint8 End; 149 vuint8 R1; 150 vuint8 G1; 151 vuint8 B1; 152 vuint8 R2; 153 vuint8 G2; 154 vuint8 B2; 155 }; 156 TArray<VTransCmd> Commands; 157 158 VTextureTranslation(); 159 void Clear(); 160 void CalcCrc(); 161 void Serialise(VStream&); 162 void BuildPlayerTrans(int, int, int); 163 void MapToRange(int, int, int, int); 164 void MapToColours(int, int, int, int, int, int, int, int); 165 void BuildBloodTrans(int); 166 void AddTransString(const VStr&); 167 GetTable()168 const vuint8* GetTable() const 169 { 170 return Table; 171 } GetPalette()172 const rgba_t* GetPalette() const 173 { 174 return Palette; 175 } 176 }; 177 178 class VTexture 179 { 180 public: 181 int Type; 182 int Format; 183 VName Name; 184 int Width; 185 int Height; 186 int SOffset; 187 int TOffset; 188 bool bNoRemap0; 189 bool bWorldPanning; 190 bool bIsCameraTexture; 191 vuint8 WarpType; 192 float SScale; // Scaling 193 float TScale; 194 int TextureTranslation; // Animation 195 int HashNext; 196 int SourceLump; 197 198 // Driver data. 199 struct VTransData 200 { 201 union 202 { 203 vuint32 Handle; 204 void* Data; 205 }; 206 VTextureTranslation* Trans; 207 int ColourMap; 208 }; 209 210 union 211 { 212 vuint32 DriverHandle; 213 void* DriverData; 214 }; 215 TArray<VTransData> DriverTranslated; 216 217 protected: 218 vuint8* Pixels8Bit; 219 VTexture* HiResTexture; 220 bool Pixels8BitValid; 221 222 public: 223 VTexture(); 224 virtual ~VTexture(); 225 226 static VTexture* CreateTexture(int, int); 227 GetWidth()228 int GetWidth() const { return Width; } GetHeight()229 int GetHeight() const { return Height; } 230 GetScaledWidth()231 int GetScaledWidth() const { return (int)(Width / SScale); } GetScaledHeight()232 int GetScaledHeight() const { return (int)(Height / TScale); } 233 GetScaledSOffset()234 int GetScaledSOffset() const { return (int)(SOffset / SScale); } GetScaledTOffset()235 int GetScaledTOffset() const { return (int)(TOffset / TScale); } 236 237 virtual void SetFrontSkyLayer(); 238 virtual bool CheckModified(); 239 virtual vuint8* GetPixels() = 0; 240 vuint8* GetPixels8(); 241 virtual rgba_t* GetPalette(); 242 virtual void Unload() = 0; 243 virtual VTexture* GetHighResolutionTexture(); 244 VTransData* FindDriverTrans(VTextureTranslation*, int); 245 246 static void AdjustGamma(rgba_t*, int); 247 static void SmoothEdges(vuint8*, int, int, vuint8*); 248 static void ResampleTexture(int, int, const vuint8*, int, int, vuint8*); 249 static void MipMap(int, int, vuint8*); 250 251 protected: 252 void FixupPalette(vuint8* Pixels, rgba_t* Palette); 253 }; 254 255 class VTextureManager 256 { 257 public: 258 vint32 DefaultTexture; 259 float Time; // Time value for warp textures 260 261 VTextureManager(); 262 void Init(); 263 void Shutdown(); 264 int AddTexture(VTexture* Tex); 265 void ReplaceTexture(int Index, VTexture* Tex); 266 int CheckNumForName(VName Name, int Type, bool bOverload = false, 267 bool bCheckAny = false); 268 int NumForName(VName Name, int Type, bool bOverload = false, 269 bool bCheckAny = false); 270 int FindTextureByLumpNum(int); 271 VName GetTextureName(int TexNum); 272 float TextureHeight(int TexNum); 273 int TextureAnimation(int InTex); 274 void SetFrontSkyLayer(int tex); 275 void GetTextureInfo(int TexNum, picinfo_t* info); 276 int AddPatch(VName Name, int Type, bool Silent = false); 277 int AddRawWithPal(VName Name, VName PalName); 278 int AddFileTexture(VName Name, int Type); 279 280 // Get unanimated texture 281 VTexture* operator[](int TexNum) 282 { 283 if ((vuint32)TexNum >= (vuint32)Textures.Num()) 284 { 285 return NULL; 286 } 287 return Textures[TexNum]; 288 } 289 290 // Get animated texture operator()291 VTexture* operator()(int TexNum) 292 { 293 if ((vuint32)TexNum >= (vuint32)Textures.Num()) 294 { 295 return NULL; 296 } 297 return Textures[TextureAnimation(TexNum)]; 298 } 299 GetNumTextures()300 int GetNumTextures() const 301 { 302 return Textures.Num(); 303 } 304 305 private: 306 enum { HASH_SIZE = 1024 }; 307 308 TArray<VTexture*> Textures; 309 int TextureHash[HASH_SIZE]; 310 311 void AddToHash(int Index); 312 void RemoveFromHash(int Index); 313 void AddTextures(); 314 void AddTexturesLump(int, int, int, bool); 315 void AddGroup(int, EWadNamespace); 316 void AddHiResTextures(); 317 }; 318 319 // r_data 320 void R_InitData(); 321 void R_ShutdownData(); 322 void R_InstallSprite(const char*, int); 323 bool R_AreSpritesPresent(int); 324 int R_ParseDecorateTranslation(VScriptParser*, int); 325 int R_GetBloodTranslation(int); 326 void R_ParseEffectDefs(); 327 328 // r_main 329 void R_Init(); // Called by startup code. 330 void R_Start(VLevel*); 331 void R_SetViewSize(int blocks); 332 void R_RenderPlayerView(); 333 VTextureTranslation* R_GetCachedTranslation(int, VLevel*); 334 335 // r_tex 336 void R_InitTexture(); 337 void R_ShutdownTexture(); 338 VAnimDoorDef* R_FindAnimDoor(vint32); 339 void R_AnimateSurfaces(); 340 341 // r_things 342 void R_DrawSpritePatch(int, int, int, int, int, int = 0, int = 0, int = 0); 343 void R_InitSprites(); 344 345 // 2D graphics 346 void R_DrawPic(int x, int y, int handle, float Aplha = 1.0); 347 348 extern VTextureManager GTextureManager; 349 350 extern int validcount; 351 352 extern int skyflatnum; 353 354 // Switches 355 extern TArray<TSwitch*> Switches; 356