Dragonfly 4.19
A text-based game engine
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
df::WorldManager Class Reference
Inheritance diagram for df::WorldManager:
Inheritance graph

Public Member Functions

int startUp () override
 
void shutDown () override
 
bool isValid (std::string event_type) const override
 
int insertObject (Object *p_o)
 
int removeObject (Object *p_o)
 
ObjectList getAllObjects (bool inactive=false) const
 
int markForDelete (Object *p_o)
 
int markForDelete (ObjectList obj_list)
 
void update ()
 
void draw ()
 
int moveObject (Object *p_o, Vector where)
 
ObjectList getCollisions (Object *p_o, Vector where) const
 
ObjectobjectWithId (int id) const
 
ObjectList objectsOfType (std::string type)
 
ObjectList objectsAtPosition (Vector where) const
 
ObjectList objectsInBox (Box box) const
 
ObjectList objectsOnLine (Line line) const
 
ObjectList objectsInCircle (Circle circle) const
 
Box getBoundary () const
 
void setBoundary (Box new_boundary)
 
Box getView () const
 
void setView (Box new_view)
 
Vector getViewSlack () const
 
void setViewSlack (Vector new_slack)
 
int setViewFollowing (Object *p_new_view_following)
 
ObjectgetViewFollowing () const
 
void setViewPosition (Vector view_pos)
 
SceneGraphgetSceneGraph () const
 
- Public Member Functions inherited from df::Manager
std::string getType () const
 
virtual int startUp ()
 
virtual void shutDown ()
 
bool isStarted () const
 
int onEvent (const Event *p_event) const
 
int registerInterest (Object *p_o, std::string event_type)
 
int unregisterInterest (Object *p_o, std::string event_type)
 

Static Public Member Functions

static WorldManagergetInstance ()
 

Private Member Functions

 WorldManager ()
 
 WorldManager (WorldManager const &)
 
void operator= (WorldManager const &)
 

Private Attributes

SceneGraph m_scene_graph
 
ObjectList m_deletions
 
Objectm_p_view_following
 
Box m_boundary
 
Box m_view
 
Vector m_view_slack
 

Additional Inherited Members

- Protected Member Functions inherited from df::Manager
void setType (std::string new_type)
 

Constructor & Destructor Documentation

◆ WorldManager() [1/2]

df::WorldManager::WorldManager ( )
private

Private since a singleton.

◆ WorldManager() [2/2]

df::WorldManager::WorldManager ( WorldManager const &  )
private

Don't allow copy.

Member Function Documentation

◆ draw()

void df::WorldManager::draw ( )

Draw all Objects in view.

Draw bottom up, from 0 to MAX_ALTITUDE.

◆ getAllObjects()

ObjectList df::WorldManager::getAllObjects ( bool  inactive = false) const

Return list of all Objects in world.

If inactive is true, include inactive Objects.

◆ getBoundary()

Box df::WorldManager::getBoundary ( ) const

Get game world boundary.

◆ getCollisions()

ObjectList df::WorldManager::getCollisions ( Object p_o,
Vector  where 
) const

Return list of Objects collided with at position 'where'.

Collisions only with solid Objects. Does not consider if p_o is solid or not.

◆ getInstance()

static WorldManager & df::WorldManager::getInstance ( )
static

Get the one and only instance of the WorldManager.

◆ getSceneGraph()

SceneGraph & df::WorldManager::getSceneGraph ( ) const

Return reference to SceneGraph.

◆ getView()

Box df::WorldManager::getView ( ) const

Get player view of game world.

◆ getViewFollowing()

Object * df::WorldManager::getViewFollowing ( ) const

Get Object view is following (NULL if none).

◆ getViewSlack()

Vector df::WorldManager::getViewSlack ( ) const

Get player "slack" for view following.

Units are in fraction of view (0-1).

◆ insertObject()

int df::WorldManager::insertObject ( Object p_o)

Add Object to world.

Return 0 if ok, else -1.

◆ isValid()

bool df::WorldManager::isValid ( std::string  event_type) const
overridevirtual

