mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-02-24 14:51:46 -05:00
Defer scene DList resource loading to in-game and support alt pathing (#4986)
* Defer scene dlist resource loading to in-game and support alt pathing * feedback
This commit is contained in:
parent
b2cb3ff87d
commit
3cd4851474
@ -36,30 +36,38 @@ SetMeshFactory::ReadResource(std::shared_ptr<Ship::ResourceInitData> initData, s
|
|||||||
for (int32_t i = 0; i < polyNum; i++) {
|
for (int32_t i = 0; i < polyNum; i++) {
|
||||||
if (setMesh->meshHeader.base.type == 0) {
|
if (setMesh->meshHeader.base.type == 0) {
|
||||||
PolygonDlist dlist;
|
PolygonDlist dlist;
|
||||||
|
dlist.opa = nullptr;
|
||||||
|
dlist.xlu = nullptr;
|
||||||
|
|
||||||
int32_t polyType = reader->ReadInt8(); // Unused
|
int32_t polyType = reader->ReadInt8(); // Unused
|
||||||
std::string meshOpa = reader->ReadString();
|
std::string meshOpa = reader->ReadString();
|
||||||
std::string meshXlu = reader->ReadString();
|
std::string meshXlu = reader->ReadString();
|
||||||
|
|
||||||
auto opaRes = Ship::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(meshOpa.c_str());
|
// Enables alt-toggling support by setting maintained c_str references to DList resource after pushing to vector the first
|
||||||
auto xluRes = Ship::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(meshXlu.c_str());
|
// Defers resource loading later in game when the scene is drawn
|
||||||
dlist.opa = meshOpa != "" ? (Gfx*)(opaRes ? opaRes->GetRawPointer() : nullptr) : 0;
|
if (meshOpa != "") {
|
||||||
dlist.xlu = meshXlu != "" ? (Gfx*)(xluRes ? xluRes->GetRawPointer() : nullptr) : 0;
|
meshOpa = "__OTR__" + meshOpa;
|
||||||
|
setMesh->opaPaths.push_back(meshOpa);
|
||||||
|
dlist.opa = (Gfx*)setMesh->opaPaths.back().c_str();
|
||||||
|
}
|
||||||
|
if (meshXlu != "") {
|
||||||
|
meshXlu = "__OTR__" + meshXlu;
|
||||||
|
setMesh->xluPaths.push_back(meshXlu);
|
||||||
|
dlist.xlu = (Gfx*)setMesh->xluPaths.back().c_str();
|
||||||
|
}
|
||||||
|
|
||||||
setMesh->opaPaths.push_back(meshOpa);
|
|
||||||
setMesh->xluPaths.push_back(meshXlu);
|
|
||||||
setMesh->dlists.push_back(dlist);
|
setMesh->dlists.push_back(dlist);
|
||||||
} else if (setMesh->meshHeader.base.type == 1) {
|
} else if (setMesh->meshHeader.base.type == 1) {
|
||||||
PolygonDlist pType;
|
PolygonDlist pType;
|
||||||
|
pType.opa = nullptr;
|
||||||
|
pType.xlu = nullptr;
|
||||||
|
|
||||||
setMesh->meshHeader.polygon1.format = reader->ReadUByte();
|
setMesh->meshHeader.polygon1.format = reader->ReadUByte();
|
||||||
std::string imgOpa = reader->ReadString();
|
|
||||||
std::string imgXlu = reader->ReadString();
|
|
||||||
|
|
||||||
auto opaRes = Ship::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(imgOpa.c_str());
|
// These strings are the same that are read and used below. Not sure why they get exported twice from the exporter.
|
||||||
auto xluRes = Ship::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(imgXlu.c_str());
|
// We read and ignore these to advance the reader.
|
||||||
pType.opa = imgOpa != "" ? (Gfx*)(opaRes ? opaRes->GetRawPointer() : nullptr) : 0;
|
reader->ReadString();
|
||||||
pType.xlu = imgXlu != "" ? (Gfx*)(xluRes ? xluRes->GetRawPointer() : nullptr) : 0;
|
reader->ReadString();
|
||||||
|
|
||||||
int32_t bgImageCount = reader->ReadUInt32();
|
int32_t bgImageCount = reader->ReadUInt32();
|
||||||
setMesh->images.reserve(bgImageCount);
|
setMesh->images.reserve(bgImageCount);
|
||||||
@ -104,17 +112,24 @@ SetMeshFactory::ReadResource(std::shared_ptr<Ship::ResourceInitData> initData, s
|
|||||||
std::string meshOpa = reader->ReadString();
|
std::string meshOpa = reader->ReadString();
|
||||||
std::string meshXlu = reader->ReadString();
|
std::string meshXlu = reader->ReadString();
|
||||||
|
|
||||||
opaRes = Ship::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(meshOpa.c_str());
|
// Use long-lived maintained c_str references
|
||||||
xluRes = Ship::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(meshXlu.c_str());
|
if (meshOpa != "") {
|
||||||
pType.opa = meshOpa != "" ? (Gfx*)(opaRes ? opaRes->GetRawPointer() : nullptr) : 0;
|
meshOpa = "__OTR__" + meshOpa;
|
||||||
pType.xlu = meshXlu != "" ? (Gfx*)(xluRes ? xluRes->GetRawPointer() : nullptr) : 0;
|
setMesh->opaPaths.push_back(meshOpa);
|
||||||
|
pType.opa = (Gfx*)setMesh->opaPaths.back().c_str();
|
||||||
|
}
|
||||||
|
if (meshXlu != "") {
|
||||||
|
meshXlu = "__OTR__" + meshXlu;
|
||||||
|
setMesh->xluPaths.push_back(meshXlu);
|
||||||
|
pType.xlu = (Gfx*)setMesh->xluPaths.back().c_str();
|
||||||
|
}
|
||||||
|
|
||||||
setMesh->opaPaths.push_back(meshOpa);
|
|
||||||
setMesh->xluPaths.push_back(meshXlu);
|
|
||||||
setMesh->dlists.push_back(pType);
|
setMesh->dlists.push_back(pType);
|
||||||
} else if (setMesh->meshHeader.base.type == 2) {
|
} else if (setMesh->meshHeader.base.type == 2) {
|
||||||
PolygonDlist2 dlist;
|
PolygonDlist2 dlist;
|
||||||
|
dlist.opa = nullptr;
|
||||||
|
dlist.xlu = nullptr;
|
||||||
|
|
||||||
int32_t polyType = reader->ReadInt8(); // Unused
|
int32_t polyType = reader->ReadInt8(); // Unused
|
||||||
dlist.pos.x = reader->ReadInt16();
|
dlist.pos.x = reader->ReadInt16();
|
||||||
dlist.pos.y = reader->ReadInt16();
|
dlist.pos.y = reader->ReadInt16();
|
||||||
@ -124,13 +139,18 @@ SetMeshFactory::ReadResource(std::shared_ptr<Ship::ResourceInitData> initData, s
|
|||||||
std::string meshOpa = reader->ReadString();
|
std::string meshOpa = reader->ReadString();
|
||||||
std::string meshXlu = reader->ReadString();
|
std::string meshXlu = reader->ReadString();
|
||||||
|
|
||||||
auto opaRes = meshOpa != "" ? Ship::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(meshOpa.c_str()) : nullptr;
|
// Use long-lived maintained c_str references
|
||||||
auto xluRes = meshXlu != "" ? Ship::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(meshXlu.c_str()) : nullptr;
|
if (meshOpa != "") {
|
||||||
dlist.opa = (Gfx*)(opaRes ? opaRes->GetRawPointer() : nullptr);
|
meshOpa = "__OTR__" + meshOpa;
|
||||||
dlist.xlu = (Gfx*)(xluRes ? xluRes->GetRawPointer() : nullptr);
|
setMesh->opaPaths.push_back(meshOpa);
|
||||||
|
dlist.opa = (Gfx*)setMesh->opaPaths.back().c_str();
|
||||||
|
}
|
||||||
|
if (meshXlu != "") {
|
||||||
|
meshXlu = "__OTR__" + meshXlu;
|
||||||
|
setMesh->xluPaths.push_back(meshXlu);
|
||||||
|
dlist.xlu = (Gfx*)setMesh->xluPaths.back().c_str();
|
||||||
|
}
|
||||||
|
|
||||||
setMesh->opaPaths.push_back(meshOpa);
|
|
||||||
setMesh->xluPaths.push_back(meshXlu);
|
|
||||||
setMesh->dlists2.push_back(dlist);
|
setMesh->dlists2.push_back(dlist);
|
||||||
} else {
|
} else {
|
||||||
SPDLOG_ERROR("Tried to load mesh in SetMesh scene header with type that doesn't exist: {}", setMesh->meshHeader.base.type);
|
SPDLOG_ERROR("Tried to load mesh in SetMesh scene header with type that doesn't exist: {}", setMesh->meshHeader.base.type);
|
||||||
@ -194,38 +214,33 @@ std::shared_ptr<Ship::IResource> SetMeshFactoryXML::ReadResource(std::shared_ptr
|
|||||||
|
|
||||||
if (setMesh->meshHeader.base.type == 0) {
|
if (setMesh->meshHeader.base.type == 0) {
|
||||||
PolygonDlist dlist;
|
PolygonDlist dlist;
|
||||||
|
dlist.opa = nullptr;
|
||||||
|
dlist.xlu = nullptr;
|
||||||
|
|
||||||
int32_t polyType = child->IntAttribute("PolyType"); // Unused
|
int32_t polyType = child->IntAttribute("PolyType"); // Unused
|
||||||
std::string meshOpa = child->Attribute("MeshOpa");
|
std::string meshOpa = child->Attribute("MeshOpa");
|
||||||
std::string meshXlu = child->Attribute("MeshXlu");
|
std::string meshXlu = child->Attribute("MeshXlu");
|
||||||
|
|
||||||
|
// Enables alt-toggling support by setting maintained c_str references to DList resource after pushing to vector the first
|
||||||
|
// Defers resource loading later in game when the scene is drawn
|
||||||
if (meshOpa != "") {
|
if (meshOpa != "") {
|
||||||
auto opaRes = Ship::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(meshOpa.c_str());
|
meshOpa = "__OTR__" + meshOpa;
|
||||||
dlist.opa = (Gfx*)(opaRes ? opaRes->GetRawPointer() : nullptr);
|
setMesh->opaPaths.push_back(meshOpa);
|
||||||
} else {
|
dlist.opa = (Gfx*)setMesh->opaPaths.back().c_str();
|
||||||
dlist.opa = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (meshXlu != "") {
|
if (meshXlu != "") {
|
||||||
auto xluRes = Ship::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(meshXlu.c_str());
|
meshXlu = "__OTR__" + meshXlu;
|
||||||
dlist.xlu = (Gfx*)(xluRes ? xluRes->GetRawPointer() : nullptr);
|
setMesh->xluPaths.push_back(meshXlu);
|
||||||
} else {
|
dlist.xlu = (Gfx*)setMesh->xluPaths.back().c_str();
|
||||||
dlist.xlu = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setMesh->opaPaths.push_back(meshOpa);
|
|
||||||
setMesh->xluPaths.push_back(meshXlu);
|
|
||||||
setMesh->dlists.push_back(dlist);
|
setMesh->dlists.push_back(dlist);
|
||||||
} else if (setMesh->meshHeader.base.type == 1) {
|
} else if (setMesh->meshHeader.base.type == 1) {
|
||||||
PolygonDlist pType;
|
PolygonDlist pType;
|
||||||
|
pType.opa = nullptr;
|
||||||
|
pType.xlu = nullptr;
|
||||||
|
|
||||||
setMesh->meshHeader.polygon1.format = child->IntAttribute("Format");
|
setMesh->meshHeader.polygon1.format = child->IntAttribute("Format");
|
||||||
std::string imgOpa = child->Attribute("ImgOpa");
|
|
||||||
std::string imgXlu = child->Attribute("ImgXlu");
|
|
||||||
|
|
||||||
auto opaRes = Ship::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(imgOpa.c_str());
|
|
||||||
auto xluRes = Ship::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(imgXlu.c_str());
|
|
||||||
pType.opa = imgOpa != "" ? (Gfx*)(opaRes ? opaRes->GetRawPointer() : nullptr) : 0;
|
|
||||||
pType.xlu = imgXlu != "" ? (Gfx*)(xluRes ? xluRes->GetRawPointer() : nullptr) : 0;
|
|
||||||
|
|
||||||
int32_t bgImageCount = child->IntAttribute("BgImageCount");
|
int32_t bgImageCount = child->IntAttribute("BgImageCount");
|
||||||
setMesh->images.reserve(bgImageCount);
|
setMesh->images.reserve(bgImageCount);
|
||||||
@ -279,16 +294,23 @@ std::shared_ptr<Ship::IResource> SetMeshFactoryXML::ReadResource(std::shared_ptr
|
|||||||
std::string meshOpa = child->Attribute("MeshOpa");
|
std::string meshOpa = child->Attribute("MeshOpa");
|
||||||
std::string meshXlu = child->Attribute("MeshXlu");
|
std::string meshXlu = child->Attribute("MeshXlu");
|
||||||
|
|
||||||
opaRes = Ship::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(meshOpa.c_str());
|
// Use long-lived maintained c_str references
|
||||||
xluRes = Ship::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(meshXlu.c_str());
|
if (meshOpa != "") {
|
||||||
pType.opa = meshOpa != "" ? (Gfx*)(opaRes ? opaRes->GetRawPointer() : nullptr) : 0;
|
meshOpa = "__OTR__" + meshOpa;
|
||||||
pType.xlu = meshXlu != "" ? (Gfx*)(xluRes ? xluRes->GetRawPointer() : nullptr) : 0;
|
setMesh->opaPaths.push_back(meshOpa);
|
||||||
|
pType.opa = (Gfx*)setMesh->opaPaths.back().c_str();
|
||||||
|
}
|
||||||
|
if (meshXlu != "") {
|
||||||
|
meshXlu = "__OTR__" + meshXlu;
|
||||||
|
setMesh->xluPaths.push_back(meshXlu);
|
||||||
|
pType.xlu = (Gfx*)setMesh->xluPaths.back().c_str();
|
||||||
|
}
|
||||||
|
|
||||||
setMesh->opaPaths.push_back(meshOpa);
|
|
||||||
setMesh->xluPaths.push_back(meshXlu);
|
|
||||||
setMesh->dlists.push_back(pType);
|
setMesh->dlists.push_back(pType);
|
||||||
} else if (setMesh->meshHeader.base.type == 2) {
|
} else if (setMesh->meshHeader.base.type == 2) {
|
||||||
PolygonDlist2 dlist;
|
PolygonDlist2 dlist;
|
||||||
|
dlist.opa = nullptr;
|
||||||
|
dlist.xlu = nullptr;
|
||||||
|
|
||||||
int32_t polyType = child->IntAttribute("PolyType"); // Unused
|
int32_t polyType = child->IntAttribute("PolyType"); // Unused
|
||||||
dlist.pos.x = child->IntAttribute("PosX");
|
dlist.pos.x = child->IntAttribute("PosX");
|
||||||
@ -299,13 +321,18 @@ std::shared_ptr<Ship::IResource> SetMeshFactoryXML::ReadResource(std::shared_ptr
|
|||||||
std::string meshOpa = child->Attribute("MeshOpa");
|
std::string meshOpa = child->Attribute("MeshOpa");
|
||||||
std::string meshXlu = child->Attribute("MeshXlu");
|
std::string meshXlu = child->Attribute("MeshXlu");
|
||||||
|
|
||||||
auto opaRes = Ship::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(meshOpa.c_str());
|
// Use long-lived maintained c_str references
|
||||||
auto xluRes = Ship::Context::GetInstance()->GetResourceManager()->LoadResourceProcess(meshXlu.c_str());
|
if (meshOpa != "") {
|
||||||
dlist.opa = meshOpa != "" ? (Gfx*)(opaRes ? opaRes->GetRawPointer() : nullptr) : 0;
|
meshOpa = "__OTR__" + meshOpa;
|
||||||
dlist.xlu = meshXlu != "" ? (Gfx*)(xluRes ? xluRes->GetRawPointer() : nullptr) : 0;
|
setMesh->opaPaths.push_back(meshOpa);
|
||||||
|
dlist.opa = (Gfx*)setMesh->opaPaths.back().c_str();
|
||||||
|
}
|
||||||
|
if (meshXlu != "") {
|
||||||
|
meshXlu = "__OTR__" + meshXlu;
|
||||||
|
setMesh->xluPaths.push_back(meshXlu);
|
||||||
|
dlist.xlu = (Gfx*)setMesh->xluPaths.back().c_str();
|
||||||
|
}
|
||||||
|
|
||||||
setMesh->opaPaths.push_back(meshOpa);
|
|
||||||
setMesh->xluPaths.push_back(meshXlu);
|
|
||||||
setMesh->dlists2.push_back(dlist);
|
setMesh->dlists2.push_back(dlist);
|
||||||
} else {
|
} else {
|
||||||
SPDLOG_ERROR("Tried to load mesh in SetMesh scene header with type that doesn't exist: {}", setMesh->meshHeader.base.type);
|
SPDLOG_ERROR("Tried to load mesh in SetMesh scene header with type that doesn't exist: {}", setMesh->meshHeader.base.type);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user