Emscripten fixes

This commit is contained in:
Yousef Khadadeh 2026-05-14 14:39:34 +03:00
parent ad1844adc7
commit c083ccc1a9
9 changed files with 60 additions and 18 deletions

View file

@ -90,7 +90,7 @@ void ScreenshotTool::gui_toolbox(Toolbar& t) {
.onClick = [&] {
controls.selectionMode = ScreenshotControls::SelectionMode::NO_SELECTION;
#ifdef __EMSCRIPTEN__
take_screenshot("a" + controls.typeSelections[screenshotConfig.selectedType], screenshotConfig.selectedType);
take_screenshot("a" + world_screenshot_info_get_extension_from_type(screenshotConfig.selectedType), screenshotConfig.selectedType);
#else
// We can't actually use the extension from the callback, so we have to set the extension of choice beforehand
Screen::ExtensionFilter setExtensionFilter;

View file

@ -57,7 +57,6 @@ class SelectableButton : public Element {
bool instantResponse = false;
bool isHeld = false;
bool isHovering = false;
bool moved = false;
std::function<void()> onClick;
};

View file

@ -47,6 +47,7 @@ nlohmann::json GlobalConfig::get_config_json(const InputManager& input) const {
toRet["guiScale"] = guiScale;
toRet["jumpTransitionTime"] = jumpTransitionTime;
toRet["disableGraphicsDriverWorkarounds"] = disableGraphicsDriverWorkarounds;
toRet["viewWebVersionWelcome"] = viewWebVersionWelcome;
toRet["dragZoomSpeed"] = dragZoomSpeed;
toRet["scrollZoomSpeed"] = scrollZoomSpeed;
toRet["vsync"] = vsyncValue;
@ -122,6 +123,7 @@ void GlobalConfig::set_config_json(InputManager& input, const nlohmann::json& j,
try{j.at("guiScale").get_to(guiScale);} catch(...) {}
try{j.at("jumpTransitionTime").get_to(jumpTransitionTime);} catch(...) {}
try{j.at("disableGraphicsDriverWorkarounds").get_to(disableGraphicsDriverWorkarounds);} catch(...) {}
try{j.at("viewWebVersionWelcome").get_to(viewWebVersionWelcome);} catch(...) {}
try{j.at("useNativeFilePicker").get_to(useNativeFilePicker);} catch(...) {}
try{j.at("themeInUse").get_to(themeCurrentlyLoaded);} catch(...) {}
if(version >= VersionNumber(0, 3, 0))

View file

@ -43,13 +43,21 @@ class GlobalConfig {
std::filesystem::path configPath;
float guiScale = 1.0f;
#ifdef __ANDROID__
float guiScale = 1.2f;
#else
float guiScale = 1.0f;
#endif
double dragZoomSpeed = 0.02;
double scrollZoomSpeed = 0.4;
float jumpTransitionTime = 0.5f;
Vector4f jumpTransitionEasing{0.75, 0.25, 0.25, 0.75};
#ifdef __EMSCRIPTEN__
bool viewWebVersionWelcome = true;
#else
bool viewWebVersionWelcome = false;
#endif
struct TabletOptions {
bool pressureAffectsBrushWidth = true;

View file

@ -92,6 +92,7 @@ void MainProgram::update() {
g.update();
screen->update();
background_update();
NetThreadManager::get().synchronous_update();
post_callback();
}
@ -183,10 +184,6 @@ void MainProgram::load_config() {
}
catch(...) {}
} catch(...) {}
#ifdef __EMSCRIPTEN__
else
conf.viewWebVersionWelcome = true;
#endif
conf.load_palettes();
g.load_theme(conf.configPath, conf.themeCurrentlyLoaded);
conf.load_licenses();

View file

@ -14,10 +14,16 @@ void NetThreadManager::init(MainProgram* m) {
return;
started = true;
main = m;
#ifndef __ANDROID__
init_thread();
#else
#ifdef __ANDROID__
AndroidJNICalls::startNetworkService();
#else
NetLibrary::init_websocket();
#endif
}
void NetThreadManager::synchronous_update() {
#ifndef __ANDROID__
NetLibrary::update();
#endif
}
@ -71,9 +77,9 @@ void NetThreadManager::destroy() {
if(!started)
return;
started = false;
#ifndef __ANDROID__
destroy_thread();
#else
#ifdef __ANDROID__
AndroidJNICalls::stopNetworkService();
#else
NetLibrary::destroy_websocket();
#endif
}

View file

@ -9,6 +9,7 @@ class NetThreadManager {
public:
static NetThreadManager& get();
void init(MainProgram* m);
void synchronous_update();
void thread_update();
void destroy();
void init_thread();

View file

@ -108,11 +108,10 @@ void world_take_screenshot(const std::shared_ptr<World>& w, const WorldScreensho
}
#else
if(success) {
std::string mimeTypeArray[] = {"image/jpeg", "image/png", "image/webp"};
auto skData = out.detachAsData();
emscripten_browser_file::download(
"screenshot" + controls.typeSelections[screenshotType],
mimeTypeArray[screenshotType],
"screenshot" + world_screenshot_info_get_extension_from_type(info.type),
world_screenshot_info_get_mime_from_type(info.type),
std::string_view((const char*)skData->bytes(), skData->size())
);
}
@ -139,8 +138,8 @@ void world_take_screenshot(const std::shared_ptr<World>& w, const WorldScreensho
#else
auto skData = out.detachAsData();
emscripten_browser_file::download(
"screenshot.svg",
"image/svg+xml",
"screenshot" + world_screenshot_info_get_extension_from_type(info.type),
world_screenshot_info_get_mime_from_type(info.type),
std::string_view((const char*)skData->bytes(), skData->size())
);
#endif
@ -213,3 +212,31 @@ void take_screenshot_area_hw(const std::shared_ptr<World>& w, const sk_sp<SkSurf
if(!surface->readPixels(aaImgData, 0, 0))
throw std::runtime_error("[ScreenshotTool::take_screenshot_area_hw] Error copy pixmap");
}
std::string world_screenshot_info_get_extension_from_type(WorldScreenshotInfo::ScreenshotType t) {
switch(t) {
case WorldScreenshotInfo::ScreenshotType::JPG:
return ".jpg";
case WorldScreenshotInfo::ScreenshotType::PNG:
return ".png";
case WorldScreenshotInfo::ScreenshotType::WEBP:
return ".webp";
case WorldScreenshotInfo::ScreenshotType::SVG:
return ".svg";
}
return "";
}
std::string world_screenshot_info_get_mime_from_type(WorldScreenshotInfo::ScreenshotType t) {
switch(t) {
case WorldScreenshotInfo::ScreenshotType::JPG:
return "image/jpeg";
case WorldScreenshotInfo::ScreenshotType::PNG:
return "image/png";
case WorldScreenshotInfo::ScreenshotType::WEBP:
return "image/webp";
case WorldScreenshotInfo::ScreenshotType::SVG:
return "image/svg+xml";
}
return "";
}

View file

@ -45,3 +45,5 @@ NLOHMANN_JSON_SERIALIZE_ENUM(WorldScreenshotInfo::ScreenshotType, {
})
void world_take_screenshot(const std::shared_ptr<World>& w, const WorldScreenshotInfo& info);
std::string world_screenshot_info_get_extension_from_type(WorldScreenshotInfo::ScreenshotType t);
std::string world_screenshot_info_get_mime_from_type(WorldScreenshotInfo::ScreenshotType t);