Changed: Updated to compile under linux

~g2k
This commit is contained in:
2005-06-20 03:03:16 -04:00
parent e2ca6ca672
commit a0b8ce778b
27 changed files with 603 additions and 236 deletions

View File

@@ -1,11 +1,10 @@
#ifndef __bmp_h__
#define __bmp_h__
#include <gl/glaux.h>
#include <stdio.h>
#include "mygl.h"
#include "datatypes.h"
#include "texture.h"
//AUX_RGBImageRec *LoadBMP(const char *Filename);
TextureImage* LoadBMP(const char* Filename);
#endif

View File

@@ -2,9 +2,11 @@
#define __camera_h__
#include <cmath>
#include <windows.h>
#ifdef WIN32
#include <windows.h> //Currently used for mouse stuff this should be replaced by oa_input
#endif
#include "vector.h"
#include "myGl.h"
#include "mygl.h"
#include "screen.h"

View File

@@ -1,8 +1,10 @@
#include "keys.h"
#include "physics.h"
#include "datatypes.h"
#include "list.h"
#include <windows.h>
#ifdef WIN32
//#include <windows.h> //used for VK_ keys and possibly something else. If this file wont compile try uncommenting this.
#endif
enum {CTRLS_FORWARD, CTRLS_BACKWARD, CTRLS_LOOKLEFT, CTRLS_LOOKRIGHT, CTRLS_LOOKUP,
CTRLS_LOOKDOWN, CTRLS_MOVELEFT, CTRLS_MOVERIGHT, CTRLS_MOVEUP, CTRLS_MOVEDOWN,
CTRLS_ROLLLEFT, CTRLS_ROLLRIGHT, CTRLS_FIREPRIMARY, CTRLS_FIRESECONDARY,

View File

@@ -1,6 +1,7 @@
#ifndef __datatypes_h__
#define __datatypes_h__
#ifdef WIN32
typedef unsigned __int8 uint8;
typedef unsigned __int16 uint16;
typedef unsigned __int32 uint32;
@@ -26,3 +27,32 @@ typedef dword dd;
typedef qword dq;
*/
#endif
#ifdef __linux
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned long uint32;
typedef unsigned long long uint64;
typedef char int8;
typedef short int16;
typedef long int32;
typedef long long int64;
typedef signed char sint8;
typedef signed short sint16;
typedef signed long sint32;
typedef signed long long sint64;
/*
typedef unsigned char byte;
typedef unsigned short word;
typedef unsigned long dword;
typedef unsigned long long qword;
typedef byte db;
typedef word dw;
typedef dword dd;
typedef qword dq;
*/
#endif
#endif

135
include/keys.h Normal file
View File

@@ -0,0 +1,135 @@
#ifdef WIN32
#include <
#define KEY_LBUTTON VK_LBUTTON
#define KEY_RBUTTON VK_RBUTTON
#define KEY_MBUTTON VK_MBUTTON
#define KEY_LEFT VK_LEFT
#define KEY_RIGHT VK_RIGHT
#define KEY_UP VK_UP
#define KEY_DOWN VK_DOWN
#define KEY_SPACE VK_SPACE
#define KEY_TAB VK_TAB
#define KEY_RETURN VK_RETURN
#define KEY_SHIFT VK_SHIFT
#define KEY_PAUSE VK_PAUSE
#define KEY_CONTROL VK_CONTROL
#define KEY_CAPITAL VK_CAPITAL
#define KEY_ESCAPE VK_ESCAPE
#define KEY_PRIOR VK_PRIOR
#define KEY_NEXT VK_NEXT
#define KEY_END VK_END
#define KEY_HOME VK_HOME
#define KEY_INSERT VK_INSERT
#define KEY_DELETE VK_DELETE
#define KEY_LWIN VK_LWIN
#define KEY_RWIN VK_RWIN
#define KEY_APPS VK_APPS
#define KEY_NUMPAD0 VK_NUMPAD0
#define KEY_NUMPAD1 VK_NUMPAD1
#define KEY_NUMPAD2 VK_NUMPAD2
#define KEY_NUMPAD3 VK_NUMPAD3
#define KEY_NUMPAD4 VK_NUMPAD4
#define KEY_NUMPAD5 VK_NUMPAD5
#define KEY_NUMPAD6 VK_NUMPAD6
#define KEY_NUMPAD7 VK_NUMPAD7
#define KEY_NUMPAD8 VK_NUMPAD8
#define KEY_NUMPAD9 VK_NUMPAD9
#define KEY_MULTIPLY VK_MULTIPLY
#define KEY_ADD VK_ADD
#define KEY_SUBTRACT VK_SUBTRACT
#define KEY_DIVIDE VK_DIVIDE
#define KEY_F1 VK_F1
#define KEY_F2 VK_F2
#define KEY_F3 VK_F3
#define KEY_F4 VK_F4
#define KEY_F5 VK_F5
#define KEY_F6 VK_F6
#define KEY_F7 VK_F7
#define KEY_F8 VK_F8
#define KEY_F9 VK_F9
#define KEY_F10 VK_F10
#define KEY_F11 VK_F11
#define KEY_F12 VK_F12
#define KEY_NUMLOCK VK_NUMLOCK
#define KEY_SCROLL VK_SCROLL
#define KEY_SEPARATOR VK_SEPARATOR
#define KEY_OEM_1 VK_OEM_1
#define KEY_OEM_2 VK_OEM_2
#define KEY_OEM_3 VK_OEM_3
#define KEY_OEM_4 VK_OEM_4
#define KEY_OEM_5 VK_OEM_5
#define KEY_OEM_6 VK_OEM_6
#define KEY_OEM_7 VK_OEM_7
#define KEY_OEM_PERIOD VK_OEM_PERIOD
#define KEY_OEM_PLUS VK_OEM_PLUS
#define KEY_OEM_MINUS VK_OEM_MINUS
#define KEY_OEM_COMMA VK_OEM_COMMA
#endif
#ifdef __linux
//TODO make these correct
#define KEY_LBUTTON 0
#define KEY_RBUTTON 1
#define KEY_MBUTTON 2
#define KEY_LEFT 3
#define KEY_RIGHT 4
#define KEY_UP 5
#define KEY_DOWN 6
#define KEY_SPACE 7
#define KEY_TAB 8
#define KEY_RETURN 9
#define KEY_SHIFT 10
#define KEY_PAUSE 11
#define KEY_CONTROL 12
#define KEY_CAPITAL 13
#define KEY_ESCAPE 14
#define KEY_PRIOR 15
#define KEY_NEXT 16
#define KEY_END 17
#define KEY_HOME 18
#define KEY_INSERT 19
#define KEY_DELETE 20
#define KEY_LWIN 21
#define KEY_RWIN 22
#define KEY_APPS 23
#define KEY_NUMPAD0 24
#define KEY_NUMPAD1 25
#define KEY_NUMPAD2 26
#define KEY_NUMPAD3 27
#define KEY_NUMPAD4 28
#define KEY_NUMPAD5 29
#define KEY_NUMPAD6 30
#define KEY_NUMPAD7 31
#define KEY_NUMPAD8 32
#define KEY_NUMPAD9 33
#define KEY_MULTIPLY 34
#define KEY_ADD 35
#define KEY_SUBTRACT 36
#define KEY_DIVIDE 37
#define KEY_F1 38
#define KEY_F2 39
#define KEY_F3 40
#define KEY_F4 41
#define KEY_F5 42
#define KEY_F6 43
#define KEY_F7 44
#define KEY_F8 45
#define KEY_F9 46
#define KEY_F10 47
#define KEY_F11 48
#define KEY_F12 49
#define KEY_NUMLOCK 50
#define KEY_SCROLL 51
#define KEY_SEPARATOR 52
#define KEY_OEM_1 53
#define KEY_OEM_2 54
#define KEY_OEM_3 55
#define KEY_OEM_4 56
#define KEY_OEM_5 57
#define KEY_OEM_6 58
#define KEY_OEM_7 59
#define KEY_OEM_PERIOD 60
#define KEY_OEM_PLUS 61
#define KEY_OEM_MINUS 62
#define KEY_OEM_COMMA 63
#endif

View File

@@ -1,22 +1,24 @@
#ifndef __LEVEL_H__
#define __LEVEL_H__
#include <windows.h>
#ifdef WIN32
#include <windows.h> //prolly used for alot but should be removed
#endif
#include <string>
#include <fstream>
#include <cctype>
#include <cmath>
#include <iostream>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glaux.h> //for auxDIBImageLoad
#include <stdio.h> //for file I/O
#include <GL/gl.h>
#include <cstdio> //for file I/O
#include "mydefs.h"
#include "bmp.h"
#include "tga.h"
#include "list.h"
#include "bass.h"
#ifdef WIN32
#include "bass.h" //for audio in windows only this should be replaced by oa_audio
#endif
#include "vector.h"
#include "camera.h"
#include "entities.h"
@@ -29,7 +31,7 @@
using namespace std;
const float piover180 = 0.0174532925f;
const string DEFAULT_TEXTURE_NAME = "oa/textures/default.tga";
const string DEFAULT_TEXTURE_NAME = "oa/textures/default.bmp";
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_OUTPUT_LINES = MAX_CONSOLE_LINES;
@@ -55,7 +57,6 @@ public:
void UpdateConsole(char);
uint32 FPS();
void ParseCmds(LPSTR);
void Print(int x, int y, const char* string, unsigned int set);
/*Not Yet Implemented

View File

@@ -37,6 +37,7 @@ public:
void FirstPosition();
void LastPosition();
void Clear();
bool Contains(ItemType) const;
unsigned int Length();
void operator=(const list<ItemType>&);
ItemType operator[](LIST_ARRAY_INDEX_TYPE) const;
@@ -341,7 +342,7 @@ ItemType& list<ItemType>::operator[](LIST_ARRAY_INDEX_TYPE index)
}
template <class ItemType>
unsigned int Length()
unsigned int list<ItemType>::Length()
{
if (head == NULL)
{
@@ -354,10 +355,25 @@ unsigned int Length()
while (temp != NULL)
{
temp = temp->next;
len++
len++;
}
return len;
}
}
template<class ItemType>
bool list<ItemType>::Contains(ItemType value)
{
listNodke<ItemType>* temp = head;
while(temp != NULL)
{
if(temp->data == value)
{
return true;
}
temp = temp->next;
}
return false;
}
#endif

View File

@@ -1,8 +1,7 @@
#ifndef __mydefs_h__
#define __mydefs_h__
#ifdef WIN32 //This whole file is windows specific right now
#include <windows.h>
static HWND g_hWnd = NULL;
#endif
#endif

View File

@@ -1,11 +1,14 @@
#ifndef __MYGL_H__
#define __MYGL_H__
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glaux.h>
#ifdef WIN32
#include <windows.h> //Remove if possible
#endif
#include <GL/gl.h>
#include <GL/glu.h>
//#include <gl/glaux.h> //Hopefully nothing needs this remove if it works in windows
#include <string>
#include "datatypes.h"
#include "screen.h"
#include "tga.h"
#include "bmp.h"
@@ -13,13 +16,15 @@
using namespace std;
#ifdef WIN32
//These three are windows specific
static HDC hDC=NULL; // Private GDI device context
static HGLRC hRC=NULL; // Permanent rendering context
static HINSTANCE hInstance; // Application instance
#endif
static SCREEN g_Screen;
int InitGL(GLvoid);
bool LoadGLTexture(string , unsigned int&, int = GL_LINEAR, int = GL_LINEAR);
void FreeGLTexture(unsigned int&);
bool LoadGLTexture(string , GLuint&, GLuint = GL_LINEAR, GLuint = GL_LINEAR);
void FreeGLTexture(GLuint&);
#endif

View File

@@ -1,7 +1,7 @@
#ifndef __glPrint_h__
#define __glPrint_h__
#include "myGL.h"
#include "mygl.h"
class GLFontClass
{

View File

@@ -3,7 +3,7 @@
#include <string>
#include "datatypes.h"
#include "myGL.h"
#include "mygl.h"
using namespace std;
@@ -13,9 +13,9 @@ public:
GL_MY_TEXTURE();
~GL_MY_TEXTURE();
string Filename();
uint32 ID();
GLuint ID();
bool Load(string filename);
bool Load(string filename, uint32 min, uint32 mag);
bool Load(string filename, GLuint min, GLuint mag);
void Free();
bool Loaded();
bool operator<(const GL_MY_TEXTURE&);
@@ -26,10 +26,10 @@ public:
bool operator>(const GL_MY_TEXTURE&);
private:
uint32 minFilter;
uint32 magFilter;
GLuint minFilter;
GLuint magFilter;
string filename;
uint32 id;
GLuint id;
};
#endif

View File

@@ -23,5 +23,4 @@ private:
};
#endif

View File

@@ -3,7 +3,10 @@
#include <string>
#include <cmath>
#include <windows.h>
#ifdef WIN32
#include <windows.h>//WTF why did I need all of these
#endif
#include "keys.h"
#include "datatypes.h"
using namespace std;
@@ -20,4 +23,3 @@ string toupper(string);
string word(string, uint32);
#endif

View File

@@ -2,9 +2,11 @@
#define __TGA_H__
#pragma comment(lib, "OpenGL32.lib")
#include <windows.h>
#include <gl\gl.h>
#include <stdio.h>
#ifdef WIN32
#include <windows.h> //I think this was only needed because gl.h uses it
#endif
#include <GL/gl.h>
#include <cstdio>
#include <string>
#include "texture.h"
@@ -31,5 +33,4 @@ const GLubyte cTGAcompare[12] = {0,0,10,0,0,0,0,0,0,0,0,0}; // Compressed TGA He
TextureImage* LoadUncompressedTGA(FILE *); // Load an Uncompressed file
TextureImage* LoadCompressedTGA(FILE *); // Load a Compressed file
#endif

View File

@@ -3,7 +3,7 @@
// Module: bmp.cpp
// Author: Tom Hicks
// Creation: 09-01-2003
// LastEdit: 10-09-2003
// LastEdit: 06-20-2005
// Editors: Tom Hicks
//
// Purpose:
@@ -18,8 +18,45 @@
//
////////////////////////////////////////////////////////////////////////////////
#include <cstdio>
#include "../include/bmp.h"
#pragma pack(push,1)
struct BITMAP_HEADER
{
uint16 type;
uint32 size;
uint16 reserved1;
uint16 reserved2;
uint32 offset;
};
struct BITMAP_INFO
{
uint32 size;
uint32 width;
uint32 height;
uint16 planes;
uint16 bitCount;
uint32 compression;
uint32 sizeImage;
uint32 xPelsPerMeter;
uint32 yPelsPerMeter;
uint32 clrUsed;
uint32 clrImportant;
};
struct BITMAP_QUAD
{
uint8 blue;
uint8 green;
uint8 red;
uint8 reserved;
};
#pragma pack(pop)
#define BITMAP_MAGIC 19778
TextureImage* LoadBMP(const char* fn)
{
//If anything is not perfect return NULL after cleaning up our mess
@@ -30,34 +67,128 @@ TextureImage* LoadBMP(const char* fn)
if(!fn)
return NULL;
//Try to open our file and if successfull...
f=fopen(fn, "r");
f=fopen(fn, "rb");
if(f)
{
//close the file
fclose(f);
BITMAP_HEADER bmpHeader;
BITMAP_INFO bmpInfo;
BITMAP_QUAD* bmpPallette = NULL;
uint32 palletteEntries = 0;
//Load our bitmap structure from the file.
AUX_RGBImageRec* bmp = auxDIBImageLoad(fn);
fread(&bmpHeader, sizeof(bmpHeader), 1, f);
fread(&bmpInfo, sizeof(bmpInfo), 1, f);
//If the load was successfull.
if(bmp)
if(bmpInfo.width < 0)
{
//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;
//This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Image width is negative", "ERROR", MB_OK);
#endif
fclose(f);
return NULL;
}
if(bmpInfo.width % 4 != 0)
{
//This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Image width must be a multiple of 8", "ERROR", MB_OK);
#endif
fclose(f);
return NULL;
}
if(bmpInfo.height < 0)
{
//This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Image height is negative", "ERROR", MB_OK);
#endif
fclose(f);
return NULL;
}
if(bmpInfo.height % 4 != 0)
{
//This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Image height must be a multiple of 8", "ERROR", MB_OK);
#endif
fclose(f);
return NULL;
}
if((bmpInfo.bitCount != 8 && bmpInfo.bitCount != 24) || bmpInfo.compression != 0)
{
//This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Only 8 and 24 bit uncompressed windows bmp files are currently supported", "ERROR", MB_OK);
#endif
fclose(f);
return NULL;
}
//Allocate memory for a TextureImage structure
TextureImage* tex = new TextureImage;
tex->sizeX = bmpInfo.width;
tex->sizeY = bmpInfo.height;
if(bmpInfo.bitCount >= 8)
{
tex->bpp = bmpInfo.bitCount >> 3;
}
tex->type = GL_RGB;
uint32 pixels = tex->sizeX * tex->sizeY;
uint32 bytes = pixels * tex->bpp;
tex->data = new uint8[bytes];
if(bmpInfo.bitCount == 8)
{
//Load the pallette
palletteEntries = bmpInfo.bitCount << 8;
bmpPallette = new BITMAP_QUAD[palletteEntries];
fread(bmpPallette, sizeof(BITMAP_QUAD), palletteEntries, f);
}
fseek(f, bmpHeader.offset, SEEK_SET);
fread(tex->data, bytes, 1, f);
if(bmpInfo.bitCount == 8)
{
//Apply the pallette
uint8* image = tex->data;
tex->bpp = 24;
bytes = pixels * tex->bpp;
tex->data = new uint8[bytes];
uint32 i;
uint32 i2;
for(i=0; i<pixels; i++)
{
i2 = i << 1 + 1;
//Should make sure image[i] < palletteEntries
tex->data[i2] = bmpPallette[image[i]].red;
tex->data[i2 + 1] = bmpPallette[image[i]].blue;
tex->data[i2 + 2] = bmpPallette[image[i]].green;
}
delete [] image;
image = NULL;
}
else if(bmpInfo.bitCount == 24)
{
uint32 i;
uint8 t;
for(i=0; i<bytes; i+=3)
{
t = tex->data[i];
tex->data[i] = tex->data[i+2];
tex->data[i+2] = t;
}
}
return tex;
}
return NULL;
}

View File

@@ -3,7 +3,7 @@
// Module: ctrls.cpp
// Author: Tom Hicks
// Creation: 09-01-2003
// LastEdit: 10-20-2003
// LastEdit: 06-19-2005
// Editors: Tom Hicks
//
// Purpose:
@@ -69,15 +69,15 @@
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);
forward.Insert(KEY_LBUTTON);
backward.Insert(KEY_RBUTTON);
lookLeft.Insert(KEY_LEFT);
lookRight.Insert(KEY_RIGHT);
lookUp.Insert(KEY_UP);
lookDown.Insert(KEY_DOWN);
moveLeft.Insert('S');
moveRight.Insert('D');
moveUp.Insert(VK_SPACE);
moveUp.Insert(KEY_SPACE);
moveDown.Insert('A');
firePrimary.Insert('F');
fireSecondary.Insert('G');

View File

@@ -1,12 +1,12 @@
#include "../include/myGL.h"
#include "../include/mygl.h"
void FreeGLTexture(unsigned int& texture)
void FreeGLTexture(GLuint& texture)
{
glDeleteTextures(1, &texture);
}
bool LoadGLTexture(string fn, unsigned int& texture, int mag, int min)
bool LoadGLTexture(string fn, GLuint& texture, GLuint mag, GLuint min)
{
if(Right(tolower(fn), 4) == ".bmp")
{

View File

@@ -3,7 +3,7 @@
// Module: myglFont.cpp
// Author: Tom Hicks
// Creation: 09-01-2003
// LastEdit: 09-01-2003
// LastEdit: 06-19-2005
// Editors: None
//
// Purpose:

View File

@@ -18,7 +18,7 @@ string GL_MY_TEXTURE::Filename()
return filename;
}
uint32 GL_MY_TEXTURE::ID()
GLuint GL_MY_TEXTURE::ID()
{
return id;
}
@@ -45,7 +45,7 @@ bool GL_MY_TEXTURE::Load(string fn)
}
}
bool GL_MY_TEXTURE::Load(string fn, uint32 min, uint32 mag)
bool GL_MY_TEXTURE::Load(string fn, GLuint min, GLuint mag)
{
if(Loaded())
Free();

View File

@@ -18,31 +18,31 @@ int Integer(std::string str)
switch(str[x])
{
case '1':
number += (int)pow(10, last-x);
number += (int)pow(10.0, last-x);
break;
case '2':
number += 2 * (int)pow(10, last-x);
number += 2 * (int)pow(10.0, last-x);
break;
case '3':
number += 3 * (int)pow(10, last-x);
number += 3 * (int)pow(10.0, last-x);
break;
case '4':
number += 4 * (int)pow(10, last-x);
number += 4 * (int)pow(10.0, last-x);
break;
case '5':
number += 5 * (int)pow(10, last-x);
number += 5 * (int)pow(10.0, last-x);
break;
case '6':
number += 6 * (int)pow(10, last-x);
number += 6 * (int)pow(10.0, last-x);
break;
case '7':
number += 7 * (int)pow(10, last-x);
number += 7 * (int)pow(10.0, last-x);
break;
case '8':
number += 8 * (int)pow(10, last-x);
number += 8 * (int)pow(10.0, last-x);
break;
case '9':
number += 9 * (int)pow(10, last-x);
number += 9 * (int)pow(10.0, last-x);
}
}
return number;
@@ -61,36 +61,36 @@ float Floating(std::string str)
switch(str[x])
{
case '1':
number += (float)pow(10, last-x);
number += (float)pow(10.0, last-x);
break;
case '2':
number += 2 * (float)pow(10, last-x);
number += 2 * (float)pow(10.0, last-x);
break;
case '3':
number += 3 * (float)pow(10, last-x);
number += 3 * (float)pow(10.0, last-x);
break;
case '4':
number += 4 * (float)pow(10, last-x);
number += 4 * (float)pow(10.0, last-x);
break;
case '5':
number += 5 * (float)pow(10, last-x);
number += 5 * (float)pow(10.0, last-x);
break;
case '6':
number += 6 * (float)pow(10, last-x);
number += 6 * (float)pow(10.0, last-x);
break;
case '7':
number += 7 * (float)pow(10, last-x);
number += 7 * (float)pow(10.0, last-x);
break;
case '8':
number += 8 * (float)pow(10, last-x);
number += 8 * (float)pow(10.0, last-x);
break;
case '9':
number += 9 * (float)pow(10, last-x);
number += 9 * (float)pow(10.0, last-x);
break;
case '.':
if (!period)
{
number *= (float)pow(10, -(last-x));
number *= (float)pow(10.0, -(last-x));
last -= (x+1);
period = true;
}
@@ -110,111 +110,111 @@ string KeyString(uint8 key)
{
switch (key)
{
case VK_LBUTTON:
case KEY_LBUTTON:
return "mouse1";
case VK_RBUTTON:
case KEY_RBUTTON:
return "mouse2";
case VK_MBUTTON:
case KEY_MBUTTON:
return "mouse3";
case VK_TAB:
case KEY_TAB:
return "tab";
case VK_RETURN:
case KEY_RETURN:
return "enter";
case VK_SHIFT:
case KEY_SHIFT:
return "shift";
case VK_CONTROL:
case KEY_CONTROL:
return "control";
case VK_PAUSE:
case KEY_PAUSE:
return "pause";
case VK_CAPITAL:
case KEY_CAPITAL:
return "capslock";
case VK_ESCAPE:
case KEY_ESCAPE:
return "esc";
case VK_SPACE:
case KEY_SPACE:
return "space";
case VK_PRIOR:
case KEY_PRIOR:
return "pageup";
case VK_NEXT:
case KEY_NEXT:
return "pagedown";
case VK_END:
case KEY_END:
return "end";
case VK_HOME:
case KEY_HOME:
return "home";
case VK_LEFT:
case KEY_LEFT:
return "left";
case VK_UP:
case KEY_UP:
return "up";
case VK_RIGHT:
case KEY_RIGHT:
return "right";
case VK_DOWN:
case KEY_DOWN:
return "down";
case VK_INSERT:
case KEY_INSERT:
return "insert";
case VK_DELETE:
case KEY_DELETE:
return "delete";
case VK_LWIN:
case KEY_LWIN:
return "lwin";
case VK_RWIN:
case KEY_RWIN:
return "rwin";
case VK_APPS:
case KEY_APPS:
return "apps";
case VK_NUMPAD0:
case KEY_NUMPAD0:
return "numpad0";
case VK_NUMPAD1:
case KEY_NUMPAD1:
return "numpad1";
case VK_NUMPAD2:
case KEY_NUMPAD2:
return "numpad2";
case VK_NUMPAD3:
case KEY_NUMPAD3:
return "numpad3";
case VK_NUMPAD4:
case KEY_NUMPAD4:
return "numpad4";
case VK_NUMPAD5:
case KEY_NUMPAD5:
return "numpad5";
case VK_NUMPAD6:
case KEY_NUMPAD6:
return "numpad6";
case VK_NUMPAD7:
case KEY_NUMPAD7:
return "numpad7";
case VK_NUMPAD8:
case KEY_NUMPAD8:
return "numpad8";
case VK_NUMPAD9:
case KEY_NUMPAD9:
return "numpad9";
case VK_MULTIPLY:
case KEY_MULTIPLY:
return "numpad*";
case VK_ADD:
case KEY_ADD:
return "numpad+";
case VK_SUBTRACT:
case KEY_SUBTRACT:
return "numpad-";
case VK_DIVIDE:
case KEY_DIVIDE:
return "numpad/";
case VK_F1:
case KEY_F1:
return "f1";
case VK_F2:
case KEY_F2:
return "f2";
case VK_F3:
case KEY_F3:
return "f3";
case VK_F4:
case KEY_F4:
return "f4";
case VK_F5:
case KEY_F5:
return "f5";
case VK_F6:
case KEY_F6:
return "f6";
case VK_F7:
case KEY_F7:
return "f7";
case VK_F8:
case KEY_F8:
return "f8";
case VK_F9:
case KEY_F9:
return "f9";
case VK_F10:
case KEY_F10:
return "f10";
case VK_F11:
case KEY_F11:
return "f11";
case VK_F12:
case KEY_F12:
return "f2";
case VK_NUMLOCK:
case KEY_NUMLOCK:
return "numlock";
case VK_SCROLL:
case KEY_SCROLL:
return "scroll";
case VK_SEPARATOR:
case KEY_SEPARATOR:
return "separator";
default:
return "null";
@@ -225,147 +225,147 @@ uint8 KeyName(std::string str)
if (str.length() > 1)
{
if (str.substr(0,2) == "up")
return VK_UP;
return KEY_UP;
else if (str.substr(0,4) == "down")
return VK_DOWN;
return KEY_DOWN;
else if (str.substr(0,3) == "esc")
return VK_ESCAPE;
return KEY_ESCAPE;
else if (str.substr(0,6) == "pageup")
return VK_PRIOR;
return KEY_PRIOR;
else if (str.substr(0,8) == "pagedown")
return VK_NEXT;
return KEY_NEXT;
else if (str.substr(0,5) == "right")
return VK_RIGHT;
return KEY_RIGHT;
else if (str.substr(0,4) == "left")
return VK_LEFT;
return KEY_LEFT;
else if (str.substr(0,5) == "space")
return VK_SPACE;
return KEY_SPACE;
else if (str.substr(0,6) == "mouse1")
return VK_LBUTTON;
return KEY_LBUTTON;
else if (str.substr(0,6) == "mouse2")
return VK_RBUTTON;
return KEY_RBUTTON;
else if (str.substr(0,6) == "mouse3")
return VK_MBUTTON;
return KEY_MBUTTON;
else if (str.substr(0,4) == "home")
return VK_HOME;
return KEY_HOME;
else if (str.substr(0,3) == "end")
return VK_END;
return KEY_END;
else if (str.substr(0,3) == "tab")
return VK_TAB;
return KEY_TAB;
else if (str.substr(0,5) == "enter")
return VK_RETURN;
return KEY_RETURN;
else if (str.substr(0,6) == "insert")
return VK_INSERT;
return KEY_INSERT;
else if (str.substr(0,6) == "delete")
return VK_DELETE;
return KEY_DELETE;
else if (str.substr(0,7) == "control")
return VK_CONTROL;
return KEY_CONTROL;
else if (str.substr(0,5) == "shift")
return VK_SHIFT;
return KEY_SHIFT;
else if (str.substr(0,7) == "numpad0")
return VK_NUMPAD0;
return KEY_NUMPAD0;
else if (str.substr(0,7) == "numpad1")
return VK_NUMPAD1;
return KEY_NUMPAD1;
else if (str.substr(0,7) == "numpad2")
return VK_NUMPAD2;
return KEY_NUMPAD2;
else if (str.substr(0,7) == "numpad3")
return VK_NUMPAD3;
return KEY_NUMPAD3;
else if (str.substr(0,7) == "numpad4")
return VK_NUMPAD4;
return KEY_NUMPAD4;
else if (str.substr(0,7) == "numpad5")
return VK_NUMPAD5;
return KEY_NUMPAD5;
else if (str.substr(0,7) == "numpad6")
return VK_NUMPAD6;
return KEY_NUMPAD6;
else if (str.substr(0,7) == "numpad7")
return VK_NUMPAD7;
return KEY_NUMPAD7;
else if (str.substr(0,7) == "numpad8")
return VK_NUMPAD8;
return KEY_NUMPAD8;
else if (str.substr(0,7) == "numpad9")
return VK_NUMPAD9;
return KEY_NUMPAD9;
else if (str.substr(0,9) == "separator")
return VK_SEPARATOR;
return KEY_SEPARATOR;
else if (str.substr(0,4) == "lwin")
return VK_LWIN;
return KEY_LWIN;
else if (str.substr(0,4) == "rwin")
return VK_RWIN;
return KEY_RWIN;
else if (str.substr(0,4) == "apps")
return VK_APPS;
return KEY_APPS;
else if (str.substr(0,7) == "numpad*")
return VK_MULTIPLY;
return KEY_MULTIPLY;
else if (str.substr(0,7) == "numpad+")
return VK_ADD;
return KEY_ADD;
else if (str.substr(0,7) == "numpad/")
return VK_DIVIDE;
return KEY_DIVIDE;
else if (str.substr(0,7) == "numpad-")
return VK_SUBTRACT;
return KEY_SUBTRACT;
else if (str.substr(0,6) == "scroll")
return VK_SCROLL;
return KEY_SCROLL;
else if (str.substr(0,7) == "numlock")
return VK_NUMLOCK;
return KEY_NUMLOCK;
else if (str.substr(0,5) == "pause")
return VK_PAUSE;
return KEY_PAUSE;
else if (str.substr(0,8) == "capslock")
return VK_CAPITAL;
return KEY_CAPITAL;
/*uncomment this to enable f1 as a mappable key
else if(str.substr(0,2) == "f1")
return VK_F1;
return KEY_F1;
*/
else if (str.substr(0,2) == "f2")
return VK_F2;
return KEY_F2;
else if (str.substr(0,2) == "f3")
return VK_F3;
return KEY_F3;
else if (str.substr(0,2) == "f4")
return VK_F4;
return KEY_F4;
else if (str.substr(0,2) == "f5")
return VK_F5;
return KEY_F5;
else if (str.substr(0,2) == "f6")
return VK_F6;
return KEY_F6;
else if (str.substr(0,2) == "f7")
return VK_F7;
return KEY_F7;
else if (str.substr(0,2) == "f8")
return VK_F8;
return KEY_F8;
else if (str.substr(0,2) == "f9")
return VK_F9;
return KEY_F9;
else if (str.substr(0,2) == "f10")
return VK_F10;
return KEY_F10;
else if (str.substr(0,2) == "f11")
return VK_F11;
return KEY_F11;
else if (str.substr(0,2) == "f12")
return VK_F12;
return KEY_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;
return (uint8)NULL;
else
return NULL;
return (uint8)NULL;
}
else
{
if(str[0] == '~' || str[0] == '`')
return VK_OEM_3;
return KEY_OEM_3;
else if (str[0] == '?' || str[0] == '/')
return VK_OEM_2;
return KEY_OEM_2;
else if (str[0] == '.' || str[0] == '>')
return VK_OEM_PERIOD;
return KEY_OEM_PERIOD;
else if (str[0] == '+' || str[0] == '=')
return VK_OEM_PLUS;
return KEY_OEM_PLUS;
else if (str[0] == ';' || str[0] == ':')
return VK_OEM_1;
return KEY_OEM_1;
else if (str[0] == ',' || str[0] == '<')
return VK_OEM_COMMA;
return KEY_OEM_COMMA;
else if (str[0] == '-' || str[0] == '_')
return VK_OEM_MINUS;
return KEY_OEM_MINUS;
else if (str[0] == '[' || str[0] == '{')
return VK_OEM_4;
return KEY_OEM_4;
else if (str[0] == ']' || str[0] == '}')
return VK_OEM_6;
return KEY_OEM_6;
else if (str[0] == '\\' || str[0] == '|')
return VK_OEM_5;
return KEY_OEM_5;
else if (str[0] == '\'' || str[0] == '"')
return VK_OEM_7;
return KEY_OEM_7;
else
return toupper(str[0]);
}

