2023-05-07 07:48:12 +02:00
|
|
|
/*
|
|
|
|
* Modificator.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
|
|
|
|
|
2023-05-20 10:17:37 +02:00
|
|
|
#include "../../GameConstants.h"
|
|
|
|
#include "../../int3.h"
|
|
|
|
#include "../Zone.h"
|
|
|
|
#include "../threadpool/MapProxy.h"
|
2023-05-07 07:48:12 +02:00
|
|
|
|
|
|
|
class RmgMap;
|
|
|
|
class CMapGenerator;
|
|
|
|
class Zone;
|
2023-05-19 20:30:15 +02:00
|
|
|
class MapProxy;
|
2023-05-07 07:48:12 +02:00
|
|
|
|
|
|
|
#define MODIFICATOR(x) x(Zone & z, RmgMap & m, CMapGenerator & g): Modificator(z, m, g) {setName(#x);}
|
|
|
|
#define DEPENDENCY(x) dependency(zone.getModificator<x>());
|
|
|
|
#define POSTFUNCTION(x) postfunction(zone.getModificator<x>());
|
|
|
|
#define DEPENDENCY_ALL(x) for(auto & z : map.getZones()) \
|
|
|
|
{ \
|
|
|
|
dependency(z.second->getModificator<x>()); \
|
|
|
|
}
|
|
|
|
#define POSTFUNCTION_ALL(x) for(auto & z : map.getZones()) \
|
|
|
|
{ \
|
|
|
|
postfunction(z.second->getModificator<x>()); \
|
|
|
|
}
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
class Modificator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Modificator() = delete;
|
|
|
|
Modificator(Zone & zone, RmgMap & map, CMapGenerator & generator);
|
|
|
|
|
|
|
|
virtual void init() {/*override to add dependencies*/}
|
|
|
|
virtual char dump(const int3 &);
|
|
|
|
virtual ~Modificator() = default;
|
|
|
|
|
|
|
|
void setName(const std::string & n);
|
|
|
|
const std::string & getName() const;
|
|
|
|
|
|
|
|
bool isReady();
|
|
|
|
bool isFinished();
|
|
|
|
|
|
|
|
void run();
|
|
|
|
void dependency(Modificator * modificator);
|
|
|
|
void postfunction(Modificator * modificator);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
RmgMap & map;
|
2023-05-19 20:30:15 +02:00
|
|
|
std::shared_ptr<MapProxy> mapProxy;
|
2023-05-07 07:48:12 +02:00
|
|
|
CMapGenerator & generator;
|
|
|
|
Zone & zone;
|
|
|
|
|
|
|
|
bool finished = false;
|
|
|
|
|
2023-05-19 20:30:15 +02:00
|
|
|
mutable boost::recursive_mutex externalAccessMutex; //Used to communicate between Modificators
|
|
|
|
using RecursiveLock = boost::unique_lock<boost::recursive_mutex>;
|
2023-05-07 08:24:08 +02:00
|
|
|
using Lock = boost::unique_lock<boost::shared_mutex>;
|
|
|
|
|
2023-05-07 07:48:12 +02:00
|
|
|
private:
|
|
|
|
virtual void process() = 0;
|
|
|
|
|
|
|
|
std::string name;
|
|
|
|
|
|
|
|
std::list<Modificator*> preceeders; //must be ordered container
|
|
|
|
|
2023-05-07 08:24:08 +02:00
|
|
|
mutable boost::shared_mutex mx; //Used only for task scheduling
|
2023-05-07 07:48:12 +02:00
|
|
|
|
|
|
|
void dump();
|
|
|
|
};
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|