Added png factories among fixing asset array for hd textures

This commit is contained in:
KiritoDv
2026-01-13 21:32:14 -06:00
parent ff4adf1422
commit e1992eaf41
6 changed files with 141 additions and 12 deletions
+13 -6
View File
@@ -22,6 +22,7 @@
#include <fast/Fast3dWindow.h>
#include <fast/interpreter.h>
#include <SDL2/SDL.h>
#include <filesystem>
#ifdef USE_NETWORKING
#include <SDL2/SDL_net.h>
@@ -40,10 +41,10 @@
#include <ship/window/gui/resource/Font.h>
#include "importer/AssetArrayFactory.h"
#include "importer/RawTextureFactory.h"
#include "port/importer/GenericArrayFactory.h"
#include "controller/controldeck/ControlDeck.h"
#include <filesystem>
#include "port/mods/utils/gfxprint.h"
#include "port/mods/utils/GfxPrint.h"
#ifdef __SWITCH__
#include <port/switch/SwitchImpl.h>
@@ -152,6 +153,12 @@ GameEngine::GameEngine() : dictionary(nullptr) {
auto loader = context->GetResourceManager()->GetResourceLoader();
auto blobFactory = std::make_shared<Ship::ResourceFactoryBinaryBlobV0>();
loader->RegisterResourceFactory(std::make_shared<MK64::ResourceFactoryBinaryTextureV0>(), RESOURCE_FORMAT_BINARY,
"Texture", static_cast<uint32_t>(Fast::ResourceType::Texture), 0);
loader->RegisterResourceFactory(std::make_shared<MK64::ResourceFactoryBinaryTextureV1>(), RESOURCE_FORMAT_BINARY,
"Texture", static_cast<uint32_t>(Fast::ResourceType::Texture), 1);
loader->RegisterResourceFactory(std::make_shared<SM64::AnimationFactoryV0>(), RESOURCE_FORMAT_BINARY, "Animation",
static_cast<uint32_t>(SM64::ResourceType::Anim), 0);
loader->RegisterResourceFactory(std::make_shared<SM64::AudioBankFactoryV0>(), RESOURCE_FORMAT_BINARY, "AudioBank",
@@ -164,10 +171,10 @@ GameEngine::GameEngine() : dictionary(nullptr) {
static_cast<uint32_t>(SM64::ResourceType::SDialog), 0);
loader->RegisterResourceFactory(std::make_shared<SM64::DictionaryFactoryV0>(), RESOURCE_FORMAT_BINARY, "Dictionary",
static_cast<uint32_t>(SM64::ResourceType::Dictionary), 0);
loader->RegisterResourceFactory(std::make_shared<Fast::ResourceFactoryBinaryTextureV0>(), RESOURCE_FORMAT_BINARY,
"Texture", static_cast<uint32_t>(Fast::ResourceType::Texture), 0);
loader->RegisterResourceFactory(std::make_shared<Fast::ResourceFactoryBinaryTextureV1>(), RESOURCE_FORMAT_BINARY,
"Texture", static_cast<uint32_t>(Fast::ResourceType::Texture), 1);
// loader->RegisterResourceFactory(std::make_shared<Fast::ResourceFactoryBinaryTextureV0>(), RESOURCE_FORMAT_BINARY,
// "Texture", static_cast<uint32_t>(Fast::ResourceType::Texture), 0);
// loader->RegisterResourceFactory(std::make_shared<Fast::ResourceFactoryBinaryTextureV1>(), RESOURCE_FORMAT_BINARY,
// "Texture", static_cast<uint32_t>(Fast::ResourceType::Texture), 1);
loader->RegisterResourceFactory(std::make_shared<Fast::ResourceFactoryBinaryVertexV0>(), RESOURCE_FORMAT_BINARY,
"Vertex", static_cast<uint32_t>(Fast::ResourceType::Vertex), 0);
loader->RegisterResourceFactory(std::make_shared<Fast::ResourceFactoryBinaryDisplayListV0>(),
+3 -3
View File
@@ -243,7 +243,7 @@ void process_cmd_branch() {
if (param == 1) {
gGeoLayoutStack[gGeoLayoutStackIndex++] = reinterpret_cast<uintptr_t>(GeoLayoutParser::mReader);
SPDLOG_INFO("Branching and returning to {}:{}", name, gGeoLayoutStackIndex);
SPDLOG_TRACE("Branching and returning to {}:{}", name, gGeoLayoutStackIndex);
} else {
delete GeoLayoutParser::mReader;
}
@@ -254,7 +254,7 @@ void process_cmd_branch() {
void process_cmd_return() {
delete GeoLayoutParser::mReader;
GeoLayoutParser::mReader = reinterpret_cast<Ship::BinaryReader*>(gGeoLayoutStack[--gGeoLayoutStackIndex]);
SPDLOG_INFO("Returning to {}", gGeoLayoutStackIndex);
SPDLOG_TRACE("Returning to {}", gGeoLayoutStackIndex);
}
void process_cmd_open_node() {
@@ -456,7 +456,7 @@ void process_cmd_node_translation() {
if (params & 0x80) {
displayList = ResourceGetDataByCrc(ReadSafeCrc());
drawingLayer = params & 0x0F;
SPDLOG_INFO("Current Offset {}", GeoLayoutParser::mReader->GetBaseAddress());
SPDLOG_TRACE("Current Offset {}", GeoLayoutParser::mReader->GetBaseAddress());
}
GraphNodeTranslation* graphNode =
+15 -3
View File
@@ -3,6 +3,7 @@
#include "./types/AssetArray.h"
#include "spdlog/spdlog.h"
#include "ResourceUtil.h"
#include <fast/resource/ResourceType.h>
namespace SM64 {
std::shared_ptr<Ship::IResource>
@@ -12,14 +13,25 @@ ResourceFactoryBinaryAssetArrayV0::ReadResource(std::shared_ptr<Ship::File> file
return nullptr;
}
auto asset = std::make_shared<AssetArray>(initData);
auto array = std::make_shared<AssetArray>(initData);
auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader);
auto count = reader->ReadUInt32();
for (size_t i = 0; i < count; i++) {
asset->mPtrs.push_back(reinterpret_cast<uintptr_t>(ResourceGetDataByCrc(reader->ReadUInt64())));
auto asset = Ship::Context::GetInstance()->GetResourceManager()->LoadResource(reader->ReadUInt64());
if(asset != nullptr) {
auto data = asset->GetInitData();
if(data->Type == (uint32_t) Fast::ResourceType::Texture) {
array->mPaths.push_back("__OTR__"+data->Path);
array->mPtrs.push_back(reinterpret_cast<uintptr_t>(array->mPaths.back().c_str()));
} else {
array->mPtrs.push_back(reinterpret_cast<uintptr_t>(asset->GetRawPointer()));
}
} else {
array->mPtrs.push_back(0);
}
}
return asset;
return array;
}
} // namespace SM64
+91
View File
@@ -0,0 +1,91 @@
#include "RawTextureFactory.h"
#include "fast/resource/type/Texture.h"
#include "spdlog/spdlog.h"
#include <stb_image.h>
#include <ship/Context.h>
#include "ship/resource/archive/ArchiveManager.h"
#include "ship/resource/ResourceManager.h"
namespace MK64 {
std::shared_ptr<Ship::IResource> loadPngTexture(std::shared_ptr<Ship::File> filePng, std::shared_ptr<Ship::ResourceInitData> initData) {
auto texture = std::make_shared<Fast::Texture>(initData);
int height, width = 0;
texture->ImageData = stbi_load_from_memory((const stbi_uc*)filePng->Buffer.get()->data(),
filePng->Buffer.get()->size(), &width, &height, nullptr, 4);
texture->Width = width;
texture->Height = height;
texture->Type = Fast::TextureType::RGBA32bpp;
texture->ImageDataSize = texture->Width * texture->Height * 4;
texture->Flags = TEX_FLAG_LOAD_AS_IMG;
texture->VPixelScale = 1.0f;
texture->HByteScale = 1.0f;
return texture;
}
std::vector<std::string> extension = {".png", ".PNG", ".jpg", ".JPG", ".jpeg", ".JPEG", ".bmp", ".BMP"};
std::shared_ptr<Ship::IResource>
ResourceFactoryBinaryTextureV0::ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) {
if (!FileHasValidFormatAndReader(file, initData)) {
return nullptr;
}
for (const auto& ext : extension) {
auto filePng = Ship::Context::GetInstance()->GetResourceManager()->LoadFileProcess(
initData->Path + ext);
if (filePng != nullptr) {
return loadPngTexture(filePng, initData);
}
}
auto texture = std::make_shared<Fast::Texture>(initData);
auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader);
texture->Type = (Fast::TextureType)reader->ReadUInt32();
texture->Width = reader->ReadUInt32();
texture->Height = reader->ReadUInt32();
texture->ImageDataSize = reader->ReadUInt32();
texture->ImageData = new uint8_t[texture->ImageDataSize];
reader->Read((char*)texture->ImageData, texture->ImageDataSize);
return texture;
}
std::shared_ptr<Ship::IResource>
ResourceFactoryBinaryTextureV1::ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) {
if (!FileHasValidFormatAndReader(file, initData)) {
return nullptr;
}
for (const auto& ext : extension) {
auto filePng = Ship::Context::GetInstance()->GetResourceManager()->LoadFileProcess(
initData->Path + ext);
if (filePng != nullptr) {
return loadPngTexture(filePng, initData);
}
}
auto texture = std::make_shared<Fast::Texture>(initData);
auto reader = std::get<std::shared_ptr<Ship::BinaryReader>>(file->Reader);
texture->Type = (Fast::TextureType)reader->ReadUInt32();
texture->Width = reader->ReadUInt32();
texture->Height = reader->ReadUInt32();
texture->Flags = reader->ReadUInt32();
texture->HByteScale = reader->ReadFloat();
texture->VPixelScale = reader->ReadFloat();
texture->ImageDataSize = reader->ReadUInt32();
texture->ImageData = new uint8_t[texture->ImageDataSize];
reader->Read((char*)texture->ImageData, texture->ImageDataSize);
return texture;
}
} // namespace Fast
+18
View File
@@ -0,0 +1,18 @@
#pragma once
#include "ship/resource/Resource.h"
#include "ship/resource/ResourceFactoryBinary.h"
namespace MK64 {
class ResourceFactoryBinaryTextureV0 final : public Ship::ResourceFactoryBinary {
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) override;
};
class ResourceFactoryBinaryTextureV1 final : public Ship::ResourceFactoryBinary {
public:
std::shared_ptr<Ship::IResource> ReadResource(std::shared_ptr<Ship::File> file,
std::shared_ptr<Ship::ResourceInitData> initData) override;
};
} // namespace MK64
+1
View File
@@ -13,5 +13,6 @@ namespace SM64 {
size_t GetPointerSize();
std::vector<uintptr_t> mPtrs;
std::vector<std::string> mPaths;
};
}