Posted 01 April 2016 - 11:27 PM
Hello, everyone. I have a new API for you guys to try out.
It calculates the cycles that are running on your script. So you know how many times per second the computer reads at.
in my current project which is making a decent networking system i use it just to see the likely hood of dropping a packet.
the max speed is 20 C/ps. or sleep(.01) in your main loop with nothing else in the way.
Feel free to use this little gadget any time and if youd like to give credit you can for the idea or scource code im your guy ;)/>. i know most of you are going to fuck with this thing and make it for your own needs so have at it.
version 1.0 - its not really an api. just a cool function used for data collection.
here is a picture for validation:
my settings are the same as in the test code above.
ALSO: if you are interested in swapping settings on the fly this wont do it. just runs it how it is configured
It calculates the cycles that are running on your script. So you know how many times per second the computer reads at.
in my current project which is making a decent networking system i use it just to see the likely hood of dropping a packet.
the max speed is 20 C/ps. or sleep(.01) in your main loop with nothing else in the way.
Feel free to use this little gadget any time and if youd like to give credit you can for the idea or scource code im your guy ;)/>. i know most of you are going to fuck with this thing and make it for your own needs so have at it.
version 1.0 - its not really an api. just a cool function used for data collection.
get_speed_table = { -- create table for data
speed_conversion = "cp/s", -- cp/s cp/m
selected_speed_units = 1, -- change for 1 = frames/1 60 = frames/60
speed_conversion_units = {1,60}, -- unit table
first_run = true, -- start up with the right units
cycles = 0, -- the number of revolutions total
speed = 0, -- out put after conversion
origin_time = os.clock(), -- set origional time
time_forward = origin_time, -- add 1 second to the origion time
time = 0,
}
function GET_SPEED()
if get_speed_table.first_run == true then
if get_speed_table.speed_conversion == "cp/s" then
get_speed_table.time_forward = get_speed_table.origin_time +1
get_speed_table.first_run = false
else
get_speed_table.time_forward = get_speed_table.origin_time +60
get_speed_table.first_run = false
end
end
if get_speed_table.first_run == false then
get_speed_table.cycles = get_speed_table.cycles+1
get_speed_table.time = os.clock()
if get_speed_table.time >= get_speed_table.time_forward then
if get_speed_table.speed_conversion == "cp/s" then
get_speed_table.speed = get_speed_table.cycles/get_speed_table.speed_conversion_units[get_speed_table.selected_speed_units]
get_speed_table.cycles = 0
get_speed_table.time_forward = get_speed_table.time +1
end
if get_speed_table.speed_conversion == "cp/m" then
get_speed_table.speed = get_speed_table.cycles/get_speed_table.speed_conversion_units[get_speed_table.selected_speed_units]
get_speed_table.cycles = 0
get_speed_table.time_forward = get_speed_table.time +60
end
end
end
return get_speed_table.speed, get_speed_table.cycles, get_speed_table.speed_conversion
end -- eof
while true do
s,c,sc = GET_SPEED()
print("speed: "..s.." in: "..sc.."cycles counter: "..c)
sleep(.01)
term.clear()
term.setCursorPos(1,1)
end
here is a picture for validation:
my settings are the same as in the test code above.
ALSO: if you are interested in swapping settings on the fly this wont do it. just runs it how it is configured
Edited on 01 April 2016 - 09:48 PM