mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-15 01:24:45 +02:00
Redesign map editor rendering
This commit is contained in:
@ -29,26 +29,26 @@ class PlayerColor;
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
||||
struct TileObject
|
||||
struct ObjectRect
|
||||
{
|
||||
CGObjectInstance *obj;
|
||||
const CGObjectInstance * obj;
|
||||
QRect rect;
|
||||
|
||||
TileObject(CGObjectInstance *obj_, QRect rect_);
|
||||
~TileObject();
|
||||
ObjectRect(const CGObjectInstance * obj_, QRect rect_);
|
||||
~ObjectRect();
|
||||
};
|
||||
|
||||
using TileObjects = std::vector<TileObject>; //pointers to objects being on this tile with rects to be easier to blit this tile on screen
|
||||
using TileObjects = std::vector<ObjectRect>; //pointers to objects being on this tile with rects to be easier to blit this tile on screen
|
||||
|
||||
class MapHandler
|
||||
{
|
||||
public:
|
||||
struct AnimBitmapHolder
|
||||
struct BitmapHolder
|
||||
{
|
||||
std::shared_ptr<QImage> objBitmap; // main object bitmap
|
||||
std::shared_ptr<QImage> flagBitmap; // flag bitmap for the object (probably only for heroes and boats with heroes)
|
||||
|
||||
AnimBitmapHolder(std::shared_ptr<QImage> objBitmap_ = nullptr, std::shared_ptr<QImage> flagBitmap_ = nullptr)
|
||||
BitmapHolder(std::shared_ptr<QImage> objBitmap_ = nullptr, std::shared_ptr<QImage> flagBitmap_ = nullptr)
|
||||
: objBitmap(objBitmap_),
|
||||
flagBitmap(flagBitmap_)
|
||||
{}
|
||||
@ -61,7 +61,7 @@ private:
|
||||
|
||||
std::shared_ptr<QImage> findFlagBitmapInternal(std::shared_ptr<Animation> animation, int anim, int group, ui8 dir, bool moving) const;
|
||||
std::shared_ptr<QImage> findFlagBitmap(const CGHeroInstance * obj, int anim, const PlayerColor color, int group) const;
|
||||
AnimBitmapHolder findObjectBitmap(const CGObjectInstance * obj, int anim, int group = 0) const;
|
||||
BitmapHolder findObjectBitmap(const CGObjectInstance * obj, int anim, int group = 0) const;
|
||||
|
||||
//FIXME: unique_ptr should be enough, but fails to compile in MSVS 2013
|
||||
typedef std::map<std::string, std::shared_ptr<Animation>> TFlippedAnimations; //[type, rotation]
|
||||
@ -76,28 +76,22 @@ private:
|
||||
TFlippedAnimations riverAnimations;//[river type, rotation]
|
||||
TFlippedCache riverImages;//[river type, view type, rotation]
|
||||
|
||||
std::vector<TileObjects> ttiles; //informations about map tiles
|
||||
int3 sizes; //map size (x = width, y = height, z = number of levels)
|
||||
const CMap * map;
|
||||
|
||||
enum class EMapCacheType : char
|
||||
{
|
||||
TERRAIN, OBJECTS, ROADS, RIVERS, FOW, HEROES, HERO_FLAGS, FRAME, AFTER_LAST
|
||||
};
|
||||
std::vector<TileObjects> tileObjects; //informations about map tiles
|
||||
std::map<const CGObjectInstance *, std::set<int3>> tilesCache; //set of tiles beloging to object
|
||||
|
||||
const CMap * map = nullptr;
|
||||
|
||||
void initObjectRects();
|
||||
void initTerrainGraphics();
|
||||
QRgb getTileColor(int x, int y, int z);
|
||||
|
||||
QPolygon lockBitMask;
|
||||
|
||||
std::shared_ptr<QImage> getObjectImage(const CGObjectInstance * obj);
|
||||
|
||||
public:
|
||||
MapHandler();
|
||||
~MapHandler() = default;
|
||||
|
||||
void reset(const CMap * Map);
|
||||
|
||||
void updateWater();
|
||||
|
||||
void drawTerrainTile(QPainter & painter, int x, int y, int z);
|
||||
/// draws a river segment on current tile
|
||||
@ -105,17 +99,21 @@ public:
|
||||
/// draws a road segment on current tile
|
||||
void drawRoad(QPainter & painter, int x, int y, int z);
|
||||
|
||||
void invalidate(int x, int y, int z); //invalidates all objects in particular tile
|
||||
void invalidate(CGObjectInstance *); //invalidates object rects
|
||||
void invalidate(const std::vector<int3> &); //invalidates all tiles
|
||||
std::set<int3> invalidate(const CGObjectInstance *); //invalidates object rects
|
||||
void invalidateObjects(); //invalidates all objects on the map
|
||||
std::vector<int3> getTilesUnderObject(CGObjectInstance *) const;
|
||||
const std::set<int3> & getTilesUnderObject(const CGObjectInstance *) const;
|
||||
|
||||
//get objects at position
|
||||
std::vector<ObjectRect> & getObjects(const int3 & tile);
|
||||
std::vector<ObjectRect> & getObjects(int x, int y, int z);
|
||||
|
||||
//returns set of tiles to draw
|
||||
std::set<int3> removeObject(const CGObjectInstance * object);
|
||||
std::set<int3> addObject(const CGObjectInstance * object);
|
||||
|
||||
/// draws all objects on current tile (higher-level logic, unlike other draw*** methods)
|
||||
void drawObjects(QPainter & painter, int x, int y, int z, const std::set<const CGObjectInstance *> & locked);
|
||||
void drawObject(QPainter & painter, const TileObject & object);
|
||||
void drawObjectAt(QPainter & painter, const CGObjectInstance * object, int x, int y);
|
||||
std::vector<TileObject> & getObjects(int x, int y, int z);
|
||||
|
||||
void drawMinimapTile(QPainter & painter, int x, int y, int z);
|
||||
|
||||
|
Reference in New Issue
Block a user