LCOV - code coverage report
Current view: top level - lib/src/game - game_loop.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 13 20 65.0 %
Date: 2021-08-10 15:50:53 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:flutter/scheduler.dart';
       2             : 
       3             : class GameLoop {
       4             :   void Function(double dt) callback;
       5             :   Duration previous = Duration.zero;
       6             :   late Ticker _ticker;
       7             : 
       8           2 :   GameLoop(this.callback) {
       9           6 :     _ticker = Ticker(_tick);
      10             :   }
      11             : 
      12           1 :   void _tick(Duration timestamp) {
      13           1 :     final dt = _computeDeltaT(timestamp);
      14           2 :     callback(dt);
      15             :   }
      16             : 
      17           1 :   double _computeDeltaT(Duration now) {
      18           4 :     final delta = previous == Duration.zero ? Duration.zero : now - previous;
      19           1 :     previous = now;
      20           2 :     return delta.inMicroseconds / Duration.microsecondsPerSecond;
      21             :   }
      22             : 
      23           2 :   void start() {
      24           4 :     _ticker.start();
      25             :   }
      26             : 
      27           0 :   void stop() {
      28           0 :     _ticker.stop();
      29             :   }
      30             : 
      31           2 :   void dispose() {
      32           4 :     _ticker.dispose();
      33             :   }
      34             : 
      35           0 :   void pause() {
      36           0 :     _ticker.muted = true;
      37           0 :     previous = Duration.zero;
      38             :   }
      39             : 
      40           0 :   void resume() {
      41           0 :     _ticker.muted = false;
      42             :   }
      43             : }

Generated by: LCOV version 1.15