*** 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

BIN
OpenArena User's Manual.doc Normal file

Binary file not shown.

1096
OpenArena User's Manual.htm Normal file

File diff suppressed because it is too large Load Diff

1096
OpenArena User's Manual.html Normal file

File diff suppressed because it is too large Load Diff

BIN
OpenArena/bass.dll Normal file

Binary file not shown.

View File

@@ -0,0 +1,30 @@
bind forward up
bind backward down
bind forward mouse1
bind backward mouse2
bind lookleft left
bind lookright right
bind lookup pageup
bind lookdown pagedown
bind moveleft s
bind moveright d
bind moveup space
bind movedown a
bind fireprimary f
bind firesecondary g
bind weapnext t
bind weapprev r
bind togglelights l
bind togglefps p
bind toggleconsole `
bind togglemouselook null
bind quickmouselook null
set turnspeed 1.0
//set movespeed 0.2
set fullscreen 0
set mousespeed 5
set mouselook 1
set screenwidth 1024
set screenheight 768
set colordepth 32
set maxfps 500

View File

@@ -0,0 +1,36 @@
bind forward up
bind backward down
bind forward mouse1
bind backward mouse2
bind lookleft left
bind lookright right
bind lookup pageup
bind lookdown pagedown
bind moveleft s
bind moveright d
bind moveup space
bind movedown a
bind fireprimary f
bind firesecondary g
bind weapnext t
bind weapprev r
bind togglelights l
bind togglefps p
bind toggleconsole ~
bind toggleconsole `
bind toggleconsole i
bind togglemouselook m
bind quickmouselook y
set turnspeed 0.02
set movespeed 0.2
set mousespeed 5
set mouselook 1
set screenwidth 800
set screenheight 600
set colordepth 16
set fullscreen 0
map intro.map
set maxfps 60
set rollleft w
set rollright e
set sound 1

View File

@@ -0,0 +1,16 @@
1
1
0
-10 -10 -5 0 0
-10 10 -5 0 1
10 -10 -5 1 0
0 0 1
3
groundc.tga
moonc.tga
nightSkyc.tga
bgm1.mp3

View File

@@ -0,0 +1,14 @@
1
1
0
-10 -10 -5 0 0
-10 10 -5 0 1
10 -10 -5 1 0
0 0 1
3
groundc.tga
moonc.tga
nightSkyc.tga
bgm1.mp3

View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 450 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

BIN
bass.dll Normal file

Binary file not shown.

1221
include/bass.h Normal file

File diff suppressed because it is too large Load Diff

11
include/bmp.h Normal file
View File

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

88
include/camera.h Normal file
View File

@@ -0,0 +1,88 @@
#ifndef __camera_h__
#define __camera_h__
#include <cmath>
#include <windows.h>
#include "vector.h"
#include "myGl.h"
#include "screen.h"
class CameraClass
{
public:
//Constructors
CameraClass(); //Default Constructor
//Purpose:
//
//CameraClass(const CameraClass&); //Copy Constructor
//Purpose:
//
//Observer Accessors
Vec3f Position();
//Purpose:
//
Vec3f View();
//Purpose:
//
Vec3f UpVector();
//Purpose:
//
Vec3f Strafe();
//Purpose:
//
//Mutators
void PositionCamera(double xpos, double ypos, double zpos,
double xview, double yview, double zview,
double xup, double yup, double zup);
//Purpose:
//
void PositionCamera(Vec3f pos, Vec3f view, Vec3f up);
//Purpose:
//
void RotateView(double angle, double X, double Y, double Z);
//Purpose:
//
void SetViewByMouse(SCREEN g_Screen);
//Purpose:
//
void RotateAroundPoint(Vec3f vCenter, double X, double Y, double Z);
//Purpose:
//
void StrafeCamera(double speed);
//Purpose:
//
void MoveCamera(double speed);
//Purpose:
//
void Update();
//Purpose:
//
void Look();
//Purpose:
//
private:
Vec3f m_vPosition;
Vec3f m_vView;
Vec3f m_vUpVector;
Vec3f m_vStrafe;
};
#endif

14
include/critter.h Normal file
View File

@@ -0,0 +1,14 @@
#ifndef __critter_h__
#define __critter_h__
#include "md3.h"
class CRITTER
{
public:
MD3_MODEL model;
};
#endif

33
include/ctrls.h Normal file
View File

@@ -0,0 +1,33 @@
#include "physics.h"
#include "datatypes.h"
#include "list.h"
#include <windows.h>
class ControlSchemeClass
{
public:
void LoadDefaultControlScheme();
void ClearControlScheme();
list<uint8> forward;
list<uint8> backward;
list<uint8> lookLeft;
list<uint8> lookRight;
list<uint8> lookUp;
list<uint8> lookDown;
list<uint8> moveLeft;
list<uint8> moveRight;
list<uint8> moveUp;
list<uint8> moveDown;
list<uint8> firePrimary;
list<uint8> fireSecondary;
list<uint8> weaponNext;
list<uint8> weaponPrev;
list<uint8> toggleLights;
list<uint8> toggleFPS;
list<uint8> toggleConsole;
list<uint8> toggleMouseLook;
list<uint8> quickMouseLook;
list<uint8> rollLeft;
list<uint8> rollRight;
};

28
include/datatypes.h Normal file
View File

