• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

Pilot Activated Lighting

Messages
13
Country
australia
G'day Everyone

I am currently 'messing' with the great PAPI system that simzlxy generously posted after getting it to work. I plan to create full custom lighting for my YSHT scenery and am starting to have a play with a pilot activated lighting system. Starting with the PAPI, I am trying to make it so the user selects the PAL frequency, which turns the lighting on and then stays on for 30 minutes before turning off. I can easily make it frequency activated, but I have come up against a brick wall in regards to timing it so it stays on for 30 minutes regardless of comm frequency.

Any help would be greatly appreciated :)
 
Hi,

You would have to store the moment that it was turned on somewhere, I would use a local variable for that. And then each time you would have to check if the 30 minutes since the last time the frequency was tuned have already passed.
 
Hi Arno,

Thanks for the reply. I did try that, but I couldn't get it to work. Could you please provide an example of how to do this?
 
Hi Jake,

Unfortunately I do not have a complete example of this, as I never tried to code just lighting myself (in the Netherlands there are no pilot activated lights). But maybe you can show the code that you tried and did not work. Then I'll have a look at it and see where I can help.
 
Okay no worries.

I am new to asm tweaking and don't have the slightest idea how to use a timer.

This code is causing FS to freeze upon switching to 123.9:

Code:
zlxy_papi_MasterScale_2 label BGLCODE

IFIN1 a1, cmfreq, 2390h, 2390h
SETWRD usrvar, 1
BGL_JUMP_32 lightson

lightson label BGLCODE
    SEPARATION_PLANE nolgt_1, 0,0,-20621, 32767
    SEPARATION_PLANE nolgt_2, 1259,32706,1554, 32767
    BGL_LIGHT LIGHT_NAV, 0.000, 1.078, -0.001, 20, 0.60, 0.40, 0FFFFF5F5h, 0.000000, 0.000000, 1.000000 ; source poly num = 1593
    BGL_LIGHT LIGHT_NAV, 0.000, 1.078, -0.001, 20, 0.60, 0.40, 0FFFFF5F5h, 0.000000, 0.000000, 1.000000 ; source poly num = 1593
    BGL_LIGHT LIGHT_NAV, 0.000, 1.078, -0.001, 20, 0.60, 0.40, 0FFFFF5F5h, 0.000000, 0.000000, 1.000000 ; source poly num = 1593
<left out useless part>
    BGL_LIGHT LIGHT_NAV, -60.000, 1.078, -0.001, 20, 0.60, 0.40, 0FFFF0000h, 0.000000, 0.000000, 1.000000 ; source poly num = 9304
    BGL_LIGHT LIGHT_NAV, -60.000, 1.078, -0.001, 20, 0.60, 0.40, 0FFFF0000h, 0.000000, 0.000000, 1.000000 ; source poly num = 9304
     nolgt_51 label BGLCODE   
nolgt_1 label BGLCODE 

a1 label word

IFIN2 lightsoff, usrvar, 1, 1, 5fch, 32400, 32400
SETWRD usrvar, 0

lightsoff label word

IFIN1 a2, usrvar, 1, 1
BGL_JUMP_32 lightson

a2 label word

BGL_RETURN

Proberly looks stupid to someone who knows what they are doing :o
 
Hi Jake,

I think you are using the BGL_JUMP_32 commands wrong, it looks a bit like you are jumping around all the time. This could indeed crash FS.

I would try something like this:

Code:
zlxy_papi_MasterScale_2 label BGLCODE

IFIN1 a1, cmfreq, 2390h, 2390h
SETWRD usrvar, 1
a1 label word
IFIN2 a2, usrvar, 1, 1, 5fch, 32400, 32400
SETWRD usrvar, 0
a2 label word

IFIN1 lights_off, usrvar, 1, 1
    SEPARATION_PLANE nolgt_1, 0,0,-20621, 32767
    SEPARATION_PLANE nolgt_2, 1259,32706,1554, 32767
    BGL_LIGHT LIGHT_NAV, 0.000, 1.078, -0.001, 20, 0.60, 0.40, 0FFFFF5F5h, 0.000000, 0.000000, 1.000000 ; source poly num = 1593
    BGL_LIGHT LIGHT_NAV, 0.000, 1.078, -0.001, 20, 0.60, 0.40, 0FFFFF5F5h, 0.000000, 0.000000, 1.000000 ; source poly num = 1593
    BGL_LIGHT LIGHT_NAV, 0.000, 1.078, -0.001, 20, 0.60, 0.40, 0FFFFF5F5h, 0.000000, 0.000000, 1.000000 ; source poly num = 1593
<left out useless part>
    BGL_LIGHT LIGHT_NAV, -60.000, 1.078, -0.001, 20, 0.60, 0.40, 0FFFF0000h, 0.000000, 0.000000, 1.000000 ; source poly num = 9304
    BGL_LIGHT LIGHT_NAV, -60.000, 1.078, -0.001, 20, 0.60, 0.40, 0FFFF0000h, 0.000000, 0.000000, 1.000000 ; source poly num = 9304
     nolgt_51 label BGLCODE   
