*** empty log message ***

This commit is contained in:
2003-10-15 00:57:23 -04:00
parent 143c82175e
commit 4c6f5dfb15
69 changed files with 8788 additions and 0 deletions

63
src/bmp.cpp Normal file
View File

@@ -0,0 +1,63 @@
////////////////////////////////////////////////////////////////////////////////
//
// Module: bmp.cpp
// Author: Tom Hicks
// Creation: 09-01-2003
// LastEdit: 10-09-2003
// Editors: Tom Hicks
//
// Purpose:
// To implement a wrapper function that will load a 24bit windows bitmap
// file and return a pointer to a TextureImage object containing the image.
//
// Summary of Methods:
// Global
// -LoadBMP
// Loads a 24 bit windows bitmap file specified by fn and returns a
// pointer to a TextureImage object containing the bitmap image.
//
////////////////////////////////////////////////////////////////////////////////
#include "../include/bmp.h"
TextureImage* LoadBMP(const char* fn)
{
//If anything is not perfect return NULL after cleaning up our mess
FILE* f=NULL; //A pointer to our file structure
//If our filename is null
if(!fn)
return NULL;
//Try to open our file and if successfull...
f=fopen(fn, "r");
if(f)
{
//close the file
fclose(f);
//Load our bitmap structure from the file.
AUX_RGBImageRec* bmp = auxDIBImageLoad(fn);
//If the load was successfull.
if(bmp)
{
//Allocate memory for a TextureImage Structure.
TextureImage* tex = new TextureImage;
//Convert the bitmap to a TextureImage.
tex->data = bmp->data;
tex->sizeX = bmp->sizeX;
tex->sizeY = bmp->sizeY;
tex->type = GL_RGB;
tex->bpp = 3;
//Free the bitmap but not it's data and return our TextureImage.
free(bmp);
return tex;
}
}
return NULL;
}

190
src/camera.cpp Normal file
View File

@@ -0,0 +1,190 @@
////////////////////////////////////////////////////////////////////////////////
//
// Module: camera.cpp
// Author: Tom Hicks
// Creation: 09-01-2003
// LastEdit: 10-09-2003
// Editors: Tom Hicks
//
// Purpose:
// To implement an OpenGL Camera
//
// Summary of Methods:
// CameraClass
// -CameraClass();
// Initalize PDM's. Sets position to 0,0,0 up to 0,1,0 and view to 0,0,-1
// -Vec3f Position();
// Returns a copy of the position vector.
// -Vec3f View();
// Returns a copy of the view vector.
// -Vec3f UpVector();
// Returns a copy of the up vector.
// -Vec3f Strafe();
// Returns a copy of the strafe vector.
// -void PositionCamera(double xpos, double ypos, double zpos,
// double xview, double yview, double zview,
// double xup, double yup, double zup);
// Sets the position, up, and view vectors to those created from the respective input values.
// -void PositionCamera(Vec3f pos, Vec3f view, Vec3f up);
// Sets the position, up, and view vectors to those passed in.
// -void RotateView(double angle, double X, double Y, double Z);
// Rotates the view angle degrees on the axis specified by X, Y, and Z.
// -void SetViewByMouse(SCREEN g_Screen);
// Rotates the pitch and yaw of the view based on the mouse.
// -void RotateAroundPoint(double angle, double X, double Y, double Z, Vec3f vCenter);
// Rotates the view angle degrees around a point vCenter on the axis specified by X, Y, Z.
// -void StrafeCamera(double speed);
// Moves the camera along an axis perpendicular to the plane specified by the up and view vectors a distance specified by speed.
// -void MoveCamera(double speed);
// Moves the camera along the axis specified by it's view vector a distance equal to speed.
// -void Update();
// Update the internal strafe vector.
// -void Look();
// Positions the current viewport at point of the camera and facing the same direction.
//
////////////////////////////////////////////////////////////////////////////////
#include "../include/camera.h"
CameraClass::CameraClass()
{
m_vPosition = Vec3f(0,0,0);
m_vView = Vec3f(0,0,-1);
m_vUpVector = Vec3f(0,1,0);
}
void CameraClass::PositionCamera(double xpos, double ypos, double zpos,
double xview, double yview, double zview,
double xup, double yup, double zup)
{
m_vPosition = Vec3f(xpos, ypos, zpos);
m_vView = Vec3f(xview, yview, zview);
m_vUpVector = Vec3f(xup, yup, zup);
}
void CameraClass::PositionCamera(Vec3f pos, Vec3f view, Vec3f up)
{
m_vPosition = pos;
m_vView = view;
m_vUpVector = up;
}
void CameraClass::SetViewByMouse(SCREEN g_Screen)
{
static double currentRotX = 0.0f;
POINT mpos;
POINT middle;
double angleZ;
middle.x = g_Screen.width / 2;
middle.y = g_Screen.height / 2;
GetCursorPos(&mpos);
SetCursorPos(middle.x, middle.y);
if(mpos.x != middle.x || mpos.y != middle.y)
{
angleZ = double(middle.y - mpos.y) / 1000.0f;
currentRotX -= angleZ;
if(currentRotX > 1.0f)
currentRotX = 1.0f;
else if(currentRotX < -1.0f)
currentRotX = -1.0f;
else
{
Vec3f axis = (m_vView - m_vPosition).cross(m_vUpVector);
axis.normalize();
RotateView(angleZ, axis.x, axis.y, axis.z);
//need to switch these two when I figure out stuff for flight
//till then I think the first is faster
RotateView(double(middle.x - mpos.x) / 1000.0f, 0, 1, 0);
//RotateView(double(middle.x - mpos.x) / 1000.0f, m_vUpVector.x, m_vUpVector.y, m_vUpVector.z);
}
}
}
void CameraClass::MoveCamera(double speed)
{
Vec3f heading = (m_vView - m_vPosition).normalized();
m_vPosition.x += heading.x * speed;
m_vPosition.z += heading.z * speed;
m_vView.x += heading.x * speed;
m_vView.z += heading.z * speed;
}
void CameraClass::RotateView(double angle, double x, double y, double z)
{
Vec3f nView;
Vec3f cView;
cView = m_vView - m_vPosition;
double cosTheta = cos(angle);
double sinTheta = sin(angle);
nView.x = (cosTheta + (1 - cosTheta) * x * x) * cView.x +
((1 - cosTheta) * x * y - z * sinTheta) * cView.y +
((1 - cosTheta) * x * z + y * sinTheta) * cView.z;
nView.y = (cosTheta + (1 - cosTheta) * y * y) * cView.y +
((1- cosTheta) * x * y + z * sinTheta) * cView.x +
((1 - cosTheta) * y * z - x * sinTheta) * cView.z;
nView.z = (cosTheta + (1 - cosTheta) * z * z) * cView.z+
((1 - cosTheta) * x * z - y * sinTheta) * cView.x +
((1 - cosTheta) * y * z + x * sinTheta) * cView.y;
m_vView.x = m_vPosition.x + nView.x;
m_vView.y = m_vPosition.y + nView.y;
m_vView.z = m_vPosition.z + nView.z;
}
void CameraClass::StrafeCamera(double speed)
{
m_vPosition.x += m_vStrafe.x * speed;
m_vPosition.z += m_vStrafe.z * speed;
m_vView.x += m_vStrafe.x * speed;
m_vView.z += m_vStrafe.z * speed;
}
void CameraClass::Update()
{
m_vStrafe =((m_vView - m_vPosition).cross(m_vUpVector)).normalized();
//SetViewByMouse(); //TODO take this whole function out asap
}
void CameraClass::Look()
{
gluLookAt(m_vPosition.x, m_vPosition.y, m_vPosition.z,
m_vView.x, m_vView.y, m_vView.z,
m_vUpVector.x, m_vUpVector.y, m_vUpVector.z);
}
Vec3f CameraClass::Position()
{
return m_vPosition;
}
Vec3f CameraClass::Strafe()
{
return m_vStrafe;
}
Vec3f CameraClass::UpVector()
{
return m_vUpVector;
}
Vec3f CameraClass::View()
{
return m_vView;
}

112
src/ctrls.cpp Normal file
View File

@@ -0,0 +1,112 @@
////////////////////////////////////////////////////////////////////////////////
//
// Module: ctrls.cpp
// Author: Tom Hicks
// Creation: 09-01-2003
// LastEdit: 10-09-2003
// Editors: Tom Hicks
//
// Purpose:
// To implement a system for managing a bindable control scheme.
//
// Summary of Methods:
// ControlSchemeClass
// void LoadDefaultControlScheme();
// void ClearControlScheme();
//
// Summary of Properties:
// ControlSchemeClass
// -list<uint8> forward;
// A list of the VKeys associated with forward.
// -list<uint8> backward;
// A list of the VKeys associated with backward.
// -list<uint8> lookLeft;
// A list of the VKeys associated with turning left.
// -list<uint8> lookRight;
// A list of the VKeys associated with turning right.
// -list<uint8> lookUp;
// A list of the VKeys associated with looking up.
// -list<uint8> lookDown;
// A list of the VKeys associated with looking down.
// -list<uint8> moveLeft;
// A list of the VKeys associated with strafing left.
// -list<uint8> moveRight;
// A list of the VKeys associated with strafing right.
// -list<uint8> moveUp;
// A list of the VKeys associated with jumping.
// -list<uint8> moveDown;
// A list of the VKeys associated with crouching.
// -list<uint8> firePrimary;
// A list of the VKeys associated with activating the primary ability of the active item.
// -list<uint8> fireSecondary;
// A list of the VKeys associated with activating the secondary ablilty of the active item.
// -list<uint8> weaponNext;
// A list of the VKeys associated with switching to the next item.
// -list<uint8> weaponPrev;
// A list of the VKeys associated with switching to the previous item.
// -list<uint8> toggleLights;
// A list of the VKeys associated with turning lighting on and off.
// -list<uint8> toggleFPS;
// A list of the VKeys associated with turning the FPS display on and off.
// -list<uint8> toggleConsole;
// A list of the VKeys associated with toggling the display of the console.
// -list<uint8> toggleMouseLook;
// A list of the VKeys associated with toggling mouse look.
// -list<uint8> quickMouseLook;
// A list of the VKeys associated with temporarily switching the mouse look mode.
// -list<uint8> rollLeft;
// A list of the VKeys associated with rolling left.
// -list<uint8> rollRight;
// A list of the VKeys associated with rolling right.
//
////////////////////////////////////////////////////////////////////////////////
#include "../include/ctrls.h"
void ControlSchemeClass::LoadDefaultControlScheme()
{
forward.Insert(VK_LBUTTON);
backward.Insert(VK_RBUTTON);
lookLeft.Insert(VK_LEFT);
lookRight.Insert(VK_RIGHT);
lookUp.Insert(VK_UP);
lookDown.Insert(VK_DOWN);
moveLeft.Insert('S');
moveRight.Insert('D');
moveUp.Insert(VK_SPACE);
moveDown.Insert('A');
firePrimary.Insert('F');
fireSecondary.Insert('G');
weaponNext.Insert('T');
weaponPrev.Insert('R');
toggleLights.Insert('L');
toggleFPS.Insert('P');
toggleConsole.Insert('~');
toggleMouseLook.Insert('M');
quickMouseLook.Insert('Q');
rollLeft.Insert('W');
rollRight.Insert('E');
}
void ControlSchemeClass::ClearControlScheme()
{
backward.Clear();
firePrimary.Clear();
fireSecondary.Clear();
forward.Clear();
lookDown.Clear();
lookUp.Clear();
lookRight.Clear();
lookLeft.Clear();
moveDown.Clear();
moveUp.Clear();
moveLeft.Clear();
moveRight.Clear();
quickMouseLook.Clear();
toggleConsole.Clear();
toggleFPS.Clear();
toggleLights.Clear();
toggleMouseLook.Clear();
weaponNext.Clear();
weaponPrev.Clear();
}

