Engine 0.0.6
Game engine in lua
Loading...
Searching...
No Matches
fps.lua
Go to the documentation of this file.
1local function fps_counter(fps_limit, fps_tracker, current_time)
2 if current_time >= fps_tracker.last_check + 1000 then
3 fps_tracker.last_check = current_time
4 fps_tracker.total_fps = fps_tracker.frame_count
5 fps_tracker.frame_count = 0
6
7 if fps_tracker.drop_count == 0 then
8 return true
9 end
10
11 if fps_tracker.total_fps + fps_tracker.drop_count > fps_limit then
12 fps_tracker.fall_streak = 0
13 return true
14 end
15
16 fps_tracker.fall_streak = fps_tracker.fall_streak + 1
17
18 if fps_tracker.fall_streak >= fps_tracker.allowed_falls then
19 fps_tracker.fall_streak = 0
20 return false
21 end
22 end
23
24 fps_tracker.frame_count = fps_tracker.frame_count + 1
25 fps_tracker.time_delta = current_time - fps_tracker.last_frame_time
26 fps_tracker.last_frame_time = current_time
27
28 return true
29end
30
31local function install(std, game, application, config_fps)
32 local index = 1
33
34 application.internal = application.internal or {}
35 config_fps.inverse_list = {}
36
37 local fps_obj = {total_fps=0,frame_count=0,last_check=0,last_frame_time=0,time_delta=0,fall_streak=0,drop=0}
38 fps_obj.allowed_falls=application.config and application.config.fps_time or 1
39 fps_obj.drop_count=application.config and application.config.fps_drop or 2
40
41 while index <= #config_fps.list do
42 config_fps.inverse_list[config_fps.list[index]] = index
43 index = index + 1
44 end
45
46 application.internal.fps_controler=function(milis)
47 local index = config_fps.inverse_list[game.fps_max]
48 game.milis = event.uptime()
49 game.fps = fps_obj.total_fps
50 game.dt = fps_obj.time_delta
51 if not fps_counter(game.fps_max, fps_obj, game.milis) then
52 if index < #config_fps.list then
53 game.fps_max = config_fps.list[index + 1]
54 end
55 end
56 return config_fps.time[index]
57 end
58
59 return {
60 fps_controler = fps_controler
61 }
62end
63
64local P = {
66}
67
68return P
local application
Definition main.lua:16
local game
Definition main.lua:17
local std
Definition main.lua:18
local function install(std, game, application)
local function fps_counter(fps_limit, fps_tracker, current_time)