raiseTable = { "advshading 1", "shadows 1 1024", "water 1", "shadows 1 2048", "water 3", "shadows 4096", "water 2" } lowerTable = { "advshading 0", "shadows 0", "water 0", "shadows 1 1024", "water 1", "shadows 1 2048", "water 3" } maxFps = 40 minFps = 30 function widget:GetInfo() return { name = "FPSManager", desc = "fill", author = "quantum", date = "May 28, 2007", license = "GNU GPL, v2 or later", layer = 0, enabled = false -- loaded by default? } end counter = 0 detailLevel = 1 fpsTable = {} raisePoints = 0 lowerPoints = 0 function RaiseDetail() raisePoints = raisePoints + 1 if detailLevel < 8 and raisePoints > 3 then --Spring.SendCommands({"echo detail is "..detailLevel..", raising"}) Spring.SendCommands({raiseTable[detailLevel]}) detailLevel = detailLevel + 1 raisePoints = 0 end end function LowerDetail() lowerPoints = lowerPoints + 1 if detailLevel > 1 and lowerPoints > 3 then --Spring.SendCommands({"echo detail is "..detailLevel..", lowering"}) Spring.SendCommands({lowerTable[detailLevel - 1]}) detailLevel = detailLevel - 1 lowerPoints = 0 end end function widget:Initialize() Spring.SendCommands({"water 0", "shadows 0", "advshading 0"}) end function widget:Update(t) counter = counter + 1 table.insert(fpsTable, Spring.GetFPS()) if #fpsTable > 30 then table.remove(fpsTable, 1) end if counter % 30 == 0 then counter = 0 sum = 0 for _, v in ipairs(fpsTable) do sum = sum + v end average = sum / #fpsTable --Spring.SendCommands({"echo average FPS is "..average}) if average > maxFps then RaiseDetail() else raisePoints = 0 end if average < minFps then LowerDetail() else lowerPoints = 0 end end end