]> git.jsancho.org Git - lugaru.git/blob - Source/Game.h
HUGE refactoring:
[lugaru.git] / Source / Game.h
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3
4 This file is part of Lugaru.
5
6 Lugaru is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */
21
22 #ifndef _GAME_H_
23 #define _GAME_H_
24
25 #include "SDL.h"
26
27 #if (defined(__APPLE__) && defined(__MACH__))
28 #  ifdef PLATFORM_MACOSX
29 #    error Do not define PLATFORM_MACOSX for new builds. It is for the old Carbonized build.
30 #  endif
31 #endif
32
33 #ifdef PLATFORM_MACOSX
34 #include <Carbon.h>
35 #include "Quicktime.h"
36 #endif
37
38 //Jordan included glut.h
39 //#include <glut.h>
40
41 #include "TGALoader.h"
42
43 #if !PLATFORM_MACOSX
44 #include "WinInput.h"
45 #else
46 #include "Macinput.h"
47 #endif
48
49 #include "Terrain.h"
50 #include "Skybox.h"
51 #include "Skeleton.h"
52 #include "Models.h"
53 #include "Lights.h"
54 #include "Person.h"
55 #include "Constants.h"
56 #include "Sprites.h"
57 //#include <agl.h>
58 #include "Text.h"
59 #include "Objects.h"
60 //#include <DrawSprocket.h>
61 #include "Weapons.h"
62 #include "binio.h"
63 #include <fstream>
64 #include "gamegl.h"
65 #include "Stereo.h"
66 #include "Account.h"
67
68 extern GLuint rabbittexture;
69
70 class Game
71 {
72         public:
73                 typedef std::map<std::string, GLuint> TextureList;
74                 typedef std::map<GLuint, std::string> GLTextureList;
75                 typedef TextureList::iterator TexIter;
76                 static TextureList textures;
77
78                 GLuint terraintexture;
79                 GLuint terraintexture2;
80                 GLuint terraintexture3;
81                 GLuint screentexture;
82                 GLuint screentexture2;
83                 GLuint logotexture;
84                 GLuint loadscreentexture;
85                 GLuint Maparrowtexture;
86                 GLuint Mapboxtexture;
87                 GLuint Mapcircletexture;
88                 GLuint cursortexture;
89                 GLuint Mainmenuitems[10];
90
91                 int nummenuitems;
92                 int startx[100];
93                 int starty[100];
94                 int endx[100];
95                 int endy[100];
96                 float selectedlong[100];
97                 float offsetx[100];
98                 float offsety[100];
99                 float movex[100];
100                 float movey[100];
101                 float transition;
102                 int anim;
103                 int selected;
104                 int keyselect;
105                 int loaddistrib;
106                 int indemo;
107
108                 bool won;
109
110                 bool entername;
111
112                 char menustring[100][256];
113                 char registrationname[256];
114                 float registrationnumber;
115
116                 int newdetail;
117                 int newscreenwidth;
118                 int newscreenheight;
119
120                 bool gameon;
121                 float deltah,deltav;
122                 int mousecoordh,mousecoordv;
123                 int oldmousecoordh,oldmousecoordv;
124                 float rotation,rotation2;
125                 SkyBox skybox;
126                 bool cameramode;
127                 bool cameratogglekeydown;
128                 bool chattogglekeydown;
129                 int olddrawmode;
130                 int drawmode;
131                 bool drawmodetogglekeydown;
132                 bool explodetogglekeydown;
133                 bool detailtogglekeydown;
134                 bool firstload;
135                 bool oldbutton;
136
137                 float leveltime;
138                 float loadtime;
139
140                 Model hawk;
141                 XYZ hawkcoords;
142                 XYZ realhawkcoords;
143                 GLuint hawktexture;
144                 float hawkrotation;
145                 float hawkcalldelay;
146
147                 Model eye;
148                 Model iris;
149                 Model cornea;
150
151                 bool stealthloading;
152
153                 int campaignnumlevels;
154                 char campaignmapname[50][256];
155                 char campaigndescription[50][256];
156                 int campaignchoosenext[50];
157                 int campaignnumnext[50];
158                 int campaignnextlevel[50][10];
159                 int campaignchoicesmade;
160                 int campaignchoices[5000];
161                 int campaignlocationx[50];
162                 int campaignlocationy[50];
163                 int campaignchoicenum;
164                 int campaignchoicewhich[10];
165                 int whichchoice;
166
167                 int numlevelspassed;
168                 int levelorder[5000];
169                 int levelvisible[50];
170                 int levelhighlight[50];
171
172                 bool minimap;
173
174                 int musictype,oldmusictype,oldoldmusictype;
175                 bool realthreat;
176
177                 Model rabbit;
178                 XYZ rabbitcoords;
179
180                 XYZ mapcenter;
181                 float mapradius;
182
183                 Text text;
184                 float fps;
185
186                 XYZ cameraloc;
187                 float cameradist;
188
189                 bool envtogglekeydown;
190                 bool slomotogglekeydown;
191                 bool texturesizetogglekeydown;
192                 bool freezetogglekeydown;
193                 int drawtoggle;
194
195                 bool editorenabled;
196                 int editortype;
197                 float editorsize;
198                 float editorrotation;
199                 float editorrotation2;
200
201                 float brightness;
202
203                 int quit;
204                 int tryquit;
205
206                 XYZ pathpoint[30];
207                 int numpathpoints;
208                 int numpathpointconnect[30];
209                 int pathpointconnect[30][30];
210                 int pathpointselected;
211
212                 int endgame;
213                 bool scoreadded;
214                 int numchallengelevels;
215
216                 bool console;
217                 int archiveselected;
218                 char consoletext[15][256];
219                 int consolechars[15];
220                 bool chatting;
221                 char displaytext[15][256];
222                 int displaychars[15];
223                 float displaytime[15];
224                 float displayblinkdelay;
225                 bool displayblink;
226                 int displayselected;
227                 bool consolekeydown;
228                 bool consoletogglekeydown;
229                 float consoleblinkdelay;
230                 bool consoleblink;
231                 int consoleselected;
232                 int togglekey[140];
233                 float togglekeydelay[140];
234                 bool registernow;
235                 bool autocam;
236
237                 unsigned short crouchkey,jumpkey,forwardkey,chatkey,backkey,leftkey,rightkey,drawkey,throwkey,attackkey;
238                 bool oldattackkey;
239
240                 long long MD5_string (char *string);
241                 static void LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha);
242                 static void LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize);
243                 void LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize);
244                 bool AddClothes(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize);
245                 void InitGame();
246                 void LoadStuff();
247                 void LoadingScreen();
248                 void FadeLoadingScreen(float howmuch);
249                 void Dispose();
250                 int DrawGLScene(StereoSide side);
251                 void Tick();
252                 void TickOnce();
253                 void TickOnceAfter();
254                 void SetUpLighting();
255                 void Loadlevel(int which);
256                 void Loadlevel(char *name);
257                 void LoadSounds();
258                 void Setenvironment(int which);
259                 GLvoid ReSizeGLScene(float fov, float near);
260                 int findPathDist(int start,int end);
261                 int checkcollide(XYZ startpoint, XYZ endpoint);
262                 int checkcollide(XYZ startpoint, XYZ endpoint, int what);
263                 int loading;
264                 float talkdelay;
265                 
266                 void fireSound(int sound=fireendsound);
267                 void setKeySelected();
268
269                 int numboundaries;
270                 XYZ boundary[360];
271
272                 int whichlevel;
273                 int oldenvironment;
274                 int targetlevel;
275                 float changedelay;
276
277                 float musicvolume[4];
278                 float oldmusicvolume[4];
279                 int musicselected;
280                 int change;
281                 Game();
282                 ~Game() {
283                         for(int i=0;i<10;i++){
284                                 if(Mainmenuitems[i])glDeleteTextures( 1, &Mainmenuitems[i] );
285                         }
286                         glDeleteTextures( 1, &cursortexture );
287                         glDeleteTextures( 1, &Maparrowtexture );
288                         glDeleteTextures( 1, &Mapboxtexture );
289                         glDeleteTextures( 1, &Mapcircletexture );
290                         glDeleteTextures( 1, &terraintexture );
291                         glDeleteTextures( 1, &terraintexture2 );
292                         if(screentexture>0)glDeleteTextures( 1, &screentexture );
293                         if(screentexture2>0)glDeleteTextures( 1, &screentexture2 );
294                         glDeleteTextures( 1, &hawktexture );
295                         glDeleteTextures( 1, &logotexture );
296                         glDeleteTextures( 1, &loadscreentexture );
297
298                         Dispose();
299                 }
300                 bool isWaiting() { return waiting; };
301         private:
302                 void setKeySelected_thread();
303                 static int thread(void *data);
304                 void inputText();
305                 void inputText_thread();
306                 void flash();
307                 bool waiting;
308                 bool mainmenutogglekeydown;
309                 //int mainmenu;
310                 Account* accountactive;
311 };
312
313 #ifndef __forceinline
314 #  ifdef __GNUC__
315 #    define __forceinline inline __attribute__((always_inline))
316 #  endif
317 #endif
318
319 static __forceinline void swap_gl_buffers(void)
320 {
321
322     SDL_GL_SwapBuffers();
323
324 }
325
326 #ifdef __GNUC__
327 #define LONGLONGCONST(x) (x##ll)
328 #else
329 #define LONGLONGCONST(x) (x)
330 #endif
331
332 extern "C" { void UndefinedSymbolToExposeStubbedCode(void); }
333 //#define STUBBED(x) UndefinedSymbolToExposeStubbedCode();
334 #define STUBBED(x) { static bool seen = false; if (!seen) { seen = true; fprintf(stderr, "STUBBED: %s at %s:%d\n", x, __FILE__, __LINE__); } }
335 //#define STUBBED(x)
336
337 #endif