Inherits from OGWBase : NSObject
Declared in OGWWorld.h

Overview

Represents a game world. The world should be the only OpenGW objects created from and retained in a view (controller) object.

The world has aspects, keyed values, categories, entities, maps and the multithreading simulation object.

World aspects follow the OGWWorld*Aspect naming convention.

A world is typically a single level or map in a game. It can represent a simple puzzle game playfield (ie Tic Tac Toe) or a large, freely traversable world with no boundaries. You can even have multiple separate worlds. For example you could implement an inventory system as a separate world, where entities from the actual world are moved to the inventory world and back.

Tasks

World Constituents

Delegate

Create World

Simulating the World

Properties

categories

The OGWWorldCategories object.

@property (readonly) OGWWorldCategories *categories

Return Value

The OGWWorldCategories object.

Declared In

OGWWorld.h

delegate

Typically a view object beomes the world delegate, in order to react to certain world events.

@property id<OGWWorldDelegate> delegate

Return Value

The world delegate or nil if there’s no world delegate.

Declared In

OGWWorld.h

entities

The OGWWorldEntities object.

@property (readonly) OGWWorldEntities *entities

Return Value

The OGWWorldEntities object.

Declared In

OGWWorld.h

maps

The OGWWorldMaps object.

@property (readonly) OGWWorldMaps *maps

Return Value

The OGWWorldMaps object.

Declared In

OGWWorld.h

simulation

The OGWWorldSimulation object.

@property (readonly) OGWWorldSimulation *simulation

Return Value

The OGWWorldSimulation object.

Declared In

OGWWorld.h

Class Methods

worldWithAspectClasses:

Creates a world with an array of world aspect Class objects.

+ (id)worldWithAspectClasses:(NSArray *)aspectClasses

Parameters

aspectClasses

An array of Class objects which should follow the naming convention OGWWorld*Aspect.

Discussion

Usage example:

NSArray* worldAspects = @[[OGWWorldGravityAspect class], [OGWWorldContactTestAspect class]];
OGWWorld* world = [OGWWorld worldWithAspectClasses:worldAspects];

Declared In

OGWWorld.h

Instance Methods

simulate

Advances the world simulation by one simulation step. Most games would call this every frame update.

- (void)simulate

Discussion

The world simulation advances by concrete integer steps. Time is not used internally. Instead the proper way to make an OpenGW world framerate-independent is to decide on a minimum update rate for the world, let’s say the world should be updated 30 times per second (30 Hz). Given a game loop method that receives the current time you would implement it as follows:

// ivars used by this example:
NSTimeInterval nextGameWorldUpdateTime;
NSTimeInterval lastGameWorldUpdateTime;

-(void) gameLoop:(NSTimeInterval)currentTime
{
    if (currentTime >= nextGameWorldUpdateTime)
    {
        // game world updates at a fixed rate (here: 30 times per second)
        // should fps drop below 30 fps world update will be performed every frame
        nextGameWorldUpdateTime = currentTime + (1.0 / 30.0);
        lastGameWorldUpdateTime = currentTime;

        [gameWorld simulate];

        // draw the world (depends on engine used)
        [renderer drawWorld:gameWorld];
    }
    else
    {
        // draw the world (depends on engine used)
        // optional: interpolate view by applying delta time since last world update to view positions
        [renderer drawWorld:gameWorld delta:currentTime - lastGameWorldUpdateTime];
    }
}

This approach has the following advantages:

  • At 30 fps or higher, the game world simulation runs at a fixed interval (framerate independent mode).
  • At below 30 fps, the game world simulation runs every frame and thus slower (framerate dependent mode).
  • Prevents low-framerate tunneling issues by automatically falling back to framerate dependent mode in low framerate situations.
  • Enables you to optionally interpolate view positions based on time delta and entity velocities. Thus view runs at full speed while game world retains its state during frames that are only interpolated.

To fully understand the implications of applying delta time to changes in position read:
http://www.learn-cocos2d.com/2013/10/game-engine-multiply-delta-time-or-not/

Declared In

OGWWorld.h