kiwiengine 0.0.1-alpha → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ko.md +550 -0
- package/README.md +575 -4
- package/examples/collision-test/assets/cat.png +0 -0
- package/examples/collision-test/dist/game.js +2 -0
- package/examples/collision-test/dist/game.js.LICENSE.txt +35 -0
- package/examples/collision-test/index.ts +30 -0
- package/examples/dom-particle-test/assets/bird.png +0 -0
- package/examples/dom-particle-test/dist/game.js +2 -0
- package/examples/dom-particle-test/dist/game.js.LICENSE.txt +35 -0
- package/examples/dom-particle-test/index.html +24 -0
- package/examples/dom-particle-test/index.ts +27 -0
- package/examples/dom-sprite-test/assets/bird.png +0 -0
- package/examples/dom-sprite-test/assets/fire.png +0 -0
- package/examples/dom-sprite-test/assets/run.png +0 -0
- package/examples/dom-sprite-test/dist/game.js +2 -0
- package/examples/dom-sprite-test/dist/game.js.LICENSE.txt +35 -0
- package/examples/dom-sprite-test/index.html +24 -0
- package/examples/dom-sprite-test/index.ts +38 -0
- package/examples/dom-test/dist/game.js +2 -0
- package/examples/dom-test/dist/game.js.LICENSE.txt +35 -0
- package/examples/dom-test/index.html +24 -0
- package/examples/dom-test/index.ts +22 -0
- package/examples/flappy-cat/assets/bgm/bgm.ogg +0 -0
- package/examples/flappy-cat/assets/images/base.png +0 -0
- package/examples/flappy-cat/assets/images/bg.png +0 -0
- package/examples/flappy-cat/assets/images/cat.png +0 -0
- package/examples/flappy-cat/assets/images/pipe-green.png +0 -0
- package/examples/flappy-cat/assets/images/pipe-red.png +0 -0
- package/examples/flappy-cat/assets/sfx/die.wav +0 -0
- package/examples/flappy-cat/assets/sfx/hit.wav +0 -0
- package/examples/flappy-cat/assets/sfx/point.wav +0 -0
- package/examples/flappy-cat/assets/sfx/wing.wav +0 -0
- package/examples/flappy-cat/dist/game.js +0 -0
- package/examples/flappy-cat/index.html +24 -0
- package/examples/flappy-cat/index.ts +0 -0
- package/examples/particle-test/assets/bird.png +0 -0
- package/examples/particle-test/dist/game.js +2 -0
- package/examples/particle-test/dist/game.js.LICENSE.txt +35 -0
- package/examples/particle-test/index.html +24 -0
- package/examples/particle-test/index.ts +30 -0
- package/examples/renderer-test/dist/game.js +2 -0
- package/examples/renderer-test/dist/game.js.LICENSE.txt +35 -0
- package/examples/renderer-test/index.html +24 -0
- package/examples/renderer-test/index.ts +9 -0
- package/examples/simple-battle/assets/bgm/battle.mp3 +0 -0
- package/examples/simple-battle/assets/bitmap-fonts/white-peaberry.fnt +107 -0
- package/examples/simple-battle/assets/bitmap-fonts/white-peaberry.png +0 -0
- package/examples/simple-battle/assets/joystick/joystick.png +0 -0
- package/examples/simple-battle/assets/joystick/knob.png +0 -0
- package/examples/simple-battle/assets/sfx/hero/die/die.wav +0 -0
- package/examples/simple-battle/assets/sfx/hero/heal/heal.wav +0 -0
- package/examples/simple-battle/assets/sfx/hero/hit/hit1.wav +0 -0
- package/examples/simple-battle/assets/sfx/hero/hit/hit2.wav +0 -0
- package/examples/simple-battle/assets/sfx/hero/hit/hit3.wav +0 -0
- package/examples/simple-battle/assets/sfx/hero/miss/miss1.wav +0 -0
- package/examples/simple-battle/assets/sfx/hero/miss/miss2.wav +0 -0
- package/examples/simple-battle/assets/sfx/hero/miss/miss3.wav +0 -0
- package/examples/simple-battle/assets/sfx/orc/die/die.wav +0 -0
- package/examples/simple-battle/assets/sfx/orc/hit/hit1.wav +0 -0
- package/examples/simple-battle/assets/sfx/orc/hit/hit2.wav +0 -0
- package/examples/simple-battle/assets/sfx/orc/hit/hit3.wav +0 -0
- package/examples/simple-battle/assets/sfx/orc/miss/miss1.wav +0 -0
- package/examples/simple-battle/assets/sfx/orc/miss/miss2.wav +0 -0
- package/examples/simple-battle/assets/sfx/orc/miss/miss3.wav +0 -0
- package/examples/simple-battle/assets/spritesheets/hero-atlas.json +289 -0
- package/examples/simple-battle/assets/spritesheets/hero.png +0 -0
- package/examples/simple-battle/assets/spritesheets/orc-atlas.json +289 -0
- package/examples/simple-battle/assets/spritesheets/orc.png +0 -0
- package/examples/simple-battle/assets/spritesheets/potion-atlas.json +83 -0
- package/examples/simple-battle/assets/spritesheets/potion.png +0 -0
- package/examples/simple-battle/dist/game.js +2 -0
- package/examples/simple-battle/dist/game.js.LICENSE.txt +35 -0
- package/examples/simple-battle/hud/damage-text.ts +45 -0
- package/examples/simple-battle/hud/heal-text.ts +45 -0
- package/examples/simple-battle/hud/hp-bar.ts +38 -0
- package/examples/simple-battle/index.html +24 -0
- package/examples/simple-battle/index.ts +41 -0
- package/examples/simple-battle/objects/character.ts +95 -0
- package/examples/simple-battle/objects/hero.ts +113 -0
- package/examples/simple-battle/objects/orc.ts +109 -0
- package/examples/simple-battle/objects/potion.ts +29 -0
- package/examples/simple-battle/stage.ts +176 -0
- package/examples/spine-test/assets/spine/spineboy.atlas +95 -0
- package/examples/spine-test/assets/spine/spineboy.png +0 -0
- package/examples/spine-test/assets/spine/spineboy.skel +0 -0
- package/examples/spine-test/dist/game.js +2 -0
- package/examples/spine-test/dist/game.js.LICENSE.txt +35 -0
- package/examples/spine-test/index.html +24 -0
- package/examples/spine-test/index.ts +29 -0
- package/examples/sprite-test/assets/bird.png +0 -0
- package/examples/sprite-test/assets/fire.png +0 -0
- package/examples/sprite-test/dist/game.js +2 -0
- package/examples/sprite-test/dist/game.js.LICENSE.txt +35 -0
- package/examples/sprite-test/index.html +24 -0
- package/examples/sprite-test/index.ts +41 -0
- package/examples/tsconfig.json +2 -1
- package/examples/webpack.config.js +14 -3
- package/jest.config.ts +10 -0
- package/lib/asset/audio.js +47 -11
- package/lib/asset/audio.js.map +1 -1
- package/lib/asset/loaders/audio.js +3 -3
- package/lib/asset/loaders/audio.js.map +1 -1
- package/lib/asset/loaders/binary.js +3 -3
- package/lib/asset/loaders/binary.js.map +1 -1
- package/lib/asset/loaders/bitmap-font.js +71 -0
- package/lib/asset/loaders/bitmap-font.js.map +1 -0
- package/lib/asset/loaders/font.js +1 -1
- package/lib/asset/loaders/font.js.map +1 -1
- package/lib/asset/loaders/loader.js +17 -12
- package/lib/asset/loaders/loader.js.map +1 -1
- package/lib/asset/loaders/spritesheet.js +6 -7
- package/lib/asset/loaders/spritesheet.js.map +1 -1
- package/lib/asset/loaders/text.js +3 -3
- package/lib/asset/loaders/text.js.map +1 -1
- package/lib/asset/loaders/texture.js +5 -4
- package/lib/asset/loaders/texture.js.map +1 -1
- package/lib/asset/preload.js +60 -56
- package/lib/asset/preload.js.map +1 -1
- package/lib/collision/check-collision.js +804 -0
- package/lib/collision/check-collision.js.map +1 -0
- package/lib/collision/check-collision.test.js +300 -0
- package/lib/collision/check-collision.test.js.map +1 -0
- package/lib/collision/colliders.js +8 -0
- package/lib/collision/colliders.js.map +1 -0
- package/lib/debug.js.map +1 -0
- package/lib/dom/dom-animated-sprite.js +121 -0
- package/lib/dom/dom-animated-sprite.js.map +1 -0
- package/lib/dom/dom-game-object.js +106 -0
- package/lib/dom/dom-game-object.js.map +1 -0
- package/lib/dom/dom-particle.js +105 -0
- package/lib/dom/dom-particle.js.map +1 -0
- package/lib/dom/dom-preload.js +43 -0
- package/lib/dom/dom-preload.js.map +1 -0
- package/lib/dom/dom-sprite.js +40 -0
- package/lib/dom/dom-sprite.js.map +1 -0
- package/lib/dom/dom-texture-loader.js +36 -0
- package/lib/dom/dom-texture-loader.js.map +1 -0
- package/lib/dom/dom-utils.js +20 -0
- package/lib/dom/dom-utils.js.map +1 -0
- package/lib/index copy.js +16 -0
- package/lib/index copy.js.map +1 -0
- package/lib/index.js +35 -10
- package/lib/index.js.map +1 -1
- package/lib/input/joystick.js +262 -0
- package/lib/input/joystick.js.map +1 -0
- package/lib/node/core/dirty-number.js +38 -0
- package/lib/node/core/dirty-number.js.map +1 -0
- package/lib/node/core/game-node.js +63 -0
- package/lib/node/core/game-node.js.map +1 -0
- package/lib/node/core/game-object.js +8 -0
- package/lib/node/core/game-object.js.map +1 -0
- package/lib/node/core/renderable.js +52 -0
- package/lib/node/core/renderable.js.map +1 -0
- package/lib/node/core/transform.js +59 -0
- package/lib/node/core/transform.js.map +1 -0
- package/lib/node/core/transformable.js +85 -0
- package/lib/node/core/transformable.js.map +1 -0
- package/lib/node/ext/animated-sprite.js +96 -0
- package/lib/node/ext/animated-sprite.js.map +1 -0
- package/lib/node/ext/bitmap-text.js +89 -0
- package/lib/node/ext/bitmap-text.js.map +1 -0
- package/lib/node/ext/circle.js +28 -0
- package/lib/node/ext/circle.js.map +1 -0
- package/lib/node/ext/deplay.js +20 -0
- package/lib/node/ext/deplay.js.map +1 -0
- package/lib/node/ext/dom-container.js +51 -0
- package/lib/node/ext/dom-container.js.map +1 -0
- package/lib/node/ext/interval.js +20 -0
- package/lib/node/ext/interval.js.map +1 -0
- package/lib/node/ext/particle.js +98 -0
- package/lib/node/ext/particle.js.map +1 -0
- package/lib/node/ext/rectangle.js +32 -0
- package/lib/node/ext/rectangle.js.map +1 -0
- package/lib/node/ext/spine.js +272 -0
- package/lib/node/ext/spine.js.map +1 -0
- package/lib/node/ext/sprite.js +42 -0
- package/lib/node/ext/sprite.js.map +1 -0
- package/lib/node/physics/physics-object.js +112 -0
- package/lib/node/physics/physics-object.js.map +1 -0
- package/lib/node/physics/physics-world.js +27 -0
- package/lib/node/physics/physics-world.js.map +1 -0
- package/lib/renderer/camera.js +19 -0
- package/lib/renderer/camera.js.map +1 -0
- package/lib/renderer/container-manager.js +29 -0
- package/lib/renderer/container-manager.js.map +1 -0
- package/lib/renderer/fps-display.js +18 -0
- package/lib/renderer/fps-display.js.map +1 -0
- package/lib/renderer/layer.js +12 -0
- package/lib/renderer/layer.js.map +1 -0
- package/lib/renderer/renderer.js +145 -0
- package/lib/renderer/renderer.js.map +1 -0
- package/lib/renderer/ticker.js +56 -0
- package/lib/renderer/ticker.js.map +1 -0
- package/lib/renderer/ticker.test.js +241 -0
- package/lib/renderer/ticker.test.js.map +1 -0
- package/lib/types/asset/audio.d.ts +5 -4
- package/lib/types/asset/audio.d.ts.map +1 -1
- package/lib/types/asset/loaders/audio.d.ts +1 -1
- package/lib/types/asset/loaders/audio.d.ts.map +1 -1
- package/lib/types/asset/loaders/binary.d.ts +1 -1
- package/lib/types/asset/loaders/binary.d.ts.map +1 -1
- package/lib/types/asset/loaders/bitmap-font.d.ts +16 -0
- package/lib/types/asset/loaders/bitmap-font.d.ts.map +1 -0
- package/lib/types/asset/loaders/font.d.ts +1 -1
- package/lib/types/asset/loaders/font.d.ts.map +1 -1
- package/lib/types/asset/loaders/loader.d.ts +6 -6
- package/lib/types/asset/loaders/loader.d.ts.map +1 -1
- package/lib/types/asset/loaders/spritesheet.d.ts +5 -5
- package/lib/types/asset/loaders/spritesheet.d.ts.map +1 -1
- package/lib/types/asset/loaders/text.d.ts +1 -1
- package/lib/types/asset/loaders/text.d.ts.map +1 -1
- package/lib/types/asset/loaders/texture.d.ts +2 -2
- package/lib/types/asset/loaders/texture.d.ts.map +1 -1
- package/lib/types/asset/preload.d.ts +5 -3
- package/lib/types/asset/preload.d.ts.map +1 -1
- package/lib/types/bitmap-font.js +2 -0
- package/lib/types/bitmap-font.js.map +1 -0
- package/lib/types/collision/check-collision.d.ts +4 -0
- package/lib/types/collision/check-collision.d.ts.map +1 -0
- package/lib/types/collision/check-collision.test.d.ts +2 -0
- package/lib/types/collision/check-collision.test.d.ts.map +1 -0
- package/lib/types/collision/colliders.d.ts +34 -0
- package/lib/types/collision/colliders.d.ts.map +1 -0
- package/lib/types/debug.d.ts.map +1 -0
- package/lib/types/dom/dom-animated-sprite.d.ts +29 -0
- package/lib/types/dom/dom-animated-sprite.d.ts.map +1 -0
- package/lib/types/dom/dom-game-object.d.ts +44 -0
- package/lib/types/dom/dom-game-object.d.ts.map +1 -0
- package/lib/types/dom/dom-particle.d.ts +30 -0
- package/lib/types/dom/dom-particle.d.ts.map +1 -0
- package/lib/types/dom/dom-preload.d.ts +2 -0
- package/lib/types/dom/dom-preload.d.ts.map +1 -0
- package/lib/types/dom/dom-sprite.d.ts +13 -0
- package/lib/types/dom/dom-sprite.d.ts.map +1 -0
- package/lib/types/dom/dom-texture-loader.d.ts +8 -0
- package/lib/types/dom/dom-texture-loader.d.ts.map +1 -0
- package/lib/types/dom/dom-utils.d.ts +3 -0
- package/lib/types/dom/dom-utils.d.ts.map +1 -0
- package/lib/types/index copy.d.ts +16 -0
- package/lib/types/index copy.d.ts.map +1 -0
- package/lib/types/index.d.ts +25 -11
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/input/joystick.d.ts +28 -0
- package/lib/types/input/joystick.d.ts.map +1 -0
- package/lib/types/node/core/dirty-number.d.ts +17 -0
- package/lib/types/node/core/dirty-number.d.ts.map +1 -0
- package/lib/types/node/core/game-node.d.ts +16 -0
- package/lib/types/node/core/game-node.d.ts.map +1 -0
- package/lib/types/node/core/game-object.d.ts +8 -0
- package/lib/types/node/core/game-object.d.ts.map +1 -0
- package/lib/types/node/core/renderable.d.ts +22 -0
- package/lib/types/node/core/renderable.d.ts.map +1 -0
- package/lib/types/node/core/transform.d.ts +25 -0
- package/lib/types/node/core/transform.d.ts.map +1 -0
- package/lib/types/node/core/transformable.d.ts +44 -0
- package/lib/types/node/core/transformable.d.ts.map +1 -0
- package/lib/types/node/ext/animated-sprite.d.ts +28 -0
- package/lib/types/node/ext/animated-sprite.d.ts.map +1 -0
- package/lib/types/node/ext/bitmap-text.d.ts +14 -0
- package/lib/types/node/ext/bitmap-text.d.ts.map +1 -0
- package/lib/types/node/ext/circle.d.ts +19 -0
- package/lib/types/node/ext/circle.d.ts.map +1 -0
- package/lib/types/node/ext/deplay.d.ts +8 -0
- package/lib/types/node/ext/deplay.d.ts.map +1 -0
- package/lib/types/node/ext/dom-container.d.ts +12 -0
- package/lib/types/node/ext/dom-container.d.ts.map +1 -0
- package/lib/types/node/ext/interval.d.ts +9 -0
- package/lib/types/node/ext/interval.d.ts.map +1 -0
- package/lib/types/node/ext/particle.d.ts +30 -0
- package/lib/types/node/ext/particle.d.ts.map +1 -0
- package/lib/types/node/ext/rectangle.d.ts +22 -0
- package/lib/types/node/ext/rectangle.d.ts.map +1 -0
- package/lib/types/node/ext/spine.d.ts +36 -0
- package/lib/types/node/ext/spine.d.ts.map +1 -0
- package/lib/types/node/ext/sprite.d.ts +13 -0
- package/lib/types/node/ext/sprite.d.ts.map +1 -0
- package/lib/types/node/physics/physics-object.d.ts +38 -0
- package/lib/types/node/physics/physics-object.d.ts.map +1 -0
- package/lib/types/node/physics/physics-world.d.ts +18 -0
- package/lib/types/node/physics/physics-world.d.ts.map +1 -0
- package/lib/types/renderer/camera.d.ts +13 -0
- package/lib/types/renderer/camera.d.ts.map +1 -0
- package/lib/types/renderer/container-manager.d.ts +9 -0
- package/lib/types/renderer/container-manager.d.ts.map +1 -0
- package/lib/types/renderer/fps-display.d.ts +7 -0
- package/lib/types/renderer/fps-display.d.ts.map +1 -0
- package/lib/types/renderer/layer.d.ts +7 -0
- package/lib/types/renderer/layer.d.ts.map +1 -0
- package/lib/types/renderer/renderer.d.ts +40 -0
- package/lib/types/renderer/renderer.d.ts.map +1 -0
- package/lib/types/renderer/ticker.d.ts +6 -0
- package/lib/types/renderer/ticker.d.ts.map +1 -0
- package/lib/types/renderer/ticker.test.d.ts +40 -0
- package/lib/types/renderer/ticker.test.d.ts.map +1 -0
- package/lib/types/types/bitmap-font.d.ts +18 -0
- package/lib/types/types/bitmap-font.d.ts.map +1 -0
- package/lib/types/utils/device.d.ts +2 -0
- package/lib/types/utils/device.d.ts.map +1 -0
- package/lib/utils/device.js +2 -0
- package/lib/utils/device.js.map +1 -0
- package/package.json +8 -7
- package/src/asset/audio.ts +134 -90
- package/src/asset/loaders/audio.ts +19 -19
- package/src/asset/loaders/binary.ts +16 -16
- package/src/asset/loaders/bitmap-font.ts +85 -0
- package/src/asset/loaders/font.ts +14 -14
- package/src/asset/loaders/loader.ts +27 -23
- package/src/asset/loaders/spritesheet.ts +34 -36
- package/src/asset/loaders/text.ts +15 -15
- package/src/asset/loaders/texture.ts +29 -28
- package/src/asset/preload.ts +75 -64
- package/src/collision/check-collision.test.ts +349 -0
- package/src/collision/check-collision.ts +821 -0
- package/src/collision/colliders.ts +19 -0
- package/src/debug.ts +5 -0
- package/src/dom/dom-animated-sprite.ts +153 -0
- package/src/dom/dom-game-object.ts +131 -0
- package/src/dom/dom-particle.ts +151 -0
- package/src/dom/dom-preload.ts +54 -0
- package/src/dom/dom-sprite.ts +50 -0
- package/src/dom/dom-texture-loader.ts +44 -0
- package/src/dom/dom-utils.ts +19 -0
- package/src/index.ts +46 -13
- package/src/input/joystick.ts +316 -0
- package/src/node/core/dirty-number.ts +45 -0
- package/src/node/core/game-node.ts +74 -0
- package/src/node/core/game-object.ts +11 -0
- package/src/node/core/renderable.ts +65 -0
- package/src/node/core/transform.ts +70 -0
- package/src/node/core/transformable.ts +111 -0
- package/src/node/ext/animated-sprite.ts +123 -0
- package/src/node/ext/bitmap-text.ts +109 -0
- package/src/node/ext/circle.ts +40 -0
- package/src/node/ext/deplay.ts +24 -0
- package/src/node/ext/dom-container.ts +62 -0
- package/src/node/ext/interval.ts +24 -0
- package/src/node/ext/particle.ts +142 -0
- package/src/node/ext/rectangle.ts +51 -0
- package/src/node/ext/spine.ts +323 -0
- package/src/node/ext/sprite.ts +53 -0
- package/src/node/physics/physics-object.ts +156 -0
- package/src/node/physics/physics-world.ts +40 -0
- package/src/renderer/camera.ts +25 -0
- package/src/renderer/container-manager.ts +36 -0
- package/src/renderer/fps-display.ts +21 -0
- package/src/renderer/layer.ts +15 -0
- package/src/renderer/renderer.ts +180 -0
- package/src/renderer/ticker.test.ts +325 -0
- package/src/renderer/ticker.ts +54 -0
- package/src/types/bitmap-font.ts +19 -0
- package/src/utils/device.ts +1 -0
- package/examples/test-dom/index.ts +0 -21
- package/lib/game-object/game-object-physics.js +0 -188
- package/lib/game-object/game-object-physics.js.map +0 -1
- package/lib/game-object/game-object-rendering.js +0 -35
- package/lib/game-object/game-object-rendering.js.map +0 -1
- package/lib/game-object/game-object.js +0 -162
- package/lib/game-object/game-object.js.map +0 -1
- package/lib/game-object/transform.js +0 -118
- package/lib/game-object/transform.js.map +0 -1
- package/lib/game-object-ext/animated-sprite.js +0 -117
- package/lib/game-object-ext/animated-sprite.js.map +0 -1
- package/lib/game-object-ext/dom-container.js +0 -56
- package/lib/game-object-ext/dom-container.js.map +0 -1
- package/lib/game-object-ext/rect.js +0 -30
- package/lib/game-object-ext/rect.js.map +0 -1
- package/lib/game-object-ext/spine.js +0 -206
- package/lib/game-object-ext/spine.js.map +0 -1
- package/lib/game-object-ext/sprite.js +0 -46
- package/lib/game-object-ext/sprite.js.map +0 -1
- package/lib/game-object-ext/text.js +0 -68
- package/lib/game-object-ext/text.js.map +0 -1
- package/lib/game-object-ext/tiling-sprite.js +0 -64
- package/lib/game-object-ext/tiling-sprite.js.map +0 -1
- package/lib/types/game-object/game-object-physics.d.ts +0 -42
- package/lib/types/game-object/game-object-physics.d.ts.map +0 -1
- package/lib/types/game-object/game-object-rendering.d.ts +0 -15
- package/lib/types/game-object/game-object-rendering.d.ts.map +0 -1
- package/lib/types/game-object/game-object.d.ts +0 -81
- package/lib/types/game-object/game-object.d.ts.map +0 -1
- package/lib/types/game-object/transform.d.ts +0 -43
- package/lib/types/game-object/transform.d.ts.map +0 -1
- package/lib/types/game-object-ext/animated-sprite.d.ts +0 -29
- package/lib/types/game-object-ext/animated-sprite.d.ts.map +0 -1
- package/lib/types/game-object-ext/dom-container.d.ts +0 -16
- package/lib/types/game-object-ext/dom-container.d.ts.map +0 -1
- package/lib/types/game-object-ext/rect.d.ts +0 -17
- package/lib/types/game-object-ext/rect.d.ts.map +0 -1
- package/lib/types/game-object-ext/spine.d.ts +0 -35
- package/lib/types/game-object-ext/spine.d.ts.map +0 -1
- package/lib/types/game-object-ext/sprite.d.ts +0 -14
- package/lib/types/game-object-ext/sprite.d.ts.map +0 -1
- package/lib/types/game-object-ext/text.d.ts +0 -26
- package/lib/types/game-object-ext/text.d.ts.map +0 -1
- package/lib/types/game-object-ext/tiling-sprite.d.ts +0 -20
- package/lib/types/game-object-ext/tiling-sprite.d.ts.map +0 -1
- package/lib/types/utils/debug.d.ts.map +0 -1
- package/lib/types/utils/go.d.ts +0 -26
- package/lib/types/utils/go.d.ts.map +0 -1
- package/lib/types/world/world-debug.d.ts +0 -11
- package/lib/types/world/world-debug.d.ts.map +0 -1
- package/lib/types/world/world-physics.d.ts +0 -16
- package/lib/types/world/world-physics.d.ts.map +0 -1
- package/lib/types/world/world-rendering.d.ts +0 -28
- package/lib/types/world/world-rendering.d.ts.map +0 -1
- package/lib/types/world/world.d.ts +0 -38
- package/lib/types/world/world.d.ts.map +0 -1
- package/lib/utils/debug.js.map +0 -1
- package/lib/utils/go.js +0 -33
- package/lib/utils/go.js.map +0 -1
- package/lib/world/world-debug.js +0 -89
- package/lib/world/world-debug.js.map +0 -1
- package/lib/world/world-physics.js +0 -45
- package/lib/world/world-physics.js.map +0 -1
- package/lib/world/world-rendering.js +0 -123
- package/lib/world/world-rendering.js.map +0 -1
- package/lib/world/world.js +0 -147
- package/lib/world/world.js.map +0 -1
- package/src/game-object/game-object-physics.ts +0 -191
- package/src/game-object/game-object-rendering.ts +0 -27
- package/src/game-object/game-object.ts +0 -190
- package/src/game-object/transform.ts +0 -164
- package/src/game-object-ext/animated-sprite.ts +0 -140
- package/src/game-object-ext/dom-container.ts +0 -67
- package/src/game-object-ext/rect.ts +0 -40
- package/src/game-object-ext/spine.ts +0 -235
- package/src/game-object-ext/sprite.ts +0 -55
- package/src/game-object-ext/text.ts +0 -83
- package/src/game-object-ext/tiling-sprite.ts +0 -73
- package/src/utils/debug.ts +0 -5
- package/src/utils/go.ts +0 -53
- package/src/world/world-debug.ts +0 -114
- package/src/world/world-physics.ts +0 -52
- package/src/world/world-rendering.ts +0 -145
- package/src/world/world.ts +0 -171
- /package/examples/{test-dom → collision-test}/index.html +0 -0
- /package/lib/{utils/debug.js → debug.js} +0 -0
- /package/lib/types/{utils/debug.d.ts → debug.d.ts} +0 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { autoDetectRenderer, Container as PixiContainer } from 'pixi.js';
|
|
2
|
+
import { debugMode } from '../debug';
|
|
3
|
+
import { setStyle } from '../dom/dom-utils';
|
|
4
|
+
import { RenderableNode } from '../node/core/renderable';
|
|
5
|
+
import { Camera } from './camera';
|
|
6
|
+
import { RendererContainerManager } from './container-manager';
|
|
7
|
+
import { FpsDisplay } from './fps-display';
|
|
8
|
+
import { Layer } from './layer';
|
|
9
|
+
import { Ticker } from './ticker';
|
|
10
|
+
export class Renderer extends RenderableNode {
|
|
11
|
+
container;
|
|
12
|
+
#containerManager;
|
|
13
|
+
#ticker = new Ticker((dt) => this.#render(dt));
|
|
14
|
+
camera = new Camera();
|
|
15
|
+
fpsDisplay;
|
|
16
|
+
#logicalWidth;
|
|
17
|
+
#logicalHeight;
|
|
18
|
+
#backgroundColor;
|
|
19
|
+
#backgroundAlpha;
|
|
20
|
+
#pixiRenderer;
|
|
21
|
+
#layers = {};
|
|
22
|
+
_isSizeDirty = false;
|
|
23
|
+
canvasWidth = 0;
|
|
24
|
+
canvasHeight = 0;
|
|
25
|
+
canvasLeft = 0;
|
|
26
|
+
canvasTop = 0;
|
|
27
|
+
viewportScale = 1;
|
|
28
|
+
centerX = 0;
|
|
29
|
+
centerY = 0;
|
|
30
|
+
constructor(container, options) {
|
|
31
|
+
super(new PixiContainer({ sortableChildren: true }));
|
|
32
|
+
this.container = container;
|
|
33
|
+
this.renderer = this;
|
|
34
|
+
this.worldTransform.x.v = 0;
|
|
35
|
+
this.worldTransform.y.v = 0;
|
|
36
|
+
this.worldTransform.resetDirty();
|
|
37
|
+
this.#containerManager = new RendererContainerManager(container);
|
|
38
|
+
this.#containerManager.on('resize', (width, height) => this.#updateSize(width, height));
|
|
39
|
+
this.camera.on('positionChanged', () => this.#updatePosition());
|
|
40
|
+
this.camera.on('scaleChanged', () => this.#updatePosition());
|
|
41
|
+
if (options) {
|
|
42
|
+
if (options.logicalWidth !== undefined)
|
|
43
|
+
this.#logicalWidth = options.logicalWidth;
|
|
44
|
+
if (options.logicalHeight !== undefined)
|
|
45
|
+
this.#logicalHeight = options.logicalHeight;
|
|
46
|
+
if (options.backgroundColor !== undefined)
|
|
47
|
+
this.#backgroundColor = options.backgroundColor;
|
|
48
|
+
if (options.backgroundAlpha !== undefined)
|
|
49
|
+
this.#backgroundAlpha = options.backgroundAlpha;
|
|
50
|
+
if (options.layers) {
|
|
51
|
+
for (const layerOption of options.layers) {
|
|
52
|
+
const layer = new Layer(layerOption.drawOrder);
|
|
53
|
+
this._pixiContainer.addChild(layer._pixiContainer);
|
|
54
|
+
this.#layers[layerOption.name] = layer;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (debugMode) {
|
|
59
|
+
this.fpsDisplay = new FpsDisplay(container);
|
|
60
|
+
}
|
|
61
|
+
this.init();
|
|
62
|
+
}
|
|
63
|
+
async init() {
|
|
64
|
+
const options = {
|
|
65
|
+
eventMode: 'none',
|
|
66
|
+
resolution: window.devicePixelRatio,
|
|
67
|
+
};
|
|
68
|
+
if (this.#logicalWidth)
|
|
69
|
+
options.width = this.#logicalWidth;
|
|
70
|
+
if (this.#logicalHeight)
|
|
71
|
+
options.height = this.#logicalHeight;
|
|
72
|
+
if (this.#backgroundColor)
|
|
73
|
+
options.backgroundColor = this.#backgroundColor;
|
|
74
|
+
if (this.#backgroundAlpha)
|
|
75
|
+
options.backgroundAlpha = this.#backgroundAlpha;
|
|
76
|
+
const pr = await autoDetectRenderer(options);
|
|
77
|
+
setStyle(pr.canvas, {
|
|
78
|
+
position: 'absolute',
|
|
79
|
+
touchAction: 'auto',
|
|
80
|
+
});
|
|
81
|
+
this.container.appendChild(pr.canvas);
|
|
82
|
+
this.#pixiRenderer = pr;
|
|
83
|
+
const cr = this.container.getBoundingClientRect();
|
|
84
|
+
this.#updateSize(cr.width, cr.height);
|
|
85
|
+
}
|
|
86
|
+
#updatePosition() {
|
|
87
|
+
const S = this.camera.scale;
|
|
88
|
+
this._pixiContainer.scale = S;
|
|
89
|
+
this._pixiContainer.position.set(this.centerX - this.camera.x * S, this.centerY - this.camera.y * S);
|
|
90
|
+
}
|
|
91
|
+
#updateSize(containerWidth, containerHeight) {
|
|
92
|
+
const canvasWidth = this.#logicalWidth ?? containerWidth;
|
|
93
|
+
const canvasHeight = this.#logicalHeight ?? containerHeight;
|
|
94
|
+
this.canvasWidth = canvasWidth;
|
|
95
|
+
this.canvasHeight = canvasHeight;
|
|
96
|
+
this.centerX = canvasWidth / 2;
|
|
97
|
+
this.centerY = canvasHeight / 2;
|
|
98
|
+
this.#updatePosition();
|
|
99
|
+
const S = Math.min(containerWidth / canvasWidth, containerHeight / canvasHeight);
|
|
100
|
+
this.viewportScale = S;
|
|
101
|
+
const displayWidth = canvasWidth * S;
|
|
102
|
+
const displayHeight = canvasHeight * S;
|
|
103
|
+
const canvasLeft = (containerWidth - displayWidth) / 2;
|
|
104
|
+
const canvasTop = (containerHeight - displayHeight) / 2;
|
|
105
|
+
this.canvasLeft = canvasLeft;
|
|
106
|
+
this.canvasTop = canvasTop;
|
|
107
|
+
if (this.#pixiRenderer) {
|
|
108
|
+
this.#pixiRenderer.resize(canvasWidth, canvasHeight);
|
|
109
|
+
setStyle(this.#pixiRenderer.canvas, {
|
|
110
|
+
width: `${displayWidth}px`,
|
|
111
|
+
height: `${displayHeight}px`,
|
|
112
|
+
left: `${canvasLeft}px`,
|
|
113
|
+
top: `${canvasTop}px`,
|
|
114
|
+
});
|
|
115
|
+
this.emit('resize', canvasWidth, canvasHeight);
|
|
116
|
+
}
|
|
117
|
+
this._isSizeDirty = true;
|
|
118
|
+
}
|
|
119
|
+
#render(dt) {
|
|
120
|
+
this._isSizeDirty = false;
|
|
121
|
+
this.update(dt);
|
|
122
|
+
this._updateWorldTransform();
|
|
123
|
+
this.#pixiRenderer?.render(this._pixiContainer);
|
|
124
|
+
this.fpsDisplay?.update();
|
|
125
|
+
}
|
|
126
|
+
_addToLayer(node, layerName) {
|
|
127
|
+
const layer = this.#layers[layerName];
|
|
128
|
+
if (!layer)
|
|
129
|
+
throw new Error(`Layer ${layerName} does not exist.`);
|
|
130
|
+
layer._pixiContainer.addChild(node._pixiContainer);
|
|
131
|
+
}
|
|
132
|
+
remove() {
|
|
133
|
+
this.#containerManager.remove();
|
|
134
|
+
this.#ticker.remove();
|
|
135
|
+
this.#pixiRenderer?.destroy();
|
|
136
|
+
this.fpsDisplay?.remove();
|
|
137
|
+
super.remove();
|
|
138
|
+
}
|
|
139
|
+
screenToWorld(screenX, screenY) {
|
|
140
|
+
const x = (screenX - this.canvasLeft) / this.viewportScale - this.canvasWidth / 2;
|
|
141
|
+
const y = (screenY - this.canvasTop) / this.viewportScale - this.canvasHeight / 2;
|
|
142
|
+
return { x, y };
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=renderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../../src/renderer/renderer.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,kBAAkB,EAAe,SAAS,IAAI,aAAa,EAA4B,MAAM,SAAS,CAAA;AAClI,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAUjC,MAAM,OAAO,QAAS,SAAQ,cAE5B;IAuBmB;IAtBnB,iBAAiB,CAA0B;IAC3C,OAAO,GAAG,IAAI,MAAM,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, ColorSource, Container as PixiContainer, Renderer as PixiRenderer } from 'pixi.js'\nimport { debugMode } from '../debug'\nimport { setStyle } from '../dom/dom-utils'\nimport { RenderableNode } from '../node/core/renderable'\nimport { Camera } from './camera'\nimport { RendererContainerManager } from './container-manager'\nimport { FpsDisplay } from './fps-display'\nimport { Layer } from './layer'\nimport { Ticker } from './ticker'\n\nexport type RendererOptions = {\n logicalWidth?: number\n logicalHeight?: number\n backgroundColor?: ColorSource\n backgroundAlpha?: number\n layers?: { name: string; drawOrder: number }[]\n}\n\nexport class Renderer extends RenderableNode<PixiContainer, {\n resize: (width: number, height: number) => void\n}> {\n #containerManager: RendererContainerManager\n #ticker = new Ticker((dt) => this.#render(dt))\n camera = new Camera()\n fpsDisplay?: FpsDisplay\n\n #logicalWidth?: number\n #logicalHeight?: number\n #backgroundColor?: ColorSource\n #backgroundAlpha?: number\n\n #pixiRenderer?: PixiRenderer\n #layers: { [name: string]: Layer } = {}\n _isSizeDirty = false\n\n canvasWidth = 0\n canvasHeight = 0\n canvasLeft = 0\n canvasTop = 0\n viewportScale = 1\n centerX = 0\n centerY = 0\n\n constructor(public container: HTMLElement, options?: RendererOptions) {\n super(new PixiContainer({ sortableChildren: true }))\n this.renderer = this\n\n this.worldTransform.x.v = 0\n this.worldTransform.y.v = 0\n this.worldTransform.resetDirty()\n\n this.#containerManager = new RendererContainerManager(container)\n this.#containerManager.on('resize', (width, height) => this.#updateSize(width, height))\n\n this.camera.on('positionChanged', () => this.#updatePosition())\n this.camera.on('scaleChanged', () => this.#updatePosition())\n\n if (options) {\n if (options.logicalWidth !== undefined) this.#logicalWidth = options.logicalWidth\n if (options.logicalHeight !== undefined) this.#logicalHeight = options.logicalHeight\n if (options.backgroundColor !== undefined) this.#backgroundColor = options.backgroundColor\n if (options.backgroundAlpha !== undefined) this.#backgroundAlpha = options.backgroundAlpha\n\n if (options.layers) {\n for (const layerOption of options.layers) {\n const layer = new Layer(layerOption.drawOrder)\n this._pixiContainer.addChild(layer._pixiContainer)\n this.#layers[layerOption.name] = layer\n }\n }\n }\n\n if (debugMode) {\n this.fpsDisplay = new FpsDisplay(container)\n }\n\n this.init()\n }\n\n private async init() {\n const options: Partial<AutoDetectOptions> = {\n eventMode: 'none',\n resolution: window.devicePixelRatio,\n }\n\n if (this.#logicalWidth) options.width = this.#logicalWidth\n if (this.#logicalHeight) options.height = this.#logicalHeight\n if (this.#backgroundColor) options.backgroundColor = this.#backgroundColor\n if (this.#backgroundAlpha) options.backgroundAlpha = this.#backgroundAlpha\n\n const pr = await autoDetectRenderer(options)\n\n setStyle(pr.canvas, {\n position: 'absolute',\n touchAction: 'auto',\n })\n this.container.appendChild(pr.canvas)\n\n this.#pixiRenderer = pr\n\n const cr = this.container.getBoundingClientRect()\n this.#updateSize(cr.width, cr.height)\n }\n\n #updatePosition() {\n const S = this.camera.scale\n this._pixiContainer.scale = S\n this._pixiContainer.position.set(\n this.centerX - this.camera.x * S,\n this.centerY - this.camera.y * S\n )\n }\n\n #updateSize(containerWidth: number, containerHeight: number) {\n const canvasWidth = this.#logicalWidth ?? containerWidth\n const canvasHeight = this.#logicalHeight ?? containerHeight\n this.canvasWidth = canvasWidth\n this.canvasHeight = canvasHeight\n\n this.centerX = canvasWidth / 2\n this.centerY = canvasHeight / 2\n this.#updatePosition()\n\n const S = Math.min(containerWidth / canvasWidth, containerHeight / canvasHeight)\n this.viewportScale = S\n\n const displayWidth = canvasWidth * S\n const displayHeight = canvasHeight * S\n\n const canvasLeft = (containerWidth - displayWidth) / 2\n const canvasTop = (containerHeight - displayHeight) / 2\n this.canvasLeft = canvasLeft\n this.canvasTop = canvasTop\n\n if (this.#pixiRenderer) {\n this.#pixiRenderer.resize(canvasWidth, canvasHeight)\n\n setStyle(this.#pixiRenderer.canvas, {\n width: `${displayWidth}px`,\n height: `${displayHeight}px`,\n left: `${canvasLeft}px`,\n top: `${canvasTop}px`,\n })\n\n this.emit('resize', canvasWidth, canvasHeight)\n }\n\n this._isSizeDirty = true\n }\n\n #render(dt: number) {\n this._isSizeDirty = false\n\n this.update(dt)\n this._updateWorldTransform()\n this.#pixiRenderer?.render(this._pixiContainer)\n this.fpsDisplay?.update()\n }\n\n _addToLayer(node: RenderableNode<PixiContainer, EventMap>, layerName: string) {\n const layer = this.#layers[layerName]\n if (!layer) throw new Error(`Layer ${layerName} does not exist.`)\n layer._pixiContainer.addChild(node._pixiContainer)\n }\n\n override remove() {\n this.#containerManager.remove()\n this.#ticker.remove()\n this.#pixiRenderer?.destroy()\n this.fpsDisplay?.remove()\n super.remove()\n }\n\n screenToWorld(screenX: number, screenY: number) {\n const x = (screenX - this.canvasLeft) / this.viewportScale - this.canvasWidth / 2\n const y = (screenY - this.canvasTop) / this.viewportScale - this.canvasHeight / 2\n return { x, y }\n }\n}\n"]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { debugMode } from '../debug';
|
|
2
|
+
export class Ticker {
|
|
3
|
+
#fpsCap;
|
|
4
|
+
#frameId = 0;
|
|
5
|
+
constructor(onTick) {
|
|
6
|
+
let prevTime = 0;
|
|
7
|
+
let lagSeconds = 0;
|
|
8
|
+
const step = (timestamp) => {
|
|
9
|
+
const dt = (timestamp - prevTime) / 1000;
|
|
10
|
+
if (dt > 0) {
|
|
11
|
+
const fpsCap = this.#fpsCap;
|
|
12
|
+
if (fpsCap !== undefined && fpsCap > 0) {
|
|
13
|
+
lagSeconds += dt;
|
|
14
|
+
const fixedStep = 1 / fpsCap;
|
|
15
|
+
if (lagSeconds >= fixedStep) {
|
|
16
|
+
onTick(fixedStep);
|
|
17
|
+
if (lagSeconds >= fixedStep * 2) {
|
|
18
|
+
onTick(dt);
|
|
19
|
+
lagSeconds = 0;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
lagSeconds -= fixedStep;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
onTick(dt);
|
|
28
|
+
}
|
|
29
|
+
prevTime = timestamp;
|
|
30
|
+
}
|
|
31
|
+
this.#frameId = requestAnimationFrame(step);
|
|
32
|
+
};
|
|
33
|
+
this.#frameId = requestAnimationFrame(step);
|
|
34
|
+
if (debugMode) {
|
|
35
|
+
if (!document.hasFocus())
|
|
36
|
+
this.#fpsCap = 6;
|
|
37
|
+
window.addEventListener('blur', this.#blurListener);
|
|
38
|
+
window.addEventListener('focus', this.#focusListener);
|
|
39
|
+
window.addEventListener('pageshow', this.#pageshowListener);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
#blurListener = () => { this.#fpsCap = 6; };
|
|
43
|
+
#focusListener = () => { this.#fpsCap = undefined; };
|
|
44
|
+
#pageshowListener = (event) => {
|
|
45
|
+
if (event.persisted) {
|
|
46
|
+
this.#fpsCap = undefined;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
remove() {
|
|
50
|
+
cancelAnimationFrame(this.#frameId);
|
|
51
|
+
window.removeEventListener('blur', this.#blurListener);
|
|
52
|
+
window.removeEventListener('focus', this.#focusListener);
|
|
53
|
+
window.removeEventListener('pageshow', this.#pageshowListener);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=ticker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ticker.js","sourceRoot":"","sources":["../../src/renderer/ticker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEpC,MAAM,OAAO,MAAM;IACjB,OAAO,CAAS;IAChB,QAAQ,GAAG,CAAC,CAAA;IAEZ,YAAY,MAA4B;QACtC,IAAI,QAAQ,GAAG,CAAC,CAAA;QAChB,IAAI,UAAU,GAAG,CAAC,CAAA;QAElB,MAAM,IAAI,GAAG,CAAC,SAAiB,EAAE,EAAE;YACjC,MAAM,EAAE,GAAG,CAAC,SAAS,GAAG,QAAQ,CAAC,GAAG,IAAI,CAAA;YACxC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;gBACX,MAA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GAAG,IAAI,CAAC,OAAO,GAAG,SAAS,CAAA,CAAC,CAAC,CAAA;IACnD,iBAAiB,GAAG,CAAC,KAA0B,EAAE,EAAE;QACjD,IAAI,KAAK,CAAC,SAAS,EAAE,CAAC;YACpB,IAAI,CAAC,OAAO,GAAG,SAAS,CAAA;QAC1B,CAAC;IACH,CAAC,CAAA;IAED,MAAM;QACJ,oBAAoB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACnC,MAAM,CAAC,mBAAmB,CAAC,MAAM,EAAE,IAAI,CAAC,aAAa,CAAC,CAAA;QACtD,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,cAAc,CAAC,CAAA;QACxD,MAAM,CAAC,mBAAmB,CAAC,UAAU,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAA;IAChE,CAAC;CACF","sourcesContent":["import { debugMode } from '../debug'\n\nexport class Ticker {\n #fpsCap?: number\n #frameId = 0\n\n constructor(onTick: (dt: number) => void) {\n let prevTime = 0\n let lagSeconds = 0\n\n const step = (timestamp: number) => {\n const dt = (timestamp - prevTime) / 1000\n if (dt > 0) {\n const fpsCap = this.#fpsCap\n if (fpsCap !== undefined && fpsCap > 0) {\n lagSeconds += dt\n const fixedStep = 1 / fpsCap\n if (lagSeconds >= fixedStep) {\n onTick(fixedStep)\n if (lagSeconds >= fixedStep * 2) { onTick(dt); lagSeconds = 0 }\n else { lagSeconds -= fixedStep }\n }\n } else {\n onTick(dt)\n }\n prevTime = timestamp\n }\n this.#frameId = requestAnimationFrame(step)\n }\n this.#frameId = requestAnimationFrame(step)\n\n if (debugMode) {\n if (!document.hasFocus()) this.#fpsCap = 6\n window.addEventListener('blur', this.#blurListener)\n window.addEventListener('focus', this.#focusListener)\n window.addEventListener('pageshow', this.#pageshowListener)\n }\n }\n\n #blurListener = () => { this.#fpsCap = 6 }\n #focusListener = () => { this.#fpsCap = undefined }\n #pageshowListener = (event: PageTransitionEvent) => {\n if (event.persisted) {\n this.#fpsCap = undefined\n }\n }\n\n remove() {\n cancelAnimationFrame(this.#frameId)\n window.removeEventListener('blur', this.#blurListener)\n window.removeEventListener('focus', this.#focusListener)\n window.removeEventListener('pageshow', this.#pageshowListener)\n }\n}\n"]}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/** @jest-environment jsdom */
|
|
3
|
+
// Simulated monotonic clock (ms)
|
|
4
|
+
let nowMs = 0;
|
|
5
|
+
// RAF callback registry: id -> cb
|
|
6
|
+
const rafCallbacks = new Map();
|
|
7
|
+
let nextRafId = 1;
|
|
8
|
+
const installTimeAndRafMocks = () => {
|
|
9
|
+
jest.spyOn(performance, 'now').mockImplementation(() => nowMs);
|
|
10
|
+
jest
|
|
11
|
+
.spyOn(window, 'requestAnimationFrame')
|
|
12
|
+
.mockImplementation((cb) => {
|
|
13
|
+
const id = nextRafId++;
|
|
14
|
+
rafCallbacks.set(id, cb);
|
|
15
|
+
return id;
|
|
16
|
+
});
|
|
17
|
+
jest.spyOn(window, 'cancelAnimationFrame').mockImplementation((id) => {
|
|
18
|
+
rafCallbacks.delete(id);
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
const resetHarness = () => {
|
|
22
|
+
nowMs = 0;
|
|
23
|
+
rafCallbacks.clear();
|
|
24
|
+
nextRafId = 1;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Advance a single frame: move the clock by advanceMs and
|
|
28
|
+
* run only the currently registered RAF callbacks
|
|
29
|
+
* (callbacks registered during this step run on the next step).
|
|
30
|
+
*/
|
|
31
|
+
const step = (advanceMs) => {
|
|
32
|
+
nowMs += advanceMs;
|
|
33
|
+
const cbs = [...rafCallbacks.values()];
|
|
34
|
+
rafCallbacks.clear();
|
|
35
|
+
for (const cb of cbs)
|
|
36
|
+
cb(nowMs);
|
|
37
|
+
};
|
|
38
|
+
/** Advance multiple frames (helper) */
|
|
39
|
+
const advance = (totalMs, stepMs = 16) => {
|
|
40
|
+
const n = Math.floor(totalMs / stepMs);
|
|
41
|
+
for (let i = 0; i < n; i++)
|
|
42
|
+
step(stepMs);
|
|
43
|
+
const remain = totalMs - n * stepMs;
|
|
44
|
+
if (remain > 0)
|
|
45
|
+
step(remain);
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Helper to (re)load Ticker with a specific debugMode value.
|
|
49
|
+
* Uses jest.resetModules + jest.doMock to inject the desired export.
|
|
50
|
+
*/
|
|
51
|
+
const loadTickerWithDebug = async (debug) => {
|
|
52
|
+
jest.resetModules();
|
|
53
|
+
jest.doMock('../debug', () => ({ debugMode: debug }), { virtual: true });
|
|
54
|
+
const mod = await import('./ticker');
|
|
55
|
+
return mod.Ticker;
|
|
56
|
+
};
|
|
57
|
+
/** Small helpers to read arguments cleanly */
|
|
58
|
+
const argOf = (mockFn, nthZeroBased) => mockFn.mock.calls[nthZeroBased][0];
|
|
59
|
+
const lastArg = (mockFn) => {
|
|
60
|
+
const i = mockFn.mock.calls.length - 1;
|
|
61
|
+
return mockFn.mock.calls[i][0];
|
|
62
|
+
};
|
|
63
|
+
/** ----------------------- Lifecycle -------------------------- **/
|
|
64
|
+
beforeEach(() => {
|
|
65
|
+
resetHarness();
|
|
66
|
+
jest.restoreAllMocks();
|
|
67
|
+
installTimeAndRafMocks();
|
|
68
|
+
});
|
|
69
|
+
afterEach(() => {
|
|
70
|
+
jest.restoreAllMocks();
|
|
71
|
+
resetHarness();
|
|
72
|
+
});
|
|
73
|
+
/** ----------------------- Tests ------------------------------ **/
|
|
74
|
+
describe('uncapped mode (debugMode=false)', () => {
|
|
75
|
+
it('calls onTick once per frame with raw deltaTime (seconds)', async () => {
|
|
76
|
+
const Ticker = await loadTickerWithDebug(false);
|
|
77
|
+
const spy = jest.fn();
|
|
78
|
+
const ticker = new Ticker(spy); // default: uncapped
|
|
79
|
+
step(10); // 0.010
|
|
80
|
+
step(20); // 0.020
|
|
81
|
+
step(30); // 0.030
|
|
82
|
+
expect(spy).toHaveBeenCalledTimes(3);
|
|
83
|
+
// Assert shapes, then values
|
|
84
|
+
expect(spy).toHaveBeenNthCalledWith(1, expect.any(Number));
|
|
85
|
+
expect(spy).toHaveBeenNthCalledWith(2, expect.any(Number));
|
|
86
|
+
expect(spy).toHaveBeenNthCalledWith(3, expect.any(Number));
|
|
87
|
+
expect(argOf(spy, 0)).toBeCloseTo(0.010, 6);
|
|
88
|
+
expect(argOf(spy, 1)).toBeCloseTo(0.020, 6);
|
|
89
|
+
expect(argOf(spy, 2)).toBeCloseTo(0.030, 6);
|
|
90
|
+
ticker.remove();
|
|
91
|
+
});
|
|
92
|
+
it('does not call onTick when deltaTime <= 0', async () => {
|
|
93
|
+
const Ticker = await loadTickerWithDebug(false);
|
|
94
|
+
const spy = jest.fn();
|
|
95
|
+
const ticker = new Ticker(spy);
|
|
96
|
+
step(0);
|
|
97
|
+
expect(spy).not.toHaveBeenCalled();
|
|
98
|
+
step(5);
|
|
99
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
100
|
+
expect(spy).toHaveBeenLastCalledWith(expect.any(Number));
|
|
101
|
+
expect(lastArg(spy)).toBeCloseTo(0.005, 6);
|
|
102
|
+
ticker.remove();
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
describe('capped mode via blur (debugMode=true -> 6fps)', () => {
|
|
106
|
+
it('accumulates lag and calls at fixed-step boundaries (avoid exact boundary)', async () => {
|
|
107
|
+
const Ticker = await loadTickerWithDebug(true);
|
|
108
|
+
jest.spyOn(document, 'hasFocus').mockReturnValue(true);
|
|
109
|
+
const spy = jest.fn();
|
|
110
|
+
const ticker = new Ticker(spy);
|
|
111
|
+
// Apply 6fps cap using blur (fixedStep ≈ 1/6 ≈ 0.1666667s)
|
|
112
|
+
window.dispatchEvent(new Event('blur'));
|
|
113
|
+
// 100 + 70 = 170ms -> crosses one boundary -> one call ≈ fixedStep
|
|
114
|
+
step(100);
|
|
115
|
+
step(70);
|
|
116
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
117
|
+
expect(spy).toHaveBeenLastCalledWith(expect.any(Number));
|
|
118
|
+
expect(lastArg(spy)).toBeCloseTo(1 / 6, 6);
|
|
119
|
+
// Remaining lag ≈ 0.0033s
|
|
120
|
+
step(91); // still below another boundary
|
|
121
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
122
|
+
step(80); // crosses again
|
|
123
|
+
expect(spy).toHaveBeenCalledTimes(2);
|
|
124
|
+
expect(spy).toHaveBeenLastCalledWith(expect.any(Number));
|
|
125
|
+
expect(lastArg(spy)).toBeCloseTo(1 / 6, 6);
|
|
126
|
+
ticker.remove();
|
|
127
|
+
});
|
|
128
|
+
it('long frame (delta >= 2*fixedStep) triggers two calls: fixedStep then raw delta; then lag resets', async () => {
|
|
129
|
+
const Ticker = await loadTickerWithDebug(true);
|
|
130
|
+
jest.spyOn(document, 'hasFocus').mockReturnValue(true);
|
|
131
|
+
const spy = jest.fn();
|
|
132
|
+
const ticker = new Ticker(spy);
|
|
133
|
+
window.dispatchEvent(new Event('blur')); // enable 6fps cap
|
|
134
|
+
// 500ms (0.5s) >= 2 * (1/6 ≈ 0.3333s)
|
|
135
|
+
step(500);
|
|
136
|
+
expect(spy).toHaveBeenCalledTimes(2);
|
|
137
|
+
expect(spy).toHaveBeenNthCalledWith(1, expect.any(Number));
|
|
138
|
+
expect(argOf(spy, 0)).toBeCloseTo(1 / 6, 6);
|
|
139
|
+
expect(spy).toHaveBeenNthCalledWith(2, expect.any(Number));
|
|
140
|
+
expect(argOf(spy, 1)).toBeCloseTo(0.5, 6);
|
|
141
|
+
// Repeat pattern
|
|
142
|
+
step(500);
|
|
143
|
+
expect(spy).toHaveBeenCalledTimes(4);
|
|
144
|
+
expect(spy).toHaveBeenNthCalledWith(3, expect.any(Number));
|
|
145
|
+
expect(argOf(spy, 2)).toBeCloseTo(1 / 6, 6);
|
|
146
|
+
expect(spy).toHaveBeenNthCalledWith(4, expect.any(Number));
|
|
147
|
+
expect(argOf(spy, 3)).toBeCloseTo(0.5, 6);
|
|
148
|
+
ticker.remove();
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
describe('runtime transitions via focus/pageshow (debugMode=true)', () => {
|
|
152
|
+
it('blur -> capped(6fps) / focus -> uncapped: after focus, raw delta behavior resumes', async () => {
|
|
153
|
+
const Ticker = await loadTickerWithDebug(true);
|
|
154
|
+
jest.spyOn(document, 'hasFocus').mockReturnValue(true);
|
|
155
|
+
const spy = jest.fn();
|
|
156
|
+
const ticker = new Ticker(spy);
|
|
157
|
+
// Enter capped mode and get one fixed-step call
|
|
158
|
+
window.dispatchEvent(new Event('blur'));
|
|
159
|
+
step(170);
|
|
160
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
161
|
+
expect(spy).toHaveBeenLastCalledWith(expect.any(Number));
|
|
162
|
+
expect(lastArg(spy)).toBeCloseTo(1 / 6, 6);
|
|
163
|
+
// Back to uncapped
|
|
164
|
+
window.dispatchEvent(new Event('focus'));
|
|
165
|
+
spy.mockClear();
|
|
166
|
+
step(16);
|
|
167
|
+
step(33);
|
|
168
|
+
expect(spy).toHaveBeenCalledTimes(2);
|
|
169
|
+
expect(spy).toHaveBeenNthCalledWith(1, expect.any(Number));
|
|
170
|
+
expect(argOf(spy, 0)).toBeCloseTo(0.016, 6);
|
|
171
|
+
expect(spy).toHaveBeenNthCalledWith(2, expect.any(Number));
|
|
172
|
+
expect(argOf(spy, 1)).toBeCloseTo(0.033, 6);
|
|
173
|
+
ticker.remove();
|
|
174
|
+
});
|
|
175
|
+
it('pageshow(persisted=true) sets fpsCap to uncapped again', async () => {
|
|
176
|
+
const Ticker = await loadTickerWithDebug(true);
|
|
177
|
+
jest.spyOn(document, 'hasFocus').mockReturnValue(true);
|
|
178
|
+
const spy = jest.fn();
|
|
179
|
+
const ticker = new Ticker(spy);
|
|
180
|
+
window.dispatchEvent(new Event('blur'));
|
|
181
|
+
step(200); // > 1/6s => fixed-step call
|
|
182
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
183
|
+
expect(spy).toHaveBeenLastCalledWith(expect.any(Number));
|
|
184
|
+
expect(lastArg(spy)).toBeCloseTo(1 / 6, 6);
|
|
185
|
+
// Create a pageshow event with persisted=true (jsdom lacks PageTransitionEvent)
|
|
186
|
+
const evt = new Event('pageshow');
|
|
187
|
+
Object.defineProperty(evt, 'persisted', { value: true });
|
|
188
|
+
window.dispatchEvent(evt);
|
|
189
|
+
spy.mockClear();
|
|
190
|
+
step(25);
|
|
191
|
+
step(40);
|
|
192
|
+
expect(spy).toHaveBeenCalledTimes(2);
|
|
193
|
+
expect(spy).toHaveBeenNthCalledWith(1, expect.any(Number));
|
|
194
|
+
expect(argOf(spy, 0)).toBeCloseTo(0.025, 6);
|
|
195
|
+
expect(spy).toHaveBeenNthCalledWith(2, expect.any(Number));
|
|
196
|
+
expect(argOf(spy, 1)).toBeCloseTo(0.040, 6);
|
|
197
|
+
ticker.remove();
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
describe('remove()', () => {
|
|
201
|
+
it('cancels next RAF and stops future ticks; also cleans up listeners', async () => {
|
|
202
|
+
const Ticker = await loadTickerWithDebug(true);
|
|
203
|
+
// Ensure the ticker starts in uncapped mode so the first small step triggers a tick.
|
|
204
|
+
jest.spyOn(document, 'hasFocus').mockReturnValue(true);
|
|
205
|
+
const spy = jest.fn();
|
|
206
|
+
const cancelSpy = jest.spyOn(window, 'cancelAnimationFrame');
|
|
207
|
+
const ticker = new Ticker(spy);
|
|
208
|
+
step(16); // ~0.016s -> should tick in uncapped mode
|
|
209
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
210
|
+
ticker.remove();
|
|
211
|
+
expect(cancelSpy).toHaveBeenCalled();
|
|
212
|
+
spy.mockClear();
|
|
213
|
+
advance(200, 16);
|
|
214
|
+
expect(spy).not.toHaveBeenCalled();
|
|
215
|
+
// Listeners are cleaned up (dispatching events does nothing and does not throw)
|
|
216
|
+
expect(() => window.dispatchEvent(new Event('blur'))).not.toThrow();
|
|
217
|
+
expect(() => window.dispatchEvent(new Event('focus'))).not.toThrow();
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
describe('long-running sanity (ragged frames, capped=6fps)', () => {
|
|
221
|
+
it('produces a reasonable number of calls; includes fixedStep calls', async () => {
|
|
222
|
+
const Ticker = await loadTickerWithDebug(true);
|
|
223
|
+
jest.spyOn(document, 'hasFocus').mockReturnValue(true);
|
|
224
|
+
const spy = jest.fn();
|
|
225
|
+
const ticker = new Ticker(spy);
|
|
226
|
+
window.dispatchEvent(new Event('blur')); // 6fps -> fixedStep ≈ 0.1667
|
|
227
|
+
// Total ~1000ms with some long frames to trigger the split branch
|
|
228
|
+
const frames = [33, 33, 35, 201, 51, 61, 41, 201, 201, 251];
|
|
229
|
+
for (const ms of frames)
|
|
230
|
+
step(ms);
|
|
231
|
+
const calls = spy.mock.calls.length;
|
|
232
|
+
// With lag resets/rounding, tolerate a loose range
|
|
233
|
+
expect(calls).toBeGreaterThanOrEqual(5);
|
|
234
|
+
expect(calls).toBeLessThanOrEqual(9);
|
|
235
|
+
// At least one call should be exactly the fixed step (~1/6)
|
|
236
|
+
const hasFixedStep = spy.mock.calls.some(([dt]) => Math.abs(dt - 1 / 6) < 1e-6);
|
|
237
|
+
expect(hasFixedStep).toBe(true);
|
|
238
|
+
ticker.remove();
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
//# sourceMappingURL=ticker.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ticker.test.js","sourceRoot":"","sources":["../../src/renderer/ticker.test.ts"],"names":[],"mappings":";AAAA,8BAA8B;AAqB9B,iCAAiC;AACjC,IAAI,KAAK,GAAG,CAAC,CAAA;AAEb,kCAAkC;AAClC,MAAM,YAAY,GAAG,IAAI,GAAG,EAAmB,CAAA;AAC/C,IAAI,SAAS,GAAG,CAAC,CAAA;AAEjB,MAAM,sBAAsB,GAAG,GAAG,EAAE;IAClC,IAAI,CAAC,KAAK,CAA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G,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;QAC3D,KAAK,MAAM,EAAE,IAAI,MAAM;YAAE,IAAI,CAAC,EAAE,CAAC,CAAA;QAEjC,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAA;QACnC,mDAAmD;QACnD,MAAM,CAAC,KAAK,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAA;QACvC,MAAM,CAAC,KAAK,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAA;QAEpC,4DAA4D;QAC5D,MAAM,YAAY,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAE,EAAa,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,CAAA;QAC3F,MAAM,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAE/B,MAAM,CAAC,MAAM,EAAE,CAAA;IACjB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["/** @jest-environment jsdom */\n\n/**\n * Test Suite — Ticker (Jest)\n * -------------------------------------------------------\n * Goals\n * - Avoid floating-point pitfalls around fixed step boundaries\n * - Validate uncapped, capped via blur (6fps), long frame split,\n * focus/pageshow transitions, and remove()\n * - In this implementation: no setFixedFps; debugMode + focus/blur/pageshow control fps cap\n *\n * Principles\n * - Do not assert exactly at the boundary (e.g., prefer 170ms over ~166ms)\n * - Validate deltaTime using toBeCloseTo + loose call count checks\n */\n\n/** ----------------------- Time & RAF harness ----------------------- **/\n\n// Local callback type to avoid depending on DOM lib typings.\ntype FrameCb = (time: number) => void\n\n// Simulated monotonic clock (ms)\nlet nowMs = 0\n\n// RAF callback registry: id -> cb\nconst rafCallbacks = new Map<number, FrameCb>()\nlet nextRafId = 1\n\nconst installTimeAndRafMocks = () => {\n jest.spyOn(performance, 'now').mockImplementation(() => nowMs)\n\n jest\n .spyOn(window, 'requestAnimationFrame')\n .mockImplementation((cb: FrameCb) => {\n const id = nextRafId++\n rafCallbacks.set(id, cb)\n return id as unknown as number\n })\n\n jest.spyOn(window, 'cancelAnimationFrame').mockImplementation((id: number) => {\n rafCallbacks.delete(id)\n })\n}\n\nconst resetHarness = () => {\n nowMs = 0\n rafCallbacks.clear()\n nextRafId = 1\n}\n\n/**\n * Advance a single frame: move the clock by advanceMs and\n * run only the currently registered RAF callbacks\n * (callbacks registered during this step run on the next step).\n */\nconst step = (advanceMs: number) => {\n nowMs += advanceMs\n const cbs = [...rafCallbacks.values()]\n rafCallbacks.clear()\n for (const cb of cbs) cb(nowMs)\n}\n\n/** Advance multiple frames (helper) */\nconst advance = (totalMs: number, stepMs = 16) => {\n const n = Math.floor(totalMs / stepMs)\n for (let i = 0; i < n; i++) step(stepMs)\n const remain = totalMs - n * stepMs\n if (remain > 0) step(remain)\n}\n\n/**\n * Helper to (re)load Ticker with a specific debugMode value.\n * Uses jest.resetModules + jest.doMock to inject the desired export.\n */\nconst loadTickerWithDebug = async (debug: boolean) => {\n jest.resetModules()\n jest.doMock('../debug', () => ({ debugMode: debug }), { virtual: true })\n const mod = await import('./ticker')\n return (mod as any).Ticker as new (onTick: (dt: number) => void) => { remove(): void }\n}\n\n/** Small helpers to read arguments cleanly */\nconst argOf = (mockFn: jest.Mock, nthZeroBased: number) => mockFn.mock.calls[nthZeroBased][0] as number\nconst lastArg = (mockFn: jest.Mock) => {\n const i = mockFn.mock.calls.length - 1\n return mockFn.mock.calls[i][0] as number\n}\n\n/** ----------------------- Lifecycle -------------------------- **/\n\nbeforeEach(() => {\n resetHarness()\n jest.restoreAllMocks()\n installTimeAndRafMocks()\n})\n\nafterEach(() => {\n jest.restoreAllMocks()\n resetHarness()\n})\n\n/** ----------------------- Tests ------------------------------ **/\n\ndescribe('uncapped mode (debugMode=false)', () => {\n it('calls onTick once per frame with raw deltaTime (seconds)', async () => {\n const Ticker = await loadTickerWithDebug(false)\n const spy = jest.fn()\n const ticker = new Ticker(spy) // default: uncapped\n\n step(10) // 0.010\n step(20) // 0.020\n step(30) // 0.030\n\n expect(spy).toHaveBeenCalledTimes(3)\n\n // Assert shapes, then values\n expect(spy).toHaveBeenNthCalledWith(1, expect.any(Number))\n expect(spy).toHaveBeenNthCalledWith(2, expect.any(Number))\n expect(spy).toHaveBeenNthCalledWith(3, expect.any(Number))\n\n expect(argOf(spy, 0)).toBeCloseTo(0.010, 6)\n expect(argOf(spy, 1)).toBeCloseTo(0.020, 6)\n expect(argOf(spy, 2)).toBeCloseTo(0.030, 6)\n\n ticker.remove()\n })\n\n it('does not call onTick when deltaTime <= 0', async () => {\n const Ticker = await loadTickerWithDebug(false)\n const spy = jest.fn()\n const ticker = new Ticker(spy)\n\n step(0)\n expect(spy).not.toHaveBeenCalled()\n\n step(5)\n expect(spy).toHaveBeenCalledTimes(1)\n expect(spy).toHaveBeenLastCalledWith(expect.any(Number))\n expect(lastArg(spy)).toBeCloseTo(0.005, 6)\n\n ticker.remove()\n })\n})\n\ndescribe('capped mode via blur (debugMode=true -> 6fps)', () => {\n it('accumulates lag and calls at fixed-step boundaries (avoid exact boundary)', async () => {\n const Ticker = await loadTickerWithDebug(true)\n jest.spyOn(document, 'hasFocus').mockReturnValue(true)\n\n const spy = jest.fn()\n const ticker = new Ticker(spy)\n\n // Apply 6fps cap using blur (fixedStep ≈ 1/6 ≈ 0.1666667s)\n window.dispatchEvent(new Event('blur'))\n\n // 100 + 70 = 170ms -> crosses one boundary -> one call ≈ fixedStep\n step(100)\n step(70)\n expect(spy).toHaveBeenCalledTimes(1)\n expect(spy).toHaveBeenLastCalledWith(expect.any(Number))\n expect(lastArg(spy)).toBeCloseTo(1 / 6, 6)\n\n // Remaining lag ≈ 0.0033s\n step(91) // still below another boundary\n expect(spy).toHaveBeenCalledTimes(1)\n step(80) // crosses again\n expect(spy).toHaveBeenCalledTimes(2)\n expect(spy).toHaveBeenLastCalledWith(expect.any(Number))\n expect(lastArg(spy)).toBeCloseTo(1 / 6, 6)\n\n ticker.remove()\n })\n\n it('long frame (delta >= 2*fixedStep) triggers two calls: fixedStep then raw delta; then lag resets', async () => {\n const Ticker = await loadTickerWithDebug(true)\n jest.spyOn(document, 'hasFocus').mockReturnValue(true)\n\n const spy = jest.fn()\n const ticker = new Ticker(spy)\n\n window.dispatchEvent(new Event('blur')) // enable 6fps cap\n\n // 500ms (0.5s) >= 2 * (1/6 ≈ 0.3333s)\n step(500)\n expect(spy).toHaveBeenCalledTimes(2)\n\n expect(spy).toHaveBeenNthCalledWith(1, expect.any(Number))\n expect(argOf(spy, 0)).toBeCloseTo(1 / 6, 6)\n\n expect(spy).toHaveBeenNthCalledWith(2, expect.any(Number))\n expect(argOf(spy, 1)).toBeCloseTo(0.5, 6)\n\n // Repeat pattern\n step(500)\n expect(spy).toHaveBeenCalledTimes(4)\n\n expect(spy).toHaveBeenNthCalledWith(3, expect.any(Number))\n expect(argOf(spy, 2)).toBeCloseTo(1 / 6, 6)\n\n expect(spy).toHaveBeenNthCalledWith(4, expect.any(Number))\n expect(argOf(spy, 3)).toBeCloseTo(0.5, 6)\n\n ticker.remove()\n })\n})\n\ndescribe('runtime transitions via focus/pageshow (debugMode=true)', () => {\n it('blur -> capped(6fps) / focus -> uncapped: after focus, raw delta behavior resumes', async () => {\n const Ticker = await loadTickerWithDebug(true)\n jest.spyOn(document, 'hasFocus').mockReturnValue(true)\n\n const spy = jest.fn()\n const ticker = new Ticker(spy)\n\n // Enter capped mode and get one fixed-step call\n window.dispatchEvent(new Event('blur'))\n step(170)\n expect(spy).toHaveBeenCalledTimes(1)\n expect(spy).toHaveBeenLastCalledWith(expect.any(Number))\n expect(lastArg(spy)).toBeCloseTo(1 / 6, 6)\n\n // Back to uncapped\n window.dispatchEvent(new Event('focus'))\n\n spy.mockClear()\n step(16)\n step(33)\n expect(spy).toHaveBeenCalledTimes(2)\n\n expect(spy).toHaveBeenNthCalledWith(1, expect.any(Number))\n expect(argOf(spy, 0)).toBeCloseTo(0.016, 6)\n\n expect(spy).toHaveBeenNthCalledWith(2, expect.any(Number))\n expect(argOf(spy, 1)).toBeCloseTo(0.033, 6)\n\n ticker.remove()\n })\n\n it('pageshow(persisted=true) sets fpsCap to uncapped again', async () => {\n const Ticker = await loadTickerWithDebug(true)\n jest.spyOn(document, 'hasFocus').mockReturnValue(true)\n\n const spy = jest.fn()\n const ticker = new Ticker(spy)\n\n window.dispatchEvent(new Event('blur'))\n step(200) // > 1/6s => fixed-step call\n expect(spy).toHaveBeenCalledTimes(1)\n expect(spy).toHaveBeenLastCalledWith(expect.any(Number))\n expect(lastArg(spy)).toBeCloseTo(1 / 6, 6)\n\n // Create a pageshow event with persisted=true (jsdom lacks PageTransitionEvent)\n const evt = new Event('pageshow') as Event & { persisted?: boolean }\n Object.defineProperty(evt, 'persisted', { value: true })\n window.dispatchEvent(evt)\n\n spy.mockClear()\n step(25)\n step(40)\n expect(spy).toHaveBeenCalledTimes(2)\n\n expect(spy).toHaveBeenNthCalledWith(1, expect.any(Number))\n expect(argOf(spy, 0)).toBeCloseTo(0.025, 6)\n\n expect(spy).toHaveBeenNthCalledWith(2, expect.any(Number))\n expect(argOf(spy, 1)).toBeCloseTo(0.040, 6)\n\n ticker.remove()\n })\n})\n\ndescribe('remove()', () => {\n it('cancels next RAF and stops future ticks; also cleans up listeners', async () => {\n const Ticker = await loadTickerWithDebug(true)\n\n // Ensure the ticker starts in uncapped mode so the first small step triggers a tick.\n jest.spyOn(document, 'hasFocus').mockReturnValue(true)\n\n const spy = jest.fn()\n const cancelSpy = jest.spyOn(window, 'cancelAnimationFrame')\n\n const ticker = new Ticker(spy)\n\n step(16) // ~0.016s -> should tick in uncapped mode\n expect(spy).toHaveBeenCalledTimes(1)\n\n ticker.remove()\n expect(cancelSpy).toHaveBeenCalled()\n\n spy.mockClear()\n advance(200, 16)\n expect(spy).not.toHaveBeenCalled()\n\n // Listeners are cleaned up (dispatching events does nothing and does not throw)\n expect(() => window.dispatchEvent(new Event('blur'))).not.toThrow()\n expect(() => window.dispatchEvent(new Event('focus'))).not.toThrow()\n })\n})\n\ndescribe('long-running sanity (ragged frames, capped=6fps)', () => {\n it('produces a reasonable number of calls; includes fixedStep calls', async () => {\n const Ticker = await loadTickerWithDebug(true)\n jest.spyOn(document, 'hasFocus').mockReturnValue(true)\n\n const spy = jest.fn()\n const ticker = new Ticker(spy)\n\n window.dispatchEvent(new Event('blur')) // 6fps -> fixedStep ≈ 0.1667\n\n // Total ~1000ms with some long frames to trigger the split branch\n const frames = [33, 33, 35, 201, 51, 61, 41, 201, 201, 251]\n for (const ms of frames) step(ms)\n\n const calls = spy.mock.calls.length\n // With lag resets/rounding, tolerate a loose range\n expect(calls).toBeGreaterThanOrEqual(5)\n expect(calls).toBeLessThanOrEqual(9)\n\n // At least one call should be exactly the fixed step (~1/6)\n const hasFixedStep = spy.mock.calls.some(([dt]) => Math.abs((dt as number) - 1 / 6) < 1e-6)\n expect(hasFixedStep).toBe(true)\n\n ticker.remove()\n })\n})\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const audioContext: AudioContext;
|
|
1
|
+
export declare const audioContext: AudioContext;
|
|
2
2
|
declare class MusicPlayer {
|
|
3
3
|
#private;
|
|
4
4
|
constructor();
|
|
@@ -14,8 +14,9 @@ declare class SfxPlayer {
|
|
|
14
14
|
get volume(): number;
|
|
15
15
|
set volume(volume: number);
|
|
16
16
|
play(src: string): void;
|
|
17
|
+
playRandom(...srcs: string[]): void;
|
|
17
18
|
}
|
|
18
|
-
declare const musicPlayer: MusicPlayer;
|
|
19
|
-
declare const sfxPlayer: SfxPlayer;
|
|
20
|
-
export {
|
|
19
|
+
export declare const musicPlayer: MusicPlayer;
|
|
20
|
+
export declare const sfxPlayer: SfxPlayer;
|
|
21
|
+
export {};
|
|
21
22
|
//# sourceMappingURL=audio.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audio.d.ts","sourceRoot":"","sources":["../../../src/asset/audio.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"audio.d.ts","sourceRoot":"","sources":["../../../src/asset/audio.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY,cAAoE,CAAA;AAgJ7F,cAAM,WAAW;;;IAmBf,IAAI,MAAM,IAIS,MAAM,CAFxB;IAED,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,EAIxB;IAED,IAAI,CAAC,GAAG,EAAE,MAAM;IAMhB,KAAK;IAIL,IAAI;CAIL;AAED,cAAM,SAAS;;;IAQb,IAAI,MAAM,IAIS,MAAM,CAFxB;IAED,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,EAGxB;IAED,IAAI,CAAC,GAAG,EAAE,MAAM;IAIhB,UAAU,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE;CAG7B;AAED,eAAO,MAAM,WAAW,aAAoB,CAAA;AAC5C,eAAO,MAAM,SAAS,WAAkB,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Loader } from './loader';
|
|
2
2
|
declare class AudioLoader extends Loader<AudioBuffer> {
|
|
3
|
-
protected
|
|
3
|
+
protected doLoad(src: string): Promise<AudioBuffer | undefined>;
|
|
4
4
|
}
|
|
5
5
|
export declare const audioLoader: AudioLoader;
|
|
6
6
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audio.d.ts","sourceRoot":"","sources":["../../../../src/asset/loaders/audio.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"audio.d.ts","sourceRoot":"","sources":["../../../../src/asset/loaders/audio.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,cAAM,WAAY,SAAQ,MAAM,CAAC,WAAW,CAAC;cAClB,MAAM,CAAC,GAAG,EAAE,MAAM;CAgC5C;AAED,eAAO,MAAM,WAAW,aAAoB,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Loader } from './loader';
|
|
2
2
|
declare class BinaryLoader extends Loader<Uint8Array> {
|
|
3
|
-
protected
|
|
3
|
+
protected doLoad(src: string): Promise<Uint8Array<ArrayBuffer> | undefined>;
|
|
4
4
|
}
|
|
5
5
|
export declare const binaryLoader: BinaryLoader;
|
|
6
6
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"binary.d.ts","sourceRoot":"","sources":["../../../../src/asset/loaders/binary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"binary.d.ts","sourceRoot":"","sources":["../../../../src/asset/loaders/binary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,cAAM,YAAa,SAAQ,MAAM,CAAC,UAAU,CAAC;cAClB,MAAM,CAAC,GAAG,EAAE,MAAM;CA0B5C;AAED,eAAO,MAAM,YAAY,cAAqB,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BitmapFont, Char } from '../../types/bitmap-font';
|
|
2
|
+
import { Loader } from './loader';
|
|
3
|
+
declare class BitmapFontLoader extends Loader<BitmapFont> {
|
|
4
|
+
#private;
|
|
5
|
+
protected doLoad(fnt: string, src: string): Promise<{
|
|
6
|
+
src: string;
|
|
7
|
+
chars: Record<number, Char>;
|
|
8
|
+
texture: import("pixi.js").Texture<import("pixi.js").TextureSource<any>>;
|
|
9
|
+
size: number;
|
|
10
|
+
lineHeight: number;
|
|
11
|
+
} | undefined>;
|
|
12
|
+
protected cleanup(fnt: string): void;
|
|
13
|
+
}
|
|
14
|
+
export declare const bitmapFontLoader: BitmapFontLoader;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=bitmap-font.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitmap-font.d.ts","sourceRoot":"","sources":["../../../../src/asset/loaders/bitmap-font.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAGjC,cAAM,gBAAiB,SAAQ,MAAM,CAAC,UAAU,CAAC;;cAGtB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;;;;;;;cAuErC,OAAO,CAAC,GAAG,EAAE,MAAM;CAIvC;AAED,eAAO,MAAM,gBAAgB,kBAAyB,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Loader } from './loader';
|
|
2
2
|
declare class FontFamilyLoader extends Loader<boolean> {
|
|
3
|
-
protected
|
|
3
|
+
protected doLoad(fontName: string): Promise<true | undefined>;
|
|
4
4
|
}
|
|
5
5
|
export declare const fontFamilyLoader: FontFamilyLoader;
|
|
6
6
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"font.d.ts","sourceRoot":"","sources":["../../../../src/asset/loaders/font.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"font.d.ts","sourceRoot":"","sources":["../../../../src/asset/loaders/font.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,cAAM,gBAAiB,SAAQ,MAAM,CAAC,OAAO,CAAC;cACnB,MAAM,CAAC,QAAQ,EAAE,MAAM;CAqBjD;AAED,eAAO,MAAM,gBAAgB,kBAAyB,CAAA"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
declare abstract class Loader<T> {
|
|
1
|
+
export declare abstract class Loader<T> {
|
|
2
2
|
#private;
|
|
3
|
-
protected
|
|
3
|
+
protected cachedAssets: Map<string, T>;
|
|
4
4
|
protected loadingPromises: Map<string, Promise<T | undefined>>;
|
|
5
5
|
protected hasActiveRef(id: string): boolean;
|
|
6
|
-
protected abstract
|
|
7
|
-
protected
|
|
8
|
-
|
|
6
|
+
protected abstract doLoad(id: string, ...args: any[]): Promise<T | undefined>;
|
|
7
|
+
protected cleanup(id: string, asset: T): void;
|
|
8
|
+
checkCached(id: string): boolean;
|
|
9
|
+
getCached(id: string): T | undefined;
|
|
9
10
|
load(id: string, ...args: any[]): Promise<T | undefined>;
|
|
10
11
|
release(id: string): void;
|
|
11
12
|
}
|
|
12
|
-
export { Loader };
|
|
13
13
|
//# sourceMappingURL=loader.d.ts.map
|