#pragma once
#include <Windows.h>
#include <vector>
#include "cDirect3D.h"
#include "cCamera.h"
#include "cTerrain.h"
#include "cXFile.h"
#include "userinput.h"
#include "defines.h"
#include "font.h"
// SINGLETON Class that holds all the info all the classes need to reach. =) ****-> Johan.
class DataBase
{
public:
static DataBase* getInstance(); // Returns the instance of the database that we have made, if we haven´t it create one ****-> Johan.
~DataBase(); // Destructor, this cleans all the crap.
IDirect3DVertexBuffer9 * g_pVB; // vertex buffer
IDirect3DIndexBuffer9 * g_pIB; // index buffer
IDirect3DTexture9 * g_pTexture[4]; // texture handle
int g_nVertices; // number of vertices
int g_nIndices; // number if indices
float * g_height; // heightmap
float g_offsY; // camera height over ground
cTerrain *m_terrain;
Direct3D* d3d;
UserInput g_ui;
class Camera* g_cam;
class cFont* m_font[NUMFONTS];
class cXFile* m_xFile;
private:
DataBase(); // Default Constructor, read more in the DataBase.cpp ****-> Johan.
DataBase(const DataBase &) {} // Constructor witch take a database as a variable ****-> Johan.
static DataBase *m_DataBase; // The database itself ****-> Johan.
};
////////////////////////////////
/***** MADE BY *********
* JOHAN JOHNSSON *
******************************/
#include "cDatabase.h"
#include "cCamera.h"
#include "defines.h"
// ----------------------------------------------------------------------------
// Initialize - Set the database pointer to zero ****-> Johan
// ----------------------------------------------------------------------------
DataBase* DataBase::m_DataBase = 0;
// ----------------------------------------------------------------------------
// getInstance - return singleton instance ****-> Johan
// ----------------------------------------------------------------------------
DataBase* DataBase::getInstance()
{
if( !m_DataBase ) // First time caller?
m_DataBase = new DataBase();
return m_DataBase; // Return it!
}
// ----------------------------------------------------------------------------
// DataBase Default Constructor - Sets the variables to the proper value ****->Johan
// ----------------------------------------------------------------------------
DataBase::DataBase()
{
g_pVB = NULL; // vertex buffer
g_pIB = NULL; // index buffer
g_nVertices = 0; // number of vertices
g_nIndices = 0; // number if indices
g_height = NULL; // heightmap
g_offsY = 0; // camera height over ground
g_cam = new Camera(D3DXVECTOR3(0, 0, 0), 0, D3DX_PI * 1.15f, 0); // the camera
d3d = new Direct3D();
m_xFile = new cXFile[NUMOBJECTS];
}
// ----------------------------------------------------------------------------
// ~DataBase default destructor - Cleans up the shit we have made ****-> Johan
// ----------------------------------------------------------------------------
DataBase::~DataBase()
{
g_pTexture[0]->Release();
g_pTexture[1]->Release();
g_pTexture[2]->Release();
g_pTexture[3]->Release();
if(g_pVB)
g_pVB->Release();
if(g_pIB)
g_pIB->Release();
delete g_cam;
delete[] m_xFile;
delete d3d;
}