Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions editor/Exporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <fstream>
#include <future>
#include <map>
#include <sstream>
#include <vector>

using namespace doriax;
Expand Down Expand Up @@ -2472,6 +2473,9 @@ bool editor::Exporter::copyEngine() {
projectSettings += indent + std::string("set(DORIAX_STOREKIT ") + (project->getIOSProjectSettings().storeKitEnabled ? "ON" : "OFF") + ")";
projectSettings += indent + "set(DORIAX_WEB_PORTAL " + Stream::webPortalTypeToString(project->getWebProjectSettings().portal) + ")";
projectSettings += indent + "set(DORIAX_WEB_PORTAL_GAME_ID \"" + escapeCMakeCString(project->getWebProjectSettings().portalGameId) + "\")";
std::ostringstream maxPixelRatio;
maxPixelRatio << project->getWebProjectSettings().maxPixelRatio;
projectSettings += indent + "set(DORIAX_WEB_MAX_PIXEL_RATIO " + maxPixelRatio.str() + ")";
cmakeContent.replace(projectSettingsPos, projectSettingsMarker.size(), projectSettings);
} else {
Out::warning("Exported CMakeLists.txt is missing the project settings marker; using platform defaults");
Expand Down
2 changes: 2 additions & 0 deletions editor/Project.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ namespace doriax::editor{
std::string headInclude;
bool resizeCanvasToWindow = true;
bool hideEmscriptenUI = false;
// Most framebuffer pixels per CSS pixel, 1 or more
float maxPixelRatio = 2.0f;
// Its SDK is loaded for the WebPortal class
WebPortalType portal = WebPortalType::NONE;
// For portals that identify the game, like GameDistribution
Expand Down
2 changes: 2 additions & 0 deletions editor/Stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2046,6 +2046,7 @@ YAML::Node editor::Stream::encodeProject(Project* project) {
if (!web.headInclude.empty()) webNode["headInclude"] = web.headInclude;
if (web.resizeCanvasToWindow != defaultWeb.resizeCanvasToWindow) webNode["resizeCanvasToWindow"] = web.resizeCanvasToWindow;
if (web.hideEmscriptenUI != defaultWeb.hideEmscriptenUI) webNode["hideEmscriptenUI"] = web.hideEmscriptenUI;
if (web.maxPixelRatio != defaultWeb.maxPixelRatio) webNode["maxPixelRatio"] = web.maxPixelRatio;
if (web.portal != defaultWeb.portal) webNode["portal"] = webPortalTypeToString(web.portal);
if (!web.portalGameId.empty()) webNode["portalGameId"] = web.portalGameId;
if (webNode.size() != 0) root["web"] = webNode;
Expand Down Expand Up @@ -2389,6 +2390,7 @@ void editor::Stream::decodeProject(Project* project, const YAML::Node& node, con
if (webNode["headInclude"]) web.headInclude = webNode["headInclude"].as<std::string>();
if (webNode["resizeCanvasToWindow"].IsDefined()) web.resizeCanvasToWindow = webNode["resizeCanvasToWindow"].as<bool>();
if (webNode["hideEmscriptenUI"].IsDefined()) web.hideEmscriptenUI = webNode["hideEmscriptenUI"].as<bool>();
if (webNode["maxPixelRatio"]) web.maxPixelRatio = std::max(1.0f, webNode["maxPixelRatio"].as<float>());
if (webNode["portal"]) web.portal = stringToWebPortalType(webNode["portal"].as<std::string>());
if (webNode["portalGameId"]) web.portalGameId = webNode["portalGameId"].as<std::string>();
}
Expand Down
3 changes: 2 additions & 1 deletion editor/ai/EditorActionExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7542,6 +7542,7 @@ ActionResult EditorActionExecutor::setProjectSettings(const Json& arguments) {
WebProjectSettings& web = project->getWebProjectSettings();
if (arguments.contains("web_resize_canvas")) web.resizeCanvasToWindow = arguments["web_resize_canvas"].get<bool>();
if (arguments.contains("web_hide_emscripten_ui")) web.hideEmscriptenUI = arguments["web_hide_emscripten_ui"].get<bool>();
if (arguments.contains("web_max_pixel_ratio")) web.maxPixelRatio = arguments["web_max_pixel_ratio"].get<float>();

if (!project->saveProjectFile()) {
return failResult("Failed to save the project settings.");
Expand All @@ -7554,7 +7555,7 @@ ActionResult EditorActionExecutor::setProjectSettings(const Json& arguments) {
{"window", {{"width", project->getWindowWidth()}, {"height", project->getWindowHeight()}}},
{"vsync", project->isVSyncEnabled()},
{"loading", loadingSettingsJson(project->getLoadingSettings())},
{"web", {{"resize_canvas", web.resizeCanvasToWindow}, {"hide_emscripten_ui", web.hideEmscriptenUI}}}});
{"web", {{"resize_canvas", web.resizeCanvasToWindow}, {"hide_emscripten_ui", web.hideEmscriptenUI}, {"max_pixel_ratio", web.maxPixelRatio}}}});
}

ActionResult EditorActionExecutor::createProject(const Json& arguments) {
Expand Down
6 changes: 5 additions & 1 deletion editor/ai/EditorActionRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,8 @@ const std::vector<ToolDefinition>& cachedTools() {
{"loading_timeout", numberSchema("Seconds without load progress before a load stops waiting")},
{"async_loading", boolSchema("Load files on worker threads while the loading scene is shown")},
{"web_resize_canvas", boolSchema("Web export: the canvas fills the browser window")},
{"web_hide_emscripten_ui", boolSchema("Web export: hide the Emscripten logo, status and console around the canvas")}
{"web_hide_emscripten_ui", boolSchema("Web export: hide the Emscripten logo, status and console around the canvas")},
{"web_max_pixel_ratio", numberSchema("Web export: most pixels drawn per CSS pixel on phones and HiDPI screens, 1 or more. Lower costs less GPU time")}
}),
false
},
Expand Down Expand Up @@ -2030,6 +2031,9 @@ ValidationResult EditorActionRegistry::validate(const std::string& name, const J
return fail(std::string("set_project_settings ") + key + " must be a non-negative number.");
}
}
if (arguments.contains("web_max_pixel_ratio") && (!arguments["web_max_pixel_ratio"].is_number() || arguments["web_max_pixel_ratio"].get<double>() < 1.0)) {
return fail("set_project_settings web_max_pixel_ratio must be a number of at least 1.");
}
for (const char* key : {"vsync", "async_loading", "web_resize_canvas", "web_hide_emscripten_ui"}) {
if (arguments.contains(key) && !arguments[key].is_boolean()) {
return fail(std::string("set_project_settings ") + key + " must be a boolean.");
Expand Down
11 changes: 11 additions & 0 deletions editor/window/dialog/ProjectSettingsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,7 @@ void ProjectSettingsWindow::open(Project* project) {
snprintf(m_webHeadIncludeBuffer, sizeof(m_webHeadIncludeBuffer), "%s", web.headInclude.c_str());
m_webResizeCanvasToWindow = web.resizeCanvasToWindow;
m_webHideEmscriptenUI = web.hideEmscriptenUI;
m_webMaxPixelRatio = web.maxPixelRatio;
m_webPortalIndex = findWebPortalIndex(web.portal);
snprintf(m_webPortalGameIdBuffer, sizeof(m_webPortalGameIdBuffer), "%s", web.portalGameId.c_str());

Expand Down Expand Up @@ -1418,6 +1419,15 @@ void ProjectSettingsWindow::drawWebSettings() {
ImGui::Checkbox("##WebHideEmscriptenUI", &m_webHideEmscriptenUI);
endSettingsRow("Hide the standard logo, status, controls and output console. Runtime scripts remain active. Custom HTML elements are not removed.");

const WebProjectSettings defaults;
if (beginSettingsRow("Max Pixel Ratio", m_webMaxPixelRatio != defaults.maxPixelRatio)) {
m_webMaxPixelRatio = defaults.maxPixelRatio;
}
ImGui::SetNextItemWidth(-helpMarkerWidth());
UIUtils::inputFloat("##WebMaxPixelRatio", &m_webMaxPixelRatio, 0.25f, 1.0f, "%.2f");
m_webMaxPixelRatio = std::isfinite(m_webMaxPixelRatio) ? std::max(m_webMaxPixelRatio, 1.0f) : defaults.maxPixelRatio;
endSettingsRow("Most pixels drawn per CSS pixel on phones and HiDPI screens. Higher is sharper and costs more GPU time. 1 ignores the screen density.");

drawComboSetting("Game Portal", "##WebPortal", webPortalNames, webPortalCount, m_webPortalIndex, findWebPortalIndex(WebPortalType::NONE),
"Loads this portal's SDK for the WebPortal class: ads and gameplay events. Each portal needs its own export.");

Expand Down Expand Up @@ -1756,6 +1766,7 @@ bool ProjectSettingsWindow::applySettings() {
applyTextBuffer(web.headInclude, m_webHeadIncludeBuffer);
web.resizeCanvasToWindow = m_webResizeCanvasToWindow;
web.hideEmscriptenUI = m_webHideEmscriptenUI;
web.maxPixelRatio = m_webMaxPixelRatio;
web.portal = webPortalValues[std::clamp(m_webPortalIndex, 0, webPortalCount - 1)];
applyTextBuffer(web.portalGameId, m_webPortalGameIdBuffer);

Expand Down
1 change: 1 addition & 0 deletions editor/window/dialog/ProjectSettingsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ namespace doriax::editor {
char m_webHeadIncludeBuffer[2048] = {0};
bool m_webResizeCanvasToWindow = true;
bool m_webHideEmscriptenUI = false;
float m_webMaxPixelRatio = 2.0f;
int m_webPortalIndex = 0;
char m_webPortalGameIdBuffer[128] = {0};
char m_linuxApplicationNameBuffer[256] = {0};
Expand Down
8 changes: 6 additions & 2 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ set(DORIAX_WEB_PORTALS none crazygames poki gamedistribution yandex youtube)
set(DORIAX_WEB_PORTAL none CACHE STRING "Game portal SDK of web builds")
set_property(CACHE DORIAX_WEB_PORTAL PROPERTY STRINGS ${DORIAX_WEB_PORTALS})
set(DORIAX_WEB_PORTAL_GAME_ID "" CACHE STRING "Game ID for web portals that need one, like GameDistribution")
set(DORIAX_WEB_MAX_PIXEL_RATIO 2 CACHE STRING "Most framebuffer pixels per CSS pixel of web builds")

# =============================================================
# STANDALONE PROJECT SETUP
Expand Down Expand Up @@ -212,10 +213,13 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
endif()
if(NOT DORIAX_WEB_PORTAL STREQUAL "none")
string(TOUPPER "${DORIAX_WEB_PORTAL}" WEB_PORTAL_NAME)
# only WebPortals.cpp reads them, so switching portals rebuilds that file alone
set_property(SOURCE ${DORIAX_ROOT}/platform/emscripten/WebPortals.cpp APPEND PROPERTY COMPILE_DEFINITIONS
# only these files read them, so switching portals rebuilds no other
set_property(SOURCE ${DORIAX_ROOT}/platform/emscripten/WebPortals.cpp ${DORIAX_ROOT}/platform/emscripten/DoriaxWeb.cpp
APPEND PROPERTY COMPILE_DEFINITIONS
"DORIAX_WEB_PORTAL_${WEB_PORTAL_NAME}" "DORIAX_WEB_PORTAL_GAME_ID=\"${DORIAX_WEB_PORTAL_GAME_ID}\"")
endif()
set_property(SOURCE ${DORIAX_ROOT}/platform/emscripten/DoriaxWeb.cpp APPEND PROPERTY COMPILE_DEFINITIONS
"DORIAX_WEB_MAX_PIXEL_RATIO=${DORIAX_WEB_MAX_PIXEL_RATIO}")

set(CMAKE_EXECUTABLE_SUFFIX ".html")

Expand Down
5 changes: 3 additions & 2 deletions engine/core/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1323,13 +1323,14 @@ void Engine::systemShutdown(){
}

void Engine::systemPause(){
AudioSystem::pauseAll();
// first, so audio the game pauses here stays paused after the resume
Engine::onPause.call();
AudioSystem::systemPause();
paused = true;
}

void Engine::systemResume(){
AudioSystem::resumeAll();
AudioSystem::systemResume();
Engine::onResume.call();
paused = false;
}
Expand Down
27 changes: 27 additions & 0 deletions engine/core/subsystem/AudioSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ bool AudioSystem::inited = false;
float AudioSystem::globalVolume = 1.0;
bool AudioSystem::muted = false;

std::vector<unsigned int> AudioSystem::systemPausedVoices;

AudioSystem::AudioSystem(Scene* scene): SubSystem(scene){
signature.set(scene->getComponentId<SoundComponent>());

Expand Down Expand Up @@ -215,6 +217,31 @@ void AudioSystem::resumeAll(){
}
}

void AudioSystem::systemPause(){
if (!inited) {
return;
}

SoLoud::Soloud& soloud = getSoloud();
soloud.lockAudioMutex_internal();
for (unsigned int i = 0; i < soloud.mHighestVoice; i++) {
if (soloud.mVoice[i] && !(soloud.mVoice[i]->mFlags & SoLoud::AudioSourceInstance::PAUSED)) {
systemPausedVoices.push_back(soloud.getHandleFromVoice_internal(i));
soloud.setVoicePause_internal(i, true);
}
}
soloud.unlockAudioMutex_internal();
}

void AudioSystem::systemResume(){
if (inited) {
for (unsigned int handle : systemPausedVoices) {
getSoloud().setPause(handle, false);
}
}
systemPausedVoices.clear();
}

void AudioSystem::checkActive(){
if (inited) {
if (getSoloud().getVoiceCount() == 0){
Expand Down
11 changes: 11 additions & 0 deletions engine/core/subsystem/AudioSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include "component/SoundComponent.h"

#include <vector>

namespace SoLoud{
class Soloud;
}
Expand All @@ -16,6 +18,8 @@ namespace doriax{

class DORIAX_API AudioSystem : public SubSystem {

friend class Engine;

private:
static bool inited;

Expand All @@ -24,6 +28,13 @@ namespace doriax{
static float globalVolume;
static bool muted;

// voices to resume, the game's own pauses are kept
static std::vector<unsigned int> systemPausedVoices;

// Called by Engine
static void systemPause();
static void systemResume();

Vector3 cameraLastPosition;
bool outputRequested = false;

Expand Down
Loading
Loading