cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

timer.h (1829B)


      1/*
      2 * Gearboy - Nintendo Game Boy Emulator
      3 * Copyright (C) 2012  Ignacio Sanchez
      4 
      5 * This program is free software: you can redistribute it and/or modify
      6 * it under the terms of the GNU General Public License as published by
      7 * the Free Software Foundation, either version 3 of the License, or
      8 * any later version.
      9 
     10 * This program is distributed in the hope that it will be useful,
     11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     13 * GNU General Public License for more details.
     14 
     15 * You should have received a copy of the GNU General Public License
     16 * along with this program.  If not, see http://www.gnu.org/licenses/
     17 *
     18 */
     19
     20#pragma once
     21#ifndef _TIMER_H
     22#define	_TIMER_H
     23
     24#include <mach/mach.h>
     25#include <mach/mach_time.h>
     26#include "../../../src/definitions.h"
     27
     28#define FPS_REFRESH_TIME	0.5f
     29
     30#define FRAME_RATE_AVERAGE 5
     31
     32class Timer
     33{
     34public:
     35    Timer(void);
     36
     37    Timer(bool calculateFPS)
     38    {
     39        m_bCalculateFPS = calculateFPS;
     40
     41        Reset();
     42    };
     43
     44    ~Timer(void);
     45    void Start(void);
     46    void Stop(void);
     47    void Continue(void);
     48
     49    float GetActualTime(void) const;
     50    float GetFrameTime(void) const;
     51    float GetDeltaTime(void) const;
     52
     53    void Reset(void);
     54    void Update(void);
     55    float GetFPS(void) const;
     56
     57    bool IsRunning(void) const;
     58
     59    void SetOffset(const float offset)
     60    {
     61        m_fOffset = offset;
     62    };
     63
     64private:
     65    bool m_bCalculateFPS;
     66    bool m_bIsRunning;
     67
     68    float m_fOffset;
     69
     70    u64 m_i64BaseTicks;
     71    u64 m_i64StopedTicks;
     72
     73    float m_fResolution;
     74
     75    float m_fFrameTime;
     76    float m_fDeltaTime;
     77
     78    u32 m_iFrameCount;
     79    float m_fLastUpdate;
     80    float m_fFPS;
     81
     82    float m_fDeltaTimeAccumulation[FRAME_RATE_AVERAGE];
     83    int m_iCurrentAccumulator;
     84};
     85
     86#endif	/* _TIMER_H */