2014-01-22 17:33:55 +01:00
# include <components/version/version.hpp>
2012-01-21 01:14:35 +01:00
# include <components/files/configurationmanager.hpp>
2016-07-27 00:58:31 +01:00
# include <components/files/escape.hpp>
2019-01-22 10:08:48 +04:00
# include <components/fallback/fallback.hpp>
2016-01-06 12:46:06 +01:00
# include <components/fallback/validate.hpp>
2018-08-03 13:19:12 +04:00
# include <components/debug/debugging.hpp>
2019-02-24 22:41:11 +03:00
# include <components/misc/rng.hpp>
2011-04-28 09:39:40 +02:00
2010-06-16 12:13:21 +02:00
# include "engine.hpp"
2010-02-28 14:51:17 +01:00
2014-06-10 02:22:58 +02:00
# if defined(_WIN32)
2015-07-05 18:10:02 +12:00
# ifndef WIN32_LEAN_AND_MEAN
2014-01-04 07:30:43 +02:00
# define WIN32_LEAN_AND_MEAN
2015-07-05 18:10:02 +12:00
# endif
2014-05-23 23:26:05 +02:00
# include <windows.h>
2010-09-19 02:01:01 +02:00
// makes __argc and __argv available on windows
2012-07-17 09:44:24 +02:00
# include <cstdlib>
2010-09-19 02:01:01 +02:00
# endif
2017-08-06 13:02:22 +02:00
# if (defined(__APPLE__) || defined(__linux) || defined(__unix) || defined(__posix))
# include <unistd.h>
# endif
2013-11-16 15:56:15 +01:00
2012-02-24 20:19:32 +01:00
/**
* Workaround for problems with whitespaces in paths in older versions of Boost library
*/
# if (BOOST_VERSION <= 104600)
namespace boost
{
template < >
inline boost : : filesystem : : path lexical_cast < boost : : filesystem : : path , std : : string > ( const std : : string & arg )
{
return boost : : filesystem : : path ( arg ) ;
}
} /* namespace boost */
# endif /* (BOOST_VERSION <= 104600) */
2012-04-03 01:47:43 +02:00
2016-01-06 12:46:06 +01:00
using namespace Fallback ;
2012-04-03 01:47:43 +02:00
2011-08-19 21:06:09 +02:00
/**
* \ brief Parses application command line and calls \ ref Cfg : : ConfigurationManager
* to parse configuration files .
*
* Results are directly written to \ ref Engine class .
*
* \ retval true - Everything goes OK
* \ retval false - Error
*/
2012-01-21 01:14:35 +01:00
bool parseOptions ( int argc , char * * argv , OMW : : Engine & engine , Files : : ConfigurationManager & cfgMgr )
2010-02-28 14:51:17 +01:00
{
2010-06-27 16:44:15 -07:00
// Create a local alias for brevity
2010-10-05 18:23:53 +02:00
namespace bpo = boost : : program_options ;
2016-07-12 01:06:57 +01:00
typedef std : : vector < std : : string > StringsVector ;
2010-06-27 16:44:15 -07:00
2011-08-19 21:06:09 +02:00
bpo : : options_description desc ( " Syntax: openmw <options> \n Allowed options " ) ;
2010-06-10 10:31:50 +02:00
desc . add_options ( )
2011-08-19 21:06:09 +02:00
( " help " , " print help message " )
2011-07-08 16:16:20 +02:00
( " version " , " print version information and quit " )
2016-07-20 02:48:57 +01:00
( " data " , bpo : : value < Files : : EscapePathContainer > ( ) - > default_value ( Files : : EscapePathContainer ( ) , " data " )
2014-09-13 20:41:57 +02:00
- > multitoken ( ) - > composing ( ) , " set data directories (later directories have higher priority) " )
2011-08-19 21:06:09 +02:00
2016-07-12 01:06:57 +01:00
( " data-local " , bpo : : value < Files : : EscapeHashString > ( ) - > default_value ( " " ) ,
2011-05-05 19:50:28 +02:00
" set local data directory (highest priority) " )
2011-08-19 21:06:09 +02:00
2016-07-12 17:09:57 +01:00
( " fallback-archive " , bpo : : value < Files : : EscapeStringVector > ( ) - > default_value ( Files : : EscapeStringVector ( ) , " fallback-archive " )
2013-03-09 21:08:08 +01:00
- > multitoken ( ) , " set fallback BSA archives (later archives have higher priority) " )
2016-07-12 01:06:57 +01:00
( " resources " , bpo : : value < Files : : EscapeHashString > ( ) - > default_value ( " resources " ) ,
2011-01-04 01:34:55 +01:00
" set resources directory " )
2011-08-19 21:06:09 +02:00
2016-07-12 01:06:57 +01:00
( " start " , bpo : : value < Files : : EscapeHashString > ( ) - > default_value ( " " ) ,
2010-10-05 18:23:53 +02:00
" set initial cell " )
2011-08-19 21:06:09 +02:00
2016-07-12 17:09:57 +01:00
( " content " , bpo : : value < Files : : EscapeStringVector > ( ) - > default_value ( Files : : EscapeStringVector ( ) , " " )
2013-09-29 09:11:57 +02:00
- > multitoken ( ) , " content file(s): esm/esp, or omwgame/omwaddon " )
2011-08-19 21:06:09 +02:00
2013-12-26 02:24:12 +01:00
( " no-sound " , bpo : : value < bool > ( ) - > implicit_value ( true )
2011-08-19 21:06:09 +02:00
- > default_value ( false ) , " disable all sounds " )
2012-04-02 20:47:09 +02:00
( " script-all " , bpo : : value < bool > ( ) - > implicit_value ( true )
2011-08-19 21:06:09 +02:00
- > default_value ( false ) , " compile all scripts (excluding dialogue scripts) at startup " )
2014-12-13 02:47:04 +01:00
( " script-all-dialogue " , bpo : : value < bool > ( ) - > implicit_value ( true )
- > default_value ( false ) , " compile all dialogue scripts at startup " )
2012-07-30 11:43:28 +02:00
( " script-console " , bpo : : value < bool > ( ) - > implicit_value ( true )
- > default_value ( false ) , " enable console-only script functionality " )
2016-07-12 01:06:57 +01:00
( " script-run " , bpo : : value < Files : : EscapeHashString > ( ) - > default_value ( " " ) ,
2012-11-27 04:50:49 -06:00
" select a file containing a list of console commands that is executed on startup " )
2012-07-30 12:37:46 +02:00
2014-02-02 14:09:59 +01:00
( " script-warn " , bpo : : value < int > ( ) - > implicit_value ( 1 )
- > default_value ( 1 ) ,
" handling of warnings when compiling scripts \n "
" \t 0 - ignore warning \n "
" \t 1 - show warning but consider script as correctly compiled anyway \n "
" \t 2 - treat warnings as errors " )
2016-07-12 17:09:57 +01:00
( " script-blacklist " , bpo : : value < Files : : EscapeStringVector > ( ) - > default_value ( Files : : EscapeStringVector ( ) , " " )
2014-07-21 09:34:10 +02:00
- > multitoken ( ) , " ignore the specified script (if the use of the blacklist is enabled) " )
( " script-blacklist-use " , bpo : : value < bool > ( ) - > implicit_value ( true )
- > default_value ( true ) , " enable script blacklisting " )
2016-07-12 01:06:57 +01:00
( " load-savegame " , bpo : : value < Files : : EscapeHashString > ( ) - > default_value ( " " ) ,
2015-02-04 22:17:30 +01:00
" load a save game file on game startup (specify an absolute filename or a filename relative to the current working directory) " )
2015-01-07 03:03:56 +01:00
2013-11-16 11:33:20 +01:00
( " skip-menu " , bpo : : value < bool > ( ) - > implicit_value ( true )
- > default_value ( false ) , " skip main menu on game startup " )
2014-09-01 11:55:12 +02:00
( " new-game " , bpo : : value < bool > ( ) - > implicit_value ( true )
- > default_value ( false ) , " run new game sequence (ignored if skip-menu=0) " )
2012-04-02 20:47:09 +02:00
( " fs-strict " , bpo : : value < bool > ( ) - > implicit_value ( true )
2011-08-19 21:06:09 +02:00
- > default_value ( false ) , " strict file system handling (no case folding) " )
Added new command line option: "encoding"
Added new command line option: "encoding" which allow to
change font encoding used in game messages.
Currently there are three evailable encodings:
win1250 - Central and Eastern European (languages
that use Latin script, such as Polish,
Czech, Slovak, Hungarian, Slovene, Bosnian,
Croatian, Serbian (Latin script),
Romanian and Albanian)
win1251 - languages that use the Cyrillic alphabet
such as Russian, Bulgarian, Serbian Cyrillic
and others
win1252 - Western European (Latin) - default
Signed-off-by: Lukasz Gromanowski <lgromanowski@gmail.com>
2011-07-17 22:16:50 +02:00
2016-07-12 01:06:57 +01:00
( " encoding " , bpo : : value < Files : : EscapeHashString > ( ) - >
Added new command line option: "encoding"
Added new command line option: "encoding" which allow to
change font encoding used in game messages.
Currently there are three evailable encodings:
win1250 - Central and Eastern European (languages
that use Latin script, such as Polish,
Czech, Slovak, Hungarian, Slovene, Bosnian,
Croatian, Serbian (Latin script),
Romanian and Albanian)
win1251 - languages that use the Cyrillic alphabet
such as Russian, Bulgarian, Serbian Cyrillic
and others
win1252 - Western European (Latin) - default
Signed-off-by: Lukasz Gromanowski <lgromanowski@gmail.com>
2011-07-17 22:16:50 +02:00
default_value ( " win1252 " ) ,
2011-07-17 22:53:20 +02:00
" Character encoding used in OpenMW game messages: \n "
Added new command line option: "encoding"
Added new command line option: "encoding" which allow to
change font encoding used in game messages.
Currently there are three evailable encodings:
win1250 - Central and Eastern European (languages
that use Latin script, such as Polish,
Czech, Slovak, Hungarian, Slovene, Bosnian,
Croatian, Serbian (Latin script),
Romanian and Albanian)
win1251 - languages that use the Cyrillic alphabet
such as Russian, Bulgarian, Serbian Cyrillic
and others
win1252 - Western European (Latin) - default
Signed-off-by: Lukasz Gromanowski <lgromanowski@gmail.com>
2011-07-17 22:16:50 +02:00
" \n \t win1250 - Central and Eastern European such as Polish, Czech, Slovak, Hungarian, Slovene, Bosnian, Croatian, Serbian (Latin script), Romanian and Albanian languages \n "
" \n \t win1251 - Cyrillic alphabet such as Russian, Bulgarian, Serbian Cyrillic and other languages \n "
" \n \t win1252 - Western European (Latin) alphabet, used by default " )
2011-10-08 10:31:23 +02:00
2016-07-12 01:06:57 +01:00
( " fallback " , bpo : : value < FallbackMap > ( ) - > default_value ( FallbackMap ( ) , " " )
2012-04-02 20:47:09 +02:00
- > multitoken ( ) - > composing ( ) , " fallback values " )
2017-03-04 21:36:11 +01:00
( " no-grab " , bpo : : value < bool > ( ) - > implicit_value ( true ) - > default_value ( false ) , " Don't grab mouse cursor " )
2013-11-29 20:06:54 +01:00
2014-08-11 20:37:29 +02:00
( " export-fonts " , bpo : : value < bool > ( ) - > implicit_value ( true )
- > default_value ( false ) , " Export Morrowind .fnt fonts to PNG image and XML file in current directory " )
2019-02-24 22:41:11 +03:00
( " activate-dist " , bpo : : value < int > ( ) - > default_value ( - 1 ) , " activation distance override " )
( " random-seed " , bpo : : value < unsigned int > ( )
- > default_value ( Misc : : Rng : : generateDefaultSeed ( ) ) ,
" seed value for random number generator " )
;
2013-01-08 19:52:18 -08:00
2011-08-19 21:06:09 +02:00
bpo : : parsed_options valid_opts = bpo : : command_line_parser ( argc , argv )
. options ( desc ) . allow_unregistered ( ) . run ( ) ;
2011-01-04 01:34:55 +01:00
2011-08-19 21:06:09 +02:00
bpo : : variables_map variables ;
2010-06-11 19:53:00 +02:00
2011-08-19 21:06:09 +02:00
// Runtime options override settings from all configs
2010-07-04 17:16:57 -04:00
bpo : : store ( valid_opts , variables ) ;
bpo : : notify ( variables ) ;
2010-06-10 10:31:50 +02:00
if ( variables . count ( " help " ) )
{
2010-06-16 12:21:02 +02:00
std : : cout < < desc < < std : : endl ;
2015-01-31 18:36:53 +01:00
return false ;
2011-07-08 16:16:20 +02:00
}
2015-07-18 03:01:06 +02:00
if ( variables . count ( " version " ) )
2011-07-08 16:16:20 +02:00
{
2015-07-18 03:01:06 +02:00
cfgMgr . readConfiguration ( variables , desc , true ) ;
2010-06-16 12:21:02 +02:00
2016-07-11 22:05:38 +01:00
Version : : Version v = Version : : getOpenmwVersion ( variables [ " resources " ] . as < Files : : EscapeHashString > ( ) . toStdString ( ) ) ;
2015-07-18 03:01:06 +02:00
std : : cout < < v . describe ( ) < < std : : endl ;
2010-06-16 12:21:02 +02:00
return false ;
2015-07-18 03:01:06 +02:00
}
2011-07-08 16:16:20 +02:00
2013-12-23 23:55:40 +01:00
cfgMgr . readConfiguration ( variables , desc ) ;
2016-07-11 22:05:38 +01:00
Version : : Version v = Version : : getOpenmwVersion ( variables [ " resources " ] . as < Files : : EscapeHashString > ( ) . toStdString ( ) ) ;
2015-11-19 02:56:26 +01:00
std : : cout < < v . describe ( ) < < std : : endl ;
2017-03-04 21:36:11 +01:00
engine . setGrabMouse ( ! variables [ " no-grab " ] . as < bool > ( ) ) ;
2013-11-29 20:06:54 +01:00
Added new command line option: "encoding"
Added new command line option: "encoding" which allow to
change font encoding used in game messages.
Currently there are three evailable encodings:
win1250 - Central and Eastern European (languages
that use Latin script, such as Polish,
Czech, Slovak, Hungarian, Slovene, Bosnian,
Croatian, Serbian (Latin script),
Romanian and Albanian)
win1251 - languages that use the Cyrillic alphabet
such as Russian, Bulgarian, Serbian Cyrillic
and others
win1252 - Western European (Latin) - default
Signed-off-by: Lukasz Gromanowski <lgromanowski@gmail.com>
2011-07-17 22:16:50 +02:00
// Font encoding settings
2016-07-11 22:05:38 +01:00
std : : string encoding ( variables [ " encoding " ] . as < Files : : EscapeHashString > ( ) . toStdString ( ) ) ;
2012-12-26 16:19:59 +01:00
std : : cout < < ToUTF8 : : encodingUsingMessage ( encoding ) < < std : : endl ;
engine . setEncoding ( ToUTF8 : : calculateEncoding ( encoding ) ) ;
2010-06-16 12:21:02 +02:00
2011-03-29 13:57:56 +02:00
// directory settings
2011-08-19 21:06:09 +02:00
engine . enableFSStrict ( variables [ " fs-strict " ] . as < bool > ( ) ) ;
2011-05-05 19:56:16 +02:00
2016-07-20 15:16:53 +01:00
Files : : PathContainer dataDirs ( Files : : EscapePath : : toPathContainer ( variables [ " data " ] . as < Files : : EscapePathContainer > ( ) ) ) ;
2011-05-05 19:50:28 +02:00
2016-07-11 22:05:38 +01:00
std : : string local ( variables [ " data-local " ] . as < Files : : EscapeHashString > ( ) . toStdString ( ) ) ;
2011-05-05 19:50:28 +02:00
if ( ! local . empty ( ) )
2011-08-19 21:06:09 +02:00
{
2017-10-18 01:42:11 +01:00
if ( local . front ( ) = = ' \" ' )
local = local . substr ( 1 , local . length ( ) - 2 ) ;
2012-08-16 12:59:28 +02:00
dataDirs . push_back ( Files : : PathContainer : : value_type ( local ) ) ;
2011-08-19 21:06:09 +02:00
}
2011-05-05 19:39:11 +02:00
2012-02-22 23:56:07 +01:00
cfgMgr . processPaths ( dataDirs ) ;
2019-06-01 15:57:26 +04:00
engine . setResourceDir ( variables [ " resources " ] . as < Files : : EscapeHashString > ( ) . toStdString ( ) ) ;
2011-08-19 21:06:09 +02:00
engine . setDataDirs ( dataDirs ) ;
2013-03-09 21:08:08 +01:00
// fallback archives
2016-07-12 17:09:57 +01:00
StringsVector archives = variables [ " fallback-archive " ] . as < Files : : EscapeStringVector > ( ) . toStdStringVector ( ) ;
2013-07-31 18:46:32 +02:00
for ( StringsVector : : const_iterator it = archives . begin ( ) ; it ! = archives . end ( ) ; + + it )
2013-03-09 21:08:08 +01:00
{
engine . addArchive ( * it ) ;
}
2016-07-12 17:09:57 +01:00
StringsVector content = variables [ " content " ] . as < Files : : EscapeStringVector > ( ) . toStdStringVector ( ) ;
2013-09-29 09:11:57 +02:00
if ( content . empty ( ) )
2011-03-29 13:57:56 +02:00
{
2018-08-14 23:05:43 +04:00
Log ( Debug : : Error ) < < " No content file given (esm/esp, nor omwgame/omwaddon). Aborting... " ;
return false ;
2011-03-29 13:57:56 +02:00
}
2013-09-29 09:11:57 +02:00
StringsVector : : const_iterator it ( content . begin ( ) ) ;
StringsVector : : const_iterator end ( content . end ( ) ) ;
for ( ; it ! = end ; + + it )
2011-08-19 21:06:09 +02:00
{
2013-09-29 09:11:57 +02:00
engine . addContentFile ( * it ) ;
2011-08-19 21:06:09 +02:00
}
2011-03-29 13:57:56 +02:00
// startup-settings
2016-07-11 22:05:38 +01:00
engine . setCell ( variables [ " start " ] . as < Files : : EscapeHashString > ( ) . toStdString ( ) ) ;
2014-09-01 11:55:12 +02:00
engine . setSkipMenu ( variables [ " skip-menu " ] . as < bool > ( ) , variables [ " new-game " ] . as < bool > ( ) ) ;
if ( ! variables [ " skip-menu " ] . as < bool > ( ) & & variables [ " new-game " ] . as < bool > ( ) )
2018-08-14 23:05:43 +04:00
Log ( Debug : : Warning ) < < " Warning: new-game used without skip-menu -> ignoring it " ;
2011-03-29 13:57:56 +02:00
2014-07-21 09:34:10 +02:00
// scripts
2011-08-19 21:06:09 +02:00
engine . setCompileAll ( variables [ " script-all " ] . as < bool > ( ) ) ;
2014-12-13 02:47:04 +01:00
engine . setCompileAllDialogue ( variables [ " script-all-dialogue " ] . as < bool > ( ) ) ;
2012-07-30 11:43:28 +02:00
engine . setScriptConsoleMode ( variables [ " script-console " ] . as < bool > ( ) ) ;
2016-07-11 22:05:38 +01:00
engine . setStartupScript ( variables [ " script-run " ] . as < Files : : EscapeHashString > ( ) . toStdString ( ) ) ;
2014-02-02 14:09:59 +01:00
engine . setWarningsMode ( variables [ " script-warn " ] . as < int > ( ) ) ;
2016-07-12 17:09:57 +01:00
engine . setScriptBlacklist ( variables [ " script-blacklist " ] . as < Files : : EscapeStringVector > ( ) . toStdStringVector ( ) ) ;
2014-07-21 09:34:10 +02:00
engine . setScriptBlacklistUse ( variables [ " script-blacklist-use " ] . as < bool > ( ) ) ;
2016-07-11 22:05:38 +01:00
engine . setSaveGameFile ( variables [ " load-savegame " ] . as < Files : : EscapeHashString > ( ) . toStdString ( ) ) ;
2014-07-21 09:34:10 +02:00
// other settings
2019-01-22 10:08:48 +04:00
Fallback : : Map : : init ( variables [ " fallback " ] . as < FallbackMap > ( ) . mMap ) ;
2014-07-21 09:34:10 +02:00
engine . setSoundUsage ( ! variables [ " no-sound " ] . as < bool > ( ) ) ;
engine . setActivationDistanceOverride ( variables [ " activate-dist " ] . as < int > ( ) ) ;
2014-08-11 20:37:29 +02:00
engine . enableFontExport ( variables [ " export-fonts " ] . as < bool > ( ) ) ;
2019-02-24 22:41:11 +03:00
engine . setRandomSeed ( variables [ " random-seed " ] . as < unsigned int > ( ) ) ;
2010-10-06 14:52:53 +02:00
2010-06-22 17:52:17 -07:00
return true ;
2010-06-16 12:21:02 +02:00
}
2018-08-03 15:51:17 +04:00
int runApplication ( int argc , char * argv [ ] )
2010-09-19 02:01:01 +02:00
{
2018-08-03 15:51:17 +04:00
# ifdef __APPLE__
boost : : filesystem : : path binary_path = boost : : filesystem : : system_complete ( boost : : filesystem : : path ( argv [ 0 ] ) ) ;
boost : : filesystem : : current_path ( binary_path . parent_path ( ) ) ;
2015-11-12 21:40:59 +01:00
setenv ( " OSG_GL_TEXTURE_STORAGE " , " OFF " , 0 ) ;
# endif
2018-08-03 15:51:17 +04:00
Files : : ConfigurationManager cfgMgr ;
2017-04-28 17:30:26 +02:00
std : : unique_ptr < OMW : : Engine > engine ;
2018-08-03 15:51:17 +04:00
engine . reset ( new OMW : : Engine ( cfgMgr ) ) ;
2014-07-26 22:29:04 +02:00
2018-08-03 15:51:17 +04:00
if ( parseOptions ( argc , argv , * engine , cfgMgr ) )
2014-06-10 02:22:58 +02:00
{
2018-08-03 15:51:17 +04:00
engine - > go ( ) ;
2010-09-19 02:01:01 +02:00
}
2014-06-10 02:22:58 +02:00
2018-08-03 15:51:17 +04:00
return 0 ;
}
2014-06-10 02:22:58 +02:00
2018-08-03 15:51:17 +04:00
# ifdef ANDROID
extern " C " int SDL_main ( int argc , char * * argv )
# else
int main ( int argc , char * * argv )
# endif
{
2018-08-03 13:19:12 +04:00
return wrapApplication ( & runApplication , argc , argv , " OpenMW " ) ;
2010-09-19 02:01:01 +02:00
}
2014-06-10 02:22:58 +02:00
// Platform specific for Windows when there is no console built into the executable.
// Windows will call the WinMain function instead of main in this case, the normal
// main function is then called with the __argc and __argv parameters.
# if defined(_WIN32) && !defined(_CONSOLE)
int WINAPI WinMain ( HINSTANCE hInstance , HINSTANCE hPrevInstance , LPSTR lpCmdLine , int nShowCmd )
{
return main ( __argc , __argv ) ;
}
2010-09-19 02:01:01 +02:00
# endif