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 = [&] { .onClick = [&] {
controls.selectionMode = ScreenshotControls::SelectionMode::NO_SELECTION; controls.selectionMode = ScreenshotControls::SelectionMode::NO_SELECTION;
#ifdef __EMSCRIPTEN__ #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 #else
// We can't actually use the extension from the callback, so we have to set the extension of choice beforehand // We can't actually use the extension from the callback, so we have to set the extension of choice beforehand
Screen::ExtensionFilter setExtensionFilter; Screen::ExtensionFilter setExtensionFilter;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -108,11 +108,10 @@ void world_take_screenshot(const std::shared_ptr<World>& w, const WorldScreensho
} }
#else #else
if(success) { if(success) {
std::string mimeTypeArray[] = {"image/jpeg", "image/png", "image/webp"};
auto skData = out.detachAsData(); auto skData = out.detachAsData();
emscripten_browser_file::download( emscripten_browser_file::download(
"screenshot" + controls.typeSelections[screenshotType], "screenshot" + world_screenshot_info_get_extension_from_type(info.type),
mimeTypeArray[screenshotType], world_screenshot_info_get_mime_from_type(info.type),
std::string_view((const char*)skData->bytes(), skData->size()) 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 #else
auto skData = out.detachAsData(); auto skData = out.detachAsData();
emscripten_browser_file::download( emscripten_browser_file::download(
"screenshot.svg", "screenshot" + world_screenshot_info_get_extension_from_type(info.type),
"image/svg+xml", world_screenshot_info_get_mime_from_type(info.type),
std::string_view((const char*)skData->bytes(), skData->size()) std::string_view((const char*)skData->bytes(), skData->size())
); );
#endif #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)) if(!surface->readPixels(aaImgData, 0, 0))
throw std::runtime_error("[ScreenshotTool::take_screenshot_area_hw] Error copy pixmap"); 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); 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);