Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. import time
  2. import host
  3. import bf2
  4. import realitytimer
  5. import realityadmin
  6. import realityconfig_admin
  7.  
  8. g_fps_counter = 0
  9. g_fps_current = 0
  10. g_fps_time = 0
  11. g_timer = None
  12.  
  13. def tick( data ):
  14. global g_fps_counter, g_fps_current, g_fps_time
  15. g_fps_counter += 1
  16.  
  17. if g_fps_counter == 200:
  18. currentTime = time.time()
  19. g_fps_current = (200/(currentTime - g_fps_time))
  20. host.rcon_invoke('game.sayall "Server FPS: %s"' % g_fps_current)
  21.  
  22. destroyTimer()
  23.  
  24.  
  25. def statusChanged(status):
  26. # Register the commands on map load
  27. if status == bf2.GameStatus.Loaded:
  28. realityadmin.g_adminCommands['fps'] = measureFPS
  29. realityconfig_admin.adm_adminPowerLevels['fps'] = 777
  30. # Just incase
  31. if status == bf2.GameStatus.EndGame:
  32. destroyTimer()
  33.  
  34.  
  35.  
  36. def measureFPS( args, p ):
  37. global g_timer, g_fps_counter, g_fps_time
  38. if g_timer: # Don't try measuring if we're already measuring
  39. return
  40.  
  41. host.rcon_invoke('game.sayall "Measuring FPS..."')
  42. g_timer = realitytimer.Timer(tick, -1, 1)
  43. g_timer.setRecurring(0.0001)
  44. g_fps_counter = 0
  45. g_fps_time = time.time()
  46.  
  47. def destroyTimer():
  48. global g_timer
  49. if g_timer:
  50. g_timer.destroy()
  51. g_timer = None
  52.  
  53. host.registerGameStatusHandler( statusChanged )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement