Skip to content

Commit

Permalink
[#1091] refactor Timer into an instantiable class
Browse files Browse the repository at this point in the history
time (namespace) is now a default instance of the Timer class
  • Loading branch information
obiot committed Jun 13, 2022
1 parent 52e6759 commit 372ead4
Show file tree
Hide file tree
Showing 4 changed files with 253 additions and 216 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@
## [10.11.0] (melonJS 2) - _2022-XX-XX_

### Changed
- Core: refactored Timer into an instantiable class with `time` (namespace) now being a default instance of the Timer class
- Doc: replaced JSDoc by Webdoc for documentation generation (huge thanks to @ShukantPal)

### Fixed
Expand Down
10 changes: 3 additions & 7 deletions src/state/state.js
@@ -1,7 +1,6 @@
import { pauseTrack, resumeTrack } from "./../audio/audio.js";
import * as fctUtil from "./../utils/function.js";
import * as event from "./../system/event.js";
import timer from "./../system/timer.js";
import * as game from "./../game.js";
import Stage from "./../state/stage.js";
import DefaultLoadingScreen from "./../loader/loadingscreen.js";
Expand Down Expand Up @@ -41,9 +40,6 @@ var _pauseTime = 0;
function _startRunLoop() {
// ensure nothing is running first and in valid state
if ((_animFrameId === -1) && (_state !== -1)) {
// reset the timer
timer.reset();

// start the main loop
_animFrameId = globalThis.requestAnimationFrame(_renderFrame);
}
Expand All @@ -56,9 +52,6 @@ function _startRunLoop() {
function _resumeRunLoop() {
// ensure game is actually paused and in valid state
if (_isPaused && (_state !== -1)) {
// reset the timer
timer.reset();

_isPaused = false;
}
}
Expand Down Expand Up @@ -124,6 +117,9 @@ function _switchState(state) {
// new requested state
_startRunLoop();

// publish the pause event
event.emit(event.STATE_CHANGE);

// execute callback if defined
if (_onSwitchComplete) {
_onSwitchComplete();
Expand Down
11 changes: 11 additions & 0 deletions src/system/event.js
Expand Up @@ -67,6 +67,17 @@ export const STATE_STOP = "me.state.onStop";
*/
export const STATE_RESTART = "me.state.onRestart";

/**
* event for when the changing to a different stage
* @public
* @constant
* @type {string}
* @name STATE_CHANGE
* @memberof event
* @see event.on
*/
export const STATE_CHANGE = "me.state.onChange";

/**
* event for when the video is initialized<br>
* Data passed : none <br>
Expand Down

0 comments on commit 372ead4

Please sign in to comment.