2
0
mirror of https://github.com/FWGS/xash3d-fwgs synced 2024-11-23 02:15:55 +01:00
xash3d-fwgs/engine/common/launcher.c

85 lines
2.1 KiB
C
Raw Normal View History

2018-04-18 17:32:30 +02:00
/*
launcher.c - direct xash3d launcher
Copyright (C) 2015 Mittorn
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 3 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.
*/
#if XASH_ENABLE_MAIN
#if XASH_SDLMAIN
#include <SDL.h>
2018-04-18 17:32:30 +02:00
#endif
#if XASH_EMSCRIPTEN
2018-04-18 17:32:30 +02:00
#include <emscripten.h>
#endif
#include "build.h"
#include "common.h"
#ifndef XASH_GAMEDIR
#define XASH_GAMEDIR "valve" // !!! Replace with your default (base) game directory !!!
#endif
#if XASH_WIN32
#error "Single-binary or dedicated builds aren't supported for Windows!"
#endif
2022-06-13 02:26:44 +02:00
static char szGameDir[128]; // safe place to keep gamedir
static int szArgc;
static char **szArgv;
static void Sys_ChangeGame( const char *progname )
2018-04-18 17:32:30 +02:00
{
2022-06-13 02:26:44 +02:00
// a1ba: may never be called within engine
// if platform supports execv() function
Q_strncpy( szGameDir, progname, sizeof( szGameDir ));
2022-06-13 02:26:44 +02:00
Host_Shutdown( );
2022-06-13 03:05:50 +02:00
exit( Host_Main( szArgc, szArgv, szGameDir, 1, &Sys_ChangeGame ) );
2022-06-13 02:26:44 +02:00
}
static int Sys_Start( void )
2022-06-13 02:26:44 +02:00
{
Q_strncpy( szGameDir, XASH_GAMEDIR, sizeof( szGameDir ));
2022-06-13 02:26:44 +02:00
#if XASH_EMSCRIPTEN
#ifdef EMSCRIPTEN_LIB_FS
// For some unknown reason emscripten refusing to load libraries later
COM_LoadLibrary( "menu", 0 );
COM_LoadLibrary( "server", 0 );
COM_LoadLibrary( "client", 0 );
2022-06-13 02:26:44 +02:00
#endif
#if XASH_DEDICATED
// NodeJS support for debug
EM_ASM(try {
FS.mkdir( '/xash' );
FS.mount( NODEFS, { root: '.'}, '/xash' );
FS.chdir( '/xash' );
} catch( e ) { };);
2022-06-13 02:26:44 +02:00
#endif
#elif XASH_IOS
IOS_LaunchDialog();
#endif
2022-06-13 02:26:44 +02:00
return Host_Main( szArgc, szArgv, szGameDir, 0, Sys_ChangeGame );
2018-04-18 17:32:30 +02:00
}
2022-06-13 02:26:44 +02:00
int main( int argc, char **argv )
{
#if XASH_PSVITA
// inject -dev -console into args if required
szArgc = PSVita_GetArgv( argc, argv, &szArgv );
#else
2022-06-13 02:26:44 +02:00
szArgc = argc;
szArgv = argv;
#endif // XASH_PSVITA
2022-06-13 02:26:44 +02:00
return Sys_Start();
}
#endif // XASH_ENABLE_MAIN