Engine 0.0.4
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 std = std or {}
35 application.internal = application.internal or {}
36 config_fps.inverse_list = {}
37
38 local fps_obj = {total_fps=0,frame_count=0,last_check=0,last_frame_time=0,time_delta=0,fall_streak=0,drop=0}
39 fps_obj.allowed_falls=application.config and application.config.fps_time or 1
40 fps_obj.drop_count=application.config and application.config.fps_drop or 2
41
42 while index <= #config_fps.list do
43 config_fps.inverse_list[config_fps.list[index]] = index
44 index = index + 1
45 end
46
47 application.internal.fps_controler=function(milis)
48 local index = config_fps.inverse_list[game.fps_max]
49 game.milis = event.uptime()
50 game.fps = fps_obj.total_fps
51 game.dt = fps_obj.time_delta
52 if not fps_counter(game.fps_max, fps_obj, game.milis) then
53 if index < #config_fps.list then
54 game.fps_max = config_fps.list[index + 1]
55 end
56 end
57 return config_fps.time[index]
58 end
59
60 return {
61 fps_controler = fps_controler
62 }
63end
64
65local P = {
67}
68
69return P
local function fps_counter(fps_limit, fps_tracker, current_time)
local function install(std, game, application, config_fps)
local application
Definition main.lua:16
local game
Definition main.lua:17
local std
Definition main.lua:18