Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
278 lines (216 loc) · 6.78 KB
/
Copy pathmain.cpp
File metadata and controls
278 lines (216 loc) · 6.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
#ifdef _WIN32
#include <windows.h>
#include <windowsx.h>
#else
#include <sys/time.h>
#include <time.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include "SDL/SDL.h"
#include "SDL/SDL_mixer.h"
#include "list.h"
#include "vector.h"
#include "cmc.h"
#include "3dobject.h"
#include "shadow3dobject.h"
#include "piece3dobject.h"
#include "nether.h"
/* GLOBAL VARIABLES INITIALIZATION: */
int SCREEN_X=640;
int SCREEN_Y=480;
int COLOUR_DEPTH=32;
int shadows=1;
int detaillevel=4;
bool sound=true;
int up_key=SDLK_q,down_key=SDLK_a,left_key=SDLK_o,right_key=SDLK_p,fire_key=SDLK_SPACE,pause_key=SDLK_F1;
int level=1;
int mainmenu_status=0;
int mainmenu_substatus=0;
bool fullscreen=false;
bool show_radar=true;
char mapname[128]="original.map";
C3DObject *nethertittle=0;
/* DRAWING REGION AROUND THE SHIP: */
float MINY=-8,MAXY=8,MINX=-8,MAXX=8;
/* Redrawing constant: */
const int REDRAWING_PERIOD=20;
/* Frames per second counter: */
int frames_per_sec=0;
int frames_per_sec_tmp=0;
int init_time=0;
/* Surfaces: */
SDL_Surface *screen_sfc;
NETHER *game=0;
void save_configuration(void);
void load_configuration(void);
int mainmenu_cycle(int width,int height);
void mainmenu_draw(int width,int height);
/* AUXILIAR FUNCTION DEFINITION: */
void pause(unsigned int time)
{
unsigned int initt=SDL_GetTicks();
while((SDL_GetTicks()-initt)<time);
} /* pause */
SDL_Surface *initialization(int flags)
{
const SDL_VideoInfo* info=0;
int bpp=0;
SDL_Surface *screen;
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)<0) {
fprintf(stderr,"Video initialization failed: %s\n",SDL_GetError());
return 0;
} /* if */
info=SDL_GetVideoInfo();
if(!info) {
fprintf(stderr,"Video query failed: %s\n",SDL_GetError());
return 0;
} /* if */
if (fullscreen) {
bpp=COLOUR_DEPTH;
} else {
bpp=info->vfmt->BitsPerPixel;
} /* if */
SDL_GL_SetAttribute(SDL_GL_RED_SIZE,8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE,1);
flags=SDL_OPENGL|flags;
screen=SDL_SetVideoMode(SCREEN_X,SCREEN_Y,bpp,flags);
if(screen==0) {
fprintf(stderr,"Video mode set failed: %s\n",SDL_GetError());
return 0;
} /* if */
pause(400);
if (Mix_OpenAudio(22050, AUDIO_S16, 2, 1024)) {
return 0;
} /* if */
SDL_WM_SetCaption("Nether Earth REMAKE v0.52", 0);
SDL_ShowCursor(SDL_DISABLE);
return screen;
} /* initialization */
void finalization()
{
Mix_CloseAudio();
SDL_Quit();
} /* finalization */
#ifdef _WIN32
int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
#else
int main(int argc, char** argv)
{
#endif
int time,act_time;
SDL_Event event;
bool quit = false;
load_configuration();
screen_sfc = initialization((fullscreen ? SDL_FULLSCREEN : 0));
if (screen_sfc==0) return 0;
time=init_time=SDL_GetTicks();
while (!quit) {
while( SDL_PollEvent( &event ) ) {
switch( event.type ) {
/* Keyboard event */
case SDL_KEYDOWN:
if (event.key.keysym.sym==SDLK_F12) quit = true;
if (event.key.keysym.sym==SDLK_RETURN) {
SDLMod modifiers;
modifiers=SDL_GetModState();
if ((modifiers&KMOD_ALT)!=0) {
/* Toogle FULLSCREEN mode: */
if (game!=0) game->refresh_display_lists();
if (nethertittle!=0) nethertittle->refresh_display_lists();
if (game!=0) game->deleteobjects();
if (fullscreen) fullscreen=false;
else fullscreen=true;
SDL_QuitSubSystem(SDL_INIT_VIDEO);
SDL_InitSubSystem(SDL_INIT_VIDEO);
if (SDL_WasInit(SDL_INIT_VIDEO)) {
SDL_GL_SetAttribute(SDL_GL_RED_SIZE,8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE,1);
screen_sfc = SDL_SetVideoMode(SCREEN_X, SCREEN_Y, COLOUR_DEPTH, SDL_OPENGL|(fullscreen ? SDL_FULLSCREEN : 0));
if (game!=0) game->loadobjects();
SDL_WM_SetCaption("Nether Earth REMAKE v0.5", 0);
SDL_ShowCursor(SDL_DISABLE);
} else {
quit = true;
} /* if */
} /* if */
} /* if */
break;
/* SDL_QUIT event (window close) */
case SDL_QUIT:
quit = true;
break;
} /* switch */
} /* while */
act_time=SDL_GetTicks();
if (act_time-time>=REDRAWING_PERIOD)
{
frames_per_sec_tmp+=1;
if ((act_time-init_time)>=1000) {
frames_per_sec=frames_per_sec_tmp;
frames_per_sec_tmp=0;
init_time=act_time;
} /* if */
do {
time+=REDRAWING_PERIOD;
if ((act_time-time)>50*REDRAWING_PERIOD) time=act_time;
if (game!=0) {
if (!game->gamecycle(SCREEN_X,SCREEN_Y)) {
delete game;
game=0;
mainmenu_status=0;
mainmenu_substatus=0;
} /* if */
} else {
int val=mainmenu_cycle(SCREEN_X,SCREEN_Y);
if (val==1) {
char tmp[256];
sprintf(tmp,"maps/%s",mapname);
game=new NETHER(tmp);
} /* if */
if (val==2) quit=true;
if (val==3) {
if (game!=0) game->refresh_display_lists();
if (nethertittle!=0) nethertittle->refresh_display_lists();
if (game!=0) game->deleteobjects();
SDL_QuitSubSystem(SDL_INIT_VIDEO);
SDL_InitSubSystem(SDL_INIT_VIDEO);
if (SDL_WasInit(SDL_INIT_VIDEO)) {
SDL_GL_SetAttribute(SDL_GL_RED_SIZE,8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE,1);
screen_sfc = SDL_SetVideoMode(SCREEN_X, SCREEN_Y, COLOUR_DEPTH, SDL_OPENGL|(fullscreen ? SDL_FULLSCREEN : 0));
if (game!=0) game->loadobjects();
SDL_WM_SetCaption("Nether Earth REMAKE v0.5", 0);
SDL_ShowCursor(SDL_DISABLE);
} else {
quit = true;
} /* if */
} /* if */
} /* if */
act_time=SDL_GetTicks();
} while(act_time-time>=REDRAWING_PERIOD);
if (game!=0) {
game->gameredraw(SCREEN_X,SCREEN_Y);
} else {
mainmenu_draw(SCREEN_X,SCREEN_Y);
} /* if */
} /* if */
} /* while */
delete game;
finalization();
return 0;
}