xbmc
GameLoop.h
1 /*
2  * Copyright (C) 2016-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "threads/Event.h"
12 #include "threads/Thread.h"
13 
14 #include <atomic>
15 
16 namespace KODI
17 {
18 namespace RETRO
19 {
21 {
22 public:
23  virtual ~IGameLoopCallback() = default;
24 
28  virtual void FrameEvent() = 0;
29 
33  virtual void RewindEvent() = 0;
34 };
35 
36 class CGameLoop : protected CThread
37 {
38 public:
39  CGameLoop(IGameLoopCallback* callback, double fps);
40 
41  ~CGameLoop() override;
42 
43  void Start();
44  void Stop();
45 
46  double FPS() const { return m_fps; }
47 
48  double GetSpeed() const { return m_speedFactor; }
49  void SetSpeed(double speedFactor);
50  void PauseAsync();
51 
52 protected:
53  // implementation of CThread
54  void Process() override;
55 
56 private:
57  double FrameTimeMs() const;
58  double SleepTimeMs() const;
59  double NowMs() const;
60 
61  IGameLoopCallback* const m_callback;
62  const double m_fps;
63  std::atomic<double> m_speedFactor;
64  double m_lastFrameMs = 0.0;
65  mutable double m_adjustTime = 0.0;
66  CEvent m_sleepEvent;
67 };
68 } // namespace RETRO
69 } // namespace KODI
This is an Event class built from a ConditionVariable.
Definition: Event.h:35
Definition: Thread.h:44
virtual void FrameEvent()=0
The next frame is being shown.
Definition: GameLoop.h:20
Definition: AudioDecoder.h:18
virtual void RewindEvent()=0
The prior frame is being shown.
Definition: GameLoop.h:36