In this chapter, an MSVC IDE framework is established to assist in keeping the WindowMud code organized. This involves creating some new folders within the IDE in both File and Class Views and moving files and classes into them. But first, the MFC AppWizard is used to create an application.
Use the Application Wizard to generate a working application with the ability to use WinSock, to easily add menu options, and to handle documents, if desired.
Start up MSVC and do the following:
Compile and execute WinowMud! Check out the About dialog, just to make sure the application is functioning.
To facilitate an easy to manage working environment, the project files need some rearranging. To accomplish this, some directories need to be created and source files moved into the new directories. WindowMud source code will be placed in the \Source\WinApp and the \Source\Server directories. One way to accomplish this:
If everything was done correctly, WindowMud will compile with zero errors and zero errors warnings. Test WindowMud , make sure it continues to function as expected. After a few more cosmetic changes the WindowMud project will be all set for some serious mud developing.
Test WindowMud, make sure it continues to function as expected.
The BigDog function controls all aspects of the game server. It is the game loop. BigDog is started as a separate thread via menu option Control->Start Game and is stopped via menu option Control->Stop Game. Starting BigDog as a separate thread provides the developer with the freedom to expand WindowMud to include a dialog based world editor that can be used while the mud is up.
Some effort is required to get BigDog hooked into the generated WinApp, but the time is well spent resulting in a solid foundation upon which the rest of codebase is built. To get BigDog up and running:
Ok, this is not a tutorial on how to use MSVC, but here's a hint: Resource View. Add a main menu option called 'Control' with two options under it for 'Start Game' and 'Stop Game'
Use the class wizard to add the functions for both COMMAND and UPDATE_COMMAND_UI for both of the new menu options. The COMMAND function starts and stops the game and the UPDATE_COMMAND_UI function makes the Start/Stop Game menu options available at the appropriate times.
Time for a rebuild all! (or at least a compile). Rebuild (compile) often, it is much easier to find a mistake if you haven't coded thousand of lines since the last rebuild. Look for zero errors and zero warnings. The new menu options are now available and clickable, although they don't do anything.
StartBigDog and the typedef for structure THREADSTRUCT are defined in the CMainFrame class. StartBigDog is called from OnControlStartGame which contains the code that causes StartBigDog to run as a separate thread. OnControlStopGame simply renames file GoGoGo to StopIt, which is detected by BigDog using CFile::GetStatus and the game loop ends.
BigDog, at this point, is very simple but has two abilities critical to a mud:
In the WindowMud directory, create a Running directory and a subdirectory Control. In the Control directory, create an empty file with no extension file named StopIt. Just use notepad or the text editor of choice to create it.
The direcory tree for WindowMud at this point is:
\WindowMud \WindowMud\Debug \WindowMud\res \WindowMud\Running \WindowMud\Running\Control \WindowMud\Source \WindowMud\Source\Server \WindowMud\Source\WinApp
The HomeDir variable establishes the home directory for WindowMud. Later in the project, HomeDir will be read from a text file, thus enabling WindowMud to switch to an alternate directory by simply editing HomeDir.txt and restarting the game.
Near the top of WindowMud.cpp, this line creates global variable HomeDir which is currently only referenced in BigDog.cpp. Later, this variable will be read from a file so that if the mud is moved to a different directory, a code change is not required.
CString HomeDir = "C:\\WindowMud";
Separate the WinApp and the Server files into separate folders. The WinApp folder will contain the original wizard generated application and any new dialogs (like world editor dialogs). The Server will contain the WindowMud server code. BigDog is part of the server so it should be moved into a Server folder under File View.
Currently, there is nothing to put in the Class View Server folder (BigDog is under Globals).
Moving files into separate folders causes MSVC to not be able to find the include files. To fix this:
Rebuild the application using the Rebuild All option. The following message indicates success. No errors and no warnings.
WindowMud.exe - 0 error(s), 0 warning(s)
Start WindowMud and select Menu->Control->Start Game to start the game server. Open the \WindowMud\Running\Control directory and note the file named StopIt is gone and a file called GoGoGo has been created. When the game is stopped using Menu->Control->Stop Game, the GoGoGo file is gone and StopIt has been created. Also, note that Menu->Control->Start Game and Menu->Control->Stop Game are not both available at the same time.
This chapter completes the MSVC++ IDE framework for the WindowMud project. The source code is organized into WinApp and Server folders within the Source folder. WindowMud's game loop runs as a separate thread and can be started and stopped via a menu selection.
After downloading and unzipping the project, ensure that it is in the C:\WindowMud directory or change the HomeDir variable assignment to match the chosen directory.
Download the WindowMud project