This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Glotz659's profile picture

Lag-o-Meter

Started by Glotz659, 21 January 2013 - 03:47 AM
Glotz659 #1
Posted 21 January 2013 - 04:47 AM
Hey,

I think it would be useful to have a function or peripheral to get the current frame rate of the game, so we can switch large, lag producing machines (scrap-production for mass fabricator, giant turtle swarm, water mill power plant etc) off if the game lags too much.

Syntax could be like

.getFrameRate() -- would return the frame rate as a number

sry if its bad english, its not my native language.
redeye83 #2
Posted 21 January 2013 - 04:54 AM
cant you just press "F3" and see the current FPS?
Cloudy #3
Posted 21 January 2013 - 04:57 AM
Definitely not. Makes no sense from the context of the game world.
Glotz659 #4
Posted 21 January 2013 - 05:01 AM
cant you just press "F3" and see the current FPS?

I can, but a computer can't, so i would have switch it off manually, and traveling a long distance or even between dimensions (i have a solar power plant in a bright mystcraft dimension) with lag is a pain.

edit: maybe you didn't understand waht i meant, so here's an example script:

-- startup file on a computer far from your base
rs.setOutput("back", true) -- switches machine (e.g. timer) on
while true do
if os.getFrameRate() < 30 then
  rs.setOutput("back", false) -- switches machine off again
end
sleep(60)
end
redeye83 #5
Posted 21 January 2013 - 05:26 AM
ah I didnt realise you wanted to due it auto (I feel stupid now lol)
Dlcruz129 #6
Posted 21 January 2013 - 05:30 AM
cant you just press "F3" and see the current FPS?

I can, but a computer can't, so i would have switch it off manually, and traveling a long distance or even between dimensions (i have a solar power plant in a bright mystcraft dimension) with lag is a pain.

edit: maybe you didn't understand waht i meant, so here's an example script:

-- startup file on a computer far from your base
rs.setOutput("back", true) -- switches machine (e.g. timer) on
while true do
if os.getFrameRate() < 30 then
  rs.setOutput("back", false) -- switches machine off again
end
sleep(60)
end

Again,
Definitely not. Makes no sense from the context of the game world.
Leo Verto #7
Posted 21 January 2013 - 05:40 AM
The frame rate is client-side, the code is executed server-side, this wouldn't work very well on servers.
Exerro #8
Posted 21 January 2013 - 08:01 AM
you can do it kind of btw using os.clock
Cloudy #9
Posted 21 January 2013 - 08:05 AM
Nah, not really - clock is only advanced on ticks too, and sleep works on ticks.
theoriginalbit #10
Posted 21 January 2013 - 08:14 AM
Nah, not really - clock is only advanced on ticks too, and sleep works on ticks.
Is a timer ticks? If not you could get a TPS working with clock and a timer.
Exerro #11
Posted 21 January 2013 - 08:18 AM
you can measure how long it takes for the computer to go through your code with os.clock and sleep according to that surely?
Cloudy #12
Posted 21 January 2013 - 08:55 AM
Everything is based on ticks.
NeverCast #13
Posted 21 January 2013 - 10:08 AM
I had my suspicion that everything was based on ticks, which does shatter an idea I had.
Cloudy, how about the alarms, I take it they are 100% ticks also, since they use MC time which is incremented by a 20th of a second, each tick.

Well at least the game is fully synchronized, slow or fast, everything always gets the same amount of ticks.

I think the only luck beyond this would be http with a real world clock. Checking the time difference, if there is a slew of more than 40/50% you could shut down things.
Cloudy #14
Posted 21 January 2013 - 01:06 PM
Yes, alarms are based off ticks. Everything is based off ticks.

[media]http://www.youtube.com/watch?v=shs7VQhVvxA[/media]
ChunLing #15
Posted 21 January 2013 - 01:07 PM
Or, you can just take care to program things so that they yield until they are actually needed to do something, or even shut themselves off if they aren't in use.
Orwell #16
Posted 21 January 2013 - 01:20 PM
And eventually you could use the HTTP api (if available) to compare ticks with elapsed time through a time server. This would only work properly over larger intervals I suppose.
theoriginalbit #17
Posted 21 January 2013 - 01:45 PM
Yes, alarms are based off ticks. Everything is based off ticks.

- video snip -
LOL!!! Nice…
ChunLing #18
Posted 21 January 2013 - 09:52 PM
Lister, as usual exercising less than the minimum safe hygienic discretion. "Hmm…everyone's dead, so I'll taste some of this white powder lying about."
Zoinky #19
Posted 22 January 2013 - 07:56 PM
Orwell's idea would work the best. It wouldn't be possible to compare two in-game times, since they're both advancing at the same rate (Eg. The computer could think 1 second has elapsed when it actually has been 2). I'm not great at explaining.

Off-topic-ish: How does the server calculate the TPS? Does it reference other machine times?
immibis #20
Posted 22 January 2013 - 10:14 PM
Orwell's idea would work the best. It wouldn't be possible to compare two in-game times, since they're both advancing at the same rate (Eg. The computer could think 1 second has elapsed when it actually has been 2). I'm not great at explaining.

Off-topic-ish: How does the server calculate the TPS? Does it reference other machine times?
Java code can easily access real and in-game time to compare them.