SDL3_gfx 1.0.1 Graphics primitives and surface functions for SDL3

SDL3_framerate.h
Go to the documentation of this file.
1/*
2
3 SDL3_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*/
29
30#ifndef _SDL3_framerate_h
31#define _SDL3_framerate_h
32
33/* Set up for C function definitions, even when using C++ */
34#ifdef __cplusplus
35 extern "C" {
36#endif
37
38 /* --- */
39
40#include <SDL3/SDL.h>
41
42 /* --------- Definitions */
43
47#define FPS_UPPER_LIMIT 200
48
52#define FPS_LOWER_LIMIT 1
53
57#define FPS_DEFAULT 30
58
62 typedef struct {
63 Uint32 framecount;
64 float rateticks;
65 Uint64 baseticks;
66 Uint64 lastticks;
67 Uint32 rate;
68 } FPSmanager;
69
70 /* ---- Function Prototypes */
71
72#ifdef _MSC_VER
73# if defined(DLL_EXPORT) && !defined(LIBSDL3_GFX_DLL_IMPORT)
74# define SDL3_FRAMERATE_SCOPE __declspec(dllexport)
75# else
76# ifdef LIBSDL3_GFX_DLL_IMPORT
77# define SDL3_FRAMERATE_SCOPE __declspec(dllimport)
78# endif
79# endif
80#endif
81#ifndef SDL3_FRAMERATE_SCOPE
82# define SDL3_FRAMERATE_SCOPE extern
83#endif
84
85 /* Functions return 0 or value for sucess and -1 for error */
86
87 SDL3_FRAMERATE_SCOPE void SDL_initFramerate(FPSmanager * manager);
88 SDL3_FRAMERATE_SCOPE int SDL_setFramerate(FPSmanager * manager, Uint32 rate);
89 SDL3_FRAMERATE_SCOPE int SDL_getFramerate(FPSmanager * manager);
90 SDL3_FRAMERATE_SCOPE int SDL_getFramecount(FPSmanager * manager);
91 SDL3_FRAMERATE_SCOPE Uint64 SDL_framerateDelay(FPSmanager * manager);
92
93 /* --- */
94
95 /* Ends C function definitions when using C++ */
96#ifdef __cplusplus
97}
98#endif
99
100#endif /* _SDL3_framerate_h */
SDL3_FRAMERATE_SCOPE
#define SDL3_FRAMERATE_SCOPE
Definition SDL3_framerate.h:82
SDL_getFramecount
SDL3_FRAMERATE_SCOPE int SDL_getFramecount(FPSmanager *manager)
Return the current framecount.
Definition SDL3_framerate.c:126
SDL_initFramerate
SDL3_FRAMERATE_SCOPE void SDL_initFramerate(FPSmanager *manager)
Initialize the framerate manager.
Definition SDL3_framerate.c:62
SDL_setFramerate
SDL3_FRAMERATE_SCOPE int SDL_setFramerate(FPSmanager *manager, Uint32 rate)
Set the framerate in Hz.
Definition SDL3_framerate.c:86
SDL_getFramerate
SDL3_FRAMERATE_SCOPE int SDL_getFramerate(FPSmanager *manager)
Return the current target framerate in Hz.
Definition SDL3_framerate.c:107
SDL_framerateDelay
SDL3_FRAMERATE_SCOPE Uint64 SDL_framerateDelay(FPSmanager *manager)
Delay execution to maintain a constant framerate and calculate fps.
Definition SDL3_framerate.c:146
FPSmanager
Structure holding the state and timing information of the framerate controller.
Definition SDL3_framerate.h:62
FPSmanager::framecount
Uint32 framecount
Definition SDL3_framerate.h:63
FPSmanager::baseticks
Uint64 baseticks
Definition SDL3_framerate.h:65
FPSmanager::rateticks
float rateticks
Definition SDL3_framerate.h:64
FPSmanager::lastticks
Uint64 lastticks
Definition SDL3_framerate.h:66
FPSmanager::rate
Uint32 rate
Definition SDL3_framerate.h:67