Collision Math Toy
Ian Parberry's "Introduction to Game Physics"
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CGame Class Reference

The game class.

#include <Game.h>

Inheritance diagram for CGame:
CCommon

Public Member Functions

 ~CGame ()
 Destructor. More...
 
void Initialize ()
 Initialize the game. More...
 
void ProcessFrame ()
 Process an animation frame. More...
 
void Release ()
 Release the renderer. More...
 

Private Member Functions

void LoadSounds ()
 Load sounds. More...
 
void BeginGame ()
 Begin playing the game. More...
 
void KeyboardHandler ()
 The keyboard handler. More...
 
void RenderFrame ()
 Render an animation frame. More...
 
void Launch ()
 Create and launch a ball. More...
 
void ProcessLaunch ()
 Process launch and multilaunch. More...
 

Private Attributes

CObjectManagerm_pObjectManager = nullptr
 Pointer to the object manager.
 
CDialogBoxm_pDialogBox = nullptr
 Pointer to a dialog box.
 

Additional Inherited Members

- Static Protected Attributes inherited from CCommon
static CRendererm_pRenderer = nullptr
 Pointer to the renderer.
 
static CObjectManagerm_pObjectManager = nullptr
 Pointer to the object manager.
 
static LParticleEngine2D * m_pFrontParticleEngine = nullptr
 Pointer to front particle engine.

 
static LParticleEngine2D * m_pBackParticleEngine = nullptr
 Pointer to front particle engine.
 
static bool m_bShowTrack = false
 Show trail of breadcrumbs.
 
static bool m_bShowReticles = false
 Show reticle at hit point.
 
static bool m_bShowImpacts = false
 Draw dots at collision points.
 
static bool m_bShowArrows = false
 Draw arrows for velocity vectors.
 
static bool m_bShowTangents = false
 Draw arrows for tangents.
 
static bool m_bShowSectors = false
 Draw arc sentinels and normals.
 
static bool m_bShowAABBs = false
 Draw shape AABBs.
 
static bool m_bShowLights = false
 Light up shapes on collision.
 
static bool m_bRotate = false
 Rotate kinematic shapes.
 
static bool m_bLaunch = false
 Launch a ball.
 
static bool m_bMute = false
 Mute the sound.
 
static float m_fNextBallScale = 0.5f
 Scale factor for ball size.
 
static int m_nMIterationsInit = 4
 Initial number of motion iterations.
 
static int m_nCIterationsInit = 6
 Initial number of collision iterations.
 
static int m_nMIterations = CCommon::m_nMIterationsInit
 Current number of motion iterations.
 
static int m_nCIterations = CCommon::m_nCIterationsInit
 Current number of collision iterations.
 
static bool m_bUseQuadTree = false
 Whether to use a quadtree.
 
static HWND m_hDlg = nullptr
 Control dialog box handle.
 
static float m_fLoad = 0.0f
 Processor load.
 
static float m_fLaunchSpeed = 1000.0f
 Speed at which the next ball will be launched.
 
static int m_nDesiredLaunchCnt = 1
 Number of balls to launch at next multilaunch.
 
static int m_nLaunched = 0
 Number of balls launched in current multilaunch.
 
static bool m_bMultiLaunch = false
 Whether launching multiple balls.
 
static int m_nBallsLaunched = 0
 Number of balls in play.
 
static float m_fFrequency = 60.0f*m_nMIterations
 Frequency, number of physics iterations per second.
 

Constructor & Destructor Documentation

◆ ~CGame()

CGame::~CGame ( )

Delete the renderer, particle engines, object manager, and the dialog box.

Member Function Documentation

◆ BeginGame()

void CGame::BeginGame ( )
private

Clear any old objects out of the object manager and create some new ones.

◆ Initialize()

void CGame::Initialize ( )

Initialize the renderer, particle engines, object manager, and the dialog box. Load images and sounds. Begin the game.

◆ KeyboardHandler()

void CGame::KeyboardHandler ( )
private

This is essentially a null keyboard handler because all used input is handled by buttons on the dialog box.

◆ Launch()

void CGame::Launch ( )
private

Create a ball and launch it, while playing the launch sound.

◆ LoadSounds()

void CGame::LoadSounds ( )
private

Initialize the audio player and load game sounds.

◆ ProcessFrame()

void CGame::ProcessFrame ( )

Handle keyboard input, move the game objects and render them in their new positions and orientations. Notify the audio player at the start of each frame so that it can prevent multiple copies of a sound from starting on the same frame. Ask the particle engines to animate a frame for their particles and update the dialog box so that it shows reasonable up-to-date information in its edit boxes. If m_bLaunch has been set by the dialog box, then launch a ball.

◆ ProcessLaunch()

void CGame::ProcessLaunch ( )
private

If the launch flag is set, launch a single ball and unset the flag. If the multilaunch flag is set, check whether enough time has passed to separate the balls by one radius given their launch speed and scale, and launch a new ball if it has. When enough balls have been launched, unset the multilaunch flag.

◆ Release()

void CGame::Release ( )

Release all of the DirectX12 objects by deleting the renderer.

◆ RenderFrame()

void CGame::RenderFrame ( )
private

Ask the object manager to draw the game objects. The renderer is notified of the start and end of the frame so that it can let Direct3D do its pipelining jiggery-pokery. In addition, draw the gate sprite on top of everything else and keep a record of the amount of time spent rendering and the amount of time waiting for the page flip. This will enable us to display an approximation to the processor load in the dialog box. Note: This function calls timeGetTime(), so make sure that winmm.lib is included in the library files.