@@ -0,0 +1,28 @@
#ifndef __datatypes_h__
#define __datatypes_h__
typedef unsigned __int8 uint8;
typedef unsigned __int16 uint16;
typedef unsigned __int32 uint32;
typedef unsigned __int64 uint64;
typedef __int8 int8;
typedef __int16 int16;
typedef __int32 int32;
typedef __int64 int64;
typedef signed __int8 sint8;
typedef signed __int16 sint16;
typedef signed __int32 sint32;
typedef signed __int64 sint64;
/*
typedef unsigned __int8 byte;
typedef unsigned __int16 word;
typedef unsigned __int32 dword;
typedef unsigned __int64 qword;
typedef byte db;
typedef word dw;
typedef dword dd;
typedef qword dq;
*/
#endif

58
include/entities.h Normal file
View File

@@ -0,0 +1,58 @@
using namespace std;
struct LIGHT
{
GLfloat coords[4];
GLfloat color[4];
};
struct PLAYER_START
{
Vec3f coords;
Vec3f heading;
};
struct PLAYER_DEATHMATCH_START
{
Vec3f coords;
Vec3f heading;
};
struct BOT_START
{
Vec3f coords;
Vec3f heading;
string name;
};
struct GEOMETRY
{
int x;
};
struct PROJECTILE
{
Vec3f heading;
Vec3f start;
Vec3f end;
int dammage;
float creation;
};
//const PROJECTILE BULLET = {{0,0,0},{0,0,0},{0,0,0},5};
//const PROJECTILE SPIKE = {{0,0,0},{0,0,0},{0,0,0},10};
struct ENTITY
{
PLAYER_START* Player_Start;
int numPlayer_Start;
PLAYER_DEATHMATCH_START* Player_Deathmatch_Start;
int numPlayer_Deathmatch_Start;
BOT_START* Bot_Start;
int numBot_Start;
GEOMETRY* Geometry;
int numGeometry;
PROJECTILE* Projectile;
int numProjectile;
ENTITY();
};
enum ITEM_TYPE{/*all weapons go first*/WEAPON_LASERPISTOL = 1, WEAPON_SHOTGUN = 2, ITEM_BANDAGES = 4, RUNE_DAMMAGEMULTIPLIER = 8, RUNE_PROTECTION = 16, RUNE_VAMPIRE = 32, RUNE_SPEED = 64, RUNE_DOC = 128};//This semicolon got rid of 107 errors and no warnings

30
include/entity.h Normal file
View File

@@ -0,0 +1,30 @@
#ifndef __entity_h__
#define __entity_h__
#include "datatypes.h"
enum { //Begin entity declaration
ENTITY_NONE=0, //Nonexistant entity this should never be used.
ENTITY_PLAYER_MULTI_START //Player start position for multiplayer.
}; //End entity declaration
class ENTITY
{
public:
ENTITY()
{
type = ENTITY_NONE;
vPosition = Vec3f(0,0,0);
vHeading = Vec3f(0,0,0);
vUp = Vec3f(0,0,0);
health = 0;
}
uint32 type;
Vec3f vPosition;
Vec3f vHeading;
Vec3f vUp;
uint16 health;
};
#endif

35
include/geometry.h Normal file
View File

@@ -0,0 +1,35 @@
#include "vector.h"
#include "myglTexture.h"
struct TRIANGLE
{
GL_MY_TEXTURE texture;
uint32 texID;
Vec3f vertecies[3];
Vec2f texCoords[3];
Vec3f normal;
};
class POSITION
{
public:
GLfloat xrot; // X rotation
GLfloat yrot; // Y rotation
GLfloat zrot; // Z rotation
GLfloat xtrans; // X translation
GLfloat ytrans; // Y translation
GLfloat ztrans; // Z translation
bool stepRight;
bool stepLeft;
POSITION()
{
xtrans = 0.0f;
ytrans = 0.0f;
ztrans = 0.0f;
xrot = 0.0f;
yrot = 0.0f;
zrot = 0.0f;
}
private:
};

99
include/level.h Normal file
View File

@@ -0,0 +1,99 @@
#ifndef __LEVEL_H__
#define __LEVEL_H__
#include <windows.h>
#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 "mydefs.h"
#include "bmp.h"
#include "tga.h"
#include "list.h"
#include "bass.h"
#include "vector.h"
#include "camera.h"
#include "entities.h"
#include "geometry.h"
#include "myglFont.h"
#include "myglTexture.h"
#include "player.h"
#include "strmanip.h"
using namespace std;
const float piover180 = 0.0174532925f;
const string DEFAULT_TEXTURE_NAME = "oa/textures/default.tga";
const unsigned int MAX_CONSOLE_LINES = 30; //The max number of lines to be displayed in the console
const unsigned int MAX_CONSOLE_HISTORY_LINES = MAX_CONSOLE_LINES + 20; //The max number of console lines to store in the history
enum {GL_MY_TEXTURE_CONSOLEBACKGROUND=0, NUM_MENU_TEXTURES};
class LEVEL
{
public:
LEVEL();
~LEVEL();
bool LoadMap(string mapname);
void LoadMap();
void SaveMap(string mapname);
bool LoadConfig(string cfgname);
void LoadConfig();
void SaveConfig(string cfgname);
void Execute(string cmd);
void LoadGLTextures();
void Render();
void UnloadMap();
uint32 FPS();
void ParseCmds(LPSTR);
void Print(int x, int y, const char* string, unsigned int set);
/*Not Yet Implemented
void PlayerConnect(); // implement later
void PlayerDisconnect(); // implement later
*/
SCREEN screen;
GLFontClass glFont;
string nextLevel;
PLAYER* defaultPlayer;
uint32 numTextures;
string* textureNames;
string bgm;
HSTREAM bgmStream;
unsigned char bgmCDA;
string gamedir;
float gravity;
bool mlook;
bool showFPS;
bool showConsole;
bool sound;
float turnSpeed;
float moveSpeed;
float mouseSpeed;
unsigned char maxFPS;
//Map
TRIANGLE* triangles;
uint32 numTriangles;
list<PLAYER> players;
list<ENTITY> ents;
//list<GL_MY_TEXTURE> textures;
GL_MY_TEXTURE* textures;
GL_MY_TEXTURE menuTextures[NUM_MENU_TEXTURES];
private:
string consoleHistory[MAX_CONSOLE_HISTORY_LINES];
};
#endif