lights_off label BGLCODE

It would be even nicer to use local variables instead of the user variable 1, as the user variable can also be overwritten by others. So this might cause your lights not to work as expected. I'll try to modify your code for that later, but let's first see if the crash is solved now.

Another things to take care of is the use of the tick18 variable, it does not start running at zero when you enable your lighting, so the check you do at the moment will not always give 30 minutes of on time. As it is tricky to do math in the ASM code (say add 30 to the minute variable when turned on and then check later if that minute has been reached), I need to think of a good way to check this.

You might have noticed I remove the BGL_RETURN at the end as well, this is because I am not sure if it was their in the non-tweaked output already or not. If it was there before, you need to keep it. Else it is not needed.
 
Yep that works!

Thanks Arno, really really cool. :cool:

If you find a way to make it run by time I would love to know. (I haven't got a clue!) :)
 
Good to hear that worked :). I'll do some thinking about an efficient way to make it count down the time, sounds like a nice challenge to me.
 
Has anyone come up with a way to create pilot activated lighting that turns on for a fixed period? I have a sense of how to proceed, but don't know enough of what is possible in BGL code to implement this. In concept, I would think you could do something like this:

Code:
IFIN1 noradio, cmfreq, 2390h, 2390h
SETWRD 02h, 1
SETWRD 04h, 05FCh XOR 8000h
noradio label word

IFIN2 holdlights, 02h, 1, 1, 05FCh, 04h, 04h
SETWRD 02h, 0
holdlights label word

IFIN1 lights_off, 02h, 1, 1
    BGL_LIGHT LIGHT_NAV, ....
lights_off label BGLCODE

First, we test if the radio is tuned to the desired frequency. If so, use a local variable to set a flag, then XOR the current value of tick18 with 8000h (which I think is roughly 30 minutes) and store the result in a second local variable. Next, test if tick18 equals the value of the second local variable. As long as the radio remains tuned to the target frequency, this will never happen. But if the radio is tuned to a different frequency, then tick18 will equal the value of the second local variable roughly 30 minutes later. At that point, the first local variable gets reset to 0. The final bit of code simply turns the lights on and off based on the value of the first local variable.

I am confident that the code above does not work as written. The issues are:
  • I don't know how to declare and use local variables
  • I don't know if you can XOR tick18 with a constant and store the result in a local variable
  • I don't know if you can test the value of tick18 against the value of another variable

Is it possible to do this with BGL code?

Taylor
 
Hi,

I am confident that the code above does not work as written. The issues are:
  • I don't know how to declare and use local variables
  • I don't know if you can XOR tick18 with a constant and store the result in a local variable
  • I don't know if you can test the value of tick18 against the value of another variable

Is it possible to do this with BGL code?

Yes, I think it should be possible. But it will be some advanced ASM tweaking :D.

If you look at the code of an animation you will see how local variables are defined and used. I am not sure if there is a good tutorial for it though :).

The IFMSK command can be used to check if certain bits of a variable are set or not. But I am not sure if you logic of checking for 8000h will work, as that assumes the timer variable was at 0 when you tuned. Of course it doesn't have to be.

In FS you can not test two variables against each other as far as I know, but you can test them again some present value.
 
The IFMSK command can be used to check if certain bits of a variable are set or not. But I am not sure if you logic of checking for 8000h will work, as that assumes the timer variable was at 0 when you tuned. Of course it doesn't have to be.

In FS you can not test two variables against each other as far as I know, but you can test them again some present value.

I assumed that IFMSK would not work for the reasons you mentioned. To get around the problem that tick18 does not necessarily start at zero, my thought was to compute the value of tick18 in 30 minutes, then use IFIN1 or IFIN2 to test the current value of tick18 against this computed number. To get the value of tick18 in 30 minutes, you could XOR tick18 with the desired delay, in this case 8000h, which is 32768 ticks, or roughly 30 minutes. The resulting number should be what tick18 will read in 30 minutes.

All of this presumes, of course, that there is any way in BGL code to XOR the value of tick18 with a constant value like 8000h, or to compare the current value of tick18 against a computed value.
 
To get the value of tick18 in 30 minutes, you could XOR tick18 with the desired delay

I thought about this some more and realized that this won't work. XOR'ing does not give us the number we need. Oh well, back to the drawing board.
 
I still think it should be possible, but I would have to think about the correct procedure. Maybe you can use a similar logic as the interpolation that is used for animations.

To overcome the starting problem it might also work to let the timer run for a shorter period of time (like 1 minute) and then count how many times this timer runs. That way you can get close (enough) to 30 minutes.

It's a pity you can't do calculations in the in BGL file, so would allow such cool conditions :D.
 
Arno,

I did it!!!!!

