21 #include "audio/test.h"
22 #if defined (HAVE_SDL)
25 #include "cmd/role_bitmask.h"
26 #if defined (WITH_MACOSX_BUNDLE)
38 #include "cmd/script/mission.h"
43 #include "gfx/animation.h"
45 #include "gfx/cockpit.h"
46 #include "python/init.h"
50 #include "gldrv/winsys.h"
52 #include "networking/netclient.h"
55 #include "gfx/masks.h"
56 #include "cmd/music.h"
61 #include "audio/SceneManager.h"
62 #include "audio/TemplateManager.h"
63 #include "audio/renderers/OpenAL/BorrowedOpenALRenderer.h"
66 #if !defined(_WIN32) && !defined (__HAIKU__)
67 #include <sys/signal.h>
70 #if defined (_MSC_VER) && defined (_DEBUG)
74 #if defined (CG_SUPPORT)
93 static bool ignore_network =
true;
97 ignore_network = !usenetwork;
142 Music::CleanupMuzak();
149 printf(
"Thank you for playing!\n" );
151 if (_Universe != NULL &&
Network == NULL)
154 #if defined (_MSC_VER) && defined (_DEBUG)
156 _RPT0( _CRT_ERROR,
"WARNING: Vega Strike exit not clean\n" );
164 cout<<
"Number of players"<<_Universe->
numPlayers()<<endl;
165 for (
size_t i = 0; i < _Universe->
numPlayers(); i++)
170 #if defined (CG_SUPPORT)
171 if (cloak_cg->vertexProgram) cgDestroyProgram( cloak_cg->vertexProgram );
172 if (cloak_cg->shaderContext) cgDestroyContext( cloak_cg->shaderContext );
174 Music::CleanupMuzak();
186 #if defined (WITH_MACOSX_BUNDLE)
193 cout <<
"Creating scene manager..." << endl;
194 Audio::SceneManager *sm = Audio::SceneManager::getSingleton();
196 cout <<
"Creating template manager..." << endl;
197 Audio::TemplateManager::getSingleton();
199 if (Audio::SceneManager::getSingleton() == 0)
200 throw Audio::Exception(
"Singleton null after SceneManager instantiation");
207 cerr <<
" Initializing renderer..." << endl;
208 Audio::SceneManager *sm = Audio::SceneManager::getSingleton();
211 SharedPtr<Audio::Renderer> renderer(
new Audio::BorrowedOpenALRenderer);
212 renderer->setMeterDistance(1.0);
213 renderer->setDopplerFactor(0.0);
215 sm->setRenderer( renderer );
221 Audio::SceneManager *sm = Audio::SceneManager::getSingleton();
223 sm->createScene(
"video");
224 sm->createScene(
"music");
225 sm->createScene(
"cockpit");
226 sm->createScene(
"base");
227 sm->createScene(
"space");
229 sm->setSceneActive(
"video",
true);
234 cerr <<
"Shutting down renderer..." << endl;
235 Audio::SceneManager::getSingleton()->setRenderer( SharedPtr<Audio::Renderer>() );
241 int main(
int argc,
char *argv[] )
248 if (NULL != getcwd( pwd, 8191 )) {
250 printf(
" In path %s\n", pwd );
252 printf(
" In path <<path too long>>\n" );
257 ZeroMemory( &osvi,
sizeof (OSVERSIONINFO) );
258 osvi.dwOSVersionInfoSize =
sizeof (OSVERSIONINFO);
260 GetVersionEx( &osvi );
261 isVista = (osvi.dwMajorVersion == 6);
262 printf(
"Windows version %d %d\n", osvi.dwMajorVersion, osvi.dwMinorVersion );
265 printf(
"Vega Strike " " \n"
266 "See http://www.gnu.org/copyleft/gpl.html for license details.\n\n" );
269 srand( time( NULL ) );
278 cerr<<
"GOT SUBDIR ARG = "<<subdir<<endl;
295 ignore_network =
false;
298 std::string defmis =
vs_config->
getVariable(
"general",
"default_mission",
"test/test1.mission" );
301 cerr<<
"MISSION_NAME is empty using : "<<mission_name<<endl;
317 std::vector<std::vector <char > > temp = ROLES::getAllRolePriorities();
318 #if defined(HAVE_SDL)
319 #ifndef NO_SDL_JOYSTICK
320 if ( SDL_InitSubSystem( SDL_INIT_JOYSTICK ) ) {
360 static Animation *SplashScreen = NULL;
361 static bool BootstrapMyStarSystemLoading =
true;
364 BootstrapMyStarSystemLoading = value;
368 return BootstrapMyStarSystemLoading;
380 static Animation *ani = NULL;
381 static bool reentryWatchdog =
false;
382 if (!BootstrapMyStarSystemLoading || reentryWatchdog)
385 if (SplashScreen == NULL && newSplashScreen == NULL) {
391 reentryWatchdog =
true;
392 if (newSplashScreen != NULL)
393 ani = newSplashScreen;
398 BootstrapMyStarSystemLoading =
false;
400 BootstrapMyStarSystemLoading =
true;
414 bs_tp->SetPos( -.99, -.97 );
415 bs_tp->SetCharSize( .4, .8 );
416 ScaleMatrix( tmp, Vector( 6500, 6500, 0 ) );
426 static std::string defaultbootmessage =
vs_config->
getVariable(
"graphics",
"default_boot_message",
"" );
427 static std::string initialbootmessage =
vs_config->
getVariable(
"graphics",
"initial_boot_message",
"Loading..." );
428 bs_tp->Draw( defaultbootmessage.length() > 0 ? defaultbootmessage : message.length() > 0 ? message : initialbootmessage );
433 reentryWatchdog =
false;
439 static QVector mysys;
440 static bool isset =
false;
453 static std::string mysys;
454 static bool isset =
false;
467 vector< string > ret;
468 string::size_type index = 0;
469 while ( ( index = s.find(
" " ) ) != string::npos ) {
470 ret.push_back( s.substr( 0, index ) );
471 s = s.substr( index+1 );
479 static std::string ss =
vs_config->
getVariable(
"graphics",
"splash_screen",
"vega_splash.ani" );
485 int snum = time( NULL )%s.size();
486 SplashScreen =
new Animation( s[snum].c_str(), 0 );
487 if ( sa.size() && sa[0].length() )
muzak->GotoSong( sa[snum%sa.size()] );
488 bs_tp =
new TextPlane();
502 static std::string startupview =
vs_config->
getVariable(
"graphics",
"startup_cockpit_view",
"front" );
503 cp->SetView( startupview
504 ==
"view_target" ? CP_TARGET : ( startupview
505 ==
"back" ? CP_BACK : (startupview ==
"chase" ? CP_CHASE : CP_FRONT) ) );
524 mission->GetOrigin( pos, planetname );
525 bool setplayerloc =
false;
526 string mysystem =
mission->getVariable(
"system",
"sol.system" );
530 vector< std::string >playername;
531 vector< std::string >playerpasswd;
532 string pname, ppasswd;
533 for (
int p = 0; p < numplayers; p++) {
540 if (!ignore_network) {
543 cout<<
"Missing or incomlpete section for player "<<p<<endl;
548 playername.push_back( pname );
549 playerpasswd.push_back( ppasswd );
553 string savegamefile =
mission->getVariable(
"savegame",
"" );
554 vector< SavedUnits > savedun;
555 vector< string > playersaveunit;
556 vector< StarSystem* >ss;
557 vector< string > starsysname;
558 vector< QVector > playerNloc;
561 vector< vector< std::string > >savefiles;
562 if (!ignore_network) {
563 cout<<
"Number of local players = "<<numplayers<<endl;
565 if (!ignore_network) {
574 cout<<
"Non-networking mode"<<endl;
582 vector< std::string >::iterator it, jt;
584 for (k = 0, it = playername.begin(), jt = playerpasswd.begin();
589 bool setplayerXloc =
false;
594 _Universe->
AccessCockpit( 0 )->savegame->SetPlayerLocation( myVec );
597 _Universe->
AccessCockpit( 0 )->savegame->SetStarSystem( st );
599 vector< SavedUnits >saved;
601 vector< string > packedInfo;
608 Network[k].SetConfigServerAddress( srvipadr, port );
609 if ( !
Network[k].connectLoad( pname, ppasswd, err ) ) {
610 cout<<
"error while connecting: "<<err<<endl;
613 savefiles.push_back( *
Network[k].loginSavedGame( 0 ) );
628 _Universe->
AccessCockpit( k )->savegame->ParseSaveGame( savegamefile,
637 _Universe->
AccessCockpit( k )->savegame->SetOutputFileName( savegamefile );
642 playersaveunit.push_back( _Universe->
AccessCockpit( k )->GetUnitFileName() );
644 ss.push_back( _Universe->
Init( mysystem, Vector( 0, 0, 0 ), planetname ) );
646 playerNloc.push_back( pos );
648 playerNloc.push_back( QVector( FLT_MAX, FLT_MAX, FLT_MAX ) );
649 setplayerloc = setplayerXloc;
650 for (
unsigned int j = 0;
j < saved.size();
j++)
651 savedun.push_back( saved[
j] );
659 while ( !savedun.empty() ) {
671 "Welcome to Vega Strike! Use #8080FFTab#000000 to afterburn (#8080FF+,-#000000 cruise control), #8080FFarrows#000000 to steer." );
672 if ( !str.empty() ) {
677 "The #8080FFt#000000 key targets objects; #8080FFspace#000000 fires at them & #8080FFa#000000 activates the SPEC drive. To" );
678 if ( !str.empty() ) {
683 "go to another star system, buy a jump drive for about 10000 credits, fly to a" );
684 if ( !str.empty() ) {
689 "wireframe jump-point and press #8080FFj#000000 to warp to a near star. Target a base or planet;" );
690 if ( !str.empty() ) {
695 "When you get close a green box will appear. Inside the box, #8080FFd#000000 will land." );
705 &&
mission->getVariable(
"savegame",
708 for (
size_t i = 0; i < _Universe->
numPlayers(); i++) {
713 cout<<
"Loading completed, now network init"<<endl;
724 for (
unsigned int i = 0; i < _Universe->
numPlayers(); ++i)
728 for (
unsigned int i = 0; i < _Universe->
numPlayers(); ++i)
729 _Universe->
AccessCockpit( i )->savegame->LoadSavedMissions();
739 "Command line options for vegastrike\n"
741 " -D -d \t Specify data directory\n"
742 " -N -n \t Number of players\n"
743 " -M -m \t Specify a mod to play\n"
744 " -P -p \t Specify player location\n"
745 " -J -j \t Start in a specific system\n"
746 " -A -a \t Normal resolution (800x600)\n"
747 " -H -h \t High resolution (1024x768)\n"
748 " -V -v \t Super high resolution (1280x1024)\n"
749 " --net \t Networking Enabled (Experimental)\n"
750 " --debug[=#] \t Enable debugging output, 1 major warnings, 2 medium, 3 developer notes\n"
751 " --test-audio \t Run audio tests\n"
759 QVector PlayerLocation;
760 for (
int i = 1; i < argc; i++) {
761 if (lpCmdLine[i][0] ==
'-') {
762 cerr<<
"ARG #"<<i<<
" = "<<lpCmdLine[i]<<endl;
763 switch (lpCmdLine[i][1])
768 if (lpCmdLine[i][2] == 0) {
769 cout<<
"Option -D requires an argument"<<endl;
772 datatmp = &lpCmdLine[i][2];
776 cout<<
"Specified data directory not found... exiting"<<endl;
779 cout<<
"Using data dir specified on command line : "<<datatmp<<endl;
786 if ( !(lpCmdLine[i][2] ==
'1' && lpCmdLine[i][3] ==
'\0') ) {
787 CONFIGFILE =
new char[40+strlen( lpCmdLine[i] )+1];
788 sprintf(
CONFIGFILE,
"vegastrike.config.%splayer", lpCmdLine[i]+2 );
793 retstr = string( lpCmdLine[i]+2 );
808 if ( 3 == sscanf( lpCmdLine[i]+2,
"%lf,%lf,%lf", &PlayerLocation.i, &PlayerLocation.j, &PlayerLocation.k ) )
813 st = string( (lpCmdLine[i])+2 );
836 if (strcmp( lpCmdLine[i],
"--benchmark" ) == 0) {
839 }
else if (strcmp( lpCmdLine[i],
"--net" ) == 0) {
841 ignore_network =
false;
842 }
else if (strcmp( lpCmdLine[i],
"--help" ) == 0) {
845 }
else if (strncmp( lpCmdLine[i],
"--debug", 7 ) == 0) {
846 if (lpCmdLine[i][7] == 0) {
848 }
else if (lpCmdLine[i][8] == 0) {
868 for (
int i=1; i < argc; ++i) {
869 if (argv[i][0] ==
'-') {
870 if (strcmp(
"--test-audio", argv[i])==0) {