startGameloop method

void startGameloop(
  1. TimerstepTrigger condition
)

Implementation

void startGameloop(TimerstepTrigger condition){
  _timerStateCounter = (type: condition.type, count: 0, interval: Duration.zero, elapsed: Duration.zero, start: DateTime.now());
  _timerStateTicker = createTicker((Duration elapsed){
    // gameDebug('ticker-elapsed:$elapsed');
    if(acceptTrigger){
      if(_timerStateAnimTickers.isNotEmpty){
        _timerStateAnimTickers.removeWhere((tickerCallback)=>tickerCallback(elapsed - _timerStateCounter.elapsed));
      }
      if(_timerStateCounter.type == TimerstepTriggertype.none) return gameStep(_timerStateCounter);
      /// 更新计数
      _timerStateCounter = (type:_timerStateCounter.type, count: _timerStateCounter.count + 1, elapsed: elapsed, interval: _timerStateCounter.interval + elapsed - _timerStateCounter.elapsed, start: _timerStateCounter.start);
      /// 判断
      bool countMatch = _timerStateCounter.count >= condition.count;
      bool intervalMatch = _timerStateCounter.interval >= condition.interval;
      bool nowTimeMatch = DateTime.now().millisecondsSinceEpoch >= condition.start.millisecondsSinceEpoch;
      if(
        _timerStateCounter.type == TimerstepTriggertype.count && countMatch ||
        (_timerStateCounter.type == TimerstepTriggertype.interval && intervalMatch) ||
        (_timerStateCounter.type == TimerstepTriggertype.clock && nowTimeMatch) ||
        (_timerStateCounter.type == TimerstepTriggertype.all && (countMatch || intervalMatch || nowTimeMatch))
        ){
          gameStep(_timerStateCounter);
          _timerStateCounter = (type: condition.type, count: 0, elapsed: elapsed, interval: Duration.zero, start: DateTime.now());
        }else{
          // gameDebug(_elapsed);
        }
    }})
  ..start();
}