1 //-------------------------------------------------------------------------
2 /*
3 Copyright (C) 2010 EDuke32 developers and contributors
4 
5 This file is part of EDuke32.
6 
7 EDuke32 is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License version 2
9 as published by the Free Software Foundation.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 
15 See the GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 */
21 //-------------------------------------------------------------------------
22 
23 #ifndef global_h_
24 #define global_h_
25 
26 #include "build.h"
27 #include "compat.h"
28 #include "duke3d.h"
29 #include "mmulti.h"
30 #include "quotes.h"
31 #include "sector.h"
32 #include "sounds.h"
33 
34 #define MAXMINECARTS 16
35 #define MAXJAILDOORS 32
36 #define MAXLIGHTNINSECTORS 64
37 #define MAXTORCHSECTORS 64
38 #define MAXGEOSECTORS 64
39 
40 #ifdef global_c_
41     #define G_EXTERN
42 #else
43     #define G_EXTERN extern
44 #endif
45 
46 #define MAXINTERPOLATIONS MAXSPRITES
47 // KEEPINSYNC lunatic/con_lang.lua
48 #define MAXSKILLS 7
49 
50 // duke3d global soup :(
51 
52 
53 G_EXTERN int32_t g_interpolationCnt;
54 G_EXTERN int32_t g_interpolationLock;
55 G_EXTERN int32_t oldipos[MAXINTERPOLATIONS];
56 G_EXTERN int32_t *curipos[MAXINTERPOLATIONS];
57 G_EXTERN int32_t bakipos[MAXINTERPOLATIONS];
58 
59 
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63 
64 G_EXTERN int32_t duke3d_globalflags;
65 
66 // KEEPINSYNC astub.c (used values only)
67 enum DUKE3D_GLOBALFLAGS {
68     DUKE3D_NO_WIDESCREEN_PINNING = 1<<0,
69     DUKE3D_NO_HARDCODED_FOGPALS = 1<<1,
70     DUKE3D_NO_PALETTE_CHANGES = 1<<2,
71 };
72 
73 G_EXTERN DukeStatus_t sbar;
74 G_EXTERN actor_t actor[MAXSPRITES];
75 // g_tile: tile-specific data THAT DOES NOT CHANGE during the course of a game
76 G_EXTERN tiledata_t g_tile[MAXTILES];
77 G_EXTERN animwalltype animwall[MAXANIMWALLS];
78 G_EXTERN char *apStrings[MAXQUOTES],*apXStrings[MAXQUOTES];
79 G_EXTERN char *label;
80 G_EXTERN int32_t g_musicIndex;
81 G_EXTERN char g_loadFromGroupOnly;
82 G_EXTERN char g_skillCnt;
83 G_EXTERN char pus,pub;
84 G_EXTERN char ready2send;
85 #define MAXPLAYERNAME 32
86 G_EXTERN char szPlayerName[MAXPLAYERNAME];
87 G_EXTERN char tempbuf[MAXSECTORS<<1],buf[1024];
88 G_EXTERN uint8_t packbuf[PACKBUF_SIZE];
89 #define TYPEBUFSIZE 141
90 G_EXTERN char typebuf[TYPEBUFSIZE];
91 
92 
93 G_EXTERN input_t localInput;
94 G_EXTERN input_t recsync[RECSYNCBUFSIZ];
95 
96 //G_EXTERN uint8_t syncstat, syncval[MAXPLAYERS][MOVEFIFOSIZ];
97 //G_EXTERN int32_t syncvalhead[MAXPLAYERS], syncvaltail, syncvaltottail;
98 
99 G_EXTERN int32_t avgfvel, avgsvel, avgbits;
100 G_EXTERN fix16_t avgavel, avghorz;
101 G_EXTERN int8_t avgextbits;
102 
103 G_EXTERN int32_t movefifosendplc;
104 G_EXTERN int32_t movefifoplc;
105 
106 G_EXTERN int32_t predictfifoplc;
107 G_EXTERN vec3_t mypos, omypos, myvel;
108 G_EXTERN fix16_t myhoriz, omyhoriz, myhorizoff, omyhorizoff, myang, omyang;
109 G_EXTERN int16_t mycursectnum, myjumpingcounter;
110 G_EXTERN uint8_t myjumpingtoggle, myonground, myhardlanding, myreturntocenter;
111 G_EXTERN int16_t my_moto_speed;
112 G_EXTERN uint8_t my_not_on_water, my_moto_on_ground;
113 G_EXTERN uint8_t my_moto_do_bump, my_moto_bump_fast, my_moto_on_oil, my_moto_on_mud;
114 G_EXTERN int16_t my_moto_bump, my_moto_bump_target, my_moto_turb;
115 G_EXTERN int32_t my_stairs;
116 
117 G_EXTERN vec3_t myposbak[MOVEFIFOSIZ];
118 G_EXTERN fix16_t myhorizbak[MOVEFIFOSIZ], myangbak[MOVEFIFOSIZ];
119 G_EXTERN int32_t myminlag[MAXPLAYERS], mymaxlag, otherminlag, bufferjitter;
120 
121 G_EXTERN int32_t g_networkBroadcastMode, g_movesPerPacket;
122 
123 G_EXTERN int32_t g_animWallCnt;
124 G_EXTERN int32_t g_animateCnt;
125 G_EXTERN int32_t g_cloudCnt;
126 G_EXTERN int32_t g_curViewscreen;
127 G_EXTERN int32_t g_frameRate;
128 G_EXTERN int32_t g_cyclerCnt;
129 G_EXTERN int32_t g_damageCameras;
130 G_EXTERN int32_t g_defaultLabelCnt;
131 G_EXTERN int32_t g_doQuickSave;
132 G_EXTERN int32_t g_earthquakeTime;
133 G_EXTERN int32_t g_freezerSelfDamage;
134 G_EXTERN int32_t g_gameQuit;
135 G_EXTERN int32_t g_globalRandom;
136 G_EXTERN int32_t g_labelCnt;
137 G_EXTERN int32_t g_maxPlayerHealth;
138 G_EXTERN int32_t g_mirrorCount;
139 G_EXTERN int32_t g_mostConcurrentPlayers;
140 G_EXTERN int32_t g_musicSize;
141 G_EXTERN int32_t g_playerSpawnCnt;
142 G_EXTERN int32_t g_scriptDebug;
143 G_EXTERN int32_t g_showShareware;
144 G_EXTERN int32_t g_spriteDeleteQueuePos;
145 G_EXTERN int32_t g_startArmorAmount;
146 G_EXTERN int32_t g_tripbombLaserMode;
147 G_EXTERN int32_t screenpeek;
148 
149 G_EXTERN int16_t g_animateSect[MAXANIMATES];
150 G_EXTERN int32_t *g_animatePtr[MAXANIMATES];
151 G_EXTERN int32_t g_animateGoal[MAXANIMATES];
152 G_EXTERN int32_t g_animateVel[MAXANIMATES];
153 
154 G_EXTERN int16_t g_cloudSect[256];
155 G_EXTERN int16_t g_cloudX;
156 G_EXTERN int16_t g_cloudY;
157 G_EXTERN ClockTicks g_cloudClock;
158 
159 G_EXTERN int16_t SpriteDeletionQueue[1024];
160 G_EXTERN int16_t g_cyclers[MAXCYCLERS][6];
161 G_EXTERN int16_t g_mirrorSector[64];
162 G_EXTERN int16_t g_mirrorWall[64];
163 G_EXTERN int32_t *labelcode;
164 G_EXTERN int32_t *labeltype;
165 G_EXTERN ClockTicks lockclock;
166 G_EXTERN ClockTicks ototalclock;
167 
168 G_EXTERN int32_t g_wupass;
169 G_EXTERN int32_t g_chickenPlant;
170 G_EXTERN int32_t g_thunderOn;
171 G_EXTERN int32_t g_ufoSpawn;
172 G_EXTERN int32_t g_ufoCnt;
173 G_EXTERN int32_t g_hulkSpawn;
174 G_EXTERN int32_t g_vixenLevel;
175 G_EXTERN int32_t g_lastLevel;
176 G_EXTERN int32_t g_turdLevel;
177 
178 G_EXTERN int32_t g_mineCartDir[MAXMINECARTS];
179 G_EXTERN int32_t g_mineCartSpeed[MAXMINECARTS];
180 G_EXTERN int32_t g_mineCartChildSect[MAXMINECARTS];
181 G_EXTERN int32_t g_mineCartSound[MAXMINECARTS];
182 G_EXTERN int32_t g_mineCartDist[MAXMINECARTS];
183 G_EXTERN int32_t g_mineCartDrag[MAXMINECARTS];
184 G_EXTERN int32_t g_mineCartOpen[MAXMINECARTS];
185 G_EXTERN int32_t g_mineCartSect[MAXMINECARTS];
186 G_EXTERN uint32_t g_mineCartCnt;
187 
188 G_EXTERN int32_t g_jailDoorSound[MAXJAILDOORS];
189 G_EXTERN int32_t g_jailDoorDrag[MAXJAILDOORS];
190 G_EXTERN int32_t g_jailDoorSpeed[MAXJAILDOORS];
191 G_EXTERN int32_t g_jailDoorSecHitag[MAXJAILDOORS];
192 G_EXTERN int32_t g_jailDoorDist[MAXJAILDOORS];
193 G_EXTERN int32_t g_jailDoorDir[MAXJAILDOORS];
194 G_EXTERN int32_t g_jailDoorOpen[MAXJAILDOORS];
195 G_EXTERN int32_t g_jailDoorSect[MAXJAILDOORS];
196 G_EXTERN uint32_t g_jailDoorCnt;
197 
198 G_EXTERN int32_t g_lightninSector[MAXLIGHTNINSECTORS];
199 G_EXTERN int32_t g_lightninSectorShade[MAXLIGHTNINSECTORS];
200 G_EXTERN uint32_t g_lightninCnt;
201 
202 G_EXTERN int32_t g_torchSector[MAXTORCHSECTORS];
203 G_EXTERN int32_t g_torchSectorShade[MAXTORCHSECTORS];
204 G_EXTERN int32_t g_torchType[MAXTORCHSECTORS];
205 G_EXTERN uint32_t g_torchCnt;
206 
207 G_EXTERN int32_t g_geoSectorWarp[MAXGEOSECTORS];
208 G_EXTERN int32_t g_geoSectorWarp2[MAXGEOSECTORS];
209 G_EXTERN int32_t g_geoSector[MAXGEOSECTORS];
210 G_EXTERN int32_t g_geoSectorX[MAXGEOSECTORS];
211 G_EXTERN int32_t g_geoSectorY[MAXGEOSECTORS];
212 G_EXTERN int32_t g_geoSectorX2[MAXGEOSECTORS];
213 G_EXTERN int32_t g_geoSectorY2[MAXGEOSECTORS];
214 G_EXTERN uint32_t g_geoSectorCnt;
215 
216 G_EXTERN int32_t g_thunderFlash;
217 G_EXTERN int32_t g_thunderTime;
218 G_EXTERN int32_t g_winderFlash;
219 G_EXTERN int32_t g_winderTime;
220 G_EXTERN int32_t g_brightness;
221 
222 G_EXTERN int16_t g_ambientLotag[64];
223 G_EXTERN int16_t g_ambientHitag[64];
224 G_EXTERN uint32_t g_ambientCnt;
225 
226 G_EXTERN intptr_t *apScript;
227 G_EXTERN intptr_t *g_scriptPtr;
228 
229 G_EXTERN map_t g_mapInfo[(MAXVOLUMES + 1) * MAXLEVELS];  // +1 volume for "intro", "briefing" and "loading" music
230 G_EXTERN vec2_t g_origins[MAXANIMPOINTS];
231 
232 G_EXTERN int32_t g_windTime, g_windDir;
233 G_EXTERN int16_t g_fakeBubbaCnt, g_mamaSpawnCnt, g_banjoSong, g_bellTime, g_bellSprite;
234 G_EXTERN uint8_t g_spriteExtra[MAXSPRITES], g_sectorExtra[MAXSECTORS];
235 G_EXTERN uint8_t g_changeEnemySize, g_slotWin, g_ufoSpawnMinion, g_pistonSound, g_chickenWeaponTimer, g_RAendLevel, g_RAendEpisode, g_fogType;
236 G_EXTERN int32_t g_cdTrack;
237 
238 // XXX: I think this pragma pack is meaningless here.
239 // MSDN (https://msdn.microsoft.com/en-us/library/2e70t5y1%28VS.80%29.aspx) says:
240 // "pack takes effect at the first struct, union, or class declaration after
241 //  the pragma is seen; pack has no effect on definitions."
242 #pragma pack(push,1)
243 #ifdef global_c_
244 static playerdata_t g_player_s[1 + MAXPLAYERS];
245 playerdata_t *const g_player = &g_player_s[1];
246 #else
247 extern playerdata_t *const g_player;
248 #endif
249 G_EXTERN playerspawn_t g_playerSpawnPoints[MAXPLAYERS];
250 G_EXTERN input_t inputfifo[MOVEFIFOSIZ][MAXPLAYERS];
251 #pragma pack(pop)
252 
253 G_EXTERN char g_soundlocks[MAXSOUNDS];
254 G_EXTERN int32_t g_noEnemies;
255 G_EXTERN int32_t g_restorePalette;
256 G_EXTERN int32_t g_screenCapture;
257 G_EXTERN sound_t g_sounds[MAXSOUNDS];
258 G_EXTERN uint32_t everyothertime;
259 G_EXTERN uint32_t g_moveThingsCount;
260 G_EXTERN double g_gameUpdateTime;
261 G_EXTERN double g_gameUpdateAndDrawTime;
262 #define GAMEUPDATEAVGTIMENUMSAMPLES 100
263 extern float g_gameUpdateAvgTime;
264 
265 #ifndef global_c_
266 extern char CheatKeys[2];
267 extern char g_gametypeNames[MAXGAMETYPES][33];
268 extern char g_setupFileName[BMAX_PATH];
269 extern char g_skillNames[MAXSKILLS][33];
270 extern char g_volumeNames[MAXVOLUMES][33];
271 
272 extern int32_t g_actorRespawnTime;
273 extern int32_t g_bouncemineRadius;
274 extern int32_t g_deleteQueueSize;
275 extern int32_t g_gametypeCnt;
276 extern int32_t g_itemRespawnTime;
277 extern int32_t g_morterRadius;
278 extern int32_t g_numFreezeBounces;
279 extern int32_t g_pipebombRadius;
280 extern int32_t g_playerFriction;
281 extern int32_t g_rpgRadius;
282 extern int32_t g_scriptSize;
283 extern int32_t g_seenineRadius;
284 extern int32_t g_shrinkerRadius;
285 extern int32_t g_spriteGravity;
286 extern int32_t g_timerTicsPerSecond;
287 extern int32_t g_tripbombRadius;
288 extern int32_t g_impactDamage;
289 extern int32_t g_volumeCnt;
290 
291 extern int16_t g_blimpSpawnItems[15];
292 extern int32_t g_gametypeFlags[MAXGAMETYPES];
293 extern int32_t g_volumeFlags[MAXVOLUMES];
294 
295 extern const char *s_buildDate;
296 #endif
297 
298 enum
299 {
300     EF_HIDEFROMSP = 1<<0,
301     // EF_HIDEFROMMP = 1<<1,
302 };
303 
304 EXTERN_INLINE_HEADER void G_UpdateInterpolations(void);
305 EXTERN_INLINE_HEADER void G_RestoreInterpolations(void);
306 
307 #ifdef __cplusplus
308 }
309 #endif
310 
311 #if defined global_c_ || !defined DISABLE_INLINING
312 
G_UpdateInterpolations(void)313 EXTERN_INLINE void G_UpdateInterpolations(void)  //Stick at beginning of G_DoMoveThings
314 {
315     for (bssize_t i=g_interpolationCnt-1; i>=0; i--) oldipos[i] = *curipos[i];
316 }
317 
G_RestoreInterpolations(void)318 EXTERN_INLINE void G_RestoreInterpolations(void)  //Stick at end of drawscreen
319 {
320     int32_t i=g_interpolationCnt-1;
321 
322     if (--g_interpolationLock)
323         return;
324 
325     for (; i>=0; i--) *curipos[i] = bakipos[i];
326 }
327 
328 #endif
329 
330 #endif
331