1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-26 04:12:41 +01:00

Zone files, simple case fixing, world loading

This commit is contained in:
Daniel Evans 2013-07-02 17:29:20 +01:00
parent feee2aa87d
commit e02e889745
9 changed files with 145 additions and 17 deletions

View File

@ -39,12 +39,24 @@ std::string findFileRealCase(const std::string& lowerPath) {
closedir(dp);
}
return lowerPath;
#else
// We'll just have to assume this means Windows for now.
return lowerName;
return lowerPath;
#endif
}
// Yet another hack function to fix these paths
std::string fixPath(std::string path) {
for( size_t t = 0; t < path.size(); ++t) {
path[t] = tolower(path[t]);
if(path[t] == '\\') {
path[t] = '/';
}
}
return path;
}
GTAData::GTAData(const std::string& path)
@ -94,7 +106,9 @@ void GTAData::parseDAT(const std::string& path)
}
else if(cmd == "IPL")
{
loadIPL(line.substr(space+1));
std::string fixedpath = fixPath(line.substr(space+1));
fixedpath = findFileRealCase(datpath + "/" + fixedpath);
loadIPL(fixedpath.substr((datpath+"/").size()));
}
else if(cmd == "TEXDICTION")
{
@ -198,8 +212,6 @@ char* GTAData::loadFile(const std::string& name)
return nullptr;
}
std::cout << "Loading file " << name << std::endl;
auto i = fileLocations.find(name);
if(i != fileLocations.end())
{
@ -246,10 +258,5 @@ char* GTAData::loadFile(const std::string& name)
void GTAData::loadIPL(const std::string& name)
{
std::string lowername = name;
for(size_t t = 0; t < lowername.size(); ++t)
{
lowername[t] = tolower(lowername[t]);
}
iplLocations.insert({lowername, datpath + "/" + lowername});
iplLocations.insert({name, datpath + "/" + name});
}

View File

@ -19,6 +19,14 @@ bool GTAEngine::load()
defineItems(it->second);
}
// Load the .zon IPLs since we want to have the zones loaded
for(std::map<std::string, std::string>::iterator it = gameData.iplLocations.begin();
it != gameData.iplLocations.end();
++it) {
loadZone(it->second);
placeItems(it->second);
}
return true;
}
@ -109,4 +117,22 @@ bool GTAEngine::placeItems(const std::string& name)
}
return false;
}
}
bool GTAEngine::loadZone(const std::string& path)
{
LoaderIPL ipll;
if( ipll.load(path)) {
if( ipll.zones.size() > 0) {
zones.insert(zones.begin(), ipll.zones.begin(), ipll.zones.end());
std::cout << "Loaded " << ipll.zones.size() << " zones" << std::endl;
return true;
}
}
else {
std::cerr << "Failed to load IPL " << path << std::endl;
}
return false;
}

View File

