ManaPlus
SDL2_framerate.h
Go to the documentation of this file.
1 /*
2 
3 SDL2_framerate.h: framerate manager
4 
5 Copyright (C) 2012-2014 Andreas Schiffler
6 
7 This software is provided 'as-is', without any express or implied
8 warranty. In no event will the authors be held liable for any damages
9 arising from the use of this software.
10 
11 Permission is granted to anyone to use this software for any purpose,
12 including commercial applications, and to alter it and redistribute it
13 freely, subject to the following restrictions:
14 
15 1. The origin of this software must not be misrepresented; you must not
16 claim that you wrote the original software. If you use this software
17 in a product, an acknowledgment in the product documentation would be
18 appreciated but is not required.
19 
20 2. Altered source versions must be plainly marked as such, and must not be
21 misrepresented as being the original software.
22 
23 3. This notice may not be removed or altered from any source
24 distribution.
25 
26 Andreas Schiffler -- aschiffler at ferzkopp dot net
27 
28 Changed for ManaPlus (C) 2013-2017 ManaPlus developers
29 
30 */
31 
32 #ifndef _SDL2_framerate_h
33 #define _SDL2_framerate_h
34 
35 /* Set up for C function definitions, even when using C++ */
36 #ifdef __cplusplus
37 extern "C"
38 {
39 #endif
40 
41  /* --- */
42 
43 #include "localconsts.h"
44 
45 PRAGMA48(GCC diagnostic push)
46 PRAGMA48(GCC diagnostic ignored "-Wshadow")
47 #include <SDL.h>
48 PRAGMA48(GCC diagnostic pop)
49 
50  /* --------- Definitions */
51 
52 
55 #define FPS_UPPER_LIMIT 200
56 
60 #define FPS_LOWER_LIMIT 1
61 
65 #define FPS_DEFAULT 30
66 
70  typedef struct
71  {
72  Uint32 framecount;
73  float rateticks;
74  Uint32 baseticks;
75  Uint32 lastticks;
76  Uint32 rate;
77  } FPSmanager;
78 
79  /* ---- Function Prototypes */
80 
81 #ifdef _MSC_VER
82 # if defined(DLL_EXPORT) && !defined(LIBSDL2_GFX_DLL_IMPORT)
83 # define SDL2_FRAMERATE_SCOPE __declspec(dllexport)
84 # else
85 # ifdef LIBSDL2_GFX_DLL_IMPORT
86 # define SDL2_FRAMERATE_SCOPE __declspec(dllimport)
87 # endif
88 # endif
89 #endif
90 #ifndef SDL2_FRAMERATE_SCOPE
91 # define SDL2_FRAMERATE_SCOPE extern
92 #endif
93 
94  /* Functions return 0 or value for sucess and -1 for error */
95 
98  Uint32 rate);
102 
103  /* --- */
104 
105  /* Ends C function definitions when using C++ */
106 #ifdef __cplusplus
107 }
108 #endif
109 
110 #endif /* _SDL2_framerate_h */
void SDL_initFramerate(FPSmanager *manager)
Initialize the framerate manager.
int SDL_getFramerate(FPSmanager *manager)
Return the current target framerate in Hz.
int SDL_getFramecount(FPSmanager *manager)
Return the current framecount.
#define SDL2_FRAMERATE_SCOPE
int SDL_setFramerate(FPSmanager *manager, Uint32 rate)
Set the framerate in Hz.
Uint32 SDL_framerateDelay(FPSmanager *manager)
Delay execution to maintain a constant framerate and calculate fps.
#define PRAGMA48(str)
Definition: localconsts.h:199
Structure holding the state and timing information of the framerate controller.
Uint32 baseticks
Uint32 framecount
float rateticks
Uint32 lastticks