src/GameState.hh
author Tero Marttila <terom@fixme.fi>
Tue, 20 Jan 2009 23:30:18 +0200
changeset 408 e6cfc44266af
parent 393 5dd4d782cf3a
child 412 721c60072091
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
#ifndef GAMESTATE_HH
#define GAMESTATE_HH

class GameState;

#include "PhysicsWorld.hh"
#include "Player.hh"
#include "Projectile.hh"
#include "Rope.hh"
#include "Input.hh"
#include "GraphicsPointer.hh"
#include "Config.hh"

#include <list>
#include <stdexcept>
#include <cmath>

class GameStateEventHandler {
    friend class GameState;

    protected:
        virtual void on_player_joined (Player *p) = 0;
        virtual void on_player_left (Player *p) = 0;
};

class GameState {
public:
    /**
     * All active players
     */
    std::list<Player*> player_list;

    /**
     * All active projectiles
     */
    std::list<Projectile*> projectiles;

    /**
     * Our world simulation
     */
    PhysicsWorld world;
    
    /**
     * Our terrain
     */
    Terrain &terrain;

    /**
     * The one LocalPlayer that *we* control
     */
    LocalPlayer *local_player;
    
protected:
    /**
     * Notify someone about events?
     */
    GameStateEventHandler *event_handler;

public:    
    /**
     * Create the game world, using the given terrain
     *
     * @param terrain the world's terrain
     */
    GameState (Terrain &terrain);

    /**
     * Set event handler, only one can be set
     */
    void setEventHandler (GameStateEventHandler *handler);
    
    /**
     * Adds projectile to our list of projectiles to draw
     */
    void addProjectile(Projectile *projectile);

    /**
     * Get our current LocalPlayer if we have one, else return NULL (client hasn't connected yet)
     */
    LocalPlayer *getLocalPlayer (void);
    
    /**
     * Check that local_player is NULL, and sets it to the given player
     */
    void setLocalPlayer (LocalPlayer *player);        

    /**
     * Add the given player to our player_list
     */
    void addPlayer (Player *player);
    
    /**
     * Removes the given player from player_list. If the given player was the local_player, set that to NULL
     */
    void removePlayer (Player *player);
    
    /**
     * Draws the terrain, players and projectiles
     */
    virtual void draw (Graphics *g, PixelCoordinate camera, bool displayWeapon);
};

#endif