1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-22 02:12:45 +01:00

Cleaned up some object data

Renamed some vehicle related data objects
Changed types on some vehicle data containers
Renamed GTAObject to GameObject
This commit is contained in:
Daniel Evans 2014-02-28 11:23:51 +00:00
parent caa1fd301e
commit e1a37e44c4
24 changed files with 205 additions and 152 deletions

View File

@ -4,6 +4,7 @@
#include <stdint.h>
#include <string>
#include <vector>
#include <memory>
#include <glm/glm.hpp>
/**
@ -42,9 +43,23 @@ struct ObjectData
};
/**
* Data used by vehicles
* Data used by peds
*/
struct CarData
struct CharacterData
{
uint16_t ID;
std::string modelName;
std::string textureName;
std::string type;
std::string behaviour;
std::string animGroup;
uint8_t driveMask;
};
/**
* Data shared by vehicles types.
*/
struct VehicleData
{
enum VehicleClass
{
@ -63,7 +78,7 @@ struct CarData
BICYCLE = 1 << 11,
ONFOOT = 1 << 12,
};
enum VehicleType {
CAR,
BOAT,
@ -71,7 +86,7 @@ struct CarData
PLANE,
HELI,
};
uint16_t ID;
std::string modelName;
std::string textureName;
@ -89,19 +104,7 @@ struct CarData
float wheelScale; // used only when type == CAR
};
/**
* Data used by peds
*/
struct CharacterData
{
uint16_t ID;
std::string modelName;
std::string textureName;
std::string type;
std::string behaviour;
std::string animGroup;
uint8_t driveMask;
};
typedef std::shared_ptr<VehicleData> VehicleDataHandle;
/**
* This is orthogonal to object class, it gives
@ -134,4 +137,4 @@ struct DynamicObjectData
bool cameraAvoid;
};
#endif
#endif

View File

@ -179,7 +179,7 @@ public:
/**
* Vehicle information
*/
std::map<std::string, VehicleInfo> vehicleInfo;
std::map<std::string, VehicleInfoHandle> vehicleInfo;
/**
* Texture Loader

View File

@ -1,6 +1,6 @@
#pragma once
#ifndef _GTAOBJECT_HPP_
#define _GTAOBJECT_HPP_
#ifndef _GAMEOBJECT_HPP_
#define _GAMEOBJECT_HPP_
#include <engine/GTATypes.hpp>
#include <loaders/LoaderIDE.hpp>
@ -17,7 +17,7 @@ class GameWorld;
/**
* Stores data used by call types of object instances.
*/
struct GTAObject
struct GameObject
{
glm::vec3 position;
glm::quat rotation;
@ -33,10 +33,10 @@ struct GTAObject
*/
float mHealth;
GTAObject(GameWorld* engine, const glm::vec3& pos, const glm::quat& rot, Model* model)
GameObject(GameWorld* engine, const glm::vec3& pos, const glm::quat& rot, Model* model)
: position(pos), rotation(rot), model(model), engine(engine), animator(nullptr), mHealth(0.f) {}
virtual ~GTAObject() {};
virtual ~GameObject() {};
enum Type
{
@ -87,4 +87,4 @@ struct GTAObject
virtual bool takeDamage(const DamageInfo& damage) { return false; };
};
#endif // GTAOBJECTS_HPP
#endif // __GAMEOBJECTS_HPP__

View File

@ -8,7 +8,7 @@
#include <ai/GTAAINode.hpp>
#include <ai/AIGraph.hpp>
class GTAObject;
class GameObject;
class GTACharacter;
class GTAInstance;
class GTAVehicle;
@ -101,7 +101,7 @@ public:
/**
* Destroys an existing Object
*/
void destroyObject(GTAObject* object);
void destroyObject(GameObject* object);
/**
* Returns the current hour
@ -146,7 +146,7 @@ public:
/**
* Vehicle definitions
*/
std::map<uint16_t, std::shared_ptr<CarData>> vehicleTypes;
std::map<uint16_t, std::shared_ptr<VehicleData>> vehicleTypes;
/**
* Ped definitions

View File

@ -7,6 +7,7 @@
#include <memory>
#include <glm/glm.hpp>
#include <data/ObjectData.hpp>
#include <objects/VehicleInfo.hpp>
#include <data/PathData.hpp>
class LoaderIDE
@ -28,7 +29,7 @@ public:
bool load(const std::string& filename);
std::vector<std::shared_ptr<ObjectData>> OBJSs;
std::vector<std::shared_ptr<CarData>> CARSs;
std::vector<std::shared_ptr<VehicleData>> CARSs;
std::vector<std::shared_ptr<CharacterData>> PEDSs;
std::vector<std::shared_ptr<PathData>> PATHs;
};

View File

@ -1,7 +1,7 @@
#pragma once
#ifndef _GTACHARACTER_HPP_
#define _GTACHARACTER_HPP_
#include <engine/GTAObject.hpp>
#include <engine/GameObject.hpp>
#include <bullet/BulletDynamics/Character/btKinematicCharacterController.h>
#include <bullet/btBulletCollisionCommon.h>
#include <BulletCollision/CollisionDispatch/btGhostObject.h>
@ -14,7 +14,7 @@ class GameWorld;
* @brief The GTACharacter struct
* Stores data relating to an instance of a "pedestrian".
*/
struct GTACharacter : public GTAObject
struct GTACharacter : public GameObject
{
private:
GTAVehicle* currentVehicle;

View File

@ -1,13 +1,13 @@
#pragma once
#ifndef _GTAINSTANCE_HPP_
#define _GTAINSTANCE_HPP_
#include <engine/GTAObject.hpp>
#include <engine/GameObject.hpp>
/**
* @struct GTAInstance
* Stores references to the Object data and the instance
*/
struct GTAInstance : public GTAObject
struct GTAInstance : public GameObject
{
glm::vec3 scale;
std::shared_ptr<ObjectData> object;

View File

@ -1,7 +1,7 @@
#pragma once
#ifndef _GTAVEHICLE_HPP_
#define _GTAVEHICLE_HPP_
#include <engine/GTAObject.hpp>
#include <engine/GameObject.hpp>
#include <bullet/btBulletDynamicsCommon.h>
#include <map>
#include <objects/VehicleInfo.hpp>
@ -10,7 +10,7 @@
* @class GTAVehicle
* Stores references to the vehicle data and the instance
*/
struct GTAVehicle : public GTAObject
struct GTAVehicle : public GameObject
{
private:
float steerAngle;
@ -19,12 +19,12 @@ private:
bool handbrake;
public:
std::shared_ptr<CarData> vehicle;
VehicleInfo info;
VehicleDataHandle vehicle;
VehicleInfoHandle info;
glm::vec3 colourPrimary;
glm::vec3 colourSecondary;
std::map<size_t, GTAObject*> seatOccupants;
std::map<size_t, GameObject*> seatOccupants;
btRigidBody* physBody;
btVehicleRaycaster* physRaycaster;
@ -34,8 +34,8 @@ public:
const glm::vec3& pos,
const glm::quat& rot,
Model* model,
std::shared_ptr<CarData> data,
const VehicleInfo& info,
VehicleDataHandle data,
VehicleInfoHandle info,
const glm::vec3& prim,
const glm::vec3& sec);
@ -69,9 +69,9 @@ public:
void ejectAll();
GTAObject* getOccupant(size_t seat);
GameObject* getOccupant(size_t seat);
void setOccupant(size_t seat, GTAObject* occupant);
void setOccupant(size_t seat, GameObject* occupant);
virtual bool takeDamage(const DamageInfo& damage);
};

View File

@ -3,8 +3,11 @@
#define _VEHICLE_INFO_HPP_
#include <string>
#include <vector>
#include <memory>
#include <glm/glm.hpp>
class VehicleData;
/**
* Vehicle handling data
*/
@ -80,13 +83,19 @@ struct SeatInfo {
glm::vec3 offset;
};
struct VehicleInfo
{
/**
* Vehicle Handling and runtime data.
*/
struct VehicleInfo {
/** Handling data */
VehicleHandlingInfo handling;
/** Value for caching wheel information */
std::vector<WheelInfo> wheels;
/** Value for caching seat information */
std::vector<SeatInfo> seats;
};
typedef std::shared_ptr<VehicleInfo> VehicleInfoHandle;
#endif

View File

@ -11,7 +11,7 @@
class Model;
class ModelFrame;
class GameWorld;
class GTAObject;
class GameObject;
class Animator;
/**
@ -29,13 +29,13 @@ class GTARenderer
size_t g;
size_t sg;
glm::mat4 matrix;
GTAObject* object;
GameObject* object;
};
bool renderFrame(Model* m, ModelFrame* f, const glm::mat4& matrix, GTAObject* object, bool queueTransparent = true);
bool renderFrame(Model* m, ModelFrame* f, const glm::mat4& matrix, GameObject* object, bool queueTransparent = true);
// Internal method for processing sub-geometry
bool renderSubgeometry(Model* model, size_t g, size_t sg, const glm::mat4& matrix, GTAObject* object, bool queueTransparent = true);
bool renderSubgeometry(Model* model, size_t g, size_t sg, const glm::mat4& matrix, GameObject* object, bool queueTransparent = true);
/// Queue of sub-geometry to post-render
/// With a faster occulusion culling stage
@ -72,12 +72,12 @@ public:
void renderNamedFrame(Model*, const glm::mat4& matrix, const std::string& name);
void renderGeometry(Model*, size_t geom, const glm::mat4& modelMatrix, GTAObject* = nullptr);
void renderGeometry(Model*, size_t geom, const glm::mat4& modelMatrix, GameObject* = nullptr);
/**
* Renders a model (who'd have thought)
*/
void renderModel(Model*, const glm::mat4& modelMatrix, GTAObject* = nullptr, Animator* animator = nullptr);
void renderModel(Model*, const glm::mat4& modelMatrix, GameObject* = nullptr, Animator* animator = nullptr);
/**
* Debug method renders all AI paths

View File

@ -30,7 +30,7 @@ void GTAPlayerAIController::exitVehicle()
if(character->getCurrentVehicle()) {
// Determine the seat location and teleport to outside the vehicle.
auto vehicle = character->getCurrentVehicle();
auto seatPos = vehicle->info.seats[character->getCurrentSeat()].offset;
auto seatPos = vehicle->info->seats[character->getCurrentSeat()].offset;
seatPos.x += 1.f * glm::sign(seatPos.x);
glm::mat4 vehicleMatrix;
vehicleMatrix = glm::translate(vehicleMatrix, vehicle->getPosition());

View File

@ -1,18 +0,0 @@
#include <engine/GTAObject.hpp>
#include <loaders/LoaderIFP.hpp>
#include <loaders/LoaderDFF.hpp>
void GTAObject::setPosition(const glm::vec3& pos)
{
position = pos;
}
glm::vec3 GTAObject::getPosition() const
{
return position;
}
glm::quat GTAObject::getRotation() const
{
return rotation;
}

View File

@ -330,9 +330,15 @@ void GameData::loadHandling(const std::string& path)
ss >> info.suspensionBias;
ss >> std::hex >> info.flags;
vehicleInfo.insert({info.ID, {info}});
auto mit = vehicleInfo.find(info.ID);
if(mit == vehicleInfo.end()) {
vehicleInfo.insert({info.ID,
VehicleInfoHandle(new VehicleInfo{info})});
}
else {
mit->second->handling = info;
}
}
}
void GameData::loadWaterpro(const std::string& path)

View File

@ -0,0 +1,18 @@
#include <engine/GameObject.hpp>
#include <loaders/LoaderIFP.hpp>
#include <loaders/LoaderDFF.hpp>
void GameObject::setPosition(const glm::vec3& pos)
{
position = pos;
}
glm::vec3 GameObject::getPosition() const
{
return position;
}
glm::quat GameObject::getRotation() const
{
return rotation;
}

View File

@ -239,20 +239,20 @@ GTAVehicle *GameWorld::createVehicle(const uint16_t id, const glm::vec3& pos, co
Model* model = gameData.models[vti->second->modelName];
auto info = gameData.vehicleInfo.find(vti->second->handlingID);
if(model && info != gameData.vehicleInfo.end()) {
if( info->second.wheels.size() == 0 && info->second.seats.size() == 0 ) {
if( info->second->wheels.size() == 0 && info->second->seats.size() == 0 ) {
for( const ModelFrame* f : model->frames ) {
const std::string& name = f->getName();
if( name.size() > 5 && name.substr(0, 5) == "wheel" ) {
auto frameTrans = f->getMatrix();
info->second.wheels.push_back({glm::vec3(frameTrans[3])});
info->second->wheels.push_back({glm::vec3(frameTrans[3])});
}
if(name.size() > 3 && name.substr(0, 3) == "ped" && name.substr(name.size()-4) == "seat") {
auto p = f->getDefaultTranslation();
p.x = p.x * -1.f;
info->second.seats.push_back({p});
info->second->seats.push_back({p});
p.x = p.x * -1.f;
info->second.seats.push_back({p});
info->second->seats.push_back({p});
}
}
}
@ -292,9 +292,9 @@ GTACharacter* GameWorld::createPedestrian(const uint16_t id, const glm::vec3 &po
return nullptr;
}
void GameWorld::destroyObject(GTAObject* object)
void GameWorld::destroyObject(GameObject* object)
{
if(object->type() == GTAObject::Character)
if(object->type() == GameObject::Character)
{
for(auto it = pedestrians.begin(); it != pedestrians.end(); ) {
if( *it == object ) {
@ -305,7 +305,7 @@ void GameWorld::destroyObject(GTAObject* object)
}
}
}
else if(object->type() == GTAObject::Vehicle)
else if(object->type() == GameObject::Vehicle)
{
for(auto it = vehicleInstances.begin(); it != vehicleInstances.end(); ) {
if( *it == object ) {
@ -316,7 +316,7 @@ void GameWorld::destroyObject(GTAObject* object)
}
}
}
else if(object->type() == GTAObject::Instance)
else if(object->type() == GameObject::Instance)
{
for(auto it = modelInstances.begin(); it != modelInstances.end(); ) {
if( it->second.get() == object ) {

View File

@ -92,7 +92,7 @@ bool LoaderIDE::load(const std::string &filename)
break;
}
case CARS: {
std::shared_ptr<CarData> cars(new CarData);
std::shared_ptr<VehicleData> cars(new VehicleData);
std::string id, type, classType, frequency, lvl,
comprules, wheelModelID, wheelScale;
@ -116,35 +116,35 @@ bool LoaderIDE::load(const std::string &filename)
cars->comprules = atoi(comprules.c_str());
if (type == "car") {
cars->type = CarData::CAR;
cars->type = VehicleData::CAR;
cars->wheelModelID = atoi(wheelModelID.c_str());
cars->wheelScale = atof(wheelScale.c_str());
} else if (type == "boat") {
cars->type = CarData::BOAT;
cars->type = VehicleData::BOAT;
} else if (type == "train") {
cars->type = CarData::TRAIN;
cars->type = VehicleData::TRAIN;
cars->modelLOD = atoi(wheelModelID.c_str());
} else if (type == "plane") {
cars->type = CarData::PLANE;
cars->type = VehicleData::PLANE;
} else if (type == "heli") {
cars->type = CarData::HELI;
cars->type = VehicleData::HELI;
}
const std::map<CarData::VehicleClass, std::string> classTypes{
{CarData::IGNORE, "ignore"},
{CarData::NORMAL, "normal"},
{CarData::POORFAMILY, "poorfamily"},
{CarData::RICHFAMILY, "richfamily"},
{CarData::EXECUTIVE, "executive"},
{CarData::WORKER, "worker"},
{CarData::BIG, "big"},
{CarData::TAXI, "taxi"},
{CarData::MOPED, "moped"},
{CarData::MOTORBIKE, "motorbike"},
{CarData::LEISUREBOAT, "leisureboat"},
{CarData::WORKERBOAT, "workerboat"},
{CarData::BICYCLE, "bicycle"},
{CarData::ONFOOT, "onfoot"},
const std::map<VehicleData::VehicleClass, std::string> classTypes{
{VehicleData::IGNORE, "ignore"},
{VehicleData::NORMAL, "normal"},
{VehicleData::POORFAMILY, "poorfamily"},
{VehicleData::RICHFAMILY, "richfamily"},
{VehicleData::EXECUTIVE, "executive"},
{VehicleData::WORKER, "worker"},
{VehicleData::BIG, "big"},
{VehicleData::TAXI, "taxi"},
{VehicleData::MOPED, "moped"},
{VehicleData::MOTORBIKE, "motorbike"},
{VehicleData::LEISUREBOAT, "leisureboat"},
{VehicleData::WORKERBOAT, "workerboat"},
{VehicleData::BICYCLE, "bicycle"},
{VehicleData::ONFOOT, "onfoot"},
};
for (auto &a : classTypes) {
if (classType == a.second) {

View File

@ -6,7 +6,7 @@
#include <boost/concept_check.hpp>
GTACharacter::GTACharacter(GameWorld* engine, const glm::vec3& pos, const glm::quat& rot, Model* model, std::shared_ptr<CharacterData> data)
: GTAObject(engine, pos, rot, model),
: GameObject(engine, pos, rot, model),
currentVehicle(nullptr), currentSeat(0), ped(data), physCharacter(nullptr),
controller(nullptr), currentActivity(None)
{
@ -149,7 +149,7 @@ void GTACharacter::updateCharacter()
auto otherObject = static_cast<const btCollisionObject*>(
manifold->getBody0() == physObject ? manifold->getBody1() : manifold->getBody0());
if(otherObject->getUserPointer()) {
GTAObject* object = static_cast<GTAObject*>(otherObject->getUserPointer());
GameObject* object = static_cast<GameObject*>(otherObject->getUserPointer());
if(object->type() == Vehicle) {
GTAVehicle* vehicle = static_cast<GTAVehicle*>(object);
if(vehicle->physBody->getLinearVelocity().length() > 0.1f) {
@ -248,7 +248,7 @@ void GTACharacter::setCurrentVehicle(GTAVehicle *value, size_t seat)
}
}
bool GTACharacter::takeDamage(const GTAObject::DamageInfo& dmg)
bool GTACharacter::takeDamage(const GameObject::DamageInfo& dmg)
{
mHealth -= dmg.hitpoints;
return true;

View File

@ -11,7 +11,7 @@ GTAInstance::GTAInstance(
std::shared_ptr<ObjectData> obj,
std::shared_ptr<GTAInstance> lod
)
: GTAObject(engine, pos, rot, model), scale(scale), object(obj), LODinstance(lod)
: GameObject(engine, pos, rot, model), scale(scale), object(obj), LODinstance(lod)
{
btRigidBody* body = nullptr;
auto phyit = engine->gameData.collisions.find(obj->modelName);
@ -78,7 +78,7 @@ GTAInstance::GTAInstance(
}
}
bool GTAInstance::takeDamage(const GTAObject::DamageInfo& dmg)
bool GTAInstance::takeDamage(const GameObject::DamageInfo& dmg)
{
bool explodeOnHit = (object->flags&ObjectData::EXPLODEONHIT) == ObjectData::EXPLODEONHIT;
bool smash = (object->flags&ObjectData::SMASHABLE) == ObjectData::SMASHABLE;

View File

@ -5,8 +5,8 @@
#include <sys/stat.h>
#include <data/CollisionModel.hpp>
GTAVehicle::GTAVehicle(GameWorld* engine, const glm::vec3& pos, const glm::quat& rot, Model* model, std::shared_ptr<CarData> data, const VehicleInfo& info, const glm::vec3& prim, const glm::vec3& sec)
: GTAObject(engine, pos, rot, model),
GTAVehicle::GTAVehicle(GameWorld* engine, const glm::vec3& pos, const glm::quat& rot, Model* model, VehicleDataHandle data, VehicleInfoHandle info, const glm::vec3& prim, const glm::vec3& sec)
: GameObject(engine, pos, rot, model),
steerAngle(0.f), throttle(0.f), brake(0.f), handbrake(false),
vehicle(data), info(info), colourPrimary(prim), colourSecondary(sec),
physBody(nullptr), physVehicle(nullptr)
@ -27,7 +27,7 @@ GTAVehicle::GTAVehicle(GameWorld* engine, const glm::vec3& pos, const glm::quat&
));
CollisionModel& physInst = *phyit->second.get();
btVector3 com(info.handling.centerOfMass.x, info.handling.centerOfMass.y, info.handling.centerOfMass.z);
btVector3 com(info->handling.centerOfMass.x, info->handling.centerOfMass.y, info->handling.centerOfMass.z);
// Boxes
for( size_t i = 0; i < physInst.boxes.size(); ++i ) {
@ -63,9 +63,9 @@ GTAVehicle::GTAVehicle(GameWorld* engine, const glm::vec3& pos, const glm::quat&
}
btVector3 inertia(0,0,0);
cmpShape->calculateLocalInertia(info.handling.mass, inertia);
cmpShape->calculateLocalInertia(info->handling.mass, inertia);
btRigidBody::btRigidBodyConstructionInfo rginfo(info.handling.mass, msta, cmpShape, inertia);
btRigidBody::btRigidBodyConstructionInfo rginfo(info->handling.mass, msta, cmpShape, inertia);
physBody = new btRigidBody(rginfo);
physBody->setUserPointer(this);
@ -74,7 +74,7 @@ GTAVehicle::GTAVehicle(GameWorld* engine, const glm::vec3& pos, const glm::quat&
physRaycaster = new btDefaultVehicleRaycaster(engine->dynamicsWorld);
btRaycastVehicle::btVehicleTuning tuning;
float travel = info.handling.suspensionUpperLimit - info.handling.suspensionLowerLimit;
float travel = info->handling.suspensionUpperLimit - info->handling.suspensionLowerLimit;
tuning.m_frictionSlip = 1.8f;
tuning.m_maxSuspensionTravelCm = travel * 100.f;
@ -86,15 +86,15 @@ GTAVehicle::GTAVehicle(GameWorld* engine, const glm::vec3& pos, const glm::quat&
float kC = 0.4f;
float kR = 0.6f;
for(size_t w = 0; w < info.wheels.size(); ++w) {
btVector3 connection(info.wheels[w].position.x, info.wheels[w].position.y, info.wheels[w].position.z - info.handling.suspensionLowerLimit);
for(size_t w = 0; w < info->wheels.size(); ++w) {
btVector3 connection(info->wheels[w].position.x, info->wheels[w].position.y, info->wheels[w].position.z - info->handling.suspensionLowerLimit);
bool front = connection.y() > 0;
btWheelInfo& wi = physVehicle->addWheel(connection + com, btVector3(0.f, 0.f, -1.f), btVector3(1.f, 0.f, 0.f), travel, data->wheelScale / 2.f, tuning, front);
wi.m_suspensionStiffness = info.handling.suspensionForce * 10.f;
wi.m_suspensionStiffness = info->handling.suspensionForce * 10.f;
wi.m_wheelsDampingCompression = kC * 2.f * btSqrt(wi.m_suspensionStiffness);
wi.m_wheelsDampingRelaxation = kR * 2.f * btSqrt(wi.m_suspensionStiffness);
wi.m_rollInfluence = 0.2f;
wi.m_frictionSlip = tuning.m_frictionSlip * (front ? info.handling.tractionBias : 1.f - info.handling.tractionBias);
wi.m_frictionSlip = tuning.m_frictionSlip * (front ? info->handling.tractionBias : 1.f - info->handling.tractionBias);
}
}
@ -114,7 +114,7 @@ GTAVehicle::~GTAVehicle()
void GTAVehicle::setPosition(const glm::vec3& pos)
{
GTAObject::setPosition(pos);
GameObject::setPosition(pos);
if(physBody) {
auto t = physBody->getWorldTransform();
t.setOrigin(btVector3(pos.x, pos.y, pos.z));
@ -126,7 +126,7 @@ glm::vec3 GTAVehicle::getPosition() const
{
if(physBody) {
btVector3 Pos = physBody->getWorldTransform().getOrigin();
return glm::vec3(Pos.x(), Pos.y(), Pos.z()) + info.handling.centerOfMass;
return glm::vec3(Pos.x(), Pos.y(), Pos.z()) + info->handling.centerOfMass;
}
return position;
}
@ -145,19 +145,19 @@ void GTAVehicle::tick(float dt)
if(physVehicle) {
for(size_t w = 0; w < physVehicle->getNumWheels(); ++w) {
btWheelInfo& wi = physVehicle->getWheelInfo(w);
if( info.handling.driveType == VehicleHandlingInfo::All ||
(info.handling.driveType == VehicleHandlingInfo::Forward && wi.m_bIsFrontWheel) ||
(info.handling.driveType == VehicleHandlingInfo::Rear && !wi.m_bIsFrontWheel))
if( info->handling.driveType == VehicleHandlingInfo::All ||
(info->handling.driveType == VehicleHandlingInfo::Forward && wi.m_bIsFrontWheel) ||
(info->handling.driveType == VehicleHandlingInfo::Rear && !wi.m_bIsFrontWheel))
{
physVehicle->applyEngineForce(info.handling.acceleration * 150.f * throttle, w);
physVehicle->applyEngineForce(info->handling.acceleration * 150.f * throttle, w);
}
float brakeReal = info.handling.brakeDeceleration * info.handling.mass * (wi.m_bIsFrontWheel? info.handling.brakeBias : 1.f - info.handling.brakeBias);
float brakeReal = info->handling.brakeDeceleration * info->handling.mass * (wi.m_bIsFrontWheel? info->handling.brakeBias : 1.f - info->handling.brakeBias);
physVehicle->setBrake(brakeReal * brake, w);
if(wi.m_bIsFrontWheel) {
float sign = std::signbit(steerAngle) ? -1.f : 1.f;
physVehicle->setSteeringValue(std::min(info.handling.steeringLock*(3.141f/180.f), std::abs(steerAngle)) * sign, w);
physVehicle->setSteeringValue(std::min(info->handling.steeringLock*(3.141f/180.f), std::abs(steerAngle)) * sign, w);
//physVehicle->setSteeringValue(std::min(3.141f/2.f, std::abs(steerAngle)) * sign, w);
}
}
@ -206,10 +206,10 @@ bool GTAVehicle::getHandbraking() const
void GTAVehicle::ejectAll()
{
for(std::map<size_t, GTAObject*>::iterator it = seatOccupants.begin();
for(std::map<size_t, GameObject*>::iterator it = seatOccupants.begin();
it != seatOccupants.end();
) {
if(it->second->type() == GTAObject::Character) {
if(it->second->type() == GameObject::Character) {
GTACharacter* c = static_cast<GTACharacter*>(it->second);
c->setCurrentVehicle(nullptr, 0);
c->setPosition(getPosition());
@ -218,7 +218,7 @@ void GTAVehicle::ejectAll()
}
}
GTAObject* GTAVehicle::getOccupant(size_t seat)
GameObject* GTAVehicle::getOccupant(size_t seat)
{
auto it = seatOccupants.find(seat);
if( it != seatOccupants.end() ) {
@ -227,7 +227,7 @@ GTAObject* GTAVehicle::getOccupant(size_t seat)
return nullptr;
}
void GTAVehicle::setOccupant(size_t seat, GTAObject* occupant)
void GTAVehicle::setOccupant(size_t seat, GameObject* occupant)
{
auto it = seatOccupants.find(seat);
if(occupant == nullptr) {
@ -242,7 +242,7 @@ void GTAVehicle::setOccupant(size_t seat, GTAObject* occupant)
}
}
bool GTAVehicle::takeDamage(const GTAObject::DamageInfo& dmg)
bool GTAVehicle::takeDamage(const GameObject::DamageInfo& dmg)
{
mHealth -= dmg.hitpoints;
return true;

View File

@ -268,8 +268,8 @@ void GTARenderer::renderWorld()
matrixModel = glm::translate(matrixModel,
v->getPosition());
matrixModel = matrixModel * glm::mat4_cast(v->getRotation());
if(charac->getCurrentSeat() < v->info.seats.size()) {
glm::vec3 seatpos = v->info.seats[charac->getCurrentSeat()].offset;
if(charac->getCurrentSeat() < v->info->seats.size()) {
glm::vec3 seatpos = v->info->seats[charac->getCurrentSeat()].offset;
matrixModel = glm::translate(matrixModel, seatpos);
}
}
@ -346,7 +346,7 @@ void GTARenderer::renderWorld()
renderModel(inst->model, matrixModel, inst);
// Draw wheels n' stuff
for( size_t w = 0; w < inst->info.wheels.size(); ++w) {
for( size_t w = 0; w < inst->info->wheels.size(); ++w) {
auto woi = engine->objectTypes.find(inst->vehicle->wheelModelID);
if(woi != engine->objectTypes.end()) {
Model* wheelModel = engine->gameData.models["wheels"];
@ -426,7 +426,7 @@ void GTARenderer::renderNamedFrame(Model* model, const glm::mat4 &matrix, const
}
}
void GTARenderer::renderGeometry(Model* model, size_t g, const glm::mat4& modelMatrix, GTAObject* object)
void GTARenderer::renderGeometry(Model* model, size_t g, const glm::mat4& modelMatrix, GameObject* object)
{
glUniformMatrix4fv(uniModel, 1, GL_FALSE, glm::value_ptr(modelMatrix));
glUniform4f(uniCol, 1.f, 1.f, 1.f, 1.f);
@ -442,7 +442,7 @@ void GTARenderer::renderGeometry(Model* model, size_t g, const glm::mat4& modelM
}
}
bool GTARenderer::renderFrame(Model* m, ModelFrame* f, const glm::mat4& matrix, GTAObject* object, bool queueTransparent)
bool GTARenderer::renderFrame(Model* m, ModelFrame* f, const glm::mat4& matrix, GameObject* object, bool queueTransparent)
{
auto localmatrix = matrix * f->getMatrix();
for(size_t g : f->getGeometries()) {
@ -451,7 +451,7 @@ bool GTARenderer::renderFrame(Model* m, ModelFrame* f, const glm::mat4& matrix,
continue;
}
if( object && object->type() == GTAObject::Vehicle ) {
if( object && object->type() == GameObject::Vehicle ) {
auto& name = f->getName();
if(name.size() > 3) {
if(name.substr(name.size()-3) == "dam"
@ -477,7 +477,7 @@ bool GTARenderer::renderFrame(Model* m, ModelFrame* f, const glm::mat4& matrix,
return true;
}
bool GTARenderer::renderSubgeometry(Model* model, size_t g, size_t sg, const glm::mat4& matrix, GTAObject* object, bool queueTransparent)
bool GTARenderer::renderSubgeometry(Model* model, size_t g, size_t sg, const glm::mat4& matrix, GameObject* object, bool queueTransparent)
{
glBindVertexArray(model->geometries[g]->dbuff.getVAOName());
@ -501,7 +501,7 @@ bool GTARenderer::renderSubgeometry(Model* model, size_t g, size_t sg, const glm
if( (model->geometries[g]->flags & RW::BSGeometry::ModuleMaterialColor) == RW::BSGeometry::ModuleMaterialColor) {
auto col = mat.colour;
if( object && object->type() == GTAObject::Vehicle ) {
if( object && object->type() == GameObject::Vehicle ) {
auto vehicle = static_cast<GTAVehicle*>(object);
if( (mat.flags&Model::MTF_PrimaryColour) != 0 ) {
glUniform4f(uniCol, vehicle->colourPrimary.r, vehicle->colourPrimary.g, vehicle->colourPrimary.b, 1.f);
@ -530,7 +530,7 @@ bool GTARenderer::renderSubgeometry(Model* model, size_t g, size_t sg, const glm
return true;
}
void GTARenderer::renderModel(Model* model, const glm::mat4& modelMatrix, GTAObject* object, Animator *animator)
void GTARenderer::renderModel(Model* model, const glm::mat4& modelMatrix, GameObject* object, Animator *animator)
{
renderFrame(model, model->frames[model->rootFrameIdx], modelMatrix, object);
}

View File

@ -37,7 +37,7 @@ GTAPlayerAIController* player = nullptr;
GTACharacter* playerCharacter = nullptr;
DebugDraw* debugDrawer = nullptr;
GTAObject* debugObject = nullptr;
GameObject* debugObject = nullptr;
glm::vec3 plyPos(87.f, -932.f, 58.f);
glm::vec2 plyLook;
@ -51,7 +51,7 @@ sf::Font font;
bool showControls = false;
bool hitWorldRay(glm::vec3& hit, glm::vec3& normal, GTAObject** object = nullptr)
bool hitWorldRay(glm::vec3& hit, glm::vec3& normal, GameObject** object = nullptr)
{
glm::mat4 view;
view = glm::rotate(view, -90.f, glm::vec3(1, 0, 0));
@ -69,7 +69,7 @@ bool hitWorldRay(glm::vec3& hit, glm::vec3& normal, GTAObject** object = nullptr
normal = glm::vec3(ray.m_hitNormalWorld.x(), ray.m_hitNormalWorld.y(),
ray.m_hitNormalWorld.z());
if(object) {
*object = static_cast<GTAObject*>(ray.m_collisionObject->getUserPointer());
*object = static_cast<GameObject*>(ray.m_collisionObject->getUserPointer());
}
return true;
}
@ -158,7 +158,7 @@ std::map<std::string, std::function<void (std::string)>> Commands = {
if(hitWorldRay(hit, normal)) {
glm::vec3 spawnPos = hit + glm::vec3(-5, 0.f, 0.0) + normal;
size_t k = 1;
for(std::map<uint16_t, std::shared_ptr<CarData>>::iterator it = gta->vehicleTypes.begin();
for(std::map<uint16_t, std::shared_ptr<VehicleData>>::iterator it = gta->vehicleTypes.begin();
it != gta->vehicleTypes.end(); ++it) {
if(it->first == 140) continue; // get this plane out of here.
gta->createVehicle(it->first, spawnPos);
@ -227,7 +227,7 @@ std::map<std::string, std::function<void (std::string)>> Commands = {
{"object-info",
[&](std::string) {
glm::vec3 hit, normal;
GTAObject* object;
GameObject* object;
if(hitWorldRay(hit, normal, &object)) {
debugObject = object;
}
@ -236,8 +236,8 @@ std::map<std::string, std::function<void (std::string)>> Commands = {
{"damage-object",
[&](std::string) {
if(debugObject) {
GTAObject::DamageInfo dmg;
dmg.type = GTAObject::DamageInfo::Bullet;
GameObject::DamageInfo dmg;
dmg.type = GameObject::DamageInfo::Bullet;
dmg.hitpoints = 15.f;
debugObject->takeDamage(dmg);
}
@ -590,9 +590,9 @@ void render()
}
}
}
if(debugObject->type() == GTAObject::Vehicle) {
if(debugObject->type() == GameObject::Vehicle) {
GTAVehicle* vehicle = static_cast<GTAVehicle*>(debugObject);
ss << "ID: " << vehicle->info.handling.ID << std::endl;
ss << "ID: " << vehicle->info->handling.ID << std::endl;
}
}

View File

@ -17,10 +17,19 @@ public:
glewExperimental = GL_TRUE;
glewInit();
e = new GameWorld("test_data");
e->gameData.loadIMG("/models/gta3");
e->load();
for(std::map<std::string, std::string>::iterator it = e->gameData.ideLocations.begin();
it != e->gameData.ideLocations.end();
++it) {
e->defineItems(it->second);
}
}
~Global() {
wnd.close();
delete e;
}
static Global& get()
@ -30,4 +39,4 @@ public:
}
};
#endif
#endif

View File

@ -15,8 +15,8 @@ BOOST_AUTO_TEST_CASE(instance_test_damage)
object,
nullptr
);
GTAObject::DamageInfo dmg;
dmg.type = GTAObject::DamageInfo::Bullet;
GameObject::DamageInfo dmg;
dmg.type = GameObject::DamageInfo::Bullet;
dmg.hitpoints = 50.f;
// Set object to undamagable.
@ -43,8 +43,8 @@ BOOST_AUTO_TEST_CASE(instance_test_destroy)
object,
nullptr
);
GTAObject::DamageInfo dmg;
dmg.type = GTAObject::DamageInfo::Bullet;
GameObject::DamageInfo dmg;
dmg.type = GameObject::DamageInfo::Bullet;
dmg.hitpoints = inst.mHealth + 1.f;
// Now make it damageable

25
tests/test_vehicle.cpp Normal file
View File

@ -0,0 +1,25 @@
#include <boost/test/unit_test.hpp>
#include "test_globals.hpp"
#include <objects/GTAVehicle.hpp>
BOOST_AUTO_TEST_SUITE(VehicleTests)
BOOST_AUTO_TEST_CASE(test_create_vehicle)
{
GTAVehicle* vehicle = Global::get().e->createVehicle(90u, glm::vec3(), glm::quat());
BOOST_REQUIRE(vehicle != nullptr);
BOOST_REQUIRE(vehicle->info != nullptr);
BOOST_REQUIRE(vehicle->vehicle != nullptr);
// Hardcoded values for the moment
BOOST_CHECK_EQUAL(vehicle->vehicle->type, VehicleData::CAR);
BOOST_CHECK_EQUAL(vehicle->info->wheels.size(), 4);
BOOST_CHECK_EQUAL(vehicle->info->seats.size(), 4);
}
BOOST_AUTO_TEST_SUITE_END()