2014-01-22 16:33:55 +00:00
# include <components/version/version.hpp>
2012-01-21 00:14:35 +00:00
# include <components/files/configurationmanager.hpp>
2016-07-26 23:58:31 +00:00
# include <components/files/escape.hpp>
2019-01-22 06:08:48 +00:00
# include <components/fallback/fallback.hpp>
2016-01-06 11:46:06 +00:00
# include <components/fallback/validate.hpp>
2018-08-03 09:19:12 +00:00
# include <components/debug/debugging.hpp>
2019-02-24 19:41:11 +00:00
# include <components/misc/rng.hpp>
2011-04-28 07:39:40 +00:00
2010-06-16 10:13:21 +00:00
# include "engine.hpp"
2010-02-28 13:51:17 +00:00
2017-07-15 09:44:00 +00:00
/*
Start of tes3mp addition
Include the header of the multiplayer ' s Main class
*/
2016-08-24 08:15:34 +00:00
# include "mwmp/Main.hpp"
2017-07-15 09:44:00 +00:00
/*
End of tes3mp addition
*/
2010-09-19 00:01:01 +00:00
2014-06-10 00:22:58 +00:00
# if defined(_WIN32)
2015-07-05 06:10:02 +00:00
# ifndef WIN32_LEAN_AND_MEAN
2014-01-04 05:30:43 +00:00
# define WIN32_LEAN_AND_MEAN
2015-07-05 06:10:02 +00:00
# endif
2014-05-23 21:26:05 +00:00
# include <windows.h>
2010-09-19 00:01:01 +00:00
// makes __argc and __argv available on windows
2012-07-17 07:44:24 +00:00
# include <cstdlib>
2010-09-19 00:01:01 +00:00
# endif
2017-08-06 11:02:22 +00:00
# if (defined(__APPLE__) || defined(__linux) || defined(__unix) || defined(__posix))
# include <unistd.h>
# endif
2013-11-16 14:56:15 +00:00
2017-07-15 09:44:00 +00:00
/*
Start of tes3mp addition
2017-10-08 03:17:53 +00:00
Include additional headers for multiplayer purposes
2017-07-15 09:44:00 +00:00
*/
2018-07-16 00:25:01 +00:00
# include <components/openmw-mp/ErrorMessages.hpp>
2019-08-19 18:39:33 +00:00
# include <components/openmw-mp/TimedLog.hpp>
2017-10-08 03:17:53 +00:00
# include <components/openmw-mp/Utils.hpp>
# include <components/openmw-mp/Version.hpp>
2017-07-15 09:44:00 +00:00
/*
End of tes3mp addition
*/
2017-06-18 15:16:10 +00:00
2012-04-02 23:47:43 +00:00
2016-01-06 11:46:06 +00:00
using namespace Fallback ;
2012-04-02 23:47:43 +00:00
2011-08-19 19:06:09 +00: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 00:14:35 +00:00
bool parseOptions ( int argc , char * * argv , OMW : : Engine & engine , Files : : ConfigurationManager & cfgMgr )
2010-02-28 13:51:17 +00:00
{
2010-06-27 23:44:15 +00:00
// Create a local alias for brevity
2010-10-05 16:23:53 +00:00
namespace bpo = boost : : program_options ;
2016-07-12 00:06:57 +00:00
typedef std : : vector < std : : string > StringsVector ;
2010-06-27 23:44:15 +00:00
2011-08-19 19:06:09 +00:00
bpo : : options_description desc ( " Syntax: openmw <options> \n Allowed options " ) ;
2010-06-10 08:31:50 +00:00
desc . add_options ( )
2011-08-19 19:06:09 +00:00
( " help " , " print help message " )
2011-07-08 14:16:20 +00:00
( " version " , " print version information and quit " )
2021-08-01 08:53:52 +00:00
( " replace " , bpo : : value < Files : : EscapeStringVector > ( ) - > default_value ( Files : : EscapeStringVector ( ) , " " )
- > multitoken ( ) - > composing ( ) , " settings where the values from the current source should replace those from lower-priority sources instead of being appended " )
2016-07-20 01:48:57 +00:00
( " data " , bpo : : value < Files : : EscapePathContainer > ( ) - > default_value ( Files : : EscapePathContainer ( ) , " data " )
2014-09-13 18:41:57 +00:00
- > multitoken ( ) - > composing ( ) , " set data directories (later directories have higher priority) " )
2011-08-19 19:06:09 +00:00
2020-10-23 14:34:41 +00:00
( " data-local " , bpo : : value < Files : : EscapePath > ( ) - > default_value ( Files : : EscapePath ( ) , " " ) ,
2011-05-05 17:50:28 +00:00
" set local data directory (highest priority) " )
2011-08-19 19:06:09 +00:00
2016-07-12 16:09:57 +00:00
( " fallback-archive " , bpo : : value < Files : : EscapeStringVector > ( ) - > default_value ( Files : : EscapeStringVector ( ) , " fallback-archive " )
2020-10-23 00:58:43 +00:00
- > multitoken ( ) - > composing ( ) , " set fallback BSA archives (later archives have higher priority) " )
2013-03-09 20:08:08 +00:00
2020-10-23 14:34:41 +00:00
( " resources " , bpo : : value < Files : : EscapePath > ( ) - > default_value ( Files : : EscapePath ( ) , " resources " ) ,
2011-01-04 00:34:55 +00:00
" set resources directory " )
2011-08-19 19:06:09 +00:00
2020-10-22 20:44:47 +00:00
( " start " , bpo : : value < Files : : EscapeHashString > ( ) - > default_value ( " " ) ,
2010-10-05 16:23:53 +00:00
" set initial cell " )
2011-08-19 19:06:09 +00:00
2016-07-12 16:09:57 +00:00
( " content " , bpo : : value < Files : : EscapeStringVector > ( ) - > default_value ( Files : : EscapeStringVector ( ) , " " )
2020-10-23 00:58:43 +00:00
- > multitoken ( ) - > composing ( ) , " content file(s): esm/esp, or omwgame/omwaddon " )
2011-08-19 19:06:09 +00:00
2020-01-12 07:42:47 +00:00
( " groundcover " , bpo : : value < Files : : EscapeStringVector > ( ) - > default_value ( Files : : EscapeStringVector ( ) , " " )
- > multitoken ( ) - > composing ( ) , " groundcover content file(s): esm/esp, or omwgame/omwaddon " )
2013-12-26 01:24:12 +00:00
( " no-sound " , bpo : : value < bool > ( ) - > implicit_value ( true )
2011-08-19 19:06:09 +00:00
- > default_value ( false ) , " disable all sounds " )
2012-04-02 18:47:09 +00:00
( " script-all " , bpo : : value < bool > ( ) - > implicit_value ( true )
2011-08-19 19:06:09 +00:00
- > default_value ( false ) , " compile all scripts (excluding dialogue scripts) at startup " )
2014-12-13 01:47:04 +00:00
( " script-all-dialogue " , bpo : : value < bool > ( ) - > implicit_value ( true )
- > default_value ( false ) , " compile all dialogue scripts at startup " )
2012-07-30 09:43:28 +00:00
( " script-console " , bpo : : value < bool > ( ) - > implicit_value ( true )
- > default_value ( false ) , " enable console-only script functionality " )
2020-10-22 20:44:47 +00:00
( " script-run " , bpo : : value < Files : : EscapeHashString > ( ) - > default_value ( " " ) ,
2012-11-27 10:50:49 +00:00
" select a file containing a list of console commands that is executed on startup " )
2012-07-30 10:37:46 +00:00
2014-02-02 13:09:59 +00: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 16:09:57 +00:00
( " script-blacklist " , bpo : : value < Files : : EscapeStringVector > ( ) - > default_value ( Files : : EscapeStringVector ( ) , " " )
2020-10-23 00:58:43 +00:00
- > multitoken ( ) - > composing ( ) , " ignore the specified script (if the use of the blacklist is enabled) " )
2014-07-21 07:34:10 +00:00
( " script-blacklist-use " , bpo : : value < bool > ( ) - > implicit_value ( true )
- > default_value ( true ) , " enable script blacklisting " )
2020-10-23 14:34:41 +00:00
( " load-savegame " , bpo : : value < Files : : EscapePath > ( ) - > default_value ( Files : : EscapePath ( ) , " " ) ,
2015-02-04 21:17:30 +00: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 02:03:56 +00:00
2013-11-16 10:33:20 +00:00
( " skip-menu " , bpo : : value < bool > ( ) - > implicit_value ( true )
- > default_value ( false ) , " skip main menu on game startup " )
2014-09-01 09:55:12 +00:00
( " new-game " , bpo : : value < bool > ( ) - > implicit_value ( true )
- > default_value ( false ) , " run new game sequence (ignored if skip-menu=0) " )
2012-04-02 18:47:09 +00:00
( " fs-strict " , bpo : : value < bool > ( ) - > implicit_value ( true )
2011-08-19 19:06:09 +00: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 20:16:50 +00:00
2020-10-22 20:44:47 +00: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 20:16:50 +00:00
default_value ( " win1252 " ) ,
2011-07-17 20:53:20 +00: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 20:16:50 +00: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 08:31:23 +00:00
2020-10-22 20:44:47 +00:00
( " fallback " , bpo : : value < FallbackMap > ( ) - > default_value ( FallbackMap ( ) , " " )
2012-04-02 18:47:09 +00:00
- > multitoken ( ) - > composing ( ) , " fallback values " )
2017-03-04 20:36:11 +00:00
( " no-grab " , bpo : : value < bool > ( ) - > implicit_value ( true ) - > default_value ( false ) , " Don't grab mouse cursor " )
2013-11-29 19:06:54 +00:00
2014-08-11 18:37:29 +00: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 19:41:11 +00: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-09 03:52:18 +00:00
2017-07-15 09:44:00 +00:00
/*
Start of tes3mp addition
Parse options added by multiplayer
*/
2016-11-15 19:54:06 +00:00
mwmp : : Main : : optionsDesc ( & desc ) ;
2017-07-15 09:44:00 +00:00
/*
End of tes3mp addition
*/
2016-08-24 08:15:34 +00:00
2011-08-19 19:06:09 +00:00
bpo : : parsed_options valid_opts = bpo : : command_line_parser ( argc , argv )
. options ( desc ) . allow_unregistered ( ) . run ( ) ;
2011-01-04 00:34:55 +00:00
2011-08-19 19:06:09 +00:00
bpo : : variables_map variables ;
2010-06-11 17:53:00 +00:00
2011-08-19 19:06:09 +00:00
// Runtime options override settings from all configs
2010-07-04 21:16:57 +00:00
bpo : : store ( valid_opts , variables ) ;
bpo : : notify ( variables ) ;
2010-06-10 08:31:50 +00:00
if ( variables . count ( " help " ) )
{
2020-12-08 21:23:11 +00:00
getRawStdout ( ) < < desc < < std : : endl ;
2015-01-31 17:36:53 +00:00
return false ;
2011-07-08 14:16:20 +00:00
}
2015-07-18 01:01:06 +00:00
if ( variables . count ( " version " ) )
2011-07-08 14:16:20 +00:00
{
2015-07-18 01:01:06 +00:00
cfgMgr . readConfiguration ( variables , desc , true ) ;
2010-06-16 10:21:02 +00:00
2020-10-23 14:34:41 +00:00
Version : : Version v = Version : : getOpenmwVersion ( variables [ " resources " ] . as < Files : : EscapePath > ( ) . mPath . string ( ) ) ;
2020-12-08 21:23:11 +00:00
getRawStdout ( ) < < v . describe ( ) < < std : : endl ;
2010-06-16 10:21:02 +00:00
return false ;
2015-07-18 01:01:06 +00:00
}
2011-07-08 14:16:20 +00:00
2020-10-23 00:41:28 +00:00
bpo : : variables_map composingVariables = cfgMgr . separateComposingVariables ( variables , desc ) ;
2013-12-23 22:55:40 +00:00
cfgMgr . readConfiguration ( variables , desc ) ;
2020-10-23 00:41:28 +00:00
cfgMgr . mergeComposingVariables ( variables , composingVariables , desc ) ;
2013-12-23 22:55:40 +00:00
2020-10-23 14:34:41 +00:00
Version : : Version v = Version : : getOpenmwVersion ( variables [ " resources " ] . as < Files : : EscapePath > ( ) . mPath . string ( ) ) ;
2017-10-08 03:17:53 +00:00
/*
Start of tes3mp addition
Print the multiplayer version first
*/
2021-02-10 00:54:37 +00:00
Log ( Debug : : Info ) < < Utils : : getVersionInfo ( " TES3MP client " , TES3MP_VERSION , v . mCommitHash , TES3MP_PROTO_VERSION ) ;
2017-10-08 03:17:53 +00:00
/*
End of tes3mp addition
*/
/*
Start of tes3mp change ( minor )
Because there is no need to print the commit hash again , only print OpenMW ' s version
*/
2021-01-05 05:25:31 +00:00
Log ( Debug : : Info ) < < " OpenMW version " < < v . mVersion ;
2017-10-08 03:17:53 +00:00
/*
End of tes3mp change ( minor )
*/
2015-11-19 01:56:26 +00:00
2017-03-04 20:36:11 +00:00
engine . setGrabMouse ( ! variables [ " no-grab " ] . as < bool > ( ) ) ;
2013-11-29 19:06:54 +00: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 20:16:50 +00:00
// Font encoding settings
2016-07-11 21:05:38 +00:00
std : : string encoding ( variables [ " encoding " ] . as < Files : : EscapeHashString > ( ) . toStdString ( ) ) ;
2020-12-08 07:06:30 +00:00
Log ( Debug : : Info ) < < ToUTF8 : : encodingUsingMessage ( encoding ) ;
2012-12-26 15:19:59 +00:00
engine . setEncoding ( ToUTF8 : : calculateEncoding ( encoding ) ) ;
2010-06-16 10:21:02 +00:00
2011-03-29 11:57:56 +00:00
// directory settings
2011-08-19 19:06:09 +00:00
engine . enableFSStrict ( variables [ " fs-strict " ] . as < bool > ( ) ) ;
2011-05-05 17:56:16 +00:00
2016-07-20 14:16:53 +00:00
Files : : PathContainer dataDirs ( Files : : EscapePath : : toPathContainer ( variables [ " data " ] . as < Files : : EscapePathContainer > ( ) ) ) ;
2011-05-05 17:50:28 +00:00
2020-10-23 14:34:41 +00:00
Files : : PathContainer : : value_type local ( variables [ " data-local " ] . as < Files : : EscapePath > ( ) . mPath ) ;
2011-05-05 17:50:28 +00:00
if ( ! local . empty ( ) )
2020-10-23 14:34:41 +00:00
dataDirs . push_back ( local ) ;
2011-05-05 17:39:11 +00:00
2012-02-22 22:56:07 +00:00
cfgMgr . processPaths ( dataDirs ) ;
2020-10-23 14:34:41 +00:00
engine . setResourceDir ( variables [ " resources " ] . as < Files : : EscapePath > ( ) . mPath ) ;
2011-08-19 19:06:09 +00:00
engine . setDataDirs ( dataDirs ) ;
2013-03-09 20:08:08 +00:00
// fallback archives
2016-07-12 16:09:57 +00:00
StringsVector archives = variables [ " fallback-archive " ] . as < Files : : EscapeStringVector > ( ) . toStdStringVector ( ) ;
2013-07-31 16:46:32 +00:00
for ( StringsVector : : const_iterator it = archives . begin ( ) ; it ! = archives . end ( ) ; + + it )
2013-03-09 20:08:08 +00:00
{
engine . addArchive ( * it ) ;
}
2016-07-12 16:09:57 +00:00
StringsVector content = variables [ " content " ] . as < Files : : EscapeStringVector > ( ) . toStdStringVector ( ) ;
2013-09-29 07:11:57 +00:00
if ( content . empty ( ) )
2011-03-29 11:57:56 +00:00
{
2018-08-14 19:05:43 +00:00
Log ( Debug : : Error ) < < " No content file given (esm/esp, nor omwgame/omwaddon). Aborting... " ;
return false ;
2011-03-29 11:57:56 +00:00
}
2021-08-01 08:53:52 +00:00
std : : set < std : : string > contentDedupe ;
for ( const auto & contentFile : content )
{
if ( ! contentDedupe . insert ( contentFile ) . second )
{
Log ( Debug : : Error ) < < " Content file specified more than once: " < < contentFile < < " . Aborting... " ;
return false ;
}
}
2011-03-29 11:57:56 +00:00
2020-01-12 07:42:47 +00:00
for ( auto & file : content )
{
engine . addContentFile ( file ) ;
}
StringsVector groundcover = variables [ " groundcover " ] . as < Files : : EscapeStringVector > ( ) . toStdStringVector ( ) ;
for ( auto & file : groundcover )
2011-08-19 19:06:09 +00:00
{
2020-01-12 07:42:47 +00:00
engine . addGroundcoverFile ( file ) ;
2011-08-19 19:06:09 +00:00
}
2011-03-29 11:57:56 +00:00
// startup-settings
2016-07-11 21:05:38 +00:00
engine . setCell ( variables [ " start " ] . as < Files : : EscapeHashString > ( ) . toStdString ( ) ) ;
2014-09-01 09:55:12 +00: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 19:05:43 +00:00
Log ( Debug : : Warning ) < < " Warning: new-game used without skip-menu -> ignoring it " ;
2011-03-29 11:57:56 +00:00
2014-07-21 07:34:10 +00:00
// scripts
2011-08-19 19:06:09 +00:00
engine . setCompileAll ( variables [ " script-all " ] . as < bool > ( ) ) ;
2014-12-13 01:47:04 +00:00
engine . setCompileAllDialogue ( variables [ " script-all-dialogue " ] . as < bool > ( ) ) ;
2012-07-30 09:43:28 +00:00
engine . setScriptConsoleMode ( variables [ " script-console " ] . as < bool > ( ) ) ;
2022-04-09 16:28:39 +00:00
/*
Start of tes3mp change ( major )
Clients should not be allowed to set any of these unilaterally in multiplayer , so
disable them
*/
/*
2016-07-11 21:05:38 +00:00
engine . setStartupScript ( variables [ " script-run " ] . as < Files : : EscapeHashString > ( ) . toStdString ( ) ) ;
2014-02-02 13:09:59 +00:00
engine . setWarningsMode ( variables [ " script-warn " ] . as < int > ( ) ) ;
2016-07-12 16:09:57 +00:00
engine . setScriptBlacklist ( variables [ " script-blacklist " ] . as < Files : : EscapeStringVector > ( ) . toStdStringVector ( ) ) ;
2014-07-21 07:34:10 +00:00
engine . setScriptBlacklistUse ( variables [ " script-blacklist-use " ] . as < bool > ( ) ) ;
2020-10-23 14:34:41 +00:00
engine . setSaveGameFile ( variables [ " load-savegame " ] . as < Files : : EscapePath > ( ) . mPath . string ( ) ) ;
2022-04-09 16:28:39 +00:00
*/
/*
End of tes3mp change ( major )
*/
2014-07-21 07:34:10 +00:00
// other settings
2019-01-22 06:08:48 +00:00
Fallback : : Map : : init ( variables [ " fallback " ] . as < FallbackMap > ( ) . mMap ) ;
2014-07-21 07:34:10 +00:00
engine . setSoundUsage ( ! variables [ " no-sound " ] . as < bool > ( ) ) ;
engine . setActivationDistanceOverride ( variables [ " activate-dist " ] . as < int > ( ) ) ;
2014-08-11 18:37:29 +00:00
engine . enableFontExport ( variables [ " export-fonts " ] . as < bool > ( ) ) ;
2019-02-24 19:41:11 +00:00
engine . setRandomSeed ( variables [ " random-seed " ] . as < unsigned int > ( ) ) ;
2010-10-06 12:52:53 +00:00
2017-07-15 09:44:00 +00:00
/*
Start of tes3mp addition
Configure multiplayer using parsed variables
*/
2016-11-15 19:54:06 +00:00
mwmp : : Main : : configure ( & variables ) ;
2017-07-15 09:44:00 +00:00
/*
End of tes3mp addition
*/
2016-08-24 08:15:34 +00:00
2010-06-23 00:52:17 +00:00
return true ;
2010-06-16 10:21:02 +00:00
}
2020-12-04 10:17:49 +00:00
namespace
{
class OSGLogHandler : public osg : : NotifyHandler
{
void notify ( osg : : NotifySeverity severity , const char * msg ) override
{
// Copy, because osg logging is not thread safe.
std : : string msgCopy ( msg ) ;
if ( msgCopy . empty ( ) )
return ;
Debug : : Level level ;
switch ( severity )
{
case osg : : ALWAYS :
case osg : : FATAL :
level = Debug : : Error ;
break ;
case osg : : WARN :
case osg : : NOTICE :
level = Debug : : Warning ;
break ;
case osg : : INFO :
level = Debug : : Info ;
break ;
case osg : : DEBUG_INFO :
case osg : : DEBUG_FP :
default :
level = Debug : : Debug ;
}
std : : string_view s ( msgCopy ) ;
2021-01-08 22:21:39 +00:00
if ( s . size ( ) < 1024 )
Log ( level ) < < ( s . back ( ) = = ' \n ' ? s . substr ( 0 , s . size ( ) - 1 ) : s ) ;
else
{
while ( ! s . empty ( ) )
{
size_t lineSize = 1 ;
while ( lineSize < s . size ( ) & & s [ lineSize - 1 ] ! = ' \n ' )
lineSize + + ;
Log ( level ) < < s . substr ( 0 , s [ lineSize - 1 ] = = ' \n ' ? lineSize - 1 : lineSize ) ;
s = s . substr ( lineSize ) ;
}
}
2020-12-04 10:17:49 +00:00
}
} ;
}
2018-08-03 11:51:17 +00:00
int runApplication ( int argc , char * argv [ ] )
2010-09-19 00:01:01 +00:00
{
2018-08-03 11:51:17 +00: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 20:40:59 +00:00
setenv ( " OSG_GL_TEXTURE_STORAGE " , " OFF " , 0 ) ;
# endif
2020-12-04 10:17:49 +00:00
osg : : setNotifyHandler ( new OSGLogHandler ( ) ) ;
2018-08-03 11:51:17 +00:00
Files : : ConfigurationManager cfgMgr ;
2017-04-28 15:30:26 +00:00
std : : unique_ptr < OMW : : Engine > engine ;
2018-08-03 11:51:17 +00:00
engine . reset ( new OMW : : Engine ( cfgMgr ) ) ;
2010-09-19 00:01:01 +00:00
2018-08-03 11:51:17 +00:00
if ( parseOptions ( argc , argv , * engine , cfgMgr ) )
2010-09-19 00:01:01 +00:00
{
2018-08-03 11:51:17 +00:00
engine - > go ( ) ;
2010-09-19 00:01:01 +00:00
}
2018-08-03 11:51:17 +00:00
return 0 ;
}
2010-09-19 00:01:01 +00:00
2018-01-14 23:14:30 +00:00
# ifdef ANDROID
extern " C " int SDL_main ( int argc , char * * argv )
# else
2014-06-10 00:22:58 +00:00
int main ( int argc , char * * argv )
2018-01-14 23:14:30 +00:00
# endif
2010-09-19 00:01:01 +00:00
{
2019-08-20 07:06:15 +00:00
/*
Start of tes3mp addition
Initialize the logger added for multiplayer
*/
LOG_INIT ( TimedLog : : LOG_INFO ) ;
/*
End of tes3mp addition
*/
2018-08-20 11:08:44 +00:00
/*
Start of tes3mp change ( major )
2014-06-10 00:22:58 +00:00
2018-08-20 11:08:44 +00:00
Instead of logging information in openmw . log , use a more descriptive filename
that includes a timestamp
*/
2019-08-20 07:06:15 +00:00
return wrapApplication ( & runApplication , argc , argv , " /tes3mp-client- " + TimedLog : : getFilenameTimestamp ( ) ) ;
2018-08-20 11:08:44 +00:00
/*
End of tes3mp change ( major )
*/
2010-09-19 00:01:01 +00:00
}
2014-06-10 00:22:58 +00: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 00:01:01 +00:00
# endif