Game Flow update:
Seeing as I just finnished implementing two major features of the game I thought I'd post and update.
Update 1, loading maps:
I took a page from Mago's skyroads book and added a few touches. It's a pretty similer map format with some pretty important changes. Heres a small (4 blocks) map to demonstrate the format:
Code:
SECTION_MAP
MAPNAME run_intro
MODELPATH data\models\
TEXTUREPATH data\textures\
SECTION_MODELINDEX
MODELCOUNT 3
MODEL 0 block.ms3d
MODEL 1 wedge.ms3d
MODEL 2 biwedge.ms3d
SECTION_TEXTUREINDEX
TEXTURECOUNT 3
TEXTURE 0 industry\metal_block.tga
TEXTURE 1 industry\metal_floor.tga
TEXTURE 2 industry\metal_floor2.tga
SECTION_CUSTOM_FORCE_LIST
CUSTOMFORCE 0 // id
0.0 0.0 0.0 // bx by bz
10.0 10.0 10.0 // tx ty tz
0.0 0.0 5.0 // fx fy fz
SECTION_BLOCKLIST
ROWS 1
BLOCKS 8
ROW
BLOCK 0 0 0
BLOCK 0 1 0
BLOCK 0 2 0
BLOCK 0 3 0
ROW
BLOCK 1 0 0
BLOCK 1 1 0
BLOCK 1 2 0
BLOCK 1 3 0
END_BLOCKS
END_MAP
SECTION_<type> marks off each section
The first three lines are info about the map. The name, the model path, and the texture path. This will allow for map makers to keep their custom content in relative directories.
The next section is the model index. It contains the path to each model, and an id for it. The map uses instances* of models, so a minimal ammount of media is loaded per map. Translation and rotation information is contained in the block structure.
The next section is the texture index. Basicly the same as the model index, but for textures.
The fourth section is a bit more complicated. It is where the custom forces I talked about earlier are stored. I added comments (//) to help explain them, the // arn't part of the file.
First comes the command CUSTOMFORCE, it's unecessary but I added it to help divide up the information and make it more human readable (for hand editing). Immediatly after it is the id number. Each force has an index. The indexs are used to keep track of where it is in the array of custom forces. Since I forgot to mention it earlier, it works the same for texture and model indecies. On the next consecutive lines are the vectors of the bottom left, and top right corners. Customforces are confined into 3d cubes to ease their handling. The third consecutive line has the force vector that acts upon the player.
In the last section, all the blocks are stored. They are very simple right now, only holding the texture index, row and column position. I'll be adding more parameters when I really start worry about mapping. Things like rotation for models, and individual face texture indices.
User Inter Face Menu Update:
I've finished adding in the menu system and along the way came up with a program flow method. Rather then writing a long if statement for what functions to call in the game loop I use CallBack functionality instead. When the game is initialized at run time, the main menu function is stored in the call back function pointer. Options for new game, load, resume, etc will update the callback to next appropriate function.
Thus, while a menu is being displayed, the game loop will not be updating--and vice versa.
Of course I'll be adding GUI functionality which will be ingame interface that overlays the screen and doesn't interfere with the game loop. Later on that.
Heres a few code snippets for kicks and giggles.
from ui and uimain.cpp
Code:
/*****************************************************************************************************
// All UI Menus must be initiated with proper call back functions
*****************************************************************************************************/
void UIMenuInitialize() {
uimMain = new UIMenu(UICBMain); // main menu
uimMain->setColor( newVector(0.6f, 0.02f, 0.02f) ); // set bg color
uimMain->allocateItems(1); // one menu item
// create a new menu item
UIMenuItemText *temp = new UIMenuItemText("PERIL ROADS", "Crown Title", -72);
temp->setColor( newVector(1.7f, 1.5f, 0.0f), newVector(1.0f, 0.0f, 0.0f), newVector(0.0f, 0.0f, 1.0f) );
temp->setPosition( newVector(0.00f, 0.0f, -5.0f) );
// and add it to the main menu
uimMain->replaceItem(0,temp);
// initialize other menus here
};
//////////////////////////
// UIMenu Call Back Main
//////////////////////////
void UICBMain() {
// pretty simple right now, huh?
uimMain->receive(0, 0, 0, 0);
uimMain->render();
}
from the load map function
Code:
// load model info
if(cinstr(readbuffer, "SECTION_MODELINDEX") > -1) {
// number of models
readFile >> readbuffer;
if(cinstr(readbuffer, "MODELCOUNT") > -1) {
int nummodels = 0;
readFile >> nummodels;
// delete existing data
if(m_models)
delete[] m_models;
m_models = new MS3DModel[ nummodels ];
m_modelcount = nummodels;
}
// model loading loop
while(true) {
readFile >> readbuffer;
if(cinstr(readbuffer, "MODEL") > -1) { // make sure we are getting model index info
int index = 0;
readFile >> index; // get the model index number
readFile >> readbuffer; // and get the (relative) path name
char *fullpath = new char[512]; // create temporary storage for full path name
sprintf(fullpath, "%s%s", m_modelPath, readbuffer);
char *replacePath = new char[strlen(fullpath)+1]; // this will replace the model pointer, so it isn't deleted
memcpy(replacePath, fullpath, strlen(fullpath)+1);
m_models[index].setPath(replacePath); // save the path info
//MessageBox( NULL, replacePath, "INFO", MB_OK );
delete[] fullpath; // clean up
} else { break; }
}
}