Advertisement
mrWhiskasss

тпс от serafim7

Jan 28th, 2024 (edited)
605
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- pastebin run 1EQLZfSR
  2. local timeConstant = 1 -- обновление тпс
  3.  
  4. local admins = {"mrWhiskass"}  -- заприватить пк
  5.  
  6. local computer = require("computer")
  7. local event = require("event")
  8. local fs = require('filesystem')
  9. local com = require('component')
  10. local gpu = com.gpu
  11.  
  12. local leftX = 5
  13. local topY = 14
  14. local realTimeOld = 0
  15. local realTimeNew = 0
  16. local realTimeDiff = 0
  17. local w, h = gpu.getResolution()
  18.  
  19. for i = 1,#admins do
  20.   computer.addUser(admins[i])
  21.   admins[admins[i]] = true
  22. end
  23.  
  24. local function time()
  25.   io.open('/tmp/clock.dt','w'):write(''):close()
  26.   return(fs.lastModified("/tmp/clock.dt"))
  27. end
  28.  
  29. local TPS = {}
  30. local avgTPS = 0
  31. for tSlot = 1,10 do
  32.   TPS[tSlot] = 0
  33. end
  34.  
  35. local function getColor(tps)
  36.   local H, rP, gP, bP, X = tps*12-120, 0, 0, 0, 0
  37.   if H<0 then H=0 end
  38.   X = (1-math.abs((H/60)%2-1))
  39.   if H<60 then
  40.     rP = 1
  41.     gP = X
  42.     bP = 0
  43.   elseif H<120 then
  44.     rP = X
  45.     gP = 1
  46.     bP = 0  
  47.   elseif H<180 then
  48.     rP = 0
  49.     gP = 1
  50.     bP = X  
  51.   elseif H<240 then
  52.     rP = 0
  53.     gP = X
  54.     bP = 1  
  55.   elseif H<300 then
  56.     rP = X
  57.     gP = 0
  58.     bP = 1
  59.   else
  60.     rP = 1
  61.     gP = 0
  62.     bP = X
  63.   end
  64.   return(math.floor((rP)*255)*65536+math.floor((gP)*255)*256+math.floor((bP)*255))
  65. end
  66.  
  67. local function histoPlot(tabVal,leftX, topY,step)
  68.   local height = math.floor(tabVal[step]/2)+1
  69.   if height>11 then height=11 end
  70.   gpu.setBackground(0xB4B4B4)
  71.   gpu.fill(3*step+leftX-2, topY-2, 2, 13," ")
  72.   gpu.fill(leftX-1,topY+10,33,1," ")
  73.   gpu.setBackground(getColor(tabVal[step]))
  74.   gpu.fill(3*step+leftX-2, topY-height+10, 2, height," ")
  75.   gpu.setBackground(0x0064FF)
  76.   gpu.fill(leftX+step*3-2,topY+10,2,1," ")
  77.   gpu.setBackground(0x000000)
  78. end
  79.  
  80. function event.shouldInterrupt() return false end
  81.  
  82. gpu.setResolution(38, 25)
  83. gpu.setBackground(0x000000)
  84. os.execute("cls")
  85. gpu.setForeground(0xFF9200)
  86. gpu.set(12,3,"[ TPS сервера ]")
  87. gpu.setBackground(0xB4B4B4)
  88. gpu.setForeground(0xFFFFFF)
  89. gpu.fill(leftX-1,topY-2,33,13," ")
  90. for i = 1,#TPS do
  91.   local height = math.floor(TPS[i]/2)+1
  92.   gpu.setBackground(getColor(TPS[i]))
  93.   gpu.fill(3*i+leftX-2, topY-height+10, 2, height," ")
  94. end
  95. gpu.setBackground(0x000000)
  96. gpu.set(8,6,"Текущий 00.0000 тик/сек")
  97. gpu.set(8,9,"Средний 00.0000 тик/сек")
  98. gpu.set(18,11,"T/s")
  99. gpu.set(1,12,"20")
  100. gpu.set(1,17,"10")
  101. gpu.set(1,22," 0")
  102. gpu.setForeground(0x00FFFF)
  103. while true do
  104.   for tSlot = 1,10 do
  105.     realTimeOld = time()
  106.     local e = {event.pull(timeConstant,"key_down")}
  107.     if admins[e[5]] and e[4] == 29 then
  108.       gpu.setResolution(80,25)
  109.       gpu.setBackground(0x000000)
  110.       gpu.setForeground(0xffffff)
  111.       os.execute("cls")
  112.       os.exit()
  113.     end
  114.     realTimeNew = time()
  115.     realTimeDiff = realTimeNew-realTimeOld
  116.     TPS[tSlot] = 20000*timeConstant/realTimeDiff
  117.     if TPS[tSlot] > 20 then
  118.       TPS[tSlot] = 20.0000
  119.     end
  120.     gpu.set(16,6,string.sub(tostring(TPS[tSlot])..".0000",1,7))
  121.     avgTPS = (TPS[1]+TPS[2]+TPS[3]+TPS[4]+TPS[5]+TPS[6]+TPS[7]+TPS[8]+TPS[9]+TPS[10])/10
  122.     gpu.set(16,9,string.sub(tostring(avgTPS)..".0000",1,7))
  123.     histoPlot(TPS,leftX,topY,tSlot)
  124.   end
  125. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement