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 8:09 pm

sanhozay wrote in Thu May 18, 2017 7: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: 477
Joined: Sun Dec 16, 2012 10:04 am
Location: Uppsala, Sweden
Version: 2017.3.1
OS: Ubuntu 16.04

Re: Switch click

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

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

Re: Switch click

Postby Thorsten » Sun May 21, 2017 4: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: 11087
Joined: Mon Nov 02, 2009 8:33 am

Re: Switch click

Postby sanhozay » Sun May 21, 2017 10: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 11:57 am
Location: EGNM
Callsign: G-SHOZ
Version: Git
OS: Ubuntu 16.04

Re: Switch click

Postby Thorsten » Mon May 22, 2017 4: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: 11087
Joined: Mon Nov 02, 2009 8:33 am

Re: Switch click

Postby wlbragg » Mon May 22, 2017 7: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(2-27-15)/Ohio/Midwest scenery development.
KEQA (2-27-15), 3AU, KRCP Airport Layout
User avatar
wlbragg
 
Posts: 4909
Joined: Sat Aug 25, 2012 11:31 pm
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Debain/nVGT640

Re: Switch click

Postby sanhozay » Mon May 22, 2017 7: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 11:57 am
Location: EGNM
Callsign: G-SHOZ
Version: Git
OS: Ubuntu 16.04

Re: Switch click

Postby erik » Mon May 22, 2017 7:42 am

Thorsten wrote in Mon May 22, 2017 4: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
erik
 
Posts: 1520
Joined: Thu Nov 01, 2007 1:41 pm

Previous

Return to Aircraft

Who is online

Users browsing this forum: No registered users and 2 guests