I picked up on your suggestions about BGL_INTERPOLATE and counting cycles of tick18, and it actually works! I now have pilot activated lighting that turns itself off after 15 minutes.

Attached below is the complete code for conditional display of airport lighting that follows these rules:

  1. Lights are off during the day.
  2. Lights turn on at 7:00AM and off at the end of DAWN.
  3. Lights turn on at DUSK and off at 9:00PM.
  4. All times automatically adjust for daylight savings.
  5. Between 9:00PM and 7:00AM (when the tower is closed), the lights are off until the pilot is within 5km of the lights and tunes COM1 to 119.00.
  6. If COM1 is then tuned to another frequency, the lights stay on for another 15 minutes, then turn off.
  7. If COM1 is tuned back to 119.00 before the lights turn off, then the 15 minute counter is reset to zero.

The trick was using BGL_INTERPOLATE to increment a counter variable every time a particular bit of tick18 changes from 0 to 1. I used the 5th bit, which increments my counter every 1.78 seconds. I run my counter to 512, which takes roughly 15 minutes. Once I had the algorithm worked out, the final mystery was trying to figure out where to put the localvar tables in the code so that the thing would actually work.

Any suggestions to improve this further would be most welcome. Otherwise, I need to get back to placing the rest of my airport lighting now that I have the conditional display issues sorted out. Thanks for creating this community. It is an incredible resource.

Taylor



Code:
objectname_MasterScale_2 label BGLCODE

BGL_JUMP_32 skiptables

light_table_localvars label word
   dw  0  ; switch
   dw  0  ; flag
   dw  0  ; counter

light_table_addone label word
   dw  2
   dw  0,1,999,1000

skiptables label BGLCODE

LOCAL_BASE_32 light_table_localvars

VAR_BASE_32 VAR_BASE_GLOBAL

IFIN1 nolights, 028ch, 2, 4     ; time of day is not daytime

IFIN1 DSToff, 038eh, 420, 420   ; DST if offset is 7 hr x 60 min West of GMT
IFIN1 lightson, 0389h, 4, 13    ; GMT from 4:00 to 13:59:59 (21:00-07:00 PDT)
BGL_JUMP_32 DSTend
DSToff label BGLCODE
IFIN1 lightson, 0389h, 5, 14    ; GMT from 5:00 to 14:59:59 (21:00-07:00 PST)
DSTend label BGLCODE

IFIN2 timelights, 07beh, 1900h, 1900h, 033bh, 0, 5000  ; COM1 on 119.0 within 5 km
VAR_BASE_32 VAR_BASE_LOCAL
SETWRD 0h, 1
SETWRD 2h, 0
SETWRD 4h, 0
BGL_JUMP_32 lightson

timelights label BGLCODE
VAR_BASE_32 VAR_BASE_LOCAL
IFIN1 nolights, 0h, 1, 1
VAR_BASE_OVERRIDE VAR_BASE_GLOBAL
IFMSK holdlights, 05FCh, 0010h  ; add one to the count every 1.78 seconds
IFIN1 skipcount, 2h, 0, 0
BGL_INTERPOLATE VAR_BASE_LOCAL, 4h, VAR_BASE_LOCAL, 4h, VAR_BASE_LOCAL, (offset light_table_addone - light_table_localvars)
SETWRD 2h, 1

skipcount label BGLCODE
IFIN1 lightson, 4h, 512, 1000   ; takes roughly 15 minutes to count to 512
SETWRD 0h, 0
SETWRD 2h, 0
SETWRD 4h, 0
BGL_JUMP_32 nolights

holdlights label BGLCODE
SETWRD 2h, 0

lightson label BGLCODE

VAR_BASE_32 VAR_BASE_GLOBAL

<<<BGL_LIGHT code goes here>>>

nolights label BGLCODE

BGL_RETURN
 
Outstanding! This code deserves to be placed in the Wiki for posterity.

There's absolutely no point in anyone ever having to reinvent this wheel! :D
 
That sounds like a good suggestion to me. Taylor do you want to write the explanation about the code yourself or should I assist in making an Wiki article out of this?
 
Arno,

I am happy to write this up for the wiki. It will probably take me a few days to get to it, and I would like to get your input on some of the explanations (since I am not a programmer by profession and don't really understand all the code I wrote). My goal would be to write this up so that it is comprehensible to a programming novice.

Taylor
 
Sounds good, you can make the start on the wiki then and we'll discuss afterwards and I can add more detail where needed.
 
Arno,

I have posted my tutorial on pilot activated lighting to the wiki here. It came out much longer than I expected. I doubt you will need (or want) to add more detail. In fact, you might want to break the thing up into more than one wiki entry.

Anyway, I would appreciate it if you would review the tutorial and help me correct any errors I might have made. Also, I embedded in the text three questions for you. They are in red, bolded text and should be really easy to spot.

Thanks.

Taylor
 
Thanks, I'll take a look. Hopefully later today, as I am about to run out of the house now :D.
 
Back
Top