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

Merge branch 'objects'

This commit is contained in:
Daniel Evans 2014-01-29 08:47:01 +00:00
commit 326fe4eeb3
4 changed files with 80 additions and 0 deletions

View File

@ -94,4 +94,35 @@ struct CharacterData
uint8_t driveMask;
};
/**
* This is orthogonal to object class, it gives
* Instances different physical properties.
*/
struct DynamicObjectData
{
std::string modelName;
float mass; // Kg
float turnMass; // Kg m^3
float airRes; // fraction
float elacticity; // "
float bouancy;
float uprootForce; // Force
float collDamageMulti;
/*
* 1: change model
* 2: split model
* 3: smash
* 4: change and smash
*/
uint8_t collDamageFlags;
/*
* 1: lampost
* 2: smallbox
* 3: bigbox
* 4: fencepart
*/
uint8_t collResponseFlags;
bool cameraAvoid;
};
#endif

View File

@ -14,6 +14,7 @@
#include <memory>
struct DynamicObjectData;
class GameWorld;
class TextureAtlas;
@ -124,6 +125,11 @@ public:
*/
void loadIFP(const std::string& name);
/**
* Loads data from an object definition dat.
*/
void loadDynamicObjects(const std::string& name);
/**
* Returns a pointer to the named file if it is available, the memory must be freed.
* @param name the filename in the archive
@ -210,6 +216,11 @@ public:
*/
std::map<std::string, std::unique_ptr<CollisionModel>> collisions;
/**
* DynamicObjectData
*/
std::map<std::string, std::shared_ptr<DynamicObjectData>> dynamicObjectData;
/**
* Water Rectangles
*/

View File

@ -5,6 +5,7 @@
#include <loaders/LoaderIDE.hpp>
#include <render/TextureAtlas.hpp>
#include <loaders/LoaderCOL.hpp>
#include <data/ObjectData.hpp>
#include <iostream>
#include <fstream>
@ -429,6 +430,40 @@ void GameData::loadIFP(const std::string &name)
}
}
void GameData::loadDynamicObjects(const std::string& name)
{
std::ifstream dfile(name.c_str());
if(dfile.is_open()) {
std::string lineBuff;
while(std::getline(dfile, lineBuff)) {
if(lineBuff.at(0) == ';') continue;
std::stringstream ss(lineBuff);
std::shared_ptr<DynamicObjectData> dyndata(new DynamicObjectData);
ss >> dyndata->modelName;
ss >> dyndata->mass;
ss >> dyndata->turnMass;
ss >> dyndata->airRes;
ss >> dyndata->elacticity;
ss >> dyndata->bouancy;
ss >> dyndata->uprootForce;
ss >> dyndata->collDamageMulti;
ss >> dyndata->collDamageFlags;
ss >> dyndata->collResponseFlags;
ss >> dyndata->cameraAvoid;
dynamicObjectData.insert({dyndata->modelName, dyndata});
}
}
else {
engine->logError("Failed to load dynamic object file: " + name);
}
}
char* GameData::loadFile(const std::string& name)
{
if( loadedFiles.find(name) != loadedFiles.end()) {

View File

@ -407,6 +407,9 @@ void init(std::string gtapath, bool loadWorld)
gta->load();
// Load dynamic object data
gta->gameData.loadDynamicObjects(gtapath + "/data/object.dat");
// Set time to noon.
gta->gameTime = 12.f * 60.f;