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 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) {
297 std::vector<Camera*>::const_iterator it =
m_cameras.begin();
299 if ((*it)->isEnabled()) {
307 std::pair<std::map<Instance*, Location>::iterator,
bool> insertiter =
m_transferInstances.insert(std::make_pair(instance, target));
308 if (insertiter.second ==
false) {
309 Location& loc = insertiter.first->second;
327 std::list<Layer*>::iterator layit =
m_layers.begin();
329 for (; layit !=
m_layers.end(); ++layit) {
330 if ((*layit)->isInteract()) {
339 for (; layit !=
m_layers.end(); ++layit) {
340 if ((*layit)->isWalkable()) {
341 (*layit)->createCellCache();
348 std::list<Layer*>::iterator layit =
m_layers.begin();
349 for (; layit !=
m_layers.end(); ++layit) {
350 CellCache* cache = (*layit)->getCellCache();
ExactModelCoordinate getExactLayerCoordinates() const
Gets exact layer coordinates set to this location.
const std::vector< Camera * > & getCameras() const
Get a list containing all cameras.
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.
Layer * getLayer() const
Gets the layer where this location is pointing to.
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...
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...
void addChangeListener(MapChangeListener *listener)
Adds new change listener.
void deleteLayers()
Delete all layers from the map.
uint32_t getActiveCameraCount() const
Return the number of enabled cameras in this map.
Camera describes properties of a view port shown in the main screen Main screen can have multiple cam...
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.
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.
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
Camera * addCamera(const std::string &id, const Rect &viewport)
Adds camera to the 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.
ExactModelCoordinate getMapCoordinates() const
Gets map coordinates set to this location.
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
uint32_t getLayerCount() const
Get the overall number of layers.
RenderBackend * m_renderBackend
pointer to renderbackend
An Instance is an "instantiation" of an Object at a Location.
Listener interface for changes happening on map.