Skip to content

Commit

Permalink
added quickstart parameters to release builds
Browse files Browse the repository at this point in the history
  • Loading branch information
afwbkbc committed Nov 3, 2024
1 parent a4e83cc commit 43ec0e3
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 137 deletions.
119 changes: 60 additions & 59 deletions src/config/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,36 +134,15 @@ Config::Config( const int argc, const char* argv[] )
}
);

#ifdef DEBUG
m_parser->AddRule(
"gdb", "Try to start within gdb (on supported platforms)", AH( this ) {
m_debug_flags |= DF_GDB;
}
);
m_parser->AddRule(
"mapdump", "Save map dump upon loading map", AH( this ) {
m_debug_flags |= DF_MAPDUMP;
}
);
m_parser->AddRule(
"memorydebug", "Add extra memory checks and tracking (slow!)", AH( this ) {
m_debug_flags |= DF_MEMORYDEBUG;
}
);
m_parser->AddRule(
"nopings", "Omit pings and timeouts during multiplayer games", AH( this ) {
m_debug_flags |= DF_NOPINGS;
}
);
m_parser->AddRule(
"quickstart", "Skip intro and main menu and generate/load map directly", AH( this ) {
m_debug_flags |= DF_QUICKSTART;
m_launch_flags |= LF_QUICKSTART;
}
);
const std::string s_quickstart_argument_missing = "Quickstart-related options can only be used after --quickstart argument!";
m_parser->AddRule(
"quickstart-seed", "SEED", "Generate map with specific seed (A:B:C:D)", AH( this, s_quickstart_argument_missing ) {
if ( !HasDebugFlag( DF_QUICKSTART ) ) {
if ( !HasLaunchFlag( LF_QUICKSTART ) ) {
Error( s_quickstart_argument_missing );
}
try {
Expand All @@ -172,50 +151,38 @@ Config::Config( const int argc, const char* argv[] )
catch ( std::runtime_error& e ) {
Error( "Invalid seed format! Seed must contain four numbers separated by colon, for example: 1651011033:1377505029:3019448108:3247278135" );
}
m_debug_flags |= DF_QUICKSTART_SEED;
}
);
m_parser->AddRule(
"quickstart-mapdump", "MAP_DUMP_FILE", "Load from existing map dump file (*.gsmd)", AH( this, s_quickstart_argument_missing ) {
if ( !HasDebugFlag( DF_QUICKSTART ) ) {
Error( s_quickstart_argument_missing );
}
if ( !util::FS::FileExists( value ) ) {
Error( "Map dump file \"" + value + "\" not found!" );
}
m_quickstart_mapdump = value;
m_debug_flags |= DF_QUICKSTART_MAP_DUMP;
m_launch_flags |= LF_QUICKSTART_SEED;
}
);
m_parser->AddRule(
"quickstart-mapfile", "MAP_FILE", "Load from existing map file (*.gsm)", AH( this, s_quickstart_argument_missing ) {
if ( !HasDebugFlag( DF_QUICKSTART ) ) {
if ( !HasLaunchFlag( LF_QUICKSTART ) ) {
Error( s_quickstart_argument_missing );
}
if ( !util::FS::FileExists( value ) ) {
Error( "Map file \"" + value + "\" not found!" );
}
m_quickstart_mapfile = value;
m_debug_flags |= DF_QUICKSTART_MAP_FILE;
m_launch_flags |= LF_QUICKSTART_MAP_FILE;
}
);
m_parser->AddRule(
"quickstart-mapsize", "MAP_SIZE", "Generate map of specific size (WxH)", AH( this, s_quickstart_argument_missing ) {
if ( !HasDebugFlag( DF_QUICKSTART ) ) {
if ( !HasLaunchFlag( LF_QUICKSTART ) ) {
Error( s_quickstart_argument_missing );
}
m_quickstart_mapsize = ParseSize( value );
m_debug_flags |= DF_QUICKSTART_MAP_SIZE;
m_launch_flags |= LF_QUICKSTART_MAP_SIZE;
}
);
const auto f_add_map_parameter_option =
[ this, s_quickstart_argument_missing ]( const std::string& name, const std::vector< std::string >& values, const std::string& desc, debug_flag_t flag, game::backend::settings::map_config_value_t* out_param )
[ this, s_quickstart_argument_missing ]( const std::string& name, const std::vector< std::string >& values, const std::string& desc, launch_flag_t flag, game::backend::settings::map_config_value_t* out_param )
-> void {
ASSERT( values.size() == 3, "values size mismatch" );
m_parser->AddRule(
name, values[ 0 ] + "|" + values[ 1 ] + "|" + values[ 2 ], "Generate map with specific " + desc + " setting",
AH( this, name, values, s_quickstart_argument_missing, out_param, &desc, flag ) {
if ( !HasDebugFlag( DF_QUICKSTART ) ) {
if ( !HasLaunchFlag( LF_QUICKSTART ) ) {
Error( s_quickstart_argument_missing );
}
if ( value == values[ 0 ] ) {
Expand All @@ -230,7 +197,7 @@ Config::Config( const int argc, const char* argv[] )
else {
Error( "Invalid --" + name + " value specified! Possible choices: " + values[ 0 ] + " " + values[ 1 ] + " " + values[ 2 ] );
}
m_debug_flags |= flag;
m_launch_flags |= flag;
}
);
};
Expand All @@ -240,39 +207,73 @@ Config::Config( const int argc, const char* argv[] )
"medium",
"high"
}, "ocean coverage",
DF_QUICKSTART_MAP_OCEAN, &m_quickstart_map_ocean
LF_QUICKSTART_MAP_OCEAN, &m_quickstart_map_ocean
);
f_add_map_parameter_option(
"quickstart-map-erosive", {
"strong",
"average",
"weak"
}, "erosive forces",
DF_QUICKSTART_MAP_EROSIVE, &m_quickstart_map_erosive
LF_QUICKSTART_MAP_EROSIVE, &m_quickstart_map_erosive
);
f_add_map_parameter_option(
"quickstart-map-lifeforms", {
"rare",
"average",
"abundant"
}, "native lifeforms",
DF_QUICKSTART_MAP_LIFEFORMS, &m_quickstart_map_lifeforms
LF_QUICKSTART_MAP_LIFEFORMS, &m_quickstart_map_lifeforms
);
f_add_map_parameter_option(
"quickstart-map-clouds", {
"sparse",
"average",
"dense"
}, "cloud cover",
DF_QUICKSTART_MAP_CLOUDS, &m_quickstart_map_clouds
LF_QUICKSTART_MAP_CLOUDS, &m_quickstart_map_clouds
);
m_parser->AddRule(
"quickstart-faction", "FACTION", "Play as specific faction", AH( this, s_quickstart_argument_missing ) {
if ( !HasDebugFlag( DF_QUICKSTART ) ) {
if ( !HasLaunchFlag( LF_QUICKSTART ) ) {
Error( s_quickstart_argument_missing );
}
m_quickstart_faction = value;
m_debug_flags |= DF_QUICKSTART_FACTION;
m_launch_flags |= LF_QUICKSTART_FACTION;
}
);

#ifdef DEBUG
m_parser->AddRule(
"gdb", "Try to start within gdb (on supported platforms)", AH( this ) {
m_debug_flags |= DF_GDB;
}
);
m_parser->AddRule(
"mapdump", "Save map dump upon loading map", AH( this ) {
m_debug_flags |= DF_MAPDUMP;
}
);
m_parser->AddRule(
"memorydebug", "Add extra memory checks and tracking (slow!)", AH( this ) {
m_debug_flags |= DF_MEMORYDEBUG;
}
);
m_parser->AddRule(
"nopings", "Omit pings and timeouts during multiplayer games", AH( this ) {
m_debug_flags |= DF_NOPINGS;
}
);
m_parser->AddRule(
"quickstart-mapdump", "MAP_DUMP_FILE", "Load from existing map dump file (*.gsmd)", AH( this, s_quickstart_argument_missing ) {
if ( !HasLaunchFlag( LF_QUICKSTART ) ) {
Error( s_quickstart_argument_missing );
}
if ( !util::FS::FileExists( value ) ) {
Error( "Map dump file \"" + value + "\" not found!" );
}
m_quickstart_mapdump = value;
m_debug_flags |= DF_QUICKSTART_MAP_DUMP;
}
);
m_parser->AddRule(
Expand Down Expand Up @@ -372,20 +373,10 @@ const types::Vec2< size_t >& Config::GetWindowSize() const {
return m_window_size;
}

#ifdef DEBUG

const bool Config::HasDebugFlag( const debug_flag_t flag ) const {
return m_debug_flags & flag;
}

const util::random::state_t& Config::GetQuickstartSeed() const {
return m_quickstart_seed;
}

const std::string& Config::GetQuickstartMapDump() const {
return m_quickstart_mapdump;
}

const std::string& Config::GetQuickstartMapFile() const {
return m_quickstart_mapfile;
}
Expand Down Expand Up @@ -414,6 +405,16 @@ const std::string& Config::GetQuickstartFaction() const {
return m_quickstart_faction;
}

#ifdef DEBUG

const bool Config::HasDebugFlag( const debug_flag_t flag ) const {
return m_debug_flags & flag;
}

const std::string& Config::GetQuickstartMapDump() const {
return m_quickstart_mapdump;
}

const std::string& Config::GetGSETestsScript() const {
return m_gse_tests_script;
}
Expand Down
59 changes: 30 additions & 29 deletions src/config/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,38 @@ CLASS( Config, common::Module )

void Init();

enum launch_flag_t : uint8_t {
enum launch_flag_t : uint16_t {
LF_NONE = 0,
LF_BENCHMARK = 1 << 0,
LF_SHOWFPS = 1 << 1,
LF_NOSOUND = 1 << 2,
LF_SKIPINTRO = 1 << 3,
LF_WINDOWED = 1 << 4,
LF_WINDOW_SIZE = 1 << 5
LF_WINDOW_SIZE = 1 << 5,
LF_QUICKSTART = 1 << 6,
LF_QUICKSTART_SEED = 1 << 7,
LF_QUICKSTART_MAP_FILE = 1 << 8,
LF_QUICKSTART_MAP_SIZE = 1 << 9,
LF_QUICKSTART_MAP_OCEAN = 1 << 10,
LF_QUICKSTART_MAP_EROSIVE = 1 << 11,
LF_QUICKSTART_MAP_LIFEFORMS = 1 << 12,
LF_QUICKSTART_MAP_CLOUDS = 1 << 13,
LF_QUICKSTART_FACTION = 1 << 14,
};

#ifdef DEBUG
enum debug_flag_t : uint32_t {
enum debug_flag_t : uint16_t {
DF_NONE = 0,
DF_GDB = 1 << 0,
DF_MAPDUMP = 1 << 1,
DF_MEMORYDEBUG = 1 << 2,
DF_QUICKSTART = 1 << 3,
DF_QUICKSTART_SEED = 1 << 4,
DF_QUICKSTART_MAP_DUMP = 1 << 5,
DF_QUICKSTART_MAP_FILE = 1 << 6,
DF_QUICKSTART_MAP_SIZE = 1 << 7,
DF_QUICKSTART_MAP_OCEAN = 1 << 8,
DF_QUICKSTART_MAP_EROSIVE = 1 << 9,
DF_QUICKSTART_MAP_LIFEFORMS = 1 << 10,
DF_QUICKSTART_MAP_CLOUDS = 1 << 11,
DF_QUICKSTART_FACTION = 1 << 12,
DF_QUIET = 1 << 13,
DF_GSE_ONLY = 1 << 14,
DF_GSE_TESTS = 1 << 15,
DF_GSE_TESTS_SCRIPT = 1 << 16,
DF_GSE_PROMPT_JS = 1 << 17,
DF_NOPINGS = 1 << 18,
DF_QUIET = 1 << 3,
DF_GSE_ONLY = 1 << 4,
DF_GSE_TESTS = 1 << 5,
DF_GSE_TESTS_SCRIPT = 1 << 6,
DF_GSE_PROMPT_JS = 1 << 7,
DF_NOPINGS = 1 << 8,
DF_QUICKSTART_MAP_DUMP = 1 << 9,
};
#endif

Expand All @@ -72,18 +72,19 @@ CLASS( Config, common::Module )
const bool HasLaunchFlag( const launch_flag_t flag ) const;
const types::Vec2< size_t >& GetWindowSize() const;

#ifdef DEBUG

const bool HasDebugFlag( const debug_flag_t flag ) const;
const util::random::state_t& GetQuickstartSeed() const;
const std::string& GetQuickstartMapDump() const;
const std::string& GetQuickstartMapFile() const;
const types::Vec2< size_t >& GetQuickstartMapSize() const;
const game::backend::settings::map_config_value_t GetQuickstartMapOcean() const;
const game::backend::settings::map_config_value_t GetQuickstartMapErosive() const;
const game::backend::settings::map_config_value_t GetQuickstartMapLifeforms() const;
const game::backend::settings::map_config_value_t GetQuickstartMapClouds() const;
const std::string& GetQuickstartFaction() const;

#ifdef DEBUG

const bool HasDebugFlag( const debug_flag_t flag ) const;
const std::string& GetQuickstartMapDump() const;
const std::string& GetGSETestsScript() const;

#endif
Expand All @@ -94,7 +95,6 @@ CLASS( Config, common::Module )

void Error( const std::string& error );
const types::Vec2< size_t > ParseSize( const std::string& value );
void CheckAndSetSMACPath( const std::string& path );

const std::string DEFAULT_GLSMAC_PREFIX =
#ifdef _WIN32
Expand All @@ -109,14 +109,10 @@ CLASS( Config, common::Module )
std::string m_smac_path;
smac_type_t m_smac_type = ST_AUTO;

uint8_t m_launch_flags = LF_NONE;
uint16_t m_launch_flags = LF_NONE;
types::Vec2< size_t > m_window_size = {};

#ifdef DEBUG

uint32_t m_debug_flags = DF_NONE;
util::random::state_t m_quickstart_seed = {};
std::string m_quickstart_mapdump = "";
std::string m_quickstart_mapfile = "";
types::Vec2< size_t > m_quickstart_mapsize = {};
game::backend::settings::map_config_value_t m_quickstart_map_ocean = game::backend::settings::MAP_CONFIG_OCEAN_MEDIUM;
Expand All @@ -125,6 +121,11 @@ CLASS( Config, common::Module )
game::backend::settings::map_config_value_t m_quickstart_map_clouds = game::backend::settings::MAP_CONFIG_CLOUDS_AVERAGE;
std::string m_quickstart_faction = "";

#ifdef DEBUG

uint16_t m_debug_flags = DF_NONE;
std::string m_quickstart_mapdump = "";

std::string m_gse_tests_script = "";

#endif
Expand Down
13 changes: 4 additions & 9 deletions src/game/backend/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,10 @@ void Game::Start() {

NEW( m_random, util::random::Random );

#ifdef DEBUG
const auto* config = g_engine->GetConfig();
if ( config->HasDebugFlag( config::Config::DF_QUICKSTART_SEED ) ) {
if ( config->HasLaunchFlag( config::Config::LF_QUICKSTART_SEED ) ) {
m_random->SetState( config->GetQuickstartSeed() );
}
#endif

// init map editor
NEW( m_map_editor, map_editor::MapEditor, this );
Expand Down Expand Up @@ -1945,9 +1943,9 @@ void Game::InitGame( MT_Response& response, MT_CANCELABLE ) {
}
NEW( m_map, map::Map, this );

#ifdef DEBUG
const auto* config = g_engine->GetConfig();

#ifdef DEBUG
// if crash happens - it's handy to have a seed to reproduce it
util::FS::WriteFile( config->GetDebugPath() + map::s_consts.debug.lastseed_filename, m_random->GetStateString() );
#endif
Expand All @@ -1966,14 +1964,11 @@ void Game::InitGame( MT_Response& response, MT_CANCELABLE ) {
else
#endif
{
#ifdef DEBUG
if ( !m_connection && config->HasDebugFlag( config::Config::DF_QUICKSTART_MAP_FILE ) ) {
if ( !m_connection && config->HasLaunchFlag( config::Config::LF_QUICKSTART_MAP_FILE ) ) {
const std::string& filename = config->GetQuickstartMapFile();
ec = m_map->LoadFromFile( filename );
}
else
#endif
{
else {
auto& map_settings = m_state->m_settings.global.map;
if ( map_settings.type == settings::MapSettings::MT_MAPFILE ) {
ASSERT( !map_settings.filename.empty(), "loading map requested but map file not specified" );
Expand Down
Loading

0 comments on commit 43ec0e3

Please sign in to comment.