246
include/list.cpp Normal file
View File

@@ -0,0 +1,246 @@
/*
template <class ItemType>
listNode<ItemType>::listNode()
{
next = NULL;
}
template <class ItemType>
list<ItemType>::list()
{
head = NULL;
tail = NULL;
currPos = NULL;
}
template <class ItemType>
list<ItemType>::~list()
{
currPos = NULL;
while(head != NULL)
{
tail = head;
head = head->next;
delete tail;
tail = NULL;
}
}
template <class ItemType>
list<ItemType>::list(const list<ItemType>& rtOp)
{
head = NULL;
tail = NULL
currPos = NULL;
operator=(rtOp);
}
template <class ItemType>
void list<ItemType>::Clear()
{
while(head)
Remove(head->data);
}
template <class ItemType>
void list<ItemType>::operator=(const list<ItemType>& rtOp)
{
Clear();
listNode<ItemType> temp = rtOp.head->next;
listNode<ItemType> temp2 = NULL;
if(temp != NULL)
{
head = new listNode<ItemType>;
head->data = rtOp.head->data;
tail = head;
temp2 = head;
}
while (temp != NULL)
{
temp2->next = new listNode<ItemType>;
temp2 = temp2->next;
temp2->data = temp->data;
temp = temp->next;
}
tail = temp2;
}
template <class ItemType>
bool list<ItemType>::IsEmpty()
{
return head == NULL;
}
template <class ItemType>
bool list<ItemType>::IsFull()
{
return false;
}
template <class ItemType>
void list<ItemType>::Insert(ItemType newItem)
{
listNode<ItemType>* temp = head;
if(head != NULL)
{
while(temp->next!= NULL && temp->data < newItem)
{
temp = temp->next;
}
if(temp == head)
{
tail->next = head;
head = new listNode<ItemType>;
head->next = tail->next;
tail->next = NULL;
temp = head;
}
else if(temp->data != newItem)
{
if(temp == tail)
{
tail->next = new listNode<ItemType>;
tail = tail->next;
temp = tail;
}
else
{
tail->next = temp->next;
temp = temp->next = new listNode<ItemType>;
temp->next = tail->next;
tail->next = NULL;
}
}
}
else
{
temp = tail = head = new listNode<ItemType>;
tail->next = NULL;
}
temp->data = newItem;
}
template <class ItemType>
void list<ItemType>::Remove(ItemType target)
{
if(head != NULL)
{
listNode<ItemType>* temp = head;
tail->next = head;
while(temp->next != NULL && temp->data != target)
{
tail->next = temp;
temp = temp->next;
}
if(temp->data == target)
{
if(tail->next != head)
{
tail->next->next = temp->next;
delete temp;
}
else
{
head = head->next;
delete tail->next;
}
}
tail->next = NULL;
}
}
template <class ItemType>
bool list<ItemType>::PrevPosition()
{
if(currPos != head)
{
tail->next = currPos;
currPos = head;
if(currPos != tail->next)
{
while(currPos->next != tail->next)
{
currPos = currPos->next;
}
}
tail->next = NULL;
return true;
}
else
{
return false;
}
}
template <class ItemType>
bool list<ItemType>::NextPosition()
{
if(currPos != tail)
{
currPos = currPos->next;
return true;
}
else
{
return false;
}
}
template <class ItemType>
void list<ItemType>::Remove()
{
if(currPos != NULL)
{
tail->next = currPos;
currPos = currPos->next;
delete tail->next;
tail->next = NULL;
}
}
template <class ItemType>
ItemType list<ItemType>::Retrieve()
{
if(currPos != NULL)
return currPos->data;
}
template <class ItemType>
bool list<ItemType>::IsFirstPosition()
{
return currPos == head;
}
template <class ItemType>
bool list<ItemType>::IsLastPosition()
{
return currPos == tail;
}
template <class ItemType>
void list<ItemType>::FirstPosition()
{
currPos = head;
}
template <class ItemType>
void list<ItemType>::LastPosition()
{
currPos = tail;
}
*/

312
include/list.h Normal file
View File

