Files
Documentation/Runtime.md
T

105 lines
2.8 KiB
Markdown
Raw Normal View History

This guide will describe how GamesRunnr runs upkeep functions and how FSPAnalyzer is used to schedule them in GameStartr projects.
# GamesRunnr
GamesRunnr is a module for running a series of callbacks grouped into one interval.
These callbacks deal with maintaining the state of the game, like having a callback to redraw the canvas.
These callbacks separately are referred to as games.
## Upkeep
`upkeep` is a function that runs each game once.
`upkeepTimed` is a utility function for `upkeep` that times and returns the amount of time it takes to run all the games.
2017-01-27 01:19:31 -08:00
```javascript
2016-11-26 01:39:41 -05:00
const totalTime: number = gamesRunner.upkeepTimed();
console.log(`It took `${totalTime}` ms.`);
```
## Interval and Speed
Each call of `upkeep` has a set time delay, in milliseconds, before it can be called again, called an interval.
To set the interval use `setInterval`.
2017-01-27 01:19:31 -08:00
```javascript
2016-11-26 01:39:41 -05:00
gamesRunner.setInterval(20);
```
`speed` is a variable which represents the playback speed of the intervals, for example a speed of 2 makes the intervals go by twice as fast.
To set the value, use `setSpeed`.
2017-01-27 01:19:31 -08:00
```javascript
2016-11-26 01:39:41 -05:00
gamesRunner.setSpeed(2);
```
## Pause and Play
GamesRunnr can pause and continue `upkeep` execution.
`pause` stops the execution of `upkeep` and cancels the next call of upkeep.
2017-01-27 01:19:31 -08:00
```javascript
2016-11-26 01:39:41 -05:00
gamesRunner.pause();
```
`play` continues execution of `upkeep` by calling it.
2017-01-27 01:19:31 -08:00
```javascript
2016-11-26 01:39:41 -05:00
gamesRunner.play();
```
Both `pause` and `play` allow for trigger functions to run when they are called by defining `onPause` and `onPlay`.
2017-01-27 01:19:31 -08:00
```javascript
const gamesRunner = new GamesRunnr({
games: [() => console.log("example function")],
onPause: () => console.log("upkeep is paused"),
onPlay: () => console.log("upkeep is resumed")
});
2016-11-26 01:39:41 -05:00
gamesRunner.pause();
gamesRunner.play();
```
To toggle between the two, use `togglePause`.
2017-01-27 01:19:31 -08:00
```javascript
2016-11-26 01:39:41 -05:00
gamesRunner.togglePause();
```
More can be read on GamesRunnr on its [Readme](https://github.com/FullScreenShenanigans/GamesRunnr/blob/master/README.md).
2017-01-27 01:19:31 -08:00
# FPSAnalyzr
## Measure
FSPAnalyzr is a module for recording and analyzing framerate measurements.
`measure` and is run at the end of every `upkeep` call.
2017-01-27 01:19:31 -08:00
```javascript
2016-11-26 01:39:41 -05:00
fpsAnalyzer.measure();
```
It updates the value for the current timestamp and if there was a previous timestamp recorded, it adds an FPS measurement to the list of recorded measurements with `addFPS`.
2017-01-27 01:19:31 -08:00
```javascript
2016-11-26 01:39:41 -05:00
fpsAnalyzer.addFPS(40);
```
## Getters
FPSAnalyzer has a number of getter functions that return statistics and information on the recorded measurements.
2017-01-27 01:19:31 -08:00
```javascript
2016-11-26 01:39:41 -05:00
fpsAnalyzer.getNumRecorded();
fpsAnalyzer.getTicker();
fpsAnalyzer.getMeasurements();
fpsAnalyzer.getDifferences();
fpsAnalyzer.getAverage();
fpsAnalyzer.getMedian();
fpsAnalyzer.getExtremes();
fpsAnalyzer.getRange();
```
2016-11-26 01:39:41 -05:00
More can be read on FPSAnalyzr on its [Readme](https://github.com/FullScreenShenanigans/FPSAnalyzr/blob/master/README.md).