951
src/level.cpp Normal file
View File

@@ -0,0 +1,951 @@
////////////////////////////////////////////////////////////////////////////////
//
// Module: level.cpp
// Author: Tom Hicks
// Creation: 09-01-2003
// LastEdit: 10-09-2003
// Editors: Tom Hicks
//
// Purpose:
// To implement the world or at least a reasonable copy.
//
// Summary of Methods:
// Global
// -function name
// description
// blahClass
// -function name
// description
//
// Summary of Properties:
// blahClass
// -property name
// description
//
////////////////////////////////////////////////////////////////////////////////
#include "../include/level.h"
#pragma comment(lib, "bass.lib")
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;
screen.name = "OpenArena";
showFPS = false;
showConsole = false;
nextLevel = "intro.map";
gamedir = "oa/";
sound = true;
defaultPlayer = new PLAYER;
numTriangles = 0;
triangles = NULL;
/*
for(int x=0; x<4; x++)
LightAmbient[x] = 5;
*/
//Player Stuff
mouseSpeed = 5;
turnSpeed = 1.0f;
moveSpeed = .2f;
mlook = true;
}
LEVEL::~LEVEL()
{
if(defaultPlayer)
{
try
{
delete defaultPlayer;
}
catch(...)
{
}
defaultPlayer = NULL;
}
}
bool LEVEL::LoadMap(string mapname)
{
ifstream input;
string readBuffer;
//players.Insert(*defaultPlayer);
mapname = gamedir + "maps/" + mapname;
if(tolower(Right(mapname, 4)) != ".map")
mapname = mapname + ".map";
input.open(mapname.c_str());
if(!input)
{
char* tmpChar = new char[mapname.length() + 41];
strcpy(tmpChar, "Unable to load level file ");
strcat(tmpChar, mapname.c_str());
strcat(tmpChar, " doesn't exist.");
MessageBox(NULL,tmpChar,"ERROR",MB_OK|MB_ICONEXCLAMATION);
delete [] tmpChar;
return false;
}
//Gravity
input >> readBuffer;
gravity = (float)atof(readBuffer.c_str());
//Number of triangles
input >> readBuffer;
numTriangles = Integer(readBuffer);
//Triangle Data
triangles = new TRIANGLE[numTriangles];
for(unsigned int i=0; i<numTriangles; i++)
{
//TextureID
input >> readBuffer;
triangles[i].texID = Integer(readBuffer);
for(unsigned int i2=0; i2<3; i2++)
{
//Vertex Data
input >> readBuffer;
triangles[i].vertecies[i2].x = atof(readBuffer.c_str());
input >> readBuffer;
triangles[i].vertecies[i2].y = atof(readBuffer.c_str());
input >> readBuffer;
triangles[i].vertecies[i2].z = atof(readBuffer.c_str());
input >> readBuffer;
triangles[i].texCoords[i2].x = (float)atof(readBuffer.c_str());
input >> readBuffer;
triangles[i].texCoords[i2].y = (float)atof(readBuffer.c_str());
}
//Normal
input >> readBuffer;
triangles[i].normal.x = atof(readBuffer.c_str());
input >> readBuffer;
triangles[i].normal.y = atof(readBuffer.c_str());
input >> readBuffer;
triangles[i].normal.z = atof(readBuffer.c_str());
}
//Number of textures;
input >> readBuffer;
numTextures = Integer(readBuffer);
//Texture data
textureNames = new string[numTextures];
for(unsigned int i=0; i<numTextures; i++)
{
input >> textureNames[i];
}
//BGM
input >> bgm;
//LoadGLTextures();
//Build display list
if (sound)
{
BASS_Init(-1, 44100, BASS_DEVICE_LEAVEVOL, g_hWnd);
BASS_Start();
BASS_CDInit(NULL, BASS_DEVICE_LEAVEVOL);
if(bgm.length()>=4)
{
if( toupper(bgm[0]) == 'C' &&
toupper(bgm[1]) == 'D' &&
toupper(bgm[2]) == 'A')
{
bgmCDA = Integer(bgm.substr(3,bgm.length()));
BASS_CDPlay(bgmCDA, 1, 0);
}
else
{
bgmCDA=0;
string tmpstr = gamedir + "music/bgm/" + bgm;
bgmStream = BASS_StreamCreateFile(0, (void*)tmpstr.c_str(), 0, 0, BASS_STREAM_AUTOFREE);
BASS_StreamPlay(bgmStream, 1, BASS_SAMPLE_LOOP);
}
}
}
return true;
}
void LEVEL::LoadMap()
{
LoadMap(nextLevel);
}
void LEVEL::SaveMap(string mapname)
{
ofstream output;
mapname = gamedir + "maps/" + mapname;
if(tolower(Right(mapname, 4)) != ".map")
mapname = mapname + ".map";
output.open(mapname.c_str());
if(!output)
{
char* tmpChar = new char[mapname.length() + 42];
strcpy(tmpChar, "Unable to save level file ");
strcat(tmpChar, mapname.c_str());
strcat(tmpChar, " already exists.");
MessageBox(NULL,tmpChar,"ERROR",MB_OK|MB_ICONEXCLAMATION);
delete [] tmpChar;
return;
}
//Gravity
output << gravity << endl;
//Number of triangles
output << numTriangles << endl;
//Triangle Data
for(unsigned int i=0; i<numTriangles; i++)
{
output << triangles[i].texID << endl;
for(unsigned int i2=0; i2<3; i2++)
{
output << triangles[i].vertecies[i2].x << " "
<< triangles[i].vertecies[i2].y << " "
<< triangles[i].vertecies[i2].z << " "
<< triangles[i].texCoords[i2].x << " "
<< triangles[i].texCoords[i2].y << endl;
}
output << triangles[i].normal.x << " "
<< triangles[i].normal.y << " "
<< triangles[i].normal.z << endl;
}
//Number of textures;
output << numTextures;
//Texture data
for(unsigned int i=0; i<numTextures; i++)
{
output << textureNames[i];
}
//BGM
output << bgm;
}
void LEVEL::Render()
{
glPushMatrix();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
// Move the camera to where the player is or more precisely move to world so the camer is where the playe is
defaultPlayer->camera.Look();
///*
for (uint32 i=0; i<numTriangles; i++)
{
glBindTexture(GL_TEXTURE_2D, textures[triangles[i].texID].ID());//Bind this triangle's texture
glBegin(GL_TRIANGLES);
// glNormal3f((GLfloat)triangles[i].normal.x, (GLfloat)triangles[i].normal.y, (GLfloat)triangles[i].normal.z);
for (uint32 i2=0; i2<3; i2++)
{
glTexCoord2f(triangles[i].texCoords[i2].x,
triangles[i].texCoords[i2].y);
glVertex3f((GLfloat)triangles[i].vertecies[i2].x,
(GLfloat)triangles[i].vertecies[i2].y,
(GLfloat)triangles[i].vertecies[i2].z);
}
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
//ummm nothing here yet
//Draw FPS
//This may not work yet
if (showFPS)
{
char fps[20];
sprintf(fps, "fps %d", FPS());
glPushMatrix();
glLoadIdentity();
glColor3f(1,1,1);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glFont.Print(glFont.ScreenWidth() - 120, glFont.ScreenHeight() - 30, fps, 0);
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glPopMatrix();
}
if(showConsole)
{
glPushMatrix();
glLoadIdentity();
glColor3f(1,1,1);
//disable lighting and depth testing
glDisable(GL_DEPTH_TEST);
glBindTexture(GL_TEXTURE_2D, menuTextures[GL_MY_TEXTURE_CONSOLEBACKGROUND].ID());
//glBindTexture(GL_TEXTURE_2D, 4);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, screen.width, 0, screen.height, -1, 1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2i(0,screen.height/2);
glTexCoord2f(0,1);
glVertex2i(0,screen.height);
glTexCoord2f(1,1);
glVertex2i(screen.width,screen.height);
glTexCoord2f(1,0);
glVertex2i(screen.width,screen.height/2);
glEnd();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glDisable(GL_LIGHTING);
//enable blending
glEnable(GL_BLEND);
//render the console background
for(unsigned int i=0; i<MAX_CONSOLE_LINES; i++)
{
Print(30, glFont.ScreenHeight() - i*20, consoleHistory[MAX_CONSOLE_LINES-i-1].c_str(), 0);
}
//disable blending
glDisable(GL_BLEND);
//re-enable lighting and depth testing
//glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
}
}
void LEVEL::UnloadMap()
{
//Stop audio
BASS_StreamFree(bgmStream);
BASS_Stop();
BASS_CDFree();
BASS_Free();
//Delete display list
if(triangles)
{
try
{
delete [] triangles;
}
catch(...)
{
}
}
if (textureNames)
{
try
{
delete [] textureNames;
}
catch(...)
{
}
}
}
void LEVEL::LoadGLTextures()
{
/*GLfloat light[4] = {1.0f,1.0f,1.0f,0.5f};
glLightfv(GL_LIGHT1, GL_AMBIENT, light);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHTING);*/
textures = new GL_MY_TEXTURE[numTextures];
for(uint32 i=0; i<numTextures; i++)
{
if(!textures[i].Load(gamedir + "textures/" + textureNames[i]))
textures[i].Load(DEFAULT_TEXTURE_NAME);
}
if(!glFont.BuildFont((gamedir + "textures/menu/font.bmp").c_str()))
glFont.BuildFont("oa/textures/menu/font.bmp");
//Load the console background image
if(!menuTextures[GL_MY_TEXTURE_CONSOLEBACKGROUND].Load(gamedir + "textures/menu/con_back.tga"))
menuTextures[GL_MY_TEXTURE_CONSOLEBACKGROUND].Load("oa/textures/menu/con_back.bmp");
}
uint32 LEVEL::FPS()
{
static uint32 fps=0;
static uint32 fps2=0;
static float last=0.0f; // might need to change to double
float time=GetTickCount()*.001f;
++fps;
if(time>last+1)
{
last=time;
fps2 = fps;
fps=0;
}
return fps2;
}
void LEVEL::Execute(string cmd)
{
string command;
uint32 i=0xFFFFFFFF;
while(word(cmd, ++i) != "")
{
command = word(cmd, i);
if(command == "set")
{
command = tolower(word(cmd, ++i));
if(command == "turnspeed")
{
turnSpeed = (float)atof(word(cmd, ++i).c_str());//Floating(word(cmd, ++i));
}
else if(command == "mousespeed")
{
mouseSpeed = (float)atof(word(cmd, ++i).c_str());
}
else if(command == "maxfps")
{
maxFPS = Integer(word(cmd, ++i));
}
else if(command == "sound")
{
sound = Truth(word(cmd, ++i));
}
else if(command == "game")
{
gamedir= word(cmd, ++i);
}
else if(command == "screenwidth")
{
screen.width = Integer(word(cmd, ++i));
}
else if(command == "screenheight")
{
screen.height = Integer(word(cmd, ++i));
}
else if(command == "fullscreen")
{
screen.fullscreen = Truth(word(cmd, ++i));
}
}
else if(command == "bind")
{
command = tolower(word(cmd, ++i));
if(command == "forward")
{
defaultPlayer->controls.forward.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "backward")
{
defaultPlayer->controls.backward.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "lookleft")
{
defaultPlayer->controls.lookLeft.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "lookright")
{
defaultPlayer->controls.lookRight.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "lookup")
{
defaultPlayer->controls.lookUp.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "lookdown")
{
defaultPlayer->controls.lookDown.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "moveup")
{
defaultPlayer->controls.moveUp.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "movedown")
{
defaultPlayer->controls.moveDown.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "moveleft")
{
defaultPlayer[0].controls.moveLeft.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "moveright")
{
defaultPlayer[0].controls.moveRight.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "fireprimary")
{
defaultPlayer->controls.firePrimary.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "firesecondary")
{
defaultPlayer->controls.fireSecondary.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "weapnext")
{
defaultPlayer->controls.weaponNext.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "weapprev")
{
defaultPlayer->controls.weaponPrev.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "togglelights" || command == "togglelighting")
{
defaultPlayer->controls.toggleLights.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "togglefps")
{
defaultPlayer->controls.toggleFPS.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "toggleconsole")
{
defaultPlayer->controls.toggleConsole.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "togglemouselook")
{
defaultPlayer->controls.toggleMouseLook.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "quickmouselook")
{
defaultPlayer->controls.quickMouseLook.Insert(KeyName(word(cmd, ++i)));
}
}
else if(command == "map")
{
nextLevel = word(cmd, ++i);
}
}
}
void LEVEL::ParseCmds(LPSTR lpCmdLine)
{
string cmd = lpCmdLine;
string command;
uint32 i=0xFFFFFFFF;
while(word(cmd, ++i) != "")
{
command = word(cmd, i);
if(command == "+set")
{
command = tolower(word(cmd, ++i));
if(command == "turnspeed")
{
turnSpeed = (float)atof(word(cmd, ++i).c_str());
}
else if(command == "mousespeed")
{
mouseSpeed = (float)atof(word(cmd, ++i).c_str());
}
else if(command == "maxfps")
{
maxFPS = Integer(word(cmd, ++i));
}
else if(command == "sound")
{
sound = Truth(word(cmd, ++i));
}
else if(command == "game")
{
gamedir= word(cmd, ++i);
}
}
else if(command == "+bind")
{
command = tolower(word(cmd, ++i));
if(command == "forward")
{
defaultPlayer->controls.forward.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "backward")
{
defaultPlayer->controls.backward.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "lookleft")
{
defaultPlayer->controls.lookLeft.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "lookright")
{
defaultPlayer->controls.lookRight.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "lookup")
{
defaultPlayer->controls.lookUp.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "lookdown")
{
defaultPlayer->controls.lookDown.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "moveup")
{
defaultPlayer->controls.moveUp.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "movedown")
{
defaultPlayer->controls.moveDown.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "fireprimary")
{
defaultPlayer->controls.firePrimary.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "firesecondary")
{
defaultPlayer->controls.fireSecondary.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "weapnext")
{
defaultPlayer->controls.weaponNext.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "weapprev")
{
defaultPlayer->controls.weaponPrev.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "togglelights" || command == "togglelighting")
{
defaultPlayer->controls.toggleLights.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "togglefps")
{
defaultPlayer->controls.toggleFPS.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "toggleconsole")
{
defaultPlayer->controls.toggleConsole.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "togglemouselook")
{
defaultPlayer->controls.toggleMouseLook.Insert(KeyName(word(cmd, ++i)));
}
else if(command == "quickmouselook")
{
defaultPlayer->controls.quickMouseLook.Insert(KeyName(word(cmd, ++i)));
}
}
else if(command == "+map")
{
nextLevel = word(cmd, ++i);
}
}
}
void LEVEL::LoadConfig()
{
showFPS = false;
nextLevel = "intro.map";
gamedir = "oa/";
sound = true;
mouseSpeed = 5;
turnSpeed = 1.0f;
moveSpeed = .2f;
mlook = true;
}
bool LEVEL::LoadConfig(string cfgname)
{
ifstream input;
string readBuffer;
cfgname = gamedir + "config/" + cfgname;
if(tolower(Right(cfgname, 4)) !=".cfg")
cfgname = cfgname + ".cfg";
input.open(cfgname.c_str());
if(!input)
return false;
getline(input, readBuffer);
while(input)
{
uint32 i=0xFFFFFFFF;
if(readBuffer[0] == '/' && readBuffer[1] == '/')
{
getline(input, readBuffer);
}
Execute(readBuffer);
getline(input, readBuffer);
}
return true;
}
void LEVEL::SaveConfig(string cfgname)
{
ofstream output;
cfgname = gamedir + "config/" + cfgname;
if(tolower(Right(cfgname, 4)) !=".cfg")
cfgname = cfgname + ".cfg";
output.open(cfgname.c_str());
if(!output)
return;
//Client Config
output << "set turnspeed " << turnSpeed << endl;
output << "set mousespeed " << mouseSpeed << endl;
output << "set mouselook " << mlook << endl;
output << "set screenwidth " << screen.width << endl;
output << "set screenheight " << screen.height << endl;
output << "set colordepth " << screen.bpp << endl;
output << "set maxfps " << maxFPS << endl;
//Control Scheme
//output << " bind " << action << keyname << endl;
if(!defaultPlayer->controls.backward.IsEmpty())
{
defaultPlayer->controls.backward.FirstPosition();
output << "bind backward " << string(KeyString(defaultPlayer->controls.backward.Retrieve())) << endl;
while(defaultPlayer->controls.backward.NextPosition())
output << "bind backward " << KeyString(defaultPlayer->controls.backward.Retrieve()) << endl;
}
if(!defaultPlayer->controls.firePrimary.IsEmpty())
{
defaultPlayer->controls.firePrimary.FirstPosition();
output << "bind firePrimary " << KeyString(defaultPlayer->controls.firePrimary.Retrieve()) << endl;
while(defaultPlayer->controls.firePrimary.NextPosition())
output << "bind firePrimary " << KeyString(defaultPlayer->controls.firePrimary.Retrieve()) << endl;
}
if(!defaultPlayer->controls.fireSecondary.IsEmpty())
{
defaultPlayer->controls.fireSecondary.FirstPosition();
output << "bind fireSecondary " << KeyString(defaultPlayer->controls.fireSecondary.Retrieve()) << endl;
while(defaultPlayer->controls.fireSecondary.NextPosition())
output << "bind fireSecondary " << KeyString(defaultPlayer->controls.fireSecondary.Retrieve()) << endl;
}
if(!defaultPlayer->controls.forward.IsEmpty())
{
defaultPlayer->controls.forward.FirstPosition();
output << "bind forward " << KeyString(defaultPlayer->controls.forward.Retrieve()) << endl;
while(defaultPlayer->controls.forward.NextPosition())
output << "bind forward " << KeyString(defaultPlayer->controls.forward.Retrieve()) << endl;
}
if(!defaultPlayer->controls.lookDown.IsEmpty())
{
defaultPlayer->controls.lookDown.FirstPosition();
output << "bind lookDown " << KeyString(defaultPlayer->controls.lookDown.Retrieve()) << endl;
while(defaultPlayer->controls.lookDown.NextPosition())
output << "bind lookDown " << KeyString(defaultPlayer->controls.lookDown.Retrieve()) << endl;
}
if(!defaultPlayer->controls.lookLeft.IsEmpty())
{
defaultPlayer->controls.lookLeft.FirstPosition();
output << "bind lookLeft " << KeyString(defaultPlayer->controls.lookLeft.Retrieve()) << endl;
while(defaultPlayer->controls.lookLeft.NextPosition())
output << "bind lookLeft " << KeyString(defaultPlayer->controls.lookLeft.Retrieve()) << endl;
}
if(!defaultPlayer->controls.lookRight.IsEmpty())
{
defaultPlayer->controls.lookRight.FirstPosition();
output << "bind lookRight " << KeyString(defaultPlayer->controls.lookRight.Retrieve()) << endl;
while(defaultPlayer->controls.lookRight.NextPosition())
output << "bind lookRight " << KeyString(defaultPlayer->controls.lookRight.Retrieve()) << endl;
}
if(!defaultPlayer->controls.lookUp.IsEmpty())
{
defaultPlayer->controls.lookUp.FirstPosition();
output << "bind lookUp " << KeyString(defaultPlayer->controls.lookUp.Retrieve()) << endl;
while(defaultPlayer->controls.lookUp.NextPosition())
output << "bind lookUp " << KeyString(defaultPlayer->controls.lookUp.Retrieve()) << endl;
}
if(!defaultPlayer->controls.moveDown.IsEmpty())
{
defaultPlayer->controls.moveDown.FirstPosition();
output << "bind moveDown " << KeyString(defaultPlayer->controls.moveDown.Retrieve()) << endl;
while(defaultPlayer->controls.moveDown.NextPosition())
output << "bind moveDown " << KeyString(defaultPlayer->controls.moveDown.Retrieve()) << endl;
}
if(!defaultPlayer->controls.moveLeft.IsEmpty())
{
defaultPlayer->controls.moveLeft.FirstPosition();
output << "bind moveLeft " << KeyString(defaultPlayer->controls.moveLeft.Retrieve()) << endl;
while(defaultPlayer->controls.moveLeft.NextPosition())
output << "bind moveLeft " << KeyString(defaultPlayer->controls.moveLeft.Retrieve()) << endl;
}
if(!defaultPlayer->controls.moveRight.IsEmpty())
{
defaultPlayer->controls.moveRight.FirstPosition();
output << "bind moveRight " << KeyString(defaultPlayer->controls.moveRight.Retrieve()) << endl;
while(defaultPlayer->controls.moveRight.NextPosition())
output << "bind moveRight " << KeyString(defaultPlayer->controls.moveRight.Retrieve()) << endl;
}
if(!defaultPlayer->controls.moveUp.IsEmpty())
{
defaultPlayer->controls.moveUp.FirstPosition();
output << "bind moveUp " << KeyString(defaultPlayer->controls.moveUp.Retrieve()) << endl;
while(defaultPlayer->controls.moveUp.NextPosition())
output << "bind moveUp " << KeyString(defaultPlayer->controls.moveUp.Retrieve()) << endl;
}
if(!defaultPlayer->controls.quickMouseLook.IsEmpty())
{
defaultPlayer->controls.quickMouseLook.FirstPosition();
output << "bind quickMouseLook " << KeyString(defaultPlayer->controls.quickMouseLook.Retrieve()) << endl;
while(defaultPlayer->controls.quickMouseLook.NextPosition())
output << "bind quickMouseLook " << KeyString(defaultPlayer->controls.quickMouseLook.Retrieve()) << endl;
}
if(!defaultPlayer->controls.rollLeft.IsEmpty())
{
defaultPlayer->controls.rollLeft.FirstPosition();
output << "bind rollLeft " << KeyString(defaultPlayer->controls.rollLeft.Retrieve()) << endl;
while(defaultPlayer->controls.rollLeft.NextPosition())
output << "bind rollLeft " << KeyString(defaultPlayer->controls.rollLeft.Retrieve()) << endl;
}
if(!defaultPlayer->controls.rollRight.IsEmpty())
{
defaultPlayer->controls.rollRight.FirstPosition();
output << "bind rollRight " << KeyString(defaultPlayer->controls.rollRight.Retrieve()) << endl;
while(defaultPlayer->controls.rollRight.NextPosition())
output << "bind rollRight " << KeyString(defaultPlayer->controls.rollRight.Retrieve()) << endl;
}
if(!defaultPlayer->controls.toggleConsole.IsEmpty())
{
defaultPlayer->controls.toggleConsole.FirstPosition();
output << "bind toggleConsole " << KeyString(defaultPlayer->controls.toggleConsole.Retrieve()) << endl;
while(defaultPlayer->controls.toggleConsole.NextPosition())
output << "bind toggleConsole " << KeyString(defaultPlayer->controls.toggleConsole.Retrieve()) << endl;
}
if(!defaultPlayer->controls.toggleFPS.IsEmpty())
{
defaultPlayer->controls.toggleFPS.FirstPosition();
output << "bind toggleFPS " << KeyString(defaultPlayer->controls.toggleFPS.Retrieve()) << endl;
while(defaultPlayer->controls.toggleFPS.NextPosition())
output << "bind toggleFPS " << KeyString(defaultPlayer->controls.toggleFPS.Retrieve()) << endl;
}
if(!defaultPlayer->controls.toggleLights.IsEmpty())
{
defaultPlayer->controls.toggleLights.FirstPosition();
output << "bind toggleLights " << KeyString(defaultPlayer->controls.toggleLights.Retrieve()) << endl;
while(defaultPlayer->controls.toggleLights.NextPosition())
output << "bind toggleLights " << KeyString(defaultPlayer->controls.toggleLights.Retrieve()) << endl;
}
if(!defaultPlayer->controls.toggleMouseLook.IsEmpty())
{
defaultPlayer->controls.toggleMouseLook.FirstPosition();
output << "bind toggleMouseLook " << KeyString(defaultPlayer->controls.toggleMouseLook.Retrieve()) << endl;
while(defaultPlayer->controls.toggleMouseLook.NextPosition())
output << "bind toggleMouseLook " << KeyString(defaultPlayer->controls.toggleMouseLook.Retrieve()) << endl;
}
if(!defaultPlayer->controls.weaponNext.IsEmpty())
{
defaultPlayer->controls.weaponNext.FirstPosition();
output << "bind weaponNext " << KeyString(defaultPlayer->controls.weaponNext.Retrieve()) << endl;
while(defaultPlayer->controls.weaponNext.NextPosition())
output << "bind weaponNext " << KeyString(defaultPlayer->controls.weaponNext.Retrieve()) << endl;
}
if(!defaultPlayer->controls.weaponPrev.IsEmpty())
{
defaultPlayer->controls.weaponPrev.FirstPosition();
output << "bind weaponPrev " << KeyString(defaultPlayer->controls.weaponPrev.Retrieve()) << endl;
while(defaultPlayer->controls.weaponPrev.NextPosition())
output << "bind weaponPrev " << KeyString(defaultPlayer->controls.weaponPrev.Retrieve()) << endl;
}
}
void LEVEL::Print(int x, int y, const char* str, unsigned int set)
{
glFont.Print(x,y,str, set);
}

746
src/main.cpp Normal file
View File

@@ -0,0 +1,746 @@
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Author: Tom Hicks
// Module: main.cpp
// Purpose: This is an implementation of the openarena SDK.
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
//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")
#ifndef CDS_FULLSCREEN
#define CDS_FULLSCREEN 4
#endif
using namespace std;
void InitControls();
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Function Definitions
//
//void InitControls()
// Purpose:
// Initializes controls by loading the default control config file "my.cfg".
void InitControls()
{
if (!level.LoadConfig("my.cfg"))
level.LoadConfig();
}
//
// int InitGL(GLvoid)
// Purpose:
// To do all required setup before creating an OpenGL window
// Pre:
//
// Post:
//
int InitGL(GLvoid)
{
level.LoadGLTextures();
glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
/*lighting disabled temporarily
glLightfv(GL_LIGHT1, GL_AMBIENT, level.LightAmbient);
for(index=0; index<level.numLights; index++)
{
glLightfv(GL_LIGHT1, GL_DIFFUSE, level.light[index].color);
glLightfv(GL_LIGHT1, GL_POSITION, level.light[index].coords);
}
glEnable(GL_LIGHT1);
glEnable(GL_LIGHTING);
*/
//BuildFont();
return true;
}
//
// GLvoid ReSizeGLScene(GLsizei width, GLsizei height)
// Purpose:
// To resize the OpenGL window also called on creation
// Pre:
//
// Post:
//
GLvoid ReSizeGLScene(GLsizei width, GLsizei height)
{
if (height==0)
height=1;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
GLvoid KillGLWindow(GLvoid)
{
if (g_Screen.fullscreen)
{
ChangeDisplaySettings(NULL, 0);
ShowCursor(true/*false*/);
}
if (hRC)
{
if (!wglMakeCurrent(NULL, NULL))
MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
if (!wglDeleteContext(hRC))
MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hRC=NULL;
}
if (hDC && !ReleaseDC(g_hWnd, hDC))
{
MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hDC=NULL;
}
if (g_hWnd && !DestroyWindow(g_hWnd))
{
MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
g_hWnd=NULL;
}
if (!UnregisterClass("OpenArena v0.1.0", hInstance))
{
MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hInstance=NULL;
}
}
bool CreateGLWindow(string title, int width, int height, int bits, bool fullscreenflag)
{
unsigned int PixelFormat;
WNDCLASS wc;
DWORD dwExStyle;
DWORD dwStyle;
RECT WindowRect;
WindowRect.left=(long)0;
WindowRect.right=(long)width;
WindowRect.top=(long)0;
WindowRect.bottom=(long)height;
g_Screen.fullscreen = fullscreenflag;
g_Screen.width = width;
g_Screen.height = height;
g_Screen.bpp = bits;
g_Screen.name = title;
hInstance = GetModuleHandle(NULL);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = "OpenArena v0.1.0";
if (!RegisterClass(&wc))
{
MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false;
}
if (g_Screen.fullscreen)
{
DEVMODE dmScreenSettings;
memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
dmScreenSettings.dmSize = sizeof(dmScreenSettings);
dmScreenSettings.dmPelsWidth = width;
dmScreenSettings.dmPelsHeight = height;
dmScreenSettings.dmBitsPerPel = bits;
dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
{
if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","OpenArena",MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
g_Screen.fullscreen = false;
else
{
MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_ICONSTOP);
return false;
}
}
}
if (g_Screen.fullscreen)
{
dwExStyle = WS_EX_APPWINDOW;
dwStyle = WS_POPUP;
ShowCursor(/*true*/false);
}
else
{
ShowCursor(false);
dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
dwStyle = WS_OVERLAPPEDWINDOW;
}
AdjustWindowRectEx(&WindowRect, dwStyle, false, dwExStyle);
if (!(g_hWnd = CreateWindowEx(dwExStyle, "OpenArena v0.1.0", title.c_str(), WS_CLIPSIBLINGS | WS_CLIPCHILDREN | dwStyle, 0, 0, WindowRect.right-WindowRect.left, WindowRect.bottom-WindowRect.top, NULL, NULL, hInstance, NULL)))
{
KillGLWindow();
MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false;
}
static PIXELFORMATDESCRIPTOR pfd={sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, bits, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 };
if (!(hDC=GetDC(g_hWnd)))
{
KillGLWindow();
MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false;
}
if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd)))
{
KillGLWindow();
MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false;
}
if(!SetPixelFormat(hDC,PixelFormat,&pfd))
{
KillGLWindow();
MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false;
}
if (!(hRC=wglCreateContext(hDC)))
{
KillGLWindow();
MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false;
}
if(!wglMakeCurrent(hDC,hRC))
{
KillGLWindow();
MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false;
}
ShowWindow(g_hWnd,SW_SHOW);
SetForegroundWindow(g_hWnd);
SetFocus(g_hWnd);
ReSizeGLScene(width, height);
if (!InitGL())
{
KillGLWindow();
MessageBox(NULL,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false;
}
return true;
}
LRESULT CALLBACK WndProc( HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
switch (uMsg)
{
case WM_ACTIVATE:
{
if (!HIWORD(wParam))
{
active=true;
}
else
{
active=false;
}
return 0;
}
case WM_SYSCOMMAND:
{
switch (wParam)
{
case SC_SCREENSAVE:
case SC_MONITORPOWER:
return 0;
}
break;
}
case WM_CLOSE:
{
PostQuitMessage(0);
return 0;
}
case WM_KEYDOWN:
{
keys[wParam] = true;
return 0;
}
case WM_KEYUP:
{
keys[wParam] = false;
keys2[wParam] = false;
return 0;
}
case WM_SIZE:
{
ReSizeGLScene(LOWORD(lParam),HIWORD(lParam));
return 0;
}
case WM_LBUTTONDOWN:
{
keys[VK_LBUTTON] = true;
return 0;
}
case WM_LBUTTONUP:
{
keys[VK_LBUTTON] = false;
keys[VK_LBUTTON] = false;
return 0;
}
case WM_RBUTTONDOWN:
{
keys[VK_RBUTTON] = true;
return 0;
}
case WM_RBUTTONUP:
{
keys[VK_RBUTTON] = false;
keys[VK_RBUTTON] = false;
return 0;
}
case WM_MBUTTONDOWN:
{
keys[VK_MBUTTON] = true;
return 0;
}
case WM_MBUTTONUP:
{
keys[VK_MBUTTON] = false;
keys[VK_MBUTTON] = false;
return 0;
}
}
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
bool done=false;
if (strlen(lpCmdLine))
level.ParseCmds(lpCmdLine);
InitControls();
g_Screen.name = "OpenArena v0.1.0";
g_Screen.width = level.screen.width;
g_Screen.height = level.screen.height;
g_Screen.bpp = level.screen.bpp;
g_Screen.fullscreen = level.screen.fullscreen;
level.glFont.SetScreenDimensions(g_Screen.width*2, g_Screen.height*2);
//level.glFont.BuildFont("oa\\textures\\menu\\font.bmp");//(level.gamedir + "\\textures\\menu\\font.bmp").c_str());
if (level.nextLevel != "")
level.LoadMap();
else
level.LoadMap("intro.map");
if (!CreateGLWindow(g_Screen.name, g_Screen.width, g_Screen.height, g_Screen.bpp, g_Screen.fullscreen))
{
return 0;
}
while(!done)
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if (msg.message==WM_QUIT)
{
done=true;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else
{
if (active)
{
if (keys[VK_ESCAPE])
{
done=true;
}
else
{
level.defaultPlayer[0].camera.Update();
if(fullscreen)
{
level.screen.fullscreen = true;
}
if (level.mlook)
{
level.defaultPlayer[0].camera.SetViewByMouse(g_Screen);
}
else
{
SetCursorPos(g_Screen.width/2, g_Screen.height/2);
}
//////////
//Move Backward
if(!level.defaultPlayer->controls.backward.IsEmpty())
{
level.defaultPlayer->controls.backward.FirstPosition();
if(keys[level.defaultPlayer->controls.backward.Retrieve()])
{
level.defaultPlayer->camera.MoveCamera(-level.moveSpeed);
}
else
{
while(level.defaultPlayer->controls.backward.NextPosition() && (keys[level.defaultPlayer->controls.backward.Retrieve()] != true));
{
if(keys[level.defaultPlayer->controls.backward.Retrieve()])
{
level.defaultPlayer->camera.MoveCamera(-level.moveSpeed);
}
}
}
}
//////////
//Move forward
if(!level.defaultPlayer->controls.forward.IsEmpty())
{
level.defaultPlayer->controls.forward.FirstPosition();
if(keys[level.defaultPlayer->controls.forward.Retrieve()])
{
level.defaultPlayer->camera.MoveCamera(level.moveSpeed);
}
else
{
while(level.defaultPlayer->controls.forward.NextPosition() && (keys[level.defaultPlayer->controls.forward.Retrieve()] != true));
{
if(keys[level.defaultPlayer->controls.forward.Retrieve()])
{
level.defaultPlayer->camera.MoveCamera(level.moveSpeed);
}
}
}
}
//////////
//Strafe Left
if(!level.defaultPlayer->controls.moveLeft.IsEmpty())
{
level.defaultPlayer->controls.moveLeft.FirstPosition();
if(keys[level.defaultPlayer->controls.moveLeft.Retrieve()])
{
level.defaultPlayer->camera.StrafeCamera(-level.moveSpeed);
}
else
{
while(level.defaultPlayer->controls.moveLeft.NextPosition() && (keys[level.defaultPlayer->controls.moveLeft.Retrieve()] != true));
{
if(keys[level.defaultPlayer->controls.moveLeft.Retrieve()])
{
level.defaultPlayer->camera.StrafeCamera(-level.moveSpeed);
}
}
}
}
//////////
//Strafe Right
if(!level.defaultPlayer->controls.moveRight.IsEmpty())
{
level.defaultPlayer->controls.moveRight.FirstPosition();
if(keys[level.defaultPlayer->controls.moveRight.Retrieve()])
{
level.defaultPlayer[0].camera.StrafeCamera(level.moveSpeed);
}
else
{
while(level.defaultPlayer->controls.moveRight.NextPosition() && (keys[level.defaultPlayer->controls.moveRight.Retrieve()] != true));
{
if(keys[level.defaultPlayer->controls.moveRight.Retrieve()])
{
level.defaultPlayer->camera.StrafeCamera(level.moveSpeed);
}
}
}
}
//////////
//Keyboard Look Left
if(!level.defaultPlayer->controls.lookLeft.IsEmpty())
{
level.defaultPlayer->controls.lookLeft.FirstPosition();
if(keys[level.defaultPlayer->controls.lookLeft.Retrieve()])
{
level.defaultPlayer[0].camera.RotateView(level.turnSpeed, 0, 1, 0);
}
else
{
while(level.defaultPlayer->controls.lookLeft.NextPosition() && (keys[level.defaultPlayer->controls.lookLeft.Retrieve()] != true));
{
if(keys[level.defaultPlayer->controls.lookLeft.Retrieve()])
{
level.defaultPlayer[0].camera.RotateView(level.turnSpeed, 0, 1, 0);
}
}
}
}
//////////
//Keyboard Look Right
if(!level.defaultPlayer->controls.lookRight.IsEmpty())
{
level.defaultPlayer->controls.lookRight.FirstPosition();
if(keys[level.defaultPlayer->controls.lookRight.Retrieve()])
{
level.defaultPlayer->camera.RotateView(-level.turnSpeed, 0, 1, 0);
}
else
{
while(level.defaultPlayer->controls.lookRight.NextPosition() && (keys[level.defaultPlayer->controls.lookRight.Retrieve()] != true));
{
if(keys[level.defaultPlayer->controls.lookRight.Retrieve()])
{
level.defaultPlayer->camera.RotateView(-level.turnSpeed, 0, 1, 0);
}
}
}
}
//////////
//Keyboard Look Up
if(!level.defaultPlayer->controls.lookUp.IsEmpty())
{
level.defaultPlayer->controls.lookUp.FirstPosition();
if(keys[level.defaultPlayer->controls.lookUp.Retrieve()])
{
level.defaultPlayer->camera.RotateView(level.turnSpeed, 1, 0, 0);
}
else
{
while(level.defaultPlayer->controls.lookUp.NextPosition() && (keys[level.defaultPlayer->controls.lookUp.Retrieve()] != true));
{
if(keys[level.defaultPlayer->controls.lookUp.Retrieve()])
{
level.defaultPlayer->camera.RotateView(level.turnSpeed, 1, 0, 0);
}
}
}
}
//////////
//Keyboard Look Down
if(!level.defaultPlayer->controls.lookDown.IsEmpty())
{
level.defaultPlayer->controls.lookDown.FirstPosition();
if(keys[level.defaultPlayer->controls.lookDown.Retrieve()])
{
level.defaultPlayer->camera.RotateView(-level.turnSpeed, 1, 0, 0);
}
else
{
while(level.defaultPlayer->controls.lookDown.NextPosition() && (keys[level.defaultPlayer->controls.lookDown.Retrieve()] != true));
{
if(keys[level.defaultPlayer->controls.lookDown.Retrieve()])
{
level.defaultPlayer->camera.RotateView(-level.turnSpeed, 1, 0, 0);
}
}
}
}
//////////
//Toggle Show FPS
if(!level.defaultPlayer->controls.toggleFPS.IsEmpty())
{
level.defaultPlayer->controls.toggleFPS.FirstPosition();
if(keys[level.defaultPlayer->controls.toggleFPS.Retrieve()])
{
if(!keys2[level.defaultPlayer->controls.toggleFPS.Retrieve()])
{
level.showFPS = !level.showFPS;
}
}
else
{
while(level.defaultPlayer->controls.toggleFPS.NextPosition() && (keys[level.defaultPlayer->controls.toggleFPS.Retrieve()] != true));
{
if(keys[level.defaultPlayer->controls.toggleFPS.Retrieve()])
{
if(!keys2[level.defaultPlayer->controls.toggleFPS.Retrieve()])
{
level.showFPS = !level.showFPS;
}
}
}
}
}
//////////
//Toggle MouseLook
if(!level.defaultPlayer->controls.toggleMouseLook.IsEmpty())
{
level.defaultPlayer->controls.toggleMouseLook.FirstPosition();
if(keys[level.defaultPlayer->controls.toggleMouseLook.Retrieve()])
{
if(keys2[level.defaultPlayer->controls.toggleMouseLook.Retrieve()])
{
level.mlook = ! level.mlook;
}
}
else
{
while(level.defaultPlayer->controls.toggleMouseLook.NextPosition() && (keys[level.defaultPlayer->controls.toggleMouseLook.Retrieve()] != true));
{
if(keys[level.defaultPlayer->controls.toggleMouseLook.Retrieve()])
{
if(keys2[level.defaultPlayer->controls.toggleMouseLook.Retrieve()])
{
level.mlook = ! level.mlook;
}
}
}
}
}
//////////
//Toggle Console
//if(!level.defaultPlayer[0].controls.toggleConsole.IsEmpty())
if(keys['I'])
keys['I'] = true;
if(!level.defaultPlayer->controls.toggleConsole.IsEmpty())
{
level.defaultPlayer->controls.toggleConsole.FirstPosition();
if(keys[level.defaultPlayer->controls.toggleConsole.Retrieve()])
{
if(!keys2[level.defaultPlayer->controls.toggleConsole.Retrieve()])
{
level.showConsole = !level.showConsole;
keys2[level.defaultPlayer->controls.toggleConsole.Retrieve()] = true;
}
}
else
{
while(level.defaultPlayer->controls.toggleConsole.NextPosition() && (keys[level.defaultPlayer->controls.toggleConsole.Retrieve()] != true));
{
if(keys[level.defaultPlayer->controls.toggleConsole.Retrieve()])
{
if(!keys2[level.defaultPlayer->controls.toggleConsole.Retrieve()])
{
level.showConsole = !level.showConsole;
keys2[level.defaultPlayer->controls.toggleConsole.Retrieve()] = true;
}
}
}
}
}
//////////
//Quick MouseLook
if(!level.defaultPlayer->controls.quickMouseLook.IsEmpty())
{
level.defaultPlayer->controls.quickMouseLook.FirstPosition();
if(keys[level.defaultPlayer->controls.quickMouseLook.Retrieve()])
{
if(keys2[level.defaultPlayer->controls.quickMouseLook.Retrieve()])
{
level.mlook = ! level.mlook;
}
}
else
{
while(level.defaultPlayer->controls.quickMouseLook.NextPosition() && (keys[level.defaultPlayer->controls.quickMouseLook.Retrieve()] != true));
{
if(keys[level.defaultPlayer->controls.quickMouseLook.Retrieve()])
{
if(keys2[level.defaultPlayer->controls.quickMouseLook.Retrieve()])
{
level.mlook = ! level.mlook;
}
}
}
}
}
level.Render();
}
}
SwapBuffers(hDC);
if (keys[VK_F1])
{
keys[VK_F1]=false;
KillGLWindow();
g_Screen.fullscreen=!g_Screen.fullscreen;
if (!CreateGLWindow("OpenArena",g_Screen.width,g_Screen.height,g_Screen.bpp,g_Screen.fullscreen))
{
return 0;
}
}
}
}
level.UnloadMap();
KillGLWindow();
return (msg.wParam);
}