@@ -0,0 +1,312 @@
#ifndef __list_h__
#define __list_h__
#include <cstdlib>
#pragma warning(disable:4715)
template <class ItemType>
class listNode
{
public:
listNode();
listNode<ItemType>* next;
ItemType data;
};
template <class ItemType>
class list
{
public:
list();
~list();
list(const list&);
bool IsEmpty();
bool IsFull();
void Insert(ItemType newItem);
void Remove(ItemType target);
void Remove();
ItemType Retrieve();
bool PrevPosition();
bool NextPosition();
bool IsFirstPosition();
bool IsLastPosition();
void FirstPosition();
void LastPosition();
void Clear();
void operator=(const list<ItemType>&);
ItemType operator[](unsigned int);
private:
listNode<ItemType>* head;
listNode<ItemType>* tail;
listNode<ItemType>* currPos;
};
template <class ItemType>
listNode<ItemType>::listNode()
{
next = NULL;
}
template <class ItemType>
list<ItemType>::list()
{
head = NULL;
tail = NULL;
currPos = NULL;
}
template <class ItemType>
list<ItemType>::~list()
{
currPos = NULL;
while(head != NULL)
{
tail = head;
head = head->next;
delete tail;
tail = NULL;
}
}
template <class ItemType>
list<ItemType>::list(const list<ItemType>& rtOp)
{
head = NULL;
tail = NULL
currPos = NULL;
operator=(rtOp);
}
template <class ItemType>
void list<ItemType>::Clear()
{
while(head)
Remove(head->data);
}
template <class ItemType>
void list<ItemType>::operator=(const list<ItemType>& rtOp)
{
Clear();
listNode<ItemType> temp = rtOp.head->next;
listNode<ItemType> temp2 = NULL;
if(temp != NULL)
{
head = new listNode<ItemType>;
head->data = rtOp.head->data;
tail = head;
temp2 = head;
}
while (temp != NULL)
{
temp2->next = new listNode<ItemType>;
temp2 = temp2->next;
temp2->data = temp->data;
temp = temp->next;
}
tail = temp2;
}
template <class ItemType>
bool list<ItemType>::IsEmpty()
{
return head == NULL;
}
template <class ItemType>
bool list<ItemType>::IsFull()
{
return false;
}
template <class ItemType>
void list<ItemType>::Insert(ItemType newItem)
{
listNode<ItemType>* temp = head;
if(head != NULL)
{
while(temp->next!= NULL && temp->data < newItem)
{
temp = temp->next;
}
if(temp == head)
{
tail->next = head;
head = new listNode<ItemType>;
head->next = tail->next;
tail->next = NULL;
temp = head;
}
else if(temp->data != newItem)
{
if(temp == tail)
{
tail->next = new listNode<ItemType>;
tail = tail->next;
temp = tail;
}
else
{
tail->next = temp->next;
temp = temp->next = new listNode<ItemType>;
temp->next = tail->next;
tail->next = NULL;
}
}
}
else
{
temp = tail = head = new listNode<ItemType>;
tail->next = NULL;
}
temp->data = newItem;
}
template <class ItemType>
void list<ItemType>::Remove(ItemType target)
{
if(head != NULL)
{
listNode<ItemType>* temp = head;
tail->next = head;
while(temp->next != NULL && temp->data != target)
{
tail->next = temp;
temp = temp->next;
}
if(temp->data == target)
{
if(tail->next != head)
{
tail->next->next = temp->next;
delete temp;
}
else
{
head = head->next;
delete tail->next;
}
}
tail->next = NULL;
}
}
template <class ItemType>
bool list<ItemType>::PrevPosition()
{
if(currPos != head)
{
tail->next = currPos;
currPos = head;
if(currPos != tail->next)
{
while(currPos->next != tail->next)
{
currPos = currPos->next;
}
}
tail->next = NULL;
return true;
}
else
{
return false;
}
}
template <class ItemType>
bool list<ItemType>::NextPosition()
{
if(currPos != tail)
{
currPos = currPos->next;
return true;
}
else
{
return false;
}
}
template <class ItemType>
void list<ItemType>::Remove()
{
if(currPos != NULL)
{
tail->next = currPos;
currPos = currPos->next;
delete tail->next;
tail->next = NULL;
}
}
template <class ItemType>
ItemType list<ItemType>::Retrieve()
{
if(currPos != NULL)
return currPos->data;
}
template <class ItemType>
bool list<ItemType>::IsFirstPosition()
{
return currPos == head;
}
template <class ItemType>
bool list<ItemType>::IsLastPosition()
{
return currPos == tail;
}
template <class ItemType>
void list<ItemType>::FirstPosition()
{
currPos = head;
}
template <class ItemType>
void list<ItemType>::LastPosition()
{
currPos = tail;
}
template <class ItemType>
ItemType list<ItemType>::operator[](unsigned int index)
{
if(head != NULL)
{
listNode<ItemType>* temp = head;
while(index > 0 && temp != NULL)
{
temp = temp->next;
--index;
}
if(temp != NULL)
{
return temp->data;
}
}
}
#include "list.cpp"
#endif

43
include/main.h Normal file
View File

@@ -0,0 +1,43 @@
#ifndef __main_h__
#define __main_h__
#include <windows.h> // Header file for windows
#include <stdio.h> // Header file for standard input/output
#include <gl\gl.h> // Header file for OpenGL32 library
#include <gl\glu.h> // Header file for Glu32 library
#include <gl\glaux.h> // Header file for GLaux library
#include <math.h>
#include "camera.h"
#include "level.h"
#include "myGL.h"
#include "WorldDefs.h"
#include "mydefs.h"
#pragma warning(disable: 4786)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Variables
static bool keys[256]; // Array for which keys are down now
static bool keys2[256]; // Array for which keys are were down already
static bool active=true; // Is window active flag
static bool fullscreen=true; // Is window fullscreen flag
static bool showConsole = false;// Do we need to draw the console
//static SCREEN g_Screen = {800,600,16,1,"OpenArena"};
static POINT mpos;
static float lastTime = 0.0f; // This will hold the time from the last frame
static float currentTime;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Function Declarations
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration for WndProc
void InitControls(); // Sets up player controls
int InitGL(); // All setup for OpenGL goes here
GLvoid ReSizeGLScene(GLsizei width, GLsizei height); // Resize and initialize the GL window
GLvoid KillGLWindow(GLvoid); //Properly kill the window
bool CreateGLWindow(string title, int width, int height, int bits, bool fullscreenflag);
#endif

