2023-08-01 08:19:07 +00:00
|
|
|
#include "CDMovingPlatformComponentTable.h"
|
|
|
|
|
|
|
|
CDMovingPlatformComponentTable::CDMovingPlatformComponentTable() {
|
2024-02-11 03:23:35 +00:00
|
|
|
auto& entries = GetEntriesMutable();
|
2023-08-05 08:21:59 +00:00
|
|
|
auto tableData = CDClientDatabase::ExecuteQuery("SELECT * FROM MovingPlatforms");
|
2023-08-01 08:19:07 +00:00
|
|
|
while (!tableData.eof()) {
|
|
|
|
CDMovingPlatformTableEntry entry;
|
|
|
|
entry.platformIsSimpleMover = tableData.getIntField("platformIsSimpleMover", 0) == 1;
|
|
|
|
entry.platformStartAtEnd = tableData.getIntField("platformStartAtEnd", 0) == 1;
|
|
|
|
entry.platformMove.x = tableData.getFloatField("platformMoveX", 0.0f);
|
|
|
|
entry.platformMove.y = tableData.getFloatField("platformMoveY", 0.0f);
|
|
|
|
entry.platformMove.z = tableData.getFloatField("platformMoveZ", 0.0f);
|
|
|
|
entry.moveTime = tableData.getFloatField("platformMoveTime", -1.0f);
|
|
|
|
|
2024-02-11 03:23:35 +00:00
|
|
|
DluAssert(entries.insert(std::make_pair(tableData.getIntField("id", -1), entry)).second);
|
2023-08-01 08:19:07 +00:00
|
|
|
tableData.nextRow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CDMovingPlatformComponentTable::CachePlatformEntry(ComponentID id) {
|
2024-02-11 03:23:35 +00:00
|
|
|
auto& entries = GetEntriesMutable();
|
2023-08-05 08:21:59 +00:00
|
|
|
auto query = CDClientDatabase::CreatePreppedStmt("SELECT * FROM MovingPlatforms WHERE id = ?;");
|
2023-08-01 08:19:07 +00:00
|
|
|
query.bind(1, static_cast<int32_t>(id));
|
|
|
|
|
|
|
|
auto tableData = query.execQuery();
|
|
|
|
while (!tableData.eof()) {
|
|
|
|
CDMovingPlatformTableEntry entry;
|
|
|
|
entry.platformIsSimpleMover = tableData.getIntField("platformIsSimpleMover", 0) == 1;
|
|
|
|
entry.platformStartAtEnd = tableData.getIntField("platformStartAtEnd", 0) == 1;
|
|
|
|
entry.platformMove.x = tableData.getFloatField("platformMoveX", 0.0f);
|
|
|
|
entry.platformMove.y = tableData.getFloatField("platformMoveY", 0.0f);
|
|
|
|
entry.platformMove.z = tableData.getFloatField("platformMoveZ", 0.0f);
|
|
|
|
entry.moveTime = tableData.getFloatField("platformMoveTime", -1.0f);
|
|
|
|
|
2024-02-11 03:23:35 +00:00
|
|
|
DluAssert(entries.insert(std::make_pair(tableData.getIntField("id", -1), entry)).second);
|
2023-08-01 08:19:07 +00:00
|
|
|
tableData.nextRow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::optional<CDMovingPlatformTableEntry> CDMovingPlatformComponentTable::GetPlatformEntry(ComponentID id) {
|
2024-02-11 03:23:35 +00:00
|
|
|
auto& entries = GetEntriesMutable();
|
|
|
|
auto itr = entries.find(id);
|
|
|
|
if (itr == entries.end()) {
|
2023-08-01 08:19:07 +00:00
|
|
|
CachePlatformEntry(id);
|
2024-02-11 03:23:35 +00:00
|
|
|
itr = entries.find(id);
|
2023-08-01 08:19:07 +00:00
|
|
|
}
|
2024-02-11 03:23:35 +00:00
|
|
|
return itr != entries.end() ? std::make_optional<CDMovingPlatformTableEntry>(itr->second) : std::nullopt;
|
2023-08-01 08:19:07 +00:00
|
|
|
}
|