diff --git a/include/camera.h b/include/camera.h index a56cef2..5418448 100644 --- a/include/camera.h +++ b/include/camera.h @@ -9,82 +9,82 @@ #include "mygl.h" #include "screen.h" - - -class CameraClass +namespace OpenArena { -public: - //Constructors - CameraClass(); //Default Constructor - //Purpose: - // + class Camera + { + public: + //Constructors + Camera(); //Default Constructor + //Purpose: + // + + //Camera(const Camera&); //Copy Constructor + //Purpose: + // + + //Observer Accessors + Vec3f Position(); + //Purpose: + // - //CameraClass(const CameraClass&); //Copy Constructor - //Purpose: - // + Vec3f View(); + //Purpose: + // - //Observer Accessors - Vec3f Position(); - //Purpose: - // + Vec3f UpVector(); + //Purpose: + // - Vec3f View(); - //Purpose: - // + Vec3f Strafe(); + //Purpose: + // - Vec3f UpVector(); - //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: + // - Vec3f Strafe(); - //Purpose: - // + void RotateView(double angle, double X, double Y, double Z); + //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: - // + 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: + // -private: - Vec3f m_vPosition; - Vec3f m_vView; - Vec3f m_vUpVector; - Vec3f m_vStrafe; + void Update(); + //Purpose: + // + + void Look(); + //Purpose: + // + + private: + Vec3f m_vPosition; + Vec3f m_vView; + Vec3f m_vUpVector; + Vec3f m_vStrafe; + }; }; #endif diff --git a/include/geometry.h b/include/geometry.h index 0648cbd..5690d73 100644 --- a/include/geometry.h +++ b/include/geometry.h @@ -1,16 +1,20 @@ #include "vector.h" #include "myglTexture.h" -struct TRIANGLE +namespace OpenArena { - GL_MY_TEXTURE texture; - uint32 texID; - Vec3f vertecies[3]; - Vec2f texCoords[3]; - Vec3f normal; + class Triangle + { + public: + Texture texture; + uint32 texID; + Vec3f vertecies[3]; + Vec2f texCoords[3]; + Vec3f normal; + }; }; - -class POSITION +/*//This class seems to never be used and I dont' remember why I made it. +class Position { public: GLfloat xrot; // X rotation @@ -21,7 +25,7 @@ public: GLfloat ztrans; // Z translation bool stepRight; bool stepLeft; - POSITION() + Position() { xtrans = 0.0f; ytrans = 0.0f; @@ -33,3 +37,4 @@ public: private: }; +*/ diff --git a/include/level.h b/include/level.h index 5a06f1c..f412bf5 100644 --- a/include/level.h +++ b/include/level.h @@ -30,78 +30,81 @@ #include "keys.h" using namespace std; +using OpenArena::Triangle; -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 +namespace OpenArena { -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); - - /*Not Yet Implemented - void PlayerConnect(); // implement later - void PlayerDisconnect(); // implement later - */ - SCREEN screen; - GLFontClass glFont; - string nextLevel; - PLAYER* defaultPlayer; - uint32 numTextures; - string* textureNames; + 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 - 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 players; - list ents; - //list textures; - GL_MY_TEXTURE* textures; - GL_MY_TEXTURE menuTextures[NUM_MENU_TEXTURES]; + enum {GL_MY_TEXTURE_CONSOLEBACKGROUND=0, NUM_MENU_TEXTURES}; - - -private: - void ConsolePrint(string); - string consoleHistory[MAX_CONSOLE_HISTORY_LINES]; - string consoleOutput[MAX_CONSOLE_OUTPUT_LINES]; - string outputText[MAX_OUTPUT_TEXT_LINES]; -}; - + 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); + + /*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 players; + list ents; + //list textures; + Texture* textures; + Texture menuTextures[NUM_MENU_TEXTURES]; + + + + private: + void ConsolePrint(string); + string consoleHistory[MAX_CONSOLE_HISTORY_LINES]; + string consoleOutput[MAX_CONSOLE_OUTPUT_LINES]; + string outputText[MAX_OUTPUT_TEXT_LINES]; + }; +}; #endif diff --git a/include/mygl.h b/include/mygl.h index 45566c6..3a86f63 100644 --- a/include/mygl.h +++ b/include/mygl.h @@ -22,8 +22,11 @@ using namespace std; static HINSTANCE hInstance; // Application instance #endif extern OpenArena::Window g_Screen; -int InitGL(GLvoid); - -bool LoadGLTexture(string , GLuint&, GLuint = GL_LINEAR, GLuint = GL_LINEAR); -void FreeGLTexture(GLuint&); +//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 diff --git a/include/myglFont.h b/include/myglFont.h index 2d711e7..eaee119 100644 --- a/include/myglFont.h +++ b/include/myglFont.h @@ -3,27 +3,29 @@ #include "mygl.h" -class GLFontClass +namespace OpenArena { -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 Loaded(); - void SetScreenDimensions(short, short); - void SetScreenWidth(short); - void SetScreenHeight(short); - short ScreenWidth(); - short ScreenHeight(); + 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 diff --git a/include/myglTexture.h b/include/myglTexture.h index e26b3cb..9dcac70 100644 --- a/include/myglTexture.h +++ b/include/myglTexture.h @@ -7,29 +7,31 @@ using namespace std; -class GL_MY_TEXTURE +namespace OpenArena { -public: - GL_MY_TEXTURE(); - ~GL_MY_TEXTURE(); - string Filename(); - GLuint ID(); - bool Load(string filename); - bool Load(string filename, GLuint min, GLuint 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: - GLuint minFilter; - GLuint magFilter; - string filename; - GLuint id; -}; - + 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 diff --git a/include/player.h b/include/player.h index 0ff1279..dee04b8 100644 --- a/include/player.h +++ b/include/player.h @@ -4,23 +4,25 @@ #include "camera.h" #include "ctrls.h" -class PLAYER +namespace OpenArena { -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: - + 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; + Camera camera; + + + private: + + }; }; - #endif diff --git a/include/screen.h b/include/screen.h index ebfb712..30ba984 100644 --- a/include/screen.h +++ b/include/screen.h @@ -3,26 +3,27 @@ #include using namespace std; - -class SCREEN +namespace OpenArena { -public: - SCREEN() + class Screen { - width=640; - height=480; - bpp=16; - fullscreen=false; - name = ""; - } - - short width; - short height; - char bpp; - bool fullscreen; - string name; - - + public: + Screen() + { + width=640; + height=480; + bpp=16; + fullscreen=false; + name = ""; + } + + short width; + short height; + char bpp; + bool fullscreen; + string name; + + + }; }; - #endif diff --git a/include/texture.h b/include/texture.h index 6989382..2269df5 100644 --- a/include/texture.h +++ b/include/texture.h @@ -1,8 +1,9 @@ #ifndef __texture_h__ #define __texture_h__ -struct TextureImage +class TextureImage { +public: unsigned char* data; unsigned int bpp; unsigned int sizeX; diff --git a/include/window.h b/include/window.h index 29ab77a..12e4ed2 100644 --- a/include/window.h +++ b/include/window.h @@ -19,7 +19,7 @@ namespace OpenArena typedef void (*ResizeFunc)(GLsizei width, GLsizei height); typedef int (*InitFunc)(); - class Window: public SCREEN + class Window: public Screen { public: Window(); diff --git a/include/worlddefs.h b/include/worlddefs.h index cf37d96..add134a 100644 --- a/include/worlddefs.h +++ b/include/worlddefs.h @@ -3,6 +3,6 @@ #include "level.h" -static LEVEL level; +static OpenArena::Level level; #endif diff --git a/src/camera.cpp b/src/camera.cpp index 46342c2..97a2c12 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -10,8 +10,8 @@ // To implement an OpenGL Camera // // Summary of Methods: -// CameraClass -// -CameraClass(); +// Camera +// -Camera(); // 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. @@ -29,7 +29,7 @@ // 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); +// -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. @@ -46,148 +46,151 @@ #include "../include/camera.h" -CameraClass::CameraClass() +namespace OpenArena { - 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) -{ - //Most of this is sorta right for linux I think but since I don't know how yet it's currently windows only - #ifdef WIN32 - 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) + Camera::Camera() { - 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); - } + m_vPosition = Vec3f(0,0,0); + m_vView = Vec3f(0,0,-1); + m_vUpVector = Vec3f(0,1,0); } - #endif -} - -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; + void Camera::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); + } - 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; -} + void Camera::PositionCamera(Vec3f pos, Vec3f view, Vec3f up) + { + m_vPosition = pos; + m_vView = view; + m_vUpVector = up; + } + + void Camera::SetViewByMouse(Screen g_Screen) + { + //Most of this is sorta right for linux I think but since I don't know how yet it's currently windows only + #ifdef WIN32 + 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); + } + } + #endif + } + + void Camera::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 Camera::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 Camera::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 Camera::Update() + { + m_vStrafe =((m_vView - m_vPosition).cross(m_vUpVector)).normalized(); + //SetViewByMouse(); //TODO take this whole function out asap + + } + + void Camera::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 Camera::Position() + { + return m_vPosition; + } + + Vec3f Camera::Strafe() + { + return m_vStrafe; + } + + Vec3f Camera::UpVector() + { + return m_vUpVector; + } + + Vec3f Camera::View() + { + return m_vView; + } +}; diff --git a/src/level.cpp b/src/level.cpp index 058d1fd..fd5c610 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -30,1189 +30,1192 @@ using namespace std; -LEVEL::LEVEL() +namespace OpenArena { - textureNames = NULL; - numTextures = 0; - textures = NULL; - - 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 = 0.2f; - mlook = true; -} - -LEVEL::~LEVEL() -{ - if(defaultPlayer) + Level::Level() { - delete defaultPlayer; - 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."); - - //This needs to be abstracted somehow - #ifdef WIN32 - MessageBox(NULL,tmpChar,"ERROR",MB_OK|MB_ICONEXCLAMATION); - #endif - delete [] tmpChar; - return false; - } - else - { - ConsolePrint("map file \"" + mapname + "\" opened successfully"); - } - - //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> 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()); - } - char lpszNumTriangles[6]; - sprintf(lpszNumTriangles, "%d", numTriangles); - ConsolePrint(lpszNumTriangles + string(" triangles successfully read")); - - //Number of textures; - input >> readBuffer; - numTextures = Integer(readBuffer); - - //Texture data - textureNames = new string[numTextures]; - for(unsigned int i=0; i> textureNames[i]; - } - LoadGLTextures(); - char lpszNumTextures[6]; - sprintf(lpszNumTextures, "%d", numTextures); - ConsolePrint(lpszNumTextures + string(" textures successfully read")); - - //BGM - input >> bgm; - - //Build display list - - //Sound - if (sound) - { - ConsolePrint("Starting sound"); - - //This needs to be abstracted somehow - #ifdef WIN32 - BASS_Init(-1, 44100, BASS_DEVICE_LEAVEVOL, g_hWnd); - BASS_Start(); - BASS_CDInit(NULL, BASS_DEVICE_LEAVEVOL); - #endif - - if(bgm.length()>=4) - { - if( toupper(bgm[0]) == 'C' && - toupper(bgm[1]) == 'D' && - toupper(bgm[2]) == 'A') - { - bgmCDA = Integer(bgm.substr(3,bgm.length())); - //This needs to be abstracted somehow - #ifdef WIN32 - BASS_CDPlay(bgmCDA, 1, 0); - #endif - } - else - { - bgmCDA=0; - string tmpstr = gamedir + "music/bgm/" + bgm; - //This needs to be abstracted somehow - #ifdef WIN32 - bgmStream = BASS_StreamCreateFile(0, (void*)tmpstr.c_str(), 0, 0, BASS_STREAM_AUTOFREE); - BASS_StreamPlay(bgmStream, 1, BASS_SAMPLE_LOOP); - #endif - } - } - - ConsolePrint("Sound init complete"); - } - else - { - ConsolePrint("Sound disabled"); - } - - return true; -} -bool LEVEL::LoadMap() -{ - return 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."); - - //This needs to be abstracted somehow - #ifdef WIN32 - MessageBox(NULL,tmpChar,"ERROR",MB_OK|MB_ICONEXCLAMATION); - #endif - delete [] tmpChar; - return; - } - - //Gravity - output << gravity << endl; - - //Number of triangles - output << numTriangles << endl; - - //Triangle Data - for(unsigned int i=0; icamera.Look(); - - for (uint32 i=0; ilast+1) - { - last=time; - fps2 = fps; - fps=0; - } - return fps2; -} - -void LEVEL::Execute(string cmd) -{ - string command; + showFPS = false; + showConsole = false; - uint32 i=0xFFFFFFFF; - while(word(cmd, ++i) != "") - { - command = tolower(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 == "movespeed") - { - moveSpeed = (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 == "mouselook") - { - mlook = Truth(word(cmd, ++i)); - } - 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 == "colordepth") - { - screen.bpp = Integer(word(cmd, ++i)); - } - else - { - ConsolePrint("Variable " + command + " doesn't exist"); - } - } - else if(command == "bind") - { - command = tolower(word(cmd, ++i)); - - if(command == "forward") - { - if(!defaultPlayer[0].controls.Bind(CTRLS_FORWARD, KeyName(word(cmd, ++i)))) - { - ConsolePrint("Couldn't bind " + word(cmd, i) + " to action forward"); - } - } - else if(command == "backward") - { - if(!defaultPlayer[0].controls.Bind(CTRLS_BACKWARD, KeyName(word(cmd, ++i)))) - { - ConsolePrint("Couldn't bind " + word(cmd, i) + " to action backward"); - } - } - else if(command == "lookleft") - { - if(!defaultPlayer[0].controls.Bind(CTRLS_LOOKLEFT, KeyName(word(cmd, ++i)))) - { - ConsolePrint("Couldn't bind " + word(cmd, i) + " to action lookleft"); - } - } - else if(command == "lookright") - { - if(!defaultPlayer[0].controls.Bind(CTRLS_LOOKRIGHT, KeyName(word(cmd, ++i)))) - { - ConsolePrint("Couldn't bind " + word(cmd, i) + " to action lookright"); - } - } - else if(command == "lookup") - { - if(!defaultPlayer[0].controls.Bind(CTRLS_LOOKUP, KeyName(word(cmd, ++i)))) - { - ConsolePrint("Couldn't bind " + word(cmd, i) + " to action lookup"); - } - } - else if(command == "lookdown") - { - if(!defaultPlayer[0].controls.Bind(CTRLS_LOOKDOWN, KeyName(word(cmd, ++i)))) - { - ConsolePrint("Couldn't bind " + word(cmd, i) + " to action lookdown"); - } - } - else if(command == "moveup") - { - if(!defaultPlayer[0].controls.Bind(CTRLS_MOVEUP, KeyName(word(cmd, ++i)))) - { - ConsolePrint("Couldn't bind " + word(cmd, i) + " to action moveup"); - } - } - else if(command == "movedown") - { - if(!defaultPlayer[0].controls.Bind(CTRLS_MOVEDOWN, KeyName(word(cmd, ++i)))) - { - ConsolePrint("Couldn't bind " + word(cmd, i) + " to action movedown"); - } - } - else if(command == "moveleft") - { - if(!defaultPlayer[0].controls.Bind(CTRLS_MOVELEFT, KeyName(word(cmd, ++i)))) - { - ConsolePrint("Couldn't bind " + word(cmd, i) + " to action moveleft"); - } - } - else if(command == "moveright") - { - if(!defaultPlayer[0].controls.Bind(CTRLS_MOVERIGHT, KeyName(word(cmd, ++i)))) - { - ConsolePrint("Couldn't bind " + word(cmd, i) + " to action moveright"); - } - } - else if(command == "fireprimary") - { - if(!defaultPlayer[0].controls.Bind(CTRLS_FIREPRIMARY, KeyName(word(cmd, ++i)))) - { - ConsolePrint("Couldn't bind " + word(cmd, i) + " to action fireprimary"); - } - } - else if(command == "firesecondary") - { - if(!defaultPlayer[0].controls.Bind(CTRLS_FIRESECONDARY, KeyName(word(cmd, ++i)))) - { - ConsolePrint("Couldn't bind " + word(cmd, i) + " to action firesecondary"); - } - } - else if(command == "weapnext") - { - if(!defaultPlayer[0].controls.Bind(CTRLS_WEAPONNEXT, KeyName(word(cmd, ++i)))) - { - ConsolePrint("Couldn't bind " + word(cmd, i) + " to action weapnext"); - } - } - else if(command == "weapprev") - { - if(!defaultPlayer[0].controls.Bind(CTRLS_WEAPONPREV, KeyName(word(cmd, ++i)))) - { - ConsolePrint("Couldn't bind " + word(cmd, i) + " to action weapprev"); - } - } - else if(command == "togglelights" || command == "togglelighting") - { - if(!defaultPlayer[0].controls.Bind(CTRLS_TOGGLE_LIGHTS, KeyName(word(cmd, ++i)))) - { - ConsolePrint("Couldn't bind " + word(cmd, i) + " to action togglelights"); - } - } - else if(command == "togglefps") - { - if(!defaultPlayer[0].controls.Bind(CTRLS_TOGGLE_FPS, KeyName(word(cmd, ++i)))) - { - ConsolePrint("Couldn't bind " + word(cmd, i) + " to action togglefps"); - } - } - else if(command == "toggleconsole") - { - if(!defaultPlayer[0].controls.Bind(CTRLS_TOGGLE_CONSOLE, KeyName(word(cmd, ++i)))) - { - ConsolePrint("Couldn't bind " + word(cmd, i) + " to action toggleconsole"); - } - } - else if(command == "togglemouselook") - { - if(!defaultPlayer[0].controls.Bind(CTRLS_TOGGLE_MOUSELOOK, KeyName(word(cmd, ++i)))) - { - ConsolePrint("Couldn't bind " + word(cmd, i) + " to action togglemouselook"); - } - } - else if(command == "quickmouselook") - { - if(!defaultPlayer[0].controls.Bind(CTRLS_QUICKMOUSELOOK, KeyName(word(cmd, ++i)))) - { - ConsolePrint("Couldn't bind " + word(cmd, i) + " to action quickmouselook"); - } - } - else if(command == "rollleft") - { - if(!defaultPlayer[0].controls.Bind(CTRLS_ROLLLEFT, KeyName(word(cmd, ++i)))) - { - ConsolePrint("Couldn't bind " + word(cmd, i) + " to action rollleft"); - } - } - else if(command == "rollright") - { - if(!defaultPlayer[0].controls.Bind(CTRLS_ROLLRIGHT, KeyName(word(cmd, ++i)))) - { - ConsolePrint("Couldn't bind " + word(cmd, i) + " to action rollright"); - } - } - else - { - ConsolePrint("No action identified by " + command); - } - } - else if(command == "map" || command == "map_load") - { - nextLevel = word(cmd, ++i); - UnloadMap(); - if(!LoadMap()) - { - ConsolePrint("Unable to load level " + command); - nextLevel = "intro.map"; - LoadMap(); - } - } - else if(command == "unbind") - { - command = tolower(word(cmd, ++i)); - - if(command == "all") - { - defaultPlayer[0].controls.ClearControlScheme(); - } - else - { - defaultPlayer[0].controls.Unbind(KeyName(command)); - } - } - else if(command == "exec" || command == "config_load") - { - command = tolower(word(cmd, ++i)); - if(!LoadConfig(command)) - { - ConsolePrint("Unable to load config file " + word(cmd, i)); - } - } - else if(command == "map_save") - { - command = tolower(word(cmd, ++i)); - SaveMap(command); - } - else if(command == "config_save") - { - command = tolower(word(cmd, ++i)); - SaveConfig(command); - } + nextLevel = "intro.map"; + gamedir = "oa/"; + sound = true; + + defaultPlayer = new Player; + + numTriangles = 0; + triangles = NULL; /* - else if(command == "map_add_triangle") - { - if(triangles != NULL) - { - TRIANGLE* temp = triangles; - triangles = new TRIANGLE[numTriangles + 1]; - for(int i=0; i> 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> 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()); + } + char lpszNumTriangles[6]; + sprintf(lpszNumTriangles, "%d", numTriangles); + ConsolePrint(lpszNumTriangles + string(" triangles successfully read")); + + //Number of textures; + input >> readBuffer; + numTextures = Integer(readBuffer); + + //Texture data + textureNames = new string[numTextures]; + for(unsigned int i=0; i> textureNames[i]; + } + LoadGLTextures(); + char lpszNumTextures[6]; + sprintf(lpszNumTextures, "%d", numTextures); + ConsolePrint(lpszNumTextures + string(" textures successfully read")); + + //BGM + input >> bgm; + + //Build display list + + //Sound + if (sound) + { + ConsolePrint("Starting sound"); + + //This needs to be abstracted somehow + #ifdef WIN32 + BASS_Init(-1, 44100, BASS_DEVICE_LEAVEVOL, g_hWnd); + BASS_Start(); + BASS_CDInit(NULL, BASS_DEVICE_LEAVEVOL); + #endif + + if(bgm.length()>=4) + { + if( toupper(bgm[0]) == 'C' && + toupper(bgm[1]) == 'D' && + toupper(bgm[2]) == 'A') + { + bgmCDA = Integer(bgm.substr(3,bgm.length())); + //This needs to be abstracted somehow + #ifdef WIN32 + BASS_CDPlay(bgmCDA, 1, 0); + #endif + } + else + { + bgmCDA=0; + string tmpstr = gamedir + "music/bgm/" + bgm; + //This needs to be abstracted somehow + #ifdef WIN32 + bgmStream = BASS_StreamCreateFile(0, (void*)tmpstr.c_str(), 0, 0, BASS_STREAM_AUTOFREE); + BASS_StreamPlay(bgmStream, 1, BASS_SAMPLE_LOOP); + #endif + } + } + + ConsolePrint("Sound init complete"); + } + else + { + ConsolePrint("Sound disabled"); + } + + return true; + } + bool Level::LoadMap() + { + return 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."); + + //This needs to be abstracted somehow + #ifdef WIN32 + MessageBox(NULL,tmpChar,"ERROR",MB_OK|MB_ICONEXCLAMATION); + #endif + delete [] tmpChar; + return; + } + + //Gravity + output << gravity << endl; + + //Number of triangles + output << numTriangles << endl; + + //Triangle Data + for(unsigned int i=0; icamera.Look(); + + for (uint32 i=0; ilast+1) + { + last=time; + fps2 = fps; + fps=0; + } + return fps2; + } + + void Level::Execute(string cmd) + { + string command; + + uint32 i=0xFFFFFFFF; + while(word(cmd, ++i) != "") + { + command = tolower(word(cmd, i)); - if(command == "turnspeed") + if(command == "set") { - turnSpeed = (float)atof(word(cmd, ++i).c_str()); + command = tolower(word(cmd, ++i)); + + if(command == "turnspeed") + { + turnSpeed = (float)atof(word(cmd, ++i).c_str());//Floating(word(cmd, ++i)); + } + else if(command == "movespeed") + { + moveSpeed = (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 == "mouselook") + { + mlook = Truth(word(cmd, ++i)); + } + 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 == "colordepth") + { + screen.bpp = Integer(word(cmd, ++i)); + } + else + { + ConsolePrint("Variable " + command + " doesn't exist"); + } } - else if(command == "mousespeed") + else if(command == "bind") { - mouseSpeed = (float)atof(word(cmd, ++i).c_str()); + command = tolower(word(cmd, ++i)); + + if(command == "forward") + { + if(!defaultPlayer[0].controls.Bind(CTRLS_FORWARD, KeyName(word(cmd, ++i)))) + { + ConsolePrint("Couldn't bind " + word(cmd, i) + " to action forward"); + } + } + else if(command == "backward") + { + if(!defaultPlayer[0].controls.Bind(CTRLS_BACKWARD, KeyName(word(cmd, ++i)))) + { + ConsolePrint("Couldn't bind " + word(cmd, i) + " to action backward"); + } + } + else if(command == "lookleft") + { + if(!defaultPlayer[0].controls.Bind(CTRLS_LOOKLEFT, KeyName(word(cmd, ++i)))) + { + ConsolePrint("Couldn't bind " + word(cmd, i) + " to action lookleft"); + } + } + else if(command == "lookright") + { + if(!defaultPlayer[0].controls.Bind(CTRLS_LOOKRIGHT, KeyName(word(cmd, ++i)))) + { + ConsolePrint("Couldn't bind " + word(cmd, i) + " to action lookright"); + } + } + else if(command == "lookup") + { + if(!defaultPlayer[0].controls.Bind(CTRLS_LOOKUP, KeyName(word(cmd, ++i)))) + { + ConsolePrint("Couldn't bind " + word(cmd, i) + " to action lookup"); + } + } + else if(command == "lookdown") + { + if(!defaultPlayer[0].controls.Bind(CTRLS_LOOKDOWN, KeyName(word(cmd, ++i)))) + { + ConsolePrint("Couldn't bind " + word(cmd, i) + " to action lookdown"); + } + } + else if(command == "moveup") + { + if(!defaultPlayer[0].controls.Bind(CTRLS_MOVEUP, KeyName(word(cmd, ++i)))) + { + ConsolePrint("Couldn't bind " + word(cmd, i) + " to action moveup"); + } + } + else if(command == "movedown") + { + if(!defaultPlayer[0].controls.Bind(CTRLS_MOVEDOWN, KeyName(word(cmd, ++i)))) + { + ConsolePrint("Couldn't bind " + word(cmd, i) + " to action movedown"); + } + } + else if(command == "moveleft") + { + if(!defaultPlayer[0].controls.Bind(CTRLS_MOVELEFT, KeyName(word(cmd, ++i)))) + { + ConsolePrint("Couldn't bind " + word(cmd, i) + " to action moveleft"); + } + } + else if(command == "moveright") + { + if(!defaultPlayer[0].controls.Bind(CTRLS_MOVERIGHT, KeyName(word(cmd, ++i)))) + { + ConsolePrint("Couldn't bind " + word(cmd, i) + " to action moveright"); + } + } + else if(command == "fireprimary") + { + if(!defaultPlayer[0].controls.Bind(CTRLS_FIREPRIMARY, KeyName(word(cmd, ++i)))) + { + ConsolePrint("Couldn't bind " + word(cmd, i) + " to action fireprimary"); + } + } + else if(command == "firesecondary") + { + if(!defaultPlayer[0].controls.Bind(CTRLS_FIRESECONDARY, KeyName(word(cmd, ++i)))) + { + ConsolePrint("Couldn't bind " + word(cmd, i) + " to action firesecondary"); + } + } + else if(command == "weapnext") + { + if(!defaultPlayer[0].controls.Bind(CTRLS_WEAPONNEXT, KeyName(word(cmd, ++i)))) + { + ConsolePrint("Couldn't bind " + word(cmd, i) + " to action weapnext"); + } + } + else if(command == "weapprev") + { + if(!defaultPlayer[0].controls.Bind(CTRLS_WEAPONPREV, KeyName(word(cmd, ++i)))) + { + ConsolePrint("Couldn't bind " + word(cmd, i) + " to action weapprev"); + } + } + else if(command == "togglelights" || command == "togglelighting") + { + if(!defaultPlayer[0].controls.Bind(CTRLS_TOGGLE_LIGHTS, KeyName(word(cmd, ++i)))) + { + ConsolePrint("Couldn't bind " + word(cmd, i) + " to action togglelights"); + } + } + else if(command == "togglefps") + { + if(!defaultPlayer[0].controls.Bind(CTRLS_TOGGLE_FPS, KeyName(word(cmd, ++i)))) + { + ConsolePrint("Couldn't bind " + word(cmd, i) + " to action togglefps"); + } + } + else if(command == "toggleconsole") + { + if(!defaultPlayer[0].controls.Bind(CTRLS_TOGGLE_CONSOLE, KeyName(word(cmd, ++i)))) + { + ConsolePrint("Couldn't bind " + word(cmd, i) + " to action toggleconsole"); + } + } + else if(command == "togglemouselook") + { + if(!defaultPlayer[0].controls.Bind(CTRLS_TOGGLE_MOUSELOOK, KeyName(word(cmd, ++i)))) + { + ConsolePrint("Couldn't bind " + word(cmd, i) + " to action togglemouselook"); + } + } + else if(command == "quickmouselook") + { + if(!defaultPlayer[0].controls.Bind(CTRLS_QUICKMOUSELOOK, KeyName(word(cmd, ++i)))) + { + ConsolePrint("Couldn't bind " + word(cmd, i) + " to action quickmouselook"); + } + } + else if(command == "rollleft") + { + if(!defaultPlayer[0].controls.Bind(CTRLS_ROLLLEFT, KeyName(word(cmd, ++i)))) + { + ConsolePrint("Couldn't bind " + word(cmd, i) + " to action rollleft"); + } + } + else if(command == "rollright") + { + if(!defaultPlayer[0].controls.Bind(CTRLS_ROLLRIGHT, KeyName(word(cmd, ++i)))) + { + ConsolePrint("Couldn't bind " + word(cmd, i) + " to action rollright"); + } + } + else + { + ConsolePrint("No action identified by " + command); + } } - else if(command == "maxfps") + else if(command == "map" || command == "map_load") { - maxFPS = Integer(word(cmd, ++i)); + nextLevel = word(cmd, ++i); + UnloadMap(); + if(!LoadMap()) + { + ConsolePrint("Unable to load level " + command); + nextLevel = "intro.map"; + LoadMap(); + } } - else if(command == "sound") + else if(command == "unbind") { - sound = Truth(word(cmd, ++i)); + command = tolower(word(cmd, ++i)); + + if(command == "all") + { + defaultPlayer[0].controls.ClearControlScheme(); + } + else + { + defaultPlayer[0].controls.Unbind(KeyName(command)); + } } - else if(command == "game") + else if(command == "exec" || command == "config_load") { - gamedir= word(cmd, ++i); + command = tolower(word(cmd, ++i)); + if(!LoadConfig(command)) + { + ConsolePrint("Unable to load config file " + word(cmd, i)); + } } - } - else if(command == "+bind") - { - command = tolower(word(cmd, ++i)); - - if(command == "forward") + else if(command == "map_save") { - defaultPlayer[0].controls.Bind(CTRLS_FORWARD, KeyName(word(cmd, ++i))); + command = tolower(word(cmd, ++i)); + SaveMap(command); } - else if(command == "backward") + else if(command == "config_save") { - defaultPlayer[0].controls.Bind(CTRLS_BACKWARD, KeyName(word(cmd, ++i))); + command = tolower(word(cmd, ++i)); + SaveConfig(command); } - else if(command == "lookleft") + /* + else if(command == "map_add_triangle") { - defaultPlayer[0].controls.Bind(CTRLS_LOOKLEFT, KeyName(word(cmd, ++i))); + if(triangles != NULL) + { + TRIANGLE* temp = triangles; + triangles = new TRIANGLE[numTriangles + 1]; + for(int i=0; icontrols.backward.IsEmpty()) + + void Level::SaveConfig(string cfgname) { - 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); -} - -void LEVEL::UpdateConsole(char newChar) -{ - if(newChar == '\n') - { - for (int i=MAX_CONSOLE_HISTORY_LINES - 1; i>0; i--) + 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()) { - consoleHistory[i] = consoleHistory[i-1]; + 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; } - consoleHistory[0] = ""; - ConsolePrint(consoleHistory[1]); - Execute(tolower(consoleHistory[1])); - } - else if(newChar == OpenArena::KEY_BACK) + + void Level::Print(int x, int y, const char* str, unsigned int set) { - consoleHistory[0] = Left(consoleHistory[0], consoleHistory[0].length()-1); + glFont.Print(x,y,str, set); } - else if(!(defaultPlayer->controls.toggleConsole.Contains(newChar))) + + void Level::UpdateConsole(char newChar) { - consoleHistory[0] = consoleHistory[0] + newChar; - /* - char errmsg[256]; - sprintf(errmsg, "Unhangled keypress: %d", newChar); - MessageBox(NULL, errmsg, "Balls", MB_OK); - */ + if(newChar == '\n') + { + for (int i=MAX_CONSOLE_HISTORY_LINES - 1; i>0; i--) + { + consoleHistory[i] = consoleHistory[i-1]; + } + consoleHistory[0] = ""; + ConsolePrint(consoleHistory[1]); + Execute(tolower(consoleHistory[1])); + + } + else if(newChar == OpenArena::KEY_BACK) + { + consoleHistory[0] = Left(consoleHistory[0], consoleHistory[0].length()-1); + } + else if(!(defaultPlayer->controls.toggleConsole.Contains(newChar))) + { + consoleHistory[0] = consoleHistory[0] + newChar; + /* + char errmsg[256]; + sprintf(errmsg, "Unhangled keypress: %d", newChar); + MessageBox(NULL, errmsg, "Balls", MB_OK); + */ + } } -} - -void LEVEL::ConsolePrint(string line) -{ - for (int i=MAX_CONSOLE_OUTPUT_LINES - 1; i>0; i--) + + void Level::ConsolePrint(string line) { - consoleOutput[i] = consoleOutput[i-1]; + for (int i=MAX_CONSOLE_OUTPUT_LINES - 1; i>0; i--) + { + consoleOutput[i] = consoleOutput[i-1]; + } + consoleOutput[0] = line; } - consoleOutput[0] = line; -} +}; diff --git a/src/mygl.cpp b/src/mygl.cpp index 94e0f24..0905aa5 100644 --- a/src/mygl.cpp +++ b/src/mygl.cpp @@ -1,65 +1,67 @@ #include "../include/mygl.h" - -void FreeGLTexture(GLuint& texture) +namespace OpenArena { - glDeleteTextures(1, &texture); -} - -bool LoadGLTexture(string fn, GLuint& texture, GLuint mag, GLuint min) -{ - if(Right(tolower(fn), 4) == ".bmp") + void FreeGLTexture(GLuint& texture) { - TextureImage* texImage = NULL; - if(texImage = LoadBMP(fn.c_str())) + glDeleteTextures(1, &texture); + } + + bool LoadGLTexture(string fn, GLuint& texture, GLuint mag, GLuint min) + { + if(Right(tolower(fn), 4) == ".bmp") { - 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 + TextureImage* texImage = NULL; + if(texImage = LoadBMP(fn.c_str())) { - if(texImage->data) - free(texImage->data); - free(texImage); + 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; } - return true; - } + } + 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; } } - 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; - } -} - +}; + OpenArena::Window g_Screen; diff --git a/src/myglFont.cpp b/src/myglFont.cpp index c87ed35..b9db820 100644 --- a/src/myglFont.cpp +++ b/src/myglFont.cpp @@ -25,118 +25,121 @@ #include "../include/myglFont.h" -GLFontClass::GLFontClass() +namespace OpenArena { - 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(); + Font::Font() + { + status = 0; + base = 0; + texture = 0; + screenWidth = 1; + screenHeight = 1; + } + + Font::~Font() + { + FreeFont(); + } + + bool Font::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; } - status = true; + return status; } - return status; -} - -bool GLFontClass::FreeFont() -{ - if(status) + + bool Font::FreeFont() { - glDeleteLists(base, 256); - status = false; + if(status) + { + glDeleteLists(base, 256); + status = false; + } + return status; } - return status; -} - -void GLFontClass::Print(int x, int y, const char* str, unsigned int set) -{ - if(status) + + void Font::Print(int x, int y, const char* str, unsigned int set) { - 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); + 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::Loaded() -{ - 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; -} + + bool Font::Loaded() + { + return status; + } + + void Font::SetScreenDimensions(short x, short y) + { + screenWidth = x; + screenHeight = y; + } + + void Font::SetScreenWidth(short x) + { + screenWidth = x; + } + + void Font::SetScreenHeight(short y) + { + screenHeight = y; + } + + short Font::ScreenWidth() + { + return screenWidth; + } + + short Font::ScreenHeight() + { + return screenHeight; + } +}; diff --git a/src/myglTexture.cpp b/src/myglTexture.cpp index 892936c..4338e42 100644 --- a/src/myglTexture.cpp +++ b/src/myglTexture.cpp @@ -1,107 +1,111 @@ #include "../include/myglTexture.h" +using namespace OpenArena; -GL_MY_TEXTURE::GL_MY_TEXTURE() +namespace OpenArena { - id=0xFFFFFFFF; - filename = ""; - minFilter = GL_LINEAR; - magFilter = GL_LINEAR; -} - -GL_MY_TEXTURE::~GL_MY_TEXTURE() -{ - Free(); -} - -string GL_MY_TEXTURE::Filename() -{ - return filename; -} - -GLuint 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 + Texture::Texture() { id=0xFFFFFFFF; - return false; - } -} - -bool GL_MY_TEXTURE::Load(string fn, GLuint min, GLuint 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); + filename = ""; minFilter = GL_LINEAR; magFilter = GL_LINEAR; - filename = ""; - id = 0xFFFFFFFF; } -} - -bool GL_MY_TEXTURE::operator<(const GL_MY_TEXTURE& rtOp) -{ - return id=(const GL_MY_TEXTURE& rtOp) -{ - return id>=rtOp.id; -} - -bool GL_MY_TEXTURE::operator>(const GL_MY_TEXTURE& rtOp) -{ - return id>rtOp.id; -} + + Texture::~Texture() + { + Free(); + } + + string Texture::Filename() + { + return filename; + } + + GLuint Texture::ID() + { + return id; + } + + bool Texture::Loaded() + { + return filename != ""; + } + + bool 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 Texture::Load(string fn, GLuint min, GLuint 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 Texture::Free() + { + if(Loaded()) + { + FreeGLTexture(id); + minFilter = GL_LINEAR; + magFilter = GL_LINEAR; + filename = ""; + id = 0xFFFFFFFF; + } + } + + bool Texture::operator<(const Texture& rtOp) + { + return id=(const Texture& rtOp) + { + return id>=rtOp.id; + } + + bool Texture::operator>(const Texture& rtOp) + { + return id>rtOp.id; + } +}; diff --git a/src/player.cpp b/src/player.cpp index 81948cc..c16bd56 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -1,23 +1,26 @@ #include "../include/player.h" -void PLAYER::Load() +namespace OpenArena { -} - -void PLAYER::Save() -{ -} - -void PLAYER::AddItem(unsigned int item) -{ -// inventory = inventory | item; -} - -void PLAYER::RemoveItem(unsigned int item) -{ -// inventory = inventory & ~item; -} - -void PLAYER::CreateCharacter() -{ -} + 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() + { + } +};