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 };
66 
67 #define CROSSHAIR_PAL (MAXPALOOKUPS-RESERVEDPALS-1)
68 #define kCrosshairTile 2319
69 #define kLoadScreen 2049
70 #define kLoadScreenCRC -2051908571
71 #define kLoadScreenWideBackWidth 256
72 #define kLoadScreenWideSideWidth 128
73 #define kLoadScreenWideBack 9216
74 #define kLoadScreenWideLeft 9217
75 #define kLoadScreenWideRight 9218
76 #define kLoadScreenWideMiddle 9219
77 
78 #define kFontNum 5
79 
80 struct FONT {
81     int tile, xSize, ySize, space, yoff;
82 };
83 
84 extern int gZoom;
85 extern FONT gFont[kFontNum];
86 extern int gViewMode;
87 extern VIEWPOS gViewPos;
88 extern int gViewIndex;
89 extern int gScreenTilt;
90 extern int deliriumTilt, deliriumTurn, deliriumPitch;
91 extern int gScreenTiltO, deliriumTurnO, deliriumPitchO;
92 extern int gShowFrameRate;
93 extern char gInterpolateSprite[];
94 extern char gInterpolateWall[];
95 extern char gInterpolateSector[];
96 extern LOCATION gPrevSpriteLoc[kMaxSprites];
97 extern int gViewSize;
98 extern CGameMessageMgr gGameMessageMgr;
99 extern int gViewXCenter, gViewYCenter;
100 extern int gViewX0, gViewY0, gViewX1, gViewY1;
101 extern int gViewX0S, gViewY0S, gViewX1S, gViewY1S;
102 extern palette_t CrosshairColors;
103 extern bool g_isAlterDefaultCrosshair;
104 extern float r_ambientlight, r_ambientlightrecip;
105 extern int gLastPal;
106 extern int32_t gShowFps, gFramePeriod;
107 
108 
calcFrameDelay(unsigned int const maxFPS)109 static inline double calcFrameDelay(unsigned int const maxFPS) { return maxFPS ? timerGetPerformanceFrequency() / (double)maxFPS : 0.0; }
110 
111 void viewGetFontInfo(int id, const char *unk1, int *pXSize, int *pYSize);
112 void viewUpdatePages(void);
113 void viewToggle(int viewMode);
114 void viewInitializePrediction(void);
115 void viewUpdatePrediction(GINPUT *pInput);
116 void sub_158B4(PLAYER *pPlayer);
117 void fakeProcessInput(PLAYER *pPlayer, GINPUT *pInput);
118 void fakePlayerProcess(PLAYER *pPlayer, GINPUT *pInput);
119 void fakeMoveDude(spritetype *pSprite);
120 void fakeActAirDrag(spritetype *pSprite, int num);
121 void fakeActProcessSprites(void);
122 void viewCorrectPrediction(void);
123 void viewBackupView(int nPlayer);
124 void viewCorrectViewOffsets(int nPlayer, vec3_t const *oldpos);
125 void viewClearInterpolations(void);
126 void viewAddInterpolation(void *data, INTERPOLATE_TYPE type);
127 void CalcInterpolations(void);
128 void RestoreInterpolations(void);
129 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);
130 void viewTileSprite(int nTile, int nShade, int nPalette, int x1, int y1, int x2, int y2);
131 void InitStatusBar(void);
132 void DrawStatSprite(int nTile, int x, int y, int nShade = 0, int nPalette = 0, unsigned int nStat = 0, int nScale = 65536);
133 void DrawStatMaskedSprite(int nTile, int x, int y, int nShade = 0, int nPalette = 0, unsigned int nStat = 0, int nScale = 65536);
134 void DrawStatNumber(const char *pFormat, int nNumber, int nTile, int x, int y, int nShade, int nPalette, unsigned int nStat = 0, int nScale = 65536);
135 void TileHGauge(int nTile, int x, int y, int nMult, int nDiv, int nStat = 0, int nScale = 65536);
136 void viewDrawPack(PLAYER *pPlayer, int x, int y);
137 void DrawPackItemInStatusBar(PLAYER *pPlayer, int x, int y, int x2, int y2, int nStat = 0);
138 void UpdateStatusBar(ClockTicks arg);
139 void viewInit(void);
140 void viewResizeView(int size);
141 void UpdateFrame(void);
142 void viewDrawInterface(ClockTicks arg);
143 tspritetype *viewAddEffect(int nTSprite, VIEW_EFFECT nViewEffect);
144 void viewProcessSprites(int32_t cX, int32_t cY, int32_t cZ, int32_t cA, int32_t smooth);
145 void CalcOtherPosition(spritetype *pSprite, int *pX, int *pY, int *pZ, int *vsectnum, int nAng, int zm);
146 void CalcPosition(spritetype *pSprite, int *pX, int *pY, int *pZ, int *vsectnum, int nAng, int zm);
147 void viewSetMessage(const char *pMessage, const int pal = 0, const MESSAGE_PRIORITY priority = MESSAGE_PRIORITY_NORMAL);
148 void viewDisplayMessage(void);
149 void viewSetErrorMessage(const char *pMessage);
150 void DoLensEffect(void);
151 void UpdateDacs(int nPalette, bool bNoTint = false);
152 void viewDrawScreen(void);
153 void viewLoadingScreenWide(void);
154 void viewLoadingScreenUpdate(const char *pzText4 = NULL, int nPercent = -1);
155 void viewLoadingScreen(int nTile, const char *pText, const char *pText2, const char *pText3);
156 void viewUpdateDelirium(void);
157 void viewUpdateShake(void);
158 void viewSetCrosshairColor(int32_t r, int32_t g, int32_t b);
159 void viewResetCrosshairToDefault(void);
160 void viewPrintFPS(void);
161 void viewSetSystemMessage(const char* pMessage, ...);
162 void viewPrecacheTiles(void);
163 
viewInterpolateSector(int nSector,sectortype * pSector)164 inline void viewInterpolateSector(int nSector, sectortype *pSector)
165 {
166     if (!TestBitString(gInterpolateSector, nSector))
167     {
168         viewAddInterpolation(&pSector->floorz, INTERPOLATE_TYPE_INT);
169         viewAddInterpolation(&pSector->ceilingz, INTERPOLATE_TYPE_INT);
170         viewAddInterpolation(&pSector->floorheinum, INTERPOLATE_TYPE_SHORT);
171         SetBitString(gInterpolateSector, nSector);
172     }
173 }
174 
viewInterpolateWall(int nWall,walltype * pWall)175 inline void viewInterpolateWall(int nWall, walltype *pWall)
176 {
177     if (!TestBitString(gInterpolateWall, nWall))
178     {
179         viewAddInterpolation(&pWall->x, INTERPOLATE_TYPE_INT);
180         viewAddInterpolation(&pWall->y, INTERPOLATE_TYPE_INT);
181         SetBitString(gInterpolateWall, nWall);
182     }
183 }
184 
viewBackupSpriteLoc(int nSprite,spritetype * pSprite)185 inline void viewBackupSpriteLoc(int nSprite, spritetype *pSprite)
186 {
187     if (!TestBitString(gInterpolateSprite, nSprite))
188     {
189         LOCATION *pPrevLoc = &gPrevSpriteLoc[nSprite];
190         pPrevLoc->x = pSprite->x;
191         pPrevLoc->y = pSprite->y;
192         pPrevLoc->z = pSprite->z;
193         pPrevLoc->ang = pSprite->ang;
194         SetBitString(gInterpolateSprite, nSprite);
195     }
196 }
197