26 #include <boost/lexical_cast.hpp>
47 const std::vector<RendererBase*>& renderers,
TimeProvider* tp_master):
50 m_timeProvider(tp_master),
53 m_renderBackend(renderBackend),
54 m_renderers(renderers),
60 std::vector<Camera*>::iterator iter =
m_cameras.begin();
61 for ( ; iter !=
m_cameras.end(); ++iter) {
70 std::list<Layer*>::const_iterator it =
m_layers.begin();
72 if((*it)->getId() == id)
83 std::list<Layer*>::const_iterator it =
m_layers.begin();
85 if(identifier == (*it)->getId())
86 throw NameClash(identifier);
89 Layer* layer =
new Layer(identifier,
this, grid);
94 (*i)->onLayerCreate(
this, layer);
102 std::list<Layer*>::iterator it =
m_layers.begin();
107 (*i)->onLayerDelete(
this, layer);
119 std::list<Layer*> temp_layers =
m_layers;
120 std::list<Layer*>::iterator temp_it = temp_layers.begin();
121 for(; temp_it != temp_layers.end(); ++temp_it) {
124 (*i)->onLayerDelete(
this, *temp_it);
127 std::list<Layer*>::iterator it =
m_layers.begin();
129 if(*it == *temp_it) {
142 std::list<Layer*>::iterator it =
m_layers.begin();
144 for (; it !=
m_layers.end(); ++it) {
146 (*it)->getMinMaxCoordinates(newMin, newMax, layer);
148 if (newMin.
x < min.
x) {
151 if (newMax.
x > max.
x) {
154 if (newMin.
y < min.
y) {
157 if (newMax.
y > max.
y) {
180 if (source != target) {
187 std::vector<CellCache*> cellCaches;
188 std::list<Layer*>::iterator it =
m_layers.begin();
191 if ((*it)->update()) {
194 CellCache* cache = (*it)->getCellCache();
196 cellCaches.push_back(cache);
200 for (std::vector<CellCache*>::iterator cacheIt = cellCaches.begin();
201 cacheIt != cellCaches.end(); ++cacheIt) {
213 std::vector<Camera*>::iterator camIter =
m_cameras.begin();
214 for ( ; camIter !=
m_cameras.end(); ++camIter) {
215 if ((*camIter)->isEnabled()) {
216 (*camIter)->update();
217 (*camIter)->render();
233 if ((*i) == listener) {
243 throw NotSupported(
"Must have valid layer for camera");
247 std::string errorStr =
"Camera: " +
id +
" already exists";
248 throw NameClash(errorStr);
255 std::vector<RendererBase*>::iterator iter =
m_renderers.begin();
264 std::vector<Camera*>::iterator iter =
m_cameras.begin();
265 for ( ; iter !=
m_cameras.end(); ++iter) {
266 if ((*iter)->getId() == id) {
281 std::vector<Camera*>::iterator iter =
m_cameras.begin();
282 for ( ; iter !=
m_cameras.end(); ++iter) {
283 if ((*iter)->getId() == id) {
296 std::pair<std::map<Instance*, Location>::iterator,
bool> insertiter =
m_transferInstances.insert(std::make_pair(instance, target));
297 if (insertiter.second ==
false) {
298 Location& loc = insertiter.first->second;
316 std::list<Layer*>::iterator layit =
m_layers.begin();
318 for (; layit !=
m_layers.end(); ++layit) {
319 if ((*layit)->isInteract()) {
328 for (; layit !=
m_layers.end(); ++layit) {
329 if ((*layit)->isWalkable()) {
330 (*layit)->createCellCache();
337 std::list<Layer*>::iterator layit =
m_layers.begin();
338 for (; layit !=
m_layers.end(); ++layit) {
339 CellCache* cache = (*layit)->getCellCache();
Abstract interface for all the renderbackends.
Timeprovider is an utility providing time management functionality You can have hierarchy of time pro...
bool update()
Called periodically to update events on map.
void setExactLayerCoordinates(const ExactModelCoordinate &coordinates)
Sets precise layer coordinates to this location.
Layer * getLayer(const std::string &identifier)
Get the layer with the given id.
Camera * addCamera(const std::string &id, Layer *layer, const Rect &viewport)
Adds camera to the map.
void removeChangeListener(MapChangeListener *listener)
Removes associated change listener.
std::map< Instance *, Location > m_transferInstances
holds instances which should be transferred on the next update
void setLayer(Layer *layer)
Sets layer where this location is pointing to.
A CellCache is an abstract depiction of one or a few layers and contains additional information...
void addChangeListener(MapChangeListener *listener)
Adds new change listener.
void deleteLayers()
Delete all layers from the map.
Camera describes properties of a view port shown in the main screen Main screen can have multiple cam...
Layer * getLayer() const
Gets the layer where this location is pointing to.
std::vector< MapChangeListener * > m_changeListeners
listeners for map changes
Camera * getCamera(const std::string &id)
Get a camera by its identifier.
void addInteractLayer(Layer *layer)
Adds a interact layer to the walkable layer.
uint32_t getLayerCount() const
Get the overall number of layers.
std::list< Layer * > m_layers
void removeInstance(Instance *instance)
Remove an instance from the layer.
void addRenderer(RendererBase *renderer)
Adds new renderer on the view.
void deleteLayer(Layer *)
Delete a layer from the map.
Map(const std::string &identifier, RenderBackend *renderbackend, const std::vector< RendererBase * > &renderers, TimeProvider *tp_master=NULL)
Construct a map To add map to model, one should call Model::addMap (otherwise map is not registered w...
bool addInstance(Instance *instance, const ExactModelCoordinate &p)
Add a valid instance at a specific position.
Location & getOldLocationRef()
Gets reference of old location of instance.
void removeInstanceForTransfer(Instance *instance)
Removes instance that should be transferred to another layer.
Layer * createLayer(const std::string &identifier, CellGrid *grid)
Add a Layer to this Map.
void addInstanceForTransfer(Instance *instance, const Location &target)
Adds instance that is to be transferred to another layer.
void getMinMaxCoordinates(ExactModelCoordinate &min, ExactModelCoordinate &max)
Retrieves the minimum/maximum coordinates of instances on the map.
std::vector< Layer * > m_changedLayers
holds changed layers after each update
void forceUpdate()
Updates all cells.
void createCells()
Creates cells for this CellCache based on the size of the assigned layer.
void removeCamera(const std::string &id)
Removes a camera from the map.
std::vector< Camera * > m_cameras
holds the cameras attached to this map
bool m_changed
true, if something was changed on map during previous update (layer change, creation, deletion)
void finalizeCellCaches()
Creates cellcaches for this map.
void initializeCellCaches()
Creates cellcaches for this map.
std::vector< RendererBase * > m_renderers
holds handles to all created renderers
ExactModelCoordinate getExactLayerCoordinates() const
Gets exact layer coordinates set to this location.
const std::vector< Camera * > & getCameras() const
Get a list containing all cameras.
RenderBackend * m_renderBackend
pointer to renderbackend
An Instance is an "instantiation" of an Object at a Location.
ExactModelCoordinate getMapCoordinates() const
Gets map coordinates set to this location.
Listener interface for changes happening on map.