I AM SUCH A NEWBITO
Posted: Thu Oct 09, 2008 6:35 am
I have written some crap, half assed framework and I was just wondering what you guys thought of it. Keep in mind its horrible and really spaghetti coded. Its a game state framework and I have no idea if there is a better way to manage my game. Ignore the mesh loading I am going to be making an xml reader sooner or later. In fact pretty much ignore anything that uses the Irrlicht API. This is in response to Lusikka Mage not knowing what I was talking about in my pm.
main.cpp
GAME LOOP
CGameManager:
CGameState:
And of course its a mish mash of other game state frameworks. I give credit where credit is due.
main.cpp
Code: Select all
#include <iostream>
#include <irrlicht.h> // Include the Irrlicht Library
#include "include/CGame.h"
int main(int argc, char* argv[])
{
CGame Game;
Game.Run();
return 0;
}
Code: Select all
#ifndef CGAME_H
#define CGAME_H
#include "../include/CGameManager.h"
class CGame
{
public:
CGame();
virtual ~CGame();
void Run(); // Game Loop
CGameManager m_pGameManager; // Object from CGameManager
protected:
private:
};
#endif // CGAME_H
Code: Select all
#include "../include/CGame.h"
CGame::CGame()
{
//ctor
}
CGame::~CGame()
{
//dtor
}
void CGame::Run() // Game Loop
{
while(m_pGameManager.getDevice()->run()) // While the Running Function Returns True
{
m_pGameManager.HandleEvents(); // Handle Events
m_pGameManager.Update(); // Update
m_pGameManager.Draw(); // Draw
}
// m_pGameManager.Cleanup(); // When loop ends, Clean Up
// m_pGameManager.File()->LoadGUI("data/configure/gui/gui_exit.gcs", true); // Say goodbye
}
Code: Select all
#ifndef CGAMEMANAGER_H
#define CGAMEMANAGER_H
#include <iostream>
#include <irrlicht.h>
#include "../src/ATMOsphere.cpp"
#include <stdio.h>
#include <math.h>
#include <wchar.h>
class CGameState;
using namespace std;
using namespace irr;
using namespace core;
using namespace video;
using namespace scene;
using namespace io;
using namespace gui;
class CGameManager
{
public:
CGameManager();
virtual ~CGameManager();
void Init(); // Initialise some things
void ChangeState(CGameState* state); // Change States
void HandleEvents(); // Handle Events
void Update(); // Update information
void Draw(); // Draw your graphics
bool Running() { return m_running; } // Returns if the games still running
void Quit() { m_running = false; } // Quit sets m_run to false.
IrrlichtDevice* getDevice();
IVideoDriver* getDriver();
ISceneManager* getSmgr();
IGUIEnvironment* getEnv();
ATMOsphere* getATMO();
private:
friend class CGameState;
CGameState* m_pGameState; // Vector of the states
IrrlichtDevice* m_pDevice;
IVideoDriver* m_pDriver;
ISceneManager* m_pSmgr;
IGUIEnvironment* m_pEnv;
ATMOsphere* m_pAtmo;
void CreateDevice();
bool m_running; // The variable that determines if the state is running.
protected:
};
#endif // CGAMEMANAGER_H
Code: Select all
#include "../include/CGameManager.h"
#include "../include/CGameState.h"
#include "../include/CGameStateLevel1.h"
CGameManager::CGameManager()
{
Init();
CreateDevice();
ChangeState( CGameStateLevel1::Instance() );
}
CGameManager::~CGameManager()
{
}
void CGameManager::Init()
{
m_pGameState = 0;
m_pAtmo = new ATMOsphere;
}
void CGameManager::CreateDevice()
{
m_pDevice = createDevice( video::EDT_OPENGL, dimension2d<s32>(1280, 960), 32,
false, true, true, 0);
m_pDriver = m_pDevice->getVideoDriver();
m_pSmgr = m_pDevice->getSceneManager();
m_pEnv = m_pDevice->getGUIEnvironment();
m_pDevice->setWindowCaption(L"Dejaiin- Development Version");
}
void CGameManager::ChangeState(CGameState* state)
{
if(m_pGameState)
{
m_pGameState->Cleanup(this);
}
if(state != m_pGameState)
{
m_pGameState = state;
m_pGameState->Init(this);
}
}
///////////////////////////////////////////////////////
IrrlichtDevice* CGameManager::getDevice()
{
return m_pDevice;
}
IVideoDriver* CGameManager::getDriver()
{
return m_pDriver;
}
ISceneManager* CGameManager::getSmgr()
{
return m_pSmgr;
}
IGUIEnvironment* CGameManager::getEnv()
{
return m_pEnv;
}
ATMOsphere* CGameManager::getATMO()
{
return m_pAtmo;
}
////////////////////////////////////////////////////////////
void CGameManager::HandleEvents()
{
m_pGameState->HandleEvents(this);
}
void CGameManager::Update()
{
m_pGameState->Update(this);
}
void CGameManager::Draw()
{
m_pDriver->beginScene(true, true, SColor(255,100,101,140));
m_pGameState->Draw(this);
m_pSmgr->drawAll();
m_pEnv->drawAll();
m_pDriver->endScene();
}
Code: Select all
#ifndef CGAMESTATE_H
#define CGAMESTATE_H
#include "../include/CGameManager.h"
class CGameState
{
public:
virtual void Init(CGameManager* game) = 0; // Initialisation
virtual void Cleanup(CGameManager* game) = 0; // Clean up before moving to the next class
virtual void Pause(CGameManager* game) = 0; // Pause the state
virtual void Resume(CGameManager* game) = 0; // Resume the state
virtual void HandleEvents(CGameManager* game) = 0; // Handle Events
virtual void Update(CGameManager* game) = 0; // Update
virtual void Draw(CGameManager* game) = 0; // Draw
void ChangeState(CGameManager* game, CGameState* state) {
game->ChangeState(state); // Change the state.
}
protected:
CGameState() { } // Default Constructor
private:
};
#endif // CGAMESTATE_H
And of course its a mish mash of other game state frameworks. I give credit where credit is due.