Added error reporting to the LEVEL::Execute Function

Added the LEVEL::ConsolePrint Function
Added the quit command this can be used in a config file
Fixed console to make it work more logically and allow for output
This commit is contained in:
2003-10-26 17:17:33 -05:00
parent 1b69486f3c
commit d69652025d
5 changed files with 194 additions and 39 deletions

View File

@@ -29,6 +29,6 @@ set colordepth 16
set fullscreen 0 set fullscreen 0
map intro.map map intro.map
set maxfps 60 set maxfps 60
set rollleft w bind rollleft w
set rollright e bind rollright e
set sound false set sound false

View File

@@ -32,6 +32,8 @@ const float piover180 = 0.0174532925f;
const string DEFAULT_TEXTURE_NAME = "oa/textures/default.tga"; const string DEFAULT_TEXTURE_NAME = "oa/textures/default.tga";
const unsigned int MAX_CONSOLE_LINES = 30; //The max number of lines to be displayed in the console const unsigned int MAX_CONSOLE_LINES = 30; //The max number of lines to be displayed in the console
const unsigned int MAX_CONSOLE_HISTORY_LINES = MAX_CONSOLE_LINES + 20; //The max number of console lines to store in the history const unsigned int MAX_CONSOLE_HISTORY_LINES = MAX_CONSOLE_LINES + 20; //The max number of console lines to store in the history
const unsigned int MAX_CONSOLE_OUTPUT_LINES = MAX_CONSOLE_LINES;
const unsigned int MAX_OUTPUT_TEXT_LINES = 4; //The max number of output lines to be displayed on the screen
enum {GL_MY_TEXTURE_CONSOLEBACKGROUND=0, NUM_MENU_TEXTURES}; enum {GL_MY_TEXTURE_CONSOLEBACKGROUND=0, NUM_MENU_TEXTURES};
@@ -41,7 +43,7 @@ public:
LEVEL(); LEVEL();
~LEVEL(); ~LEVEL();
bool LoadMap(string mapname); bool LoadMap(string mapname);
void LoadMap(); bool LoadMap();
void SaveMap(string mapname); void SaveMap(string mapname);
bool LoadConfig(string cfgname); bool LoadConfig(string cfgname);
void LoadConfig(); void LoadConfig();
@@ -92,9 +94,9 @@ public:
private: private:
void ConsolePrint(string);
string consoleHistory[MAX_CONSOLE_HISTORY_LINES]; string consoleHistory[MAX_CONSOLE_HISTORY_LINES];
string consoleOutput[MAX_CONSOLE_OUTPUT_LINES];
string outputText[MAX_OUTPUT_TEXT_LINES];
}; };
#endif #endif

View File

@@ -37,6 +37,7 @@ public:
void FirstPosition(); void FirstPosition();
void LastPosition(); void LastPosition();
void Clear(); void Clear();
unsigned int Length();
void operator=(const list<ItemType>&); void operator=(const list<ItemType>&);
ItemType operator[](LIST_ARRAY_INDEX_TYPE) const; ItemType operator[](LIST_ARRAY_INDEX_TYPE) const;
ItemType& operator[](LIST_ARRAY_INDEX_TYPE); ItemType& operator[](LIST_ARRAY_INDEX_TYPE);
@@ -339,4 +340,24 @@ ItemType& list<ItemType>::operator[](LIST_ARRAY_INDEX_TYPE index)
} }
} }
template <class ItemType>
unsigned int Length()
{
if (head == NULL)
{
return 0;
}
else
{
int len = 1;
listNode<ItemType> temp = head->next;
while (temp != NULL)
{
temp = temp->next;
len++
}
return len;
}
}
#endif #endif

View File