8
include/mydefs.h Normal file
View File

@@ -0,0 +1,8 @@
#ifndef __mydefs_h__
#define __mydefs_h__
#include <windows.h>
static HWND g_hWnd = NULL;
#endif

25
include/mygl.h Normal file
View File

@@ -0,0 +1,25 @@
#ifndef __MYGL_H__
#define __MYGL_H__
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glaux.h>
#include <string>
#include "screen.h"
#include "tga.h"
#include "bmp.h"
#include "strmanip.h"
using namespace std;
static HDC hDC=NULL; // Private GDI device context
static HGLRC hRC=NULL; // Permanent rendering context
static HINSTANCE hInstance; // Application instance
static SCREEN g_Screen;
int InitGL(GLvoid);
bool LoadGLTexture(string , unsigned int&, int = GL_LINEAR, int = GL_LINEAR);
void FreeGLTexture(unsigned int&);
#endif

29
include/myglFont.h Normal file
View File

@@ -0,0 +1,29 @@
#ifndef __glPrint_h__
#define __glPrint_h__
#include "myGL.h"
class GLFontClass
{
private:
short screenWidth;
short screenHeight;
unsigned int base;
unsigned int texture;
bool status;
public:
GLFontClass();
~GLFontClass();
bool BuildFont(const char*);
bool FreeFont();
void Print(int, int, const char*, unsigned int = 0);
bool Status();
void SetScreenDimensions(short, short);
void SetScreenWidth(short);
void SetScreenHeight(short);
short ScreenWidth();
short ScreenHeight();
};
#endif

35
include/myglTexture.h Normal file
View File

@@ -0,0 +1,35 @@
#ifndef __myglTexture_h__
#define __myglTexture_h__
#include <string>
#include "datatypes.h"
#include "myGL.h"
using namespace std;
class GL_MY_TEXTURE
{
public:
GL_MY_TEXTURE();
~GL_MY_TEXTURE();
string Filename();
uint32 ID();
bool Load(string filename);
bool Load(string filename, uint32 min, uint32 mag);
void Free();
bool Loaded();
bool operator<(const GL_MY_TEXTURE&);
bool operator<=(const GL_MY_TEXTURE&);
bool operator==(const GL_MY_TEXTURE&);
bool operator!=(const GL_MY_TEXTURE&);
bool operator>=(const GL_MY_TEXTURE&);
bool operator>(const GL_MY_TEXTURE&);
private:
uint32 minFilter;
uint32 magFilter;
string filename;
uint32 id;
};
#endif

9
include/opengl.h Normal file
View File

@@ -0,0 +1,9 @@
#ifndef __opengl_h__
#define __opengl_h__
#include<windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glaux.h>
#endif

5
include/physics.h Normal file
View File

@@ -0,0 +1,5 @@
class WORLD_PHYSICS
{
public:
WORLD_PHYSICS();
};

27
include/player.h Normal file
View File

@@ -0,0 +1,27 @@
#ifndef __PLAYER_H__
#define __PLAYER_H__
#include "camera.h"
#include "ctrls.h"
class PLAYER
{
public:
void Load();
void Save();
void CreateCharacter();
//void FirePrimary(ENTITY& ent);
//void FireSecondary();
void AddItem(unsigned int item);
void RemoveItem(unsigned int item);
ControlSchemeClass controls;
CameraClass camera;
private:
};
#endif

28
include/screen.h Normal file
View File

@@ -0,0 +1,28 @@
#ifndef __screen_h__
#define __screen_h__
#include <string>
using namespace std;
class SCREEN
{
public:
SCREEN()
{
width=640;
height=480;
bpp=16;
fullscreen=false;
name = "";
}
short width;
short height;
char bpp;
bool fullscreen;
string name;
};
#endif

23
include/strmanip.h Normal file
View File

@@ -0,0 +1,23 @@
#ifndef __strmanip_h__
#define __strmanip_h__
#include <string>
#include <cmath>
#include <windows.h>
#include "datatypes.h"
using namespace std;
bool Truth(string str);
int Integer(string str);
float Floating(string str);
uint8 KeyName(string str);
string KeyString(uint8);
string Right(string, uint32);
string Left(string, uint32);
string tolower(string);
string toupper(string);
string word(string, uint32);
#endif

13
include/texture.h Normal file
View File

@@ -0,0 +1,13 @@
#ifndef __texture_h__
#define __texture_h__
struct TextureImage
{
unsigned char* data;
unsigned int bpp;
unsigned int sizeX;
unsigned int sizeY;
unsigned int type;
};
#endif

35
include/tga.h Normal file
View File

