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