Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.80 KB | None | 0 0
  1. total_events_previous_second = 0
  2. total_events_this_second = 0
  3. seconds = floor(time_in_milliseconds())
  4.  
  5. function interpolate(x1, x2, d)
  6.     local difference = x2 - x1
  7.     return x1 + difference * d
  8. end
  9.  
  10. function update()
  11.     local events = get_events()
  12.     total_events_this_second = total_events_this_second + #events
  13.  
  14.     local time = time_in_milliseconds()
  15.     local current_seconds = floor(time)
  16.  
  17.     if seconds ~= current_seconds then
  18.         local time_since_previous_second = math.frac(time_in_milliseconds)
  19.         set_events_per_second(interpolate(total_events_previous_second, total_events_this_second, time_since_previous_second))
  20.        
  21.         seconds = current_seconds
  22.         total_events_previous_second = total_events_this_second
  23.         total_events_this_second = 0
  24.     end
  25. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement