Sign in to follow this  
Guest zip

global init callback for gauge collection and after failure

Recommended Posts

I was wondering if it is possible to have a global init for a gauge collection. I want to read the registry and set the path where FS2004 saves the aircraft config files. However, rather than doing this for each individual gauge, I'd rather do it ONCE on startup and save it as a variable (to save time). I could theoretically do it in only one gauge, but if someone would not include that gauge in the panel, then the init callback won't get called, causing a problem for the other gauges.Secondly, I'd like to reset values after a failure. The beauty of the electrical panel failure is that I don't need to check battery and alternator status (which costs time). However, I want to program a Davtron timer and make it go into "volts display and UT display modes" on start up. This is easy to do, but if I switch the power off, and then on again, I can't reset those values. Can I achieve this somehow? Additionally, MAKE_STATIC doesn't seem to be affected by a failure NO_DRAW, which is a pain...I hope my questions make sense...Any ideas?Cheers, Christian

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

Christian,There isn't a global init like that. Suggest you have each gauge using the information check the status of the variable containing said information. The result of this check will be that they do nothing at all if it doesn't contain valid info. In effect the whole panel would become inop if the gauge doing the reading was missing.To reset your Davtron, use a second variable to monitor its on/off status. Using this variable and the actual power variable, you can detect when the unit has been powered on or off. When such a change occurs, you can force a change in the fuction variables to get Volts and UT.MAKE_STATIC may not be affected by the NO_DRAW action, but MAKE_ICON will be. Use an RGB(0,0,0) background and move your existing bitmap to the icon.Doug

Share this post


Link to post
Share on other sites

If you modify the gauges.h file and scan for the DLLMAIN routine, you can place any init code there (I recommend using a function call, I use "GlobalInit()".The DLLMAIN entry is called once when your gauge file is loaded, because a gauge is nothing but a standard windows dynamic link library with a few specific callbacks so FS can hook into it.The nice thing about this is that if you have a multi-gauge in the same .GAU file, DLLMain is only called once.Hope this helps,

Share this post


Link to post
Share on other sites

Thanks Doud and Etienne,I have done some digging myself over the last two days and found this:Etienne should be right with the DllMain, I found this myself yesterday. However, doesn't it make more sense to put init code into module_init()? I have to actually try if this works... Seems to make more sense to me...Doug, I have used your timer suggestion, but I don't particularly like it. I could have three gauges, each needing to be reset on electrical failure, but now I have to check and set variables 3 times. This is a waste in computing resources and since this is done every frame, I'd like to avoid it. I found that the failure struct has a third variable bool bInit. The name suggests that if this is true, the code may actually call an init on failure. However, I tried setting it and it didn't work for me... I had a few more thoughts about this, eg, creating a message loop in DllMain, and checking failure states there. This could possibly work, but would need some hardcore programming, eg multithreading... MS will have such a message loop in their code it's a shame we can't tap into that one...The use of MAKE_ICON instead of MAKE_STATIC is a good one, although it feels like a hack to me. Yesterday, I realised what the problem is. If the gauge fails, it indeed doesn't draw the line anymore, but since it's been drawn, it'll stay. The fix is to make it IMAGE_USE_ERASE. This does indeed work. However, this solution will of course be slower, but I feel that this is the 'correct' one...Many thanks for your tips...Cheers, Christian

Share this post


Link to post
Share on other sites

Module Init will work (does the same thing as DLLMain()), but I trust DLLMain more :)Did you say hack? Everything in FS programming is a hack, didn't you know? Certainly feels like that :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this