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

File diff suppressed because it is too large Load Diff

View File

@@ -1,12 +0,0 @@
#ifndef __bmp_h__
#define __bmp_h__
#include "mygl.h"
#include "datatypes.h"
#include "texture.h"
namespace OpenArena{
TextureImage* LoadBMP(const char* Filename);
};
#endif

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)

View File

@@ -64,7 +64,7 @@ namespace OpenArena
// 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(Window window);
void SetViewByMouse(const Window* window);
//Purpose:
// Updates the view Vector based on the change in mouse position since the last time it was called.

View File

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

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)
{

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,11 +416,14 @@ 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};
/*GLfloat light[4] = {1.0f,1.0f,1.0f,0.5f};
glLightfv(GL_LIGHT1, GL_AMBIENT, light);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHTING);
*/
glEnable(GL_LIGHTING);*/
if(textures != NULL)
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"))

View File

@@ -25,7 +25,7 @@
#include "tga.h"
#include "list.h"
#ifdef WIN32
#include "bass.h" //for audio in windows only this should be replaced by oa_audio
#include "../lib/bass.h" //for audio in windows only this should be replaced by oa_audio
#endif
#include "vector.h"
#include "camera.h"
@@ -104,8 +104,8 @@ namespace OpenArena
uint32 numTriangles;
list<Player> players;
list<ENTITY> ents;
//list<GL_MY_TEXTURE> textures;
Texture* textures;
list<Texture> textures;
//Texture* textures;
Texture menuTextures[NUM_MENU_TEXTURES];
Window* _window;

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;

View File

@@ -29,12 +29,12 @@ using namespace std;
//These this is windows specific
static HINSTANCE hInstance; // Application instance
#endif
extern OpenArena::Window g_Screen;
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);
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);

View File

@@ -11,7 +11,7 @@ namespace OpenArena
short screenWidth;
short screenHeight;
unsigned int base;
GLuint texture;
unsigned int texture;
bool status;
public:

View File

@@ -1,4 +1,4 @@
#include "../include/myglTexture.h"
#include "myglTexture.h"
using namespace OpenArena;
namespace OpenArena

View File

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

View File

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

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

View File

@@ -9,11 +9,11 @@ namespace OpenArena
{
public:
Screen();
int GetWidth();
int GetHeight();
int GetColorDepth();
bool GetFullscreen();
const char* GetName();
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);

View File

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

View File

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

View File

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

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())
{

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

View File

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