view.h
1 //------------------------------------------------------------------------- 2 /* 3 Copyright (C) 2010-2019 EDuke32 developers and contributors 4 Copyright (C) 2019 Nuke.YKT 5 6 This file is part of NBlood. 7 8 NBlood is free software; you can redistribute it and/or 9 modify it under the terms of the GNU General Public License version 2 10 as published by the Free Software Foundation. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 15 16 See the GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program; if not, write to the Free Software 20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 */ 22 //------------------------------------------------------------------------- 23 #pragma once 24 #include "compat.h" 25 #include "build.h" 26 #include "palette.h" 27 #include "common_game.h" 28 #include "controls.h" 29 #include "messages.h" 30 #include "player.h" 31 32 enum VIEW_EFFECT { 33 kViewEffectShadow = 0, 34 kViewEffectFlareHalo, 35 kViewEffectCeilGlow, 36 kViewEffectFloorGlow, 37 kViewEffectTorchHigh, 38 kViewEffectTorchLow, 39 kViewEffectSmokeHigh, 40 kViewEffectSmokeLow, 41 kViewEffectFlame, 42 kViewEffectSpear, 43 kViewEffectTrail, 44 kViewEffectPhase, 45 kViewEffectShowWeapon, 46 kViewEffectReflectiveBall, 47 kViewEffectShoot, 48 kViewEffectTesla, 49 kViewEffectFlag, 50 kViewEffectBigFlag, 51 kViewEffectAtom, 52 #ifdef NOONE_EXTENSIONS 53 kViewEffectSpotProgress, 54 #endif 55 }; 56 57 enum VIEWPOS { 58 VIEWPOS_0 = 0, 59 VIEWPOS_1 60 }; 61 62 enum INTERPOLATE_TYPE { 63 INTERPOLATE_TYPE_INT = 0, 64 INTERPOLATE_TYPE_SHORT, 65 INTERPOLATE_TYPE_CHAR, 66 INTERPOLATE_TYPE_CHAR_PANNING, // this is only for wall/ceiling/floor texture panning 67 }; 68 69 #define CROSSHAIR_PAL (MAXPALOOKUPS-RESERVEDPALS-1) 70 #define kCrosshairTile 2319 71 #define kLoadScreen 2049 72 #define kLoadScreenCRC -2051908571 73 #define kLoadScreenWideBackWidth 256 74 #define kLoadScreenWideSideWidth 128 75 #define kLoadScreenWideBack 9216 76 #define kLoadScreenWideLeft 9217 77 #define kLoadScreenWideRight 9218 78 #define kLoadScreenWideMiddle 9219 79 80 #define kSBarNumberHealth 9220 81 #define kSBarNumberAmmo 9230 82 #define kSBarNumberInv 9240 83 #define kSBarNumberArmor1 9250 84 #define kSBarNumberArmor2 9260 85 #define kSBarNumberArmor3 9270 86 #define kSBarNegative 9280 87 88 #define kFontNum 5 89 90 #define kHudFullBackTile 9286 91 92 struct FONT { 93 int tile, xSize, ySize, space, yoff; 94 }; 95 96 extern int gZoom; 97 extern FONT gFont[kFontNum]; 98 extern int gViewMode; 99 extern VIEWPOS gViewPos; 100 extern int gViewIndex; 101 extern int gScreenTilt; 102 extern int deliriumTilt, deliriumTurn, deliriumPitch; 103 extern int gScreenTiltO, deliriumTurnO, deliriumPitchO; 104 extern int gShowFrameRate; 105 extern int gInterpolate; 106 extern char gInterpolateSprite[]; 107 extern char gInterpolateWall[]; 108 extern char gInterpolateSector[]; 109 extern char gInterpolatePanningWall[]; 110 extern char gInterpolatePanningCeiling[]; 111 extern char gInterpolatePanningFloor[]; 112 extern LOCATION gPrevSpriteLoc[kMaxSprites]; 113 extern int gViewSize; 114 extern CGameMessageMgr gGameMessageMgr; 115 extern int gViewXCenter, gViewYCenter; 116 extern int gViewX0, gViewY0, gViewX1, gViewY1; 117 extern int gViewX0S, gViewY0S, gViewX1S, gViewY1S; 118 extern palette_t CrosshairColors; 119 extern bool g_isAlterDefaultCrosshair; 120 extern float r_ambientlight, r_ambientlightrecip; 121 extern int gLastPal; 122 extern int32_t gShowFps, gFramePeriod; 123 124 125 static inline double calcFrameDelay(unsigned int const maxFPS) { return maxFPS ? timerGetPerformanceFrequency() / (double)maxFPS : 0.0; } 126 127 void viewGetFontInfo(int id, const char *unk1, int *pXSize, int *pYSize); 128 void viewToggle(int viewMode); 129 void viewInitializePrediction(void); 130 void viewUpdatePrediction(GINPUT *pInput); 131 void sub_158B4(PLAYER *pPlayer); 132 void fakeProcessInput(PLAYER *pPlayer, GINPUT *pInput); 133 void fakePlayerProcess(PLAYER *pPlayer, GINPUT *pInput); 134 void fakeMoveDude(spritetype *pSprite); 135 void fakeActAirDrag(spritetype *pSprite, int num); 136 void fakeActProcessSprites(void); 137 void viewCorrectPrediction(void); 138 void viewBackupView(int nPlayer); 139 void viewCorrectViewOffsets(int nPlayer, vec3_t const *oldpos); 140 void viewClearInterpolations(void); 141 void viewAddInterpolation(void *data, INTERPOLATE_TYPE type); 142 void CalcInterpolations(void); 143 void RestoreInterpolations(void); 144 void viewDrawText(int nFont, const char *pString, int x, int y, int nShade, int nPalette, int position, char shadow, unsigned int nStat = 0, uint8_t alpha = 0, COLORSTR *pColorStr = NULL); 145 void viewTileSprite(int nTile, int nShade, int nPalette, int x1, int y1, int x2, int y2, int nWidth = 0, int nHeight = 0, int nScale = 65536); 146 void InitStatusBar(void); 147 void DrawStatSprite(int nTile, int x, int y, int nShade = 0, int nPalette = 0, unsigned int nStat = 0, int nScale = 65536); 148 void DrawStatMaskedSprite(int nTile, int x, int y, int nShade = 0, int nPalette = 0, unsigned int nStat = 0, int nScale = 65536, char bMirror = 0); 149 void DrawStatNumber(const char *pFormat, int nNumber, int nTile, int x, int y, int nShade, int nPalette, unsigned int nStat = 0, int nScale = 65536, char bShadow = 0); 150 void TileHGauge(int nTile, int x, int y, int nMult, int nDiv, int nStat = 0, int nScale = 65536); 151 void viewDrawPack(PLAYER *pPlayer, int x, int y); 152 void DrawPackItemInStatusBar(PLAYER *pPlayer, int x, int y, int x2, int y2, int nStat = 0); 153 void viewDrawWinner(const char *pString = NULL, int nPal = 0); 154 void UpdateStatusBar(ClockTicks arg); 155 void viewInit(void); 156 void viewUpdateHudRatio(void); 157 void viewUpdateSkyRatio(void); 158 void viewResizeView(int size); 159 void UpdateFrame(void); 160 void viewDimScreen(void); 161 void viewDrawInterface(ClockTicks arg); 162 tspritetype *viewAddEffect(int nTSprite, VIEW_EFFECT nViewEffect); 163 void viewReplacePlayerAsCultist(tspritetype *pTSprite, int nSpriteOrig, int nXSpriteOrig); 164 void viewProcessSprites(int32_t cX, int32_t cY, int32_t cZ, int32_t cA, int32_t smooth); 165 void CalcOtherPosition(spritetype *pSprite, int *pX, int *pY, int *pZ, int *vsectnum, int nAng, fix16_t zm); 166 void CalcPosition(spritetype *pSprite, int *pX, int *pY, int *pZ, int *vsectnum, int nAng, int zm); 167 void viewSetMessage(const char *pMessage, const int nPal = 0, const MESSAGE_PRIORITY nPriority = MESSAGE_PRIORITY_NORMAL); 168 void viewSetMessageColor(char *pMessage, const int nPal = 0, const MESSAGE_PRIORITY nPriority = MESSAGE_PRIORITY_NORMAL, const int nPal1 = 0, const int nPal2 = 0); 169 void viewDisplayMessage(void); 170 void viewSetErrorMessage(const char *pMessage); 171 void DoLensEffect(void); 172 void UpdateDacs(int nPalette, bool bNoTint = false); 173 void viewDrawScreen(void); 174 void viewLoadingScreenWide(void); 175 void viewLoadingScreenUpdate(const char *pzText4 = NULL, int nPercent = -1); 176 void viewLoadingScreen(int nTile, const char *pText, const char *pText2, const char *pText3); 177 void viewUpdateDelirium(void); 178 void viewUpdateShake(void); 179 void viewSetCrosshairColor(int32_t r, int32_t g, int32_t b); 180 void viewResetCrosshairToDefault(void); 181 void viewSetRenderScale(char bShowRes); 182 void viewPrintFPS(void); 183 void viewSetSystemMessage(const char* pMessage, ...); 184 void viewPrecacheTiles(void); 185 186 extern fix16_t gCameraAng; 187 #include "trig.h" 188 template<typename T> tspritetype* viewInsertTSprite(int nSector, int nStatnum, T const * const pSprite) 189 { 190 if (spritesortcnt >= maxspritesonscreen) 191 return nullptr; 192 int nTSprite = spritesortcnt; 193 tspritetype *pTSprite = &tsprite[nTSprite]; 194 memset(pTSprite, 0, sizeof(tspritetype)); 195 pTSprite->cstat = 128; 196 pTSprite->xrepeat = 64; 197 pTSprite->yrepeat = 64; 198 pTSprite->owner = -1; 199 pTSprite->extra = -1; 200 pTSprite->type = -spritesortcnt; 201 pTSprite->statnum = nStatnum; 202 pTSprite->sectnum = nSector; 203 spritesortcnt++; 204 if (pSprite) 205 { 206 pTSprite->x = pSprite->x; 207 pTSprite->y = pSprite->y; 208 pTSprite->z = pSprite->z; 209 pTSprite->owner = pSprite->owner; 210 pTSprite->ang = pSprite->ang; 211 } 212 if (videoGetRenderMode() >= REND_POLYMOST) 213 { 214 pTSprite->x += Cos(gCameraAng)>>25; 215 pTSprite->y += Sin(gCameraAng)>>25; 216 } 217 return pTSprite; 218 } 219 220 inline void viewInterpolateSector(int nSector, sectortype *pSector) 221 { 222 if (gViewInterpolate && !TestBitString(gInterpolateSector, nSector)) 223 { 224 viewAddInterpolation(&pSector->floorz, INTERPOLATE_TYPE_INT); 225 viewAddInterpolation(&pSector->ceilingz, INTERPOLATE_TYPE_INT); 226 viewAddInterpolation(&pSector->floorheinum, INTERPOLATE_TYPE_SHORT); 227 SetBitString(gInterpolateSector, nSector); 228 } 229 } 230 231 inline void viewInterpolateWall(int nWall, walltype *pWall) 232 { 233 if (gViewInterpolate && !TestBitString(gInterpolateWall, nWall)) 234 { 235 viewAddInterpolation(&pWall->x, INTERPOLATE_TYPE_INT); 236 viewAddInterpolation(&pWall->y, INTERPOLATE_TYPE_INT); 237 SetBitString(gInterpolateWall, nWall); 238 } 239 } 240 241 inline void viewInterpolatePanningWall(int nWall, walltype *pWall) 242 { 243 if (gViewInterpolate && !TestBitString(gInterpolatePanningWall, nWall)) 244 { 245 viewAddInterpolation(&pWall->xpanning, INTERPOLATE_TYPE_CHAR_PANNING); 246 viewAddInterpolation(&pWall->ypanning, INTERPOLATE_TYPE_CHAR_PANNING); 247 SetBitString(gInterpolatePanningWall, nWall); 248 } 249 } 250 251 inline void viewInterpolatePanningCeiling(int nSector, sectortype *pSector) 252 { 253 if (gViewInterpolate && !TestBitString(gInterpolatePanningCeiling, nSector)) 254 { 255 viewAddInterpolation(&pSector->ceilingxpanning, INTERPOLATE_TYPE_CHAR_PANNING); 256 viewAddInterpolation(&pSector->ceilingypanning, INTERPOLATE_TYPE_CHAR_PANNING); 257 SetBitString(gInterpolatePanningCeiling, nSector); 258 } 259 } 260 261 inline void viewInterpolatePanningFloor(int nSector, sectortype *pSector) 262 { 263 if (gViewInterpolate && !TestBitString(gInterpolatePanningFloor, nSector)) 264 { 265 viewAddInterpolation(&pSector->floorxpanning, INTERPOLATE_TYPE_CHAR_PANNING); 266 viewAddInterpolation(&pSector->floorypanning, INTERPOLATE_TYPE_CHAR_PANNING); 267 SetBitString(gInterpolatePanningFloor, nSector); 268 } 269 } 270 271 inline void viewBackupSpriteLoc(int nSprite, spritetype *pSprite) 272 { 273 if (gViewInterpolate && !TestBitString(gInterpolateSprite, nSprite)) 274 { 275 LOCATION *pPrevLoc = &gPrevSpriteLoc[nSprite]; 276 pPrevLoc->x = pSprite->x; 277 pPrevLoc->y = pSprite->y; 278 pPrevLoc->z = pSprite->z; 279 pPrevLoc->ang = pSprite->ang; 280 SetBitString(gInterpolateSprite, nSprite); 281 } 282 } 283 284 inline void viewCorrectSpriteInterpolateOffsets(int nSprite, spritetype *pSprite, vec3_t const *oldpos) 285 { 286 if (TestBitString(gInterpolateSprite, nSprite)) 287 { 288 if (!gViewInterpolate) // view interpolation is off, clear interpolation flag 289 { 290 ClearBitString(gInterpolateSprite, nSprite); 291 return; 292 } 293 LOCATION *pPrevLoc = &gPrevSpriteLoc[nSprite]; 294 pPrevLoc->x = pSprite->x+(pPrevLoc->x-oldpos->x); 295 pPrevLoc->y = pSprite->y+(pPrevLoc->y-oldpos->y); 296 pPrevLoc->z = pSprite->z+(pPrevLoc->z-oldpos->z); 297 } 298 }