src/PhysicsWorld.hh
author Tero Marttila <terom@fixme.fi>
Tue, 20 Jan 2009 23:30:18 +0200
changeset 408 e6cfc44266af
parent 300 417183866f35
child 409 1a03ff151abc
permissions -rw-r--r--
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
197
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
     1
#ifndef PHYSICS_WORLD_HH
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
     2
#define PHYSICS_WORLD_HH
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
     3
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
     4
#include <ClanLib/display.h>
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
     5
#include <ClanLib/core.h>
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
     6
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
     7
#include <algorithm>
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
     8
#include <functional>
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
     9
#include <cmath>
199
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 197
diff changeset
    10
205
905028e58ed1 implement a new tick-timer that doesn't suck
terom
parents: 201
diff changeset
    11
#include "Terrain.hh"          
199
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 197
diff changeset
    12
197
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    13
class PhysicsWorld;
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    14
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    15
#include "PhysicsObject.hh"
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    16
#include "Vector.hh"
205
905028e58ed1 implement a new tick-timer that doesn't suck
terom
parents: 201
diff changeset
    17
#include "Timer.hh"
197
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    18
#include "Config.hh"
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    19
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    20
/**
408
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 300
diff changeset
    21
* PhysicsWorld class. PhysicsWorld contains a number of PhysicsObjects that are simulated forward in time using
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 300
diff changeset
    22
* the physics tick rate
197
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    23
*/
408
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 300
diff changeset
    24
class PhysicsWorld {
197
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    25
    friend class PhysicsObject;
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    26
408
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 300
diff changeset
    27
// XXX: needs some fixing up, move Terrain methods
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 300
diff changeset
    28
public:   
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 300
diff changeset
    29
    /** The world's terrain */
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 300
diff changeset
    30
    Terrain &terrain;
197
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    31
408
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 300
diff changeset
    32
protected:
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 300
diff changeset
    33
    /** List of simulated objects*/
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 300
diff changeset
    34
    std::list<PhysicsObject*> objects;
208
7709571e1131 Digging now uses projectiles.
saiam
parents: 205
diff changeset
    35
    
408
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 300
diff changeset
    36
    /** Size of simulation area */
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 300
diff changeset
    37
    Vector dimensions;
197
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    38
408
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 300
diff changeset
    39
    /** Gravity vector */
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 300
diff changeset
    40
    Vector gravity;
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 300
diff changeset
    41
    
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 300
diff changeset
    42
    /** Physics simulation ticks */
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 300
diff changeset
    43
    Timer tick_timer;
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 300
diff changeset
    44
    
197
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    45
    CL_SlotContainer slots;
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    46
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    47
public:
408
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 300
diff changeset
    48
    /**
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 300
diff changeset
    49
     * Construct a world with the given configuration. 
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 300
diff changeset
    50
     */
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 300
diff changeset
    51
    PhysicsWorld (Vector gravity, Vector dimensions, Terrain &terrain);
199
f5c86420facd Jeejee, hirvee hinaus ohi toistaseks.
saiam
parents: 197
diff changeset
    52
225
22ecb9cb9245 Rope can be drawn.
ekku
parents: 222
diff changeset
    53
    /**
197
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    54
     * Add object to the PhysicsWorld.
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    55
     *
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    56
     * @param object Pointer to the PhysicsObject to add.
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    57
     */
408
e6cfc44266af reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents: 300
diff changeset
    58
    void addPhysicsObject (PhysicsObject *object);
197
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    59
    
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    60
    /**
225
22ecb9cb9245 Rope can be drawn.
ekku
parents: 222
diff changeset
    61
     * Remove the object from the PhysicsWorld.
22ecb9cb9245 Rope can be drawn.
ekku
parents: 222
diff changeset
    62
     */
22ecb9cb9245 Rope can be drawn.
ekku
parents: 222
diff changeset
    63
    void removePhysicsObject (PhysicsObject *po);
22ecb9cb9245 Rope can be drawn.
ekku
parents: 222
diff changeset
    64
    
22ecb9cb9245 Rope can be drawn.
ekku
parents: 222
diff changeset
    65
    /**
197
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    66
     * Advance one time step in physics simulation.
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    67
     */
300
417183866f35 suicide key and respawning
terom
parents: 255
diff changeset
    68
    void tick (TimeMS tick_length);
197
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    69
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    70
    /**
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    71
     * Get current tick in physics simulation.
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    72
     *
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    73
     * @return tick Current simulation tick.
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    74
     */
300
417183866f35 suicide key and respawning
terom
parents: 255
diff changeset
    75
    TickCount getTicks (void);
197
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    76
};
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    77
d9ac888de778 Hajotetaan lis??
ekku
parents:
diff changeset
    78
#endif