2007-11-01

A Few More Things

A few simple things added today, because I’m knackered and don’t want to get too involved in anything major.

The status boolean values in the Gadget class (”_isClicked”, etc) are now contained in a “Flags” struct. I looked up Jeff’s suggestion in K&R and found that it’s as easy to implement as he intimated. As I mentioned a while ago (when I re-invented the struct in 6502 assembly), structs are a way of bundling variables together. When space on the heap is allocated for them (assuming they get allocated on the heap; perhaps I should just say “allocated”, and leave it at that), the amount of padding needed is reduced. A single bool could take up 32-bits of memory if the compiler aligns to 32-bit boundaries - 1 bit of data and 31 bits of padding. Bundling 10 bits into one struct would waste only 22 bits of memory instead of 310.

Creating a struct containing individual bits is just a matter of adding “bit fields” after each variable:

typedef struct { u8 active : 1; u8 clicked : 1; }

The bit fields give the length of the data in bits. Each can then be manipulated like a bog-standard bool.

Second item on today’s menu is virtual methods. All useful methods in the gadget classes are now virtual for easy subclassing.

Next, I’ve removed all of the unnecessary “all_gfx.h” includes from the gadget classes. The only ones left are in the Pong class (demo classes don’t really count) and the Woopsi class (which I’ll remove at some point).

Lastly, the screen flipping gadget is now in place. It currently flips the bottom screen up to the top, but doesn’t flip the top back down again. I’ll sort this another day after I’ve had some sleep…

Comments

Jeff on 2007-11-01 at 23:12 said:

Looks like I’m registered at SourceForge - id 1927539, user “jeff_laing”

ant on 2007-11-02 at 09:37 said:

OK, I think you should now be able to add bugs/feature requests. If not I’ll have another go at configuring things.