mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-22 02:12:45 +01:00
Convert vehicleInfo to vector
This commit is contained in:
parent
3c98a7222d
commit
6cc8037ffb
@ -287,7 +287,7 @@ void GameData::loadHandling(const std::string& path) {
|
||||
GenericDATLoader l;
|
||||
auto syspath = index.findFilePath(path).string();
|
||||
|
||||
l.loadHandling(syspath, vehicleInfo);
|
||||
l.loadHandling(syspath, vehicleInfos);
|
||||
}
|
||||
|
||||
SCMFile GameData::loadSCM(const std::string& path) {
|
||||
|
@ -267,7 +267,7 @@ public:
|
||||
/**
|
||||
* Vehicle information
|
||||
*/
|
||||
std::map<std::string, VehicleInfoHandle> vehicleInfo;
|
||||
std::unordered_map<std::string, VehicleInfo> vehicleInfos;
|
||||
|
||||
/**
|
||||
* Texture Loader
|
||||
|
@ -270,16 +270,16 @@ VehicleObject* GameWorld::createVehicle(const uint16_t id, const glm::vec3& pos,
|
||||
};
|
||||
|
||||
auto model = vti->getModel();
|
||||
auto info = data->vehicleInfo.find(vti->handling_);
|
||||
if (model && info != data->vehicleInfo.end() &&
|
||||
info->second->wheels.empty() && info->second->seats.empty()) {
|
||||
auto info = data->vehicleInfos.find(vti->handling_);
|
||||
if (model && info != data->vehicleInfos.end() &&
|
||||
info->second.wheels.empty() && info->second.seats.empty()) {
|
||||
auto root = model->getFrame();
|
||||
for (const auto& frame : root->getChildren()) {
|
||||
const std::string& name = frame->getName();
|
||||
|
||||
if (name.size() > 5 && name.substr(0, 5) == "wheel") {
|
||||
const auto& frameTrans = frame->getWorldTransform();
|
||||
info->second->wheels.push_back({glm::vec3(frameTrans[3])});
|
||||
info->second.wheels.push_back({glm::vec3(frameTrans[3])});
|
||||
}
|
||||
|
||||
if (name == "chassis_dummy") {
|
||||
@ -288,27 +288,27 @@ VehicleObject* GameWorld::createVehicle(const uint16_t id, const glm::vec3& pos,
|
||||
auto backseat = frame->findDescendant("ped_backseat");
|
||||
|
||||
if (frontseat) {
|
||||
addSeats(info->second->seats.front,
|
||||
addSeats(info->second.seats.front,
|
||||
frontseat->getDefaultTranslation());
|
||||
}
|
||||
if (backseat) {
|
||||
// @todo how does this work for the barracks, ambulance
|
||||
// or coach?
|
||||
addSeats(info->second->seats.back,
|
||||
addSeats(info->second.seats.back,
|
||||
backseat->getDefaultTranslation());
|
||||
}
|
||||
} else if (name == "ped_frontseat") {
|
||||
// The speeder boat does not have a chassis_dummy but has the
|
||||
// frontseat directly in the root frame.
|
||||
|
||||
addSeats(info->second->seats.front,
|
||||
addSeats(info->second.seats.front,
|
||||
frame->getDefaultTranslation());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto vehicle =
|
||||
std::make_unique<VehicleObject>(this, pos, rot, vti, info->second, prim, sec);
|
||||
std::make_unique<VehicleObject>(this, pos, rot, vti, &info->second, prim, sec);
|
||||
auto ptr = vehicle.get();
|
||||
vehicle->setGameObjectID(gid);
|
||||
|
||||
@ -950,9 +950,9 @@ VehicleObject* GameWorld::tryToSpawnVehicle(VehicleGenerator& gen) {
|
||||
auto model = data->findModelInfo<VehicleModelInfo>(id);
|
||||
RW_ASSERT(model);
|
||||
if (model) {
|
||||
auto info = data->vehicleInfo.find(model->handling_);
|
||||
if (info != data->vehicleInfo.end()) {
|
||||
const auto& handling = info->second->handling;
|
||||
auto info = data->vehicleInfos.find(model->handling_);
|
||||
if (info != data->vehicleInfos.end()) {
|
||||
const auto& handling = info->second.handling;
|
||||
position.z +=
|
||||
(handling.dimensions.z / 2.f) - handling.centerOfMass.z;
|
||||
}
|
||||
|
@ -132,8 +132,9 @@ void GenericDATLoader::loadWeapons(const std::string& name,
|
||||
}
|
||||
}
|
||||
|
||||
void GenericDATLoader::loadHandling(const std::string& name,
|
||||
VehicleInfoPtrs& vehicleData) {
|
||||
void GenericDATLoader::loadHandling(
|
||||
const std::string& name,
|
||||
std::unordered_map<std::string, VehicleInfo>& vehicleData) {
|
||||
std::ifstream hndFile(name.c_str());
|
||||
|
||||
if (hndFile.is_open()) {
|
||||
@ -144,7 +145,9 @@ void GenericDATLoader::loadHandling(const std::string& name,
|
||||
std::stringstream ss(lineBuff);
|
||||
|
||||
VehicleHandlingInfo info;
|
||||
ss >> info.ID;
|
||||
std::string ID;
|
||||
|
||||
ss >> ID;
|
||||
ss >> info.mass;
|
||||
ss >> info.dimensions.x;
|
||||
ss >> info.dimensions.y;
|
||||
@ -180,12 +183,15 @@ void GenericDATLoader::loadHandling(const std::string& name,
|
||||
|
||||
RW_CHECK(ss.eof() || ss.good(), "Loading handling data file " << name << " failed");
|
||||
|
||||
auto mit = vehicleData.find(info.ID);
|
||||
auto mit = vehicleData.find(ID);
|
||||
|
||||
if (mit == vehicleData.end()) {
|
||||
vehicleData.insert({info.ID, std::make_shared<VehicleInfo>(VehicleInfo{
|
||||
info, {}, {}})});
|
||||
vehicleData.emplace(
|
||||
std::move(ID),
|
||||
VehicleInfo{std::move(info), std::vector<WheelInfo>{},
|
||||
VehicleInfo::Seats{}});
|
||||
} else {
|
||||
mit->second->handling = info;
|
||||
mit->second.handling = info;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,8 +10,6 @@
|
||||
struct DynamicObjectData;
|
||||
struct WeaponData;
|
||||
struct VehicleInfo;
|
||||
typedef std::shared_ptr<VehicleInfo> VehicleInfoPtr;
|
||||
typedef std::map<std::string, VehicleInfoPtr> VehicleInfoPtrs;
|
||||
|
||||
class GenericDATLoader {
|
||||
public:
|
||||
@ -22,7 +20,9 @@ public:
|
||||
void loadWeapons(const std::string& name,
|
||||
std::vector<WeaponData>& weaponData);
|
||||
|
||||
void loadHandling(const std::string& name, VehicleInfoPtrs& vehicleData);
|
||||
void loadHandling(
|
||||
const std::string& name,
|
||||
std::unordered_map<std::string, VehicleInfo>& vehicleData);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -17,7 +17,6 @@ struct VehicleHandlingInfo {
|
||||
|
||||
enum DriveType { Forward = 'F', Rear = 'R', All = '4' };
|
||||
|
||||
std::string ID;
|
||||
float mass;
|
||||
glm::vec3 dimensions{};
|
||||
glm::vec3 centerOfMass{};
|
||||
@ -83,7 +82,7 @@ struct VehicleInfo {
|
||||
/** Value for caching wheel information */
|
||||
std::vector<WheelInfo> wheels;
|
||||
/** Struct for caching seat information */
|
||||
struct {
|
||||
struct Seats{
|
||||
std::vector<SeatInfo> front;
|
||||
std::vector<SeatInfo> back;
|
||||
|
||||
@ -103,9 +102,15 @@ struct VehicleInfo {
|
||||
bool empty() const {
|
||||
return front.empty() && back.empty();
|
||||
}
|
||||
} seats;
|
||||
};
|
||||
Seats seats;
|
||||
|
||||
template <typename T1, typename T2>
|
||||
VehicleInfo(VehicleHandlingInfo p_handling, T1&& p_wheels, T2&& p_seats)
|
||||
: handling(p_handling)
|
||||
, wheels(std::forward<T1>(p_wheels))
|
||||
, seats(std::forward<T2>(p_seats)) {
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<VehicleInfo> VehicleInfoHandle;
|
||||
|
||||
#endif
|
||||
|
@ -96,7 +96,7 @@ private:
|
||||
|
||||
VehicleObject::VehicleObject(GameWorld* engine, const glm::vec3& pos,
|
||||
const glm::quat& rot, BaseModelInfo* modelinfo,
|
||||
VehicleInfoHandle info, const glm::u8vec3& prim,
|
||||
VehicleInfo* info, const glm::u8vec3& prim,
|
||||
const glm::u8vec3& sec)
|
||||
: GameObject(engine, pos, rot, modelinfo)
|
||||
, info(info)
|
||||
|
@ -50,7 +50,7 @@ private:
|
||||
public:
|
||||
float health{1000.f};
|
||||
|
||||
VehicleInfoHandle info{};
|
||||
VehicleInfo* info = nullptr;
|
||||
glm::u8vec3 colourPrimary{};
|
||||
glm::u8vec3 colourSecondary{};
|
||||
bool mHasSpecial = true;
|
||||
@ -101,7 +101,7 @@ public:
|
||||
std::unordered_map<std::string, Part> dynamicParts;
|
||||
|
||||
VehicleObject(GameWorld* engine, const glm::vec3& pos, const glm::quat& rot,
|
||||
BaseModelInfo* modelinfo, VehicleInfoHandle info,
|
||||
BaseModelInfo* modelinfo, VehicleInfo* info,
|
||||
const glm::u8vec3& prim, const glm::u8vec3& sec);
|
||||
|
||||
~VehicleObject() override;
|
||||
|
@ -70,15 +70,15 @@ BOOST_AUTO_TEST_CASE(test_dynamic_dat_loader) {
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_handling_data_loader) {
|
||||
GenericDATLoader l;
|
||||
VehicleInfoPtrs loaded;
|
||||
std::unordered_map<std::string, VehicleInfo> vehicleInfos;
|
||||
|
||||
l.loadHandling(Global::get().getGamePath() + "/data/handling.cfg", loaded);
|
||||
l.loadHandling(Global::get().getGamePath() + "/data/handling.cfg", vehicleInfos);
|
||||
|
||||
BOOST_ASSERT(loaded.size() > 0);
|
||||
BOOST_ASSERT(loaded.find("STINGER") != loaded.end());
|
||||
BOOST_ASSERT(!vehicleInfos.empty());
|
||||
BOOST_ASSERT(vehicleInfos.find("STINGER") != vehicleInfos.end());
|
||||
|
||||
VehicleInfoPtr info = loaded["STINGER"];
|
||||
VehicleHandlingInfo& handling = info->handling;
|
||||
auto info = vehicleInfos.find("STINGER");
|
||||
const auto& handling = info->second.handling;
|
||||
|
||||
BOOST_CHECK_EQUAL(handling.mass, 1000.0);
|
||||
BOOST_CHECK_EQUAL(handling.flags, 0xA182);
|
||||
|
Loading…
Reference in New Issue
Block a user