1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00
vcmi/CThreadHelper.h
Michał W. Urbańczyk 90fd75e66c * Removed trailing newline from settings.txt (caused warning)
* Sprite/Bitmap handlers moved to VCMI_Lib
* Moved volume sliders 1px down for better look
2009-05-09 16:18:27 +00:00

56 lines
1.4 KiB
C++

#ifndef __CTHREADHELPER_H__
#define __CTHREADHELPER_H__
#include "global.h"
#include <boost/function.hpp>
#include <boost/thread.hpp>
/*
* CThreadHelper.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
*
*/
typedef boost::function<void()> Task;
class CThreadHelper
{
boost::mutex rtinm;
int currentTask, amount, threads;
std::vector<Task> *tasks;
void processTasks();
public:
CThreadHelper(std::vector<boost::function<void()> > *Tasks, int Threads);
void run();
};
template <typename T> inline void setData(T * data, boost::function<T()> func)
{
*data = func();
}
#define GET_DATA(TYPE,DESTINATION,FUNCTION_TO_GET) \
(boost::bind(&setData<TYPE>,&DESTINATION,FUNCTION_TO_GET))
#define GET_SURFACE(SUR_DESTINATION, SUR_NAME) \
(GET_DATA \
(SDL_Surface*,SUR_DESTINATION,\
boost::function<SDL_Surface*()>(boost::bind(&BitmapHandler::loadBitmap,SUR_NAME,true))))
#define GET_DEF(DESTINATION, DEF_NAME) \
(GET_DATA \
(CDefHandler*,DESTINATION,\
boost::function<CDefHandler*()>(boost::bind(CDefHandler::giveDef,DEF_NAME))))
#define GET_DEF_ESS(DESTINATION, DEF_NAME) \
(GET_DATA \
(CDefEssential*,DESTINATION,\
boost::function<CDefEssential*()>(boost::bind(CDefHandler::giveDefEss,DEF_NAME))))
#endif // __CTHREADHELPER_H__