The Pinball Game
Ian Parberry's "Introduction to Game Physics"
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CObjectManager Class Reference

The object manager. More...

#include <ObjectManager.h>

Inheritance diagram for CObjectManager:
CCommon

Public Member Functions

 ~CObjectManager ()
 Destructor. More...
 
CShape * AddShape (CShapeDesc *, const CObjDesc &)
 Add shape. More...
 
void move ()
 Move all objects.
More...
 
void draw ()
 Draw all objects. More...
 
void DrawOutlines ()
 Draw outlines of all objects. More...
 
void MakeWorldEdges ()
 Create shapes for world edges. More...
 
void MakeShapes ()
 Create shapes. More...
 
void LeftFlip (bool)
 Flip left flipper. More...
 
void RightFlip (bool)
 Flip right flipper. More...
 

Private Member Functions

CShape * MakeShape (CShapeDesc *, const CObjDesc &)
 Make a shape. More...
 
void BroadPhase ()
 Broad phase collision detection and response. More...
 
bool NarrowPhase (CShape *, CDynamicCircle *)
 Narrow phase collision detection and response. More...
 
void MakeBumper (const Vector2 &, float, eSprite, eSprite, eSound)
 Make a bumper. More...
 
void MakeBollard (const Vector2 &)
 Make a bollard. More...
 
CCompoundShape * MakeFlipper (const Vector2 &, const Vector2 &, float)
 Make a flipper. More...
 
void MakeThingL ()
 Make a thing (left). More...
 
void MakeThingR ()
 Make a thing (right). More...
 

Private Attributes

std::vector< CShape * > m_stdShapes [(UINT) eMotion::Size]
 Array of lists of shapes.
 
std::vector< CObject * > m_stdObjects
 Object list.
 
CGatem_pLeftGate = nullptr
 Pointer to left gate.
 
CGatem_pRightGate = nullptr
 Pointer to right gate.
 
CAabb2D m_cAABB
 AABB for the whole window.
 
CFlipperm_pLeftFlipper = nullptr
 Pointer to left flipper.
 
CFlipperm_pRightFlipper = nullptr
 Pointer to right flipper.
 

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 UINT m_nMIterations = 4
 Number of motion iterations.
 
static UINT m_nCIterations = 1
 Number of collision iterations.
 
static float m_fFrequency = 60.0f*m_nMIterations
 Frequency, number of physics iterations per second.
 
static eDrawMode m_eDrawMode = eDrawMode::Background
 Draw mode.
 
static bool m_bBallInPlay = false
 Is there a ball currently in play?
 
static UINT m_nScore = 0
 Current score.
 

Detailed Description

A collection of all of the game objects.

Constructor & Destructor Documentation

◆ ~CObjectManager()

CObjectManager::~CObjectManager ( )

The destructor clears the shape lists, which destructs all of the shapes in them.

Member Function Documentation

◆ AddShape()

CShape * CObjectManager::AddShape ( CShapeDesc *  sd,
const CObjDesc od 
)

Creates a new shape and pushes a contact descriptor for that shape into the shape list.

Parameters
sdPointer to a shape descriptor.
odObject descriptor.
Returns
Pointer to created shape.

◆ BroadPhase()

void CObjectManager::BroadPhase ( )
private

Do collision detection for all dynamic shapes against all static and kinematic shapes, and against all dynamic shapes that appear after it in the dynamic shape list.

◆ draw()

void CObjectManager::draw ( )

Draw the sprites for all objects.

◆ DrawOutlines()

void CObjectManager::DrawOutlines ( )

Draw the outlines of the shapes in all objects.

◆ LeftFlip()

void CObjectManager::LeftFlip ( bool  bUp)

If left flipper isn't moving up, set its rotational velocity to ROTSPEED (with the correct sign indicating direction), and play a sound.

Parameters
bUptrue for up flip, false for down flip.

◆ MakeBollard()

void CObjectManager::MakeBollard ( const Vector2 &  p)
private

A bollard is one of the long skinny things at the top.

Parameters
pPosition.

◆ MakeBumper()

void CObjectManager::MakeBumper ( const Vector2 &  p,
float  e,
eSprite  unlit,
eSprite  lit,
eSound  snd 
)
private

A bumper is a round thing that propels the balls at great speed.

Parameters
pPosition.
eElasticity.
unlitUnlit sprite index.
litLit sprite index.
sndCollision sound index.

◆ MakeFlipper()

CCompoundShape * CObjectManager::MakeFlipper ( const Vector2 &  p,
const Vector2 &  d,
float  a 
)
private

Flippers are compound shapes made up of 2 circles and 2 line segments.

Parameters
pPosition of center of rotation.
dOffset from position to center of sprite.
aInitial orientation.

◆ MakeShape()

CShape * CObjectManager::MakeShape ( CShapeDesc *  sd,
const CObjDesc od 
)
private

Create a new shape and a contact descriptor for that shape.

Parameters
sdPointer to a shape descriptor.
odAn object descriptor.
Returns
Pointer to a new contact descriptor.

◆ MakeShapes()

void CObjectManager::MakeShapes ( )

Make the static shapes for the things in the world. As with most physics code, this function is long and tedious, but it's important to get the details right.

◆ MakeThingL()

void CObjectManager::MakeThingL ( )
private

I don't know what to call it. One of the things on the left and right of the bollards at the top of the play area. This is the left one.

◆ MakeThingR()

void CObjectManager::MakeThingR ( )
private

I don't know what to call it. One of the things on the left and right of the bollards at the top of the play area. This is the right one.

◆ MakeWorldEdges()

void CObjectManager::MakeWorldEdges ( )

Make the static shapes for the world boundaries. As with most physics code, this function is long and tedious, but it's important to get the details right.

◆ move()

void CObjectManager::move ( )

Move all of the shapes in the dynamic and kinematic shape lists and perform collision response.

◆ NarrowPhase()

bool CObjectManager::NarrowPhase ( CShape *  pShape,
CDynamicCircle *  pCirc 
)
private

Check whether a pair of shapes collides and make appropriate response.

Parameters
pShapePointer to a static or kinematic shape.
pCircPointer to moving circle.
Returns
true if there was a collision.

◆ RightFlip()

void CObjectManager::RightFlip ( bool  bUp)

If right flipper isn't moving up, set its rotational velocity to ROTSPEED (with the correct sign indicating direction), and play a sound.

Parameters
bUptrue for up flip, false for down flip.