Timer enhancement

Let Sim Innovations know about your Air Manager experience and let us know about your dream feature addition

Moderators: russ, Ralph

Message
Author
User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Timer enhancement

#1 Post by Keith Baxter »

Hi,

I would like to see an enhancement to the timer function.

1) my_timer= timer_add(delay, period, nr_calls, callback)

2) start_timer(my_timer)

3)pause_timer(my_timer)

4)restart_timer(my_timer)

5)stop_timer(my_timer,delay)

6)timer_running(timer_id)



Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Timer enhancement

#2 Post by Keith Baxter »

Hi,

I guess it started when I tested this from the API...

Code: Select all

-- Start a timer
timer_id = timer_start(0,1000,nil)

-- Check if the timer is running
if timer_running(timer_id) then
  print("The timer is running!")
else
  print("The timer is not running...")
end
and got this error...


ERROR - logic.lua:2: Argument 'callback(3)' in function 'timer_start' is nil, which is not allowed


I am on AM4 beta by the way.


Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

JackZ
Posts: 2262
Joined: Mon Feb 22, 2016 1:02 pm

Re: Timer enhancement

#3 Post by JackZ »

Hi Keith
The 3rd argument should be a callback function.
So either you add an inline function in the timer creation, either you create an empty function with no code.

Jacques
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Timer enhancement

#4 Post by Keith Baxter »

JackZ wrote: Sat Apr 24, 2021 5:28 pm Hi Keith
The 3rd argument should be a callback function.
So either you add an inline function in the timer creation, either you create an empty function with no code.

Jacques
Jacques,

Thank you,
I gathered that after some time. Not sure others did or will. I noticed that the API was last edited in 2016. Hence it might be an oversight and need updating.

Not sure the feature is used much else I would expect a few more queries.

The pause and restart features in the initial post are what I am most interested in. If I pause the sim I also want to pause the timer in a clean way and then restart the timer when the sim is restarted. Note that the counter is the key here. Storing counter values on stop and start becomes complex for the not so savvy guys like myself. Sorry for being so vain. :D

Also for the stop_timer(), I want to have an option to stop the timer after a delay. Yes this can be done by adding "ANOTHER TIMER" and the code starts to get messy.

Keith

EDIT : When the xpl_dararef <"sim/time/paused","INT"> value is "1", I want to stop the timer. When the value is "0" , I want the timer to restart/continue running the timer.
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Timer enhancement

#5 Post by Sling »

Remember that AM needs to remain backwards compatible so any API changes need to fit in with the existing API. Currently you add and start a timer at the same time. Not sure how this would work. I think all of this can currently be achieved with the current API albeit as you say with a bit of management code so not sure it really brings a lot to the party. I think It’s more a case of learning ways to manage timer situations. I’m all for adding functions that give the ability to do things you can’t currently do but this is just another way of achieving something already possible.

BTW I use timer_running() quite a lot because it’s very useful when it comes to managing your timers.

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Timer enhancement

#6 Post by Keith Baxter »

@Sling

What you say is correct and I agree mostly. This is my view.

I am not getting this backward compatibility arg... Maybe one of the SI guys would like to chime in?


1) "SOME" of my old instruments do not work on AM4 (beta) and I will have to be reworked to make them compatible for AM4 stable

2) NEW instruments should only be compatible with the latest version of AM.

Obviously I have a different view. Perhaps a few examples where backward compatibility should be respected could assist in changing my view....

As you say Tony, Timers can be managed. It takes a lot of LUA savvy to do that and I am not sure that is in synergy with the SI concept for instrument creation to be accessible to the majority.


Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Timer enhancement

#7 Post by Sling »

Interesting,

I’d be interested to learn what worked in 3.7 but does not in 4.0.

There have been some small exceptions to the fully backwards compatible over the course of AM’s development but generally they haven’t stopped instruments from running and were due to necessity.Text comes to mind.

Having the legacy support is why some functions are no longer documented on the wiki but still work. It’s pretty common practice to retain the support but encourage users to use the new stuff. Adding new stuff doesn’t normally affect the backwards compatibility but taking something away or changing it so it doesn’t work the same would.

I guess you have to take a view on the impact when considering this. The Nav API is a good example. Changing how it works is probably not a big impact because there are currently very few instruments using it. Many of the other functions don’t fall into that same category and therefore the legacy support needs to be retained.

Tony

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Timer enhancement

#8 Post by Keith Baxter »

Tony,

Things that work in AM3.7 but do not work in AM4 (Beta)

1) All off set rotates throw out an error if the z axis is not specified. This is for images and canvas. Run this code in both AM versions and you will see what I mean.

For me. Most of my instruments use a offset rotate for pointers so I will have to go through all instruments and add the z argument should I want them to work in AM4

Code: Select all

my_canvas= canvas_add(0,0,600,600)

canvas_draw(my_canvas,function()
  _rect(50,200,500,200)
  _fill("red")
end)
rotate(my_canvas,30,400,100)
2) I have a large number of map instruments in AM3.7 . When moving a map in A3.7 the map_add_nav_img_layer & map_add_nav_txt_layer moves with the map.
in AM4 this does not work. It is not a problem for new Maps in AM because the new map_add_nav_canvas_layer is added to a group that contains the map_add and all canvas layers.


These are the major ones for me. It is not worth Corjan wasting time to try and get the old map system working on AM4. and the rotate issue I simply add a nil as the anchor_z argument for new instruments.
So from my side I would rather Corjan spend his valuable time adding new features than trying to get old ones working on AM4.

You will see in one of the AM4 release threads where I want to keep both AM3.7 and AM4. It is simply for this reason.


Keith

EDIT: My take on backward compatibility is. If We want new fancy features then it is time to chuck out all the old and bring in the new faster and enhanced systems. I am hoping that AM4 is short lived and that AM5 with a complete overall comes sooner rather than later. :D
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Timer enhancement

#9 Post by Sling »

I see. You was obviously getting away with not using the z offset because you should of used it as documented on the wiki. I use it a lot too but luckily I have nothing to change as i always use the z argument.

The map one is one of those that I think falls into the same category as the nav functions. Not heavily used and time for a revamp.

User avatar
Keith Baxter
Posts: 4674
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: Timer enhancement

#10 Post by Keith Baxter »

Sling wrote: Sun Apr 25, 2021 8:53 am I see. You was obviously getting away with not using the z offset because you should of used it as documented on the wiki. I use it a lot too but luckily I have nothing to change as i always use the z argument.

The map one is one of those that I think falls into the same category as the nav functions. Not heavily used and time for a revamp.
Tony,

Rotate without the Z arg used to work in AM 4 before. In April 2020 when animation was introduced then it stopped and the error message started.
Not really a train smash.

Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board,  32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card 

Post Reply