mirror of
https://github.com/isledecomp/isle-portable.git
synced 2025-08-02 23:26:16 -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);
|
||||
}
|
||||
|
||||
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"
|
||||
|
||||
void Emscripten_SendPresenterProgress(MxDSAction* p_action, MxPresenter::TickleState p_tickleState);
|
||||
void Emscripten_SendExtensionProgress(const char* p_extension, MxU32 p_progress);
|
||||
|
||||
#endif // EMSCRIPTEN_EVENTS_H
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "filesystem.h"
|
||||
|
||||
#include "events.h"
|
||||
#include "extensions/textureloader.h"
|
||||
#include "legogamestate.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) {
|
||||
registerFile(file);
|
||||
}
|
||||
@ -84,9 +94,17 @@ void Emscripten_SetupFilesystem()
|
||||
Extensions::TextureLoader::options["texture loader:texture path"] = directory.GetData();
|
||||
wasmfs_create_directory(directory.GetData(), 0644, fetchfs);
|
||||
|
||||
MxU32 i = 0;
|
||||
Emscripten_SendExtensionProgress("HD Textures", 0);
|
||||
for (const char* file : g_textures) {
|
||||
MxString path = directory + "/" + file + ".bmp";
|
||||
registerFile(path.GetData());
|
||||
|
||||
if (!preloadFile(path.GetData())) {
|
||||
Extensions::TextureLoader::excludedFiles.emplace_back(file);
|
||||
}
|
||||
|
||||
Emscripten_SendExtensionProgress("HD Textures", (++i * 100) / sizeOfArray(g_textures));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include <array>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
namespace Extensions
|
||||
{
|
||||
@ -14,6 +15,7 @@ public:
|
||||
static bool PatchTexture(LegoTextureInfo* p_textureInfo);
|
||||
|
||||
static std::map<std::string, std::string> options;
|
||||
static std::vector<std::string> excludedFiles;
|
||||
static bool enabled;
|
||||
|
||||
static constexpr std::array<std::pair<std::string_view, std::string_view>, 1> defaults = {
|
||||
|
@ -3,6 +3,7 @@
|
||||
using namespace Extensions;
|
||||
|
||||
std::map<std::string, std::string> TextureLoader::options;
|
||||
std::vector<std::string> TextureLoader::excludedFiles;
|
||||
bool TextureLoader::enabled = false;
|
||||
|
||||
void TextureLoader::Initialize()
|
||||
@ -97,6 +98,10 @@ bool TextureLoader::PatchTexture(LegoTextureInfo* p_textureInfo)
|
||||
|
||||
SDL_Surface* TextureLoader::FindTexture(const char* p_name)
|
||||
{
|
||||
if (std::find(excludedFiles.begin(), excludedFiles.end(), p_name) != excludedFiles.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SDL_Surface* surface;
|
||||
const char* texturePath = options["texture loader:texture path"].c_str();
|
||||
MxString path = MxString(MxOmni::GetHD()) + texturePath + "/" + p_name + ".bmp";
|
||||
|
Loading…
x
Reference in New Issue
Block a user