Skip to content

Commit 20ebb8c

Browse files
committed
Allow starting demos through a script
1 parent 374a5cb commit 20ebb8c

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

rts/Game/ClientSetup.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,5 @@ void ClientSetup::LoadFromStartScript(const std::string& setup)
7272
}
7373

7474
file.GetDef(saveFile, "", "GAME\\SaveFile");
75+
file.GetDef(demoFile, "", "GAME\\DemoFile");
7576
}

rts/Game/ClientSetup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class ClientSetup
1717
std::string myPlayerName;
1818
std::string myPasswd;
1919
std::string saveFile;
20+
std::string demoFile;
2021

2122
//! if this client is not the server player, the IP address we connect to
2223
//! if this client is the server player, the IP address that other players connect to

rts/System/SpringApp.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -694,10 +694,29 @@ CGameController* SpringApp::LoadSaveFile(const std::string& saveFile)
694694
}
695695

696696

697+
CGameController* SpringApp::LoadDemoFile(const std::string& demoFile)
698+
{
699+
const std::string ext = FileSystem::GetExtension(demoFile);
700+
701+
if (ext != "sdfz")
702+
throw content_error(std::string("Unknown demo extension: ") + ext);
703+
704+
clientSetup->isHost = true;
705+
clientSetup->myPlayerName += " (spec)";
706+
707+
pregame = new CPreGame(clientSetup);
708+
pregame->LoadDemo(demoFile);
709+
return pregame;
710+
}
711+
712+
697713
CGameController* SpringApp::RunScript(const std::string& buf)
698714
{
699715
clientSetup->LoadFromStartScript(buf);
700716

717+
if (!clientSetup->demoFile.empty())
718+
return LoadDemoFile(clientSetup->demoFile);
719+
701720
if (!clientSetup->saveFile.empty())
702721
return LoadSaveFile(clientSetup->saveFile);
703722

@@ -798,13 +817,8 @@ void SpringApp::Startup()
798817

799818
clientSetup->isHost = false;
800819
pregame = new CPreGame(clientSetup);
801-
} else if (inputFile.rfind(".sdfz") != std::string::npos) {
802-
// demo.sdfz
803-
clientSetup->isHost = true;
804-
clientSetup->myPlayerName += " (spec)";
805-
806-
pregame = new CPreGame(clientSetup);
807-
pregame->LoadDemo(inputFile);
820+
} else if (extension == "sdfz") {
821+
LoadDemoFile(inputFile);
808822
} else if (extension == "slsf" || extension == "ssf") {
809823
LoadSaveFile(inputFile);
810824
} else {

rts/System/SpringApp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class SpringApp
6262

6363
CGameController* RunScript(const std::string& buf);
6464
CGameController* LoadSaveFile(const std::string& saveName); //!< Starts game from a specified save
65+
CGameController* LoadDemoFile(const std::string& demoName); //!< Starts game from a specified save
6566
};
6667

6768
/**

0 commit comments

Comments
 (0)