mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-22 18:32:44 +01:00
clang-format files in rwengine/src/data
This commit is contained in:
parent
6444bca8db
commit
1e4d7ea133
@ -1,127 +1,106 @@
|
||||
#include "data/Chase.hpp"
|
||||
#include <fstream>
|
||||
#include <cstdint>
|
||||
#include <rw/defines.hpp>
|
||||
#include <objects/GameObject.hpp>
|
||||
#include <engine/GameWorld.hpp>
|
||||
#include <fstream>
|
||||
#include <objects/GameObject.hpp>
|
||||
#include <rw/defines.hpp>
|
||||
|
||||
#define KEYFRAMES_PER_SECOND 30
|
||||
|
||||
bool ChaseKeyframe::load(const std::string &filePath, std::vector<ChaseKeyframe> &frames)
|
||||
{
|
||||
std::ifstream chaseFile(filePath, std::ios_base::binary);
|
||||
RW_CHECK(chaseFile.is_open(), "Failed to open chase file");
|
||||
if (!chaseFile.is_open()) {
|
||||
return false;
|
||||
}
|
||||
bool ChaseKeyframe::load(const std::string &filePath,
|
||||
std::vector<ChaseKeyframe> &frames) {
|
||||
std::ifstream chaseFile(filePath, std::ios_base::binary);
|
||||
RW_CHECK(chaseFile.is_open(), "Failed to open chase file");
|
||||
if (!chaseFile.is_open()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
chaseFile.seekg(0, std::ios_base::end);
|
||||
size_t fileLength = chaseFile.tellg();
|
||||
chaseFile.seekg(0);
|
||||
chaseFile.seekg(0, std::ios_base::end);
|
||||
size_t fileLength = chaseFile.tellg();
|
||||
chaseFile.seekg(0);
|
||||
|
||||
struct ChaseEntryRecord {
|
||||
int16_t velocity[3];
|
||||
int8_t right[3];
|
||||
int8_t up[3];
|
||||
uint8_t steering;
|
||||
uint8_t driving;
|
||||
uint8_t braking;
|
||||
uint8_t handbrake;
|
||||
glm::vec3 position;
|
||||
};
|
||||
struct ChaseEntryRecord {
|
||||
int16_t velocity[3];
|
||||
int8_t right[3];
|
||||
int8_t up[3];
|
||||
uint8_t steering;
|
||||
uint8_t driving;
|
||||
uint8_t braking;
|
||||
uint8_t handbrake;
|
||||
glm::vec3 position;
|
||||
};
|
||||
|
||||
static_assert(sizeof(ChaseEntryRecord) == 28, "ChaseEntryRecord is not 28 bytes");
|
||||
RW_CHECK(fileLength % sizeof(ChaseEntryRecord) == 0, "File is not a mulitple of 28 byte");
|
||||
static_assert(sizeof(ChaseEntryRecord) == 28,
|
||||
"ChaseEntryRecord is not 28 bytes");
|
||||
RW_CHECK(fileLength % sizeof(ChaseEntryRecord) == 0,
|
||||
"File is not a mulitple of 28 byte");
|
||||
|
||||
size_t recordCount = fileLength / sizeof(ChaseEntryRecord);
|
||||
size_t recordCount = fileLength / sizeof(ChaseEntryRecord);
|
||||
|
||||
for (size_t i = 0; i < recordCount; ++i)
|
||||
{
|
||||
ChaseEntryRecord rec;
|
||||
chaseFile.read((char*)&rec, sizeof(ChaseEntryRecord));
|
||||
glm::vec3 velocity {
|
||||
rec.velocity[0]/16383.5f,
|
||||
rec.velocity[1]/16383.5f,
|
||||
rec.velocity[2]/16383.5f,
|
||||
};
|
||||
glm::vec3 right{
|
||||
rec.right[0]/127.5f,
|
||||
rec.right[1]/127.5f,
|
||||
rec.right[2]/127.5f,
|
||||
};
|
||||
glm::vec3 up{
|
||||
rec.up[0]/127.5f,
|
||||
rec.up[1]/127.5f,
|
||||
rec.up[2]/127.5f,
|
||||
};
|
||||
glm::mat3 rotation(right, up, glm::cross(right, up));
|
||||
frames.push_back({
|
||||
velocity,
|
||||
rec.steering,
|
||||
rec.driving,
|
||||
rec.braking,
|
||||
!!rec.handbrake,
|
||||
rec.position,
|
||||
glm::quat_cast(rotation)
|
||||
});
|
||||
}
|
||||
for (size_t i = 0; i < recordCount; ++i) {
|
||||
ChaseEntryRecord rec;
|
||||
chaseFile.read((char *)&rec, sizeof(ChaseEntryRecord));
|
||||
glm::vec3 velocity{
|
||||
rec.velocity[0] / 16383.5f, rec.velocity[1] / 16383.5f,
|
||||
rec.velocity[2] / 16383.5f,
|
||||
};
|
||||
glm::vec3 right{
|
||||
rec.right[0] / 127.5f, rec.right[1] / 127.5f, rec.right[2] / 127.5f,
|
||||
};
|
||||
glm::vec3 up{
|
||||
rec.up[0] / 127.5f, rec.up[1] / 127.5f, rec.up[2] / 127.5f,
|
||||
};
|
||||
glm::mat3 rotation(right, up, glm::cross(right, up));
|
||||
frames.push_back({velocity, rec.steering, rec.driving, rec.braking,
|
||||
!!rec.handbrake, rec.position,
|
||||
glm::quat_cast(rotation)});
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool ChaseCoordinator::addChaseVehicle(GameObject *vehicle, int index, const std::string &pathFile)
|
||||
{
|
||||
std::vector <ChaseKeyframe> keyframes;
|
||||
bool result = ChaseKeyframe::load(pathFile, keyframes);
|
||||
RW_CHECK(result, "Failed to load chase keyframes: " + pathFile);
|
||||
chaseVehicles[index] = {keyframes, vehicle};
|
||||
return result;
|
||||
bool ChaseCoordinator::addChaseVehicle(GameObject *vehicle, int index,
|
||||
const std::string &pathFile) {
|
||||
std::vector<ChaseKeyframe> keyframes;
|
||||
bool result = ChaseKeyframe::load(pathFile, keyframes);
|
||||
RW_CHECK(result, "Failed to load chase keyframes: " + pathFile);
|
||||
chaseVehicles[index] = {keyframes, vehicle};
|
||||
return result;
|
||||
}
|
||||
|
||||
GameObject*ChaseCoordinator::getChaseVehicle(int index)
|
||||
{
|
||||
return chaseVehicles.at(index).object;
|
||||
GameObject *ChaseCoordinator::getChaseVehicle(int index) {
|
||||
return chaseVehicles.at(index).object;
|
||||
}
|
||||
|
||||
void ChaseCoordinator::removeChaseVehicle(int index)
|
||||
{
|
||||
auto it = chaseVehicles.find(index);
|
||||
RW_CHECK(it != chaseVehicles.end(), "Vehicle not in chase");
|
||||
if (it != chaseVehicles.end())
|
||||
{
|
||||
chaseVehicles.erase(it);
|
||||
}
|
||||
void ChaseCoordinator::removeChaseVehicle(int index) {
|
||||
auto it = chaseVehicles.find(index);
|
||||
RW_CHECK(it != chaseVehicles.end(), "Vehicle not in chase");
|
||||
if (it != chaseVehicles.end()) {
|
||||
chaseVehicles.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
void ChaseCoordinator::start()
|
||||
{
|
||||
chaseTime = 0.f;
|
||||
void ChaseCoordinator::start() {
|
||||
chaseTime = 0.f;
|
||||
}
|
||||
|
||||
void ChaseCoordinator::update(float dt)
|
||||
{
|
||||
chaseTime += dt;
|
||||
size_t frameNum = chaseTime * KEYFRAMES_PER_SECOND;
|
||||
for(auto& it : chaseVehicles)
|
||||
{
|
||||
RW_CHECK(frameNum < it.second.keyframes.size(), "Vehicle out of chase keyframes");
|
||||
if (frameNum >= it.second.keyframes.size()) continue;
|
||||
void ChaseCoordinator::update(float dt) {
|
||||
chaseTime += dt;
|
||||
size_t frameNum = chaseTime * KEYFRAMES_PER_SECOND;
|
||||
for (auto &it : chaseVehicles) {
|
||||
RW_CHECK(frameNum < it.second.keyframes.size(),
|
||||
"Vehicle out of chase keyframes");
|
||||
if (frameNum >= it.second.keyframes.size()) continue;
|
||||
|
||||
const ChaseKeyframe& kf = it.second.keyframes[frameNum];
|
||||
it.second.object->setPosition(kf.position);
|
||||
it.second.object->setRotation(kf.rotation);
|
||||
}
|
||||
const ChaseKeyframe &kf = it.second.keyframes[frameNum];
|
||||
it.second.object->setPosition(kf.position);
|
||||
it.second.object->setRotation(kf.rotation);
|
||||
}
|
||||
}
|
||||
|
||||
void ChaseCoordinator::cleanup()
|
||||
{
|
||||
for(auto& it : chaseVehicles)
|
||||
{
|
||||
it.second.object->engine->destroyObject(it.second.object);
|
||||
}
|
||||
chaseVehicles.clear();
|
||||
void ChaseCoordinator::cleanup() {
|
||||
for (auto &it : chaseVehicles) {
|
||||
it.second.object->engine->destroyObject(it.second.object);
|
||||
}
|
||||
chaseVehicles.clear();
|
||||
}
|
||||
|
||||
|
@ -3,23 +3,23 @@
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
class GameObject;
|
||||
|
||||
struct ChaseKeyframe
|
||||
{
|
||||
glm::vec3 velocity;
|
||||
int steeringAngle;
|
||||
int acceleratorPower;
|
||||
int brakePower;
|
||||
bool handbrake;
|
||||
glm::vec3 position;
|
||||
glm::quat rotation;
|
||||
struct ChaseKeyframe {
|
||||
glm::vec3 velocity;
|
||||
int steeringAngle;
|
||||
int acceleratorPower;
|
||||
int brakePower;
|
||||
bool handbrake;
|
||||
glm::vec3 position;
|
||||
glm::quat rotation;
|
||||
|
||||
static bool load(const std::string& filePath, std::vector<ChaseKeyframe>& frames);
|
||||
static bool load(const std::string& filePath,
|
||||
std::vector<ChaseKeyframe>& frames);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -28,30 +28,29 @@ struct ChaseKeyframe
|
||||
* It reads in ChaseKeyframes for a set of objects, and replays them
|
||||
* over time.
|
||||
*/
|
||||
class ChaseCoordinator
|
||||
{
|
||||
class ChaseCoordinator {
|
||||
public:
|
||||
ChaseCoordinator() : chaseTime(-1.f) {
|
||||
}
|
||||
|
||||
ChaseCoordinator()
|
||||
: chaseTime(-1.f)
|
||||
{ }
|
||||
bool addChaseVehicle(GameObject* vehicle, int index,
|
||||
const std::string& pathFile);
|
||||
GameObject* getChaseVehicle(int index);
|
||||
void removeChaseVehicle(int index);
|
||||
|
||||
bool addChaseVehicle(GameObject* vehicle, int index, const std::string& pathFile);
|
||||
GameObject* getChaseVehicle(int index);
|
||||
void removeChaseVehicle(int index);
|
||||
void start();
|
||||
void update(float dt);
|
||||
|
||||
void start();
|
||||
void update(float dt);
|
||||
void cleanup();
|
||||
|
||||
void cleanup();
|
||||
private:
|
||||
float chaseTime;
|
||||
struct ChaseObject {
|
||||
std::vector<ChaseKeyframe> keyframes;
|
||||
GameObject* object;
|
||||
};
|
||||
float chaseTime;
|
||||
struct ChaseObject {
|
||||
std::vector<ChaseKeyframe> keyframes;
|
||||
GameObject* object;
|
||||
};
|
||||
|
||||
std::map<int, ChaseObject> chaseVehicles;
|
||||
std::map<int, ChaseObject> chaseVehicles;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,47 +1,44 @@
|
||||
#ifndef RWENGINE_COLLISIONMODEL_HPP
|
||||
#define RWENGINE_COLLISIONMODEL_HPP
|
||||
#include <cstdint>
|
||||
#include <glm/glm.hpp>
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
* @class CollisionModel
|
||||
* @class CollisionModel
|
||||
* Collision shapes data container.
|
||||
*/
|
||||
struct CollisionModel
|
||||
{
|
||||
/// @todo give shapes surface data
|
||||
struct Sphere
|
||||
{
|
||||
glm::vec3 center;
|
||||
float radius;
|
||||
};
|
||||
|
||||
struct Box
|
||||
{
|
||||
glm::vec3 min;
|
||||
glm::vec3 max;
|
||||
};
|
||||
|
||||
/// COL version
|
||||
int version;
|
||||
|
||||
/// Model name
|
||||
std::string name;
|
||||
uint16_t modelid;
|
||||
|
||||
// Bounding radius
|
||||
float radius;
|
||||
|
||||
glm::vec3 center;
|
||||
glm::vec3 min;
|
||||
glm::vec3 max;
|
||||
|
||||
std::vector<Sphere> spheres;
|
||||
std::vector<Box> boxes;
|
||||
std::vector<glm::vec3> vertices;
|
||||
std::vector<uint32_t> indices;
|
||||
struct CollisionModel {
|
||||
/// @todo give shapes surface data
|
||||
struct Sphere {
|
||||
glm::vec3 center;
|
||||
float radius;
|
||||
};
|
||||
|
||||
struct Box {
|
||||
glm::vec3 min;
|
||||
glm::vec3 max;
|
||||
};
|
||||
|
||||
/// COL version
|
||||
int version;
|
||||
|
||||
/// Model name
|
||||
std::string name;
|
||||
uint16_t modelid;
|
||||
|
||||
// Bounding radius
|
||||
float radius;
|
||||
|
||||
glm::vec3 center;
|
||||
glm::vec3 min;
|
||||
glm::vec3 max;
|
||||
|
||||
std::vector<Sphere> spheres;
|
||||
std::vector<Box> boxes;
|
||||
std::vector<glm::vec3> vertices;
|
||||
std::vector<uint32_t> indices;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -3,145 +3,139 @@
|
||||
#define _CUTSCENEDATA_HPP_
|
||||
#include <glm/glm.hpp>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
* @brief Stores data from .CUT files
|
||||
*/
|
||||
struct CutsceneMetadata
|
||||
{
|
||||
struct ModelEntry {
|
||||
std::string model;
|
||||
std::string animation;
|
||||
};
|
||||
struct TextEntry {
|
||||
float length;
|
||||
std::string gxt;
|
||||
};
|
||||
struct CutsceneMetadata {
|
||||
struct ModelEntry {
|
||||
std::string model;
|
||||
std::string animation;
|
||||
};
|
||||
struct TextEntry {
|
||||
float length;
|
||||
std::string gxt;
|
||||
};
|
||||
|
||||
std::string name;
|
||||
std::string name;
|
||||
|
||||
/// The origin for coordinates in the cutscene
|
||||
glm::vec3 sceneOffset;
|
||||
/// The origin for coordinates in the cutscene
|
||||
glm::vec3 sceneOffset;
|
||||
|
||||
std::vector<ModelEntry> models;
|
||||
std::map<float, TextEntry> texts;
|
||||
std::vector<ModelEntry> models;
|
||||
std::map<float, TextEntry> texts;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Stores the Camera animation data from .DAT files
|
||||
*/
|
||||
struct CutsceneTracks
|
||||
{
|
||||
std::map<float, float> zoom;
|
||||
std::map<float, float> rotation;
|
||||
std::map<float, glm::vec3> position;
|
||||
std::map<float, glm::vec3> target; /// Rotation is around the direction to this vector
|
||||
struct CutsceneTracks {
|
||||
std::map<float, float> zoom;
|
||||
std::map<float, float> rotation;
|
||||
std::map<float, glm::vec3> position;
|
||||
std::map<float, glm::vec3>
|
||||
target; /// Rotation is around the direction to this vector
|
||||
|
||||
float duration { 0.f };
|
||||
float duration{0.f};
|
||||
|
||||
glm::vec3 getPositionAt(float time)
|
||||
{
|
||||
glm::vec3 p = position.end()->second;
|
||||
for(auto it = position.begin(); it != position.end(); ++it) {
|
||||
if( it->first <= time ) {
|
||||
auto a = it->second;
|
||||
auto b = it->second;
|
||||
auto nextIt = it;
|
||||
float t = it->first;
|
||||
if( ++nextIt != position.end() ) {
|
||||
b = nextIt->second;
|
||||
t = nextIt->first;
|
||||
}
|
||||
float tdiff = t - it->first;
|
||||
p = b;
|
||||
if( tdiff > 0.f ) {
|
||||
float fac = (time - it->first) / tdiff;
|
||||
p = glm::mix(a, b, fac);
|
||||
}
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
glm::vec3 getPositionAt(float time) {
|
||||
glm::vec3 p = position.end()->second;
|
||||
for (auto it = position.begin(); it != position.end(); ++it) {
|
||||
if (it->first <= time) {
|
||||
auto a = it->second;
|
||||
auto b = it->second;
|
||||
auto nextIt = it;
|
||||
float t = it->first;
|
||||
if (++nextIt != position.end()) {
|
||||
b = nextIt->second;
|
||||
t = nextIt->first;
|
||||
}
|
||||
float tdiff = t - it->first;
|
||||
p = b;
|
||||
if (tdiff > 0.f) {
|
||||
float fac = (time - it->first) / tdiff;
|
||||
p = glm::mix(a, b, fac);
|
||||
}
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
glm::vec3 getTargetAt(float time)
|
||||
{
|
||||
glm::vec3 p = position.end()->second;
|
||||
for(auto it = target.begin(); it != target.end(); ++it) {
|
||||
if( it->first <= time ) {
|
||||
auto a = it->second;
|
||||
auto b = it->second;
|
||||
auto nextIt = it;
|
||||
float t = it->first;
|
||||
if( ++nextIt != target.end() ) {
|
||||
b = nextIt->second;
|
||||
t = nextIt->first;
|
||||
}
|
||||
float tdiff = t - it->first;
|
||||
p = b;
|
||||
if( tdiff > 0.f ) {
|
||||
float fac = (time - it->first) / tdiff;
|
||||
p = glm::mix(a, b, fac);
|
||||
}
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
glm::vec3 getTargetAt(float time) {
|
||||
glm::vec3 p = position.end()->second;
|
||||
for (auto it = target.begin(); it != target.end(); ++it) {
|
||||
if (it->first <= time) {
|
||||
auto a = it->second;
|
||||
auto b = it->second;
|
||||
auto nextIt = it;
|
||||
float t = it->first;
|
||||
if (++nextIt != target.end()) {
|
||||
b = nextIt->second;
|
||||
t = nextIt->first;
|
||||
}
|
||||
float tdiff = t - it->first;
|
||||
p = b;
|
||||
if (tdiff > 0.f) {
|
||||
float fac = (time - it->first) / tdiff;
|
||||
p = glm::mix(a, b, fac);
|
||||
}
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
float getZoomAt(float time)
|
||||
{
|
||||
float r = zoom.end()->second;
|
||||
for(auto it = zoom.begin(); it != zoom.end(); ++it) {
|
||||
if( it->first <= time ) {
|
||||
auto a = it->second;
|
||||
auto b = it->second;
|
||||
auto nextIt = it;
|
||||
float t = it->first;
|
||||
if( ++nextIt != zoom.end() ) {
|
||||
b = nextIt->second;
|
||||
t = nextIt->first;
|
||||
}
|
||||
float tdiff = t - it->first;
|
||||
r = b;
|
||||
if( tdiff > 0.f ) {
|
||||
float fac = (time - it->first) / tdiff;
|
||||
r = glm::mix(a, b, fac);
|
||||
}
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
float getZoomAt(float time) {
|
||||
float r = zoom.end()->second;
|
||||
for (auto it = zoom.begin(); it != zoom.end(); ++it) {
|
||||
if (it->first <= time) {
|
||||
auto a = it->second;
|
||||
auto b = it->second;
|
||||
auto nextIt = it;
|
||||
float t = it->first;
|
||||
if (++nextIt != zoom.end()) {
|
||||
b = nextIt->second;
|
||||
t = nextIt->first;
|
||||
}
|
||||
float tdiff = t - it->first;
|
||||
r = b;
|
||||
if (tdiff > 0.f) {
|
||||
float fac = (time - it->first) / tdiff;
|
||||
r = glm::mix(a, b, fac);
|
||||
}
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
float getRotationAt(float time)
|
||||
{
|
||||
float r = rotation.end()->second;
|
||||
for(auto it = rotation.begin(); it != rotation.end(); ++it) {
|
||||
if( it->first <= time ) {
|
||||
auto a = it->second;
|
||||
auto b = it->second;
|
||||
auto nextIt = it;
|
||||
float t = it->first;
|
||||
if( ++nextIt != rotation.end() ) {
|
||||
b = nextIt->second;
|
||||
t = nextIt->first;
|
||||
}
|
||||
float tdiff = t - it->first;
|
||||
r = b;
|
||||
if( tdiff > 0.f ) {
|
||||
float fac = (time - it->first) / tdiff;
|
||||
r = glm::mix(a, b, fac);
|
||||
}
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
float getRotationAt(float time) {
|
||||
float r = rotation.end()->second;
|
||||
for (auto it = rotation.begin(); it != rotation.end(); ++it) {
|
||||
if (it->first <= time) {
|
||||
auto a = it->second;
|
||||
auto b = it->second;
|
||||
auto nextIt = it;
|
||||
float t = it->first;
|
||||
if (++nextIt != rotation.end()) {
|
||||
b = nextIt->second;
|
||||
t = nextIt->first;
|
||||
}
|
||||
float tdiff = t - it->first;
|
||||
r = b;
|
||||
if (tdiff > 0.f) {
|
||||
float fac = (time - it->first) / tdiff;
|
||||
r = glm::mix(a, b, fac);
|
||||
}
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
struct CutsceneData
|
||||
{
|
||||
CutsceneMetadata meta;
|
||||
CutsceneTracks tracks;
|
||||
struct CutsceneData {
|
||||
CutsceneMetadata meta;
|
||||
CutsceneTracks tracks;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,10 +1,9 @@
|
||||
#include "GameTexts.hpp"
|
||||
|
||||
GameString GameStringUtil::fromString(const std::string& str)
|
||||
{
|
||||
GameString s;
|
||||
for (std::string::size_type i = 0u; i < str.size(); ++i) {
|
||||
s += str[i];
|
||||
}
|
||||
return s;
|
||||
GameString GameStringUtil::fromString(const std::string& str) {
|
||||
GameString s;
|
||||
for (std::string::size_type i = 0u; i < str.size(); ++i) {
|
||||
s += str[i];
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
@ -18,47 +18,45 @@ using GameString = std::basic_string<GameStringChar>;
|
||||
*/
|
||||
using GameStringKey = std::string;
|
||||
|
||||
namespace GameStringUtil
|
||||
{
|
||||
namespace GameStringUtil {
|
||||
/**
|
||||
* @brief fromString Converts a string to a GameString
|
||||
*
|
||||
* Encoding of GameStrings depends on the font, only simple ASCII chars will map well
|
||||
* Encoding of GameStrings depends on the font, only simple ASCII chars will map
|
||||
* well
|
||||
*/
|
||||
GameString fromString(const std::string& str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Since the encoding of symbols is arbitrary, these constants should be used in
|
||||
* hard-coded strings containing symbols outside of the ASCII-subset supported by
|
||||
* hard-coded strings containing symbols outside of the ASCII-subset supported
|
||||
* by
|
||||
* all fonts
|
||||
*/
|
||||
namespace GameSymbols
|
||||
{
|
||||
static constexpr GameStringChar Money = '$';
|
||||
static constexpr GameStringChar Heart = '{';
|
||||
static constexpr GameStringChar Armour = '[';
|
||||
static constexpr GameStringChar Star = ']';
|
||||
namespace GameSymbols {
|
||||
static constexpr GameStringChar Money = '$';
|
||||
static constexpr GameStringChar Heart = '{';
|
||||
static constexpr GameStringChar Armour = '[';
|
||||
static constexpr GameStringChar Star = ']';
|
||||
}
|
||||
|
||||
class GameTexts
|
||||
{
|
||||
using StringTable = std::unordered_map<GameStringKey, GameString>;
|
||||
StringTable m_strings;
|
||||
class GameTexts {
|
||||
using StringTable = std::unordered_map<GameStringKey, GameString>;
|
||||
StringTable m_strings;
|
||||
|
||||
public:
|
||||
void addText(const GameStringKey& id, GameString&& text) {
|
||||
m_strings.emplace(id, text);
|
||||
}
|
||||
|
||||
void addText(const GameStringKey& id, GameString&& text) {
|
||||
m_strings.emplace(id, text);
|
||||
}
|
||||
|
||||
GameString text(const GameStringKey& id) {
|
||||
auto a = m_strings.find(id);
|
||||
if( a != m_strings.end() ) {
|
||||
return a->second;
|
||||
}
|
||||
return GameStringUtil::fromString("MISSING: " + id);
|
||||
}
|
||||
|
||||
GameString text(const GameStringKey& id) {
|
||||
auto a = m_strings.find(id);
|
||||
if (a != m_strings.end()) {
|
||||
return a->second;
|
||||
}
|
||||
return GameStringUtil::fromString("MISSING: " + id);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,32 +1,31 @@
|
||||
#pragma once
|
||||
#ifndef __INSTANCEDATA_HPP__
|
||||
#define __INSTANCEDATA_HPP__
|
||||
#include <string>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <string>
|
||||
|
||||
struct InstanceData
|
||||
{
|
||||
/**
|
||||
* ID of the object this instance
|
||||
*/
|
||||
int id;
|
||||
/**
|
||||
* Model name
|
||||
*/
|
||||
std::string model;
|
||||
/**
|
||||
* Instance position
|
||||
*/
|
||||
glm::vec3 pos;
|
||||
/**
|
||||
* Instance scaleX
|
||||
*/
|
||||
glm::vec3 scale;
|
||||
/**
|
||||
* Instance rotation
|
||||
*/
|
||||
glm::quat rot;
|
||||
struct InstanceData {
|
||||
/**
|
||||
* ID of the object this instance
|
||||
*/
|
||||
int id;
|
||||
/**
|
||||
* Model name
|
||||
*/
|
||||
std::string model;
|
||||
/**
|
||||
* Instance position
|
||||
*/
|
||||
glm::vec3 pos;
|
||||
/**
|
||||
* Instance scaleX
|
||||
*/
|
||||
glm::vec3 scale;
|
||||
/**
|
||||
* Instance rotation
|
||||
*/
|
||||
glm::quat rot;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,6 +1,10 @@
|
||||
#include "data/ObjectData.hpp"
|
||||
|
||||
const ObjectInformation::ObjectClass ObjectData::class_id = ObjectInformation::_class("OBJS");
|
||||
const ObjectInformation::ObjectClass VehicleData::class_id = ObjectInformation::_class("CARS");
|
||||
const ObjectInformation::ObjectClass CharacterData::class_id = ObjectInformation::_class("PEDS");
|
||||
const ObjectInformation::ObjectClass CutsceneObjectData::class_id = ObjectInformation::_class("HIER");
|
||||
const ObjectInformation::ObjectClass ObjectData::class_id =
|
||||
ObjectInformation::_class("OBJS");
|
||||
const ObjectInformation::ObjectClass VehicleData::class_id =
|
||||
ObjectInformation::_class("CARS");
|
||||
const ObjectInformation::ObjectClass CharacterData::class_id =
|
||||
ObjectInformation::_class("PEDS");
|
||||
const ObjectInformation::ObjectClass CutsceneObjectData::class_id =
|
||||
ObjectInformation::_class("HIER");
|
||||
|
@ -2,10 +2,10 @@
|
||||
#ifndef __GLT_OBJECTDATA_HPP__
|
||||
#define __GLT_OBJECTDATA_HPP__
|
||||
#include <stdint.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <data/PathData.hpp>
|
||||
#ifdef RW_WINDOWS
|
||||
@ -17,21 +17,20 @@ typedef uint16_t ObjectID;
|
||||
/**
|
||||
* Stores basic information about an Object and it's real type.
|
||||
*/
|
||||
struct ObjectInformation
|
||||
{
|
||||
typedef size_t ObjectClass;
|
||||
static ObjectClass _class(const std::string& name)
|
||||
{
|
||||
return std::hash<std::string>()(name);
|
||||
}
|
||||
struct ObjectInformation {
|
||||
typedef size_t ObjectClass;
|
||||
static ObjectClass _class(const std::string& name) {
|
||||
return std::hash<std::string>()(name);
|
||||
}
|
||||
|
||||
ObjectID ID;
|
||||
const ObjectClass class_type;
|
||||
ObjectID ID;
|
||||
const ObjectClass class_type;
|
||||
|
||||
ObjectInformation(const ObjectClass type)
|
||||
: class_type(type) { }
|
||||
|
||||
virtual ~ObjectInformation() { }
|
||||
ObjectInformation(const ObjectClass type) : class_type(type) {
|
||||
}
|
||||
|
||||
virtual ~ObjectInformation() {
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<ObjectInformation> ObjectInformationPtr;
|
||||
@ -39,35 +38,48 @@ typedef std::shared_ptr<ObjectInformation> ObjectInformationPtr;
|
||||
/**
|
||||
* Data used by Normal Objects
|
||||
*/
|
||||
struct ObjectData : public ObjectInformation
|
||||
{
|
||||
static const ObjectClass class_id;
|
||||
struct ObjectData : public ObjectInformation {
|
||||
static const ObjectClass class_id;
|
||||
|
||||
ObjectData()
|
||||
: ObjectInformation(_class("OBJS")) { }
|
||||
ObjectData() : ObjectInformation(_class("OBJS")) {
|
||||
}
|
||||
|
||||
std::string modelName;
|
||||
std::string textureName;
|
||||
uint8_t numClumps;
|
||||
float drawDistance[3];
|
||||
int32_t flags;
|
||||
bool LOD;
|
||||
|
||||
short timeOn;
|
||||
short timeOff;
|
||||
std::string modelName;
|
||||
std::string textureName;
|
||||
uint8_t numClumps;
|
||||
float drawDistance[3];
|
||||
int32_t flags;
|
||||
bool LOD;
|
||||
|
||||
enum {
|
||||
NORMAL_CULL = 1, /// Cull model if player doesn't look at it. Ignored in GTA 3.
|
||||
DO_NOT_FADE = 1 << 1, /// Do not fade the object when it is being loaded into or out of view.
|
||||
DRAW_LAST = 1 << 2, /// Model is transparent. Render this object after all opaque objects, allowing transparencies of other objects to be visible through this object.
|
||||
ADDITIVE = 1 << 3, /// Render with additive blending. Previous flag must be enabled too.
|
||||
IS_SUBWAY = 1 << 4, /// Model is a tunnel, i.e. set the object as invisible unless the player enters cull zone flag 128. This flag works only with static models.
|
||||
IGNORE_LIGHTING = 1 << 5, /// Don't use static lighting, we want dynamic if it's possible.
|
||||
NO_ZBUFFER_WRITE = 1 << 6, /// Model is a shadow. Disable writing to z-buffer when rendering it, allowing transparencies of other objects, shadows, and lights to be visible through this object. (Not implemented in the PS2 version)
|
||||
};
|
||||
short timeOn;
|
||||
short timeOff;
|
||||
|
||||
// Information loaded from PATH sections
|
||||
std::vector<PathData> paths;
|
||||
enum {
|
||||
NORMAL_CULL =
|
||||
1, /// Cull model if player doesn't look at it. Ignored in GTA 3.
|
||||
DO_NOT_FADE = 1 << 1, /// Do not fade the object when it is being
|
||||
/// loaded into or out of view.
|
||||
DRAW_LAST = 1 << 2, /// Model is transparent. Render this object after
|
||||
/// all opaque objects, allowing transparencies of
|
||||
/// other objects to be visible through this
|
||||
/// object.
|
||||
ADDITIVE = 1 << 3, /// Render with additive blending. Previous flag
|
||||
/// must be enabled too.
|
||||
IS_SUBWAY = 1 << 4, /// Model is a tunnel, i.e. set the object as
|
||||
/// invisible unless the player enters cull zone
|
||||
/// flag 128. This flag works only with static
|
||||
/// models.
|
||||
IGNORE_LIGHTING = 1 << 5, /// Don't use static lighting, we want
|
||||
/// dynamic if it's possible.
|
||||
NO_ZBUFFER_WRITE =
|
||||
1 << 6, /// Model is a shadow. Disable writing to z-buffer when
|
||||
/// rendering it, allowing transparencies of other objects,
|
||||
/// shadows, and lights to be visible through this object.
|
||||
/// (Not implemented in the PS2 version)
|
||||
};
|
||||
|
||||
// Information loaded from PATH sections
|
||||
std::vector<PathData> paths;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<ObjectData> ObjectDataPtr;
|
||||
@ -75,116 +87,110 @@ typedef std::shared_ptr<ObjectData> ObjectDataPtr;
|
||||
/**
|
||||
* Data used by peds
|
||||
*/
|
||||
struct CharacterData : public ObjectInformation
|
||||
{
|
||||
static const ObjectClass class_id;
|
||||
struct CharacterData : public ObjectInformation {
|
||||
static const ObjectClass class_id;
|
||||
|
||||
CharacterData()
|
||||
: ObjectInformation(_class("PEDS")) { }
|
||||
CharacterData() : ObjectInformation(_class("PEDS")) {
|
||||
}
|
||||
|
||||
std::string modelName;
|
||||
std::string textureName;
|
||||
std::string type;
|
||||
std::string behaviour;
|
||||
std::string animGroup;
|
||||
uint8_t driveMask;
|
||||
std::string modelName;
|
||||
std::string textureName;
|
||||
std::string type;
|
||||
std::string behaviour;
|
||||
std::string animGroup;
|
||||
uint8_t driveMask;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Stores vehicle data loaded from item definition files.
|
||||
*/
|
||||
struct VehicleData : public ObjectInformation
|
||||
{
|
||||
static const ObjectClass class_id;
|
||||
struct VehicleData : public ObjectInformation {
|
||||
static const ObjectClass class_id;
|
||||
|
||||
VehicleData()
|
||||
: ObjectInformation(_class("CARS")) { }
|
||||
|
||||
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,
|
||||
};
|
||||
VehicleData() : ObjectInformation(_class("CARS")) {
|
||||
}
|
||||
|
||||
enum VehicleType {
|
||||
CAR,
|
||||
BOAT,
|
||||
TRAIN,
|
||||
PLANE,
|
||||
HELI,
|
||||
};
|
||||
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,
|
||||
};
|
||||
|
||||
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
|
||||
enum VehicleType {
|
||||
CAR,
|
||||
BOAT,
|
||||
TRAIN,
|
||||
PLANE,
|
||||
HELI,
|
||||
};
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<VehicleData> VehicleDataHandle;
|
||||
|
||||
struct CutsceneObjectData : public ObjectInformation
|
||||
{
|
||||
static const ObjectClass class_id;
|
||||
struct CutsceneObjectData : public ObjectInformation {
|
||||
static const ObjectClass class_id;
|
||||
|
||||
CutsceneObjectData()
|
||||
: ObjectInformation(_class("HIER")) { }
|
||||
CutsceneObjectData() : ObjectInformation(_class("HIER")) {
|
||||
}
|
||||
|
||||
std::string modelName;
|
||||
std::string textureName;
|
||||
std::string modelName;
|
||||
std::string textureName;
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* 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;
|
||||
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
|
||||
|
@ -1,41 +1,33 @@
|
||||
#pragma once
|
||||
#ifndef __GLT_PATHDATA_HPP__
|
||||
#define __GLT_PATHDATA_HPP__
|
||||
#include <stdint.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
struct PathNode
|
||||
{
|
||||
enum NodeType
|
||||
{
|
||||
EMPTY = 0, /// These are ignored
|
||||
EXTERNAL = 1, /// May join with other paths
|
||||
INTERNAL = 2 /// Internal to this path
|
||||
};
|
||||
struct PathNode {
|
||||
enum NodeType {
|
||||
EMPTY = 0, /// These are ignored
|
||||
EXTERNAL = 1, /// May join with other paths
|
||||
INTERNAL = 2 /// Internal to this path
|
||||
};
|
||||
|
||||
NodeType type;
|
||||
int32_t next;
|
||||
glm::vec3 position;
|
||||
float size;
|
||||
int other_thing;
|
||||
int other_thing2;
|
||||
NodeType type;
|
||||
int32_t next;
|
||||
glm::vec3 position;
|
||||
float size;
|
||||
int other_thing;
|
||||
int other_thing2;
|
||||
};
|
||||
|
||||
struct PathData
|
||||
{
|
||||
enum PathType
|
||||
{
|
||||
PATH_PED,
|
||||
PATH_CAR
|
||||
};
|
||||
struct PathData {
|
||||
enum PathType { PATH_PED, PATH_CAR };
|
||||
|
||||
PathType type;
|
||||
uint16_t ID;
|
||||
std::string modelName;
|
||||
std::vector<PathNode> nodes;
|
||||
PathType type;
|
||||
uint16_t ID;
|
||||
std::string modelName;
|
||||
std::vector<PathNode> nodes;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -1,123 +1,100 @@
|
||||
#include <data/Skeleton.hpp>
|
||||
#include <data/Model.hpp>
|
||||
#include <data/Skeleton.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
Skeleton::FrameTransform Skeleton::IdentityTransform = { glm::vec3(0.f), glm::quat() };
|
||||
Skeleton::FrameData Skeleton::IdentityData = { Skeleton::IdentityTransform, Skeleton::IdentityTransform, true };
|
||||
Skeleton::FrameTransform Skeleton::IdentityTransform = {glm::vec3(0.f),
|
||||
glm::quat()};
|
||||
Skeleton::FrameData Skeleton::IdentityData = {
|
||||
Skeleton::IdentityTransform, Skeleton::IdentityTransform, true};
|
||||
|
||||
Skeleton::Skeleton()
|
||||
{
|
||||
|
||||
Skeleton::Skeleton() {
|
||||
}
|
||||
|
||||
void Skeleton::setAllData(const Skeleton::FramesData& data)
|
||||
{
|
||||
framedata = data;
|
||||
void Skeleton::setAllData(const Skeleton::FramesData& data) {
|
||||
framedata = data;
|
||||
}
|
||||
|
||||
const Skeleton::FrameData& Skeleton::getData(unsigned int frameIdx) const
|
||||
{
|
||||
auto fdit = framedata.find(frameIdx);
|
||||
if( fdit == framedata.end() )
|
||||
{
|
||||
return Skeleton::IdentityData;
|
||||
}
|
||||
|
||||
return fdit->second;
|
||||
const Skeleton::FrameData& Skeleton::getData(unsigned int frameIdx) const {
|
||||
auto fdit = framedata.find(frameIdx);
|
||||
if (fdit == framedata.end()) {
|
||||
return Skeleton::IdentityData;
|
||||
}
|
||||
|
||||
return fdit->second;
|
||||
}
|
||||
|
||||
void Skeleton::setData(unsigned int frameIdx, const Skeleton::FrameData& data)
|
||||
{
|
||||
framedata[frameIdx] = data;
|
||||
void Skeleton::setData(unsigned int frameIdx, const Skeleton::FrameData& data) {
|
||||
framedata[frameIdx] = data;
|
||||
}
|
||||
|
||||
void Skeleton::setEnabled(ModelFrame* frame, bool enabled)
|
||||
{
|
||||
auto fdit = framedata.find(frame->getIndex());
|
||||
if( fdit != framedata.end() )
|
||||
{
|
||||
fdit->second.enabled = enabled;
|
||||
}
|
||||
else
|
||||
{
|
||||
FrameTransform tf { frame->getDefaultTranslation(), glm::quat_cast(frame->getDefaultRotation()) };
|
||||
framedata.insert(
|
||||
{frame->getIndex(),
|
||||
{ tf, tf, enabled }
|
||||
}
|
||||
);
|
||||
}
|
||||
void Skeleton::setEnabled(ModelFrame* frame, bool enabled) {
|
||||
auto fdit = framedata.find(frame->getIndex());
|
||||
if (fdit != framedata.end()) {
|
||||
fdit->second.enabled = enabled;
|
||||
} else {
|
||||
FrameTransform tf{frame->getDefaultTranslation(),
|
||||
glm::quat_cast(frame->getDefaultRotation())};
|
||||
framedata.insert({frame->getIndex(), {tf, tf, enabled}});
|
||||
}
|
||||
}
|
||||
|
||||
void Skeleton::setEnabled(unsigned int frameIdx, bool enabled)
|
||||
{
|
||||
auto fdit = framedata.find(frameIdx);
|
||||
if( fdit == framedata.end() )
|
||||
{
|
||||
framedata.insert(
|
||||
{ frameIdx, { Skeleton::IdentityTransform, Skeleton::IdentityTransform, enabled } }
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
fdit->second.enabled = enabled;
|
||||
}
|
||||
void Skeleton::setEnabled(unsigned int frameIdx, bool enabled) {
|
||||
auto fdit = framedata.find(frameIdx);
|
||||
if (fdit == framedata.end()) {
|
||||
framedata.insert({frameIdx,
|
||||
{Skeleton::IdentityTransform,
|
||||
Skeleton::IdentityTransform, enabled}});
|
||||
} else {
|
||||
fdit->second.enabled = enabled;
|
||||
}
|
||||
}
|
||||
|
||||
const Skeleton::FrameTransform& Skeleton::getInterpolated(unsigned int frameIdx) const
|
||||
{
|
||||
auto itit = interpolateddata.find(frameIdx);
|
||||
if( itit == interpolateddata.end() )
|
||||
{
|
||||
return Skeleton::IdentityTransform;
|
||||
}
|
||||
|
||||
return itit->second;
|
||||
const Skeleton::FrameTransform& Skeleton::getInterpolated(
|
||||
unsigned int frameIdx) const {
|
||||
auto itit = interpolateddata.find(frameIdx);
|
||||
if (itit == interpolateddata.end()) {
|
||||
return Skeleton::IdentityTransform;
|
||||
}
|
||||
|
||||
return itit->second;
|
||||
}
|
||||
|
||||
void Skeleton::interpolate(float alpha)
|
||||
{
|
||||
interpolateddata.clear();
|
||||
|
||||
for(auto i = framedata.begin(); i != framedata.end(); ++i)
|
||||
{
|
||||
auto& t2 = i->second.a.translation;
|
||||
auto& t1 = i->second.b.translation;
|
||||
|
||||
auto& r2 = i->second.a.rotation;
|
||||
auto& r1 = i->second.b.rotation;
|
||||
|
||||
interpolateddata.insert({
|
||||
i->first,
|
||||
{ glm::mix(t1, t2, alpha), glm::slerp(r1, r2, alpha) }
|
||||
});
|
||||
}
|
||||
void Skeleton::interpolate(float alpha) {
|
||||
interpolateddata.clear();
|
||||
|
||||
for (auto i = framedata.begin(); i != framedata.end(); ++i) {
|
||||
auto& t2 = i->second.a.translation;
|
||||
auto& t1 = i->second.b.translation;
|
||||
|
||||
auto& r2 = i->second.a.rotation;
|
||||
auto& r1 = i->second.b.rotation;
|
||||
|
||||
interpolateddata.insert(
|
||||
{i->first, {glm::mix(t1, t2, alpha), glm::slerp(r1, r2, alpha)}});
|
||||
}
|
||||
}
|
||||
|
||||
glm::mat4 Skeleton::getMatrix(unsigned int frameIdx) const
|
||||
{
|
||||
const FrameTransform& ft = getInterpolated(frameIdx);
|
||||
|
||||
glm::mat4 m;
|
||||
|
||||
m = glm::translate( m, ft.translation );
|
||||
m = m * glm::mat4_cast( ft.rotation );
|
||||
|
||||
return m;
|
||||
glm::mat4 Skeleton::getMatrix(unsigned int frameIdx) const {
|
||||
const FrameTransform& ft = getInterpolated(frameIdx);
|
||||
|
||||
glm::mat4 m;
|
||||
|
||||
m = glm::translate(m, ft.translation);
|
||||
m = m * glm::mat4_cast(ft.rotation);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
glm::mat4 Skeleton::getMatrix(ModelFrame* frame) const
|
||||
{
|
||||
auto itit = interpolateddata.find(frame->getIndex());
|
||||
if( itit != interpolateddata.end() )
|
||||
{
|
||||
glm::mat4 m;
|
||||
|
||||
m = glm::translate( m, itit->second.translation );
|
||||
m = m * glm::mat4_cast( itit->second.rotation );
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
return frame->getTransform();
|
||||
glm::mat4 Skeleton::getMatrix(ModelFrame* frame) const {
|
||||
auto itit = interpolateddata.find(frame->getIndex());
|
||||
if (itit != interpolateddata.end()) {
|
||||
glm::mat4 m;
|
||||
|
||||
m = glm::translate(m, itit->second.translation);
|
||||
m = m * glm::mat4_cast(itit->second.rotation);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
return frame->getTransform();
|
||||
}
|
||||
|
@ -9,56 +9,51 @@
|
||||
class ModelFrame;
|
||||
/**
|
||||
* Data class for additional frame transformation and meta data.
|
||||
*
|
||||
*
|
||||
* Provides interfaces to modify and query the visibility of model frames,
|
||||
* as well as their transformation. Modified by Animator to animate models.
|
||||
*/
|
||||
class Skeleton
|
||||
{
|
||||
class Skeleton {
|
||||
public:
|
||||
struct FrameTransform
|
||||
{
|
||||
glm::vec3 translation;
|
||||
glm::quat rotation;
|
||||
};
|
||||
|
||||
static FrameTransform IdentityTransform;
|
||||
|
||||
struct FrameData
|
||||
{
|
||||
FrameTransform a;
|
||||
FrameTransform b;
|
||||
bool enabled;
|
||||
};
|
||||
|
||||
static FrameData IdentityData;
|
||||
|
||||
typedef std::map<unsigned int, FrameData> FramesData;
|
||||
typedef std::map<unsigned int, FrameTransform> TransformData;
|
||||
|
||||
Skeleton();
|
||||
|
||||
void setAllData(const FramesData& data);
|
||||
|
||||
const FrameData& getData(unsigned int frameIdx) const;
|
||||
|
||||
void setData(unsigned int frameIdx, const FrameData& data);
|
||||
void setEnabled(ModelFrame* frame, bool enabled);
|
||||
|
||||
void setEnabled(unsigned int frameIdx, bool enabled);
|
||||
|
||||
const FrameTransform& getInterpolated(unsigned int frameIdx) const;
|
||||
|
||||
glm::mat4 getMatrix(unsigned int frameIdx) const;
|
||||
glm::mat4 getMatrix(ModelFrame* frame) const;
|
||||
|
||||
void interpolate(float alpha);
|
||||
|
||||
struct FrameTransform {
|
||||
glm::vec3 translation;
|
||||
glm::quat rotation;
|
||||
};
|
||||
|
||||
static FrameTransform IdentityTransform;
|
||||
|
||||
struct FrameData {
|
||||
FrameTransform a;
|
||||
FrameTransform b;
|
||||
bool enabled;
|
||||
};
|
||||
|
||||
static FrameData IdentityData;
|
||||
|
||||
typedef std::map<unsigned int, FrameData> FramesData;
|
||||
typedef std::map<unsigned int, FrameTransform> TransformData;
|
||||
|
||||
Skeleton();
|
||||
|
||||
void setAllData(const FramesData& data);
|
||||
|
||||
const FrameData& getData(unsigned int frameIdx) const;
|
||||
|
||||
void setData(unsigned int frameIdx, const FrameData& data);
|
||||
void setEnabled(ModelFrame* frame, bool enabled);
|
||||
|
||||
void setEnabled(unsigned int frameIdx, bool enabled);
|
||||
|
||||
const FrameTransform& getInterpolated(unsigned int frameIdx) const;
|
||||
|
||||
glm::mat4 getMatrix(unsigned int frameIdx) const;
|
||||
glm::mat4 getMatrix(ModelFrame* frame) const;
|
||||
|
||||
void interpolate(float alpha);
|
||||
|
||||
private:
|
||||
|
||||
FramesData framedata;
|
||||
TransformData interpolateddata;
|
||||
|
||||
FramesData framedata;
|
||||
TransformData interpolateddata;
|
||||
};
|
||||
|
||||
#endif
|
@ -5,67 +5,57 @@
|
||||
/**
|
||||
* Stores information about where the game can generate vehicles.
|
||||
*/
|
||||
struct VehicleGenerator
|
||||
{
|
||||
/// Script reference ID
|
||||
size_t generatorID;
|
||||
glm::vec3 position;
|
||||
float heading;
|
||||
/// ID of the vehicle to spawn, or -1 for random.
|
||||
int vehicleID;
|
||||
/// @todo not yet used
|
||||
int colourFG;
|
||||
/// @todo not yet used
|
||||
int colourBG;
|
||||
bool alwaysSpawn;
|
||||
/// @todo not yet used
|
||||
short alarmThreshold;
|
||||
/// @todo not yet used
|
||||
short lockedThreshold;
|
||||
struct VehicleGenerator {
|
||||
/// Script reference ID
|
||||
size_t generatorID;
|
||||
glm::vec3 position;
|
||||
float heading;
|
||||
/// ID of the vehicle to spawn, or -1 for random.
|
||||
int vehicleID;
|
||||
/// @todo not yet used
|
||||
int colourFG;
|
||||
/// @todo not yet used
|
||||
int colourBG;
|
||||
bool alwaysSpawn;
|
||||
/// @todo not yet used
|
||||
short alarmThreshold;
|
||||
/// @todo not yet used
|
||||
short lockedThreshold;
|
||||
|
||||
int minDelay;
|
||||
/// @todo not yet used
|
||||
int maxDelay;
|
||||
int lastSpawnTime;
|
||||
int minDelay;
|
||||
/// @todo not yet used
|
||||
int maxDelay;
|
||||
int lastSpawnTime;
|
||||
|
||||
/**
|
||||
* Number of vehicles left to spawn 0-100, 101 = never decrement.
|
||||
* Intentionally disabled to match behaviour
|
||||
*/
|
||||
int remainingSpawns;
|
||||
/**
|
||||
* Number of vehicles left to spawn 0-100, 101 = never decrement.
|
||||
* Intentionally disabled to match behaviour
|
||||
*/
|
||||
int remainingSpawns;
|
||||
|
||||
VehicleGenerator(size_t id,
|
||||
const glm::vec3& position_,
|
||||
float heading_,
|
||||
int modelID_,
|
||||
int colourFG_,
|
||||
int colourBG_,
|
||||
bool alwaysSpawn_,
|
||||
short alarmThreshold_,
|
||||
short lockedThreshold_,
|
||||
int minDelay_,
|
||||
int maxDelay_,
|
||||
int lastSpawnTime_,
|
||||
int remainingSpawns_)
|
||||
: generatorID(id)
|
||||
, position(position_)
|
||||
, heading(heading_)
|
||||
, vehicleID(modelID_)
|
||||
, colourFG(colourFG_)
|
||||
, colourBG(colourBG_)
|
||||
, alwaysSpawn(alwaysSpawn_)
|
||||
, alarmThreshold(alarmThreshold_)
|
||||
, lockedThreshold(lockedThreshold_)
|
||||
, minDelay(minDelay_)
|
||||
, maxDelay(maxDelay_)
|
||||
, lastSpawnTime(lastSpawnTime_)
|
||||
, remainingSpawns(remainingSpawns_)
|
||||
{}
|
||||
VehicleGenerator(size_t id, const glm::vec3& position_, float heading_,
|
||||
int modelID_, int colourFG_, int colourBG_,
|
||||
bool alwaysSpawn_, short alarmThreshold_,
|
||||
short lockedThreshold_, int minDelay_, int maxDelay_,
|
||||
int lastSpawnTime_, int remainingSpawns_)
|
||||
: generatorID(id)
|
||||
, position(position_)
|
||||
, heading(heading_)
|
||||
, vehicleID(modelID_)
|
||||
, colourFG(colourFG_)
|
||||
, colourBG(colourBG_)
|
||||
, alwaysSpawn(alwaysSpawn_)
|
||||
, alarmThreshold(alarmThreshold_)
|
||||
, lockedThreshold(lockedThreshold_)
|
||||
, minDelay(minDelay_)
|
||||
, maxDelay(maxDelay_)
|
||||
, lastSpawnTime(lastSpawnTime_)
|
||||
, remainingSpawns(remainingSpawns_) {
|
||||
}
|
||||
|
||||
int getScriptObjectID() const
|
||||
{
|
||||
return generatorID;
|
||||
}
|
||||
int getScriptObjectID() const {
|
||||
return generatorID;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,43 +1,38 @@
|
||||
#pragma once
|
||||
#ifndef _WEAPONDATA_HPP_
|
||||
#define _WEAPONDATA_HPP_
|
||||
#include <string>
|
||||
#include <glm/glm.hpp>
|
||||
#include <cinttypes>
|
||||
#include <glm/glm.hpp>
|
||||
#include <string>
|
||||
|
||||
struct WeaponData
|
||||
{
|
||||
enum FireType {
|
||||
MELEE,
|
||||
INSTANT_HIT,
|
||||
PROJECTILE
|
||||
};
|
||||
struct WeaponData {
|
||||
enum FireType { MELEE, INSTANT_HIT, PROJECTILE };
|
||||
|
||||
std::string name;
|
||||
FireType fireType;
|
||||
float hitRange;
|
||||
int fireRate;
|
||||
int reloadMS;
|
||||
int clipSize;
|
||||
int damage;
|
||||
float speed;
|
||||
float meleeRadius;
|
||||
float lifeSpan;
|
||||
float spread;
|
||||
glm::vec3 fireOffset;
|
||||
std::string animation1;
|
||||
std::string animation2;
|
||||
float animLoopStart;
|
||||
float animLoopEnd;
|
||||
float animFirePoint; /* Must be between 2 ^ */
|
||||
float animCrouchLoopStart;
|
||||
float animCrouchLoopEnd;
|
||||
float animCrouchFirePoint;
|
||||
float breakoutAnim;
|
||||
int modelID;
|
||||
std::uint32_t flags;
|
||||
std::string name;
|
||||
FireType fireType;
|
||||
float hitRange;
|
||||
int fireRate;
|
||||
int reloadMS;
|
||||
int clipSize;
|
||||
int damage;
|
||||
float speed;
|
||||
float meleeRadius;
|
||||
float lifeSpan;
|
||||
float spread;
|
||||
glm::vec3 fireOffset;
|
||||
std::string animation1;
|
||||
std::string animation2;
|
||||
float animLoopStart;
|
||||
float animLoopEnd;
|
||||
float animFirePoint; /* Must be between 2 ^ */
|
||||
float animCrouchLoopStart;
|
||||
float animCrouchLoopEnd;
|
||||
float animCrouchFirePoint;
|
||||
float breakoutAnim;
|
||||
int modelID;
|
||||
std::uint32_t flags;
|
||||
|
||||
int inventorySlot;
|
||||
int inventorySlot;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -45,35 +40,44 @@ struct WeaponData
|
||||
*
|
||||
* @todo RADIUS hitscans
|
||||
*/
|
||||
struct WeaponScan
|
||||
{
|
||||
enum ScanType {
|
||||
/** Instant-hit ray weapons */
|
||||
HITSCAN,
|
||||
/** Area of effect attack */
|
||||
RADIUS,
|
||||
};
|
||||
struct WeaponScan {
|
||||
enum ScanType {
|
||||
/** Instant-hit ray weapons */
|
||||
HITSCAN,
|
||||
/** Area of effect attack */
|
||||
RADIUS,
|
||||
};
|
||||
|
||||
const ScanType type;
|
||||
const ScanType type;
|
||||
|
||||
float damage;
|
||||
float damage;
|
||||
|
||||
glm::vec3 center;
|
||||
float radius;
|
||||
glm::vec3 center;
|
||||
float radius;
|
||||
|
||||
glm::vec3 end;
|
||||
glm::vec3 end;
|
||||
|
||||
WeaponData* weapon;
|
||||
WeaponData* weapon;
|
||||
|
||||
// Constructor for a RADIUS hitscan
|
||||
WeaponScan( float damage, const glm::vec3& center, float radius, WeaponData* weapon = nullptr )
|
||||
: type(RADIUS), damage(damage), center(center), radius(radius), weapon(weapon)
|
||||
{}
|
||||
// Constructor for a RADIUS hitscan
|
||||
WeaponScan(float damage, const glm::vec3& center, float radius,
|
||||
WeaponData* weapon = nullptr)
|
||||
: type(RADIUS)
|
||||
, damage(damage)
|
||||
, center(center)
|
||||
, radius(radius)
|
||||
, weapon(weapon) {
|
||||
}
|
||||
|
||||
// Constructor for a ray hitscan
|
||||
WeaponScan( float damage, const glm::vec3& start, const glm::vec3& end, WeaponData* weapon = nullptr )
|
||||
: type(HITSCAN), damage(damage), center(start), end(end), weapon(weapon)
|
||||
{}
|
||||
// Constructor for a ray hitscan
|
||||
WeaponScan(float damage, const glm::vec3& start, const glm::vec3& end,
|
||||
WeaponData* weapon = nullptr)
|
||||
: type(HITSCAN)
|
||||
, damage(damage)
|
||||
, center(start)
|
||||
, end(end)
|
||||
, weapon(weapon) {
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -11,57 +11,56 @@
|
||||
* \class Zone
|
||||
* A Zone entry
|
||||
*/
|
||||
struct ZoneData
|
||||
{
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Gang spawn density for daytime (8:00-19:00)
|
||||
*/
|
||||
unsigned int gangDensityDay[ZONE_GANG_COUNT];
|
||||
|
||||
/**
|
||||
* Gang spawn density for nighttime (19:00-8:00)
|
||||
*/
|
||||
unsigned int gangDensityNight[ZONE_GANG_COUNT];
|
||||
|
||||
/**
|
||||
* Gang car spawn density for daytime (8:00-19:00)
|
||||
*/
|
||||
unsigned int gangCarDensityDay[ZONE_GANG_COUNT];
|
||||
|
||||
/**
|
||||
* Gang car spawn density for nighttime (19:00-8:00)
|
||||
*/
|
||||
unsigned int gangCarDensityNight[ZONE_GANG_COUNT];
|
||||
|
||||
unsigned int pedGroupDay;
|
||||
unsigned int pedGroupNight;
|
||||
struct ZoneData {
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Gang spawn density for daytime (8:00-19:00)
|
||||
*/
|
||||
unsigned int gangDensityDay[ZONE_GANG_COUNT];
|
||||
|
||||
/**
|
||||
* Gang spawn density for nighttime (19:00-8:00)
|
||||
*/
|
||||
unsigned int gangDensityNight[ZONE_GANG_COUNT];
|
||||
|
||||
/**
|
||||
* Gang car spawn density for daytime (8:00-19:00)
|
||||
*/
|
||||
unsigned int gangCarDensityDay[ZONE_GANG_COUNT];
|
||||
|
||||
/**
|
||||
* Gang car spawn density for nighttime (19:00-8:00)
|
||||
*/
|
||||
unsigned int gangCarDensityNight[ZONE_GANG_COUNT];
|
||||
|
||||
unsigned int pedGroupDay;
|
||||
unsigned int pedGroupNight;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user