Board index FlightGear Development Aircraft

Switch click

Questions and discussion about creating aircraft. Flight dynamics, 3d models, cockpits, systems, animation, textures.

Re: Switch click

Postby jam007 » Thu May 18, 2017 9:09 pm

sanhozay wrote in Thu May 18, 2017 8:46 pm:I don't think the timer is strictly necessary. I think you could trigger the click sound from the click property going true->false or false->true in *-sound.xml

Ah :!: It might be one block
condition
not
property


and the other
property.


would that work?
jam007
 
Posts: 579
Joined: Sun Dec 16, 2012 11:04 am
Location: Uppsala, Sweden
Callsign: LOOP
Version: 2020.4.0
OS: Ubuntu 22.04

Re: Switch click

Postby sanhozay » Thu May 18, 2017 9:21 pm

I think so. That's what I was thinking of as two blocks.
sanhozay
 
Posts: 1207
Joined: Thu Dec 26, 2013 12:57 pm
Location: EGNM
Callsign: G-SHOZ
Version: Git
OS: Ubuntu 16.04

Re: Switch click

Postby Thorsten » Sun May 21, 2017 5:48 pm

Noticed that maketimer is the preferred way.


In the event, it seems to me like using a very sophisticated Swiss Army knife for a job where a simple screwdriver will do... But that's just my private opinion (and I'm better known for ugly fast code than for elegant code...)
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Switch click

Postby sanhozay » Sun May 21, 2017 11:33 pm

Isn't settimer prone to memory leaks? There are certainly warnings in various places in the Wiki about it, e.g.

http://wiki.flightgear.org/Nasal_library#settimer.28.29

It doesn't really explain what "improper" means but it does suggest maketimer is "highly recommended".
sanhozay
 
Posts: 1207
Joined: Thu Dec 26, 2013 12:57 pm
Location: EGNM
Callsign: G-SHOZ
Version: Git
OS: Ubuntu 16.04

Re: Switch click

Postby Thorsten » Mon May 22, 2017 5:47 am

settimer is a low-level tool and if you're not careful what you're doing in complex situations and double-check, you might waste memory and/or framerate without noticing (can you be sure you have terminated your loop correctly?)

If your code is sound however, there's nothing wrong with it.

It's perhaps a bit like the pointer in C++ - a terrific tool if you know what you're doing, but if you're careless you're better off using a higher abstraction layer.

It doesn't really explain what "improper" means but it does suggest maketimer is "highly recommended".


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.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Switch click

Postby wlbragg » Mon May 22, 2017 8:06 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.


Good point, I for one am simply repeating what I was told.
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7588
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: Switch click

Postby sanhozay » Mon May 22, 2017 8:37 am

I agree with you both but Thorsten, you haven't really explained what "sound" means. In this context, "sound" is just the opposite of "improper" isn't it?

Is this "improper" or is it "sound", and why?

Code: Select all
var func = doSomething() {
    ...
    settimer(doSomething, 0.1);
}

doSomething();
sanhozay
 
Posts: 1207
Joined: Thu Dec 26, 2013 12:57 pm
Location: EGNM
Callsign: G-SHOZ
Version: Git
OS: Ubuntu 16.04

Re: Switch click

Postby 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
erik
 
Posts: 2245
Joined: Thu Nov 01, 2007 2:41 pm

Previous

Return to Aircraft

Who is online

Users browsing this forum: No registered users and 12 guests