From 10acd67377367fbb9f45a8b62f9427115c696a8a Mon Sep 17 00:00:00 2001 From: Dav999-v Date: Sun, 19 Jun 2022 22:41:48 +0200 Subject: [PATCH] Add support for start position via level XML for CLI playtesting As already described in cc61194bed324e9fbf51847915357d613a94ff47, as well as Ved's commits from the last almost two weeks, starting VVVVVV from Ved for playtesting could be made a lot faster by "preloading" the game - letting it do all its asset loading in the background without creating a window - and then waiting until the level is passed in via stdin. There's only one problem left with this approach: VVVVVV currently expects the starting position to be passed via command line arguments, which isn't known yet at the time we'd like to start VVVVVV. Therefore, this commit allows passing the starting position via the level XML, instead of via arguments. The extra XML looks like this, and is added next to the tag: 214 112 100 100 0 4 This is handled similarly to how the equivalent arguments are handled: when the level metadata is loaded for CLI playtesting, we also try to find this tag, and if it exists, it sets the same variables that the arguments would have otherwise set. --- desktop_version/src/CustomLevels.cpp | 35 +++++++++++++++++++++++++++- desktop_version/src/CustomLevels.h | 14 ++++++++++- desktop_version/src/main.cpp | 16 +++++++++++-- 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/desktop_version/src/CustomLevels.cpp b/desktop_version/src/CustomLevels.cpp index 5f73732f..21742fdf 100644 --- a/desktop_version/src/CustomLevels.cpp +++ b/desktop_version/src/CustomLevels.cpp @@ -201,6 +201,15 @@ TAG_FINDER(find_desc2, "Desc2") TAG_FINDER(find_desc3, "Desc3") TAG_FINDER(find_website, "website") +/* For CliPlaytestArgs */ +TAG_FINDER(find_playtest, "Playtest") +TAG_FINDER(find_playx, "playx") +TAG_FINDER(find_playy, "playy") +TAG_FINDER(find_playrx, "playrx") +TAG_FINDER(find_playry, "playry") +TAG_FINDER(find_playgc, "playgc") +TAG_FINDER(find_playmusic, "playmusic") + #undef TAG_FINDER static void levelMetaDataCallback(const char* filename) @@ -245,7 +254,7 @@ void customlevelclass::getDirectoryData(void) } } -bool customlevelclass::getLevelMetaData(const std::string& _path, LevelMetaData& _data ) +bool customlevelclass::getLevelMetaDataAndPlaytestArgs(const std::string& _path, LevelMetaData& _data, CliPlaytestArgs* pt_args) { unsigned char *uMem; FILESYSTEM_loadFileToMemory(_path.c_str(), &uMem, NULL, true); @@ -273,10 +282,34 @@ bool customlevelclass::getLevelMetaData(const std::string& _path, LevelMetaData& _data.Desc3 = find_desc3(buf); _data.website = find_website(buf); + if (pt_args != NULL) + { + const std::string playtest = find_playtest(buf); + if (playtest == "") + { + pt_args->valid = false; + } + else + { + pt_args->valid = true; + pt_args->x = help.Int(find_playx(playtest).c_str()); + pt_args->y = help.Int(find_playy(playtest).c_str()); + pt_args->rx = help.Int(find_playrx(playtest).c_str()); + pt_args->ry = help.Int(find_playry(playtest).c_str()); + pt_args->gc = help.Int(find_playgc(playtest).c_str()); + pt_args->music = help.Int(find_playmusic(playtest).c_str()); + } + } + _data.filename = _path; return true; } +bool customlevelclass::getLevelMetaData(const std::string& _path, LevelMetaData& _data) +{ + return getLevelMetaDataAndPlaytestArgs(_path, _data, NULL); +} + void customlevelclass::reset(void) { version=2; //New smaller format change is 2 diff --git a/desktop_version/src/CustomLevels.h b/desktop_version/src/CustomLevels.h index 0a5cea64..a795f746 100644 --- a/desktop_version/src/CustomLevels.h +++ b/desktop_version/src/CustomLevels.h @@ -60,6 +60,17 @@ struct LevelMetaData int version; }; +struct CliPlaytestArgs +{ + int x; + int y; + int rx; + int ry; + int gc; + int music; + bool valid; +}; + extern std::vector customentities; @@ -80,7 +91,8 @@ public: void loadZips(void); void getDirectoryData(void); - bool getLevelMetaData(const std::string& filename, LevelMetaData& _data ); + bool getLevelMetaDataAndPlaytestArgs(const std::string& filename, LevelMetaData& _data, CliPlaytestArgs* pt_args); + bool getLevelMetaData(const std::string& filename, LevelMetaData& _data); void reset(void); const int* loadlevel(int rxi, int ryi); diff --git a/desktop_version/src/main.cpp b/desktop_version/src/main.cpp index 26860faf..c9dea47b 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -634,12 +634,13 @@ int main(int argc, char *argv[]) game.menustart = true; LevelMetaData meta; - if (cl.getLevelMetaData(playtestname, meta)) { + CliPlaytestArgs pt_args; + if (cl.getLevelMetaDataAndPlaytestArgs(playtestname, meta, &pt_args)) { cl.ListOfMetaData.clear(); cl.ListOfMetaData.push_back(meta); } else { cl.loadZips(); - if (cl.getLevelMetaData(playtestname, meta)) { + if (cl.getLevelMetaDataAndPlaytestArgs(playtestname, meta, &pt_args)) { cl.ListOfMetaData.clear(); cl.ListOfMetaData.push_back(meta); } else { @@ -648,6 +649,17 @@ int main(int argc, char *argv[]) } } + if (pt_args.valid) + { + savefileplaytest = true; + savex = pt_args.x; + savey = pt_args.y; + saverx = pt_args.rx; + savery = pt_args.ry; + savegc = pt_args.gc; + savemusic = pt_args.music; + } + game.loadcustomlevelstats(); game.customleveltitle=cl.ListOfMetaData[game.playcustomlevel].title; game.customlevelfilename=cl.ListOfMetaData[game.playcustomlevel].filename;