1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-12 10:03:53 +02:00
vcmi/client/adventureMap/MapView.h

131 lines
3.3 KiB
C
Raw Normal View History

/*
* MapView.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
#include "../gui/CIntObject.h"
#include "MapRendererContext.h"
class Canvas;
class MapRenderer;
class MapRendererContext : public IMapRendererContext
{
Point tileSize = Point(32, 32);
uint32_t animationTime = 0;
public:
void advanceAnimations(uint32_t ms);
2023-02-15 20:16:21 +02:00
void setTileSize(const Point & dimensions);
int3 getMapSize() const override;
bool isInMap(const int3 & coordinates) const override;
const TerrainTile & getMapTile(const int3 & coordinates) const override;
ObjectsVector getAllObjects() const override;
const CGObjectInstance * getObject(ObjectInstanceID objectID) const override;
const CGPath * currentPath() const override;
bool isVisible(const int3 & coordinates) const override;
uint32_t getAnimationPeriod() const override;
uint32_t getAnimationTime() const override;
2023-02-15 20:16:21 +02:00
Point getTileSize() const override;
bool showGrid() const override;
};
2023-02-15 20:16:21 +02:00
class MapViewModel
{
Point tileSize;
Point viewCenter;
2023-02-15 20:16:21 +02:00
Point viewDimensions;
int mapLevel = 0;
2023-02-15 20:16:21 +02:00
public:
void setTileSize(const Point & newValue);
void setViewCenter(const Point & newValue);
void setViewDimensions(const Point & newValue);
2023-02-15 20:16:21 +02:00
void setLevel(int newLevel);
/// returns current size of map tile in pixels
Point getSingleTileSize() const;
/// returns center point of map view, in Map coordinates
Point getMapViewCenter() const;
/// returns total number of visible tiles
Point getTilesVisibleDimensions() const;
/// returns rect encompassing all visible tiles
Rect getTilesTotalRect() const;
/// returns required area in pixels of cache canvas
Point getCacheDimensionsPixels() const;
/// returns actual player-visible area
Point getPixelsVisibleDimensions() const;
/// returns area covered by specified tile in map cache
Rect getCacheTileArea(const int3 & coordinates) const;
/// returns area covered by specified tile in target view
Rect getTargetTileArea(const int3 & coordinates) const;
int getLevel() const;
int3 getTileCenter() const;
/// returns tile under specified position in target view
int3 getTileAtPoint(const Point & position) const;
};
2023-02-15 20:16:21 +02:00
class MapCache
{
std::unique_ptr<Canvas> terrain;
std::shared_ptr<MapViewModel> model;
std::unique_ptr<MapRendererContext> context;
std::unique_ptr<MapRenderer> mapRenderer;
Canvas getTile(const int3 & coordinates);
void updateTile(const int3 & coordinates);
public:
2023-02-15 20:16:21 +02:00
explicit MapCache(const std::shared_ptr<MapViewModel> & model);
~MapCache();
void update(uint32_t timeDelta);
void render(Canvas & target);
};
class MapView : public CIntObject
{
2023-02-15 20:16:21 +02:00
std::shared_ptr<MapViewModel> model;
std::unique_ptr<MapCache> tilesCache;
2023-02-15 20:16:21 +02:00
std::shared_ptr<MapViewModel> createModel(const Point & dimensions) const;
public:
2023-02-15 20:16:21 +02:00
std::shared_ptr<const MapViewModel> getModel() const;
2023-02-15 20:16:21 +02:00
MapView(const Point & offset, const Point & dimensions);
void setViewCenter(const int3 & position);
void setViewCenter(const Point & position, int level);
2023-02-15 20:16:21 +02:00
void setTileSize(const Point & tileSize);
void moveHero();
void show(SDL_Surface * to) override;
void showAll(SDL_Surface * to) override;
};