Changed Moved resources around

~G2k
This commit is contained in:
2006-07-01 20:38:56 -04:00
parent 7faadb55bd
commit fc736f6b93
56 changed files with 481 additions and 1339 deletions

18
src/NullVideoPlugin.cpp Normal file
View File

@@ -0,0 +1,18 @@
#include "NullVideoPlugin.h"
namespace OpenArena
{
NullVideoPlugin::NullVideoPlugin(void)
{
}
NullVideoPlugin::~NullVideoPlugin(void)
{
}
OpenArena::Window* NullVideoPlugin::CreateNewWindow(uint32 width, uint32 height, uint32 bpp, bool fullscreen, const char* title)
{
return new OpenArena::Window();
}
};

17
src/NullVideoPlugin.h Normal file
View File

@@ -0,0 +1,17 @@
#pragma once
#include "VideoPlugin.h"
namespace OpenArena
{
class NullVideoPlugin :
public OpenArena::VideoPlugin
{
public:
NullVideoPlugin(void);
public:
virtual ~NullVideoPlugin(void);
virtual Window* CreateNewWindow(uint32 width, uint32 height, uint32 bpp = 32, bool fullscreen = false, const char* title = NULL);
};
};

13
src/Plugin.h Normal file
View File

@@ -0,0 +1,13 @@
#pragma once
namespace OpenArena
{
class Plugin
{
public:
virtual ~Plugin(void){}
enum Type {VideoPlugin, AudioPlugin, InputPlugin};
};
};

25
src/PluginManager.cpp Normal file
View File

@@ -0,0 +1,25 @@
#include "PluginManager.h"
#include "NullVideoPlugin.h"
namespace OpenArena
{
PluginManager::PluginManager(void)
{
}
PluginManager::~PluginManager(void)
{
}
list<Plugin*> PluginManager::GetPluginsOfType(Plugin::Type type)
{
return list<Plugin*>();
}
VideoPlugin* PluginManager::GetDefaultVideoPlugin(void)
{
return new NullVideoPlugin();
}
};

26
src/PluginManager.h Normal file
View File

@@ -0,0 +1,26 @@
#pragma once
#include "list.h"
#include "Plugin.h"
#include "VideoPlugin.h"
namespace OpenArena
{
/**
* Perhaps this class should be a singleton.
*/
class PluginManager
{
private:
list<Plugin*> _plugins;
public:
/**
* Creates a new PluginManager object
*/
PluginManager(void);
~PluginManager(void);
list<Plugin*> GetPluginsOfType(Plugin::Type type);
VideoPlugin* GetDefaultVideoPlugin(void);
};
};

19
src/VideoPlugin.h Normal file
View File

@@ -0,0 +1,19 @@
#pragma once
#include "Plugin.h"
#include "window.h"
#include "datatypes.h"
namespace OpenArena
{
class VideoPlugin :public Plugin
{
public:
public:
virtual ~VideoPlugin(){}
virtual Window* CreateNewWindow(uint32 width,
uint32 height,
uint32 bpp = 32,
bool fullscreen = false,
const char* title = NULL) = 0;
};
};

View File