View File

@@ -12,13 +12,19 @@ TextureImage* LoadTGA(const char * filename)
{
errmsg = "Could not open texture file ";
errmsg = errmsg + filename;
//This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, errmsg.c_str(), "ERROR", MB_OK);
#endif
return NULL;
}
if(fread(&tgaheader, sizeof(TGAHeader), 1, file) == 0)
{
//This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Could not read file header", "ERROR", MB_OK);
#endif
if(file != NULL)
fclose(file);
return NULL;
@@ -30,7 +36,10 @@ TextureImage* LoadTGA(const char * filename)
image = LoadCompressedTGA(file);
else
{
//This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "TGA file must be type 2 or type 10 ", "Invalid Image", MB_OK);
#endif
fclose(file);
return NULL;
}
@@ -44,7 +53,10 @@ TextureImage* LoadUncompressedTGA(FILE * fTGA)
if(fread(tga.header, sizeof(tga.header), 1, fTGA) == 0)
{
//This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Could not read info header", "ERROR", MB_OK);
#endif
if(fTGA != NULL)
{
fclose(fTGA);
@@ -61,7 +73,10 @@ TextureImage* LoadUncompressedTGA(FILE * fTGA)
if((image->sizeX <= 0) || (image->sizeY <= 0) || ((image->bpp != 24) && (image->bpp !=32)))
{
//This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Invalid texture information", "ERROR", MB_OK);
#endif
if(fTGA != NULL)
{
fclose(fTGA);
@@ -84,14 +99,20 @@ TextureImage* LoadUncompressedTGA(FILE * fTGA)
if(image->data == NULL)
{
//This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Could not allocate memory for image", "ERROR", MB_OK);
#endif
fclose(fTGA);
return NULL;
}
if(fread(image->data, 1, tga.imageSize, fTGA) != tga.imageSize)
{
//This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Could not read image data", "ERROR", MB_OK);
#endif
if(image->data != NULL)
{
free(image->data);
@@ -118,7 +139,10 @@ TextureImage* LoadCompressedTGA(FILE * fTGA)
if(fread(tga.header, sizeof(tga.header), 1, fTGA) == 0)
{
//This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Could not read info header", "ERROR", MB_OK);
#endif
if(fTGA != NULL)
{
fclose(fTGA);
@@ -135,7 +159,10 @@ TextureImage* LoadCompressedTGA(FILE * fTGA)
if((image->sizeX <= 0) || (image->sizeY <= 0) || ((image->bpp != 24) && (image->bpp !=32)))
{
//This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Invalid texture information", "ERROR", MB_OK);
#endif
if(fTGA != NULL)
{
fclose(fTGA);
@@ -149,7 +176,10 @@ TextureImage* LoadCompressedTGA(FILE * fTGA)
if(image->data == NULL)
{
//This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Could not allocate memory for image", "ERROR", MB_OK);
#endif
fclose(fTGA);
return NULL;
}
@@ -165,7 +195,10 @@ TextureImage* LoadCompressedTGA(FILE * fTGA)
if(fread(&chunkheader, sizeof(GLubyte), 1, fTGA) == 0)
{
//This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Could not read RLE header", "ERROR", MB_OK);
#endif
if(fTGA != NULL)
{
fclose(fTGA);
@@ -184,7 +217,10 @@ TextureImage* LoadCompressedTGA(FILE * fTGA)
{
if(fread(colorbuffer, 1, tga.bytesPerPixel, fTGA) != tga.bytesPerPixel)
{
//This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Could not read image data", "ERROR", MB_OK);
#endif
if(fTGA != NULL)
{
@@ -218,7 +254,10 @@ TextureImage* LoadCompressedTGA(FILE * fTGA)
if(currentpixel > pixelcount)
{
//This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Too many pixels read", "ERROR", NULL);
#endif
if(fTGA != NULL)
{
@@ -244,7 +283,10 @@ TextureImage* LoadCompressedTGA(FILE * fTGA)
chunkheader -= 127;
if(fread(colorbuffer, 1, tga.bytesPerPixel, fTGA) != tga.bytesPerPixel)
{
//This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Could not read from file", "ERROR", MB_OK);
#endif
if(fTGA != NULL)
{
@@ -280,7 +322,10 @@ TextureImage* LoadCompressedTGA(FILE * fTGA)
if(currentpixel > pixelcount)
{
//This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Too many pixels read", "ERROR", NULL);
#endif
if(fTGA != NULL)
{