mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-29 23:07:48 +02:00
Parallel RMG works fine for maps without water.
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* JobProvider.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 "StdInc.h"
|
||||
#include "../../GameConstants.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
typedef std::function<void()> TRMGfunction ;
|
||||
typedef std::optional<TRMGfunction> TRMGJob;
|
||||
|
||||
class DLL_LINKAGE IJobProvider
|
||||
{
|
||||
public:
|
||||
//TODO: Think about some mutex protection
|
||||
|
||||
virtual TRMGJob getNextJob() = 0;
|
||||
virtual bool hasJobs() = 0;
|
||||
};
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
57
lib/rmg/threadpool/MapProxy.cpp
Normal file
57
lib/rmg/threadpool/MapProxy.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* MapProxy.cpp, 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 "MapProxy.h"
|
||||
#include "../../TerrainHandler.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
MapProxy::MapProxy(RmgMap & map):
|
||||
map(map)
|
||||
{
|
||||
}
|
||||
|
||||
void MapProxy::insertObject(CGObjectInstance * obj)
|
||||
{
|
||||
Lock lock(mx);
|
||||
map.getEditManager()->insertObject(obj);
|
||||
}
|
||||
|
||||
void MapProxy::insertObjects(std::set<CGObjectInstance*>& objects)
|
||||
{
|
||||
Lock lock(mx);
|
||||
map.getEditManager()->insertObjects(objects);
|
||||
}
|
||||
|
||||
void MapProxy::drawTerrain(CRandomGenerator & generator, std::vector<int3> & tiles, TerrainId terrain)
|
||||
{
|
||||
Lock lock(mx);
|
||||
map.getEditManager()->getTerrainSelection().setSelection(tiles);
|
||||
map.getEditManager()->drawTerrain(terrain, &generator);
|
||||
}
|
||||
|
||||
void MapProxy::drawRivers(CRandomGenerator & generator, std::vector<int3> & tiles, TerrainId terrain)
|
||||
{
|
||||
Lock lock(mx);
|
||||
map.getEditManager()->getTerrainSelection().setSelection(tiles);
|
||||
map.getEditManager()->drawRiver(VLC->terrainTypeHandler->getById(terrain)->river, &generator);
|
||||
}
|
||||
|
||||
void MapProxy::drawRoads(CRandomGenerator & generator, std::vector<int3> & tiles, RoadId roadType)
|
||||
{
|
||||
Lock lock(mx);
|
||||
map.getEditManager()->getTerrainSelection().setSelection(tiles);
|
||||
map.getEditManager()->drawRoad(roadType, &generator);
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
41
lib/rmg/threadpool/MapProxy.h
Normal file
41
lib/rmg/threadpool/MapProxy.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* MapProxy.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 "StdInc.h"
|
||||
#include "../../mapping/CMap.h"
|
||||
#include "../RmgMap.h"
|
||||
#include "../../mapping/CMapEditManager.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
class RmgMap;
|
||||
|
||||
class MapProxy
|
||||
{
|
||||
public:
|
||||
MapProxy(RmgMap & map);
|
||||
|
||||
void insertObject(CGObjectInstance * obj);
|
||||
void insertObjects(std::set<CGObjectInstance*>& objects);
|
||||
|
||||
void drawTerrain(CRandomGenerator & generator, std::vector<int3> & tiles, TerrainId terrain);
|
||||
void drawRivers(CRandomGenerator & generator, std::vector<int3> & tiles, TerrainId terrain);
|
||||
void drawRoads(CRandomGenerator & generator, std::vector<int3> & tiles, RoadId roadType);
|
||||
|
||||
private:
|
||||
mutable boost::shared_mutex mx;
|
||||
using Lock = boost::unique_lock<boost::shared_mutex>;
|
||||
|
||||
RmgMap & map;
|
||||
};
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
@@ -11,12 +11,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "BlockingQueue.h"
|
||||
#include "JobProvider.h"
|
||||
#include <boost/thread/future.hpp>
|
||||
#include <boost/thread/condition_variable.hpp>
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
typedef std::function<void()> TRMGfunction ;
|
||||
typedef std::optional<TRMGfunction> TRMGJob;
|
||||
|
||||
//Credit to https://github.com/Liam0205/toy-threadpool/tree/master/yuuki
|
||||
|
||||
class DLL_LINKAGE ThreadPool
|
||||
|
||||
Reference in New Issue
Block a user