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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
|
/*
* PARSEC - Main Module
*
* $Author: uberlinuxguy $ - $Date: 2004/09/26 03:43:41 $
*
* Orginally written by:
* Copyright (c) Markus Hadwiger <msh@parsec.org> 1998-2000
Updated By:
Copyright (c) 2003 Sivaram Velauthapillai (sivaram33@hotmail.com or koalabear33@yahoo.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
UPDATES:
August 25, 2003:
+ Removed initialization of the old GSI sound server. OpenAL does not require
it
*/
// compilation flags/debug support
#include "config.h"
// C library includes
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// general definitions
#include "general.h"
#include "objstruc.h"
// global externals
#include "globals.h"
#include "debug.h"
// subsystem headers
#include "aud_defs.h"
#include "inp_defs.h"
#include "net_defs.h"
#include "sys_defs.h"
#include "vid_defs.h"
// local module header
#include "sl_main.h"
// proprietary module headers
#include "con_main.h"
#include "con_rc.h"
#include "e_color.h"
#include "e_events.h"
#include "e_loader.h"
#include "g_boot.h"
#include "g_gameloop.h"
#include "h_supp.h"
#include "inp_init.h"
#include "part_sys.h"
#include "sys_bind.h"
#include "sys_conv.h"
#include "sys_file.h"
#include "vid_init.h"
#ifdef SYSTEM_TARGET_LINUX
#include <SDL/SDL.h>
#else
#include <SDL.h>
#endif
#ifdef SYSTEM_TARGET_OSX
#include <CoreFoundation/CoreFoundation.h>
#endif
// flags
//#define SHOW_MEMORY_INFO_BEFORE_BOOT
#define SKIP_DEMO_INTRO
#define START_NETGAME_AFTER_DEMOINTRO
// file package location control
//#define LOAD_DATA_FROM_EXE
// size of parsec executable [bytes]
// used to load data directly from it
#define PARSEC_EXE_SIZE 396860
// info about separate data file
#ifdef LOAD_DATA_FROM_EXE
#define DATA_PACKAGE_NAME sys_ProgramName
#define DATA_PACKAGE_OFFSET PARSEC_EXE_SIZE
#else // LOAD_DATA_FROM_EXE
#define DATA_PACKAGE_NAME extra_pack_name
#define DATA_PACKAGE_OFFSET extra_pack_offset
static char extra_pack_name[] = "pscdata0.dat";
static size_t extra_pack_offset = 0;
#endif // LOAD_DATA_FROM_EXE
// define macro responsible for intro invocation
#ifndef SKIP_DEMO_INTRO
#define PLAYDEMOINTRO() PlayDemoIntro()
#else
#define PLAYDEMOINTRO() TRUE
#endif
// string constants
static char joystick_disabled[] = "Joystick code is disabled.\n";
static char exiting_game[] = "Exiting Parsec...\n";
#ifndef SYSTEM_TARGET_WINDOWS
// emulate missing or differently named c library functions -------------------
//
int stricmp( const char *s1, const char *s2 )
{
return strcasecmp( s1, s2 );
}
int strnicmp( const char *s1, const char *s2, int len )
{
return strncasecmp( s1, s2, len );
}
char *strlwr( char *str )
{
for ( char *scan = str; *scan; scan++ ) {
*scan = tolower( *scan );
}
return str;
}
char *strupr( char *str )
{
for ( char *scan = str; *scan; scan++ ) {
*scan = toupper( *scan );
}
return str;
}
#endif
#ifdef SYSTEM_TARGET_OSX
static char macresourcespath[1024];
// get absolute path to Parsec.app/Contents/Resources/, so we can chdir to it
//
PRIVATE
const char * SLm_GetMacResourcesPath()
{
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
CFURLRef absoluteResourcesURL = CFURLCopyAbsoluteURL(resourcesURL);
CFStringRef cfResourcesStringRef = CFURLCopyFileSystemPath(absoluteResourcesURL, kCFURLPOSIXPathStyle);
CFStringGetCString(cfResourcesStringRef, macresourcespath, sizeof(macresourcespath), kCFStringEncodingASCII);
CFRelease(resourcesURL);
CFRelease(absoluteResourcesURL);
CFRelease(cfResourcesStringRef);
return macresourcespath;
}
#endif
// check available memory -----------------------------------------------------
//
void SYSs_CheckMemory()
{
//TODO:
}
// cancel game mode -----------------------------------------------------------
//
INLINE
void SLm_GameCancel()
{
// cancel game sound
AUDs_CloseGameSound();
}
// start up game --------------------------------------------------------------
//
INLINE
int SLm_StartUpGame()
{
// init game state and enter main menu
if ( !GameBoot() )
return FALSE;
if ( GameInit( NETWORK_GAME_ON ) ) {
// enter gameloop
GameLoop();
// cancel game sound
AUDs_CloseGameSound();
}
// quit game
return TRUE;
}
// calibrate and init joystick ------------------------------------------------
//
INLINE
void SLm_InitJoystickCode()
{
if ( !SkipCalibrationCode ) {
// IL_CalibrateJoystick();
Op_Joystick = QueryJoystick;
JoystickDisabled = !QueryJoystick;
} else {
QueryJoystick = 0;
Op_Joystick = 0;
JoystickDisabled = 1;
MSGOUT( joystick_disabled );
}
}
// init sound -----------------------------------------------------------------
//
INLINE
void SLm_InitSound()
{
// init sound system if soundcard installed
SoundAvailable = AUDs_InitSoundSys();
Op_SoundEffects = SoundAvailable;
Op_Music = SoundAvailable;
}
// package string constants ---------------------------------------------------
//
static char package_error[] = "Data package error: file %s";
static char package_name_1[] = "pscdata1.dat";
static char package_name_2[] = "pscdata2.dat";
static char package_name_3[] = "pscdata3.dat";
// init file system -----------------------------------------------------------
//
INLINE
void SLm_InitFileSystem()
{
// make sure mp3s contained in sound package are converted to wav
if ( !SYS_ConvertPackageMP3s( package_name_2, 0 ) ) {
FERROR( package_error, package_name_2 );
}
// register mandatory main data package
if ( !SYS_RegisterPackage( DATA_PACKAGE_NAME, DATA_PACKAGE_OFFSET, NULL ) ) {
FERROR( package_error, DATA_PACKAGE_NAME );
}
// register optional package 1
SYS_RegisterPackage( package_name_1, 0, NULL);
// register optional data package
SYS_RegisterPackage( package_name_2, 0, NULL );
// register third package (new data introduced with build 0196)
SYS_RegisterPackage( package_name_3, 0, NULL );
// duplicate files in pscdata2.dat with newer versions in pscdata3.dat
SYS_OverridePackage( package_name_2, package_name_3 );
if(!SYS_CheckDataVersion()){
MSGOUT("ERROR: OpenParsec Data File Version Mismatch!");
exit(1);
}
}
// free globally allocated storage buffers ------------------------------------
//
INLINE
void SLm_FreeBuffers()
{
FreeLoaderDataBuffers();
}
// free resources and perform other exit functions ----------------------------
//
void SL_CleanUp()
{
// write rc script
WritePersistentCommands();
// kill the event manager
EVT_KillManager();
// kill game systems
KillParticleSystem();
KillConsole();
KillColorMaps();
// kill networking system;
// must not be done after SYSs_KillFrameTimer()
NETs_KillAPI();
// kill input code
INP_KillSubsystem();
// kill sound system
AUDs_KillSoundSys();
// kill timer code
SYSs_KillFrameTimer();
// free global buffers
SLm_FreeBuffers();
MSGOUT( exiting_game );
}
// system entry point ---------------------------------------------------------
//
int main( int argc, char **argv )
{
#ifdef DMALLOC
/*
* Get environ variable DMALLOC_OPTIONS and pass the settings string
* on to dmalloc_debug_setup to setup the dmalloc debugging flags.
*/
dmalloc_debug_setup(getenv("DMALLOC_OPTIONS"));
#endif
#ifdef SYSTEM_TARGET_OSX
chdir(SLm_GetMacResourcesPath());
#endif
// set program name (used in error messages)
sys_ProgramName = argv[ 0 ];
// this is the first thing we must do in order to resemble the old module registration
TheModuleManager->InitAllModules();
// check command line options
SYSs_CheckCommandLine( argc, argv );
// bind dynamic subsystem functions
SYS_BindDynamicFunctions();
// init error handling
SYSs_InitErrorHandling();
// display startup messages
StartupMessages();
// check available memory
SYSs_CheckMemory();
// init extended file system
SLm_InitFileSystem();
// init video subsystem
VID_InitSubsystem();
// read objects and other data into memory
LoadData( FetchCtrlFileName(), TRUE );
// init networking api
NETs_InitAPI();
// init sound system
SLm_InitSound();
// calibrate joystick
SLm_InitJoystickCode();
// init game and start gameloop
SLm_StartUpGame();
// restore original display mode
VIDs_RestoreDisplay();
// clean up and exit
SL_CleanUp();
return EXIT_SUCCESS;
}
|