Otclient  14/8/2020
adaptativeframecounter.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 #ifndef ADAPTATIVEFRAMECOUNTER_H
24 #define ADAPTATIVEFRAMECOUNTER_H
25 
26 #include <framework/global.h>
27 
35 {
36 public:
37  enum {
38  // 4ms because most platforms has kernel timer of 250Hz
40  };
41 
43 
45  void processNextFrame();
46  bool update();
47  void setMaxFps(int maxFps);
48  bool isFpsLimitActive() { return m_maxFps != 0; }
49 
51  float getFrameDelayHit();
52  int getLastFps() { return m_lastFps; }
53  int getPartialFps() { return (int)m_partialFps; }
54  int getMaxFps() { return m_maxFps; }
55  int getFrames() { return m_frames; }
56  float getMediumFrameDelay() { return m_mediumFrameDelay; }
57 
58 private:
59  int m_frames;
60  int m_partialFrames;
61  float m_partialFps;
62  float m_maxPartialFps;
63  ticks_t m_frameDelaySum;
64  ticks_t m_mediumFrameDelay;
65  ticks_t m_lastFrame;
66  int m_lastFps;
67  int m_maxFps;
68  ticks_t m_bestFrameDelay;
69  ticks_t m_lastFpsUpdate;
70  ticks_t m_lastPartialFpsUpdate;
71  float m_sleepMicros;
72 };
73 
74 #endif
AdaptativeFrameCounter::getFrameDelayHit
float getFrameDelayHit()
Definition: adaptativeframecounter.cpp:110
AdaptativeFrameCounter::getFrames
int getFrames()
Definition: adaptativeframecounter.h:55
AdaptativeFrameCounter::isFpsLimitActive
bool isFpsLimitActive()
Definition: adaptativeframecounter.h:48
AdaptativeFrameCounter::getMaxFps
int getMaxFps()
Definition: adaptativeframecounter.h:54
AdaptativeFrameCounter::processNextFrame
void processNextFrame()
Definition: adaptativeframecounter.cpp:54
AdaptativeFrameCounter::update
bool update()
Definition: adaptativeframecounter.cpp:63
AdaptativeFrameCounter::AdaptativeFrameCounter
AdaptativeFrameCounter()
Definition: adaptativeframecounter.cpp:26
ticks_t
int64 ticks_t
Definition: types.h:43
AdaptativeFrameCounter::getPartialFps
int getPartialFps()
Definition: adaptativeframecounter.h:53
AdaptativeFrameCounter
Definition: adaptativeframecounter.h:34
AdaptativeFrameCounter::MINIMUM_MICROS_SLEEP
@ MINIMUM_MICROS_SLEEP
Definition: adaptativeframecounter.h:39
AdaptativeFrameCounter::setMaxFps
void setMaxFps(int maxFps)
Definition: adaptativeframecounter.cpp:90
AdaptativeFrameCounter::getLastFps
int getLastFps()
Definition: adaptativeframecounter.h:52
AdaptativeFrameCounter::shouldProcessNextFrame
bool shouldProcessNextFrame()
Definition: adaptativeframecounter.cpp:43
AdaptativeFrameCounter::getMaximumSleepMicros
int getMaximumSleepMicros()
Definition: adaptativeframecounter.cpp:103
global.h
AdaptativeFrameCounter::getMediumFrameDelay
float getMediumFrameDelay()
Definition: adaptativeframecounter.h:56