mirror of
				https://github.com/OpenFusionProject/OpenFusion.git
				synced 2025-11-04 02:30:21 +00:00 
			
		
		
		
	[refac] Stop using WarpLocation for coordinates and introduce a Vec3
This commit is contained in:
		@@ -127,7 +127,7 @@ static void mssCommand(std::string full, std::vector<std::string>& args, CNSocke
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // get the route (if it doesn't exist yet, this will also make it)
 | 
			
		||||
    std::vector<WarpLocation>* route = &TableData::RunningSkywayRoutes[routeNum];
 | 
			
		||||
    std::vector<Vec3>* route = &TableData::RunningSkywayRoutes[routeNum];
 | 
			
		||||
 | 
			
		||||
    // mss <route> add <height>
 | 
			
		||||
    if (args[2] == "add") {
 | 
			
		||||
@@ -158,7 +158,7 @@ static void mssCommand(std::string full, std::vector<std::string>& args, CNSocke
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        WarpLocation pulled = route->back();
 | 
			
		||||
        Vec3 pulled = route->back();
 | 
			
		||||
        route->pop_back(); // remove point at top of stack
 | 
			
		||||
        Chat::sendServerMessage(sock, "[MSS] Removed point (" + std::to_string(pulled.x) + ", " + std::to_string(pulled.y) + ", " + std::to_string(pulled.z) + ") from route " + std::to_string(routeNum));
 | 
			
		||||
        return;
 | 
			
		||||
@@ -171,7 +171,7 @@ static void mssCommand(std::string full, std::vector<std::string>& args, CNSocke
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        WarpLocation pulled = route->back();
 | 
			
		||||
        Vec3 pulled = route->back();
 | 
			
		||||
        PlayerManager::sendPlayerTo(sock, pulled.x, pulled.y, pulled.z);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
@@ -190,7 +190,7 @@ static void mssCommand(std::string full, std::vector<std::string>& args, CNSocke
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        WarpLocation pulled = route->front();
 | 
			
		||||
        Vec3 pulled = route->front();
 | 
			
		||||
        PlayerManager::sendPlayerTo(sock, pulled.x, pulled.y, pulled.z);
 | 
			
		||||
        Transport::testMssRoute(sock, route);
 | 
			
		||||
        return;
 | 
			
		||||
 
 | 
			
		||||
@@ -701,9 +701,9 @@ static void roamingStep(Mob *mob, time_t currTime) {
 | 
			
		||||
    if (mob->appearanceData.iConditionBitFlag & CSB_BIT_DN_MOVE_SPEED)
 | 
			
		||||
        speed /= 2;
 | 
			
		||||
 | 
			
		||||
    std::queue<WarpLocation> queue;
 | 
			
		||||
    WarpLocation from = { mob->x, mob->y, mob->z };
 | 
			
		||||
    WarpLocation to = { farX, farY, mob->z };
 | 
			
		||||
    std::queue<Vec3> queue;
 | 
			
		||||
    Vec3 from = { mob->x, mob->y, mob->z };
 | 
			
		||||
    Vec3 to = { farX, farY, mob->z };
 | 
			
		||||
 | 
			
		||||
    // add a route to the queue; to be processed in Transport::stepNPCPathing()
 | 
			
		||||
    Transport::lerp(&queue, from, to, speed);
 | 
			
		||||
@@ -720,7 +720,7 @@ static void roamingStep(Mob *mob, time_t currTime) {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            std::queue<WarpLocation> queue2;
 | 
			
		||||
            std::queue<Vec3> queue2;
 | 
			
		||||
            Mob* followerMob = (Mob*)NPCManager::NPCs[mob->groupMember[i]];
 | 
			
		||||
            from = { followerMob->x, followerMob->y, followerMob->z };
 | 
			
		||||
            to = { farX + followerMob->offsetX, farY + followerMob->offsetY, followerMob->z };
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,7 @@
 | 
			
		||||
 | 
			
		||||
using namespace TableData;
 | 
			
		||||
 | 
			
		||||
std::map<int32_t, std::vector<WarpLocation>> TableData::RunningSkywayRoutes;
 | 
			
		||||
std::map<int32_t, std::vector<Vec3>> TableData::RunningSkywayRoutes;
 | 
			
		||||
std::map<int32_t, int> TableData::RunningNPCRotations;
 | 
			
		||||
std::map<int32_t, int> TableData::RunningNPCMapNumbers;
 | 
			
		||||
std::map<int32_t, BaseNPC*> TableData::RunningMobs;
 | 
			
		||||
@@ -40,14 +40,14 @@ public:
 | 
			
		||||
static void constructPathSkyway(json& pathData) {
 | 
			
		||||
    // Interpolate
 | 
			
		||||
    json pathPoints = pathData["points"];
 | 
			
		||||
    std::queue<WarpLocation> points;
 | 
			
		||||
    std::queue<Vec3> points;
 | 
			
		||||
    json::iterator _point = pathPoints.begin();
 | 
			
		||||
    auto point = _point.value();
 | 
			
		||||
    WarpLocation last = { point["iX"] , point["iY"] , point["iZ"] }; // start pos
 | 
			
		||||
    Vec3 last = { point["iX"] , point["iY"] , point["iZ"] }; // start pos
 | 
			
		||||
    // use some for loop trickery; start position should not be a point
 | 
			
		||||
    for (_point++; _point != pathPoints.end(); _point++) {
 | 
			
		||||
        point = _point.value();
 | 
			
		||||
        WarpLocation coords = { point["iX"] , point["iY"] , point["iZ"] };
 | 
			
		||||
        Vec3 coords = { point["iX"] , point["iY"] , point["iZ"] };
 | 
			
		||||
        Transport::lerp(&points, last, coords, pathData["iMonkeySpeed"]);
 | 
			
		||||
        points.push(coords); // add keyframe to the queue
 | 
			
		||||
        last = coords; // update start pos
 | 
			
		||||
@@ -58,16 +58,16 @@ static void constructPathSkyway(json& pathData) {
 | 
			
		||||
static void constructPathNPC(json& pathData, int32_t id=0) {
 | 
			
		||||
    // Interpolate
 | 
			
		||||
    json pathPoints = pathData["points"];
 | 
			
		||||
    std::queue<WarpLocation> points;
 | 
			
		||||
    std::queue<Vec3> points;
 | 
			
		||||
    json::iterator _point = pathPoints.begin();
 | 
			
		||||
    auto point = _point.value();
 | 
			
		||||
    WarpLocation from = { point["iX"] , point["iY"] , point["iZ"] }; // point A coords
 | 
			
		||||
    Vec3 from = { point["iX"] , point["iY"] , point["iZ"] }; // point A coords
 | 
			
		||||
    int stopTime = point["stop"];
 | 
			
		||||
    for (_point++; _point != pathPoints.end(); _point++) { // loop through all point Bs
 | 
			
		||||
        point = _point.value();
 | 
			
		||||
        for(int i = 0; i < stopTime + 1; i++) // repeat point if it's a stop
 | 
			
		||||
            points.push(from); // add point A to the queue
 | 
			
		||||
        WarpLocation to = { point["iX"] , point["iY"] , point["iZ"] }; // point B coords
 | 
			
		||||
        Vec3 to = { point["iX"] , point["iY"] , point["iZ"] }; // point B coords
 | 
			
		||||
        Transport::lerp(&points, from, to, pathData["iBaseSpeed"]); // lerp from A to B
 | 
			
		||||
        from = to; // update point A
 | 
			
		||||
        stopTime = point["stop"];
 | 
			
		||||
@@ -282,11 +282,11 @@ static void loadPaths(json& pathData, int32_t* nextId) {
 | 
			
		||||
        // slider circuit
 | 
			
		||||
        json pathDataSlider = pathData["slider"];
 | 
			
		||||
        // lerp between keyframes
 | 
			
		||||
        std::queue<WarpLocation> route;
 | 
			
		||||
        std::queue<Vec3> route;
 | 
			
		||||
        // initial point
 | 
			
		||||
        json::iterator _point = pathDataSlider.begin(); // iterator
 | 
			
		||||
        auto point = _point.value();
 | 
			
		||||
        WarpLocation from = { point["iX"] , point["iY"] , point["iZ"] }; // point A coords
 | 
			
		||||
        Vec3 from = { point["iX"] , point["iY"] , point["iZ"] }; // point A coords
 | 
			
		||||
        int stopTime = point["stop"] ? SLIDER_STOP_TICKS : 0; // arbitrary stop length
 | 
			
		||||
        // remaining points
 | 
			
		||||
        for (_point++; _point != pathDataSlider.end(); _point++) { // loop through all point Bs
 | 
			
		||||
@@ -294,7 +294,7 @@ static void loadPaths(json& pathData, int32_t* nextId) {
 | 
			
		||||
            for (int i = 0; i < stopTime + 1; i++) { // repeat point if it's a stop
 | 
			
		||||
                route.push(from); // add point A to the queue
 | 
			
		||||
            }
 | 
			
		||||
            WarpLocation to = { point["iX"] , point["iY"] , point["iZ"] }; // point B coords
 | 
			
		||||
            Vec3 to = { point["iX"] , point["iY"] , point["iZ"] }; // point B coords
 | 
			
		||||
            // we may need to change this later; right now, the speed is cut before and after stops (no accel)
 | 
			
		||||
            float curve = 1;
 | 
			
		||||
            if (stopTime > 0) { // point A is a stop
 | 
			
		||||
@@ -310,11 +310,11 @@ static void loadPaths(json& pathData, int32_t* nextId) {
 | 
			
		||||
        int passedDistance = 0;
 | 
			
		||||
        // initial point
 | 
			
		||||
        int pos = 0;
 | 
			
		||||
        WarpLocation lastPoint = route.front();
 | 
			
		||||
        Vec3 lastPoint = route.front();
 | 
			
		||||
        route.pop();
 | 
			
		||||
        route.push(lastPoint);
 | 
			
		||||
        for (pos = 1; pos < route.size(); pos++) {
 | 
			
		||||
            WarpLocation point = route.front();
 | 
			
		||||
            Vec3 point = route.front();
 | 
			
		||||
            passedDistance += hypot(point.x - lastPoint.x, point.y - lastPoint.y);
 | 
			
		||||
            if (passedDistance >= SLIDER_GAP_SIZE) { // space them out uniformaly
 | 
			
		||||
                passedDistance -= SLIDER_GAP_SIZE; // step down
 | 
			
		||||
@@ -685,11 +685,11 @@ static void loadGruntwork(json& gruntwork, int32_t* nextId) {
 | 
			
		||||
        auto skyway = gruntwork["skyway"];
 | 
			
		||||
        for (auto _route = skyway.begin(); _route != skyway.end(); _route++) {
 | 
			
		||||
            auto route = _route.value();
 | 
			
		||||
            std::vector<WarpLocation> points;
 | 
			
		||||
            std::vector<Vec3> points;
 | 
			
		||||
 | 
			
		||||
            for (auto _point = route["points"].begin(); _point != route["points"].end(); _point++) {
 | 
			
		||||
                auto point = _point.value();
 | 
			
		||||
                points.push_back(WarpLocation{point["x"], point["y"], point["z"]});
 | 
			
		||||
                points.push_back(Vec3{point["x"], point["y"], point["z"]});
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            RunningSkywayRoutes[(int)route["iRouteID"]] = points;
 | 
			
		||||
@@ -1006,7 +1006,7 @@ void TableData::flush() {
 | 
			
		||||
        route["iMonkeySpeed"] = 1500;
 | 
			
		||||
 | 
			
		||||
        std::cout << "serializing mss route " << (int)pair.first << std::endl;
 | 
			
		||||
        for (WarpLocation& point : pair.second) {
 | 
			
		||||
        for (Vec3& point : pair.second) {
 | 
			
		||||
            json tmp;
 | 
			
		||||
 | 
			
		||||
            tmp["x"] = point.x;
 | 
			
		||||
 
 | 
			
		||||
@@ -12,7 +12,7 @@ const int MOB_GROUP_ID_OFFSET = 20000;
 | 
			
		||||
typedef nlohmann::json json;
 | 
			
		||||
 | 
			
		||||
namespace TableData {
 | 
			
		||||
    extern std::map<int32_t, std::vector<WarpLocation>> RunningSkywayRoutes;
 | 
			
		||||
    extern std::map<int32_t, std::vector<Vec3>> RunningSkywayRoutes;
 | 
			
		||||
    extern std::map<int32_t, int> RunningNPCRotations;
 | 
			
		||||
    extern std::map<int32_t, int> RunningNPCMapNumbers;
 | 
			
		||||
    extern std::map<int32_t, BaseNPC*> RunningMobs;
 | 
			
		||||
 
 | 
			
		||||
@@ -13,9 +13,9 @@ using namespace Transport;
 | 
			
		||||
 | 
			
		||||
std::map<int32_t, TransportRoute> Transport::Routes;
 | 
			
		||||
std::map<int32_t, TransportLocation> Transport::Locations;
 | 
			
		||||
std::map<int32_t, std::queue<WarpLocation>> Transport::SkywayPaths;
 | 
			
		||||
std::unordered_map<CNSocket*, std::queue<WarpLocation>> Transport::SkywayQueues;
 | 
			
		||||
std::unordered_map<int32_t, std::queue<WarpLocation>> Transport::NPCQueues;
 | 
			
		||||
std::map<int32_t, std::queue<Vec3>> Transport::SkywayPaths;
 | 
			
		||||
std::unordered_map<CNSocket*, std::queue<Vec3>> Transport::SkywayQueues;
 | 
			
		||||
std::unordered_map<int32_t, std::queue<Vec3>> Transport::NPCQueues;
 | 
			
		||||
 | 
			
		||||
static void transportRegisterLocationHandler(CNSocket* sock, CNPacketData* data) {
 | 
			
		||||
    auto transport = (sP_CL2FE_REQ_REGIST_TRANSPORTATION_LOCATION*)data->buf;
 | 
			
		||||
@@ -131,7 +131,7 @@ static void transportWarpHandler(CNSocket* sock, CNPacketData* data) {
 | 
			
		||||
            plr->onMonkey = true;
 | 
			
		||||
            break;
 | 
			
		||||
        } else if (TableData::RunningSkywayRoutes.find(route.mssRouteNum) != TableData::RunningSkywayRoutes.end()) {
 | 
			
		||||
            std::vector<WarpLocation>* _route = &TableData::RunningSkywayRoutes[route.mssRouteNum];
 | 
			
		||||
            std::vector<Vec3>* _route = &TableData::RunningSkywayRoutes[route.mssRouteNum];
 | 
			
		||||
            Nanos::summonNano(sock, -1);
 | 
			
		||||
            testMssRoute(sock, _route);
 | 
			
		||||
            plr->onMonkey = true;
 | 
			
		||||
@@ -169,13 +169,13 @@ static void transportWarpHandler(CNSocket* sock, CNPacketData* data) {
 | 
			
		||||
    PlayerManager::updatePlayerPosition(sock, target->x, target->y, target->z, INSTANCE_OVERWORLD, plr->angle);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Transport::testMssRoute(CNSocket *sock, std::vector<WarpLocation>* route) {
 | 
			
		||||
void Transport::testMssRoute(CNSocket *sock, std::vector<Vec3>* route) {
 | 
			
		||||
    int speed = 1500; // TODO: make this adjustable
 | 
			
		||||
    std::queue<WarpLocation> path;
 | 
			
		||||
    WarpLocation last = route->front(); // start pos
 | 
			
		||||
    std::queue<Vec3> path;
 | 
			
		||||
    Vec3 last = route->front(); // start pos
 | 
			
		||||
 | 
			
		||||
    for (int i = 1; i < route->size(); i++) {
 | 
			
		||||
        WarpLocation coords = route->at(i);
 | 
			
		||||
        Vec3 coords = route->at(i);
 | 
			
		||||
        Transport::lerp(&path, last, coords, speed);
 | 
			
		||||
        path.push(coords); // add keyframe to the queue
 | 
			
		||||
        last = coords; // update start pos
 | 
			
		||||
@@ -191,10 +191,10 @@ void Transport::testMssRoute(CNSocket *sock, std::vector<WarpLocation>* route) {
 | 
			
		||||
static void stepSkywaySystem() {
 | 
			
		||||
 | 
			
		||||
    // using an unordered map so we can remove finished players in one iteration
 | 
			
		||||
    std::unordered_map<CNSocket*, std::queue<WarpLocation>>::iterator it = SkywayQueues.begin();
 | 
			
		||||
    std::unordered_map<CNSocket*, std::queue<Vec3>>::iterator it = SkywayQueues.begin();
 | 
			
		||||
    while (it != SkywayQueues.end()) {
 | 
			
		||||
 | 
			
		||||
        std::queue<WarpLocation>* queue = &it->second;
 | 
			
		||||
        std::queue<Vec3>* queue = &it->second;
 | 
			
		||||
 | 
			
		||||
        if (PlayerManager::players.find(it->first) == PlayerManager::players.end()) {
 | 
			
		||||
            // pluck out dead socket + update iterator
 | 
			
		||||
@@ -218,7 +218,7 @@ static void stepSkywaySystem() {
 | 
			
		||||
            it = SkywayQueues.erase(it); // remove player from tracking map + update iterator
 | 
			
		||||
            plr->onMonkey = false;
 | 
			
		||||
        } else {
 | 
			
		||||
            WarpLocation point = queue->front(); // get point
 | 
			
		||||
            Vec3 point = queue->front(); // get point
 | 
			
		||||
            queue->pop(); // remove point from front of queue
 | 
			
		||||
 | 
			
		||||
            INITSTRUCT(sP_FE2CL_PC_BROOMSTICK_MOVE, bmstk);
 | 
			
		||||
@@ -240,10 +240,10 @@ static void stepSkywaySystem() {
 | 
			
		||||
static void stepNPCPathing() {
 | 
			
		||||
 | 
			
		||||
    // all NPC pathing queues
 | 
			
		||||
    std::unordered_map<int32_t, std::queue<WarpLocation>>::iterator it = NPCQueues.begin();
 | 
			
		||||
    std::unordered_map<int32_t, std::queue<Vec3>>::iterator it = NPCQueues.begin();
 | 
			
		||||
    while (it != NPCQueues.end()) {
 | 
			
		||||
 | 
			
		||||
        std::queue<WarpLocation>* queue = &it->second;
 | 
			
		||||
        std::queue<Vec3>* queue = &it->second;
 | 
			
		||||
 | 
			
		||||
        BaseNPC* npc = nullptr;
 | 
			
		||||
        if (NPCManager::NPCs.find(it->first) != NPCManager::NPCs.end())
 | 
			
		||||
@@ -267,7 +267,7 @@ static void stepNPCPathing() {
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        WarpLocation point = queue->front(); // get point
 | 
			
		||||
        Vec3 point = queue->front(); // get point
 | 
			
		||||
        queue->pop(); // remove point from front of queue
 | 
			
		||||
 | 
			
		||||
        // calculate displacement
 | 
			
		||||
@@ -327,12 +327,12 @@ static void tickTransportationSystem(CNServer* serv, time_t currTime) {
 | 
			
		||||
/*
 | 
			
		||||
 * Linearly interpolate between two points and insert the results into a queue.
 | 
			
		||||
 */
 | 
			
		||||
void Transport::lerp(std::queue<WarpLocation>* queue, WarpLocation start, WarpLocation end, int gapSize, float curve) {
 | 
			
		||||
void Transport::lerp(std::queue<Vec3>* queue, Vec3 start, Vec3 end, int gapSize, float curve) {
 | 
			
		||||
    int dXY = hypot(end.x - start.x, end.y - start.y); // XY plane distance
 | 
			
		||||
    int distanceBetween = hypot(dXY, end.z - start.z); // total distance
 | 
			
		||||
    int lerps = distanceBetween / gapSize; // number of intermediate points to add
 | 
			
		||||
    for (int i = 1; i <= lerps; i++) {
 | 
			
		||||
        WarpLocation lerp;
 | 
			
		||||
        Vec3 lerp;
 | 
			
		||||
        // lerp math
 | 
			
		||||
        //float frac = i / (lerps + 1);
 | 
			
		||||
        float frac = powf(i, curve) / powf(lerps + 1, curve);
 | 
			
		||||
@@ -342,7 +342,7 @@ void Transport::lerp(std::queue<WarpLocation>* queue, WarpLocation start, WarpLo
 | 
			
		||||
        queue->push(lerp); // add lerp'd point
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
void Transport::lerp(std::queue<WarpLocation>* queue, WarpLocation start, WarpLocation end, int gapSize) {
 | 
			
		||||
void Transport::lerp(std::queue<Vec3>* queue, Vec3 start, Vec3 end, int gapSize) {
 | 
			
		||||
    lerp(queue, start, end, gapSize, 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,10 @@ const int SLIDER_SPEED = 1200;
 | 
			
		||||
const int SLIDER_STOP_TICKS = 16;
 | 
			
		||||
const int SLIDER_GAP_SIZE = 45000;
 | 
			
		||||
 | 
			
		||||
struct Vec3 {
 | 
			
		||||
    int x, y, z;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct WarpLocation {
 | 
			
		||||
    int x, y, z, instanceID, isInstance, limitTaskID, npcID;
 | 
			
		||||
};
 | 
			
		||||
@@ -23,14 +27,14 @@ struct TransportLocation {
 | 
			
		||||
namespace Transport {
 | 
			
		||||
    extern std::map<int32_t, TransportRoute> Routes;
 | 
			
		||||
    extern std::map<int32_t, TransportLocation> Locations;
 | 
			
		||||
    extern std::map<int32_t, std::queue<WarpLocation>> SkywayPaths; // predefined skyway paths with points
 | 
			
		||||
    extern std::unordered_map<CNSocket*, std::queue<WarpLocation>> SkywayQueues; // player sockets with queued broomstick points
 | 
			
		||||
    extern std::unordered_map<int32_t, std::queue<WarpLocation>> NPCQueues; // NPC ids with queued pathing points
 | 
			
		||||
    extern std::map<int32_t, std::queue<Vec3>> SkywayPaths; // predefined skyway paths with points
 | 
			
		||||
    extern std::unordered_map<CNSocket*, std::queue<Vec3>> SkywayQueues; // player sockets with queued broomstick points
 | 
			
		||||
    extern std::unordered_map<int32_t, std::queue<Vec3>> NPCQueues; // NPC ids with queued pathing points
 | 
			
		||||
 | 
			
		||||
    void init();
 | 
			
		||||
 | 
			
		||||
    void testMssRoute(CNSocket *sock, std::vector<WarpLocation>* route);
 | 
			
		||||
    void testMssRoute(CNSocket *sock, std::vector<Vec3>* route);
 | 
			
		||||
 | 
			
		||||
    void lerp(std::queue<WarpLocation>*, WarpLocation, WarpLocation, int, float);
 | 
			
		||||
    void lerp(std::queue<WarpLocation>*, WarpLocation, WarpLocation, int);
 | 
			
		||||
    void lerp(std::queue<Vec3>*, Vec3, Vec3, int, float);
 | 
			
		||||
    void lerp(std::queue<Vec3>*, Vec3, Vec3, int);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user