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