@@ -0,0 +1,35 @@
#ifndef __TGA_H__
#define __TGA_H__
#pragma comment(lib, "OpenGL32.lib")
#include <windows.h>
#include <gl\gl.h>
#include <stdio.h>
#include <string>
#include "texture.h"
struct TGAHeader
{
GLubyte Header[12]; // File Header To Determine File Type
};
struct TGA
{
GLubyte header[6]; // Holds The First 6 Useful Bytes Of The File
GLuint bytesPerPixel; // Number Of BYTES Per Pixel (3 Or 4)
GLuint imageSize; // Amount Of Memory Needed To Hold The Image
GLuint type; // The Type Of Image, GL_RGB Or GL_RGBA
GLuint Height; // Height Of Image
GLuint Width; // Width Of Image
GLuint Bpp; // Number Of BITS Per Pixel (24 Or 32)
};
TextureImage* LoadTGA(const char *filename);
const GLubyte uTGAcompare[12] = {0,0,2, 0,0,0,0,0,0,0,0,0}; // Uncompressed TGA Header
const GLubyte cTGAcompare[12] = {0,0,10,0,0,0,0,0,0,0,0,0}; // Compressed TGA Header
TextureImage* LoadUncompressedTGA(FILE *); // Load an Uncompressed file
TextureImage* LoadCompressedTGA(FILE *); // Load a Compressed file
#endif

57
include/vector.h Normal file
View File

@@ -0,0 +1,57 @@
#ifndef __vector_h__
#define __vector_h__
#include <cmath>
class Vec3d
{
public:
double x,y,z;
Vec3d(); //Default Constructor
Vec3d(const Vec3d&); //Copy Constructor
Vec3d(double, double); //From an angle
Vec3d(double, double, double); //From values
double lengthsquared() const;
double length() const;
void normalize();
Vec3d normalized() const;
Vec3d cross(const Vec3d&) const;
void operator=(const Vec3d&);
Vec3d operator*(const Vec3d&) const;
Vec3d operator+(const Vec3d&) const;
Vec3d operator-(const Vec3d&) const;
Vec3d operator*(double) const;
Vec3d operator/(double) const;
};
Vec3d Vector(double, double);
//Vec3d Angle2Vec3f()
class Vec2f
{
public:
float x,y;
Vec2f(); //Default Constructor
Vec2f(const Vec2f&); //Copy Constructor
Vec2f(double); // from an angle
Vec2f(double, double); //from values
double lengthsquared() const;
double length() const;
void normalize();
Vec2f normalized() const;
Vec2f cross(const Vec2f&) const;
Vec2f operator=(const Vec2f&);
Vec2f operator*(const Vec2f&) const;
Vec2f operator+(const Vec2f&) const;
Vec2f operator-(const Vec2f&) const;
//Vec2f operator/(const Vec2f&) const; //Is this right?
Vec2f operator*(double) const;
Vec2f operator/(double) const;
};
typedef Vec3d Vec3f;
#endif

8
include/worlddefs.h Normal file
View File

@@ -0,0 +1,8 @@
#ifndef __WorldDefs_h__
#define __WorldDefs_h__
#include "level.h"
static LEVEL level;
#endif

BIN
lib/bass.lib Normal file

Binary file not shown.

2
license.txt Normal file
View File

@@ -0,0 +1,2 @@
This program can be distributed under the GNU GPL with the following exception. I want to make this multiplayer compatible later on. So any modifications that have anything to do with encryption or netcode don't have to be opensource as long as a copy of the source is sent to me to peruse and possibly add to the program (with applicable credit given). Other than that OA will be open source hence the name. Alternatively you can redistribute OA under the QTPL.
If you would like to modify the source code all I want you to do is make the new source available includeing giving me a copy either by e-mail headhunter45@hotmail.com but I have the inbox protector on so make sure the subject line has something identifiable in it preferably even just OpenArena as a subject this is only necessary the first time or two you e-mail me so I can add you to my address book. Also I have created a msn community you can post a link to the source in there and I'll download it myself (http://groups.msn.com/CodersCorner).

BIN
oa.ncb Normal file

Binary file not shown.

159
oa.nsi Normal file
View File

