Commit aeb30782 authored by NTAuthority's avatar NTAuthority

command-line convar/command parsing - example: +set developer 2 +hi hey ho...

command-line convar/command parsing - example: +set developer 2 +hi hey ho +hey world +set wo "ah ah" +load_ide rofl mao
parent f78f55b7
Pipeline #51 skipped
......@@ -8,9 +8,63 @@ namespace krt
{
int Main::Run(const ProgramArguments& arguments)
{
Game TheGame;
// parse argument list and handle console commands
sys::InitializeConsole();
TheGame.Run();
// the argument list to pass after the game initialized
std::vector<ProgramArguments> argumentBits;
std::vector<std::pair<std::string, std::string>> setList;
{
for (int i : irange(arguments.Count()))
{
const std::string& argument = arguments[i];
// if this is a command-like
if (argument.length() > 1 && argument[0] == '+')
{
// if this is a set command, queue it for the early execution buffer
if (argument == "+set" && (i + 2) < arguments.Count())
{
setList.push_back({ arguments[i + 1], arguments[i + 2] });
}
else
{
// capture bits up to the next +
std::vector<std::string> thisBits;
thisBits.push_back(argument.substr(1));
for (size_t j : irange<size_t>(i + 1, arguments.Count()))
{
const std::string& bit = arguments[j];
if (bit.length() > 0 && bit[0] == '+')
{
break;
}
thisBits.push_back(bit);
}
argumentBits.push_back(ProgramArguments{ thisBits });
}
}
}
}
{
// create and initialize the game
Game TheGame(setList);
// run argument bits captures
for (const auto& bit : argumentBits)
{
console::ExecuteSingleCommand(bit);
}
// run the game
TheGame.Run();
}
return 0;
}
......
......@@ -24,7 +24,7 @@ class Game
friend struct Entity;
public:
Game(void);
Game(const std::vector<std::pair<std::string, std::string>>& setList);
~Game(void);
void Run();
......
......@@ -24,12 +24,10 @@ namespace krt
Game* theGame = NULL;
Game::Game(void) : streaming(GAME_NUM_STREAMING_CHANNELS), texManager(streaming), modelManager(streaming, texManager)
Game::Game(const std::vector<std::pair<std::string, std::string>>& setList) : streaming(GAME_NUM_STREAMING_CHANNELS), texManager(streaming), modelManager(streaming, texManager)
{
assert(theGame == NULL);
sys::InitializeConsole();
// Initialize console variables.
maxFPSVariable = std::make_unique<ConVar<int>>("maxFPS", ConVar_Archive, 60, &maxFPS);
timescaleVariable = std::make_unique<ConVar<float>>("timescale", ConVar_None, 1.0f, &timescale);
......@@ -49,6 +47,12 @@ Game::Game(void) : streaming(GAME_NUM_STREAMING_CHANNELS), texManager(streaming)
// run config.cfg
console::ExecuteSingleCommand(ProgramArguments{ "exec", "user:/config.cfg" });
// override variables from console
for (auto& pair : setList)
{
console::ExecuteSingleCommand(ProgramArguments{ "set", pair.first, pair.second });
}
// Detect where the game is installed.
// For now, I guess we do it manually.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment