1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-07-08 13:54:52 +02:00

Avoid using shared_ptr for InstanceData

This commit is contained in:
Filip Gawin 2019-01-18 02:07:36 +01:00
parent 44148c528a
commit f15f3cefdd
4 changed files with 13 additions and 12 deletions

View File

@ -116,9 +116,9 @@ bool GameWorld::placeItems(const std::string& name) {
if (ipll.load(name)) {
// Find the object.
for (const auto& inst : ipll.m_instances) {
if (!createInstance(inst->id, inst->pos, inst->rot)) {
if (!createInstance(inst.id, inst.pos, inst.rot)) {
logger->error("World", "No object data for instance " +
std::to_string(inst->id) + " in " +
std::to_string(inst.id) + " in " +
name);
}
}

View File

@ -80,18 +80,18 @@ bool LoaderIPL::load(std::istream &str) {
getline(strstream, rotZ, ',');
getline(strstream, rotW, ',');
auto instance = std::make_shared<InstanceData>(
m_instances.emplace_back(
lexical_cast<int>(id), // ID
model.substr(1, model.size() - 1),
glm::vec3(lexical_cast<float>(posX), lexical_cast<float>(posY),
glm::vec3(lexical_cast<float>(posX),
lexical_cast<float>(posY),
lexical_cast<float>(posZ)),
glm::vec3(lexical_cast<float>(scaleX), lexical_cast<float>(scaleY),
glm::vec3(lexical_cast<float>(scaleX),
lexical_cast<float>(scaleY),
lexical_cast<float>(scaleZ)),
glm::normalize(
glm::quat(-lexical_cast<float>(rotW), lexical_cast<float>(rotX),
lexical_cast<float>(rotY), lexical_cast<float>(rotZ))));
m_instances.push_back(instance);
glm::normalize(glm::quat(
-lexical_cast<float>(rotW), lexical_cast<float>(rotX),
lexical_cast<float>(rotY), lexical_cast<float>(rotZ))));
} else if (section == ZONE) {
ZoneData zone;

View File

@ -6,6 +6,7 @@
#include <vector>
#include <data/ZoneData.hpp>
#include <data/InstanceData.hpp>
struct InstanceData;
@ -22,7 +23,7 @@ public:
bool load(std::istream& stream);
/// The list of instances from the IPL file
std::vector<std::shared_ptr<InstanceData>> m_instances;
std::vector<InstanceData> m_instances;
/// List of Zones
ZoneDataList zones;

View File

@ -77,7 +77,7 @@ BOOST_AUTO_TEST_CASE(instance_data_is_correct) {
BOOST_REQUIRE(loader.load(test_data_stream));
const auto expectedInstance = InstanceData(112, "ModelB", {10.0f, 12.0f, 5.0f}, {1.f, 1.f, 1.f}, {0.0f, 0.f, 0.f, 1.0f});
BOOST_TEST(*loader.m_instances[1] == expectedInstance);
BOOST_TEST(loader.m_instances[1] == expectedInstance);
}
BOOST_AUTO_TEST_SUITE_END()