From f813c0ded225d13ba5a173b4377b53faaa15f709 Mon Sep 17 00:00:00 2001 From: Luiz Bills Date: Thu, 19 Jun 2025 12:28:56 -0300 Subject: [PATCH 1/4] improve game loop --- src/index.js | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/index.js b/src/index.js index 4b39cd1..5cc8db4 100644 --- a/src/index.js +++ b/src/index.js @@ -1401,29 +1401,26 @@ export default function litecanvas(settings = {}) { * @param {DOMHighResTimeStamp} now */ function drawFrame(now) { - let updated = 0, - frameTime = (now - _lastFrameTime) / 1000 + let updated = 0 _lastFrameTime = now if (settings.animate) { - if (frameTime > 0.3) { - console.warn('skipping too long frame') - } else { - _accumulated += frameTime + _accumulated += math.min(0.2, (now - _lastFrameTime) / 1000) - while (_accumulated >= _deltaTime) { - updated++ - instance.emit('update', _deltaTime * _timeScale, updated) - instance.def('T', instance.T + _deltaTime * _timeScale) - _accumulated -= _deltaTime - } + while (_accumulated >= _deltaTime) { + updated++ + instance.emit('update', _deltaTime * _timeScale, updated) + instance.def('T', instance.T + _deltaTime * _timeScale) + _accumulated -= _deltaTime } // request the next frame // check if the last ID exists, because // quit() delete it (sets to zero) - if (_rafid) _rafid = raf(drawFrame) + if (_rafid) { + _rafid = raf(drawFrame) + } } else { // when the canvas is not animated // we force one frame when redraws are triggered From de0237152096a08135a39a2b105e1a0a6d9f188f Mon Sep 17 00:00:00 2001 From: Luiz Bills Date: Thu, 19 Jun 2025 12:29:54 -0300 Subject: [PATCH 2/4] update deps --- bun.lock | 22 +++++++++++----------- package.json | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/bun.lock b/bun.lock index e3e770b..2b52e99 100644 --- a/bun.lock +++ b/bun.lock @@ -84,27 +84,27 @@ "@sindresorhus/merge-streams": ["@sindresorhus/merge-streams@2.3.0", "", {}, "sha512-LtoMMhxAlorcGhmFYI+LhPgbPZCkgP6ra1YL604EeF6U98pLlQ3iWIGMdWSC+vWmPBWBNgmDBAhnAobLROJmwg=="], - "@swc/core": ["@swc/core@1.12.1", "", { "dependencies": { "@swc/counter": "^0.1.3", "@swc/types": "^0.1.23" }, "optionalDependencies": { "@swc/core-darwin-arm64": "1.12.1", "@swc/core-darwin-x64": "1.12.1", "@swc/core-linux-arm-gnueabihf": "1.12.1", "@swc/core-linux-arm64-gnu": "1.12.1", "@swc/core-linux-arm64-musl": "1.12.1", "@swc/core-linux-x64-gnu": "1.12.1", "@swc/core-linux-x64-musl": "1.12.1", "@swc/core-win32-arm64-msvc": "1.12.1", "@swc/core-win32-ia32-msvc": "1.12.1", "@swc/core-win32-x64-msvc": "1.12.1" }, "peerDependencies": { "@swc/helpers": ">=0.5.17" }, "optionalPeers": ["@swc/helpers"] }, "sha512-aKXdDTqxTVFl/bKQZ3EQUjEMBEoF6JBv29moMZq0kbVO43na6u/u+3Vcbhbrh+A2N0X5OL4RaveuWfAjEgOmeA=="], + "@swc/core": ["@swc/core@1.12.3", "", { "dependencies": { "@swc/counter": "^0.1.3", "@swc/types": "^0.1.23" }, "optionalDependencies": { "@swc/core-darwin-arm64": "1.12.3", "@swc/core-darwin-x64": "1.12.3", "@swc/core-linux-arm-gnueabihf": "1.12.3", "@swc/core-linux-arm64-gnu": "1.12.3", "@swc/core-linux-arm64-musl": "1.12.3", "@swc/core-linux-x64-gnu": "1.12.3", "@swc/core-linux-x64-musl": "1.12.3", "@swc/core-win32-arm64-msvc": "1.12.3", "@swc/core-win32-ia32-msvc": "1.12.3", "@swc/core-win32-x64-msvc": "1.12.3" }, "peerDependencies": { "@swc/helpers": ">=0.5.17" }, "optionalPeers": ["@swc/helpers"] }, "sha512-c4NeXW8P3gPqcFwtm+4aH+F2Cj5KJLMiLaKhSj3mpv19glq+jmekomdktAw/VHyjsXlsmouOeNWrk8rVlkCRsg=="], - "@swc/core-darwin-arm64": ["@swc/core-darwin-arm64@1.12.1", "", { "os": "darwin", "cpu": "arm64" }, "sha512-nUjWVcJ3YS2N40ZbKwYO2RJ4+o2tWYRzNOcIQp05FqW0+aoUCVMdAUUzQinPDynfgwVshDAXCKemY8X7nN5MaA=="], + "@swc/core-darwin-arm64": ["@swc/core-darwin-arm64@1.12.3", "", { "os": "darwin", "cpu": "arm64" }, "sha512-QCV9vQ/s27AMxm8j8MTDL/nDoiEMrANiENRrWnb0Fxvz/O39CajPVShp/W7HlOkzt1GYtUXPdQJpSKylugfrWw=="], - "@swc/core-darwin-x64": ["@swc/core-darwin-x64@1.12.1", "", { "os": "darwin", "cpu": "x64" }, "sha512-OGm4a4d3OeJn+tRt8H/eiHgTFrJbS6r8mi/Ob65tAEXZGHN900T2kR7c5ALr0V2hBOQ8BfhexwPoQlGQP/B95w=="], + "@swc/core-darwin-x64": ["@swc/core-darwin-x64@1.12.3", "", { "os": "darwin", "cpu": "x64" }, "sha512-LylCMfzGhdvl5tyKaTT9ePetHUX7wSsST7hxWiHzS+cUMj7FnhcfdEr6kcNVT7y1RJn3fCvuv7T98ZB+T2q3HA=="], - "@swc/core-linux-arm-gnueabihf": ["@swc/core-linux-arm-gnueabihf@1.12.1", "", { "os": "linux", "cpu": "arm" }, "sha512-76YeeQKyK0EtNkQiNBZ0nbVGooPf9IucY0WqVXVpaU4wuG7ZyLEE2ZAIgXafIuzODGQoLfetue7I8boMxh1/MA=="], + "@swc/core-linux-arm-gnueabihf": ["@swc/core-linux-arm-gnueabihf@1.12.3", "", { "os": "linux", "cpu": "arm" }, "sha512-DQODb7S+q+pwQY41Azcavwb2rb4rGxP70niScRDxB9X68hHOM9D0w9fxzC+Nr3AHcPSmVJUYUIiq5h38O5hVgQ=="], - "@swc/core-linux-arm64-gnu": ["@swc/core-linux-arm64-gnu@1.12.1", "", { "os": "linux", "cpu": "arm64" }, "sha512-BxJDIJPq1+aCh9UsaSAN6wo3tuln8UhNXruOrzTI8/ElIig/3sAueDM6Eq7GvZSGGSA7ljhNATMJ0elD7lFatQ=="], + "@swc/core-linux-arm64-gnu": ["@swc/core-linux-arm64-gnu@1.12.3", "", { "os": "linux", "cpu": "arm64" }, "sha512-nTxtJSq78AjeaQBueYImoFBs5j7qXbgOxtirpyt8jE29NQBd0VFzDzRBhkr6I9jq0hNiChgMkqBN4eUkEQjytg=="], - "@swc/core-linux-arm64-musl": ["@swc/core-linux-arm64-musl@1.12.1", "", { "os": "linux", "cpu": "arm64" }, "sha512-NhLdbffSXvY0/FwUSAl4hKBlpe5GHQGXK8DxTo3HHjLsD9sCPYieo3vG0NQoUYAy4ZUY1WeGjyxeq4qZddJzEQ=="], + "@swc/core-linux-arm64-musl": ["@swc/core-linux-arm64-musl@1.12.3", "", { "os": "linux", "cpu": "arm64" }, "sha512-lBGvC5UgPSxqLr/y1NZxQhyRQ7nXy3/Ec1Z47YNXtqtpKiG1EcOGPyS0UZgwiYQkXqq8NBFMHnyHmpKnXTvRDA=="], - "@swc/core-linux-x64-gnu": ["@swc/core-linux-x64-gnu@1.12.1", "", { "os": "linux", "cpu": "x64" }, "sha512-CrYnV8SZIgArQ9LKH0xEF95PKXzX9WkRSc5j55arOSBeDCeDUQk1Bg/iKdnDiuj5HC1hZpvzwMzSBJjv+Z70jA=="], + "@swc/core-linux-x64-gnu": ["@swc/core-linux-x64-gnu@1.12.3", "", { "os": "linux", "cpu": "x64" }, "sha512-61wZ8hwxNYzBY9MCWB50v90ICzdIhOuPk1O1qXswz9AXw5O6iQStEBHQ1rozPkfQ/rmhepk0pOf/6LCwssJOwg=="], - "@swc/core-linux-x64-musl": ["@swc/core-linux-x64-musl@1.12.1", "", { "os": "linux", "cpu": "x64" }, "sha512-BQMl3d0HaGB0/h2xcKlGtjk/cGRn2tnbsaChAKcjFdCepblKBCz1pgO/mL7w5iXq3s57wMDUn++71/a5RAkZOA=="], + "@swc/core-linux-x64-musl": ["@swc/core-linux-x64-musl@1.12.3", "", { "os": "linux", "cpu": "x64" }, "sha512-NNeBiTpCgWt80vumTKVoaj6Fa/ZjUcaNQNM7np3PIgB8EbuXfyztboV7vUxpkmD/lUgsk8GlEFYViHvo6VMefQ=="], - "@swc/core-win32-arm64-msvc": ["@swc/core-win32-arm64-msvc@1.12.1", "", { "os": "win32", "cpu": "arm64" }, "sha512-b7NeGnpqTfmIGtUqXBl0KqoSmOnH64nRZoT5l4BAGdvwY7nxitWR94CqZuwyLPty/bLywmyDA9uO12Kvgb3+gg=="], + "@swc/core-win32-arm64-msvc": ["@swc/core-win32-arm64-msvc@1.12.3", "", { "os": "win32", "cpu": "arm64" }, "sha512-fxraM7exaPb1/W0CoHW45EFNOQUQh0nonBEcNFm2iv095mziBwttyxZyQBoDkQocpkd5NtsZw3xW5FTBPnn+Vw=="], - "@swc/core-win32-ia32-msvc": ["@swc/core-win32-ia32-msvc@1.12.1", "", { "os": "win32", "cpu": "ia32" }, "sha512-iU/29X2D7cHBp1to62cUg/5Xk8K+lyOJiKIGGW5rdzTW/c2zz3d/ehgpzVP/rqC4NVr88MXspqHU4il5gmDajw=="], + "@swc/core-win32-ia32-msvc": ["@swc/core-win32-ia32-msvc@1.12.3", "", { "os": "win32", "cpu": "ia32" }, "sha512-FFIhMPXIDjRcewomwbYGPvem7Fj76AsuzbRahnAyp+OzJwrrtxVmra/kyUCfj4kix7vdGByY0WvVfiVCf5b7Mg=="], - "@swc/core-win32-x64-msvc": ["@swc/core-win32-x64-msvc@1.12.1", "", { "os": "win32", "cpu": "x64" }, "sha512-+Zh+JKDwiFqV5N9yAd2DhYVGPORGh9cfenu1ptr9yge+eHAf7vZJcC3rnj6QMR1QJh0Y5VC9+YBjRFjZVA7XDw=="], + "@swc/core-win32-x64-msvc": ["@swc/core-win32-x64-msvc@1.12.3", "", { "os": "win32", "cpu": "x64" }, "sha512-Sf4iSg+IYT5AzFSDDmii08DfeKcvtkVxIuo+uS8BJMbiLjFNjgMkkVlBthknGyJcSK15ncg9248XjnM4jU8DZA=="], "@swc/counter": ["@swc/counter@0.1.3", "", {}, "sha512-e2BR4lsJkkRlKZ/qCHPw9ZaSxc0MVUd7gtbtaB7aMvHeJVYe8sOB8DBZkP2DtISHGSku9sCK6T6cnY0CtXrOCQ=="], diff --git a/package.json b/package.json index cb01fbf..8b61abf 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "author": "Luiz Bills ", "contributors": [], "devDependencies": { - "@swc/core": "^1.12.1", + "@swc/core": "^1.12.3", "ava": "^6.4.0", "esbuild": "^0.25.5", "gzip-size": "^7.0.0", From 2bc1943d4cad0b8ee26f8d0eaa98f9c5eced1d4b Mon Sep 17 00:00:00 2001 From: Luiz Bills Date: Thu, 19 Jun 2025 12:39:33 -0300 Subject: [PATCH 3/4] fix game loop --- src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 5cc8db4..d5862ce 100644 --- a/src/index.js +++ b/src/index.js @@ -1403,10 +1403,10 @@ export default function litecanvas(settings = {}) { function drawFrame(now) { let updated = 0 - _lastFrameTime = now - if (settings.animate) { + // prevents too long frames _accumulated += math.min(0.2, (now - _lastFrameTime) / 1000) + _lastFrameTime = now while (_accumulated >= _deltaTime) { updated++ From 88b6e4ba4f178bc2076f698e6c54299ed5fd5af3 Mon Sep 17 00:00:00 2001 From: Luiz Bills Date: Thu, 19 Jun 2025 12:41:59 -0300 Subject: [PATCH 4/4] bump version also, update keywords --- bun.lock | 6 ++---- package.json | 11 ++++------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/bun.lock b/bun.lock index 2b52e99..c264bcb 100644 --- a/bun.lock +++ b/bun.lock @@ -3,15 +3,13 @@ "workspaces": { "": { "name": "litecanvas", - "dependencies": { - "tap-min": "^3.0.0", - }, "devDependencies": { - "@swc/core": "^1.12.1", + "@swc/core": "^1.12.3", "ava": "^6.4.0", "esbuild": "^0.25.5", "gzip-size": "^7.0.0", "prettier": "^3.5.3", + "tap-min": "^3.0.0", }, }, }, diff --git a/package.json b/package.json index 8b61abf..a85ca24 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "litecanvas", - "version": "0.83.3", + "version": "0.83.4", "description": "Lightweight HTML5 canvas 2D game engine suitable for small projects and creative coding. Inspired by PICO-8 and P5/Processing.", "license": "MIT", "author": "Luiz Bills ", @@ -10,7 +10,8 @@ "ava": "^6.4.0", "esbuild": "^0.25.5", "gzip-size": "^7.0.0", - "prettier": "^3.5.3" + "prettier": "^3.5.3", + "tap-min": "^3.0.0" }, "homepage": "https://litecanvas.github.io/about.html", "repository": { @@ -39,8 +40,7 @@ "2d", "html5", "gamedev", - "game", - "engine", + "game engine", "javascript", "js13k", "creative-coding", @@ -57,8 +57,5 @@ "tests/**/*", "!tests/_mocks" ] - }, - "dependencies": { - "tap-min": "^3.0.0" } }