@ -96,13 +96,14 @@ void GTARenderer::renderWorld(GTAEngine* engine)
glm::vec3 pos(obj.posX, obj.posY, obj.posZ);
glm::vec3 scale(obj.scaleX, obj.scaleY, obj.scaleZ);
float mindist = glm::length(pos - camera.worldPos);
float mindist = 100000.f;
for (size_t g = 0; g < model->geometries.size(); g++)
{
RW::BSGeometryBounds& bounds = model->geometries[g].geometryBounds;
mindist = std::min(mindist, glm::length((pos+bounds.center) - camera.worldPos) - bounds.radius);
}
if( mindist > inst.object->drawDistance[0] || (inst.object->modelName.substr(0, 3) == "LOD" && mindist > inst.object->drawDistance[0])) {
if( mindist > (inst.object->drawDistance[0] * (inst.object->LOD ? 1.f : 2.f))
|| (inst.object->LOD && mindist < 250.f) ) {
culled++;
continue;
}

View File

@ -73,6 +73,7 @@ bool LoaderIDE::load(const std::string &filename)
objs.flags = atoi(flags.c_str());
objs.modelName = modelName;
objs.textureName = textureName;
objs.LOD = modelName.find("LOD") != modelName.npos;
OBJSs.push_back(objs);
break;

View File

@ -7,7 +7,7 @@
enum SectionTypes
{
INST,
INST,
PICK,
CULL,
ZONE,
@ -109,6 +109,39 @@ bool LoaderIPL::load(const std::string& filename)
m_instances.push_back(instance);
}
else if(section == ZONE)
{
Zone zone;
std::stringstream strstream(line);
std::string value;
getline(strstream, value, ',');
zone.name = value;
getline(strstream, value, ',');
zone.type = atoi(value.c_str());
getline(strstream, value, ',');
zone.min.x = atof(value.c_str());
getline(strstream, value, ',');
zone.min.y = atof(value.c_str());
getline(strstream, value, ',');
zone.min.z = atof(value.c_str());
getline(strstream, value, ',');
zone.max.x = atof(value.c_str());
getline(strstream, value, ',');
zone.max.y = atof(value.c_str());
getline(strstream, value, ',');
zone.max.z = atof(value.c_str());
getline(strstream, value, ',');
zone.island = atoi(value.c_str());
zones.push_back(zone);
}
}
}

View File

@ -71,6 +71,11 @@ public:
*/
bool placeItems(const std::string& name);
/**
* Loads the Zones from a zon/IPL file
*/
bool loadZone(const std::string& path);
/**
* Roughly the middle of everything
*/
@ -92,6 +97,11 @@ public:
*/
GTARenderer renderer;
/**
* Map Zones
*/
std::vector<LoaderIPL::Zone> zones;
/**
* Object Definitions
*/

View File

@ -29,6 +29,7 @@ public:
size_t numClumps;
float drawDistance[3];
int32_t flags;
bool LOD;
};
enum VehicleClass

View File

@ -27,6 +27,42 @@ public:
class LoaderIPL
{
public:
/**
* \class Zone
* A Zone entry
*/
class Zone
{
public:
/**
* The name of the Zone (see .gxt)
*/
std::string name;
int type;
/**
* Bottom left of the Zone
*/
glm::vec3 min;
/**
* Top Right of the zone
*/
glm::vec3 max;
/**
* Island number
*/
int island;
/**
* Text of the zone?
*/
std::string Text;
};
/// Load the IPL data into memory
bool load(const std::string& filename);
@ -35,6 +71,9 @@ public:
/// The centroid of the instances
glm::vec3 centroid;
/// List of Zones
std::vector<Zone> zones;
};
#endif // LoaderIPL_h__

View File

@ -25,6 +25,7 @@ GTAEngine* gta = nullptr;
glm::vec3 plyPos;
glm::vec2 plyLook;
float moveSpeed = 20.0f;
void handleEvent(sf::Event &event)
{
@ -34,9 +35,19 @@ void handleEvent(sf::Event &event)
case sf::Keyboard::Escape:
window.close();
break;
case sf::Keyboard::Space:
moveSpeed = 60.f;
break;
default: break;
}
break;
case sf::Event::KeyReleased:
switch(event.key.code) {
case sf::Keyboard::Space:
moveSpeed = 20.f;
break;
}
break;
default: break;
}
}
@ -55,10 +66,10 @@ void init(std::string gtapath)
gta->load();
// Test out a known IPL.
gta->placeItems(gtapath + "/data/maps/industsw/industSW.ipl");
/*gta->placeItems(gtapath + "/data/maps/industsw/industSW.ipl");
gta->placeItems(gtapath + "/data/maps/industnw/industNW.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;
}
@ -66,7 +77,6 @@ void init(std::string gtapath)
void update(float dt)
{
static int i = 0;
constexpr float moveSpeed = 20;
sf::Vector2i screenCenter{sf::Vector2i{window.getSize()} / 2};
sf::Vector2i mousePos = sf::Mouse::getPosition(window);