1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-06 09:09:40 +02:00
Files
vcmi/lib/rmg/modificators/Modificator.h
Alexander Wilms 522cb571b3 Remove redundant virtual specifiers
`grep -nr virtual | grep -v googletest | grep override > ../redundant_virtual.txt`

```python
import os

with open("../redundant_virtual.txt") as f:
    for line in f:
        print()
        line: str = line.strip()
        print(line)
        tmp = line.split(":")
        file = tmp[0].strip()
        code = tmp[-1].strip()
        print(file)
        print(code)
        new_code = code.replace("virtual ", "", 1)
        # https://superuser.com/a/802490/578501
        command = f"export FIND='{code}' && export REPLACE='{new_code}' && ruby -p -i -e \"gsub(ENV['FIND'], ENV['REPLACE'])\" {file}"
        os.system(command)
```
2024-02-10 20:46:13 +01:00

81 lines
1.9 KiB
C++

/*
* 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
#include "../../GameConstants.h"
#include "../../int3.h"
#include "../Zone.h"
#include "../threadpool/MapProxy.h"
class RmgMap;
class CMapGenerator;
class Zone;
class MapProxy;
#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);
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;
std::shared_ptr<MapProxy> mapProxy;
CMapGenerator & generator;
Zone & zone;
bool finished = false;
mutable boost::recursive_mutex externalAccessMutex; //Used to communicate between Modificators
using RecursiveLock = boost::unique_lock<boost::recursive_mutex>;
using Lock = boost::unique_lock<boost::shared_mutex>;
private:
virtual void process() = 0;
std::string name;
std::list<Modificator*> preceeders; //must be ordered container
mutable boost::shared_mutex mx; //Used only for task scheduling
void dump();
};
VCMI_LIB_NAMESPACE_END