Fixed console and made commands typed there work

This commit is contained in:
2003-10-20 13:31:30 -04:00
parent 4c6f5dfb15
commit 1685e64676
13 changed files with 411 additions and 296 deletions

View File

@@ -18,7 +18,7 @@ bind togglelights l
bind togglefps p
bind toggleconsole ~
bind toggleconsole `
bind toggleconsole i
bind toggleconsole z
bind togglemouselook m
bind quickmouselook y
set turnspeed 0.02
@@ -33,4 +33,4 @@ map intro.map
set maxfps 60
set rollleft w
set rollright e
set sound 1
set sound false

View File

@@ -8,6 +8,7 @@ class ControlSchemeClass
public:
void LoadDefaultControlScheme();
void ClearControlScheme();
void Unbind(uint8);
list<uint8> forward;
list<uint8> backward;

View File

@@ -50,6 +50,7 @@ public:
void LoadGLTextures();
void Render();
void UnloadMap();
void UpdateConsole(char);
uint32 FPS();
void ParseCmds(LPSTR);

View File

@@ -179,28 +179,29 @@ void list<ItemType>::Remove(ItemType target)
if(head != NULL)
{
listNode<ItemType>* temp = head;
tail->next = head;
listNode<ItemType>* temp2 = head;
while(temp->next != NULL && temp->data != target)
{
tail->next = temp;
temp2 = temp;
temp = temp->next;
}
if(temp->data == target)
{
if(tail->next != head)
if(temp != head)
{
tail->next->next = temp->next;
temp2->next = temp->next;
delete temp;
}
else
{
if(tail == head)
tail = NULL;
head = head->next;
delete tail->next;
delete temp2;
}
}
tail->next = NULL;
}
}

View File

@@ -22,7 +22,8 @@ static bool keys[256]; // Array for which keys are down now
static bool keys2[256]; // Array for which keys are were down already
static bool active=true; // Is window active flag
static bool fullscreen=true; // Is window fullscreen flag
static bool showConsole = false;// Do we need to draw the console
//static bool showConsole = false;// Do we need to draw the console
//static SCREEN g_Screen = {800,600,16,1,"OpenArena"};

BIN
oa.ncb

Binary file not shown.

2
oa.sln
View File

@@ -1,4 +1,4 @@
Microsoft Visual Studio Solution File, Format Version 8.00
Microsoft Visual Studio Solution File, Format Version 7.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "oa", "oa.vcproj", "{6F5D0FF6-A032-4356-932E-865B601E0DD4}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection

BIN
oa.suo

Binary file not shown.

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Version="7.0"
Name="oa"
ProjectGUID="{6F5D0FF6-A032-4356-932E-865B601E0DD4}"
SccProjectName=""
@@ -102,7 +102,7 @@
<Tool
Name="VCLinkerTool"
AdditionalOptions="/MACHINE:I386"
OutputFile=".\Debug/oa.exe"
OutputFile=".\Debug\oa.exe"
LinkIncremental="2"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories=".\lib"
@@ -147,6 +147,9 @@
<File
RelativePath=".\src\bmp.cpp">
</File>
<File
RelativePath="src\camera.cpp">
</File>
<File
RelativePath=".\src\ctrls.cpp">
</File>

View File

@@ -3,7 +3,7 @@
// Module: ctrls.cpp
// Author: Tom Hicks
// Creation: 09-01-2003
// LastEdit: 10-09-2003
// LastEdit: 10-20-2003
// Editors: Tom Hicks
//
// Purpose:
@@ -12,7 +12,11 @@
// Summary of Methods:
// ControlSchemeClass
// void LoadDefaultControlScheme();
// -Loads the default control scheme
// void ClearControlScheme();
// -Clears the control scheme
// void Unbind(uint8 key);
// -Removes key from all control lists.
//
// Summary of Properties:
// ControlSchemeClass
@@ -110,3 +114,24 @@ void ControlSchemeClass::ClearControlScheme()
weaponPrev.Clear();
}
void ControlSchemeClass::Unbind(uint8 key)
{
backward.Remove(key);
firePrimary.Remove(key);
fireSecondary.Remove(key);
forward.Remove(key);
lookDown.Remove(key);
lookUp.Remove(key);
lookRight.Remove(key);
lookLeft.Remove(key);
moveDown.Remove(key);
moveUp.Remove(key);
moveRight.Remove(key);
quickMouseLook.Remove(key);
toggleConsole.Remove(key);
toggleFPS.Remove(key);
toggleLights.Remove(key);
toggleMouseLook.Remove(key);
weaponNext.Remove(key);
weaponPrev.Remove(key);
}

View File

@@ -3,7 +3,7 @@
// Module: level.cpp
// Author: Tom Hicks
// Creation: 09-01-2003
// LastEdit: 10-09-2003
// LastEdit: 10-20-2003
// Editors: Tom Hicks
//
// Purpose:
@@ -32,12 +32,12 @@ using namespace std;
LEVEL::LEVEL()
{
/*
consoleHistory[0] = "hello0";
consoleHistory[1] = "hello1";
consoleHistory[MAX_CONSOLE_HISTORY_LINES-2] = "hello3";
consoleHistory[MAX_CONSOLE_HISTORY_LINES-1] = "hello4";
*/
textureNames = NULL;
numTextures = 0;
@@ -80,9 +80,6 @@ LEVEL::~LEVEL()
}
}
bool LEVEL::LoadMap(string mapname)
{
ifstream input;
@@ -284,20 +281,6 @@ void LEVEL::Render()
}
glEnd();
}
/**/
/*
glBindTexture(GL_TEXTURE_2D, 1);
glBegin(GL_TRIANGLES);
glTexCoord2f(0,0);
glVertex3f(-10, -10,-5);
glTexCoord2f(0,2);
glVertex3f(-10,10,-5);
glTexCoord2f(2,0);
glVertex3f(10,-10,-5);
glEnd();
/**/
glPopMatrix();
//Draw HUD
@@ -464,7 +447,7 @@ void LEVEL::Execute(string cmd)
uint32 i=0xFFFFFFFF;
while(word(cmd, ++i) != "")
{
command = word(cmd, i);
command = tolower(word(cmd, i));
if(command == "set")
{
@@ -588,6 +571,19 @@ void LEVEL::Execute(string cmd)
{
nextLevel = word(cmd, ++i);
}
else if(command == "unbind")
{
command = tolower(word(cmd, ++i));
if(command == "all")
{
defaultPlayer[0].controls.ClearControlScheme();
}
else
{
defaultPlayer[0].controls.Unbind(KeyName(command));
}
}
}
}
@@ -949,3 +945,29 @@ void LEVEL::Print(int x, int y, const char* str, unsigned int set)
{
glFont.Print(x,y,str, set);
}
void LEVEL::UpdateConsole(char newChar)
{
if(newChar == '\n')
{
Execute(tolower(consoleHistory[0]));
for (int i=MAX_CONSOLE_HISTORY_LINES - 1; i>0; i--)
{
consoleHistory[i] = consoleHistory[i-1];
}
consoleHistory[0] = "";
}
else if(newChar == VK_BACK)
{
consoleHistory[0] = Left(consoleHistory[0], consoleHistory[0].length()-1);
}
else
{
consoleHistory[0] = consoleHistory[0] + newChar;
/*
char errmsg[256];
sprintf(errmsg, "Unhangled keypress: %d", newChar);
MessageBox(NULL, errmsg, "Balls", MB_OK);
*/
}
}

View File

@@ -1,33 +1,56 @@
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
// Author: Tom Hicks
// Module: main.cpp
// Purpose: This is an implementation of the openarena SDK.
// Author: Tom Hicks
// Creation: 09-01-2003
// LastEdit: 10-20-2003
// Editors: Tom Hicks
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Purpose:
// To implement the OpenArena SDK.
//
// Summary of Methods:
// Global
// -InitControls()
// Loads the defaultPlayer's configuration.
// -InitGL()
// Initializes OpenGL and is responsible for loading textures.
// -ResizeGLScene(GLsizei width, GLsizei height)
// Resizes the viewport to the current size of the visible area of the window specified by width and height.
// -KillGLWindow()
// Closes the window.
// -CreateGLWindow(string title, int width, int height, int bits, bool fullscreenflag)
// Creates the window with the specified parameters.
// -WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
// Main procedure.
// -WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
// Window Procedure for the OpenGL window.
//
////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
//include necessary header files
#include "../include/main.h"
//link necessary libraries
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "glaux.lib")
#pragma comment(lib, "winmm.lib")
//Ensure CDS_FULLSCREEN is defined
#ifndef CDS_FULLSCREEN
#define CDS_FULLSCREEN 4
#endif
using namespace std;
void InitControls();
int InitGL(GLvoid);
void ReSizeGLScene(GLsizei width, GLsizei height);
bool CreateGLWindow(string title, int width, int height, int bits, bool fullscreenflag);
void KillGLWindow();
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Function Definitions
@@ -89,7 +112,7 @@ int InitGL(GLvoid)
// Post:
//
GLvoid ReSizeGLScene(GLsizei width, GLsizei height)
void ReSizeGLScene(GLsizei width, GLsizei height)
{
if (height==0)
height=1;
@@ -103,7 +126,7 @@ GLvoid ReSizeGLScene(GLsizei width, GLsizei height)
glLoadIdentity();
}
GLvoid KillGLWindow(GLvoid)
void KillGLWindow()
{
if (g_Screen.fullscreen)
{
@@ -311,10 +334,48 @@ LRESULT CALLBACK WndProc( HWND hWnd,
return 0;
}
case WM_KEYDOWN:
{
if(level.showConsole)
{
level.defaultPlayer[0].controls.toggleConsole.FirstPosition();
if(wParam == level.defaultPlayer[0].controls.toggleConsole.Retrieve())
{
level.showConsole = false;
}
else
{
while(level.defaultPlayer[0].controls.toggleConsole.NextPosition() && level.showConsole)
{
if(level.defaultPlayer[0].controls.toggleConsole.Retrieve() == wParam)
{
level.showConsole = false;
}
}
}
if(wParam == VK_RETURN)
{
level.UpdateConsole('\n');
}
else if(wParam == VK_SPACE)
{
level.UpdateConsole(' ');
}
else if(wParam == VK_BACK)
{
level.UpdateConsole(VK_BACK);
}
else if(isalpha(uint8(wParam)))
{
level.UpdateConsole(wParam);
}
}
else
{
keys[wParam] = true;
return 0;
}
}
case WM_KEYUP:
{
keys[wParam] = false;
@@ -424,11 +485,14 @@ int WINAPI WinMain( HINSTANCE hInstance,
{
level.defaultPlayer[0].camera.Update();
if(fullscreen)
if(level.showConsole)
{
level.screen.fullscreen = true;
if(keys['I'] && !keys2['I'])
level.showConsole = false;
//level.UpdateConsole('\n');
}
else
{
if (level.mlook)
{
level.defaultPlayer[0].camera.SetViewByMouse(g_Screen);
@@ -662,31 +726,27 @@ int WINAPI WinMain( HINSTANCE hInstance,
//////////
//Toggle Console
//if(!level.defaultPlayer[0].controls.toggleConsole.IsEmpty())
if(keys['I'])
keys['I'] = true;
if(!level.defaultPlayer->controls.toggleConsole.IsEmpty())
if(!level.defaultPlayer[0].controls.toggleConsole.IsEmpty())
{
level.defaultPlayer->controls.toggleConsole.FirstPosition();
if(keys[level.defaultPlayer->controls.toggleConsole.Retrieve()])
level.defaultPlayer[0].controls.toggleConsole.FirstPosition();
if(keys[level.defaultPlayer[0].controls.toggleConsole.Retrieve()])
{
if(!keys2[level.defaultPlayer->controls.toggleConsole.Retrieve()])
if(!keys2[level.defaultPlayer[0].controls.toggleConsole.Retrieve()])
{
level.showConsole = !level.showConsole;
keys2[level.defaultPlayer->controls.toggleConsole.Retrieve()] = true;
keys2[level.defaultPlayer[0].controls.toggleConsole.Retrieve()] = true;
}
}
else
{
while(level.defaultPlayer->controls.toggleConsole.NextPosition() && (keys[level.defaultPlayer->controls.toggleConsole.Retrieve()] != true));
while(level.defaultPlayer[0].controls.toggleConsole.NextPosition() && (keys[level.defaultPlayer[0].controls.toggleConsole.Retrieve()] != true));
{
if(keys[level.defaultPlayer->controls.toggleConsole.Retrieve()])
if(keys[level.defaultPlayer[0].controls.toggleConsole.Retrieve()])
{
if(!keys2[level.defaultPlayer->controls.toggleConsole.Retrieve()])
if(!keys2[level.defaultPlayer[0].controls.toggleConsole.Retrieve()])
{
level.showConsole = !level.showConsole;
keys2[level.defaultPlayer->controls.toggleConsole.Retrieve()] = true;
keys2[level.defaultPlayer[0].controls.toggleConsole.Retrieve()] = true;
}
}
}
@@ -719,9 +779,10 @@ int WINAPI WinMain( HINSTANCE hInstance,
}
}
}
//level.Render();
}
level.Render();
//
}
}

View File

@@ -257,7 +257,7 @@ string word(string str, uint32 wordNum)
{
if(wordNum < 1)
{
while (!isspace(str[++length]) && length <= maxLength);
while (!isspace(str[++length]) && length < maxLength);
return str.substr(start, length);
}