Accept all user-defined events (returns true).

Return false for other engine events.

Reimplemented from df::Manager.

◆ markForDelete() [1/2]

int df::WorldManager::markForDelete ( Object p_o)

Indicate Object is to be deleted at end of current game loop.

Return 0 if ok, else -1.

◆ markForDelete() [2/2]

int df::WorldManager::markForDelete ( ObjectList  obj_list)

Indicate Objects in list are to be deleted at end of current game loop.

Return 0 if ok, else -1.

◆ moveObject()

int df::WorldManager::moveObject ( Object p_o,
Vector  where 
)

Move Object.

If collision with solid, send collision events. If no collision with solid, move ok. If all collided objects soft, move ok. If Object is spectral, move ok. If move ok, move. If moved, adjust view if following this Object. If moved from inside world boundary to outside, generate EventOut. Return 0 if moved, else -1 if collision with solid.

◆ objectsAtPosition()

ObjectList df::WorldManager::objectsAtPosition ( Vector  where) const

Return list of all Objects at position 'where'.


Does include bounding boxes. Return empty list if none found.

◆ objectsInBox()

ObjectList df::WorldManager::objectsInBox ( Box  box) const

Return list of all Objects in Box.

Does include bounding boxes. Return empty list if none found.

◆ objectsInCircle()

ObjectList df::WorldManager::objectsInCircle ( Circle  circle) const

Return a list of all Objects in circle.

Does include bounding boxes. Return empty list if none found.

◆ objectsOfType()

ObjectList df::WorldManager::objectsOfType ( std::string  type)

Return list of Objects matching type.

List is empty if none found.

◆ objectsOnLine()

ObjectList df::WorldManager::objectsOnLine ( Line  line) const

Return a list of all Objects on line from point1 to point2.

Does include bounding boxes. Return empty list if none found.

◆ objectWithId()

Object * df::WorldManager::objectWithId ( int  id) const

Return Object with indicated id.

NULL if Object is not found.

◆ operator=()

void df::WorldManager::operator= ( WorldManager const &  )
private

Don't allow assignment.

◆ removeObject()

int df::WorldManager::removeObject ( Object p_o)

Remove Object from world.

Return 0 if ok, else -1.

◆ setBoundary()

void df::WorldManager::setBoundary ( Box  new_boundary)

Set game world boundary.

◆ setView()

void df::WorldManager::setView ( Box  new_view)

Set player view of game world.

◆ setViewFollowing()

int df::WorldManager::setViewFollowing ( Object p_new_view_following)

Set view to center screen on Object.

Set to NULL to stop following. If Object not legit, return -1 else return 0.

◆ setViewPosition()

void df::WorldManager::setViewPosition ( Vector  view_pos)

Set view to center screen on position view_pos.

View edge will not go beyond world boundary.

◆ setViewSlack()

void df::WorldManager::setViewSlack ( Vector  new_slack)

Set player "slack" for view following.

Units are in fraction of view (0-1).

◆ shutDown()

void df::WorldManager::shutDown ( )
overridevirtual

Shutdown game world (delete all game world Objects).

Reimplemented from df::Manager.

◆ startUp()

int df::WorldManager::startUp ( )
overridevirtual

Startup game world (initialize everything to empty).

Return 0.

Reimplemented from df::Manager.

◆ update()

void df::WorldManager::update ( )

Update world.

Update positions of Objects based on their velocities. Lastly, delete Objects marked for deletion.

Member Data Documentation

◆ m_boundary

Box df::WorldManager::m_boundary
private

World boundary.

◆ m_deletions

ObjectList df::WorldManager::m_deletions
private

List of all Objects to delete.

◆ m_p_view_following

Object* df::WorldManager::m_p_view_following
private

Object view is following.

◆ m_scene_graph

SceneGraph df::WorldManager::m_scene_graph
private

Storage for all Objects, game and view.

◆ m_view

Box df::WorldManager::m_view
private

Player view of game world.

◆ m_view_slack

Vector df::WorldManager::m_view_slack
private

"Slack" for view following.