Inherits from NSObject
Conforms to NSFastEnumeration
Declared in OGWWorldEntities.h

Overview

Categorized collection of entities with fast lookup by uniqueID (dictionary) and fast, ordered enumeration (array). Special enumerators exist to query entities within a rectangle, distance (radius), category and other filters or combinations.

Tip: try to optimize your entity categories for enumerations. If you find yourself often needing to enumerate different categories or all entities to do the same thing, consider if you can improve the categorization of your entities to better sort your enumeration needs. Remember: categories were built for enumeration!

Note: currently no filtered enumeration optimizations are in place, but it is planned to implement spatial hashing in the future to speed up location-based enumerations.

Properties

all

An array containing all entities in the world.

@property (readonly) NSArray *all

Return Value

An array containing all entities in the world.

See Also

Declared In

OGWWorldEntities.h

Class Methods

entitiesWithWorld:

+ (id)entitiesWithWorld:(OGWWorld *)world

Instance Methods

addEntitiesInArray:

Adds entities from an array.

- (void)addEntitiesInArray:(NSArray *)entities

Parameters

entities

An array of entities.

Declared In

OGWWorldEntities.h

addEntity:

Add an entity.

- (void)addEntity:(OGWEntity *)entity

Parameters

entity

The entity to add.

Declared In

OGWWorldEntities.h

createCollectionForCategory:

- (void)createCollectionForCategory:(const OGWEntityCategory *)category

entitiesInCategory:

Returns an array of all entities whose category matches. This is a fast operation, the array already exists, it is not created dynamically.

- (NSArray *)entitiesInCategory:(const OGWEntityCategory *)category

Parameters

category

An instance of OGWEntityCategory previously added to the world.

Return Value

An array of OGWEntity objects with matching category.

Declared In

OGWWorldEntities.h

entityForUniqueID:

Returns entity by ID.

- (OGWEntity *)entityForUniqueID:(GWID)uniqueID

Parameters

uniqueID

An entity’s unique ID.

Return Value

The entity for a given unique ID number. Returns nil if no such entity exists.

Declared In

OGWWorldEntities.h

enumerateEntitiesContainingPoint:usingBlock:

Enumerate all entities whose world bounding boxes contain the point (in world coordinates).

- (void)enumerateEntitiesContainingPoint:(GWPoint)point usingBlock:(OGWEntityEnumerationBlock)block

Parameters

point

The point the entity must contain, in world coordinates.

block

The block to run for each entity whose world bounding box contains the point.

Declared In

OGWWorldEntities.h

enumerateEntitiesInCategory:containingPoint:usingBlock:

Enumerate all entities of a given category whose bounding boxes contain a point.

- (void)enumerateEntitiesInCategory:(const OGWEntityCategory *)category containingPoint:(GWPoint)point usingBlock:(OGWEntityEnumerationBlock)block

Parameters

category

A reference to a valid OGWEntityCategory previously added to the world.

point

The point the entities test for containment, in world coordinates.

block

The block to run for each entity with a matching category and whose world bounding box contains the point.

Declared In

OGWWorldEntities.h

enumerateEntitiesInCategory:intersectingRect:usingBlock:

Enumerate all entities of a given category intersecting a rectangle.

- (void)enumerateEntitiesInCategory:(const OGWEntityCategory *)category intersectingRect:(GWRect)rect usingBlock:(OGWEntityEnumerationBlock)block

Parameters

category

A reference to a valid OGWEntityCategory previously added to the world.

rect

The rect the entities will test for intersection, in world coordinates.

block

The block to run for each entity with a matching category and intersecting world bounding box.

Declared In

OGWWorldEntities.h

enumerateEntitiesInCategory:near:radius:usingBlock:

Enumerate all entities of a given category near a point in a given radius.

- (void)enumerateEntitiesInCategory:(const OGWEntityCategory *)category near:(GWPoint)center radius:(GWFloat)radius usingBlock:(OGWEntityEnumerationBlock)block

Parameters

category

A reference to a valid OGWEntityCategory previously added to the world.

center

The center point of the radius/distance check, in world coordinates.

radius

The radius (aka distance) in which to search for entities.

block

The block to run for each entity with a matching category and within radius of the center point.

Declared In

OGWWorldEntities.h

enumerateEntitiesInCategory:usingBlock:

Enumerate all entities of a given category. The block runs for every entity with a matching category.

- (void)enumerateEntitiesInCategory:(const OGWEntityCategory *)category usingBlock:(OGWEntityEnumerationBlock)block

Parameters

category

A reference to a valid OGWEntityCategory previously added to the world.

block

The block to run for each entity with a matching category.

Declared In

OGWWorldEntities.h

enumerateEntitiesIntersectingRect:usingBlock:

Enumerate all entities whose world bounding boxes intersect a rectangle.

- (void)enumerateEntitiesIntersectingRect:(GWRect)rect usingBlock:(OGWEntityEnumerationBlock)block

Parameters

rect

A rect in world coordinates.

block

The block to run for each intersecting entity.

Declared In

OGWWorldEntities.h

enumerateEntitiesNear:radius:usingBlock:

Enumerate all entities within a given radius (distance) to the center point.

- (void)enumerateEntitiesNear:(GWPoint)center radius:(GWFloat)radius usingBlock:(OGWEntityEnumerationBlock)block

Parameters

center

The center position of the distance check, in world coordinates.

radius

The radius around (distance from) the center point where to look for entities.

block

The block to run for each entity whose distance to the center point is less than or equal to radius.

Declared In

OGWWorldEntities.h

removeAllEntitiesInCategory:

Removes all entities with matching category.

- (void)removeAllEntitiesInCategory:(const OGWEntityCategory *)category

Parameters

category

An instance of OGWEntityCategory previously added to the world.

Declared In

OGWWorldEntities.h

removeEntity:

Removes an entity. Does nothing if the entity does not exist or is nil.

- (void)removeEntity:(OGWEntity *)entity

Parameters

entity

The entity to remove.

Declared In

OGWWorldEntities.h

simulationDidPerformStep

- (void)simulationDidPerformStep