26 #include <boost/lexical_cast.hpp>
48 const std::vector<RendererBase*>& renderers,
TimeProvider* tp_master):
51 m_timeProvider(tp_master),
54 m_renderBackend(renderBackend),
55 m_renderers(renderers),
64 std::vector<Camera*>::iterator iter =
m_cameras.begin();
65 for ( ; iter !=
m_cameras.end(); ++iter) {
74 std::list<Layer*>::const_iterator it =
m_layers.begin();
76 if((*it)->getId() == id)
87 std::list<Layer*>::const_iterator it =
m_layers.begin();
89 if(identifier == (*it)->getId())
90 throw NameClash(identifier);
93 Layer* layer =
new Layer(identifier,
this, grid);
98 (*i)->onLayerCreate(
this, layer);
106 std::list<Layer*>::iterator it =
m_layers.begin();
111 (*i)->onLayerDelete(
this, layer);
123 std::list<Layer*> temp_layers =
m_layers;
124 std::list<Layer*>::iterator temp_it = temp_layers.begin();
125 for(; temp_it != temp_layers.end(); ++temp_it) {
128 (*i)->onLayerDelete(
this, *temp_it);
131 std::list<Layer*>::iterator it =
m_layers.begin();
133 if(*it == *temp_it) {
146 std::list<Layer*>::iterator it =
m_layers.begin();
148 for (; it !=
m_layers.end(); ++it) {
150 (*it)->getMinMaxCoordinates(newMin, newMax, layer);
152 if (newMin.
x < min.
x) {
155 if (newMax.
x > max.
x) {
158 if (newMin.
y < min.
y) {
161 if (newMax.
y > max.
y) {
184 if (source != target) {
191 std::vector<CellCache*> cellCaches;
192 std::list<Layer*>::iterator it =
m_layers.begin();
195 if ((*it)->update()) {
198 CellCache* cache = (*it)->getCellCache();
200 cellCaches.push_back(cache);
204 for (std::vector<CellCache*>::iterator cacheIt = cellCaches.begin();
205 cacheIt != cellCaches.end(); ++cacheIt) {
217 std::vector<Camera*>::iterator camIter =
m_cameras.begin();
218 for ( ; camIter !=
m_cameras.end(); ++camIter) {
219 if ((*camIter)->isEnabled()) {
220 (*camIter)->update();
221 (*camIter)->render();
237 if ((*i) == listener) {
247 throw NotSupported(
"Must have valid layer for camera");
251 std::string errorStr =
"Camera: " +
id +
" already exists";
252 throw NameClash(errorStr);
259 std::vector<RendererBase*>::iterator iter =
m_renderers.begin();
268 std::vector<Camera*>::iterator iter =
m_cameras.begin();
269 for ( ; iter !=
m_cameras.end(); ++iter) {
270 if ((*iter)->getId() == id) {
285 std::vector<Camera*>::iterator iter =
m_cameras.begin();
286 for ( ; iter !=
m_cameras.end(); ++iter) {
287 if ((*iter)->getId() == id) {
301 std::vector<Camera*>::const_iterator it =
m_cameras.begin();
303 if ((*it)->isEnabled()) {
311 std::pair<std::map<Instance*, Location>::iterator,
bool> insertiter =
m_transferInstances.insert(std::make_pair(instance, target));
312 if (insertiter.second ==
false) {
313 Location& loc = insertiter.first->second;
331 std::list<Layer*>::iterator layit =
m_layers.begin();
333 for (; layit !=
m_layers.end(); ++layit) {
334 if ((*layit)->isInteract()) {
343 for (; layit !=
m_layers.end(); ++layit) {
344 if ((*layit)->isWalkable()) {
345 (*layit)->createCellCache();
352 std::list<Layer*>::iterator layit =
m_layers.begin();
353 for (; layit !=
m_layers.end(); ++layit) {
354 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.
TriggerController * m_triggerController
This class serves as a central place to manage triggers for a 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.
uint32_t getActiveCameraCount() const
Return the number of enabled cameras in this map.
Listener interface for changes happening on map.