mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-23 07:43:01 +01:00
Attempt to fix automatic segment heights
This commit is contained in:
@@ -14,6 +14,8 @@
|
||||
*****************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#include <map>
|
||||
|
||||
#include "SegmentSupportHeightCall.hpp"
|
||||
|
||||
extern "C" {
|
||||
@@ -110,3 +112,41 @@ bool SegmentSupportHeightCall::CallsEqual(std::vector<SegmentSupportCall> lhs, s
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<SegmentSupportCall>* SegmentSupportHeightCall::FindMostCommonSupportCall(std::vector<SegmentSupportCall> *calls) {
|
||||
std::map<std::vector<SegmentSupportCall>, int> map;
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
if (map.count(calls[i]) == 0) {
|
||||
map[calls[i]] = 1;
|
||||
} else {
|
||||
map[calls[i]] += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (map.size() == 1) {
|
||||
return &calls[0];
|
||||
}
|
||||
|
||||
if (map.size() == 2) {
|
||||
for (auto &&item : map) {
|
||||
if (item.second == 3) {
|
||||
return (std::vector<SegmentSupportCall> *)&item.first;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (map.size() == 3) {
|
||||
for (auto &&item : map) {
|
||||
if (item.second == 2) {
|
||||
return (std::vector<SegmentSupportCall> *)&item.first;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,18 @@ struct SegmentSupportCall
|
||||
uint16 segments;
|
||||
sint32 height;
|
||||
sint16 slope;
|
||||
|
||||
bool operator<(const SegmentSupportCall &other) const {
|
||||
if (height != other.height) {
|
||||
return height < other.height;
|
||||
}
|
||||
|
||||
if (segments != other.segments) {
|
||||
return segments < other.segments;
|
||||
}
|
||||
|
||||
return slope < other.slope;
|
||||
}
|
||||
};
|
||||
|
||||
class SegmentSupportHeightCall {
|
||||
@@ -33,4 +45,5 @@ public:
|
||||
static std::vector<SegmentSupportCall> getSegmentCalls(support_height supports[9], uint8 rotation);
|
||||
static bool CallsMatch(std::vector<SegmentSupportCall> tileSegmentSupportCalls[4]);
|
||||
static bool CallsEqual(std::vector<SegmentSupportCall> lhs, std::vector<SegmentSupportCall> rhs);
|
||||
static std::vector<SegmentSupportCall> * FindMostCommonSupportCall(std::vector<SegmentSupportCall> calls[4]);
|
||||
};
|
||||
|
||||
@@ -270,13 +270,19 @@ namespace Intercept2
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<SegmentSupportCall> referenceCalls = tileSegmentSupportCalls[0];
|
||||
|
||||
if (!SegmentSupportHeightCall::CallsMatch(tileSegmentSupportCalls)) {
|
||||
// TODO: if 3 directions do share the same mask, use that call list as a reference.
|
||||
printf("Original segment calls didn't match. [trackSequence:%d chainLift:%d]\n", trackSequence, chainLift);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
printf("# %d\n%s", i, Printer::PrintSegmentSupportHeightCalls(tileSegmentSupportCalls[i]).c_str());
|
||||
std::vector<SegmentSupportCall> *found = SegmentSupportHeightCall::FindMostCommonSupportCall(tileSegmentSupportCalls);
|
||||
if (found != nullptr) {
|
||||
referenceCalls = *found;
|
||||
} else {
|
||||
printf("Original segment calls didn't match. [trackSequence:%d chainLift:%d]\n", trackSequence, chainLift);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
printf("# %d\n%s", i, Printer::PrintSegmentSupportHeightCalls(tileSegmentSupportCalls[i]).c_str());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int direction = 0; direction < 4; direction++) {
|
||||
@@ -320,7 +326,6 @@ namespace Intercept2
|
||||
if (!GeneralSupportHeightCall::CallsMatch(tileGeneralSupportCalls)) {
|
||||
SupportCall *found = GeneralSupportHeightCall::FindMostCommonSupportCall(tileGeneralSupportCalls);
|
||||
if (found == nullptr) {
|
||||
// TODO: if 3 directions do share the output, use that.
|
||||
printf("Original support calls didn't match. [trackSequence:%d chainLift:%d]\n", trackSequence, chainLift);
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
printf("[%d, 0x%02X] ", tileGeneralSupportCalls[i].height, tileGeneralSupportCalls[i].slope);
|
||||
|
||||
Reference in New Issue
Block a user