mirror of
https://github.com/HarbourMasters/SpaghettiKart
synced 2026-07-09 23:02:11 -04:00
Import fast64 paths
This commit is contained in:
@@ -158,6 +158,9 @@ GameEngine::GameEngine() {
|
||||
loader->RegisterResourceFactory(std::make_shared<MK64::ResourceFactoryBinaryTrackWaypointsV0>(),
|
||||
RESOURCE_FORMAT_BINARY, "Waypoints",
|
||||
static_cast<uint32_t>(MK64::ResourceType::Waypoints), 0);
|
||||
loader->RegisterResourceFactory(std::make_shared<MK64::ResourceFactoryXMLTrackWaypointsV0>(),
|
||||
RESOURCE_FORMAT_XML, "Paths",
|
||||
static_cast<uint32_t>(MK64::ResourceType::Waypoints), 0);
|
||||
loader->RegisterResourceFactory(std::make_shared<MK64::ResourceFactoryBinaryActorSpawnDataV0>(),
|
||||
RESOURCE_FORMAT_BINARY, "SpawnData",
|
||||
static_cast<uint32_t>(MK64::ResourceType::SpawnData), 0);
|
||||
|
||||
@@ -29,4 +29,43 @@ ResourceFactoryBinaryTrackWaypointsV0::ReadResource(std::shared_ptr<Ship::File>
|
||||
|
||||
return section;
|
||||
}
|
||||
|
||||
std::shared_ptr<Ship::IResource>
|
||||
ResourceFactoryXMLTrackWaypointsV0::ReadResource(std::shared_ptr<Ship::File> file,
|
||||
std::shared_ptr<Ship::ResourceInitData> initData) {
|
||||
if (!FileHasValidFormatAndReader(file, initData)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto paths = std::make_shared<Paths>(initData);
|
||||
|
||||
auto root = std::get<std::shared_ptr<tinyxml2::XMLDocument>>(file->Reader)->FirstChildElement();
|
||||
|
||||
auto path = root->FirstChildElement("TrackWaypoint");
|
||||
|
||||
while (path != nullptr) {
|
||||
|
||||
std::vector<TrackWaypoint> waypointPath; // Temporary container for this path
|
||||
|
||||
auto pointElem = path->FirstChildElement("Point");
|
||||
|
||||
while (pointElem != nullptr) {
|
||||
TrackWaypoint point;
|
||||
point.posX = pointElem->IntAttribute("X");
|
||||
point.posY = pointElem->IntAttribute("Y");
|
||||
point.posZ = pointElem->IntAttribute("Z");
|
||||
point.trackSegment = pointElem->IntAttribute("ID");
|
||||
|
||||
waypointPath.push_back(point); // Push to temp vector
|
||||
|
||||
pointElem = pointElem->NextSiblingElement("Point");
|
||||
}
|
||||
|
||||
paths->PathList.push_back(waypointPath); // Push full path to outer list
|
||||
|
||||
path = path->NextSiblingElement("TrackWaypoint");
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
|
||||
} // namespace MK64
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "Resource.h"
|
||||
#include "ResourceFactoryBinary.h"
|
||||
#include "ResourceFactoryXML.h"
|
||||
|
||||
namespace MK64 {
|
||||
class ResourceFactoryBinaryTrackWaypointsV0 : public Ship::ResourceFactoryBinary {
|
||||
@@ -10,4 +11,10 @@ class ResourceFactoryBinaryTrackWaypointsV0 : public Ship::ResourceFactoryBinary
|
||||
std::shared_ptr<Ship::ResourceInitData> initData) override;
|
||||
};
|
||||
|
||||
class ResourceFactoryXMLTrackWaypointsV0 : public Ship::ResourceFactoryXML {
|
||||
public:
|
||||
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file,
|
||||
std::shared_ptr<Ship::ResourceInitData> initData) override;
|
||||
};
|
||||
|
||||
} // namespace MK64
|
||||
|
||||
@@ -12,4 +12,22 @@ TrackWaypoint* TrackWaypoints::GetPointer() {
|
||||
size_t TrackWaypoints::GetPointerSize() {
|
||||
return TrackWaypointList.size() * sizeof(TrackWaypoint);
|
||||
}
|
||||
|
||||
|
||||
Paths::Paths() : Resource(std::shared_ptr<Ship::ResourceInitData>()) {
|
||||
}
|
||||
|
||||
// I don't know how to return this properly
|
||||
TrackWaypoint* Paths::GetPointer() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
size_t Paths::GetPointerSize() {
|
||||
size_t totalWaypoints = 0;
|
||||
for (const auto& path : PathList) {
|
||||
totalWaypoints += path.size();
|
||||
}
|
||||
return totalWaypoints * sizeof(TrackWaypoint);
|
||||
}
|
||||
|
||||
} // namespace MK64
|
||||
|
||||
@@ -12,6 +12,7 @@ struct TrackWaypoint {
|
||||
};
|
||||
|
||||
namespace MK64 {
|
||||
// Used for binary import from torch
|
||||
class TrackWaypoints : public Ship::Resource<TrackWaypoint> {
|
||||
public:
|
||||
using Resource::Resource;
|
||||
@@ -23,4 +24,18 @@ class TrackWaypoints : public Ship::Resource<TrackWaypoint> {
|
||||
|
||||
std::vector<TrackWaypoint> TrackWaypointList;
|
||||
};
|
||||
|
||||
// Used for xml
|
||||
class Paths : public Ship::Resource<TrackWaypoint> {
|
||||
public:
|
||||
using Resource::Resource;
|
||||
|
||||
Paths();
|
||||
|
||||
TrackWaypoint* GetPointer() override;
|
||||
size_t GetPointerSize() override;
|
||||
|
||||
std::vector<std::vector<TrackWaypoint>> PathList;
|
||||
};
|
||||
|
||||
} // namespace MK64
|
||||
|
||||
Reference in New Issue
Block a user