Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add --game & --map to command-line options

if both parameters are set, this starts spring a with minimal setup and
it sets the modoption minimalsetup = 1
  • Loading branch information...
commit 041a021047efcf634ea19ce815c9385c7e77cc38 1 parent cb3fd46
@abma abma authored
View
7 doc/manpages/spring.6.txt
@@ -125,6 +125,13 @@ ifndef::DEDICATED[ Dump a list of available Skirmish AIs to STDOUT]
*--list-config-vars*::
Dump all default config vars in JSON-format to STDOUT
+*--game*::'GAME'::
+ instantly start the GAME with a minimal setup. Requires --map to be present, too.
+ Sets the modoption minimalsetup = 1
+
+*--map*::'MAP'::
+ Requires --game to be set, too. see --game
+
DATA DIR
--------
Data directories are searched for content, and among other things, may contain:
View
1  rts/Menu/CMakeLists.txt
@@ -2,7 +2,6 @@
# This list was created using this *nix shell command:
# > find . -name "*.cpp"" | sort
SET(sources_engine_Menu
- "${CMAKE_CURRENT_SOURCE_DIR}/ScriptHandler.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/SelectMenu.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/SelectionWidget.cpp"
)
View
66 rts/Menu/SelectMenu.cpp
@@ -10,7 +10,7 @@
#include <boost/cstdint.hpp>
#include "SelectionWidget.h"
-#include "ScriptHandler.h"
+#include "System/AIScriptHandler.h"
#include "Game/ClientSetup.h"
#include "Game/GlobalUnsynced.h"
#include "Game/PreGame.h"
@@ -19,7 +19,6 @@
#include "System/Config/ConfigHandler.h"
#include "System/Exceptions.h"
#include "System/Log/ILog.h"
-#include "System/TdfParser.h"
#include "System/Util.h"
#include "System/Input/InputHandler.h"
#include "System/FileSystem/ArchiveScanner.h"
@@ -27,6 +26,7 @@
#include "System/FileSystem/VFSHandler.h"
#include "System/FileSystem/FileSystem.h"
#include "System/MsgStrings.h"
+#include "System/StartScriptGen.h"
#include "aGui/Gui.h"
#include "aGui/VerticalLayout.h"
#include "aGui/HorizontalLayout.h"
@@ -120,66 +120,6 @@ class SettingsWindow : public agui::Window
};
};
-std::string CreateDefaultSetup(const std::string& map, const std::string& mod, const std::string& script,
- const std::string& playername)
-{
- TdfParser::TdfSection setup;
- TdfParser::TdfSection* game = setup.construct_subsection("GAME");
- game->add_name_value("Mapname", map);
- game->add_name_value("Gametype", mod);
-
- TdfParser::TdfSection* modopts = game->construct_subsection("MODOPTIONS");
- modopts->AddPair("MaxSpeed", 20);
-
- game->AddPair("IsHost", 1);
- game->AddPair("OnlyLocal", 1);
- game->add_name_value("MyPlayerName", playername);
-
- game->AddPair("NoHelperAIs", configHandler->GetBool("NoHelperAIs"));
-
- TdfParser::TdfSection* player0 = game->construct_subsection("PLAYER0");
- player0->add_name_value("Name", playername);
- player0->AddPair("Team", 0);
-
- const bool isSkirmishAITestScript = CScriptHandler::Instance().IsSkirmishAITestScript(script);
- if (isSkirmishAITestScript) {
- SkirmishAIData aiData = CScriptHandler::Instance().GetSkirmishAIData(script);
- TdfParser::TdfSection* ai = game->construct_subsection("AI0");
- ai->add_name_value("Name", "Enemy");
- ai->add_name_value("ShortName", aiData.shortName);
- ai->add_name_value("Version", aiData.version);
- ai->AddPair("Host", 0);
- ai->AddPair("Team", 1);
- } else {
- TdfParser::TdfSection* player1 = game->construct_subsection("PLAYER1");
- player1->add_name_value("Name", "Enemy");
- player1->AddPair("Team", 1);
- }
-
- TdfParser::TdfSection* team0 = game->construct_subsection("TEAM0");
- team0->AddPair("TeamLeader", 0);
- team0->AddPair("AllyTeam", 0);
-
- TdfParser::TdfSection* team1 = game->construct_subsection("TEAM1");
- if (isSkirmishAITestScript) {
- team1->AddPair("TeamLeader", 0);
- } else {
- team1->AddPair("TeamLeader", 1);
- }
- team1->AddPair("AllyTeam", 1);
-
- TdfParser::TdfSection* ally0 = game->construct_subsection("ALLYTEAM0");
- ally0->AddPair("NumAllies", 0);
-
- TdfParser::TdfSection* ally1 = game->construct_subsection("ALLYTEAM1");
- ally1->AddPair("NumAllies", 0);
-
- std::ostringstream str;
- setup.print(str);
-
- return str.str();
-}
-
SelectMenu::SelectMenu(bool server) : GuiElement(NULL), conWindow(NULL), settingsWindow(NULL), curSelect(NULL)
{
SetPos(0,0);
@@ -268,7 +208,7 @@ void SelectMenu::Single()
once = true;
mySettings->isHost = true;
pregame = new CPreGame(mySettings);
- pregame->LoadSetupscript(CreateDefaultSetup(selw->userMap, selw->userMod, selw->userScript, mySettings->myPlayerName));
+ pregame->LoadSetupscript(StartScriptGen::CreateDefaultSetup(selw->userMap, selw->userMod, selw->userScript, mySettings->myPlayerName));
agui::gui->RmElement(this);
//delete this;
}
View
6 rts/Menu/SelectionWidget.cpp
@@ -8,7 +8,7 @@
#include "System/FileSystem/FileSystem.h"
#include "System/Exceptions.h"
#include "System/Config/ConfigHandler.h"
-#include "ScriptHandler.h"
+#include "System/AIScriptHandler.h"
const std::string SelectionWidget::NoModSelect = "No game selected";
const std::string SelectionWidget::NoMapSelect = "No map selected";
@@ -106,8 +106,8 @@ void SelectionWidget::ShowScriptList()
curSelect->Selected.connect(boost::bind(&SelectionWidget::SelectScript, this, _1));
curSelect->WantClose.connect(boost::bind(&SelectionWidget::CleanWindow, this));
- CScriptHandler::ScriptList scriptList = CScriptHandler::Instance().GetScriptList();
- for (CScriptHandler::ScriptList::iterator it = scriptList.begin(); it != scriptList.end(); ++it) {
+ CAIScriptHandler::ScriptList scriptList = CAIScriptHandler::Instance().GetScriptList();
+ for (CAIScriptHandler::ScriptList::iterator it = scriptList.begin(); it != scriptList.end(); ++it) {
curSelect->list->AddItem(*it, "");
}
View
16 rts/Menu/ScriptHandler.cpp → rts/System/AIScriptHandler.cpp
@@ -1,6 +1,6 @@
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
-#include "ScriptHandler.h"
+#include "AIScriptHandler.h"
#include "ExternalAI/Interface/aidefines.h"
#include "ExternalAI/IAILibraryManager.h"
@@ -8,14 +8,14 @@
#include <stdexcept>
-CScriptHandler& CScriptHandler::Instance()
+CAIScriptHandler& CAIScriptHandler::Instance()
{
- static CScriptHandler instance;
+ static CAIScriptHandler instance;
return instance;
}
-bool CScriptHandler::IsSkirmishAITestScript(const std::string& scriptName) const
+bool CAIScriptHandler::IsSkirmishAITestScript(const std::string& scriptName) const
{
const ScriptMap::const_iterator scriptsIt = scripts.find(scriptName);
@@ -26,7 +26,7 @@ bool CScriptHandler::IsSkirmishAITestScript(const std::string& scriptName) const
}
-const SkirmishAIData& CScriptHandler::GetSkirmishAIData(const std::string& scriptName) const
+const SkirmishAIData& CAIScriptHandler::GetSkirmishAIData(const std::string& scriptName) const
{
const ScriptMap::const_iterator scriptsIt = scripts.find(scriptName);
@@ -44,14 +44,14 @@ const SkirmishAIData& CScriptHandler::GetSkirmishAIData(const std::string& scrip
}
-void CScriptHandler::Add(CScript* script)
+void CAIScriptHandler::Add(CScript* script)
{
scripts.insert(ScriptMap::value_type(script->name, script));
scriptNames.push_back(script->name);
}
-CScriptHandler::CScriptHandler()
+CAIScriptHandler::CAIScriptHandler()
{
// default script
Add(new CScript("Player Only: Testing Sandbox"));
@@ -75,7 +75,7 @@ CScriptHandler::CScriptHandler()
}
-CScriptHandler::~CScriptHandler()
+CAIScriptHandler::~CAIScriptHandler()
{
for (ScriptMap::iterator it = scripts.begin(); it != scripts.end(); ++it) {
delete it->second;
View
8 rts/Menu/ScriptHandler.h → rts/System/AIScriptHandler.h
@@ -5,7 +5,7 @@
#include "ExternalAI/SkirmishAIData.h"
-class CScriptHandler
+class CAIScriptHandler
{
private:
struct CScript {
@@ -27,7 +27,7 @@ class CScriptHandler
typedef std::vector<std::string> ScriptList;
typedef std::map<std::string, CScript*> ScriptMap;
- static CScriptHandler& Instance();
+ static CAIScriptHandler& Instance();
bool IsSkirmishAITestScript(const std::string& scriptName) const;
const SkirmishAIData& GetSkirmishAIData(const std::string& scriptName) const;
@@ -37,8 +37,8 @@ class CScriptHandler
private:
void Add(CScript* script);
- CScriptHandler();
- ~CScriptHandler();
+ CAIScriptHandler();
+ ~CAIScriptHandler();
ScriptMap scripts;
ScriptList scriptNames;
View
2  rts/System/CMakeLists.txt
@@ -3,6 +3,7 @@
# > find . -name "*.cpp" -or -name "*.c" | sort
# Then Sound/ stuff was removed, because it is now a separate static lib.
SET(sources_engine_System_common
+ "${CMAKE_CURRENT_SOURCE_DIR}/AIScriptHandler.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/AutohostInterface.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/BaseNetProtocol.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Config/ConfigHandler.cpp"
@@ -50,6 +51,7 @@ SET(sources_engine_System_common
"${CMAKE_CURRENT_SOURCE_DIR}/SafeVector.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/SafeCStrings.c"
"${CMAKE_CURRENT_SOURCE_DIR}/SpringApp.cpp"
+ "${CMAKE_CURRENT_SOURCE_DIR}/StartScriptGen.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Sync/FPUCheck.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Sync/Logger.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Sync/SyncChecker.cpp"
View
70 rts/System/SpringApp.cpp
@@ -51,6 +51,7 @@
#include "System/Log/ILog.h"
#include "System/myMath.h"
#include "System/OpenMP_cond.h"
+#include "System/StartScriptGen.h"
#include "System/TimeProfiler.h"
#include "System/Util.h"
#include "System/FileSystem/DataDirLocater.h"
@@ -726,6 +727,8 @@ void SpringApp::ParseCmdLine()
cmdline->AddSwitch(0, "list-config-vars", "Dump a list of config vars and meta data to stdout");
cmdline->AddSwitch('i', "isolation", "Limit the data-dir (games & maps) scanner to one directory");
cmdline->AddString(0, "isolation-dir", "Specify the isolation-mode data-dir (see --isolation)");
+ cmdline->AddString(0, "game", "Specify the game that will be instantly loaded");
+ cmdline->AddString(0, "map", "Specify the map that will be instantly loaded");
try {
cmdline->Parse();
@@ -819,11 +822,38 @@ void SpringApp::ParseCmdLine()
}
+void SpringApp::RunScript(const std::string buf) {
+ startsetup = new ClientSetup();
+ startsetup->Init(buf);
+
+ // commandline parameters overwrite setup
+ if (cmdline->IsSet("client"))
+ startsetup->isHost = false;
+ else if (cmdline->IsSet("server"))
+ startsetup->isHost = true;
+
+#ifdef SYNCDEBUG
+ CSyncDebugger::GetInstance()->Initialize(startsetup->isHost, 64); //FIXME: add actual number of player
+#endif
+ pregame = new CPreGame(startsetup);
+ if (startsetup->isHost)
+ pregame->LoadSetupscript(buf);
+}
+
+
/**
* Initializes instance of GameSetup
*/
void SpringApp::Startup()
{
+ if ((cmdline->IsSet("game") && cmdline->IsSet("map"))) { // --game and --map directly specified, try to run them
+ const std::string game = cmdline->GetString("game");
+ const std::string map = cmdline->GetString("map");
+ std::string buf = StartScriptGen::CreateMinimalSetup(game, map);
+ RunScript(buf);
+ return;
+ }
+
std::string inputFile = cmdline->GetInputFile();
if (inputFile.empty())
{
@@ -886,21 +916,7 @@ void SpringApp::Startup()
std::string buf;
if (!fh.LoadStringData(buf))
throw content_error("Setup-script cannot be read: " + startscript);
- startsetup = new ClientSetup();
- startsetup->Init(buf);
-
- // commandline parameters overwrite setup
- if (cmdline->IsSet("client"))
- startsetup->isHost = false;
- else if (cmdline->IsSet("server"))
- startsetup->isHost = true;
-
-#ifdef SYNCDEBUG
- CSyncDebugger::GetInstance()->Initialize(startsetup->isHost, 64); //FIXME: add actual number of player
-#endif
- pregame = new CPreGame(startsetup);
- if (startsetup->isHost)
- pregame->LoadSetupscript(buf);
+ RunScript(buf);
}
}
@@ -1023,18 +1039,16 @@ void SpringApp::Shutdown()
{
if (gu) gu->globalQuit = true;
-#define DeleteAndNull(x) delete x; x = NULL;
-
GML::Exit();
- DeleteAndNull(pregame);
- DeleteAndNull(game);
+ SafeDelete(pregame);
+ SafeDelete(game);
SafeDelete(net);
- DeleteAndNull(gameServer);
- DeleteAndNull(gameSetup);
+ SafeDelete(gameServer);
+ SafeDelete(gameSetup);
CLoadScreen::DeleteInstance();
ISound::Shutdown();
- DeleteAndNull(font);
- DeleteAndNull(smallFont);
+ SafeDelete(font);
+ SafeDelete(smallFont);
CNamedTextures::Kill();
GLContext::Free();
GlobalConfig::Deallocate();
@@ -1050,11 +1064,11 @@ void SpringApp::Shutdown()
#endif
SDL_Quit();
- DeleteAndNull(gs);
- DeleteAndNull(gu);
- DeleteAndNull(globalRendering);
- DeleteAndNull(startsetup);
- DeleteAndNull(luaSocketRestrictions);
+ SafeDelete(gs);
+ SafeDelete(gu);
+ SafeDelete(globalRendering);
+ SafeDelete(startsetup);
+ SafeDelete(luaSocketRestrictions);
FileSystemInitializer::Cleanup();
View
1  rts/System/SpringApp.h
@@ -49,6 +49,7 @@ class SpringApp
private:
bool MainEventHandler(const SDL_Event& ev);
+ void RunScript(const std::string buf);
private:
std::string binaryName;
View
105 rts/System/StartScriptGen.cpp
@@ -0,0 +1,105 @@
+/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
+
+#include "System/TdfParser.h"
+#include "StartScriptGen.h"
+#include "AIScriptHandler.h"
+#include "Config/ConfigHandler.h"
+
+#include <string>
+
+std::string StartScriptGen::CreateMinimalSetup(const std::string game, const std::string map) {
+ std::string playername = "unnamed"; //FIXME
+ TdfParser::TdfSection setup;
+ TdfParser::TdfSection* g = setup.construct_subsection("GAME");
+
+ g->add_name_value("Mapname", map);
+ g->add_name_value("Gametype", game);
+
+ TdfParser::TdfSection* modopts = g->construct_subsection("MODOPTIONS");
+ modopts->AddPair("MaxSpeed", 20);
+ modopts->AddPair("MinimalSetup", 1); //use for ingame detecting this type of start
+
+ g->AddPair("IsHost", 1);
+ g->AddPair("OnlyLocal", 1);
+ g->add_name_value("MyPlayerName", playername);
+
+ TdfParser::TdfSection* player0 = g->construct_subsection("PLAYER0");
+ player0->add_name_value("Name", playername);
+ player0->AddPair("Team", 0);
+
+ TdfParser::TdfSection* team0 = g->construct_subsection("TEAM0");
+ team0->AddPair("TeamLeader", 0);
+ team0->AddPair("AllyTeam", 0);
+
+ TdfParser::TdfSection* ally0 = g->construct_subsection("ALLYTEAM0");
+ ally0->AddPair("NumAllies", 0);
+
+
+ std::ostringstream str;
+ setup.print(str);
+ printf("%s\n", str.str().c_str());
+ return str.str();
+}
+
+
+std::string StartScriptGen::CreateDefaultSetup(const std::string& map, const std::string& game, const std::string& ai,
+ const std::string& playername)
+{
+ //FIXME:: duplicate code with CreateMinimalSetup
+ TdfParser::TdfSection setup;
+ TdfParser::TdfSection* g = setup.construct_subsection("GAME");
+ g->add_name_value("Mapname", map);
+ g->add_name_value("Gametype", game);
+
+ TdfParser::TdfSection* modopts = g->construct_subsection("MODOPTIONS");
+ modopts->AddPair("MaxSpeed", 20);
+
+ g->AddPair("IsHost", 1);
+ g->AddPair("OnlyLocal", 1);
+ g->add_name_value("MyPlayerName", playername);
+
+ g->AddPair("NoHelperAIs", configHandler->GetBool("NoHelperAIs"));
+
+ TdfParser::TdfSection* player0 = g->construct_subsection("PLAYER0");
+ player0->add_name_value("Name", playername);
+ player0->AddPair("Team", 0);
+
+ const bool isSkirmishAITestScript = CAIScriptHandler::Instance().IsSkirmishAITestScript(ai);
+ if (isSkirmishAITestScript) {
+ SkirmishAIData aiData = CAIScriptHandler::Instance().GetSkirmishAIData(ai);
+ TdfParser::TdfSection* ai = g->construct_subsection("AI0");
+ ai->add_name_value("Name", "Enemy");
+ ai->add_name_value("ShortName", aiData.shortName);
+ ai->add_name_value("Version", aiData.version);
+ ai->AddPair("Host", 0);
+ ai->AddPair("Team", 1);
+ } else {
+ TdfParser::TdfSection* player1 = g->construct_subsection("PLAYER1");
+ player1->add_name_value("Name", "Enemy");
+ player1->AddPair("Team", 1);
+ }
+
+ TdfParser::TdfSection* team0 = g->construct_subsection("TEAM0");
+ team0->AddPair("TeamLeader", 0);
+ team0->AddPair("AllyTeam", 0);
+
+ TdfParser::TdfSection* team1 = g->construct_subsection("TEAM1");
+ if (isSkirmishAITestScript) {
+ team1->AddPair("TeamLeader", 0);
+ } else {
+ team1->AddPair("TeamLeader", 1);
+ }
+ team1->AddPair("AllyTeam", 1);
+
+ TdfParser::TdfSection* ally0 = g->construct_subsection("ALLYTEAM0");
+ ally0->AddPair("NumAllies", 0);
+
+ TdfParser::TdfSection* ally1 = g->construct_subsection("ALLYTEAM1");
+ ally1->AddPair("NumAllies", 0);
+
+ std::ostringstream str;
+ setup.print(str);
+
+ return str.str();
+}
+
View
22 rts/System/StartScriptGen.h
@@ -0,0 +1,22 @@
+/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
+
+class StartScriptGen {
+
+public:
+ /**
+ * creates an empty script.txt with game & map, no error checking is done!
+ * @param game name of the game
+ * @param map name of the map
+ */
+ static std::string CreateMinimalSetup(const std::string game, const std::string map); //FIXME: should be non-static
+ /**
+ * creates an empty script.txt with game & map, only few error checking is done!
+ * @param game name of the game
+ * @param map name of the map
+ * @param ai ai to use (Lua/Skirmish), if not found "empty" player is used
+ * @param playername name to use ingame
+ */
+ static std::string CreateDefaultSetup(const std::string& map, const std::string& game, const std::string& ai, const std::string& playername); //FIXME: should be non-static
+
+};
+
Please sign in to comment.
Something went wrong with that request. Please try again.