@@ -0,0 +1,159 @@
; example2.nsi
;
; This script is based on example1.nsi, but it remember the directory,
; has uninstall support and (optionally) installs start menu shortcuts.
;
; It will install makensisw.exe into a directory that the user selects,
;--------------------------------
; The name of the installer
Name "OpenArena"
; The installer icon
Icon "${NSISDIR}\contrib\Icons\setup.ico"
; The file to write
OutFile "OpenArena-0.1.0-alpha.exe"
; The default installation directory
InstallDir "$PROGRAMFILES\HHPS\OpenArena-0.1.0-alpha"
; Registry key to check for directory (so if you install again, it will
; overwrite the old one automatically)
InstallDirRegKey HKLM SOFTWARE\HHPS\OpenArena-0.1.0-alpha "Install_Dir"
; The text to prompt the user to enter a directory
ComponentText "This will install OpenArena on your computer. Select which options you want installed."
; The text to prompt the user to enter a directory
DirText "Choose a directory to install in to:"
;--------------------------------
; The stuff to install
Section "Base (required)"
SectionIn RO
; Set output path to the installation directory.
SetOutPath $INSTDIR
; Put file there
File ".\bass.dll"
File ".\license.txt"
File ".\OpenArena User's Manual.doc"
File ".\OpenArena User's Manual.html"
SetOutPath $INSTDIR\OpenArena
File ".\bass.dll"
; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\HHPS\OpenArena-0.1.0-alpha "Install_Dir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenArena v0.1.0-alpha" "DisplayName" "OpenArena v0.1.0-alpha (remove only)"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenArena v0.1.0-alpha" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteUninstaller "uninstall.exe"
CreateDirectory "$SMPROGRAMS\HHPS\OpenArena"
SetOutPath $INSTDIR\OpenArena
CreateShortCut "$SMPROGRAMS\HHPS\OpenArena\Readme v0.1.0-alpha.lnk" "$INSTDIR\OpenArena User's Manual.html"
SectionEnd
; optional section (can be disabled by the user)
Section "SDK"
SetOutPath $INSTDIR
File ".\oa.sln"
File ".\oa.vcproj"
File ".\oa.ncb"
File ".\oa.suo"
File ".\heading.txt"
SetOutPath $INSTDIR\include
File ".\include\*.h"
SetOutPath $INSTDIR\lib
File ".\lib\*.lib"
SetOutPath $INSTDIR\src
File ".\src\*.cpp"
SetOutPath $INSTDIR\OpenArena\oa\config
File ".\OpenArena\oa\config\my.cfg"
CreateDirectory $INSTDIR\OpenArena\oa\maps
CreateDirectory $INSTDIR\OpenArena\oa\music\bgm
CreateDirectory $INSTDIR\OpenArena\oa\textures\menu
SetOutPath $INSTDIR\OpenArena
CreateShortCut "$SMPROGRAMS\HHPS\OpenArena\OpenArena SDK v0.1.0-alpha.lnk" "$INSTDIR\oa.sln"
SectionEnd
Section "Media"
SetOutPath $INSTDIR\OpenArena
File ".\OpenArena\oa.exe"
SetOutPath $INSTDIR\OpenArena\oa\config
File ".\OpenArena\oa\config\my.cfg"
SetOutPath $INSTDIR\OpenArena\oa\maps
File ".\OpenArena\oa\maps\intro.map"
File ".\OpenArena\oa\maps\oamap1.map"
SetOutPath $INSTDIR\OpenArena\oa\music\bgm
File ".\OpenArena\oa\music\bgm\*.mp3"
SetOutPath $INSTDIR\OpenArena\oa\textures
File ".\OpenArena\oa\textures\*.tga"
File ".\OpenArena\oa\textures\*.bmp"
SetOutPath $INSTDIR\OpenArena\oa\textures\menu
File ".\OpenArena\oa\textures\menu\*.bmp"
File ".\OpenArena\oa\textures\menu\*.tga"
SetOutPath $INSTDIR\OpenArena
CreateShortCut "$SMPROGRAMS\HHPS\OpenArena\OpenArena v0.1.0-alpha.lnk" "$INSTDIR\OpenArena\oa.exe"
SectionEnd
;--------------------------------
; Uninstaller
UninstallText "This will uninstall example2. Hit next to continue."
; Uninstall section
Section "Uninstall"
; remove registry keys
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenArena v0.1.0-alpha"
DeleteRegKey HKLM SOFTWARE\HHPS\OpenArena-0.1.0-alpha
; remove files and uninstaller
Delete /REBOOTOK $INSTDIR\OpenArena\*.*
Delete /REBOOTOK $INSTDIR\include\*.*
Delete /REBOOTOK $INSTDIR\lib\*.*
Delete /REBOOTOK $INSTDIR\src\*.*
Delete /REBOOTOK $INSTDIR\bass.dll
Delete /REBOOTOK $INSTDIR\heading.txt
Delete /REBOOTOK $INSTDIR\license.txt
Delete /REBOOTOK $INSTDIR\oa.ncb
Delete /REBOOTOK $INSTDIR\oa.sln
Delete /REBOOTOK $INSTDIR\oa.sou
Delete /REBOOTOK $INSTDIR\oa.vcproj
Delete /REBOOTOK "$INSTDIR\OpenArena User's Manual.doc"
Delete /REBOOTOK "$INSTDIR\OpenArena User's Manual.html"
Delete /REBOOTOK $INSTDIR\uninstall.exe
; remove shortcuts, if any
Delete /REBOOTOK "$SMPROGRAMS\HHPS\OpenArena\Readme v0.1.0-alpha.lnk"
Delete /REBOOTOK "$SMPROGRAMS\HHPS\OpenArena\OpenArena SDK v0.1.0-alpha.lnk"
Delete /REBOOTOK "$SMPROGRAMS\HHPS\OpenArena\OpenArena v0.1.0-alpha.lnk"
; remove directories used
RMDIR /r $INSTDIR\include
RMDIR /r $INSTDIR\lib
RMDIR /r $INSTDIR\OpenArena
RMDIR /r $INSTDIR\src
RMDIR /r "$INSTDIR"
SectionEnd

21
oa.sln Normal file
View File

@@ -0,0 +1,21 @@
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "oa", "oa.vcproj", "{6F5D0FF6-A032-4356-932E-865B601E0DD4}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
Release = Release
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{6F5D0FF6-A032-4356-932E-865B601E0DD4}.Debug.ActiveCfg = Debug|Win32
{6F5D0FF6-A032-4356-932E-865B601E0DD4}.Debug.Build.0 = Debug|Win32
{6F5D0FF6-A032-4356-932E-865B601E0DD4}.Release.ActiveCfg = Release|Win32
{6F5D0FF6-A032-4356-932E-865B601E0DD4}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal

BIN
oa.suo Normal file

Binary file not shown.

325
oa.vcproj Normal file
View File

