1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-26 16:24:35 +01:00

Trim common calls out direction switch

This commit is contained in:
Ted John
2016-10-08 22:20:59 +01:00
parent 643247237c
commit bc36bb48a2

View File

@@ -317,39 +317,44 @@ private:
void GenerateCalls(int tabs, std::vector<function_call> calls[4], int height)
{
std::vector<function_call> commonCalls = TrimCommonCallsEnd(calls);
int totalCalls = 0;
for (int direction = 0; direction < 4; direction++)
{
totalCalls += calls[direction].size();
}
if (totalCalls == 0)
if (totalCalls != 0)
{
return;
}
WriteLine(tabs, "switch (direction) {");
for (int direction = 0; direction < 4; direction++)
{
if (calls[direction].size() == 0) continue;
WriteLine(tabs, "case %d:", direction);
for (int d2 = direction + 1; d2 < 4; d2++)
WriteLine(tabs, "switch (direction) {");
for (int direction = 0; direction < 4; direction++)
{
if (CompareFunctionCalls(calls[direction], calls[d2]))
if (calls[direction].size() == 0) continue;
WriteLine(tabs, "case %d:", direction);
for (int d2 = direction + 1; d2 < 4; d2++)
{
// Clear identical other direction calls and add case for it
calls[d2].clear();
WriteLine(tabs, "case %d:", d2);
if (CompareFunctionCalls(calls[direction], calls[d2]))
{
// Clear identical other direction calls and add case for it
calls[d2].clear();
WriteLine(tabs, "case %d:", d2);
}
}
}
for (auto call : calls[direction])
{
GenerateCalls(tabs + 1, call, height, direction);
for (auto call : calls[direction])
{
GenerateCalls(tabs + 1, call, height, direction);
}
WriteLine(tabs + 1, "break;");
}
WriteLine(tabs + 1, "break;");
WriteLine(tabs, "}");
}
for (auto call : commonCalls)
{
GenerateCalls(tabs, call, height, 0);
}
WriteLine(tabs, "}");
}
void GenerateCalls(int tabs, const function_call &call, int height, int direction)
@@ -427,6 +432,31 @@ private:
}
}
std::vector<function_call> TrimCommonCallsEnd(std::vector<function_call> calls[4])
{
std::vector<function_call> commonCalls;
while (calls[0].size() != 0)
{
function_call lastCall = calls[0].back();
for (int i = 0; i < 4; i++)
{
if (calls[i].size() == 0 || !CompareFunctionCall(calls[i].back(), lastCall))
{
goto finished;
}
}
for (int i = 0; i < 4; i++)
{
calls[i].pop_back();
}
commonCalls.push_back(lastCall);
}
finished:
return commonCalls;
}
bool CompareFunctionCalls(const std::vector<function_call> &a, const std::vector<function_call> &b)
{
if (a.size() != b.size()) return false;