codesamples >> crossplatform mainprogram class

Crossplatform: MainProgram class

Project:

Crossplatform application (Windows & PS3)

Engine:

Custom

Code language:

C++

Class description:

The main class which creates all the important objects for Windows and PS3.

MainProgram.cpp

#include "MainProgram.h"
#include "SceneManager.h"
#include "Camera.h"

#if defined(WIN32)
// Windows Specific: Includes
#include "ShaderManager_Win32.h"
#include "Device_Win32.h"
#endif

#if defined(PS3)
// PS3 Specific: Includes
#include "ShaderManager_PS3.h"
#include "Device_PS3.h"
#endif

// Constructor
MainProgram::MainProgram(): m_pSceneManager(0), m_pCamera(0), m_pShaderManager(0)
{
}

// Destructor
MainProgram::~MainProgram()
{
	// Delete pointers and set to zero
	delete m_pSceneManager;
	m_pSceneManager = 0;

	delete m_pCamera;
	m_pCamera = 0;

	delete m_pShaderManager;
	m_pShaderManager;
}

void MainProgram::CreateScene(DEVICE* device)
{
	// Create the scene and add objects
	m_pSceneManager = new SceneManager(device);
	m_pSceneManager->CreateCubes(10);
	m_pSceneManager->CreateOctahedrons(1000);
}

void MainProgram::Update(float time)
{
	// Update the Camera & the scene
	m_pCamera->Update(time);
	m_pSceneManager->UpdateScene(m_pCamera, time);
}

#if defined(WIN32)
void MainProgram::CreateCamera(int width, int height)
{
	// Create the camera
	m_pCamera = new Camera(width, height);
}

void MainProgram::CreateShader(ID3D11Device* device, ID3D11DeviceContext* deviceContext)
{
	// Create the Win32 ShaderManager
	m_pShaderManager = new ShaderManager_Win32(device, deviceContext, m_pCamera);
}
#endif

#if defined(PS3)
void MainProgram::CreateCamera()
{
	// Create the camera
	m_pCamera = new Camera();
}

void MainProgram::CreateShader()
{
	// Create the PS3 ShaderManager
	m_pShaderManager = new ShaderManager_PS3();
}
#endif

MainProgram.h

#ifndef _MAINPROGRAM_H
#define _MAINPROGRAM_H

// Windows Specific: Includes & Forward declarations
#if defined(WIN32)
#include <windows.h>
#include <d3d11.h>
#include <d3dx11.h>
#include <d3dcompiler.h>
#include <vector>
#include <assert.h>
#include <string.h>

#include "Device_Win32.h"

class ShaderManager_Win32;

#elif(PS3)
// PS3 Specific: Includes & Forward declarations
#include "Device_PS3.h"

class ShaderManager_PS3;
#endif

// Crossplatform: Forward declarations
class SceneManager;
class Camera;

class MainProgram
{
public:

	// Crossplatform: Functions
	MainProgram();
	virtual ~MainProgram();
	void Update(float time);
	Camera* GetCamera(){return m_pCamera;}
	SceneManager* GetScene(){return m_pSceneManager;}
	void CreateScene(DEVICE* device);

	// Platform specific functions
	#if defined(WIN32)
	// Windows Specific: Functions
	void CreateCamera(int width, int height);
	void CreateShader(ID3D11Device* device, ID3D11DeviceContext* deviceContext);
	ShaderManager_Win32* GetShaderManager(){return m_pShaderManager;}	

	#elif defined(PS3)
	// PS3 Specific: Functions
	void CreateCamera();
	void CreateShader();
	ShaderManager_PS3* GetShaderManager(){return m_pShaderManager;}
	#endif

private:
	// Crossplatform: Datamembers
	SceneManager* m_pSceneManager;
	Camera* m_pCamera;

#if defined(WIN32)
	// Windows Specific: Datamembers
	ShaderManager_Win32* m_pShaderManager;

#elif(PS3)
	// PS3 Specific: Datamembers
	ShaderManager_PS3* m_pShaderManager;
#endif
};


#endif