@@ -105,6 +105,10 @@ bool LEVEL::LoadMap(string mapname)
delete [] tmpChar; delete [] tmpChar;
return false; return false;
} }
else
{
ConsolePrint("map file \"" + mapname + "\" opened successfully");
}
//Gravity //Gravity
input >> readBuffer; input >> readBuffer;
@@ -146,6 +150,9 @@ bool LEVEL::LoadMap(string mapname)
input >> readBuffer; input >> readBuffer;
triangles[i].normal.z = atof(readBuffer.c_str()); triangles[i].normal.z = atof(readBuffer.c_str());
} }
char lpszNumTriangles[6];
sprintf(lpszNumTriangles, "%d", numTriangles);
ConsolePrint(lpszNumTriangles + string(" triangles successfully read"));
//Number of textures; //Number of textures;
input >> readBuffer; input >> readBuffer;
@@ -157,6 +164,9 @@ bool LEVEL::LoadMap(string mapname)
{ {
input >> textureNames[i]; input >> textureNames[i];
} }
char lpszNumTextures[6];
sprintf(lpszNumTextures, "%d", numTextures);
ConsolePrint(lpszNumTextures + string(" textures successfully read"));
//BGM //BGM
input >> bgm; input >> bgm;
@@ -165,6 +175,8 @@ bool LEVEL::LoadMap(string mapname)
//Build display list //Build display list
if (sound) if (sound)
{ {
ConsolePrint("Starting sound");
BASS_Init(-1, 44100, BASS_DEVICE_LEAVEVOL, g_hWnd); BASS_Init(-1, 44100, BASS_DEVICE_LEAVEVOL, g_hWnd);
BASS_Start(); BASS_Start();
BASS_CDInit(NULL, BASS_DEVICE_LEAVEVOL); BASS_CDInit(NULL, BASS_DEVICE_LEAVEVOL);
@@ -186,13 +198,15 @@ bool LEVEL::LoadMap(string mapname)
BASS_StreamPlay(bgmStream, 1, BASS_SAMPLE_LOOP); BASS_StreamPlay(bgmStream, 1, BASS_SAMPLE_LOOP);
} }
} }
ConsolePrint("Sound init complete");
} }
return true; return true;
} }
void LEVEL::LoadMap() bool LEVEL::LoadMap()
{ {
LoadMap(nextLevel); return LoadMap(nextLevel);
} }
void LEVEL::SaveMap(string mapname) void LEVEL::SaveMap(string mapname)
@@ -263,7 +277,7 @@ void LEVEL::Render()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity(); glLoadIdentity();
// Move the camera to where the player is or more precisely move to world so the camer is where the playe is // Move the camera to where the player is
defaultPlayer->camera.Look(); defaultPlayer->camera.Look();
///* ///*
for (uint32 i=0; i<numTriangles; i++) for (uint32 i=0; i<numTriangles; i++)
@@ -347,11 +361,15 @@ void LEVEL::Render()
glEnable(GL_BLEND); glEnable(GL_BLEND);
//render the console background //render the console background
for(unsigned int i=0; i<MAX_CONSOLE_LINES; i++) //render the console output text
for(unsigned int i=0; i<MAX_CONSOLE_LINES-1; i++)
{ {
Print(30, glFont.ScreenHeight() - i*20, consoleHistory[MAX_CONSOLE_LINES-i-1].c_str(), 0); Print(30, glFont.ScreenHeight() - i*20, consoleOutput[MAX_CONSOLE_LINES-i-2].c_str(), 0);
} }
//Render the currently typed command
Print(30,glFont.ScreenHeight() - i*20, consoleHistory[0].c_str(),0);
//disable blending //disable blending
glDisable(GL_BLEND); glDisable(GL_BLEND);
@@ -457,10 +475,18 @@ void LEVEL::Execute(string cmd)
{ {
turnSpeed = (float)atof(word(cmd, ++i).c_str());//Floating(word(cmd, ++i)); turnSpeed = (float)atof(word(cmd, ++i).c_str());//Floating(word(cmd, ++i));
} }
else if(command == "movespeed")
{
moveSpeed = (float)atof(word(cmd, ++i).c_str());//FLoating(word(cmd, ++i));
}
else if(command == "mousespeed") else if(command == "mousespeed")
{ {
mouseSpeed = (float)atof(word(cmd, ++i).c_str()); mouseSpeed = (float)atof(word(cmd, ++i).c_str());
} }
else if(command == "mouselook")
{
mlook = Truth(word(cmd, ++i));
}
else if(command == "maxfps") else if(command == "maxfps")
{ {
maxFPS = Integer(word(cmd, ++i)); maxFPS = Integer(word(cmd, ++i));
@@ -485,6 +511,14 @@ void LEVEL::Execute(string cmd)
{ {
screen.fullscreen = Truth(word(cmd, ++i)); screen.fullscreen = Truth(word(cmd, ++i));
} }
else if(command == "colordepth")
{
screen.bpp = Integer(word(cmd, ++i));
}
else
{
ConsolePrint("Variable " + command + " doesn't exist");
}
} }
else if(command == "bind") else if(command == "bind")
{ {
@@ -492,86 +526,166 @@ void LEVEL::Execute(string cmd)
if(command == "forward") if(command == "forward")
{ {
defaultPlayer[0].controls.Bind(CTRLS_FORWARD, KeyName(word(cmd, ++i))); if(!defaultPlayer[0].controls.Bind(CTRLS_FORWARD, KeyName(word(cmd, ++i))))
{
ConsolePrint("Couldn't bind " + word(cmd, i) + " to action forward");
}
} }
else if(command == "backward") else if(command == "backward")
{ {
defaultPlayer[0].controls.Bind(CTRLS_BACKWARD, KeyName(word(cmd, ++i))); if(!defaultPlayer[0].controls.Bind(CTRLS_BACKWARD, KeyName(word(cmd, ++i))))
{
ConsolePrint("Couldn't bind " + word(cmd, i) + " to action backward");
}
} }
else if(command == "lookleft") else if(command == "lookleft")
{ {
defaultPlayer[0].controls.Bind(CTRLS_LOOKLEFT, KeyName(word(cmd, ++i))); if(!defaultPlayer[0].controls.Bind(CTRLS_LOOKLEFT, KeyName(word(cmd, ++i))))
{
ConsolePrint("Couldn't bind " + word(cmd, i) + " to action lookleft");
}
} }
else if(command == "lookright") else if(command == "lookright")
{ {
defaultPlayer[0].controls.Bind(CTRLS_LOOKRIGHT, KeyName(word(cmd, ++i))); if(!defaultPlayer[0].controls.Bind(CTRLS_LOOKRIGHT, KeyName(word(cmd, ++i))))
{
ConsolePrint("Couldn't bind " + word(cmd, i) + " to action lookright");
}
} }
else if(command == "lookup") else if(command == "lookup")
{ {
defaultPlayer[0].controls.Bind(CTRLS_LOOKUP, KeyName(word(cmd, ++i))); if(!defaultPlayer[0].controls.Bind(CTRLS_LOOKUP, KeyName(word(cmd, ++i))))
{
ConsolePrint("Couldn't bind " + word(cmd, i) + " to action lookup");
}
} }
else if(command == "lookdown") else if(command == "lookdown")
{ {
defaultPlayer[0].controls.Bind(CTRLS_LOOKDOWN, KeyName(word(cmd, ++i))); if(!defaultPlayer[0].controls.Bind(CTRLS_LOOKDOWN, KeyName(word(cmd, ++i))))
{
ConsolePrint("Couldn't bind " + word(cmd, i) + " to action lookdown");
}
} }
else if(command == "moveup") else if(command == "moveup")
{ {
defaultPlayer[0].controls.Bind(CTRLS_MOVEUP, KeyName(word(cmd, ++i))); if(!defaultPlayer[0].controls.Bind(CTRLS_MOVEUP, KeyName(word(cmd, ++i))))
{
ConsolePrint("Couldn't bind " + word(cmd, i) + " to action moveup");
}
} }
else if(command == "movedown") else if(command == "movedown")
{ {
defaultPlayer[0].controls.Bind(CTRLS_MOVEDOWN, KeyName(word(cmd, ++i))); if(!defaultPlayer[0].controls.Bind(CTRLS_MOVEDOWN, KeyName(word(cmd, ++i))))
{
ConsolePrint("Couldn't bind " + word(cmd, i) + " to action movedown");
}
} }
else if(command == "moveleft") else if(command == "moveleft")
{ {
defaultPlayer[0].controls.Bind(CTRLS_MOVELEFT, KeyName(word(cmd, ++i))); if(!defaultPlayer[0].controls.Bind(CTRLS_MOVELEFT, KeyName(word(cmd, ++i))))
{
ConsolePrint("Couldn't bind " + word(cmd, i) + " to action moveleft");
}
} }
else if(command == "moveright") else if(command == "moveright")
{ {
defaultPlayer[0].controls.Bind(CTRLS_MOVERIGHT, KeyName(word(cmd, ++i))); if(!defaultPlayer[0].controls.Bind(CTRLS_MOVERIGHT, KeyName(word(cmd, ++i))))
{
ConsolePrint("Couldn't bind " + word(cmd, i) + " to action moveright");
}
} }
else if(command == "fireprimary") else if(command == "fireprimary")
{ {
defaultPlayer[0].controls.Bind(CTRLS_FIREPRIMARY, KeyName(word(cmd, ++i))); if(!defaultPlayer[0].controls.Bind(CTRLS_FIREPRIMARY, KeyName(word(cmd, ++i))))
{
ConsolePrint("Couldn't bind " + word(cmd, i) + " to action fireprimary");
}
} }
else if(command == "firesecondary") else if(command == "firesecondary")
{ {
defaultPlayer[0].controls.Bind(CTRLS_FIRESECONDARY, KeyName(word(cmd, ++i))); if(!defaultPlayer[0].controls.Bind(CTRLS_FIRESECONDARY, KeyName(word(cmd, ++i))))
{
ConsolePrint("Couldn't bind " + word(cmd, i) + " to action firesecondary");
}
} }
else if(command == "weapnext") else if(command == "weapnext")
{ {
defaultPlayer[0].controls.Bind(CTRLS_WEAPONNEXT, KeyName(word(cmd, ++i))); if(!defaultPlayer[0].controls.Bind(CTRLS_WEAPONNEXT, KeyName(word(cmd, ++i))))
{
ConsolePrint("Couldn't bind " + word(cmd, i) + " to action weapnext");
}
} }
else if(command == "weapprev") else if(command == "weapprev")
{ {
defaultPlayer[0].controls.Bind(CTRLS_WEAPONPREV, KeyName(word(cmd, ++i))); if(!defaultPlayer[0].controls.Bind(CTRLS_WEAPONPREV, KeyName(word(cmd, ++i))))
{
ConsolePrint("Couldn't bind " + word(cmd, i) + " to action weapprev");
}
} }
else if(command == "togglelights" || command == "togglelighting") else if(command == "togglelights" || command == "togglelighting")
{ {
defaultPlayer[0].controls.Bind(CTRLS_TOGGLE_LIGHTS, KeyName(word(cmd, ++i))); if(!defaultPlayer[0].controls.Bind(CTRLS_TOGGLE_LIGHTS, KeyName(word(cmd, ++i))))
{
ConsolePrint("Couldn't bind " + word(cmd, i) + " to action togglelights");
}
} }
else if(command == "togglefps") else if(command == "togglefps")
{ {
defaultPlayer[0].controls.Bind(CTRLS_TOGGLE_FPS, KeyName(word(cmd, ++i))); if(!defaultPlayer[0].controls.Bind(CTRLS_TOGGLE_FPS, KeyName(word(cmd, ++i))))
{
ConsolePrint("Couldn't bind " + word(cmd, i) + " to action togglefps");
}
} }
else if(command == "toggleconsole") else if(command == "toggleconsole")
{ {
defaultPlayer[0].controls.Bind(CTRLS_TOGGLE_CONSOLE, KeyName(word(cmd, ++i))); if(!defaultPlayer[0].controls.Bind(CTRLS_TOGGLE_CONSOLE, KeyName(word(cmd, ++i))))
{
ConsolePrint("Couldn't bind " + word(cmd, i) + " to action toggleconsole");
}
} }
else if(command == "togglemouselook") else if(command == "togglemouselook")
{ {
defaultPlayer[0].controls.Bind(CTRLS_TOGGLE_MOUSELOOK, KeyName(word(cmd, ++i))); if(!defaultPlayer[0].controls.Bind(CTRLS_TOGGLE_MOUSELOOK, KeyName(word(cmd, ++i))))
{
ConsolePrint("Couldn't bind " + word(cmd, i) + " to action togglemouselook");
}
} }
else if(command == "quickmouselook") else if(command == "quickmouselook")
{ {
defaultPlayer[0].controls.Bind(CTRLS_QUICKMOUSELOOK, KeyName(word(cmd, ++i))); if(!defaultPlayer[0].controls.Bind(CTRLS_QUICKMOUSELOOK, KeyName(word(cmd, ++i))))
{
ConsolePrint("Couldn't bind " + word(cmd, i) + " to action quickmouselook");
}
}
else if(command == "rollleft")
{
if(!defaultPlayer[0].controls.Bind(CTRLS_ROLLLEFT, KeyName(word(cmd, ++i))))
{
ConsolePrint("Couldn't bind " + word(cmd, i) + " to action rollleft");
}
}
else if(command == "rollright")
{
if(!defaultPlayer[0].controls.Bind(CTRLS_ROLLRIGHT, KeyName(word(cmd, ++i))))
{
ConsolePrint("Couldn't bind " + word(cmd, i) + " to action rollright");
}
}
else
{
ConsolePrint("No action identified by " + command);
} }
} }
else if(command == "map" || command == "map_load") else if(command == "map" || command == "map_load")
{ {
nextLevel = word(cmd, ++i); nextLevel = word(cmd, ++i);
UnloadMap(); UnloadMap();
LoadMap(); if(!LoadMap())
{
ConsolePrint("Unable to load level " + command);
nextLevel = "intro.map";
LoadMap();
}
} }
else if(command == "unbind") else if(command == "unbind")
{ {
@@ -589,7 +703,10 @@ void LEVEL::Execute(string cmd)
else if(command == "exec" || command == "config_load") else if(command == "exec" || command == "config_load")
{ {
command = tolower(word(cmd, ++i)); command = tolower(word(cmd, ++i));
LoadConfig(command); if(!LoadConfig(command))
{
ConsolePrint("Unable to load config file " + word(cmd, i));
}
} }
else if(command == "map_save") else if(command == "map_save")
{ {
@@ -630,10 +747,14 @@ void LEVEL::Execute(string cmd)
} }
} }
*/ */
else if(command == "quit")
{
PostQuitMessage(0);
}
else
{
ConsolePrint("Unknown command " + command);
}
} }
} }
@@ -1039,12 +1160,14 @@ void LEVEL::UpdateConsole(char newChar)
{ {
if(newChar == '\n') if(newChar == '\n')
{ {
Execute(tolower(consoleHistory[0]));
for (int i=MAX_CONSOLE_HISTORY_LINES - 1; i>0; i--) for (int i=MAX_CONSOLE_HISTORY_LINES - 1; i>0; i--)
{ {
consoleHistory[i] = consoleHistory[i-1]; consoleHistory[i] = consoleHistory[i-1];
} }
consoleHistory[0] = ""; consoleHistory[0] = "";
ConsolePrint(consoleHistory[1]);
Execute(tolower(consoleHistory[1]));
} }
else if(newChar == VK_BACK) else if(newChar == VK_BACK)
{ {
@@ -1059,4 +1182,13 @@ void LEVEL::UpdateConsole(char newChar)
MessageBox(NULL, errmsg, "Balls", MB_OK); MessageBox(NULL, errmsg, "Balls", MB_OK);
*/ */
} }
}
void LEVEL::ConsolePrint(string line)
{
for (int i=MAX_CONSOLE_OUTPUT_LINES - 1; i>0; i--)
{
consoleOutput[i] = consoleOutput[i-1];
}
consoleOutput[0] = line;
} }

View File

@@ -455,7 +455,7 @@ LRESULT CALLBACK WndProc(HWND hWnd,
} }
else else
{ {
level.UpdateConsole('.,'); level.UpdateConsole('.');
} }
} }
else if(wParam == VK_OEM_PLUS) else if(wParam == VK_OEM_PLUS)
@@ -488,7 +488,7 @@ LRESULT CALLBACK WndProc(HWND hWnd,
} }
else else
{ {
level.UpdateConsole('-,'); level.UpdateConsole('-');
} }
} }
else if(isalpha(uint8(wParam))) else if(isalpha(uint8(wParam)))