• 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.

Tips for writing efficient code?

Messages
10,158
Country
us-arizona
Hey guys,

I was just wondering if there are any pros and cons to 'using up space' on a FS9 XML gauge.

For instance, I am using a TON of labels to section off all the various compartments of my PFD and MFD. Can I leave those in there when I ship out my finished code? or should I go in and delete alot of the non-code labelling? I would really like to keep it as it is, and seems to run fine on my computer.

I thought I would ask.

Also, I was told once that some XML code can be accidentally written in such a way as to slow down systems. I dont know how that happens, but supposedly one can write code which if not found in FS, will seek to bring down frame rates by using excess system memory.


Bill
LHC
 
I believe labelling is a good practice when you have to deal with complex code in a gauge. I use a lot of labels to identify my elements and their purposes, considering that labels and comments are discarded -not parsed- at gauge load time.

Regarding XML code slowing down system, that's not exactly true as you present it. Actually there are three things to consider when writing efficient code in XML

-<Element> are processed as classes with an integral structure each, and there is a limif of the amount a gauge can handle. It should be better to use just the proper number of them within a gauge, no matter would be very rare to reach this point in a standard XML file.

-<Value>/<Visible>/<Update> scripts are parsed to core C interpreting functions one char at a time, so the less code you write here, the better for performance. Lots of unnecessary if{ els{ could improve readability, but being rather harmless in basic gauges, should be avoided in complex ones.

-Bitmaps really affect performance (fps), depending on their size and color deep. Some of them could be replaced by <Text> and similar commands in some long panel projects.

Tom
 
Hey Tom,

Many thanks for the input on that.

On writing code, I found out how its 'seen' by opening the XML in IE7 to try to locate a fault/mistake in the code I was working on yesterday, and saw how it auto-eliminates spaces and puts all unreadables < !-- and -- > sections to a lite gray (barely visible).

I'll keep that in mind on the multiple calculations in a sophisticated gauge, which is what I am working on.

On Bitmaps, I had thought that making the system draw the rectangles and font was hardest on a system. I have been replacing things with bitmaps.. arrghh.. I didnt know realise that Bitmaps take more resources. I'll use Font Text and custom draw Rectangles and lines more often. Might even save me more time as well.

Many thanks for the input on this Tom.


Bill
LHC
 
Back
Top