mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-09-29 17:57:23 +02:00
8edf2f0ac6
This commit refactors custom level scripts to no longer be stored in one giant vector containing not only every single script name, but every single script's contents as well. More specifically, scriptclass::customscript has been converted to an std::vector<Script> scriptclass::customscripts (note the extra S), and a Script is just a struct with an std::string name and std::vector<std::string> contents. This is an improvement in both performance and maintainability. The game no longer has to look through script contents in case they're actually script names, and then manually extract the script contents from there. Instead, all it has to do is look for script names only. And the contents are provided for free. This results in a performance gain. Also, the old system resulted in lots of boilerplate everywhere anytime scripts had to be handled or parsed. Now, the boilerplate is only done when saving or loading a custom level. This makes code quality much, much better. To be sure I didn't actually change anything, I tested by first saving Dimension Open in current 2.3 (because current 2.3 gets rid of the awful edentity whitespace), and then resaved it on this patch. There is absolutely no difference between the current-2.3-resave and this-patch-resave.
77 lines
1.2 KiB
C++
77 lines
1.2 KiB
C++
#ifndef SCRIPT_H
|
|
#define SCRIPT_H
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "Enums.h"
|
|
|
|
#define filllines(lines) commands.insert(commands.end(), lines, lines + sizeof(lines)/sizeof(lines[0]))
|
|
|
|
|
|
struct Script
|
|
{
|
|
std::string name;
|
|
std::vector<std::string> contents;
|
|
};
|
|
|
|
class scriptclass
|
|
{
|
|
public:
|
|
|
|
|
|
scriptclass();
|
|
|
|
void load(std::string t);
|
|
void loadother(std::string t);
|
|
|
|
|
|
void inline add(std::string t)
|
|
{
|
|
commands.push_back(t);
|
|
}
|
|
|
|
void clearcustom();
|
|
|
|
void tokenize(std::string t);
|
|
|
|
void run();
|
|
|
|
void resetgametomenu();
|
|
|
|
void startgamemode(int t);
|
|
|
|
void teleport();
|
|
|
|
void hardreset();
|
|
|
|
void loadcustom(std::string t);
|
|
|
|
//Script contents
|
|
std::vector<std::string> commands;
|
|
std::vector<std::string> words;
|
|
std::vector<std::string> txt;
|
|
std::string scriptname;
|
|
int position;
|
|
int looppoint, loopcount;
|
|
|
|
int scriptdelay;
|
|
bool running;
|
|
std::string tempword;
|
|
std::string currentletter;
|
|
|
|
//Textbox stuff
|
|
int textx;
|
|
int texty;
|
|
int r,g,b;
|
|
|
|
//Misc
|
|
int i, j, k;
|
|
|
|
//Custom level stuff
|
|
std::vector<Script> customscripts;
|
|
};
|
|
|
|
extern scriptclass script;
|
|
|
|
#endif /* SCRIPT_H */
|