diff options
Diffstat (limited to 'src/engine/RaceManager.cpp')
| -rw-r--r-- | src/engine/RaceManager.cpp | 51 |
1 files changed, 48 insertions, 3 deletions
diff --git a/src/engine/RaceManager.cpp b/src/engine/RaceManager.cpp index ae1ef828f..75b871cde 100644 --- a/src/engine/RaceManager.cpp +++ b/src/engine/RaceManager.cpp @@ -13,9 +13,54 @@ extern "C" { RaceManager::RaceManager(World& world) : WorldContext(world) { } +std::unordered_map<uintptr_t, std::shared_ptr<Vtx>> mirroredVtxCache; + +// Populates a collision mesh for mirror mode +extern "C" void add_triangle_to_collision_mesh(Vtx* vtx1, Vtx* vtx2, Vtx* vtx3, Vtx** outVtx1, Vtx** outVtx2, Vtx** outVtx3) { + if (gIsMirrorMode != 0) { + auto getOrCreateMirrored = [](Vtx* original) -> Vtx* { + uintptr_t key = reinterpret_cast<uintptr_t>(original); + + auto it = mirroredVtxCache.find(key); + if (it != mirroredVtxCache.end()) { + return it->second.get(); + } + + auto newVtx = std::make_shared<Vtx>(*original); + newVtx->v.ob[0] = -newVtx->v.ob[0]; + + mirroredVtxCache[key] = newVtx; + + return newVtx.get(); + }; + + Vtx* m1 = getOrCreateMirrored(vtx1); + Vtx* m2 = getOrCreateMirrored(vtx2); + Vtx* m3 = getOrCreateMirrored(vtx3); + + // don't invert winding here, already done in the gfx + *outVtx1 = m1; + *outVtx2 = m2; + *outVtx3 = m3; + + } else { + // Pas de miroir, on passe les originaux + *outVtx1 = vtx1; + *outVtx2 = vtx2; + *outVtx3 = vtx3; + } +} + void RaceManager::Load() { - if (WorldContext.CurrentCourse) { - WorldContext.CurrentCourse->Load(); + if (WorldContext.GetCurrentCourse()) { + mirroredVtxCache.clear(); + WorldContext.GetCurrentCourse()->Load(); + } +} + +void RaceManager::UnLoad() { + if (WorldContext.GetCurrentCourse()) { + WorldContext.GetCurrentCourse()->UnLoad(); } } @@ -29,7 +74,7 @@ void RaceManager::PreInit() { } void RaceManager::BeginPlay() { - auto course = WorldContext.CurrentCourse; + auto course = WorldContext.GetCurrentCourse(); if (course) { // Do not spawn finishline in credits or battle mode. And if bSpawnFinishline. |
