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)) { if (ipll.load(name)) {
// Find the object. // Find the object.
for (const auto& inst : ipll.m_instances) { 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 " + logger->error("World", "No object data for instance " +
std::to_string(inst->id) + " in " + std::to_string(inst.id) + " in " +
name); name);
} }
} }

View file

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

View file

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

View file

@ -77,7 +77,7 @@ BOOST_AUTO_TEST_CASE(instance_data_is_correct) {
BOOST_REQUIRE(loader.load(test_data_stream)); 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}); 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() BOOST_AUTO_TEST_SUITE_END()