mirror of
https://github.com/rwengine/openrw.git
synced 2024-09-15 06:52:34 +02:00
Added IPL Loader
This commit is contained in:
parent
3cf53a5dd6
commit
a2b06209bb
@ -1,4 +1,4 @@
|
||||
add_executable(datadump main.cpp ../framework/gtadata.cpp ../framework/LoaderIMG.cpp)
|
||||
add_executable(datadump main.cpp ../framework/gtadata.cpp ../framework/LoaderIMG.cpp ../framework/LoaderIPL.cpp)
|
||||
|
||||
target_link_libraries( datadump sfml-graphics sfml-window sfml-system GL GLEW )
|
||||
|
||||
|
113
framework/LoaderIPL.cpp
Normal file
113
framework/LoaderIPL.cpp
Normal file
@ -0,0 +1,113 @@
|
||||
#include "LoaderIPL.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
enum SectionTypes
|
||||
{
|
||||
INST,
|
||||
PICK,
|
||||
CULL,
|
||||
ZONE,
|
||||
NONE
|
||||
};
|
||||
|
||||
/// Load the IPL data into memory
|
||||
bool LoaderIPL::load(const std::string& filename)
|
||||
{
|
||||
std::ifstream str(filename);
|
||||
|
||||
if(!str.is_open())
|
||||
return false;
|
||||
|
||||
SectionTypes section = NONE;
|
||||
while(!str.eof())
|
||||
{
|
||||
std::string line;
|
||||
getline(str, line);
|
||||
|
||||
if(!line.empty() && line[0] == '#')
|
||||
{
|
||||
// nothing, just a comment
|
||||
}
|
||||
else if(line == "end") // terminating a section
|
||||
{
|
||||
section = NONE;
|
||||
}
|
||||
else if(section == NONE) // starting a new section
|
||||
{
|
||||
if(line == "inst")
|
||||
{
|
||||
section = INST;
|
||||
}
|
||||
if(line == "pick")
|
||||
{
|
||||
section = PICK;
|
||||
}
|
||||
if(line == "cull")
|
||||
{
|
||||
section = CULL;
|
||||
}
|
||||
if(line == "zone")
|
||||
{
|
||||
section = ZONE;
|
||||
}
|
||||
}
|
||||
else // regular entry
|
||||
{
|
||||
if(section == INST)
|
||||
{
|
||||
LoaderIPLInstance instance;
|
||||
|
||||
std::string id;
|
||||
std::string model;
|
||||
std::string posX, posY, posZ;
|
||||
std::string scaleX, scaleY, scaleZ;
|
||||
std::string rotX, rotY, rotZ, rotW;
|
||||
|
||||
std::stringstream strstream(line);
|
||||
|
||||
// read all the contents of the line
|
||||
getline(strstream, id, ',');
|
||||
getline(strstream, model, ',');
|
||||
getline(strstream, posX, ',');
|
||||
getline(strstream, posY, ',');
|
||||
getline(strstream, posZ, ',');
|
||||
getline(strstream, scaleX, ',');
|
||||
getline(strstream, scaleY, ',');
|
||||
getline(strstream, scaleZ, ',');
|
||||
getline(strstream, rotX, ',');
|
||||
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());
|
||||
|
||||
/*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;*/
|
||||
|
||||
m_instances.push_back(instance);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
35
framework/LoaderIPL.h
Normal file
35
framework/LoaderIPL.h
Normal file
@ -0,0 +1,35 @@
|
||||
#ifndef LoaderIPL_h__
|
||||
#define LoaderIPL_h__
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
\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
|
||||
\brief Loads all data from a IPL file into memory
|
||||
*/
|
||||
class LoaderIPL
|
||||
{
|
||||
public:
|
||||
/// Load the IPL data into memory
|
||||
bool load(const std::string& filename);
|
||||
|
||||
/// The list of instances from the IPL file
|
||||
std::vector<LoaderIPLInstance> m_instances;
|
||||
};
|
||||
|
||||
#endif // LoaderIPL_h__
|
@ -1,4 +1,5 @@
|
||||
#include "gtadata.h"
|
||||
#include "LoaderIPL.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
@ -57,5 +58,14 @@ void GTAData::loadCOL(const size_t zone, const std::string& name)
|
||||
|
||||
void GTAData::loadIPL(const std::string& name)
|
||||
{
|
||||
std::cout << "IPL File " << name << std::endl;
|
||||
LoaderIPL ipll;
|
||||
|
||||
if(ipll.load(name))
|
||||
{
|
||||
// wait for it..
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Failed to load IPL: " << name << std::endl;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user