Sign in to follow this  
Guest zip

Redundant code?

Recommended Posts

Have seen people doing this:

case PANEL_SERVICE_PRE_INITIALIZE:if (MGaugeSound == NULL) {MGaugeSound = LoadLibrary("GaugeSound");}bg_element = (PELEMENT_STATIC_IMAGE)pgauge->elements_list[0];GaugePlaySound = (TGaugePlaySound)GetProcAddress(MGaugeSound,"GaugePlaySound");GaugeStopSound = (TGaugeStopSound)GetProcAddress(MGaugeSound,"GaugeStopSound");TerminateSounds = (TTerminateSounds)GetProcAddress(MGaugeSound,"TerminateSounds");break;case PANEL_SERVICE_PRE_KILL:MGaugeSound = GetModuleHandle("GaugeSound");if (MGaugeSound == NULL) {MGaugeSound = LoadLibrary("GaugeSound");}GaugePlaySound = (TGaugePlaySound)GetProcAddress(MGaugeSound,"GaugePlaySound");GaugeStopSound = (TGaugeStopSound)GetProcAddress(MGaugeSound,"GaugeStopSound");TerminateSounds = (TTerminateSounds)GetProcAddress(MGaugeSound,"TerminateSounds");(TerminateSounds)();FreeLibrary(MGaugeSound);break;

But seems like once you have loaded the DLL and located the functions, that you do not need to repeat this. So, the above could be:

case PANEL_SERVICE_PRE_INITIALIZE:if (MGaugeSound == NULL) {MGaugeSound = LoadLibrary("GaugeSound");}bg_element = (PELEMENT_STATIC_IMAGE)pgauge->elements_list[0];GaugePlaySound = (TGaugePlaySound)GetProcAddress(MGaugeSound,"GaugePlaySound");GaugeStopSound = (TGaugeStopSound)GetProcAddress(MGaugeSound,"GaugeStopSound");TerminateSounds = (TTerminateSounds)GetProcAddress(MGaugeSound,"TerminateSounds");break;case PANEL_SERVICE_PRE_KILL:(TerminateSounds)();FreeLibrary(MGaugeSound);break;

Also, what's with this line?:

bg_element = (PELEMENT_STATIC_IMAGE)pgauge->elements_list[0];

Is this just a short-cut?Thanks,Stick

Share this post


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

A lot of the examples I've seen can probably use some serious cleaning up and optimization, not to mention that a hefty dose of comments would be nice :).Warning: lines using pre-processor macros which run galore in gauge writing can lead to mysterious and hard to find bugs.I cache most global values, including handles at it seems redundant to read them at every cycle since they do not change and you want to do everything to increase frame rates.The only issue I see is that if you have multiple shared DLLs with different instances but share the code, so that you would need to check the current instance and handle inside the main gauge callback function.As far as the element question, it's a reference to a paintable bitmap (one created by MAKE_STATIC, with the DIB image flag specified). That's normally the second item after your background image in the element list, but it doesn't have to be. You need to use the proper element offset in the list though. If you try to paint on an image without the DIB flag and use the wrong offset in the element list, you usually end up with a crash. Using a debugger helps you ensure you get the right item.If you lookup the flight map example in the SDK samples, it shows you how to do GDI+ drawings on a static bitmap.

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