63
src/mygl.cpp Normal file
View File

@@ -0,0 +1,63 @@
#include "../include/myGL.h"
void FreeGLTexture(unsigned int& texture)
{
glDeleteTextures(1, &texture);
}
bool LoadGLTexture(string fn, unsigned int& texture, int mag, int min)
{
if(Right(tolower(fn), 4) == ".bmp")
{
TextureImage* texImage = NULL;
if(texImage = LoadBMP(fn.c_str()))
{
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, texImage->sizeX, texImage->sizeY, 0, texImage->type, GL_UNSIGNED_BYTE, texImage->data);
if(texImage) //Just in case somehow the file was empty or unloadable
{
if(texImage->data)
free(texImage->data);
free(texImage);
}
return true;
}
else
{
return false;
}
}
else if(Right(tolower(fn), 4) == ".tga")
{
TextureImage* texImage = NULL;
if(texImage = LoadTGA(fn.c_str()))
{
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, 3, texImage->sizeX, texImage->sizeY, 0, texImage->type, GL_UNSIGNED_BYTE, texImage->data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
if(texImage) //Just in case somehow the file was empty or unloadable
{
if(texImage->data)
free(texImage->data);
free(texImage);
}
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}

142
src/myglFont.cpp Normal file
View File

@@ -0,0 +1,142 @@
////////////////////////////////////////////////////////////////////////////////
//
// Module: myglFont.cpp
// Author: Tom Hicks
// Creation: 09-01-2003
// LastEdit: 09-01-2003
// Editors: None
//
// Purpose:
//
// Summary of Methods:
// Global
// -function name
// description
// blahClass
// -function name
// description
//
// Summary of Properties:
// blahClass
// -property name
// description
//
////////////////////////////////////////////////////////////////////////////////
#include "../include/myglFont.h"
GLFontClass::GLFontClass()
{
status = 0;
base = 0;
texture = 0;
screenWidth = 1;
screenHeight = 1;
}
GLFontClass::~GLFontClass()
{
FreeFont();
}
bool GLFontClass::BuildFont(const char* texName)
{
FreeFont();
if(LoadGLTexture(texName, texture, GL_NEAREST, GL_NEAREST))
{
float x, y;
base = glGenLists(256);
glBindTexture(GL_TEXTURE_2D, texture);
for(short i = 0; i<256; i++)
{
x = i%16/16.0f;
y = i/16/16.0f;
glNewList(base+i, GL_COMPILE);
glBegin(GL_QUADS);
glTexCoord2f(x, 1-y-0.0625f);
glVertex2i(0,0);
glTexCoord2f(x+0.0625f, 1-y-0.0625f);
glVertex2i(16,0);
glTexCoord2f(x+0.0625f, 1-y);
glVertex2i(16,16);
glTexCoord2f(x, 1-y);
glVertex2i(0,16);
glEnd();
glTranslated(16,0,0);
glEndList();
}
status = true;
}
return status;
}
bool GLFontClass::FreeFont()
{
if(status)
{
glDeleteLists(base, 256);
status = false;
}
return status;
}
void GLFontClass::Print(int x, int y, const char* str, unsigned int set)
{
if(status)
{
if(set>1)
set = 1;
glBindTexture(GL_TEXTURE_2D, texture);
//glDisable(GL_DEPTH_TEST);
//glEnable(GL_BLEND);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0,screenWidth,0,screenHeight,-1,1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glTranslated(x, y, 0);
glListBase(base-32+(128*set));
glCallLists(strlen(str), GL_BYTE, str);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
//glDisable(GL_BLEND);
//glEnable(GL_DEPTH_TEST);
}
}
bool GLFontClass::Status()
{
return status;
}
void GLFontClass::SetScreenDimensions(short x, short y)
{
screenWidth = x;
screenHeight = y;
}
void GLFontClass::SetScreenWidth(short x)
{
screenWidth = x;
}
void GLFontClass::SetScreenHeight(short y)
{
screenHeight = y;
}
short GLFontClass::ScreenWidth()
{
return screenWidth;
}
short GLFontClass::ScreenHeight()
{
return screenHeight;
}

107
src/myglTexture.cpp Normal file
View File

@@ -0,0 +1,107 @@
#include "../include/myglTexture.h"
GL_MY_TEXTURE::GL_MY_TEXTURE()
{
id=0xFFFFFFFF;
filename = "";
minFilter = GL_LINEAR;
magFilter = GL_LINEAR;
}
GL_MY_TEXTURE::~GL_MY_TEXTURE()
{
Free();
}
string GL_MY_TEXTURE::Filename()
{
return filename;
}
uint32 GL_MY_TEXTURE::ID()
{
return id;
}
bool GL_MY_TEXTURE::Loaded()
{
return filename != "";
}
bool GL_MY_TEXTURE::Load(string fn)
{
if(Loaded())
Free();
if(LoadGLTexture(fn.c_str(), id, minFilter, magFilter))
{
filename = fn;
return true;
}
else
{
id=0xFFFFFFFF;
return false;
}
}
bool GL_MY_TEXTURE::Load(string fn, uint32 min, uint32 mag)
{
if(Loaded())
Free();
if(LoadGLTexture(fn.c_str(), id, min, mag))
{
filename = fn;
minFilter = min;
magFilter = mag;
return true;
}
else
{
id=0xFFFFFFFF;
return false;
}
}
void GL_MY_TEXTURE::Free()
{
if(Loaded())
{
FreeGLTexture(id);
minFilter = GL_LINEAR;
magFilter = GL_LINEAR;
filename = "";
id = 0xFFFFFFFF;
}
}
bool GL_MY_TEXTURE::operator<(const GL_MY_TEXTURE& rtOp)
{
return id<rtOp.id;
}
bool GL_MY_TEXTURE::operator<=(const GL_MY_TEXTURE& rtOp)
{
return id<=rtOp.id;
}
bool GL_MY_TEXTURE::operator==(const GL_MY_TEXTURE& rtOp)
{
return id==rtOp.id;
}
bool GL_MY_TEXTURE::operator!=(const GL_MY_TEXTURE& rtOp)
{
return id!=rtOp.id;
}
bool GL_MY_TEXTURE::operator>=(const GL_MY_TEXTURE& rtOp)
{
return id>=rtOp.id;
}
bool GL_MY_TEXTURE::operator>(const GL_MY_TEXTURE& rtOp)
{
return id>rtOp.id;
}

5
src/physics.cpp Normal file
View File

@@ -0,0 +1,5 @@
#include "../include/physics.h"
WORLD_PHYSICS::WORLD_PHYSICS()
{
}

23
src/player.cpp Normal file
View File

@@ -0,0 +1,23 @@
#include "../include/player.h"
void PLAYER::Load()
{
}
void PLAYER::Save()
{
}
void PLAYER::AddItem(unsigned int item)
{
// inventory = inventory | item;
}
void PLAYER::RemoveItem(unsigned int item)
{
// inventory = inventory & ~item;
}
void PLAYER::CreateCharacter()
{
}

289
src/strmanip.cpp Normal file
View File

@@ -0,0 +1,289 @@
#include "../include/strmanip.h"
bool Truth(std::string str)
{
if (toupper(str[0]) == 'T' || str[0] == '1')
return true;
else
return false;
}
int Integer(std::string str)
{
int last = str.length() - 1;
int number = 0;
for (int x = last; x>=0; x--)
{
switch(str[x])
{
case '1':
number += (int)pow(10, last-x);
break;
case '2':
number += 2 * (int)pow(10, last-x);
break;
case '3':
number += 3 * (int)pow(10, last-x);
break;
case '4':
number += 4 * (int)pow(10, last-x);
break;
case '5':
number += 5 * (int)pow(10, last-x);
break;
case '6':
number += 6 * (int)pow(10, last-x);
break;
case '7':
number += 7 * (int)pow(10, last-x);
break;
case '8':
number += 8 * (int)pow(10, last-x);
break;
case '9':
number += 9 * (int)pow(10, last-x);
}
}
return number;
}
float Floating(std::string str)
{
//this doesn't work right yet so use atof for now
int last = str.length() - 1;
float number = 0.0f;
bool period = false;
for (int x = last; x>=0; x--)
{
switch(str[x])
{
case '1':
number += (float)pow(10, last-x);
break;
case '2':
number += 2 * (float)pow(10, last-x);
break;
case '3':
number += 3 * (float)pow(10, last-x);
break;
case '4':
number += 4 * (float)pow(10, last-x);
break;
case '5':
number += 5 * (float)pow(10, last-x);
break;
case '6':
number += 6 * (float)pow(10, last-x);
break;
case '7':
number += 7 * (float)pow(10, last-x);
break;
case '8':
number += 8 * (float)pow(10, last-x);
break;
case '9':
number += 9 * (float)pow(10, last-x);
break;
case '.':
if (!period)
{
number *= (float)pow(10, -(last-x));
last -= (x+1);
period = true;
}
else
return number;
}
}
if(str[0] =='-')
return -number;
else
return number;
}
string KeyString(uint8 key)
{
switch (key)
{
case VK_UP:
return "up";
case VK_DOWN:
return "down";
case VK_LEFT:
return "left";
case VK_RIGHT:
return "right";
case VK_PRIOR:
return "pageup";
case VK_NEXT:
return "pagedown";
case VK_SPACE:
return "space";
case VK_LBUTTON:
return "mouse1";
case VK_RBUTTON:
return "mouse2";
case VK_MBUTTON:
return "mouse3";
case VK_F1:
return "f1";
case VK_F2:
return "f2";
case VK_F3:
return "f3";
case VK_F4:
return "f4";
case VK_F5:
return "f5";
case VK_F6:
return "f6";
case VK_F7:
return "f7";
case VK_F8:
return "f8";
case VK_F9:
return "f9";
case VK_F10:
return "f10";
case VK_F11:
return "f11";
case VK_F12:
return "f2";
default:
return "null";
};
}
uint8 KeyName(std::string str)
{
if (str.length() > 1)
{
if (str.substr(0,2) == "up")
return VK_UP;
else if (str.substr(0,4) == "down")
return VK_DOWN;
else if (str.substr(0,6) == "pageup")
return VK_PRIOR;
else if (str.substr(0,8) == "pagedown")
return VK_NEXT;
else if (str.substr(0,5) == "right")
return VK_RIGHT;
else if (str.substr(0,4) == "left")
return VK_LEFT;
else if (str.substr(0,5) == "space")
return VK_SPACE;
else if (str.substr(0,6) == "mouse1")
return VK_LBUTTON;
else if (str.substr(0,6) == "mouse2")
return VK_RBUTTON;
else if (str.substr(0,6) == "mouse3")
return VK_MBUTTON;
/*uncomment this to enable f1 as a mappable key
else if(str.substr(0,2) == "f1")
return VK_F1;
*/
else if (str.substr(0,2) == "f2")
return VK_F2;
else if (str.substr(0,2) == "f3")
return VK_F3;
else if (str.substr(0,2) == "f4")
return VK_F4;
else if (str.substr(0,2) == "f5")
return VK_F5;
else if (str.substr(0,2) == "f6")
return VK_F6;
else if (str.substr(0,2) == "f7")
return VK_F7;
else if (str.substr(0,2) == "f8")
return VK_F8;
else if (str.substr(0,2) == "f9")
return VK_F9;
else if (str.substr(0,2) == "f10")
return VK_F10;
else if (str.substr(0,2) == "f11")
return VK_F11;
else if (str.substr(0,2) == "f12")
return VK_F12;
//Add Game specific keys here and e-mail headhunter45@hotmail.com subject OpenArena keys so I can add them please
else if (str.substr(0,4) == "null")
return NULL;
else
return NULL;
}
else
return toupper(str[0]);
}
string Right(string str, uint32 len)
{
return str.substr(str.length()-len, len);
}
string Left(string str, uint32 len)
{
return str.substr(0, len);
}
string tolower(string str)
{
for(uint32 i=0; i<str.length(); i++)
str[i] = tolower(str[i]);
return str;
}
string toupper(string str)
{
for(uint32 i=0; i<str.length(); i++)
str[i] = toupper(str[i]);
return str;
}
string word(string str, uint32 wordNum)
{
///////////////
//stopped here
///////////////
uint32 start = 0;
uint32 length = 0;
uint32 maxLength = str.length();
if(str.length() > 0)
{
if(wordNum < 1)
{
while (!isspace(str[++length]) && length <= maxLength);
return str.substr(start, length);
}
else
{
while(isspace(str[start]))
++start;
for(uint32 i=0; i<wordNum; i++)
{
while(start <maxLength && !isspace(str[start]))// && start <= maxLength)
++start;
while(start < maxLength && isspace(str[start]))
++start;
}
;
while((start+length) < maxLength && !isspace(str[start+length]))
++length;
return str.substr(start, length);
}
}
else
{
return "";
}
}

619
src/tga.cpp Normal file
View File

@@ -0,0 +1,619 @@
#include "../include/tga.h"
TextureImage* LoadTGA(const char * filename)
{
TGAHeader tgaheader;
TextureImage* image;
std::string errmsg;
FILE* file = fopen(filename, "rb");
if(file == NULL)
{
errmsg = "Could not open texture file ";
errmsg = errmsg + filename;
MessageBox(NULL, errmsg.c_str(), "ERROR", MB_OK);
return NULL;
}
if(fread(&tgaheader, sizeof(TGAHeader), 1, file) == 0)
{
MessageBox(NULL, "Could not read file header", "ERROR", MB_OK);
if(file != NULL)
fclose(file);
return NULL;
}
if(memcmp(uTGAcompare, &tgaheader, sizeof(tgaheader)) == 0)
image = LoadUncompressedTGA(file);
else if(memcmp(cTGAcompare, &tgaheader, sizeof(tgaheader)) == 0)
image = LoadCompressedTGA(file);
else
{
MessageBox(NULL, "TGA file must be type 2 or type 10 ", "Invalid Image", MB_OK);
fclose(file);
return NULL;
}
return image;
}
TextureImage* LoadUncompressedTGA(FILE * fTGA)
{
TGA tga;
TextureImage* image = new TextureImage;
if(fread(tga.header, sizeof(tga.header), 1, fTGA) == 0)
{
MessageBox(NULL, "Could not read info header", "ERROR", MB_OK);
if(fTGA != NULL)
{
fclose(fTGA);
}
return NULL;
}
image->sizeY = tga.header[1] * 256 + tga.header[0];
image->sizeX = tga.header[3] * 256 + tga.header[2];
image->bpp = tga.header[4];
tga.Width = image->sizeX;
tga.Height = image->sizeY;
tga.Bpp = image->bpp;
if((image->sizeX <= 0) || (image->sizeY <= 0) || ((image->bpp != 24) && (image->bpp !=32)))
{
MessageBox(NULL, "Invalid texture information", "ERROR", MB_OK);
if(fTGA != NULL)
{
fclose(fTGA);
}
return NULL;
}
if(image->bpp == 24)
{
image->type = GL_RGB;
}
else
{
image->type = GL_RGBA;
}
tga.bytesPerPixel = (tga.Bpp / 8);
tga.imageSize = (tga.bytesPerPixel * tga.Width * tga.Height);
image->data = (GLubyte *)malloc(tga.imageSize);
if(image->data == NULL)
{
MessageBox(NULL, "Could not allocate memory for image", "ERROR", MB_OK);
fclose(fTGA);
return NULL;
}
if(fread(image->data, 1, tga.imageSize, fTGA) != tga.imageSize)
{
MessageBox(NULL, "Could not read image data", "ERROR", MB_OK);
if(image->data != NULL)
{
free(image->data);
}
fclose(fTGA);
return NULL;
}
for(GLuint cswap = 0; cswap < (int)tga.imageSize; cswap += tga.bytesPerPixel)
{
image->data[cswap] ^= image->data[cswap+2] ^=
image->data[cswap] ^= image->data[cswap+2];
}
fclose(fTGA);
return image;
}
TextureImage* LoadCompressedTGA(FILE * fTGA)
{
TextureImage* image = new TextureImage;
TGA tga;
if(fread(tga.header, sizeof(tga.header), 1, fTGA) == 0)
{
MessageBox(NULL, "Could not read info header", "ERROR", MB_OK);
if(fTGA != NULL)
{
fclose(fTGA);
}
return NULL;
}
image->sizeX = tga.header[1] * 256 + tga.header[0];
image->sizeY = tga.header[3] * 256 + tga.header[2];
image->bpp = tga.header[4];
tga.Width = image->sizeX;
tga.Height = image->sizeY;
tga.Bpp = image->bpp;
if((image->sizeX <= 0) || (image->sizeY <= 0) || ((image->bpp != 24) && (image->bpp !=32)))
{
MessageBox(NULL, "Invalid texture information", "ERROR", MB_OK);
if(fTGA != NULL)
{
fclose(fTGA);
}
return NULL;
}
tga.bytesPerPixel = (tga.Bpp / 8);
tga.imageSize = (tga.bytesPerPixel * tga.Width * tga.Height);
image->data = (GLubyte *)malloc(tga.imageSize);
if(image->data == NULL)
{
MessageBox(NULL, "Could not allocate memory for image", "ERROR", MB_OK);
fclose(fTGA);
return NULL;
}
GLuint pixelcount = tga.Height * tga.Width;
GLuint currentpixel = 0;
GLuint currentbyte = 0;
GLubyte * colorbuffer = (GLubyte *)malloc(tga.bytesPerPixel);
do
{
GLubyte chunkheader = 0;
if(fread(&chunkheader, sizeof(GLubyte), 1, fTGA) == 0)
{
MessageBox(NULL, "Could not read RLE header", "ERROR", MB_OK);
if(fTGA != NULL)
{
fclose(fTGA);
}
if(image->data != NULL)
{
free(image->data);
}
return NULL;
}
if(chunkheader < 128)
{
chunkheader++;
for(short counter = 0; counter < chunkheader; counter++)
{
if(fread(colorbuffer, 1, tga.bytesPerPixel, fTGA) != tga.bytesPerPixel)
{
MessageBox(NULL, "Could not read image data", "ERROR", MB_OK);
if(fTGA != NULL)
{
fclose(fTGA);
}
if(colorbuffer != NULL)
{
free(colorbuffer);
}
if(image->data != NULL)
{
free(image->data);
}
return NULL;
}
image->data[currentbyte ] = colorbuffer[2];
image->data[currentbyte + 1 ] = colorbuffer[1];
image->data[currentbyte + 2 ] = colorbuffer[0];
if(tga.bytesPerPixel == 4)
{
image->data[currentbyte + 3] = colorbuffer[3];
}
currentbyte += tga.bytesPerPixel;
currentpixel++;
if(currentpixel > pixelcount)
{
MessageBox(NULL, "Too many pixels read", "ERROR", NULL);
if(fTGA != NULL)
{
fclose(fTGA);
}
if(colorbuffer != NULL)
{
free(colorbuffer);
}
if(image->data != NULL)
{
free(image->data);
}
return NULL;
}
}
}
else
{
chunkheader -= 127;
if(fread(colorbuffer, 1, tga.bytesPerPixel, fTGA) != tga.bytesPerPixel)
{
MessageBox(NULL, "Could not read from file", "ERROR", MB_OK);
if(fTGA != NULL)
{
fclose(fTGA);
}
if(colorbuffer != NULL)
{
free(colorbuffer);
}
if(image->data != NULL)
{
free(image->data);
}
return NULL;
}
for(short counter = 0; counter < chunkheader; counter++)
{
image->data[currentbyte ] = colorbuffer[2];
image->data[currentbyte + 1 ] = colorbuffer[1];
image->data[currentbyte + 2 ] = colorbuffer[0];
if(tga.bytesPerPixel == 4)
{
image->data[currentbyte + 3] = colorbuffer[3];
}
currentbyte += tga.bytesPerPixel;
currentpixel++;
if(currentpixel > pixelcount)
{
MessageBox(NULL, "Too many pixels read", "ERROR", NULL);
if(fTGA != NULL)
{
fclose(fTGA);
}
if(colorbuffer != NULL)
{
free(colorbuffer);
}
if(image->data != NULL)
{
free(image->data);
}
return NULL;
}
}
}
}
while(currentpixel < pixelcount);
fclose(fTGA);
return image;
}
/*
TextureImage* LoadTGA(const char * filename)
{
TGAHeader tgaheader;
TextureImage* image;
std::string errmsg;
FILE* file = fopen(filename, "rb");
if(file == NULL)
{
errmsg = "Could not open texture file ";
errmsg = errmsg + filename;
MessageBox(NULL, errmsg.c_str(), "ERROR", MB_OK);
return NULL;
}
if(fread(&tgaheader, sizeof(TGAHeader), 1, file) == 0)
{
MessageBox(NULL, "Could not read file header", "ERROR", MB_OK);
if(file != NULL)
fclose(file);
return NULL;
}
if(memcmp(uTGAcompare, &tgaheader, sizeof(tgaheader)) == 0)
image = LoadUncompressedTGA(file);
else if(memcmp(cTGAcompare, &tgaheader, sizeof(tgaheader)) == 0)
image = LoadCompressedTGA(file);
else
{
MessageBox(NULL, "TGA file must be type 2 or type 10 ", "Invalid Image", MB_OK);
fclose(file);
return NULL;
}
return image;
}
TextureImage* LoadUncompressedTGA(FILE * fTGA)
{
TGA tga;
TextureImage* image = new TextureImage;
if(fread(tga.header, sizeof(tga.header), 1, fTGA) == 0)
{
MessageBox(NULL, "Could not read info header", "ERROR", MB_OK);
if(fTGA != NULL)
{
fclose(fTGA);
}
return NULL;
}
image->sizeY = tga.header[1] * 256 + tga.header[0];
image->sizeX = tga.header[3] * 256 + tga.header[2];
image->bpp = tga.header[4];
tga.Width = image->sizeX;
tga.Height = image->sizeY;
tga.Bpp = image->bpp;
if((image->sizeX <= 0) || (image->sizeY <= 0) || ((image->bpp != 24) && (image->bpp !=32)))
{
MessageBox(NULL, "Invalid texture information", "ERROR", MB_OK);
if(fTGA != NULL)
{
fclose(fTGA);
}
return NULL;
}
if(image->bpp == 24)
{
image->type = GL_RGB;
}
else
{
image->type = GL_RGBA;
}
tga.bytesPerPixel = (tga.Bpp / 8);
tga.imageSize = (tga.bytesPerPixel * tga.Width * tga.Height);
image->data = (GLubyte *)malloc(tga.imageSize);
if(image->data == NULL)
{
MessageBox(NULL, "Could not allocate memory for image", "ERROR", MB_OK);
fclose(fTGA);
return NULL;
}
if(fread(image->data, 1, tga.imageSize, fTGA) != tga.imageSize)
{
MessageBox(NULL, "Could not read image data", "ERROR", MB_OK);
if(image->data != NULL)
{
free(image->data);
}
fclose(fTGA);
return NULL;
}
for(GLuint cswap = 0; cswap < (int)tga.imageSize; cswap += tga.bytesPerPixel)
{
image->data[cswap] ^= image->data[cswap+2] ^=
image->data[cswap] ^= image->data[cswap+2];
}
fclose(fTGA);
return image;
}
TextureImage* LoadCompressedTGA(FILE * fTGA)
{
TextureImage* image = new TextureImage;
TGA tga;
if(fread(tga.header, sizeof(tga.header), 1, fTGA) == 0)
{
MessageBox(NULL, "Could not read info header", "ERROR", MB_OK);
if(fTGA != NULL)
{
fclose(fTGA);
}
return NULL;
}
image->sizeX = tga.header[1] * 256 + tga.header[0];
image->sizeY = tga.header[3] * 256 + tga.header[2];
image->bpp = tga.header[4];
tga.Width = image->sizeX;
tga.Height = image->sizeY;
tga.Bpp = image->bpp;
if((image->sizeX <= 0) || (image->sizeY <= 0) || ((image->bpp != 24) && (image->bpp !=32)))
{
MessageBox(NULL, "Invalid texture information", "ERROR", MB_OK);
if(fTGA != NULL)
{
fclose(fTGA);
}
return NULL;
}
tga.bytesPerPixel = (tga.Bpp / 8);
tga.imageSize = (tga.bytesPerPixel * tga.Width * tga.Height);
image->data = (GLubyte *)malloc(tga.imageSize);
if(image->data == NULL)
{
MessageBox(NULL, "Could not allocate memory for image", "ERROR", MB_OK);
fclose(fTGA);
return NULL;
}
GLuint pixelcount = tga.Height * tga.Width;
GLuint currentpixel = 0;
GLuint currentbyte = 0;
GLubyte * colorbuffer = (GLubyte *)malloc(tga.bytesPerPixel);
do
{
GLubyte chunkheader = 0;
if(fread(&chunkheader, sizeof(GLubyte), 1, fTGA) == 0)
{
MessageBox(NULL, "Could not read RLE header", "ERROR", MB_OK);
if(fTGA != NULL)
{
fclose(fTGA);
}
if(image->data != NULL)
{
free(image->data);
}
return NULL;
}
if(chunkheader < 128)
{
chunkheader++;
for(short counter = 0; counter < chunkheader; counter++)
{
if(fread(colorbuffer, 1, tga.bytesPerPixel, fTGA) != tga.bytesPerPixel)
{
MessageBox(NULL, "Could not read image data", "ERROR", MB_OK);
if(fTGA != NULL)
{
fclose(fTGA);
}
if(colorbuffer != NULL)
{
free(colorbuffer);
}
if(image->data != NULL)
{
free(image->data);
}
return NULL;
}
image->data[currentbyte ] = colorbuffer[2];
image->data[currentbyte + 1 ] = colorbuffer[1];
image->data[currentbyte + 2 ] = colorbuffer[0];
if(tga.bytesPerPixel == 4)
{
image->data[currentbyte + 3] = colorbuffer[3];
}
currentbyte += tga.bytesPerPixel;
currentpixel++;
if(currentpixel > pixelcount)
{
MessageBox(NULL, "Too many pixels read", "ERROR", NULL);
if(fTGA != NULL)
{
fclose(fTGA);
}
if(colorbuffer != NULL)
{
free(colorbuffer);
}
if(image->data != NULL)
{
free(image->data);
}
return NULL;
}
}
}
else
{
chunkheader -= 127;
if(fread(colorbuffer, 1, tga.bytesPerPixel, fTGA) != tga.bytesPerPixel)
{
MessageBox(NULL, "Could not read from file", "ERROR", MB_OK);
if(fTGA != NULL)
{
fclose(fTGA);
}
if(colorbuffer != NULL)
{
free(colorbuffer);
}
if(image->data != NULL)
{
free(image->data);
}
return NULL;
}
for(short counter = 0; counter < chunkheader; counter++)
{
image->data[currentbyte ] = colorbuffer[2];
image->data[currentbyte + 1 ] = colorbuffer[1];
image->data[currentbyte + 2 ] = colorbuffer[0];
if(tga.bytesPerPixel == 4)
{
image->data[currentbyte + 3] = colorbuffer[3];
}
currentbyte += tga.bytesPerPixel;
currentpixel++;
if(currentpixel > pixelcount)
{
MessageBox(NULL, "Too many pixels read", "ERROR", NULL);
if(fTGA != NULL)
{
fclose(fTGA);
}
if(colorbuffer != NULL)
{
free(colorbuffer);
}
if(image->data != NULL)
{
free(image->data);
}
return NULL;
}
}
}
}
while(currentpixel < pixelcount);
fclose(fTGA);
return image;
}
*/

163
src/vector.cpp Normal file
View File

@@ -0,0 +1,163 @@
#include "../include/vector.h"
Vec3d::Vec3d()
{
x=0.0f;
y=0.0f;
z=0.0f;
}
Vec3d::Vec3d(const Vec3d& orig)
{
operator=(orig);
}
Vec3d::Vec3d(double xr=0, double zr=0)
{
x=(double)sin(90-xr);
y=(double)sin(xr);
z=(double)(y*tan(zr));
}
Vec3d::Vec3d(double X, double Y, double Z)
{
x = X;
y = Y;
z = Z;
}
double Vec3d::lengthsquared()const
{
return (x*x+y*y+z*z);
}
double Vec3d::length() const
{
return (double)sqrt(lengthsquared());
}
void Vec3d::normalize()
{
x/=length();
y/=length();
z/=length();
}
void Vec3d::operator=(const Vec3d& v)
{
x = v.x;
y = v.y;
z = v.z;
}
Vec3d Vec3d::cross(const Vec3d& v) const
{
return Vec3d(y*v.z-z*v.y, z*v.x-x*v.z, x*v.y-y*v.x);
}
Vec3d Vec3d::operator*(const Vec3d& v) const
{
return Vec3d(y*v.z-z*v.y, z*v.x-x*v.z, x*v.y-y*v.x);
}
Vec3d Vec3d::operator+(const Vec3d& v)const
{
return Vec3d(x+v.x, y+v.y, z+v.z);
}
Vec3d Vec3d::operator*(double f) const
{
return Vec3d(x*f, y*f, z*f);
}
Vec3d Vec3d::operator-(const Vec3d& v)const
{
return Vec3d(x-v.x, y-v.y, z-v.z);
}
Vec3d Vec3d::operator/(double k) const
{
return Vec3d(x/k, y/k, z/k);
}
Vec3d Vec3d::normalized() const
{
return Vec3d(x/length(), y/length(), z/length());
}
Vec2f::Vec2f()
{
x=0;
y=0;
}
Vec2f::Vec2f(const Vec2f& rtOp)
{
x=rtOp.x;
y=rtOp.y;
}
Vec2f Vec2f::cross(const Vec2f& rtOp) const
{
return Vec2f(y-rtOp.y, rtOp.x-x);
}
double Vec2f::length()const
{
return sqrt(x*x+y*y);
}
double Vec2f::lengthsquared()const
{
return (x*x+y*y);
}
void Vec2f::normalize()
{
x/=(float)length();
y/=(float)length();
}
Vec2f Vec2f::normalized() const
{
return Vec2f(x/length(), y/length());
}
Vec2f Vec2f::operator*(double rtOp) const
{
return Vec2f(x*rtOp, y*rtOp);
}
Vec2f Vec2f::operator+(const Vec2f& rtOp) const
{
return Vec2f(x+rtOp.x, y+rtOp.y);
}
Vec2f Vec2f::operator*(const Vec2f& rtOp) const
{
return Vec2f(x*rtOp.x, y*rtOp.y);
}
Vec2f Vec2f::operator-(const Vec2f& rtOp) const
{
return Vec2f(x-rtOp.x, y-rtOp.y);
}
Vec2f Vec2f::operator/(double rtOp) const
{
return Vec2f(x/rtOp, y/rtOp);
}
Vec2f Vec2f::operator=(const Vec2f& rtOp)
{
x=rtOp.x;
y=rtOp.x;
return Vec2f(x,y);
}
Vec2f::Vec2f(double X, double Y)
{
x=(float)X;
y=(float)Y;
}