From b0a2e79599b8fc2df42e26b39d455b7b8b39a670 Mon Sep 17 00:00:00 2001 From: Jannik Vogel Date: Fri, 12 Aug 2016 16:39:29 +0200 Subject: [PATCH] Refactor seat storage, fixes entering wrong seat --- rwengine/src/engine/GameWorld.cpp | 22 +++++++++++++++++----- rwengine/src/objects/VehicleInfo.hpp | 21 +++++++++++++++++++-- rwengine/src/objects/VehicleObject.cpp | 2 +- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/rwengine/src/engine/GameWorld.cpp b/rwengine/src/engine/GameWorld.cpp index 02e8aeac..eb70aea5 100644 --- a/rwengine/src/engine/GameWorld.cpp +++ b/rwengine/src/engine/GameWorld.cpp @@ -382,12 +382,24 @@ VehicleObject *GameWorld::createVehicle(const uint16_t id, const glm::vec3& pos, auto frameTrans = f->getMatrix(); info->second->wheels.push_back({glm::vec3(frameTrans[3])}); } - if(name.size() > 3 && name.substr(0, 3) == "ped" && name.substr(name.size()-4) == "seat") { + if(name == "ped_frontseat") { auto p = f->getDefaultTranslation(); - p.x = p.x * -1.f; - info->second->seats.push_back({p}); - p.x = p.x * -1.f; - info->second->seats.push_back({p}); + // Left seat + p.x = -p.x; + info->second->seats.front.push_back({p}); + // Right seat + p.x = -p.x; + info->second->seats.front.push_back({p}); + } + if(name == "ped_backseat") { + // @todo how does this work for the barracks, ambulance or coach? + auto p = f->getDefaultTranslation(); + // Left seat + p.x = -p.x; + info->second->seats.back.push_back({p}); + // Right seat + p.x = -p.x; + info->second->seats.back.push_back({p}); } } } diff --git a/rwengine/src/objects/VehicleInfo.hpp b/rwengine/src/objects/VehicleInfo.hpp index 99039abb..02017d2b 100644 --- a/rwengine/src/objects/VehicleInfo.hpp +++ b/rwengine/src/objects/VehicleInfo.hpp @@ -92,8 +92,25 @@ struct VehicleInfo { /** Value for caching wheel information */ std::vector wheels; - /** Value for caching seat information */ - std::vector seats; + /** Struct for caching seat information */ + struct { + std::vector front; + std::vector back; + + SeatInfo operator[](size_t index) const { + // Try front seats first + if (index < front.size()) { + return front[index]; + } + index -= front.size(); + + // Get back seat + return back[index]; + } + size_t size() const { + return front.size() + back.size(); + } + } seats; }; typedef std::shared_ptr VehicleInfoHandle; diff --git a/rwengine/src/objects/VehicleObject.cpp b/rwengine/src/objects/VehicleObject.cpp index 43e1937b..b3b80434 100644 --- a/rwengine/src/objects/VehicleObject.cpp +++ b/rwengine/src/objects/VehicleObject.cpp @@ -533,7 +533,7 @@ bool VehicleObject::isOccupantDriver(size_t seat) const VehicleObject::Part* VehicleObject::getSeatEntryDoor(size_t seat) { - auto pos = info->seats.at(seat).offset + glm::vec3(0.f, 0.5f, 0.f); + auto pos = info->seats[seat].offset + glm::vec3(0.f, 0.5f, 0.f); Part* nearestDoor = nullptr; float d = std::numeric_limits::max(); for(auto& p : dynamicParts)