mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-09 12:22:34 +01:00
Refactored Instance data
This commit is contained in:
parent
0b046947da
commit
84c94c5c24
32
framework2/include/renderwure/data/InstanceData.hpp
Normal file
32
framework2/include/renderwure/data/InstanceData.hpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#pragma once
|
||||||
|
#ifndef __INSTANCEDATA_HPP__
|
||||||
|
#define __INSTANCEDATA_HPP__
|
||||||
|
#include <string>
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
#include <glm/gtc/quaternion.hpp>
|
||||||
|
|
||||||
|
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
|
@ -98,12 +98,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
GTACharacter* createPedestrian(const uint16_t id, const glm::vec3& pos, const glm::quat& rot = glm::quat());
|
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
|
* Game Clock
|
||||||
*/
|
*/
|
||||||
|
@ -1,23 +1,10 @@
|
|||||||
#ifndef _LOADERIPL_HPP_
|
#ifndef _LOADERIPL_HPP_
|
||||||
#define _LOADERIPL_HPP_
|
#define _LOADERIPL_HPP_
|
||||||
|
#include <renderwure/data/InstanceData.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <glm/glm.hpp>
|
#include <memory>
|
||||||
|
|
||||||
/**
|
|
||||||
\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
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
\class LoaderIPL
|
\class LoaderIPL
|
||||||
@ -66,10 +53,7 @@ public:
|
|||||||
bool load(const std::string& filename);
|
bool load(const std::string& filename);
|
||||||
|
|
||||||
/// The list of instances from the IPL file
|
/// The list of instances from the IPL file
|
||||||
std::vector<LoaderIPLInstance> m_instances;
|
std::vector<std::shared_ptr<InstanceData>> m_instances;
|
||||||
|
|
||||||
/// The centroid of the instances
|
|
||||||
glm::vec3 centroid;
|
|
||||||
|
|
||||||
/// List of Zones
|
/// List of Zones
|
||||||
std::vector<Zone> zones;
|
std::vector<Zone> zones;
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
#include <renderwure/objects/GTAVehicle.hpp>
|
#include <renderwure/objects/GTAVehicle.hpp>
|
||||||
|
|
||||||
GTAEngine::GTAEngine(const std::string& path)
|
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;
|
gameData.engine = this;
|
||||||
}
|
}
|
||||||
@ -123,17 +123,13 @@ bool GTAEngine::placeItems(const std::string& name)
|
|||||||
{
|
{
|
||||||
// Find the object.
|
// Find the object.
|
||||||
for( size_t i = 0; i < ipll.m_instances.size(); ++i) {
|
for( size_t i = 0; i < ipll.m_instances.size(); ++i) {
|
||||||
LoaderIPLInstance& inst = ipll.m_instances[i];
|
std::shared_ptr<InstanceData> inst = ipll.m_instances[i];
|
||||||
glm::quat rot(-inst.rotW, inst.rotX, inst.rotY, inst.rotZ);
|
if(! createInstance(inst->id, inst->pos, inst->rot)) {
|
||||||
rot = glm::normalize(rot);
|
std::cerr << "No object for instance " << inst->id << " (" << path << ")" << std::endl;
|
||||||
if(! createInstance(inst.id, glm::vec3(inst.posX, inst.posY, inst.posZ), 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 ) {
|
for( size_t i = 0; i < objectInstances.size(); ++i ) {
|
||||||
if( !objectInstances[i]->object->LOD ) {
|
if( !objectInstances[i]->object->LOD ) {
|
||||||
auto lodInstit = modelInstances.find("LOD" + objectInstances[i]->object->modelName.substr(3));
|
auto lodInstit = modelInstances.find("LOD" + objectInstances[i]->object->modelName.substr(3));
|
||||||
|
@ -60,8 +60,6 @@ bool LoaderIPL::load(const std::string& filename)
|
|||||||
{
|
{
|
||||||
if(section == INST)
|
if(section == INST)
|
||||||
{
|
{
|
||||||
LoaderIPLInstance instance;
|
|
||||||
|
|
||||||
std::string id;
|
std::string id;
|
||||||
std::string model;
|
std::string model;
|
||||||
std::string posX, posY, posZ;
|
std::string posX, posY, posZ;
|
||||||
@ -83,30 +81,15 @@ bool LoaderIPL::load(const std::string& filename)
|
|||||||
getline(strstream, rotY, ',');
|
getline(strstream, rotY, ',');
|
||||||
getline(strstream, rotZ, ',');
|
getline(strstream, rotZ, ',');
|
||||||
getline(strstream, rotW, ',');
|
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::shared_ptr<InstanceData> instance(new InstanceData{
|
||||||
|
atoi(id.c_str()), // ID
|
||||||
/*std::cout << "id: " << instance.id << std::endl;
|
model.substr(1, model.size()-1),
|
||||||
std::cout << "model: " << instance.model << std::endl;
|
glm::vec3(atof(posX.c_str()), atof(posY.c_str()), atof(posZ.c_str())),
|
||||||
std::cout << "posX: " << instance.posX << std::endl;
|
glm::vec3(atof(scaleX.c_str()), atof(scaleY.c_str()), atof(scaleZ.c_str())),
|
||||||
std::cout << "posY: " << instance.posY << std::endl;
|
glm::normalize(glm::quat(-atof(rotW.c_str()), atof(rotX.c_str()), atof(rotY.c_str()), atof(rotZ.c_str())))
|
||||||
std::cout << "posZ: " << instance.posZ << std::endl;
|
});
|
||||||
std::cout << "rotW: " << instance.rotW << std::endl;*/
|
|
||||||
|
|
||||||
m_instances.push_back(instance);
|
m_instances.push_back(instance);
|
||||||
}
|
}
|
||||||
else if(section == ZONE)
|
else if(section == ZONE)
|
||||||
|
@ -97,8 +97,6 @@ void init(std::string gtapath)
|
|||||||
gta->placeItems(gtapath + "/data/maps/industse/industSE.ipl");
|
gta->placeItems(gtapath + "/data/maps/industse/industSE.ipl");
|
||||||
gta->placeItems(gtapath + "/data/maps/industne/industNE.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);
|
glm::vec3 spawnPos = plyPos + glm::vec3(-5, -20, 0.0);
|
||||||
size_t k = 1;
|
size_t k = 1;
|
||||||
// Spawn every vehicle, cause why not.
|
// Spawn every vehicle, cause why not.
|
||||||
|
@ -258,8 +258,6 @@ void init(std::string gtapath, bool loadWorld)
|
|||||||
gta->loadZone(it->second);
|
gta->loadZone(it->second);
|
||||||
gta->placeItems(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);
|
glm::vec3 spawnPos = plyPos + glm::vec3(-5, -20, 0.0);
|
||||||
|
Loading…
Reference in New Issue
Block a user