Bah
1,846
3
Advertisement
Work has eaten my time this past week. I found some old code from a past (failed, shock horror) game project. It was in C and I thought I could thieve/reuse most of it as a base for Space Invaders (after porting it to C# of course [smile]).
I had a look through and I remembered doing something pretty interesting that helped me with a problem that I don't think is mentioned much: Switching what is rendered and what inputs are taken in a game. For example: your main game menu looks entirely different to the 'main' part of your game and it takes different inputs. How do you manage these different situations?
What I had done is implement a RenderMode table which linked a number of callbacks to the bits in an __int64. This allowed me to toggle drawing things to the screen by simply bitwise XOR-ing the relevant bit in the current RenderMode. I could then bitwise AND each RenderMode in the lookup table with the current RenderMode and if it came out true I would call the relevant callback which would draw something to the screen.
This then extended to my input functions where I would associate each key (mouse or keyboard) with a callback and a RenderMode- ensuring that some keys could be painlessly reused for a menu or in the game proper.
I'm currently porting this code over to C# (using ulong so I get the possibility of 128 unique RenderModes) hopefully it will be as much of a success as it was in C.
I'll post the C code if anyone wants, I can't be bothered to upload it if it ain't gonna be used [grin]
I had a look through and I remembered doing something pretty interesting that helped me with a problem that I don't think is mentioned much: Switching what is rendered and what inputs are taken in a game. For example: your main game menu looks entirely different to the 'main' part of your game and it takes different inputs. How do you manage these different situations?
What I had done is implement a RenderMode table which linked a number of callbacks to the bits in an __int64. This allowed me to toggle drawing things to the screen by simply bitwise XOR-ing the relevant bit in the current RenderMode. I could then bitwise AND each RenderMode in the lookup table with the current RenderMode and if it came out true I would call the relevant callback which would draw something to the screen.
This then extended to my input functions where I would associate each key (mouse or keyboard) with a callback and a RenderMode- ensuring that some keys could be painlessly reused for a menu or in the game proper.
I'm currently porting this code over to C# (using ulong so I get the possibility of 128 unique RenderModes) hopefully it will be as much of a success as it was in C.
I'll post the C code if anyone wants, I can't be bothered to upload it if it ain't gonna be used [grin]
Advertisement
Advertisement
Advertisement
Discussion