src/PhysicsWorld.hh
author Tero Marttila <terom@fixme.fi>
Wed, 21 Jan 2009 00:21:42 +0200
changeset 409 1a03ff151abc
parent 408 e6cfc44266af
child 423 947ab54de4b7
permissions -rw-r--r--
add --terrain-seed and --terrain-size arguments, plus bugfixes
#ifndef PHYSICS_WORLD_HH
#define PHYSICS_WORLD_HH

#include <ClanLib/display.h>
#include <ClanLib/core.h>

#include <algorithm>
#include <functional>
#include <cmath>

#include "Terrain.hh"          

class PhysicsWorld;

#include "PhysicsObject.hh"
#include "Vector.hh"
#include "Timer.hh"
#include "Config.hh"

/**
* PhysicsWorld class. PhysicsWorld contains a number of PhysicsObjects that are simulated forward in time using
* the physics tick rate
*/
class PhysicsWorld {
    friend class PhysicsObject;

// XXX: needs some fixing up, move Terrain methods
public:   
    /** The world's terrain */
    Terrain &terrain;
    
    /** Size of simulation area */
    Vector dimensions;

protected:
    /** List of simulated objects*/
    std::list<PhysicsObject*> objects;
    
    /** Gravity vector */
    Vector gravity;
    
    /** Physics simulation ticks */
    Timer tick_timer;
    
    CL_SlotContainer slots;

public:
    /**
     * Construct a world with the given configuration. 
     */
    PhysicsWorld (Vector gravity, Vector dimensions, Terrain &terrain);

    /**
     * Add object to the PhysicsWorld.
     *
     * @param object Pointer to the PhysicsObject to add.
     */
    void addPhysicsObject (PhysicsObject *object);
    
    /**
     * Remove the object from the PhysicsWorld.
     */
    void removePhysicsObject (PhysicsObject *po);
    
    /**
     * Advance one time step in physics simulation.
     */
    void tick (TimeMS tick_length);

    /**
     * Get current tick in physics simulation.
     *
     * @return tick Current simulation tick.
     */
    TickCount getTicks (void);
};

#endif