by erik » Mon May 22, 2017 8:42 am
Thorsten wrote in Mon May 22, 2017 5:47 am:What worries me a bit is the combination of a) the Wiki largely has been written by a single person and b) everyone saying 'settimer is bad' without the majority of people who say it being able to explain why.
Form a low level point of view I know that Windows has two types of timers: Single Shot and Repeatable timers.
Repeatable timers have the advantage that it does not require to be set up every time saving some, and possible a lot of, CPU time.
Now looking up in the code FlightGear has something similar:
settimer is a single shot timer which requires quite some code to set up a hardware interrupt timer. And to make it repeatable you will need to set up a new timer every call.
maketimer is a repeatable timer which just increases a counter every frame and tests if it should run the required function if enough times has passed. Code wise this is much cleaner and this makes me agree that if you want a repeatable timer 'maketimer' is the preferred solution.
Does this make settimer unsafe or leak memory?
nah, it's just using the wrong tool for the task.
Erik
Current: Parachutist, Paraglider, Pterosaur, Pilatus PC-9M and variants, ERCO Ercoupe, Fokker Dr.1, Fokker 50, Fokker 100
Less active: Cessna T-37, T-38, Santa Claus. Previous: General Dynamics F-16. Worked on: Wright Flyer