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