@@ -19,48 +19,208 @@
////////////////////////////////////////////////////////////////////////////////
#include <cstdio>
#include "../include/bmp.h"
#include "bmp.h"
#ifdef WIN32
#pragma warning(disable:4996)
#endif
namespace OpenArena{
#pragma pack(push,1)
struct BITMAP_HEADER
Bitmap::Bitmap()
{
uint16 type;
uint32 size;
uint16 reserved1;
uint16 reserved2;
uint32 offset;
};
Bitmap(1, 1);
}
struct BITMAP_INFO
Bitmap::Bitmap(uint32 width, uint32 height, uint32 bitsPerPixel, Image::Type type)
{
uint32 size;
uint32 width;
uint32 height;
uint16 planes;
uint16 bitCount;
uint32 compression;
uint32 sizeImage;
uint32 xPelsPerMeter;
uint32 yPelsPerMeter;
uint32 clrUsed;
uint32 clrImportant;
};
_width = width;
_height = height;
_bpp = bitsPerPixel;
_type = type;
_data = new uint8[_width * _height * (_bpp >> 3)];
}
struct BITMAP_QUAD
Bitmap::~Bitmap()
{
uint8 blue;
uint8 green;
uint8 red;
uint8 reserved;
};
#pragma pack(pop)
delete [] _data;
}
#define BITMAP_MAGIC 19778
uint8 * Bitmap::GetImageData() const
{
return _data;
}
uint32 Bitmap::GetBitsPerPixel() const
{
return _bpp;
}
uint32 Bitmap::GetBytesPerPixel() const
{
return _bpp >> 3;
}
uint32 Bitmap::GetWidth() const
{
return _width;
}
uint32 Bitmap::GetHeight() const
{
return _height;
}
Image::Type Bitmap::GetType() const
{
return _type;
}
Bitmap* Bitmap::CreateFromFile(const char* filename)
{
FILE* file = NULL; //A file from cstdlib?
//If our filename is null return an empty 1x1 image
if(filename == NULL)
{
return new Bitmap(1,1);
}
//Try to open the file
file = fopen(filename, "rb");
//If the open failed return an empry 1x1 image
if(file == NULL)
{
return new Bitmap(1,1);
}
BITMAP_HEADER bmpHeader;
BITMAP_INFO bmpInfo;
BITMAP_QUAD* pallette = NULL;
uint32 numPalletteEntries = 0;
uint32 numPixels;
//Read the header from the file
fread(&bmpHeader, sizeof(bmpHeader), 1, file);
fread(&bmpInfo, sizeof(bmpInfo), 1, file);
//Check for an invalid header
if(bmpInfo.width < 0) //See if the width is negative
{
//This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Image width is negative", "ERROR", MB_OK);
#endif
fclose(file);
return NULL;
}
if(bmpInfo.width % 4 != 0) //If the width is not a multiple of 4
{
//This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Image width must be a multiple of 8", "ERROR", MB_OK);
#endif
fclose(file);
return NULL;
}
if(bmpInfo.height < 0) //If the height is negative
{
//This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Image height is negative", "ERROR", MB_OK);
#endif
fclose(file);
return NULL;
}
if(bmpInfo.height % 4 != 0) //If the height is not a multiple of 4
{
//This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Image height must be a multiple of 8", "ERROR", MB_OK);
#endif
fclose(file);
return NULL;
}
if((bmpInfo.bitCount != 8 && bmpInfo.bitCount != 24) || bmpInfo.compression != 0) //Make sure the file is 8 or 24 bit and uncompressed
{ //This needs to be abstracted somehow
#ifdef WIN32
MessageBox(NULL, "Only 8 and 24 bit uncompressed windows bmp files are currently supported", "ERROR", MB_OK);
#endif
fclose(file);
return NULL;
}
Bitmap* image = new Bitmap(bmpInfo.width, bmpInfo.height, bmpInfo.bitCount, (Type)GL_RGB);
numPixels = image->GetWidth() * image->GetHeight();
//If 8-bit load the pallette
if(image->GetBitsPerPixel() == 8)
{
//TODO finish this
numPalletteEntries = image->GetBytesPerPixel();
pallette = new BITMAP_QUAD[numPalletteEntries];
// fread(pallette, sizeof(OpenArena::Bitmap::BITMAP_QUAD), pallette, file);
}
//Seek to the start of data
fseek(file, bmpHeader.offset, SEEK_SET);
//Read the image data
fread(image->_data, numPixels * image->GetBytesPerPixel(), 1, file);
//If 8-bit apply the pallette
if(image->GetBitsPerPixel() == 8)
{
//TODO finish this
uint32 i1, i2;
for(i1=0; i1<numPixels; i1++)
{
i2 = (i1 << 1) + 1;
if(image->_data[i1] < numPalletteEntries)
{
image->_data[i2] = pallette[image->_data[i1]].red;
image->_data[i2+1] = pallette[image->_data[i1]].blue;
image->_data[i2+2] = pallette[image->_data[i1]].green;
}
}
//uint8* image = tex->data;
//tex->bpp = 24;
//bytes = pixels * tex->bpp;
//tex->data = new uint8[bytes];
//uint32 i;
//uint32 i2;
//for(i=0; i<pixels; i++)
//{
// i2 = (i << 1) + 1;
// //Should make sure image[i] < palletteEntries
// tex->data[i2] = bmpPallette[image[i]].red;
// tex->data[i2 + 1] = bmpPallette[image[i]].blue;
// tex->data[i2 + 2] = bmpPallette[image[i]].green;
//}
//delete [] image;
//image = NULL;
}
else if(image->GetBitsPerPixel() == 24)
{
//Convert to rgb
uint32 i;
uint8 swap;
for(i=0; i<numPixels * image->GetBytesPerPixel(); i+=3)
{
swap = image->_data[i];
image->_data[i] = image->_data[i+2];
image->_data[i+2] = swap;
}
}
return image;
}
TextureImage* LoadBMP(const char* fn)
{
@@ -77,9 +237,9 @@ namespace OpenArena{
f=fopen(fn, "rb");
if(f)
{
BITMAP_HEADER bmpHeader;
BITMAP_INFO bmpInfo;
BITMAP_QUAD* bmpPallette = NULL;
Bitmap::BITMAP_HEADER bmpHeader;
Bitmap::BITMAP_INFO bmpInfo;
Bitmap::BITMAP_QUAD* bmpPallette = NULL;
uint32 palletteEntries = 0;
fread(&bmpHeader, sizeof(bmpHeader), 1, f);
@@ -152,8 +312,8 @@ namespace OpenArena{
{
//Load the pallette
palletteEntries = bmpInfo.bitCount << 8;
bmpPallette = new BITMAP_QUAD[palletteEntries];
fread(bmpPallette, sizeof(BITMAP_QUAD), palletteEntries, f);
bmpPallette = new Bitmap::BITMAP_QUAD[palletteEntries];
fread(bmpPallette, sizeof(Bitmap::BITMAP_QUAD), palletteEntries, f);
}
fseek(f, bmpHeader.offset, SEEK_SET);

69
src/bmp.h Normal file
View File

@@ -0,0 +1,69 @@
#ifndef __bmp_h__
#define __bmp_h__
#include "Image.h"
#include "mygl.h"
#include "datatypes.h"
#include "texture.h"
namespace OpenArena{
TextureImage* LoadBMP(const char* Filename);
class Bitmap :Image
{
public:
virtual ~Bitmap();
virtual uint8 * GetImageData() const;
virtual uint32 GetBitsPerPixel() const;
virtual uint32 GetBytesPerPixel() const;
virtual uint32 GetWidth() const;
virtual uint32 GetHeight() const;
virtual Image::Type GetType() const;
static Bitmap* CreateFromFile(const char* filename);
private:
Bitmap();
Bitmap(uint32 width, uint32 height, uint32 = 24, Image::Type = Image::Type_RGB);
uint8* _data;
uint32 _width;
uint32 _height;
uint32 _bpp;
Image::Type _type;
public:
#pragma pack(push,1)
struct BITMAP_HEADER
{
uint16 type;
uint32 size;
uint16 reserved1;
uint16 reserved2;
uint32 offset;
};
struct BITMAP_INFO
{
uint32 size;
uint32 width;
uint32 height;
uint16 planes;
uint16 bitCount;
uint32 compression;
uint32 sizeImage;
uint32 xPelsPerMeter;
uint32 yPelsPerMeter;
uint32 clrUsed;
uint32 clrImportant;
};
struct BITMAP_QUAD
{
uint8 blue;
uint8 green;
uint8 red;
uint8 reserved;
};
#pragma pack(pop)
#define BITMAP_MAGIC 19778
};
};
#endif

View File

@@ -44,7 +44,7 @@
//
////////////////////////////////////////////////////////////////////////////////
#include "../include/camera.h"
#include "camera.h"
namespace OpenArena
{
@@ -71,7 +71,7 @@ namespace OpenArena
m_vUpVector = up;
}
void Camera::SetViewByMouse(Window window)
void Camera::SetViewByMouse(const Window* window)
{
//Remove the ifdef and use the linux section for both linux and windows
#ifdef __linux
@@ -112,8 +112,8 @@ namespace OpenArena
POINT mpos;
POINT middle;
double angleZ;
middle.x = window.GetWidth() / 2;
middle.y = window.GetHeight() / 2;
middle.x = window->GetWidth() / 2;
middle.y = window->GetHeight() / 2;
GetCursorPos(&mpos);
SetCursorPos(middle.x, middle.y);
if(mpos.x != middle.x || mpos.y != middle.y)

100
src/camera.h Normal file
View File

@@ -0,0 +1,100 @@
#ifndef __camera_h__
#define __camera_h__
#include <cmath>
#ifdef WIN32
#include <windows.h> //Currently used for mouse stuff this should be replaced by oa_input
#endif
#include "vector.h"
#include "mygl.h"
#include "screen.h"
namespace OpenArena
{
class Camera
{
public:
//Constructors
Camera(); //Default Constructor
//Purpose:
// Creates a new Camera object located at the origin, pointing at the negative z-axis with up being the positive y-axis
//Camera(const Camera&); //Copy Constructor
//Purpose:
//
//Observer Accessors
Vec3f Position();
//Purpose:
// Returns the position vector of this camera.
// This vector is the location of the camera.
Vec3f View();
//Purpose:
// Returns the view vector of this camera.
// This vector is the direction the camera is pointing.
Vec3f UpVector();
//Purpose:
// Returns the up vector of this camera.
// This vector points up in the rendered view.
Vec3f Strafe();
//Purpose:
// Returns the strafe vector fo this camera.
// This is the direction StrafeCamera will move
//Mutators
void PositionCamera(double xpos, double ypos, double zpos,
double xview, double yview, double zview,
double xup, double yup, double zup);
//Purpose:
// Relocates and reorientates the camera as determined by the given vector components.
void PositionCamera(Vec3f pos, Vec3f view, Vec3f up);
//Purpose:
// Relocates and reorientates the camera as determined by the given vectos.
void Camera::RotateView(double angle, Vec3d axis);
//Purpose:
// Rotates the camera by angle degrees about the axis specified by axis.
void RotateView(double angle, double X, double Y, double Z);
//Purpose:
// Rotates the camera by angle degrees about the axis specified by the given components.
// Works the same as glRotatef(angle, X, Y, Z).
void SetViewByMouse(const Window* window);
//Purpose:
// Updates the view Vector based on the change in mouse position since the last time it was called.
//This function needs to be reimagined and better fleshed out.
//void RotateAroundPoint(Vec3f vCenter, double X, double Y, double Z);
//Purpose:
// Rotates the camera arount the point vCenter X degrees around the x-axis, Y degrees around the y-axis, and Z degrees around the z-axis in that order
void StrafeCamera(double speed);
//Purpose:
// Moves the camera along it's strafe vector speed units.
void MoveCamera(double speed);
//Purpose:
// Moves the camera along it's view vector speed units.
void Update();
//Purpose:
// Recalculates the strafe vector.
void Look();
//Purpose:
// Calls gluLookAt with stored values to set the scene to the camera.
private:
Vec3f m_vPosition;
Vec3f m_vView;
Vec3f m_vUpVector;
Vec3f m_vStrafe;
};
};
#endif

View File

@@ -65,7 +65,7 @@
//
////////////////////////////////////////////////////////////////////////////////
#include "../include/ctrls.h"
#include "ctrls.h"
namespace OpenArena{
void ControlScheme::LoadDefaultControlScheme()

42
src/ctrls.h Normal file
View File

@@ -0,0 +1,42 @@
#include "keys.h"
#include "physics.h"
#include "datatypes.h"
#include "list.h"
namespace OpenArena{
class ControlScheme
{
public:
enum Action{ACTION_FORWARD, ACTION_BACKWARD, ACTION_LOOKLEFT, ACTION_LOOKRIGHT, ACTION_LOOKUP,
ACTION_LOOKDOWN, ACTION_MOVELEFT, ACTION_MOVERIGHT, ACTION_MOVEUP, ACTION_MOVEDOWN,
ACTION_ROLLLEFT, ACTION_ROLLRIGHT, ACTION_FIREPRIMARY, ACTION_FIRESECONDARY,
ACTION_WEAPONNEXT, ACTION_WEAPONPREV, ACTION_TOGGLE_LIGHTS, ACTION_TOGGLE_FPS,
ACTION_TOGGLE_CONSOLE, ACTION_TOGGLE_MOUSELOOK, ACTION_QUICKMOUSELOOK};
void LoadDefaultControlScheme();
void ClearControlScheme();
void Unbind(uint8);
bool Bind(uint32, uint8);
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;
};
};

58
src/datatypes.h Normal file
View File

@@ -0,0 +1,58 @@
#ifndef __datatypes_h__
#define __datatypes_h__
#ifdef WIN32 //Make this MSVC something
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
#ifdef __GNUC__ //ie if we are using GCC //used to be __linux
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned long uint32;
typedef unsigned long long uint64;
typedef char int8;
typedef short int16;
typedef long int32;
typedef long long int64;
typedef signed char sint8;
typedef signed short sint16;
typedef signed long sint32;
typedef signed long long sint64;
/*
typedef unsigned char byte;
typedef unsigned short word;
typedef unsigned long dword;
typedef unsigned long long qword;
typedef byte db;
typedef word dw;
typedef dword dd;
typedef qword dq;
*/
#endif
#endif

60
src/entities.h Normal file
View File

@@ -0,0 +1,60 @@
//Yank/rename these maybe MapEntities
using namespace std;
using OpenArena::Vec3d;
struct LIGHT
{
GLfloat coords[4];
GLfloat color[4];
};
struct PLAYER_START
{
Vec3d coords;
Vec3d heading;
};
struct PLAYER_DEATHMATCH_START
{
Vec3d coords;
Vec3d heading;
};
struct BOT_START
{
Vec3d coords;
Vec3d heading;
string name;
};
struct GEOMETRY
{
int x;
};
struct PROJECTILE
{
Vec3d heading;
Vec3d start;
Vec3d 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

31
src/entity.h Normal file
View File

@@ -0,0 +1,31 @@
//Yank/rename this class
#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

15
src/geometry.h Normal file
View File

@@ -0,0 +1,15 @@
#include "vector.h"
#include "myglTexture.h"
namespace OpenArena
{
class Triangle
{
public:
Texture texture;
uint32 texID;
Vec3f vertecies[3];
Vec2f texCoords[3];
Vec3f normal;
};
};

21
src/image.h Normal file
View File

@@ -0,0 +1,21 @@
#pragma once
#include "datatypes.h"
namespace OpenArena
{
class Image
{
public:
//RGB should equal GL_RGB;
enum Type{Type_RGB};
virtual uint8 * GetImageData() const = 0;
virtual uint32 GetBitsPerPixel() const = 0;
virtual uint32 GetBytesPerPixel() const = 0;
virtual uint32 GetWidth() const = 0;
virtual uint32 GetHeight() const = 0;
virtual Image::Type GetType() const = 0;
virtual ~Image(void){}
};
};

View File

@@ -1,4 +1,4 @@
#include "../include/keys.h"
#include "keys.h"
char OpenArena::KeyToASCII(Keys key, bool shift)
{

117
src/keys.h Normal file
View File

@@ -0,0 +1,117 @@
#ifndef __keys_h__
#define __keys_h__
namespace OpenArena
{
enum Keys{
KEY_UNKNOWN = 0,
KEY_BUTTON0,
KEY_BUTTON1,
KEY_BUTTON2,
KEY_BUTTON3,
KEY_BUTTON4,
KEY_LEFT,
KEY_RIGHT,
KEY_UP,
KEY_DOWN,
KEY_SPACE,
KEY_RETURN,
KEY_SHIFT,
KEY_PAUSE,
KEY_CONTROL,
KEY_CAPITAL,
KEY_ESCAPE,
KEY_PRIOR,
KEY_NEXT,
KEY_END,
KEY_HOME,
KEY_INSERT,
KEY_DELETE,
KEY_LWIN,
KEY_RWIN,
KEY_APPS,
KEY_NUMPAD0,
KEY_NUMPAD1,
KEY_NUMPAD2,
KEY_NUMPAD3,
KEY_NUMPAD4,
KEY_NUMPAD5,
KEY_NUMPAD6,
KEY_NUMPAD7,
KEY_NUMPAD8,
KEY_NUMPAD9,
KEY_MULTIPLY,
KEY_ADD,
KEY_SUBTRACT,
KEY_DIVIDE,
KEY_F1,
KEY_F2,
KEY_F3,
KEY_F4,
KEY_F5,
KEY_F6,
KEY_F7,
KEY_F8,
KEY_F9,
KEY_F10,
KEY_F11,
KEY_F12,
KEY_NUMLOCK,
KEY_SCROLL,
KEY_SEPARATOR,
KEY_OEM_1,
KEY_OEM_2,
KEY_OEM_3,
KEY_OEM_4,
KEY_OEM_5,
KEY_OEM_6,
KEY_OEM_7,
KEY_OEM_PERIOD,
KEY_OEM_PLUS,
KEY_OEM_MINUS,
KEY_OEM_COMMA,
KEY_BACK,
KEY_TAB,
KEY_0,
KEY_1,
KEY_2,
KEY_3,
KEY_4,
KEY_5,
KEY_6,
KEY_7,
KEY_8,
KEY_9,
KEY_A,
KEY_B,
KEY_C,
KEY_D,
KEY_E,
KEY_F,
KEY_G,
KEY_H,
KEY_I,
KEY_J,
KEY_K,
KEY_L,
KEY_M,
KEY_N,
KEY_O,
KEY_P,
KEY_Q,
KEY_R,
KEY_S,
KEY_T,
KEY_U,
KEY_V,
KEY_W,
KEY_X,
KEY_Y,
KEY_Z
};
const Keys KEY_LBUTTON = KEY_BUTTON0;
const Keys KEY_RBUTTON = KEY_BUTTON1;
const Keys KEY_MBUTTON = KEY_BUTTON2;
char KeyToASCII(Keys key, bool shift);
};
#endif

View File

@@ -24,8 +24,8 @@
//
////////////////////////////////////////////////////////////////////////////////
#include "../include/level.h"
#include "../include/version.h"
#include "level.h"
#include "version.h"
#pragma comment(lib, "bass.lib")
#ifdef WIN32
@@ -40,7 +40,6 @@ namespace OpenArena
_window = NULL;
textureNames = NULL;
numTextures = 0;
textures = NULL;
screen.SetName(OPENARENA_VERSION);
@@ -417,12 +416,15 @@ namespace OpenArena
}
//Free all map textures
textures.Clear();
/*
if(textures)
{
delete [] textures;
textures = NULL;
}
*/
//Free the array of texture names
if (textureNames)
{
@@ -433,23 +435,22 @@ namespace OpenArena
void Level::LoadGLTextures()
{
printf("In LoadGLTextures: _window = %d\n", _window);
if(_window != NULL)
{
/*
GLfloat light[4] = {1.0f,1.0f,1.0f,0.5f};
glLightfv(GL_LIGHT1, GL_AMBIENT, light);
/*GLfloat light[4] = {1.0f,1.0f,1.0f,0.5f};
glLightfv(GL_LIGHT1, GL_AMBIENT, light);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHTING);
*/
if(textures != NULL)
glEnable(GL_LIGHTING);*/
textures.Clear();
/* if(textures != NULL)
{
delete [] textures;
}
textures = new Texture[numTextures];
*/
for(uint32 i=0; i<numTextures; i++)
{
if(!textures[i].Load(gamedir + "textures/" + textureNames[i]))
@@ -457,7 +458,9 @@ namespace OpenArena
}
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"))

121
src/level.h Normal file
View File

@@ -0,0 +1,121 @@
#ifndef __LEVEL_H__
#define __LEVEL_H__
#ifdef WIN32
#include <windows.h> //prolly used for alot but should be removed
#endif
#include <string>
#include <fstream>
#include <cctype>
#include <cmath>
#include <iostream>
#ifdef WIN32
#include <GL/gl.h>
#endif
#ifdef __linux
#include <GL/gl.h>
#endif
#ifdef __APPLE___
#include <gl.h>
#endif
#include <cstdio> //for file I/O
#include "mydefs.h"
#include "bmp.h"
#include "tga.h"
#include "list.h"
#ifdef WIN32
#include "../lib/bass.h" //for audio in windows only this should be replaced by oa_audio
#endif
#include "vector.h"
#include "camera.h"
#include "entities.h"
#include "geometry.h"
#include "myglFont.h"
#include "myglTexture.h"
#include "player.h"
#include "strmanip.h"
#include "keys.h"
using namespace std;
using OpenArena::Triangle;
namespace OpenArena
{
const float piover180 = 0.0174532925f;
const string DEFAULT_TEXTURE_NAME = "oa/textures/default.bmp";
const unsigned int MAX_CONSOLE_LINES = 30; //The max number of lines to be displayed in the console
const unsigned int MAX_CONSOLE_HISTORY_LINES = MAX_CONSOLE_LINES + 20; //The max number of console lines to store in the history
const unsigned int MAX_CONSOLE_OUTPUT_LINES = MAX_CONSOLE_LINES;
const unsigned int MAX_OUTPUT_TEXT_LINES = 4; //The max number of output lines to be displayed on the screen
enum {GL_MY_TEXTURE_CONSOLEBACKGROUND=0, NUM_MENU_TEXTURES};
class Level
{
public:
Level();
~Level();
bool LoadMap(string mapname);
bool 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();
void UpdateConsole(char);
uint32 FPS();
void ParseCmds(const char*);
void Print(int x, int y, const char* string, unsigned int set);
void SetWindow(Window*);
Window* GetWindow();
/*Not Yet Implemented
void PlayerConnect(); // implement later
void PlayerDisconnect(); // implement later
*/
Screen screen;
Font glFont;
string nextLevel;
Player* defaultPlayer;
uint32 numTextures;
string* textureNames;
string bgm;
#ifdef WIN32
HSTREAM bgmStream;
#endif
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<Texture> textures;
//Texture* textures;
Texture menuTextures[NUM_MENU_TEXTURES];
Window* _window;
// private:
void ConsolePrint(string);
private:
string consoleHistory[MAX_CONSOLE_HISTORY_LINES];
string consoleOutput[MAX_CONSOLE_OUTPUT_LINES];
string outputText[MAX_OUTPUT_TEXT_LINES];
};
};
#endif

380
src/list.h Normal file
View File

@@ -0,0 +1,380 @@
#ifndef __list_h__
#define __list_h__
#include <cstdlib>
#pragma warning(disable:4715)
namespace OpenArena{
typedef unsigned int LIST_ARRAY_INDEX_TYPE;
template <class ItemType>
class listNode
{
public:
listNode();
ItemType data;
listNode<ItemType>* next;
};
template <class ItemType>
class list
{
public:
list();
~list();
list(const list&);
bool IsEmpty() const;
bool IsFull() const;
void Insert(ItemType newItem);
void Remove(ItemType target);
void Remove();
ItemType Retrieve() const;
bool PrevPosition();
bool NextPosition();
bool IsFirstPosition() const;
bool IsLastPosition() const;
void FirstPosition();
void LastPosition();
void Clear();
bool Contains(ItemType) const;
unsigned int Length();
void operator=(const list<ItemType>&);
ItemType operator[](LIST_ARRAY_INDEX_TYPE) const;
ItemType& operator[](LIST_ARRAY_INDEX_TYPE);
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();
if(!rtOp.IsEmpty())
{
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() const
{
return head == NULL;
}
template <class ItemType>
bool list<ItemType>::IsFull() const
{
return false;
}
template <class ItemType>
void list<ItemType>::Insert(ItemType newItem)
{
listNode<ItemType>* temp = head;
listNode<ItemType>* temp2 = NULL;
if(head == NULL)
{
temp = tail = head = new listNode<ItemType>;
}
else
{
if(newItem < head->data)
{
temp2 = head;
temp = head = new listNode<ItemType>;
head->next = temp2;
temp2 = NULL;
}
else
{
//temp = head;
while(temp->next != NULL && newItem > temp->next->data)
{
temp = temp->next;
}
temp2 = temp->next;
temp = temp->next = new listNode<ItemType>;
temp->next = temp2;
temp2 = NULL;
}
}
temp->data = newItem;
if(temp->next == NULL)
{
tail = temp;
}
}
template <class ItemType>
void list<ItemType>::Remove(ItemType target)
{
if(head != NULL)
{
listNode<ItemType>* temp = head;
listNode<ItemType>* temp2 = head;
while(temp->next != NULL && temp->data != target)
{
temp2 = temp;
temp = temp->next;
}
if(temp->data == target)
{
if(temp != head)
{
temp2->next = temp->next;
delete temp;
}
else
{
if(tail == head)
tail = NULL;
head = head->next;
delete temp2;
}
}
}
}
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() const
{
if(currPos != NULL)
return currPos->data;
}
template <class ItemType>
bool list<ItemType>::IsFirstPosition() const
{
return currPos == head;
}
template <class ItemType>
bool list<ItemType>::IsLastPosition() const
{
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[](LIST_ARRAY_INDEX_TYPE index) const
{
if(head == NULL)
{
//We should throw an exception here but instead I'll just return shit guess for now if somebody does this they're just fucked.
}
else
{
listNode<ItemType>* temp = head;
LIST_ARRAY_INDEX_TYPE current;
for(current=0;current <index; current++)
{
if(temp->next == NULL)
{
temp->next = new listNode<ItemType>;
}
temp = temp->next;
}
return temp->data;
}
}
template <class ItemType>
ItemType& list<ItemType>::operator[](LIST_ARRAY_INDEX_TYPE index)
{
if(head == NULL)
{
tail = currPos = head = new listNode<ItemType>;
return (ItemType&)(head->data);
}
else
{
listNode<ItemType>* temp = head;
LIST_ARRAY_INDEX_TYPE current;
for(current=0;current <index; current++)
{
if(temp->next == NULL)
{
temp->next = new listNode<ItemType>;
}
temp = temp->next;
}
return (ItemType&)(temp->data);
}
}
template <class ItemType>
unsigned int list<ItemType>::Length()
{
if (head == NULL)
{
return 0;
}
else
{
int len = 1;
listNode<ItemType> temp = head->next;
while (temp != NULL)
{
temp = temp->next;
len++;
}
return len;
}
}
template<class ItemType>
bool list<ItemType>::Contains(ItemType value) const
{
listNode<ItemType>* temp = head;
while(temp != NULL)
{
if(temp->data == value)
{
return true;
}
temp = temp->next;
}
return false;
}
};
#endif

62
src/main.h Normal file
View File

@@ -0,0 +1,62 @@
#ifndef __main_h__
#define __main_h__
#ifdef WIN32
#include <windows.h> // Header file for windows
#endif
#include <cstdio> // Header file for standard input/output
#ifdef WIN32
#include <GL/gl.h> // Header file for OpenGL32 library
#include <GL/glu.h> // Header file for Glu32 library
#endif
#ifdef __linux
#include <GL/gl.h> // Header file for OpenGL32 library
#include <GL/glu.h> // Header file for Glu32 library
#endif
#ifdef __APPLE__
#include <GL/gl.h> // Header file for OpenGL32 library
#include <GL/glu.h> // Header file for Glu32 library
#endif
#include <math.h>
#include "camera.h"
#include "level.h"
#include "mygl.h"
#include "worlddefs.h"
#include "mydefs.h"
#include "screen.h"
#include "window.h"
#include "vector.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 OpenArena::Vec2i g_mousePosition;
#ifdef WIN32
static POINT mpos;
#endif
static float lastTime = 0.0f; // This will hold the time from the last frame
static float currentTime;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Function Declarations
//This shouldn't need to be here
//LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration for WndProc
void InitControls(); // Sets up player controls
int InitGL(); // All setup for OpenGL goes here
void ReSizeGLScene(GLsizei width, GLsizei height); // Resize and initialize the GL window
#endif

7
src/mydefs.h Normal file
View File

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

View File

@@ -1,12 +1,13 @@
#include "../include/mygl.h"
#include "mygl.h"
namespace OpenArena
{
void FreeGLTexture(GLuint texture)
void FreeGLTexture(GLuint& texture)
{
glDeleteTextures(1, texture);
glDeleteTextures(1, &texture);
}
bool LoadGLTexture(string fn, GLuint texture, GLuint mag, GLuint min)
bool LoadGLTexture(string fn, GLuint& texture, GLuint mag, GLuint min)
{
if(Right(tolower(fn), 4) == ".bmp")
{
@@ -63,4 +64,4 @@ namespace OpenArena
}
};
OpenArena::Window g_Screen;
OpenArena::Window* g_Screen = NULL;

40
src/mygl.h Normal file
View File

@@ -0,0 +1,40 @@
#ifndef __MYGL_H__
#define __MYGL_H__
#ifdef WIN32
#include <windows.h> //Remove if possible
#include <GL/gl.h>
#include <GL/glu.h>
#endif
#ifdef __linux
#include <GL/gl.h>
#include <GL/glu.h>
#endif
#ifdef __APPLE__
#include <GL/gl.h>
#include <GL/glu.h>
#endif
//#include <gl/glaux.h> //Hopefully nothing needs this remove if it works in windows
#include <string>
#include "datatypes.h"
#include "screen.h"
#include "tga.h"
#include "bmp.h"
#include "strmanip.h"
#include "window.h"
using namespace std;
#ifdef WIN32
//These this is windows specific
static HINSTANCE hInstance; // Application instance
#endif
extern OpenArena::Window* g_Screen;
//This doesn't need to be here I think
//int InitGL(GLvoid);
namespace OpenArena
{
bool LoadGLTexture(string , GLuint&, GLuint = GL_LINEAR, GLuint = GL_LINEAR);
void FreeGLTexture(GLuint);
};
#endif

View File

@@ -23,7 +23,7 @@
//
////////////////////////////////////////////////////////////////////////////////
#include "../include/myglFont.h"
#include "myglFont.h"
namespace OpenArena
{
@@ -45,7 +45,7 @@ namespace OpenArena
{
FreeFont();
if(LoadGLTexture(texName, texture, GL_NEAREST, GL_NEAREST))
if(OpenArena::LoadGLTexture(texName, texture, GL_NEAREST, GL_NEAREST))
{
float x, y;
base = glGenLists(256);

31
src/myglFont.h Normal file
View File

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

View File

@@ -1,4 +1,4 @@
#include "../include/myglTexture.h"
#include "myglTexture.h"
using namespace OpenArena;
namespace OpenArena
@@ -43,7 +43,7 @@ namespace OpenArena
}
else
{
id = 0xFFFFFFFF;
id=0xFFFFFFFF;
return false;
}
}
@@ -83,31 +83,31 @@ namespace OpenArena
bool Texture::operator<(const Texture& rtOp)
{
return id < rtOp.id;
return id<rtOp.id;
}
bool Texture::operator<=(const Texture& rtOp)
{
return id<= rtOp.id;
return id<=rtOp.id;
}
bool Texture::operator==(const Texture& rtOp)
{
return id== rtOp.id;
return id==rtOp.id;
}
bool Texture::operator!=(const Texture& rtOp)
{
return id!= rtOp.id;
return id!=rtOp.id;
}
bool Texture::operator>=(const Texture& rtOp)
{
return id>= rtOp.id;
return id>=rtOp.id;
}
bool Texture::operator>(const Texture& rtOp)
{
return id> rtOp.id;
return id>rtOp.id;
}
};

37
src/myglTexture.h Normal file
View File

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

31
src/oa_audio.h Normal file
View File

@@ -0,0 +1,31 @@
#ifndef __oa_audio_h__
#define __oa_audio_h__
#include "vector.h"
//NO REAL work is done by _init or _fini they should just call
// Init and DeInit instead.
void _init();
void _fini();
void Init();
void DeInit();
namespace OpenArena
{
namespace Audio
{
class Stream
{
Stream();
Stream(const char* filename);
bool Load(const char* filename);
void UnLoad();
bool Play();
bool Play3D();
SetPosition(Vec3d position);
Vec3d GetPosition();
};
};
};
#endif

18
src/oa_game.h Normal file
View File

@@ -0,0 +1,18 @@
#ifndef __oa_game_h__
#define __oa_game_h__
//NO REAL work is done by _init or _fini they should just call
// Init and DeInit instead.
void _init();
void _fini();
void Init();
void DeInit();
namespace OpenArena
{
namespace Game
{
};
};
#endif

18
src/oa_input.h Normal file
View File

@@ -0,0 +1,18 @@
#ifndef __oa_input_h__
#define __oa_input_h__
//NO REAL work is done by _init or _fini they should just call
// Init and DeInit instead.
void _init();
void _fini();
void Init();
void DeInit();
namespace OpenArena
{
namespace Input
{
};
};
#endif

18
src/oa_net.h Normal file
View File

@@ -0,0 +1,18 @@
#ifndef __oa_net_h__
#define __oa_net_h__
//NO REAL work is done by _init or _fini they should just call
// Init and DeInit instead.
void _init();
void _fini();
void Init();
void DeInit();
namespace OpenArena
{
namespace Net
{
};
};
#endif

18
src/oa_video.h Normal file
View File

@@ -0,0 +1,18 @@
#ifndef __oa_video_h__
#define __oa_video_h__
//NO REAL work is done by _init or _fini they should just call
// Init and DeInit instead.
void _init();
void _fini();
void Init();
void DeInit();
namespace OpenArena
{
namespace Video
{
};
};
#endif

9
src/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

View File

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

6
src/physics.h Normal file
View File

@@ -0,0 +1,6 @@
//Rename/Move
class WORLD_PHYSICS
{
public:
WORLD_PHYSICS();
};

View File

@@ -1,4 +1,4 @@
#include "../include/player.h"
#include "player.h"
namespace OpenArena
{

28
src/player.h Normal file
View File

@@ -0,0 +1,28 @@
#ifndef __PLAYER_H__
#define __PLAYER_H__
#include "camera.h"
#include "ctrls.h"
namespace OpenArena
{
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);
ControlScheme controls;
Camera camera;
private:
};
};
#endif

View File

@@ -1,4 +1,4 @@
#include "../include/screen.h"
#include "screen.h"
namespace OpenArena
{
@@ -11,27 +11,27 @@ namespace OpenArena
_name = "";
}
int Screen::GetWidth()
int Screen::GetWidth() const
{
return _width;
}
int Screen::GetHeight()
int Screen::GetHeight() const
{
return _height;
}
int Screen::GetColorDepth()
int Screen::GetColorDepth() const
{
return _colorDepth;
}
bool Screen::GetFullscreen()
bool Screen::GetFullscreen() const
{
return _fullscreen;
}
const char* Screen::GetName()
const char* Screen::GetName() const
{
return _name.c_str();
}

34
src/screen.h Normal file
View File

@@ -0,0 +1,34 @@
#ifndef __screen_h__
#define __screen_h__
#include <string>
using namespace std;
namespace OpenArena
{
class Screen
{
public:
Screen();
int GetWidth() const;
int GetHeight() const;
int GetColorDepth() const;
bool GetFullscreen() const;
const char* GetName() const;
void SetWidth(int);
void SetHeight(int);
void Resize(int, int);
void SetColorDepth(int);
void SetFullscreen(bool);
void ToggleFullscreen();
void SetName(const char*);
void SetName(string);
protected:
short _width;
short _height;
char _colorDepth;
bool _fullscreen;
// public:
string _name;
};
};
#endif

View File

@@ -1,5 +1,5 @@
#include <cctype>
#include "../include/strmanip.h"
#include "strmanip.h"
bool Truth(std::string str)
{

22
src/strmanip.h Normal file
View File

@@ -0,0 +1,22 @@
#ifndef __strmanip_h__
#define __strmanip_h__
#include <string>
#include <cmath>
#include "keys.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

14
src/texture.h Normal file
View File

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

View File

@@ -1,5 +1,5 @@
#include "../include/tga.h"
#include "tga.h"
#ifdef WIN32
#pragma warning(disable:4996)
#endif

43
src/tga.h Normal file
View File

@@ -0,0 +1,43 @@
#ifndef __TGA_H__
#define __TGA_H__
#pragma comment(lib, "OpenGL32.lib")
#ifdef WIN32
#include <windows.h> //I think this was only needed because gl.h uses it
#include <GL/gl.h>
#endif
#ifdef __linux
#include <GL/gl.h>
#endif
#ifdef __APPLE__
#include <GL/gl.h>
#endif
#include <cstdio>
#include <string>
#include "texture.h"
namespace OpenArena{
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

View File

@@ -1,4 +1,4 @@
#include "../include/vector.h"
#include "vector.h"
namespace OpenArena{
Vec3d::Vec3d()

83
src/vector.h Normal file
View File

@@ -0,0 +1,83 @@
#ifndef __vector_h__
#define __vector_h__
#include <cmath>
namespace OpenArena{
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;
class Vec2i
{
public:
int x,y;
Vec2i(); //Default Constructor
Vec2i(const Vec2i&); //Copy Constructor
Vec2i(int); // from an angle
Vec2i(int,int); //from values
int lengthsquared() const;
int length() const;
void normalize();
Vec2i normalized() const;
Vec2i cross(const Vec2i&) const;
Vec2i operator=(const Vec2i&);
Vec2i operator*(const Vec2i&) const;
Vec2i operator+(const Vec2i&) const;
Vec2i operator-(const Vec2i&) const;
//Vec2i operator/(const Vec2i&) const; //Is this right?
Vec2i operator*(int) const;
Vec2i operator/(int) const;
bool operator==(const Vec2i&) const;
bool operator!=(const Vec2i&) const;
};
};
#endif

2
src/version.h Normal file
View File

@@ -0,0 +1,2 @@
//#define OPENARENA_VERSION "OpenArena: v0.1.2"
#define OPENARENA_VERSION "OpenArena: CVS"

View File

@@ -1,4 +1,4 @@
#include "../include/window.h"
#include "window.h"
#ifdef __linux
void OpenArena::Window::SwapBuffers()
@@ -143,6 +143,7 @@ bool OpenArena::Window::Open()
vi = glXChooseVisual(display, screen, attrListDbl);
if(vi == NULL)
{
vi = glXChooseVisual(display, screen, attrListSgl);
doubleBuffered = false;
printf("Only Singlebuffered Visual!\n");
@@ -433,7 +434,7 @@ bool OpenArena::Window::Open()
ShowWindow(window,SW_SHOW);
SetForegroundWindow(window);
SetFocus(window);
OnResize(_width, _height);
_resizer->Resize(_width, _height);
if (!_initializer->Initialize())
{

113
src/window.h Normal file
View File

@@ -0,0 +1,113 @@
#ifndef __window_h__
#define __window_h__
#include "screen.h"
#ifdef __linux
#include <GL/gl.h>
#include <GL/glx.h>
#include <X11/extensions/xf86vmode.h>
#include <X11/keysym.h>
#endif
#ifdef __APPLE__
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glx.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
//#include <X11/extensions/xf86vmode.h>
#include <X11/keysym.h>
#endif
#ifdef WIN32
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#endif
#include "vector.h"
namespace OpenArena
{
class Window: public Screen
{
public:
class Resizer
{
public:
void Resize(GLsizei width, GLsizei height);
};
class Initializer
{
public:
int Initialize();
};
public:
Window();
~Window();
void Close();
bool Open();
bool Open(string title, int width, int height, int bits, bool fullscreenflag); //make that string a const char* after this works
void SetInitializer(Initializer* initializer);
void SetResizer(Resizer* resizer);
void SwapBuffers();
void Resize(GLsizei width, GLsizei height);
Vec2i GetMousePosition();
void SetMousePosition(Vec2i pos);
#ifdef __linux
Display* GetDisplay();
private:
Cursor CreateWindowedCursor();
Cursor CreateFullscreenCursor();
int screen;
::Window window;
GLXContext hRC;
XSetWindowAttributes attributes;
bool doubleBuffered;
XF86VidModeModeInfo vidMode;
int x, y;
Display* display;
#endif
#ifdef __APPLE__
Display* GetDisplay();
private:
Cursor CreateWindowedCursor();
Cursor CreateFullscreenCursor();
int screen;
::Window window;
GLXContext hRC;
XSetWindowAttributes attributes;
bool doubleBuffered;
//XF86VidModeModeInfo vidMode;
int x, y;
Display* display;
#endif
private:
Resizer* _resizer;
Initializer* _initializer;
#ifdef WIN32
HGLRC glContext;
HWND window;
HDC deviceContext;
HINSTANCE instance;
#endif
};
};
#ifdef WIN32
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
#endif
#ifdef __linux
static int attrListSgl[] = {GLX_RGBA, GLX_RED_SIZE, 4, GLX_GREEN_SIZE, 4, GLX_BLUE_SIZE, 4, GLX_DEPTH_SIZE, 16, None};
static int attrListDbl[] = {GLX_RGBA, GLX_DOUBLEBUFFER, GLX_RED_SIZE, 4, GLX_GREEN_SIZE, 4, GLX_BLUE_SIZE, 4, GLX_DEPTH_SIZE, 16, None};
#endif
#ifdef __APPLE__
static int attrListSgl[] = {GLX_RGBA, GLX_RED_SIZE, 4, GLX_GREEN_SIZE, 4, GLX_BLUE_SIZE, 4, GLX_DEPTH_SIZE, 16, None};
static int attrListDbl[] = {GLX_RGBA, GLX_DOUBLEBUFFER, GLX_RED_SIZE, 4, GLX_GREEN_SIZE, 4, GLX_BLUE_SIZE, 4, GLX_DEPTH_SIZE, 16, None};
#endif
#endif

View File

@@ -29,8 +29,8 @@
////////////////////////////////////////////////////////////////////////////////
#ifdef WIN32
//include necessary header files
#include "../include/main.h"
#include "../include/version.h"
#include "main.h"
#include "version.h"
//link necessary libraries
#pragma comment(lib, "opengl32.lib")
@@ -250,9 +250,10 @@ int WINAPI WinMain( HINSTANCE hInstance,
level.LoadMap();
}
g_Screen.SetOnInit(InitGL);
g_Screen.SetOnResize(ReSizeGLScene);
if (!g_Screen.Open(string(OPENARENA_VERSION), level.screen.GetWidth(), level.screen.GetHeight(), level.screen.GetColorDepth(), level.screen.GetFullscreen()))
g_Screen = g_PluginManager.GetDefaultVideoPlugin()->CreateNewWindow(level.screen.GetWidth(), level.screen.GetHeight());
g_Screen->SetInitializer(new OpenArena::Window::Initializer());
g_Screen->SetResizer(new OpenArena::Window::Resizer());
if (!g_Screen->Open(string(OPENARENA_VERSION), level.screen.GetWidth(), level.screen.GetHeight(), level.screen.GetColorDepth(), level.screen.GetFullscreen()))
{
return 0;
}
@@ -292,7 +293,7 @@ int WINAPI WinMain( HINSTANCE hInstance,
}
else
{
SetCursorPos(g_Screen.GetWidth()/2, g_Screen.GetHeight()/2);
SetCursorPos(g_Screen->GetWidth()/2, g_Screen->GetHeight()/2);
}
//////////
@@ -579,14 +580,14 @@ int WINAPI WinMain( HINSTANCE hInstance,
}
}
g_Screen.SwapBuffers();
g_Screen->SwapBuffers();
if (keys[OpenArena::KEY_F1])
{
keys[OpenArena::KEY_F1]=false;
g_Screen.Close();
g_Screen.ToggleFullscreen();
if (!g_Screen.Open("OpenArena",g_Screen.GetWidth(),g_Screen.GetHeight(),g_Screen.GetColorDepth(),g_Screen.GetFullscreen()))
g_Screen->Close();
g_Screen->ToggleFullscreen();
if (!g_Screen->Open("OpenArena",g_Screen->GetWidth(),g_Screen->GetHeight(),g_Screen->GetColorDepth(),g_Screen->GetFullscreen()))
{
return 0;
}
@@ -594,7 +595,7 @@ int WINAPI WinMain( HINSTANCE hInstance,
}
level.UnloadMap();
g_Screen.Close();
g_Screen->Close();
return (msg.wParam);
}

9
src/worlddefs.h Normal file
View File

@@ -0,0 +1,9 @@
#ifndef __WorldDefs_h__
#define __WorldDefs_h__
#include "PluginManager.h"
#include "level.h"
static OpenArena::Level level;
static OpenArena::PluginManager g_PluginManager;
#endif