1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 03:12:36 +01:00

Added IDE Loader!

This commit is contained in:
Timmy Sjöstedt 2013-07-02 12:16:41 +02:00
parent eb6d79f9fb
commit d796dea97e
4 changed files with 275 additions and 0 deletions

View File

@ -10,6 +10,7 @@ add_library(renderware
LoaderCOL.cpp
LoaderIMG.cpp
LoaderIPL.cpp
LoaderIDE.cpp
GTAData.cpp
GTAEngine.cpp

View File

@ -1,6 +1,7 @@
#include <renderwure/engine/GTAData.hpp>
#include <renderwure/loaders/LoaderIPL.hpp>
#include <renderwure/loaders/LoaderDFF.hpp>
#include <renderwure/loaders/LoaderIDE.hpp>
#include <iostream>
#include <fstream>
@ -57,6 +58,11 @@ void GTAData::load()
void GTAData::loadIDE(const std::string& name)
{
std::cout << "IDE File " << name << std::endl;
LoaderIDE ideLoader;
if ( ! ideLoader.load(datpath + name)) {
std::cerr << "COULD NOT LOAD IDE FILE '" << name << "' FOR SOME REASON" << std::endl;
}
}
void GTAData::loadCOL(const size_t zone, const std::string& name)

172
framework2/LoaderIDE.cpp Normal file
View File

@ -0,0 +1,172 @@
#include <renderwure/loaders/LoaderIDE.hpp>
#include <fstream>
#include <string>
#include <map>
#include <sstream>
#include <algorithm>
bool LoaderIDE::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);
line.erase(std::find_if(line.rbegin(), line.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), line.end());
if ( ! line.empty() && line[0] == '#')
continue;
if (line == "end") {
section = NONE;
} else if(section == NONE) {
if (line == "objs") {
section = OBJS;
} else if (line == "tobj") {
section = TOBJ;
} else if (line == "peds") {
section = PEDS;
} else if (line == "cars") {
section = CARS;
} else if (line == "hier") {
section = HIER;
} else if (line == "2dfx") {
section = TWODFX;
} else if (line == "path") {
section = PATH;
}
} else {
// Remove ALL the whitespace!!
line.erase(remove_if(line.begin(), line.end(), isspace), line.end());
std::stringstream strstream(line);
switch (section) {
case OBJS: { // Supports Type 1, 2 and 3
OBJS_t objs;
std::string id, numClumps, flags,
modelName, textureName;
// Read the content of the line
getline(strstream, id, ',');
getline(strstream, modelName, ',');
getline(strstream, textureName, ',');
getline(strstream, numClumps, ',');
objs.numClumps = atoi(numClumps.c_str());
for (size_t i = 0; i < objs.numClumps; i++) {
std::string drawDistance;
getline(strstream, drawDistance, ',');
objs.drawDistance[i] = atoi(drawDistance.c_str());
}
getline(strstream, flags, ',');
// Put stuff in our struct
objs.ID = atoi(id.c_str());
objs.flags = atoi(flags.c_str());
objs.modelName = modelName;
objs.textureName = textureName;
OBJSs.push_back(objs);
break;
}
case CARS: {
CARS_t cars;
std::string id, modelName, textureName, type, handlingID,
gameName, classType, frequency, lvl,
comprules, wheelModelID, wheelScale;
getline(strstream, id, ',');
getline(strstream, cars.modelName, ',');
getline(strstream, cars.textureName, ',');
getline(strstream, type, ',');
getline(strstream, cars.handlingID, ',');
getline(strstream, cars.gameName, ',');
getline(strstream, classType, ',');
getline(strstream, frequency, ',');
getline(strstream, lvl, ',');
getline(strstream, comprules, ',');
getline(strstream, wheelModelID, ',');
getline(strstream, wheelScale, ',');
cars.ID = atoi(id.c_str());
cars.frequency = atoi(frequency.c_str());
cars.lvl = atoi(lvl.c_str());
cars.comprules = atoi(comprules.c_str());
if (type == "car") {
cars.type = CAR;
cars.wheelModelID = atoi(wheelModelID.c_str());
cars.wheelScale = atof(wheelScale.c_str());
} else if (type == "boat") {
cars.type = BOAT;
} else if (type == "train") {
cars.type = TRAIN;
cars.modelLOD = atoi(wheelModelID.c_str());
} else if (type == "plane") {
cars.type = PLANE;
} else if (type == "heli") {
cars.type = HELI;
}
const std::map<VehicleClass, std::string> classTypes{
{IGNORE, "ignore"},
{NORMAL, "normal"},
{POORFAMILY, "poorfamily"},
{RICHFAMILY, "richfamily"},
{EXECUTIVE, "executive"},
{WORKER, "worker"},
{BIG, "big"},
{TAXI, "taxi"},
{MOPED, "moped"},
{MOTORBIKE, "motorbike"},
{LEISUREBOAT, "leisureboat"},
{WORKERBOAT, "workerboat"},
{BICYCLE, "bicycle"},
{ONFOOT, "onfoot"},
};
for (auto &a : classTypes) {
if (classType == a.second) {
cars.classType = a.first;
break;
}
}
CARSs.push_back(cars);
break;
}
case PEDS: {
PEDS_t peds;
std::string id, modelName, textureName, type,
behaviour, animGroup, driveMask;
getline(strstream, id, ',');
getline(strstream, peds.modelName, ',');
getline(strstream, peds.textureName, ',');
getline(strstream, peds.type, ',');
getline(strstream, peds.behaviour, ',');
getline(strstream, peds.animGroup, ',');
getline(strstream, driveMask, ',');
peds.ID = atoi(id.c_str());
peds.driveMask = atoi(driveMask.c_str());
PEDSs.push_back(peds);
break;
}
}
}
}
return true;
}