@@ -0,0 +1,325 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="oa"
ProjectGUID="{6F5D0FF6-A032-4356-932E-865B601E0DD4}"
SccProjectName=""
SccLocalPath="">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory=".\OpenArena"
IntermediateDirectory=".\Release"
ConfigurationType="1"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="..\include"
PreprocessorDefinitions="WIN32,NDEBUG,_WINDOWS"
StringPooling="TRUE"
RuntimeLibrary="4"
EnableFunctionLevelLinking="TRUE"
UsePrecompiledHeader="2"
PrecompiledHeaderFile=".\Release/oa.pch"
AssemblerListingLocation=".\"
ObjectFile=".\"
ProgramDataBaseFileName=".\"
WarningLevel="3"
SuppressStartupBanner="TRUE"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="/MACHINE:I386"
AdditionalDependencies="odbc32.lib odbccp32.lib"
OutputFile=".\OpenArena\oa.exe"
Version="0.1.0-alpha"
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories=".\lib"
ProgramDatabaseFile=".\Release/oa.pdb"
SubSystem="2"/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="NDEBUG"
MkTypLibCompatible="TRUE"
SuppressStartupBanner="TRUE"
TargetEnvironment="1"
TypeLibraryName=".\Release/oa.tlb"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1033"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Debug|Win32"
OutputDirectory=".\Debug"
IntermediateDirectory=".\Debug"
ConfigurationType="1"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="FALSE"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32,_DEBUG,_WINDOWS"
BasicRuntimeChecks="3"
RuntimeLibrary="5"
UsePrecompiledHeader="2"
PrecompiledHeaderFile=".\Debug/oa.pch"
AssemblerListingLocation=".\Debug/"
ObjectFile=".\Debug/"
ProgramDataBaseFileName=".\Debug/"
WarningLevel="3"
SuppressStartupBanner="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="/MACHINE:I386"
OutputFile=".\Debug/oa.exe"
LinkIncremental="2"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories=".\lib"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile=".\Debug/oa.pdb"
SubSystem="2"/>
<Tool
Name="VCMIDLTool"
PreprocessorDefinitions="_DEBUG"
MkTypLibCompatible="TRUE"
SuppressStartupBanner="TRUE"
TargetEnvironment="1"
TypeLibraryName=".\Debug/oa.tlb"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1033"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
<File
RelativePath=".\src\bmp.cpp">
</File>
<File
RelativePath=".\src\ctrls.cpp">
</File>
<File
RelativePath=".\src\Level.cpp">
</File>
<File
RelativePath=".\src\Main.cpp">
</File>
<File
RelativePath=".\src\mygl.cpp">
</File>
<File
RelativePath=".\src\myglFont.cpp">
</File>
<File
RelativePath=".\src\myglTexture.cpp">
</File>
<File
RelativePath=".\src\Player.cpp">
</File>
<File
RelativePath=".\src\strmanip.cpp">
</File>
<File
RelativePath=".\src\tga.cpp">
</File>
<File
RelativePath=".\src\vector.cpp">
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl">
<File
RelativePath=".\Include\bass.h">
</File>
<File
RelativePath=".\Include\bmp.h">
</File>
<File
RelativePath=".\Include\camera.h">
</File>
<File
RelativePath=".\Include\critter.h">
</File>
<File
RelativePath=".\Include\ctrls.h">
</File>
<File
RelativePath=".\Include\datatypes.h">
</File>
<File
RelativePath=".\Include\entities.h">
</File>
<File
RelativePath=".\Include\entity.h">
</File>
<File
RelativePath=".\Include\geometry.h">
</File>
<File
RelativePath=".\Include\Level.h">
</File>
<File
RelativePath=".\Include\list.h">
</File>
<File
RelativePath=".\Include\Main.h">
</File>
<File
RelativePath=".\Include\mydefs.h">
</File>
<File
RelativePath=".\Include\mygl.h">
</File>
<File
RelativePath=".\Include\myglTexture.h">
</File>
<File
RelativePath=".\Include\opengl.h">
</File>
<File
RelativePath=".\Include\Player.h">
</File>
<File
RelativePath=".\Include\screen.h">
</File>
<File
RelativePath=".\Include\strmanip.h">
</File>
<File
RelativePath=".\Include\texture.h">
</File>
<File
RelativePath=".\Include\tga.h">
</File>
<File
RelativePath=".\Include\vector.h">
</File>
<File
RelativePath=".\Include\WorldDefs.h">
</File>
</Filter>
<Filter
Name="oa"
Filter="">
<Filter
Name="maps"
Filter=".map, .lit">
<File
RelativePath=".\OpenArena\oa\maps\intro.map">
</File>
<File
RelativePath=".\OpenArena\oa\maps\oamap1.map">
</File>
</Filter>
<Filter
Name="textures"
Filter=".bmp, .jpg, .tga, .png">
<File
RelativePath="OpenArena\oa\textures\groundc.tga">
</File>
<File
RelativePath="OpenArena\oa\textures\moonc.tga">
</File>
<File
RelativePath="OpenArena\oa\textures\nightSkyc.tga">
</File>
<File
RelativePath=".\OpenArena\oa\textures\test.bmp">
</File>
<Filter
Name="menu"
Filter="">
<File
RelativePath="OpenArena\oa\textures\menu\font.bmp">
</File>
</Filter>
</Filter>
<Filter
Name="config"
Filter=".cfg">
<File
RelativePath="OpenArena\oa\config\G2k.cfg">
</File>
<File
RelativePath="OpenArena\oa\config\My.cfg">
</File>
</Filter>
<Filter
Name="music"
Filter="">
<Filter
Name="bgm"
Filter="">
<File
RelativePath="OpenArena\oa\music\bgm\bgm1.mp3">
</File>
<File
RelativePath="OpenArena\oa\music\bgm\bgm2.mp3">
</File>
</Filter>
</Filter>
</Filter>
<Filter
Name="Resource Files"
Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
</Filter>
<File
RelativePath=".\heading.txt">
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

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;
}

BIN
vc70.idb Normal file

Binary file not shown.