The Pinball Game
Game Physics with Bespoke Code
Loading...
Searching...
No Matches
CObjectManager Class Reference

The object manager. More...

#include <ObjectManager.h>

Inheritance diagram for CObjectManager:
Collaboration diagram for CObjectManager:

Public Member Functions

 ~CObjectManager ()
 Destructor.
 
Shapes::CShape * AddShape (Shapes::CShapeDesc *, const CObjDesc &)
 Add shape.
 
void Move ()
 Move all objects.

 
void Draw ()
 Draw all objects.
 
void DrawOutlines ()
 Draw outlines of all objects.
 
void MakeWorldEdges ()
 Create shapes for world edges.
 
void MakeShapes ()
 Create shapes.
 
void LeftFlip (bool)
 Flip left flipper.
 
void RightFlip (bool)
 Flip right flipper.
 

Private Member Functions

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

Private Attributes

std::vector< Shapes::CShape * > m_stdShapes [(UINT) Shapes::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.
 
Shapes::CAabb2D m_cAABB
 AABB for the whole window.
 
CFlipperm_pLeftFlipper = nullptr
 Pointer to left flipper.
 
CFlipperm_pRightFlipper = nullptr
 Pointer to righ t flipper.
 

Additional Inherited Members

- Static Protected Attributes inherited from CCommon
static Sage::CSpriteRenderer * m_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 managed 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()

Shapes::CShape * CObjectManager::AddShape ( Shapes::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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Draw()

void CObjectManager::Draw ( )

Draw the game objects using Painter's Algorithm. The background is drawn first, then the game objects are asked to draw themselves in the order that they are in the object list. That is, they are drawn from back to front.

Here is the caller graph for this function:

◆ DrawOutlines()

void CObjectManager::DrawOutlines ( )

Draw the outlines of the shapes in all objects.

Here is the caller graph for this function:

◆ 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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MakeBollard()

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

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

Parameters
pPosition.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MakeFlipper()

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

Make a compound shape for a flipper, which is made up of two circles and two line segments tangent to the circles.

Parameters
pPosition of center of rotation.
dOffset from position to center of sprite.
aInitial orientation.
Returns
Pointer to the created compound shape.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MakeShape()

Shapes::CShape * CObjectManager::MakeShape ( Shapes::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.
Here is the caller graph for this function:

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Move()

void CObjectManager::Move ( )

Move all dynamic and kinematic shapes and perform broad phase collision detection and response.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ NarrowPhase()

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

Check whether a shape collides with a dynamic circle and make response.

Parameters
pShapePointer to a static or kinematic shape.
pCircPointer to moving circle.
Returns
true if there was a collision.
Here is the caller graph for this function:

◆ 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.
Here is the call graph for this function:
Here is the caller graph for this function: