The online racing simulator
[Z25] Alternative DashLights enum
(4 posts, started )
[Z25] Alternative DashLights enum
If, unlike Scawen within LFS itself, you only need the DashLights enum as bitmask, the following implementation is slightly (exactly 2 cpu cycles on x86 :razz faster than the reference implementation (see Scawen's post below on how to use the reference implementation):

enum
{
DL_SHIFT = 1, // bit 0 - shift light
DL_FULLBEAM = 2, // bit 1 - full beam
DL_HANDBRAKE = 4, // bit 2 - handbrake
DL_PITSPEED = 8, // bit 3 - pit speed limiter
DL_TC = 16, // bit 4 - TC active or switched off
DL_SIGNAL_L = 32, // bit 5 - left turn signal
DL_SIGNAL_R = 64, // bit 6 - right turn signal
DL_SIGNAL_ANY = 128, // bit 7 - shared turn signal
DL_OILWARN = 256, // bit 8 - oil pressure warning
DL_BATTERY = 512, // bit 9 - battery warning
DL_ABS = 1024, // bit 10 - ABS active or switched off
DL_SPARE = 2048, // bit 11
};

Although this will also work in C++, using an enum, meant to enumerate constants, for this purpose seems like a bit of a misuse to me. I recommend using const in C++ instead.
It's not a bug, because it's the actual enum that LFS uses, and it works.

To get the number representing the bit field, you just shift 1 left by the DL_x value.

e.g.

unsigned mask = 1 << DL_HANDBRAKE;

if (ShowLights & mask)
{
// handbrake light is switched on
}

Quote from Scawen :It's not a bug, because it's the actual enum that LFS uses, and it works.

Huh, to be honest I didn't think of that, I obviously had my "premature optimisation"-goggles on That said, if you'd implement it my way, you'd save yourself the bitshift
That's true, but this is also used for loops over arrays of lights and light info structures, so the plain index is used a lot within LFS.

[Z25] Alternative DashLights enum
(4 posts, started )
FGED GREDG RDFGDR GSFDG