mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-26 04:12:41 +01:00
Convert chaseVehicles to unordered_map and use reserve
This commit is contained in:
parent
84c09d93ce
commit
b2f9567c3f
@ -74,7 +74,7 @@ bool ChaseCoordinator::addChaseVehicle(GameObject *vehicle, int index,
|
|||||||
std::vector<ChaseKeyframe> keyframes;
|
std::vector<ChaseKeyframe> keyframes;
|
||||||
bool result = ChaseKeyframe::load(pathFile, keyframes);
|
bool result = ChaseKeyframe::load(pathFile, keyframes);
|
||||||
RW_CHECK(result, "Failed to load chase keyframes: " + pathFile);
|
RW_CHECK(result, "Failed to load chase keyframes: " + pathFile);
|
||||||
chaseVehicles[index] = {keyframes, vehicle};
|
chaseVehicles[index] = {std::move(keyframes), vehicle};
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,20 +97,24 @@ void ChaseCoordinator::start() {
|
|||||||
void ChaseCoordinator::update(float dt) {
|
void ChaseCoordinator::update(float dt) {
|
||||||
chaseTime += dt;
|
chaseTime += dt;
|
||||||
auto frameNum = static_cast<size_t>(chaseTime * KEYFRAMES_PER_SECOND);
|
auto frameNum = static_cast<size_t>(chaseTime * KEYFRAMES_PER_SECOND);
|
||||||
for (auto &it : chaseVehicles) {
|
for (auto &[index, chase] : chaseVehicles) {
|
||||||
RW_CHECK(frameNum < it.second.keyframes.size(),
|
RW_CHECK(frameNum < chase.keyframes.size(),
|
||||||
"Vehicle out of chase keyframes");
|
"Vehicle out of chase keyframes");
|
||||||
if (frameNum >= it.second.keyframes.size()) continue;
|
if (frameNum >= chase.keyframes.size()) continue;
|
||||||
|
|
||||||
const ChaseKeyframe &kf = it.second.keyframes[frameNum];
|
const ChaseKeyframe &kf = chase.keyframes[frameNum];
|
||||||
it.second.object->setPosition(kf.position);
|
chase.object->setPosition(kf.position);
|
||||||
it.second.object->setRotation(kf.rotation);
|
chase.object->setRotation(kf.rotation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ChaseCoordinator::reserve(size_t nr) {
|
||||||
|
chaseVehicles.reserve(nr);
|
||||||
|
}
|
||||||
|
|
||||||
void ChaseCoordinator::cleanup() {
|
void ChaseCoordinator::cleanup() {
|
||||||
for (auto &it : chaseVehicles) {
|
for (auto &[index, chase] : chaseVehicles) {
|
||||||
it.second.object->engine->destroyObject(it.second.object);
|
chase.object->engine->destroyObject(chase.object);
|
||||||
}
|
}
|
||||||
chaseVehicles.clear();
|
chaseVehicles.clear();
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtc/quaternion.hpp>
|
#include <glm/gtc/quaternion.hpp>
|
||||||
#include <map>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class GameObject;
|
class GameObject;
|
||||||
@ -50,6 +50,8 @@ public:
|
|||||||
void start();
|
void start();
|
||||||
void update(float dt);
|
void update(float dt);
|
||||||
|
|
||||||
|
void reserve(size_t nr);
|
||||||
|
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -59,7 +61,7 @@ private:
|
|||||||
GameObject* object;
|
GameObject* object;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::map<int, ChaseObject> chaseVehicles;
|
std::unordered_map<int, ChaseObject> chaseVehicles;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -9399,32 +9399,38 @@ void opcode_0353(const ScriptArguments& args, const ScriptCharacter character) {
|
|||||||
void opcode_0354(const ScriptArguments& args, const ScriptFloat arg1) {
|
void opcode_0354(const ScriptArguments& args, const ScriptFloat arg1) {
|
||||||
RW_UNUSED(arg1);
|
RW_UNUSED(arg1);
|
||||||
// Hardcoded list of vehicles, put this somewhere else.
|
// Hardcoded list of vehicles, put this somewhere else.
|
||||||
|
auto chaseVehicle = [](auto& args, const auto& data) {
|
||||||
|
args.getWorld()->chase.reserve(data.size());
|
||||||
|
|
||||||
#define CHASE_VEHICLE(model, x, y, z, hdg, c1, c2, path) \
|
for (auto& [model, x, y, z, hdg, c1, c2, path] : data) {
|
||||||
{ \
|
auto vehicle0 = args.getWorld()->createVehicle(
|
||||||
auto vehicle0 = args.getWorld()->createVehicle( \
|
model, glm::vec3(x, y, z),
|
||||||
model, \
|
glm::angleAxis(glm::radians(hdg), glm::vec3(0.f, 0.f, 1.f)));
|
||||||
glm::vec3(x, y, z), \
|
vehicle0->setPrimaryColour(c1);
|
||||||
glm::angleAxis(glm::radians(hdg), glm::vec3(0.f, 0.f, 1.f))); \
|
vehicle0->setSecondaryColour(c2);
|
||||||
vehicle0->setPrimaryColour(c1);\
|
args.getWorld()->chase.addChaseVehicle(
|
||||||
vehicle0->setSecondaryColour(c2);\
|
vehicle0, path,
|
||||||
args.getWorld()->chase.addChaseVehicle(vehicle0, path,\
|
args.getWorld()->data->getDataPath().string() +
|
||||||
args.getWorld()->data->getDataPath().string()+"/data/paths/CHASE" #path ".DAT");\
|
"/data/paths/CHASE" + std::to_string(path) + ".DAT");
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
CHASE_VEHICLE(116, 273.5422f, -1167.1907f, 24.9906f, 64.f, 2, 1, 0);
|
chaseVehicle(
|
||||||
CHASE_VEHICLE(117, 231.1783f, -1388.832f, 25.9782f, 90.0f, 2, 1, 1);
|
args, std::initializer_list<
|
||||||
CHASE_VEHICLE(130, -28.9762f, -1031.3367f, 25.9781f, 242.0f, 1, 75, 2);
|
std::tuple<int, float, float, float, float, float, int, int>>{
|
||||||
CHASE_VEHICLE(96, 114.1564f, -796.6938f, 24.9782f, 180.0f, 0, 0, 3);
|
{116, 273.5422f, -1167.1907f, 24.9906f, 64.f, 2, 1, 0},
|
||||||
CHASE_VEHICLE(110, 184.3156f, -1473.251f, 25.9782f, 0.0f, 6, 6, 4);
|
{117, 231.1783f, -1388.832f, 25.9782f, 90.0f, 2, 1, 1},
|
||||||
CHASE_VEHICLE(105, 173.8868f, -1377.6514f, 25.9782f, 0.0f, 4, 5, 6);
|
{130, -28.9762f, -1031.3367f, 25.9781f, 242.0f, 1, 75, 2},
|
||||||
CHASE_VEHICLE(92, 102.5946f, -943.9363f, 25.9781f, 270.0f, 53,53, 7);
|
{96, 114.1564f, -796.6938f, 24.9782f, 180.0f, 0, 0, 3},
|
||||||
CHASE_VEHICLE(105, 177.7157f, -862.1865f, 25.9782f, 155.0f, 41, 1, 10);
|
{110, 184.3156f, -1473.251f, 25.9782f, 0.0f, 6, 6, 4},
|
||||||
CHASE_VEHICLE(92, 170.5698f, -889.0236f, 25.9782f, 154.0f, 10, 10,11);
|
{105, 173.8868f, -1377.6514f, 25.9782f, 0.0f, 4, 5, 6},
|
||||||
CHASE_VEHICLE(111, 402.6081f, -917.4963f, 37.381f, 90.0f, 34, 1, 14);
|
{92, 102.5946f, -943.9363f, 25.9781f, 270.0f, 53, 53, 7},
|
||||||
CHASE_VEHICLE(110, -33.4962f, -938.4563f, 25.9781f, 266.0f, 6, 6, 16);
|
{105, 177.7157f, -862.1865f, 25.9782f, 155.0f, 41, 1, 10},
|
||||||
CHASE_VEHICLE(111, 49.3631f, -987.605f, 25.9781f, 0.0f, 51, 1, 18);
|
{92, 170.5698f, -889.0236f, 25.9782f, 154.0f, 10, 10, 11},
|
||||||
CHASE_VEHICLE(110, 179.0049f, -1154.6686f, 25.9781f, 0.0f, 6, 76, 19);
|
{111, 402.6081f, -917.4963f, 37.381f, 90.0f, 34, 1, 14},
|
||||||
|
{110, -33.4962f, -938.4563f, 25.9781f, 266.0f, 6, 6, 16},
|
||||||
|
{111, 49.3631f, -987.605f, 25.9781f, 0.0f, 51, 1, 18},
|
||||||
|
{110, 179.0049f, -1154.6686f, 25.9781f, 0.0f, 6, 76, 19}});
|
||||||
|
|
||||||
args.getWorld()->chase.start();
|
args.getWorld()->chase.start();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user