Resolving the Conflicts
In the last section, we listed some of the conflicts we need to resolve before we can reach our goal. I approach the problem with the use of classes since classes can automate things. Even though C++ is somewhat easy, VB is much easier. Note that all things I did here could be done without using classes. However, I think it was simplified and cleared up when I used classes. You'll hopefully see what I mean later.
To wrap up this section--the first problem we mentioned above is going to be solved by having a class called "CLine". It contains functions for all sorts of line manipulations. The second problem will be resolved with our "CBuffer" class and the last two will be solved by our "CConsole" class.
You only need to use the CConsole class for implementing this console. CConsole uses the CBuffer and CLine classes to do its buffer manipulation. The way this console works is described here:
The programmer creates an instance of the CConsole class.
Upon the main window's KeyPress Event (WM_KEYPRESS), the programmer sends the CConsole object the corresponding ASCII key code.
CConsole processes the key, if the console is in the active state. CConsole automatically toggles active state when the "~" (tilde) key is pressed, just like in Quake.
If the key is processed, CConsole adds the key to its CLine class instance. CLine checks to make sure that the maximum number of characters that could be held on the screen's line is not exceeded. If the Enter key is pressed, the data in the CLine instance of CConsole is added to the CBuffer class.
CBuffer adds the CLine object to itself, and does any line scrolling (oldest line gets scrolled out of view, and the newest line gets its place in the very bottom).
When rendering, right before swapping the backbuffer to the screen, the programmer calls the CConsole's Render function. The Render function draws each line of CBuffer onto the backbuffer, if it is in active state.
When done, the programmer releases the CConsole instance, which releases the CBuffer and CLine along with its font surface and background image surface.
See how simple it is? It's much more simple than any one of my older approaches at least. (Special thanks to Gaz and Ripper)
|