From 84c94c5c24c968248426b72a5a4e4913028fcae7 Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Thu, 5 Dec 2013 07:23:07 +0000 Subject: [PATCH] Refactored Instance data --- .../include/renderwure/data/InstanceData.hpp | 32 ++++++++++++++++++ .../include/renderwure/engine/GTAEngine.hpp | 6 ---- .../include/renderwure/loaders/LoaderIPL.hpp | 22 ++----------- framework2/src/engine/GTAEngine.cpp | 14 +++----- framework2/src/loaders/LoaderIPL.cpp | 33 +++++-------------- game/main.cpp | 2 -- viewer/main.cpp | 2 -- 7 files changed, 48 insertions(+), 63 deletions(-) create mode 100644 framework2/include/renderwure/data/InstanceData.hpp diff --git a/framework2/include/renderwure/data/InstanceData.hpp b/framework2/include/renderwure/data/InstanceData.hpp new file mode 100644 index 00000000..ba60de9d --- /dev/null +++ b/framework2/include/renderwure/data/InstanceData.hpp @@ -0,0 +1,32 @@ +#pragma once +#ifndef __INSTANCEDATA_HPP__ +#define __INSTANCEDATA_HPP__ +#include +#include +#include + +struct InstanceData +{ + /** + * ID of the object this instance + */ + int id; + /** + * Model name + */ + std::string model; + /** + * Instance position + */ + glm::vec3 pos; + /** + * Instance scaleX + */ + glm::vec3 scale; + /** + * Instance rotation + */ + glm::quat rot; +}; + +#endif \ No newline at end of file diff --git a/framework2/include/renderwure/engine/GTAEngine.hpp b/framework2/include/renderwure/engine/GTAEngine.hpp index 76ef6753..4cb40db8 100644 --- a/framework2/include/renderwure/engine/GTAEngine.hpp +++ b/framework2/include/renderwure/engine/GTAEngine.hpp @@ -98,12 +98,6 @@ public: */ GTACharacter* createPedestrian(const uint16_t id, const glm::vec3& pos, const glm::quat& rot = glm::quat()); - /** - * Roughly the middle of everything - */ - glm::vec3 itemCentroid; - size_t itemCount; - /** * Game Clock */ diff --git a/framework2/include/renderwure/loaders/LoaderIPL.hpp b/framework2/include/renderwure/loaders/LoaderIPL.hpp index ef512298..28fd722b 100644 --- a/framework2/include/renderwure/loaders/LoaderIPL.hpp +++ b/framework2/include/renderwure/loaders/LoaderIPL.hpp @@ -1,23 +1,10 @@ #ifndef _LOADERIPL_HPP_ #define _LOADERIPL_HPP_ +#include #include #include -#include - -/** - \class LoaderIPLInstance - \brief One INST entry's data from a IPL file -*/ -class LoaderIPLInstance -{ -public: - int id; ///< ID of the asset in the main IMG archive - std::string model; ///< Name of the model for this instance, as seen in the IMG archive - float posX, posY, posZ; ///< 3D Position of the instance - float scaleX, scaleY, scaleZ; ///< Scale of the instance - float rotX, rotY, rotZ, rotW; ///< Rotation of the instance, in a Quaternion -}; +#include /** \class LoaderIPL @@ -66,10 +53,7 @@ public: bool load(const std::string& filename); /// The list of instances from the IPL file - std::vector m_instances; - - /// The centroid of the instances - glm::vec3 centroid; + std::vector> m_instances; /// List of Zones std::vector zones; diff --git a/framework2/src/engine/GTAEngine.cpp b/framework2/src/engine/GTAEngine.cpp index a340ad15..42bf922d 100644 --- a/framework2/src/engine/GTAEngine.cpp +++ b/framework2/src/engine/GTAEngine.cpp @@ -11,7 +11,7 @@ #include GTAEngine::GTAEngine(const std::string& path) - : itemCount(0), gameTime(0.f), gameData(path), renderer(this), randomEngine(rand()) + : gameTime(0.f), gameData(path), renderer(this), randomEngine(rand()) { gameData.engine = this; } @@ -123,17 +123,13 @@ bool GTAEngine::placeItems(const std::string& name) { // Find the object. for( size_t i = 0; i < ipll.m_instances.size(); ++i) { - LoaderIPLInstance& inst = ipll.m_instances[i]; - glm::quat rot(-inst.rotW, inst.rotX, inst.rotY, inst.rotZ); - rot = glm::normalize(rot); - if(! createInstance(inst.id, glm::vec3(inst.posX, inst.posY, inst.posZ), rot)) { - std::cerr << "No object for instance " << inst.id << " (" << path << ")" << std::endl; + std::shared_ptr inst = ipll.m_instances[i]; + if(! createInstance(inst->id, inst->pos, inst->rot)) { + std::cerr << "No object for instance " << inst->id << " (" << path << ")" << std::endl; } } - itemCentroid += ipll.centroid; - itemCount += ipll.m_instances.size(); - // Associate LODs. + // Attempt to Associate LODs. for( size_t i = 0; i < objectInstances.size(); ++i ) { if( !objectInstances[i]->object->LOD ) { auto lodInstit = modelInstances.find("LOD" + objectInstances[i]->object->modelName.substr(3)); diff --git a/framework2/src/loaders/LoaderIPL.cpp b/framework2/src/loaders/LoaderIPL.cpp index e3de90b0..c57e90bb 100644 --- a/framework2/src/loaders/LoaderIPL.cpp +++ b/framework2/src/loaders/LoaderIPL.cpp @@ -60,8 +60,6 @@ bool LoaderIPL::load(const std::string& filename) { if(section == INST) { - LoaderIPLInstance instance; - std::string id; std::string model; std::string posX, posY, posZ; @@ -83,30 +81,15 @@ bool LoaderIPL::load(const std::string& filename) getline(strstream, rotY, ','); getline(strstream, rotZ, ','); getline(strstream, rotW, ','); - - // convert to our structure - instance.id = atoi(id.c_str()); - instance.model = model.substr(1, model.size()-1); - instance.posX = atof(posX.c_str()); - instance.posY = atof(posY.c_str()); - instance.posZ = atof(posZ.c_str()); - instance.scaleX = atof(scaleX.c_str()); - instance.scaleY = atof(scaleY.c_str()); - instance.scaleZ = atof(scaleZ.c_str()); - instance.rotX = atof(rotX.c_str()); - instance.rotY = atof(rotY.c_str()); - instance.rotZ = atof(rotZ.c_str()); - instance.rotW = atof(rotW.c_str()); - centroid += glm::vec3(instance.posX, instance.posY, instance.posZ); - - /*std::cout << "id: " << instance.id << std::endl; - std::cout << "model: " << instance.model << std::endl; - std::cout << "posX: " << instance.posX << std::endl; - std::cout << "posY: " << instance.posY << std::endl; - std::cout << "posZ: " << instance.posZ << std::endl; - std::cout << "rotW: " << instance.rotW << std::endl;*/ - + std::shared_ptr instance(new InstanceData{ + atoi(id.c_str()), // ID + model.substr(1, model.size()-1), + glm::vec3(atof(posX.c_str()), atof(posY.c_str()), atof(posZ.c_str())), + glm::vec3(atof(scaleX.c_str()), atof(scaleY.c_str()), atof(scaleZ.c_str())), + glm::normalize(glm::quat(-atof(rotW.c_str()), atof(rotX.c_str()), atof(rotY.c_str()), atof(rotZ.c_str()))) + }); + m_instances.push_back(instance); } else if(section == ZONE) diff --git a/game/main.cpp b/game/main.cpp index 77556cb0..bd331fd8 100644 --- a/game/main.cpp +++ b/game/main.cpp @@ -97,8 +97,6 @@ void init(std::string gtapath) gta->placeItems(gtapath + "/data/maps/industse/industSE.ipl"); gta->placeItems(gtapath + "/data/maps/industne/industNE.ipl");*/ - plyPos = gta->itemCentroid / (float) gta->itemCount + glm::vec3(0, 0, 2); - glm::vec3 spawnPos = plyPos + glm::vec3(-5, -20, 0.0); size_t k = 1; // Spawn every vehicle, cause why not. diff --git a/viewer/main.cpp b/viewer/main.cpp index 68606481..cfa582ab 100644 --- a/viewer/main.cpp +++ b/viewer/main.cpp @@ -258,8 +258,6 @@ void init(std::string gtapath, bool loadWorld) gta->loadZone(it->second); gta->placeItems(it->second); } - - plyPos = gta->itemCentroid / (float) gta->itemCount + glm::vec3(0, 0, 2); } glm::vec3 spawnPos = plyPos + glm::vec3(-5, -20, 0.0);