View File

@ -0,0 +1,96 @@
#pragma once
#ifndef _LOADERIDE_HPP_
#define _LOADERIDE_HPP_
#include <iostream>
#include <vector>
#include <glm/glm.hpp>
class LoaderIDE
{
public:
enum SectionTypes
{
NONE,
OBJS,
TOBJ,
PEDS,
CARS,
HIER,
TWODFX,
PATH,
};
struct OBJS_t
{
uint16_t ID;
std::string modelName;
std::string textureName;
size_t numClumps;
float drawDistance[3];
int32_t flags;
};
enum VehicleClass
{
IGNORE = 0,
NORMAL = 1,
POORFAMILY = 1 << 1,
RICHFAMILY = 1 << 2,
EXECUTIVE = 1 << 3,
WORKER = 1 << 4,
BIG = 1 << 5,
TAXI = 1 << 6,
MOPED = 1 << 7,
MOTORBIKE = 1 << 8,
LEISUREBOAT = 1 << 9,
WORKERBOAT = 1 << 10,
BICYCLE = 1 << 11,
ONFOOT = 1 << 12,
};
enum VehicleType {
CAR,
BOAT,
TRAIN,
PLANE,
HELI,
};
struct CARS_t
{
uint16_t ID;
std::string modelName;
std::string textureName;
VehicleType type;
std::string handlingID;
std::string gameName;
VehicleClass classType;
uint8_t frequency; // big enough int type?
uint8_t lvl; // big enough int type?
uint16_t comprules;
union { // big enough int types?
uint16_t wheelModelID; // used only when type == CAR
int16_t modelLOD; // used only when type == PLANE
};
float wheelScale; // used only when type == CAR
};
struct PEDS_t
{
uint16_t ID;
std::string modelName;
std::string textureName;
std::string type;
std::string behaviour;
std::string animGroup;
uint8_t driveMask;
};
// Load the IDE data into memory
bool load(const std::string& filename);
std::vector<OBJS_t> OBJSs;
std::vector<CARS_t> CARSs;
std::vector<PEDS_t> PEDSs;
};
#endif