Skip to content

Instantly share code, notes, and snippets.

@clooth
Created September 2, 2012 10:52
Show Gist options
  • Save clooth/3596777 to your computer and use it in GitHub Desktop.
Save clooth/3596777 to your computer and use it in GitHub Desktop.
#ifndef ENGINE_H
#define ENGINE_H
#include "SDL.h"
/** The base engine class **/
class CEngine {
private:
/** Last iteration's tick value **/
long m_lLastTick;
/** Window size **/
int m_iWidth;
int m_iHeight;
/** Has quit been called? **/
bool m_bQuit;
/** The title of the window **/
const char* m_czTitle;
/** Screen surface **/
SDL_Surface* m_pScreen;
/** Is the window minimized? **/
bool m_bMinimized;
/** Variables to calculate the frame rate **/
/** Tick counter **/
int m_iFPSTickCounter;
/** Frame rate counter **/
int m_iFPSCounter;
/** Stores the last calculated frame rate **/
int m_iCurrentFPS;
protected:
void DoThink();
void DoRender();
void SetSize(const int& iWidth, const int& iHeight);
void HandleInput();
public:
CEngine();
virtual ~CEngine();
void Init();
void Start();
/** Overloaded - Data that should be initialized when the application starts. **/
virtual void AdditionalInit() {}
/** Overloaded - All the games calculation and updating.
@param iElapsedTime The time in ms elapsed since the function was called last. **/
virtual void Think(const int& iElapsedTime) {}
/** Overloaded - All the games rendering.
@param pDestSurface The main screen surface. **/
virtual void Render(SDL_Surface* pDestSurface) {}
/** Overloaded - Allocated data that should be cleaned up. **/
virtual void End() {}
/** Overloaded - Window is active again **/
virtual void WindowActive() {}
/** Overloaded - Window is inactive **/
virtual void WindowInactive() {}
/** Overloaded - Keyboard key has been released.
@param iKeyEnum The key number. **/
virtual void KeyUp(const int& iKeyEnum) {}
/** Overloaded - Keyboard key has just been pressed.
@param iKeyEnum The key number. **/
virtual void KeyDown(const int& iKeyEnum) {}
/** Overloaded - The mouse has been moved.
@param iButton Specifies if a mouse button is pressed.
@param iX The mouse position on the X-axis in pixels.
@param iY The mouse position on the Y-axis in pixels.
@param iRelX The mouse position on the X-axis relative to the last position.
@param iRelY The mouse position on the Y-axis relative to the last position. **/
virtual void MouseMoved(const int& iButton,
const int& iX,
const int& iY,
const int& iRelX,
const int& iRelY) {}
/** Overloaded - A mouse button has been released.
@param iButton Specifies if a mouse button is pressed.
@param iX The mouse position on the X-axis in pixels.
@param iY The mouse position on the Y-axis in pixels.
@param iRelX The mouse position on the X-axis relative to the last position.
@param iRelY The mouse position on the Y-axis relative to the last position. **/
virtual void MouseButtonUp(const int& iButton,
const int& iX,
const int& iY,
const int& iRelX,
const int& iRelY) {}
/** Overloaded - A mouse button has been pressed.
@param iButton Specifies if a mouse button is pressed.
@param iX The mouse position on the X-axis in pixels.
@param iY The mouse position on the Y-axis in pixels.
@param iRelX The mouse position on the X-axis relative to the last position.
@param iRelY The mouse position on the Y-axis relative to the last position. **/
virtual void MouseButtonDown(const int& iButton,
const int& iX,
const int& iY,
const int& iRelX,
const int& iRelY) {}
void SetTitle(const char* czTitle);
const char* GetTitle();
SDL_Surface* GetSurface();
int getFPS();
};
#endif // ENGINE_H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment