mirror of
https://github.com/isledecomp/isle-portable.git
synced 2025-08-03 07:36:20 -04:00
(Web port) Improve loading UX for HD Textures (#648)
This commit is contained in:
parent
7473330e47
commit
89f2f5cefe
@ -36,3 +36,11 @@ void Emscripten_SendPresenterProgress(MxDSAction* p_action, MxPresenter::TickleS
|
|||||||
|
|
||||||
Emscripten_SendEvent("presenterProgress", buf);
|
Emscripten_SendEvent("presenterProgress", buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Emscripten_SendExtensionProgress(const char* p_extension, MxU32 p_progress)
|
||||||
|
{
|
||||||
|
char buf[128];
|
||||||
|
SDL_snprintf(buf, sizeof(buf), "{\"name\": \"%s\", \"progress\": %d}", p_extension, p_progress);
|
||||||
|
|
||||||
|
Emscripten_SendEvent("extensionProgress", buf);
|
||||||
|
}
|
||||||
|
@ -4,5 +4,6 @@
|
|||||||
#include "mxpresenter.h"
|
#include "mxpresenter.h"
|
||||||
|
|
||||||
void Emscripten_SendPresenterProgress(MxDSAction* p_action, MxPresenter::TickleState p_tickleState);
|
void Emscripten_SendPresenterProgress(MxDSAction* p_action, MxPresenter::TickleState p_tickleState);
|
||||||
|
void Emscripten_SendExtensionProgress(const char* p_extension, MxU32 p_progress);
|
||||||
|
|
||||||
#endif // EMSCRIPTEN_EVENTS_H
|
#endif // EMSCRIPTEN_EVENTS_H
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "filesystem.h"
|
#include "filesystem.h"
|
||||||
|
|
||||||
|
#include "events.h"
|
||||||
#include "extensions/textureloader.h"
|
#include "extensions/textureloader.h"
|
||||||
#include "legogamestate.h"
|
#include "legogamestate.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
@ -73,6 +74,15 @@ void Emscripten_SetupFilesystem()
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const auto preloadFile = [](const char* p_path) -> bool {
|
||||||
|
size_t length = 0;
|
||||||
|
void* data = SDL_LoadFile(p_path, &length);
|
||||||
|
if (data) {
|
||||||
|
SDL_free(data);
|
||||||
|
}
|
||||||
|
return length > 0;
|
||||||
|
};
|
||||||
|
|
||||||
for (const char* file : g_files) {
|
for (const char* file : g_files) {
|
||||||
registerFile(file);
|
registerFile(file);
|
||||||
}
|
}
|
||||||
@ -84,9 +94,17 @@ void Emscripten_SetupFilesystem()
|
|||||||
Extensions::TextureLoader::options["texture loader:texture path"] = directory.GetData();
|
Extensions::TextureLoader::options["texture loader:texture path"] = directory.GetData();
|
||||||
wasmfs_create_directory(directory.GetData(), 0644, fetchfs);
|
wasmfs_create_directory(directory.GetData(), 0644, fetchfs);
|
||||||
|
|
||||||
|
MxU32 i = 0;
|
||||||
|
Emscripten_SendExtensionProgress("HD Textures", 0);
|
||||||
for (const char* file : g_textures) {
|
for (const char* file : g_textures) {
|
||||||
MxString path = directory + "/" + file + ".bmp";
|
MxString path = directory + "/" + file + ".bmp";
|
||||||
registerFile(path.GetData());
|
registerFile(path.GetData());
|
||||||
|
|
||||||
|
if (!preloadFile(path.GetData())) {
|
||||||
|
Extensions::TextureLoader::excludedFiles.emplace_back(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
Emscripten_SendExtensionProgress("HD Textures", (++i * 100) / sizeOfArray(g_textures));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace Extensions
|
namespace Extensions
|
||||||
{
|
{
|
||||||
@ -14,6 +15,7 @@ public:
|
|||||||
static bool PatchTexture(LegoTextureInfo* p_textureInfo);
|
static bool PatchTexture(LegoTextureInfo* p_textureInfo);
|
||||||
|
|
||||||
static std::map<std::string, std::string> options;
|
static std::map<std::string, std::string> options;
|
||||||
|
static std::vector<std::string> excludedFiles;
|
||||||
static bool enabled;
|
static bool enabled;
|
||||||
|
|
||||||
static constexpr std::array<std::pair<std::string_view, std::string_view>, 1> defaults = {
|
static constexpr std::array<std::pair<std::string_view, std::string_view>, 1> defaults = {
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
using namespace Extensions;
|
using namespace Extensions;
|
||||||
|
|
||||||
std::map<std::string, std::string> TextureLoader::options;
|
std::map<std::string, std::string> TextureLoader::options;
|
||||||
|
std::vector<std::string> TextureLoader::excludedFiles;
|
||||||
bool TextureLoader::enabled = false;
|
bool TextureLoader::enabled = false;
|
||||||
|
|
||||||
void TextureLoader::Initialize()
|
void TextureLoader::Initialize()
|
||||||
@ -97,6 +98,10 @@ bool TextureLoader::PatchTexture(LegoTextureInfo* p_textureInfo)
|
|||||||
|
|
||||||
SDL_Surface* TextureLoader::FindTexture(const char* p_name)
|
SDL_Surface* TextureLoader::FindTexture(const char* p_name)
|
||||||
{
|
{
|
||||||
|
if (std::find(excludedFiles.begin(), excludedFiles.end(), p_name) != excludedFiles.end()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
SDL_Surface* surface;
|
SDL_Surface* surface;
|
||||||
const char* texturePath = options["texture loader:texture path"].c_str();
|
const char* texturePath = options["texture loader:texture path"].c_str();
|
||||||
MxString path = MxString(MxOmni::GetHD()) + texturePath + "/" + p_name + ".bmp";
|
MxString path = MxString(MxOmni::GetHD()) + texturePath + "/" + p_name + ".bmp";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user