Repository navigation
Web: sharp rendering on HiDPI screens and pause while the page is hidden - #146
Merged
eduardodoria merged 1 commit intoNov 23, 2026
Merged
Conversation
The web framebuffer follows devicePixelRatio, up to the new DORIAX_WEB_MAX_PIXEL_RATIO (2 by default, Max Pixel Ratio in the editor), and input is scaled to framebuffer pixels. The game pauses while the page is hidden, through one pause control shared with ads, portals and WebGL context loss. A system pause resumes only the sounds it paused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
I published a Doriax 0.8.5 game on itch.io for the Doriax Flash Jam 2026 and found two problems on phones:
DoriaxWeb::renderLoopsizes the framebuffer with the CSS size of the canvas. On a phone with 800×360 CSS pixels at 3 device pixels per CSS pixel, the framebuffer is 800×360, a 1280×720 letterboxed game is drawn in 640×360, and the browser stretches it 3×. Text suffers most.requestAnimationFrameon a hidden page, but SoLoud mixes in its own audio callback.Engine::systemPauseexists, but nothing calls it for page visibility on the web.Fix
HiDPI framebuffer
DoriaxWeb::updateFramebufferSizereplaces the sizing block inrenderLoop. Each frame:width/heightattributes, so multiplying it would grow the canvas every frame. After a resize the CSS size is measured again and, if it followed the attributes, it is fixed at its previous size.visualViewport.scalekeeps the game from drawing more pixels than the screen has.pixelRatio, so a captured cursor moves at the same speed at every density.EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_NONE, and the render loop sizes the framebuffer like any other change.changeCanvasSize(exported to the page) now sets the canvas CSS size; the framebuffer follows on the next frame.Pause while hidden
DoriaxWeb::setPaused(PauseReason, bool)is the only place the web platform pauses and resumes the engine. Reasons:AD,PORTAL,HIDDEN,CONTEXT_LOST; the game resumes when none is left. The two flagsWebPortals.cppkept for ads and portals moved into it, and the WebGL context callbacks use it too, so a tab switch during an ad no longer resumes the game early.visibilitychangecallback setsHIDDEN. When the page hides, a pending IndexedDB sync runs at once, so a file saved inonPauseis not lost if the tab is closed.unregisterCallbacks(it would otherwise reach a closed Lua state afterSystem::quit).#ifndef DORIAX_WEB_PORTAL_YOUTUBE.Audio pause (all platforms)
Engine::systemPause/systemResumeusedAudioSystem::pauseAll/resumeAll, and SoLoud's resume-all also restarts sounds the game had paused itself (already an issue on Android and iOS when returning from background). New privateAudioSystem::systemPause/systemResume(reached throughfriend class Engine) remember the voices that were playing and resume only those.Engine::systemPausenow callsonPausebefore pausing audio, so a game that callsAudioSystem.pauseAll()inonPausestays silent after resuming.pauseAll/resumeAllkeep their meaning for games.Build option and editor
engine/CMakeLists.txt: cache variableDORIAX_WEB_MAX_PIXEL_RATIO(default 2), passed toDoriaxWeb.cpponly. The portal definitions now also reachDoriaxWeb.cpp, for the YouTube guard.web.maxPixelRatioinproject.yaml, minimum 1), exported to the generatedCMakeLists.txt. The AI/MCP toolset_project_settingsacceptsweb_max_pixel_ratio.Behaviour changes
NATIVEscaling on the web, canvas units are device pixels (up to the limit).System::getScreenWidth/getScreenHeightreturn the framebuffer size, which is no longer the CSS size on those screens.onPauseruns just before audio pauses, not after.changeCanvasSizesees the new size one frame later.Testing
changeCanvasSizefrom the page, density changes while running, pages without a viewport tag, an iframe, real tab switches with the audio output measured, and every pair of pause reasons — 156 checks pass.Engine::systemPause/systemResumeagainstlibdoriax.sowith three voices, including 4000 quick toggles against the audio thread.Not changed
Sound::isPlaying()returns false for a looping sound after its first pass.resize_callbackinDoriaxWeb.cppstill passes framebuffer pixels tochangeCanvasSize(it is never registered).🤖 Generated with Claude Code