mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-05 06:50:04 +00:00
Move lerp to td init, add variable gap size
This commit is contained in:
parent
6a78a301c9
commit
a5ffe26c44
@ -52,11 +52,7 @@ void TableData::init() {
|
|||||||
|
|
||||||
nlohmann::json pathDataSkyway = pathData["skyway"];
|
nlohmann::json pathDataSkyway = pathData["skyway"];
|
||||||
for (nlohmann::json::iterator skywayPath = pathDataSkyway.begin(); skywayPath != pathDataSkyway.end(); skywayPath++) {
|
for (nlohmann::json::iterator skywayPath = pathDataSkyway.begin(); skywayPath != pathDataSkyway.end(); skywayPath++) {
|
||||||
std::vector<WarpLocation> points;
|
constructPath(skywayPath);
|
||||||
nlohmann::json pathPoints = skywayPath.value()["points"];
|
|
||||||
for (nlohmann::json::iterator point = pathPoints.begin(); point != pathPoints.end(); point++)
|
|
||||||
points.push_back({point.value()["iX"], point.value()["iY"], point.value()["iZ"] });
|
|
||||||
TransportManager::SkywayPaths[skywayPath.value()["iRouteID"]] = points;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "[INFO] Loaded " << TransportManager::SkywayPaths.size() << " skyway paths" << std::endl;
|
std::cout << "[INFO] Loaded " << TransportManager::SkywayPaths.size() << " skyway paths" << std::endl;
|
||||||
@ -235,3 +231,29 @@ int TableData::getItemType(int itemSet) {
|
|||||||
}
|
}
|
||||||
return overriden;
|
return overriden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TableData::constructPath(nlohmann::json::iterator pathData) {
|
||||||
|
// Interpolate
|
||||||
|
nlohmann::json pathPoints = pathData.value()["points"];
|
||||||
|
std::queue<WarpLocation> points;
|
||||||
|
nlohmann::json::iterator point = pathPoints.begin();
|
||||||
|
WarpLocation last = { point.value()["iX"] , point.value()["iY"] , point.value()["iZ"] }; // start pos
|
||||||
|
// use some for loop trickery
|
||||||
|
for (point++; point != pathPoints.end(); point++) {
|
||||||
|
WarpLocation coords = { point.value()["iX"] , point.value()["iY"] , point.value()["iZ"] };
|
||||||
|
// avoiding pow here
|
||||||
|
int distanceBetween = sqrt((last.x - coords.x) * (last.x - coords.x) + (last.y - coords.y) * (last.y - coords.y) + (last.z - coords.z) * (last.z - coords.z));
|
||||||
|
int lerps = distanceBetween / (int)pathData.value()["iMaxGapSize"]; // integer division to ensure a whole number
|
||||||
|
for (int i = 0; i < lerps; i++) {
|
||||||
|
WarpLocation lerp;
|
||||||
|
float frac = (i + 1) * 1.0f / (lerps + 1);
|
||||||
|
lerp.x = (last.x * (1.0f - frac)) + (coords.x * frac);
|
||||||
|
lerp.y = (last.y * (1.0f - frac)) + (coords.y * frac);
|
||||||
|
lerp.z = (last.z * (1.0f - frac)) + (coords.z * frac);
|
||||||
|
points.push(lerp); // add lerp'd point to the queue
|
||||||
|
}
|
||||||
|
points.push(coords);
|
||||||
|
last = coords; // update start pos
|
||||||
|
}
|
||||||
|
TransportManager::SkywayPaths[pathData.value()["iRouteID"]] = points;
|
||||||
|
}
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#include "contrib/JSON.hpp"
|
||||||
|
|
||||||
namespace TableData {
|
namespace TableData {
|
||||||
void init();
|
void init();
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
int getItemType(int);
|
int getItemType(int);
|
||||||
|
void constructPath(nlohmann::json::iterator);
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
std::map<int32_t, TransportRoute> TransportManager::Routes;
|
std::map<int32_t, TransportRoute> TransportManager::Routes;
|
||||||
std::map<int32_t, TransportLocation> TransportManager::Locations;
|
std::map<int32_t, TransportLocation> TransportManager::Locations;
|
||||||
std::map<int32_t, std::vector<WarpLocation>> TransportManager::SkywayPaths;
|
std::map<int32_t, std::queue<WarpLocation>> TransportManager::SkywayPaths;
|
||||||
std::unordered_map<CNSocket*, std::queue<WarpLocation>> TransportManager::SkywayQueue;
|
std::unordered_map<CNSocket*, std::queue<WarpLocation>> TransportManager::SkywayQueue;
|
||||||
|
|
||||||
void TransportManager::init() {
|
void TransportManager::init() {
|
||||||
@ -118,7 +118,7 @@ void TransportManager::transportWarpHandler(CNSocket* sock, CNPacketData* data)
|
|||||||
|
|
||||||
TransportLocation target;
|
TransportLocation target;
|
||||||
PlayerView& plrv = PlayerManager::players[sock];
|
PlayerView& plrv = PlayerManager::players[sock];
|
||||||
std::vector<WarpLocation>* points = nullptr;
|
std::queue<WarpLocation>* points = nullptr;
|
||||||
switch (route.type)
|
switch (route.type)
|
||||||
{
|
{
|
||||||
case 1: // S.C.A.M.P.E.R.
|
case 1: // S.C.A.M.P.E.R.
|
||||||
@ -153,37 +153,13 @@ void TransportManager::transportWarpHandler(CNSocket* sock, CNPacketData* data)
|
|||||||
resp.iZ = plr->z;
|
resp.iZ = plr->z;
|
||||||
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_WARP_USE_TRANSPORTATION_SUCC, sizeof(sP_FE2CL_REP_PC_WARP_USE_TRANSPORTATION_SUCC));
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_WARP_USE_TRANSPORTATION_SUCC, sizeof(sP_FE2CL_REP_PC_WARP_USE_TRANSPORTATION_SUCC));
|
||||||
|
|
||||||
/*
|
|
||||||
* Not strictly necessary since there isn't a valid SCAMPER that puts you in the
|
|
||||||
* same map tile you were already in, but we might as well force an NPC reload.
|
|
||||||
*/
|
|
||||||
PlayerView& plrv = PlayerManager::players[sock];
|
PlayerView& plrv = PlayerManager::players[sock];
|
||||||
|
|
||||||
PlayerManager::removePlayerFromChunks(plrv.currentChunks, sock);
|
PlayerManager::removePlayerFromChunks(plrv.currentChunks, sock);
|
||||||
plrv.currentChunks.clear();
|
plrv.currentChunks.clear();
|
||||||
plrv.chunkPos = std::make_pair<int, int>(0, 0);
|
plrv.chunkPos = std::make_pair<int, int>(0, 0);
|
||||||
if (points == nullptr) // no skyway path set
|
if (points != nullptr) // check if skyway path set
|
||||||
return;
|
SkywayQueue[sock] = *points;
|
||||||
|
|
||||||
// Interpolate
|
|
||||||
std::queue<WarpLocation> queue;
|
|
||||||
WarpLocation last = { plr->x, plr->y, plr->z }; // start pos
|
|
||||||
for (std::vector<WarpLocation>::iterator point = points->begin(); point != points->end(); point++) {
|
|
||||||
// avoiding pow here
|
|
||||||
int distanceBetween = sqrt((last.x - point->x) * (last.x - point->x) + (last.y - point->y) * (last.y - point->y) + (last.z - point->z) * (last.z - point->z));
|
|
||||||
int lerps = distanceBetween / (int)LERP_GAP; // integer division to ensure a whole number
|
|
||||||
for (int i = 0; i < lerps; i++) {
|
|
||||||
WarpLocation lerp;
|
|
||||||
float frac = (i + 1) * 1.0f / (lerps + 1);
|
|
||||||
lerp.x = (last.x * (1.0f - frac)) + (point->x * frac);
|
|
||||||
lerp.y = (last.y * (1.0f - frac)) + (point->y * frac);
|
|
||||||
lerp.z = (last.z * (1.0f - frac)) + (point->z * frac);
|
|
||||||
queue.push(lerp); // add lerp'd point to the queue
|
|
||||||
}
|
|
||||||
queue.push(*point);
|
|
||||||
last = { point->x, point->y, point->z }; // update start pos
|
|
||||||
}
|
|
||||||
SkywayQueue[sock] = queue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransportManager::tickSkywaySystem(CNServer* serv, time_t currTime) {
|
void TransportManager::tickSkywaySystem(CNServer* serv, time_t currTime) {
|
||||||
|
@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
#define LERP_GAP 3000
|
|
||||||
|
|
||||||
struct WarpLocation;
|
struct WarpLocation;
|
||||||
|
|
||||||
struct TransportRoute {
|
struct TransportRoute {
|
||||||
@ -20,7 +18,7 @@ struct TransportLocation {
|
|||||||
namespace TransportManager {
|
namespace TransportManager {
|
||||||
extern std::map<int32_t, TransportRoute> Routes;
|
extern std::map<int32_t, TransportRoute> Routes;
|
||||||
extern std::map<int32_t, TransportLocation> Locations;
|
extern std::map<int32_t, TransportLocation> Locations;
|
||||||
extern std::map<int32_t, std::vector<WarpLocation>> SkywayPaths;
|
extern std::map<int32_t, std::queue<WarpLocation>> SkywayPaths;
|
||||||
extern std::unordered_map<CNSocket*, std::queue<WarpLocation>> SkywayQueue;
|
extern std::unordered_map<CNSocket*, std::queue<WarpLocation>> SkywayQueue;
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
Loading…
Reference in New Issue
Block a user