Show worldclient.h syntax highlighted
/***************************************************************************
worldclient.h
-------------------
begin : Thu Nov 14 2002
copyright : (C) 2002 by Brendon Higgins
email : freepop-devel@lists.sourceforge.net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef WORLDCLIENT_H_INCLUDED
#define WORLDCLIENT_H_INCLUDED
#include <connectstate.h>
#include <mapclient.h>
#include <ClanLib/network.h>
#include <boost/utility.hpp>
#include <algorithm>
#include <deque>
class Paintable;
class EntityClient;
class Identity;
/**
* A world, client edition. Contains a map and entities.
*/
class WorldClient: public boost::noncopyable {
public:
/**
* Entity list type. Cannot be std::list as std::sort requires
* a random access iterator.
*/
typedef std::deque<EntityClient*> EntityClientList;
/**
* Entity list iterator type.
*/
typedef EntityClientList::iterator EntityClientIterator;
private:
/**
* Paintable list type.
*/
typedef std::deque<Paintable*> PaintableList;
/**
* Paintable iterator type.
*/
typedef PaintableList::iterator PaintableIterator;
public:
/**
* Constructor. The map is extracted from the given input source.
* \param i The input that describes the world.
* \param s The net session.
* \param r A pointer to the rules this world must follow. This pointer is
* kept in a world object, but it is NOT passed with ownership. The rules
* structure must be deleted somewhere else.
* \param p Pointer to the player list. Kept similarly to \p r.
*/
WorldClient(CL_InputSource* i, CL_NetSession* s, const Rules* r,
const PlayerList* p);
/**
* Destructor.
*/
~WorldClient();
/**
* Get the map.
*/
MapClient* getMap();
/**
* Get the map.
*/
const MapClient* getMap() const;
/**
* Get the entity list.
*/
EntityClientList* getEntities();
/**
* Get the entity list.
*/
const EntityClientList* getEntities() const;
/**
* Add an entity to the list.
*/
void addEntity(EntityClient* e);
/**
* Remove an entity from the list.
*/
void destroyEntity(EntityClient* e);
/**
* Get the entity with the given ID. Will return 0 if no such entity can be
* found.
*/
EntityClient* findEntity(const Identity& id);
/**
* Remove every entity from the list.
*/
void clearEntities();
/**
* Add a paintable.
*/
void paintablesAdd(Paintable* d);
/**
* Remove a paintable.
*/
void paintablesErase(Paintable* d);
/**
* Remove every paintable from the list.
* \note This will delete all the paintables, so make sure that no entities
* are in the paintables list by calling clearEntities() first.
*/
void clearPaintables();
/**
* Update drawing parameters of all drawables.
*/
void drawUpdate(unsigned int d);
/**
* Draw the map and the entities.
*/
void draw() const;
/**
* Predict what the entities will do.
* \param d Delay since last predict (ms).
*/
void predict(unsigned int d);
/**
* Notify entities that a player's colour has changed.
*/
void playerColourChange();
/**
* Get the rules.
*/
const Rules* getRules() const;
/**
* Find a player that matches the given slot \p s.
*/
const PlayerClient* findPlayer(int s) const;
/**
* Get the current display rotation.
*/
const Rotation& getDisplayRotation() const;
/**
* Rotate the display 90 degrees clockwise.
*/
void displayRotateClock();
/**
* Rotate the display 90 degrees anticlockwise.
*/
void displayRotateAnti();
/**
* Sorts the paintables.
*/
void sortPaintables();
private:
/**
* Functor to sort the paintables.
*/
class PaintableSorter {
public:
/**
* Constructor.
*/
PaintableSorter(const WorldClient* w);
/**
* Sorting operator.
*/
bool operator()(Paintable* d1, Paintable* d2);
private:
/**
* The world on which the entities reside.
*/
const WorldClient* c;
};
/**
* Receives entity messages.
*/
void onMessage(CL_NetPacket& packet, CL_NetComputer &computer);
/**
* Notify entities that the display rotation has changed.
* \param r The new display rotation.
*/
void displayRotationChange(const Rotation& r);
/**
* The map.
*/
MapClient map;
/**
* The entities.
*/
EntityClientList entities;
/**
* The paintables.
*/
PaintableList paintables;
/**
* Rules.
*/
const Rules* rules;
/**
* Players.
*/
const PlayerList* players;
/**
* Slot to receive entity messages.
*/
CL_Slot slotMessage;
};
#endif /* ndef WORLDCLIENT_H_INCLUDED */
See more files for this project here