2022-12-06 13:41:29 +02:00
|
|
|
/*
|
2022-12-11 23:16:23 +02:00
|
|
|
* BattleFieldController.h, part of VCMI engine
|
2022-12-06 13:41:29 +02:00
|
|
|
*
|
|
|
|
* 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 "../../lib/battle/BattleHex.h"
|
|
|
|
|
2022-12-11 22:09:57 +02:00
|
|
|
class Canvas;
|
2022-12-09 13:26:17 +02:00
|
|
|
class BattleInterface;
|
2022-12-06 13:41:29 +02:00
|
|
|
|
|
|
|
enum class EBattleFieldLayer {
|
|
|
|
// confirmed ordering requirements:
|
|
|
|
OBSTACLES = 0,
|
|
|
|
CORPSES = 0,
|
|
|
|
WALLS = 1,
|
2022-12-11 12:29:11 +02:00
|
|
|
HEROES = 2,
|
|
|
|
STACKS = 2, // after corpses, obstacles, walls
|
|
|
|
BATTLEMENTS = 3, // after stacks
|
|
|
|
STACK_AMOUNTS = 3, // after stacks, obstacles, corpses
|
|
|
|
EFFECTS = 4, // after obstacles, battlements
|
2022-12-06 13:41:29 +02:00
|
|
|
};
|
|
|
|
|
2022-12-09 13:26:17 +02:00
|
|
|
class BattleRenderer
|
2022-12-06 13:41:29 +02:00
|
|
|
{
|
|
|
|
public:
|
2022-12-13 15:10:31 +02:00
|
|
|
using RendererRef = Canvas &;
|
|
|
|
using RenderFunctor = std::function<void(RendererRef)>;
|
2022-12-06 13:41:29 +02:00
|
|
|
|
|
|
|
private:
|
2022-12-13 13:58:16 +02:00
|
|
|
BattleInterface & owner;
|
2022-12-06 13:41:29 +02:00
|
|
|
|
|
|
|
struct RenderableInstance
|
|
|
|
{
|
|
|
|
RenderFunctor functor;
|
|
|
|
EBattleFieldLayer layer;
|
|
|
|
BattleHex tile;
|
|
|
|
};
|
|
|
|
std::vector<RenderableInstance> objects;
|
|
|
|
|
|
|
|
void collectObjects();
|
|
|
|
void sortObjects();
|
2022-12-13 15:10:31 +02:00
|
|
|
void renderObjects(RendererRef targetCanvas);
|
2022-12-06 13:41:29 +02:00
|
|
|
public:
|
2022-12-13 13:58:16 +02:00
|
|
|
BattleRenderer(BattleInterface & owner);
|
2022-12-06 13:41:29 +02:00
|
|
|
|
|
|
|
void insert(EBattleFieldLayer layer, BattleHex tile, RenderFunctor functor);
|
2022-12-13 15:10:31 +02:00
|
|
|
void execute(RendererRef targetCanvas);
|
2022-12-06 13:41:29 +02:00
|
|
|
};
|