1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

[PLATFORM] MinGW support added

* disabled features unsupported by MinGW
* fixed issues with DLL_LINKAGE
! BOOST_THREAD_VERSION in now 3 workaround for existing code added, consider refactoring.
* some small tweaks ("-fpedantic" warnings)
This commit is contained in:
alexvins 2012-09-15 19:16:16 +00:00
parent 7087be1f02
commit 369f0ae9c6
19 changed files with 259 additions and 236 deletions

View File

@ -51,6 +51,9 @@
//The only available version is 3, as of Boost 1.50 //The only available version is 3, as of Boost 1.50
#define BOOST_FILESYSTEM_VERSION 3 #define BOOST_FILESYSTEM_VERSION 3
#define BOOST_THREAD_VERSION 3
#define BOOST_THREAD_DONT_PROVIDE_THREAD_DESTRUCTOR_CALLS_TERMINATE_IF_JOINABLE 1
//#define BOOST_SYSTEM_NO_DEPRECATED 1
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/assert.hpp> #include <boost/assert.hpp>
@ -97,7 +100,11 @@ typedef boost::int8_t si8; //signed int 8 bits (1 byte)
// Import + Export macro declarations // Import + Export macro declarations
#ifdef _WIN32 #ifdef _WIN32
#ifdef __GNUC__
#define DLL_EXPORT __attribute__((dllexport))
#else
#define DLL_EXPORT __declspec(dllexport) #define DLL_EXPORT __declspec(dllexport)
#endif
#else #else
#if defined(__GNUC__) && GCC_VERSION >= 400 #if defined(__GNUC__) && GCC_VERSION >= 400
#define DLL_EXPORT __attribute__ ((visibility("default"))) #define DLL_EXPORT __attribute__ ((visibility("default")))
@ -107,7 +114,11 @@ typedef boost::int8_t si8; //signed int 8 bits (1 byte)
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
#ifdef __GNUC__
#define DLL_IMPORT __attribute__((dllimport))
#else
#define DLL_IMPORT __declspec(dllimport) #define DLL_IMPORT __declspec(dllimport)
#endif
#else #else
#if defined(__GNUC__) && GCC_VERSION >= 400 #if defined(__GNUC__) && GCC_VERSION >= 400
#define DLL_IMPORT __attribute__ ((visibility("default"))) #define DLL_IMPORT __attribute__ ((visibility("default")))

View File

@ -29,7 +29,7 @@ struct BattleResult;
struct BattleSpellCast; struct BattleSpellCast;
struct CObstacleInstance; struct CObstacleInstance;
template <typename T> struct CondSh; template <typename T> struct CondSh;
struct SetStackEffect;; struct SetStackEffect;
struct BattleAction; struct BattleAction;
class CGTownInstance; class CGTownInstance;
struct CatapultAttack; struct CatapultAttack;

View File

@ -27,4 +27,4 @@ namespace BitmapHandler
SDL_Surface * loadBitmapFromDir(std::string path, std::string fname, bool setKey=true); SDL_Surface * loadBitmapFromDir(std::string path, std::string fname, bool setKey=true);
//Load file from any LODs //Load file from any LODs
SDL_Surface * loadBitmap(std::string fname, bool setKey=true); SDL_Surface * loadBitmap(std::string fname, bool setKey=true);
}; }

View File

@ -351,7 +351,7 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const ui8 * FDef, const BMPPal
Uint32 keycol = SDL_MapRGBA(ret->format, ttcol.r, ttcol.b, ttcol.g, ttcol.unused); Uint32 keycol = SDL_MapRGBA(ret->format, ttcol.r, ttcol.b, ttcol.g, ttcol.unused);
SDL_SetColorKey(ret, SDL_SRCCOLORKEY, keycol); SDL_SetColorKey(ret, SDL_SRCCOLORKEY, keycol);
return ret; return ret;
}; }
CDefEssential * CDefHandler::essentialize() CDefEssential * CDefHandler::essentialize()
{ {

View File

@ -69,7 +69,7 @@ namespace boost
{ {
class mutex; class mutex;
class recursive_mutex; class recursive_mutex;
}; }
enum enum
{ {

View File

@ -124,7 +124,7 @@ public:
CPicture *playerListBg; CPicture *playerListBg;
CHighlightableButtonsGroup *difficulty; CHighlightableButtonsGroup *difficulty;
CDefHandler *sizes, *sFlags;; CDefHandler *sizes, *sFlags;
void changeSelection(const CMapInfo *to); void changeSelection(const CMapInfo *to);
void showAll(SDL_Surface * to); void showAll(SDL_Surface * to);

View File

@ -142,11 +142,14 @@ bool CBIKHandler::open(std::string name)
tlog1 << "BIK handler: failed to open " << name << std::endl; tlog1 << "BIK handler: failed to open " << name << std::endl;
goto checkErrorAndClean; goto checkErrorAndClean;
} }
//GCC wants scope of waveout to dont cross labels/swith/goto
{
void *waveout = GetProcAddress(dll,"_BinkOpenWaveOut@4"); void *waveout = GetProcAddress(dll,"_BinkOpenWaveOut@4");
if(waveout) if(waveout)
binkSetSoundSystem(waveout,NULL); binkSetSoundSystem(waveout,NULL);
}
hBink = binkOpen(hBinkFile, 0x8a800000); hBink = binkOpen(hBinkFile, 0x8a800000);
if(!hBink) if(!hBink)
{ {

View File

@ -123,7 +123,7 @@ struct SSetCaptureState
namespace Colors namespace Colors
{ {
}; }
#define OBJ_CONSTRUCTION SObjectConstruction obj__i(this) #define OBJ_CONSTRUCTION SObjectConstruction obj__i(this)
#define OBJ_CONSTRUCTION_CAPTURING_ALL defActions = 255; SSetCaptureState obj__i1(true, 255); SObjectConstruction obj__i(this) #define OBJ_CONSTRUCTION_CAPTURING_ALL defActions = 255; SSetCaptureState obj__i1(true, 255); SObjectConstruction obj__i(this)

View File

@ -1313,13 +1313,13 @@ void CBoundedLabel::recalculateLines(const std::string &Txt)
CLabelGroup::CLabelGroup(EFonts Font, EAlignment Align, const SDL_Color &Color): CLabelGroup::CLabelGroup(EFonts Font, EAlignment Align, const SDL_Color &Color):
font(Font), align(Align), color(Color) font(Font), align(Align), color(Color)
{}; {}
void CLabelGroup::add(int x, int y, const std::string &text) void CLabelGroup::add(int x, int y, const std::string &text)
{ {
OBJ_CONSTRUCTION_CAPTURING_ALL; OBJ_CONSTRUCTION_CAPTURING_ALL;
new CLabel(x, y, font, align, color, text); new CLabel(x, y, font, align, color, text);
}; }
CTextBox::CTextBox(std::string Text, const Rect &rect, int SliderStyle, EFonts Font /*= FONT_SMALL*/, EAlignment Align /*= TOPLEFT*/, const SDL_Color &Color /*= Colors::Cornsilk*/) CTextBox::CTextBox(std::string Text, const Rect &rect, int SliderStyle, EFonts Font /*= FONT_SMALL*/, EAlignment Align /*= TOPLEFT*/, const SDL_Color &Color /*= Colors::Cornsilk*/)
:CBoundedLabel(rect.x, rect.y, Font, Align, Color, Text), sliderStyle(SliderStyle), slider(NULL) :CBoundedLabel(rect.x, rect.y, Font, Align, Color, Text), sliderStyle(SliderStyle), slider(NULL)

View File

@ -193,4 +193,4 @@ namespace CSDL_Ext
void applyEffect(SDL_Surface * surf, const SDL_Rect * rect, int mode); //mode: 0 - sepia, 1 - grayscale void applyEffect(SDL_Surface * surf, const SDL_Rect * rect, int mode); //mode: 0 - sepia, 1 - grayscale
std::string trimToFit(std::string text, int widthLimit, EFonts font); std::string trimToFit(std::string text, int widthLimit, EFonts font);
}; }

View File

@ -575,7 +575,7 @@ void CArtHandler::makeItCreatureArt (int aid, bool onlyCreature /*=true*/)
a->possibleSlots[ArtBearer::COMMANDER].clear(); a->possibleSlots[ArtBearer::COMMANDER].clear();
} }
a->possibleSlots[ArtBearer::CREATURE].push_back(ArtifactPosition::CREATURE_SLOT); a->possibleSlots[ArtBearer::CREATURE].push_back(ArtifactPosition::CREATURE_SLOT);
}; }
void CArtHandler::makeItCommanderArt (int aid, bool onlyCommander /*=true*/) void CArtHandler::makeItCommanderArt (int aid, bool onlyCommander /*=true*/)
{ {
@ -587,7 +587,7 @@ void CArtHandler::makeItCommanderArt (int aid, bool onlyCommander /*=true*/)
} }
for (int i = ArtifactPosition::COMMANDER1; i <= ArtifactPosition::COMMANDER6; ++i) for (int i = ArtifactPosition::COMMANDER1; i <= ArtifactPosition::COMMANDER6; ++i)
a->possibleSlots[ArtBearer::COMMANDER].push_back(i); a->possibleSlots[ArtBearer::COMMANDER].push_back(i);
}; }
void CArtHandler::addBonuses() void CArtHandler::addBonuses()
{ {

View File

@ -25,9 +25,10 @@
#else #else
#define WIN32_LEAN_AND_MEAN //excludes rarely used stuff from windows headers - delete this line if something is missing #define WIN32_LEAN_AND_MEAN //excludes rarely used stuff from windows headers - delete this line if something is missing
#include <windows.h> #include <windows.h>
#ifndef __MINGW32__
#include <dbghelp.h> #include <dbghelp.h>
#pragma comment(lib, "dbghelp.lib") #pragma comment(lib, "dbghelp.lib")
#endif
typedef WORD TColor; typedef WORD TColor;
HANDLE handleIn; HANDLE handleIn;
HANDLE handleOut; HANDLE handleOut;
@ -114,6 +115,7 @@ LONG WINAPI onUnhandledException(EXCEPTION_POINTERS* exception)
const DWORD threadId = ::GetCurrentThreadId(); const DWORD threadId = ::GetCurrentThreadId();
tlog1 << "Thread ID: " << threadId << " [" << std::dec << std::setw(0) << threadId << "]\n"; tlog1 << "Thread ID: " << threadId << " [" << std::dec << std::setw(0) << threadId << "]\n";
#ifndef __MINGW32__
//exception info to be placed in the dump //exception info to be placed in the dump
MINIDUMP_EXCEPTION_INFORMATION meinfo = {threadId, exception, TRUE}; MINIDUMP_EXCEPTION_INFORMATION meinfo = {threadId, exception, TRUE};
@ -132,6 +134,7 @@ LONG WINAPI onUnhandledException(EXCEPTION_POINTERS* exception)
HANDLE dfile = CreateFileA(mname, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_WRITE|FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0); HANDLE dfile = CreateFileA(mname, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_WRITE|FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0);
tlog1 << "Crash info will be put in " << mname << std::endl; tlog1 << "Crash info will be put in " << mname << std::endl;
MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), dfile, MiniDumpWithDataSegs, &meinfo, 0, 0); MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), dfile, MiniDumpWithDataSegs, &meinfo, 0, 0);
#endif
MessageBoxA(0, "VCMI has crashed. We are sorry. File with information about encountered problem has been created.", "VCMI Crashhandler", MB_OK | MB_ICONERROR); MessageBoxA(0, "VCMI has crashed. We are sorry. File with information about encountered problem has been created.", "VCMI Crashhandler", MB_OK | MB_ICONERROR);
return EXCEPTION_EXECUTE_HANDLER; return EXCEPTION_EXECUTE_HANDLER;
} }

View File

@ -133,7 +133,7 @@ public:
class DLL_LINKAGE CCreatureSet : public IArmyDescriptor //seven combined creatures class DLL_LINKAGE CCreatureSet : public IArmyDescriptor //seven combined creatures
{ {
CCreatureSet(const CCreatureSet&);; CCreatureSet(const CCreatureSet&);
CCreatureSet &operator=(const CCreatureSet&); CCreatureSet &operator=(const CCreatureSet&);
public: public:
TSlots stacks; //slots[slot_id]->> pair(creature_id,creature_quantity) TSlots stacks; //slots[slot_id]->> pair(creature_id,creature_quantity)

View File

@ -53,13 +53,13 @@ std::vector<const CArtifact *> CGTownInstance::merchantArtifacts;
std::vector<int> CGTownInstance::universitySkills; std::vector<int> CGTownInstance::universitySkills;
void IObjectInterface::onHeroVisit(const CGHeroInstance * h) const void IObjectInterface::onHeroVisit(const CGHeroInstance * h) const
{}; {}
void IObjectInterface::onHeroLeave(const CGHeroInstance * h) const void IObjectInterface::onHeroLeave(const CGHeroInstance * h) const
{}; {}
void IObjectInterface::newTurn () const void IObjectInterface::newTurn () const
{}; {}
IObjectInterface::~IObjectInterface() IObjectInterface::~IObjectInterface()
{} {}

View File

@ -50,6 +50,7 @@ void CThreadHelper::processTasks()
void setThreadName(const std::string &name) void setThreadName(const std::string &name)
{ {
#ifdef _WIN32 #ifdef _WIN32
#ifndef __GNUC__
//follows http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx //follows http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
const DWORD MS_VC_EXCEPTION=0x406D1388; const DWORD MS_VC_EXCEPTION=0x406D1388;
#pragma pack(push,8) #pragma pack(push,8)
@ -67,6 +68,7 @@ void setThreadName(const std::string &name)
info.dwThreadID = -1; info.dwThreadID = -1;
info.dwFlags = 0; info.dwFlags = 0;
__try __try
{ {
RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info ); RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info );
@ -74,6 +76,10 @@ void setThreadName(const std::string &name)
__except(EXCEPTION_EXECUTE_HANDLER) __except(EXCEPTION_EXECUTE_HANDLER)
{ {
} }
#else
//not supported
#endif
#else #else
prctl(PR_SET_NAME, name.c_str(), 0, 0, 0); prctl(PR_SET_NAME, name.c_str(), 0, 0, 0);
#endif #endif

View File

@ -66,7 +66,7 @@ namespace boost
class basic_socket_acceptor; class basic_socket_acceptor;
} }
class mutex; class mutex;
}; }
enum SerializationLvl enum SerializationLvl
{ {

View File

@ -641,7 +641,7 @@ namespace NBonus
//DLL_LINKAGE const HeroBonus * get(const CBonusSystemNode *obj, int from, int id ); //DLL_LINKAGE const HeroBonus * get(const CBonusSystemNode *obj, int from, int id );
DLL_LINKAGE void getModifiersWDescr(const CBonusSystemNode *obj, TModDescr &out, Bonus::BonusType type, int subtype = -1 ); //out: pairs<modifier value, modifier description> DLL_LINKAGE void getModifiersWDescr(const CBonusSystemNode *obj, TModDescr &out, Bonus::BonusType type, int subtype = -1 ); //out: pairs<modifier value, modifier description>
DLL_LINKAGE int getCount(const CBonusSystemNode *obj, int from, int id); DLL_LINKAGE int getCount(const CBonusSystemNode *obj, int from, int id);
}; }
/// generates HeroBonus from given data /// generates HeroBonus from given data
inline Bonus makeFeatureVal(Bonus::BonusType type, ui8 duration, si16 subtype, si32 value, Bonus::BonusSource source, ui16 turnsRemain = 0, si32 additionalInfo = 0) inline Bonus makeFeatureVal(Bonus::BonusType type, ui8 duration, si16 subtype, si32 value, Bonus::BonusSource source, ui16 turnsRemain = 0, si32 additionalInfo = 0)

View File

@ -48,7 +48,7 @@ struct CPack
{ {
tlog1 << "CPack serialized... this should not happen!\n"; tlog1 << "CPack serialized... this should not happen!\n";
} }
DLL_LINKAGE void applyGs(CGameState *gs) void applyGs(CGameState *gs)
{}; {};
}; };
@ -629,7 +629,7 @@ struct NewStructures : public CPackForClient //504
{ {
NewStructures(){type = 504;}; NewStructures(){type = 504;};
void applyCl(CClient *cl); void applyCl(CClient *cl);
DLL_LINKAGE virtual void applyGs(CGameState *gs); DLL_LINKAGE void applyGs(CGameState *gs);
si32 tid; si32 tid;
std::set<si32> bid; std::set<si32> bid;

View File

@ -25,7 +25,7 @@ namespace Res
#define scalarOperator(OPSIGN) \ #define scalarOperator(OPSIGN) \
DLL_LINKAGE ResourceSet operator OPSIGN(const TResource &rhs) const \ ResourceSet operator OPSIGN(const TResource &rhs) const \
{ \ { \
ResourceSet ret = *this; \ ResourceSet ret = *this; \
for(int i = 0; i < size(); i++) \ for(int i = 0; i < size(); i++) \
@ -37,7 +37,7 @@ namespace Res
#define vectorOperator(OPSIGN) \ #define vectorOperator(OPSIGN) \
DLL_LINKAGE ResourceSet operator OPSIGN(const ResourceSet &rhs) const \ ResourceSet operator OPSIGN(const ResourceSet &rhs) const \
{ \ { \
ResourceSet ret = *this; \ ResourceSet ret = *this; \
for(int i = 0; i < size(); i++) \ for(int i = 0; i < size(); i++) \
@ -48,7 +48,7 @@ namespace Res
#define opEqOperator(OPSIGN, RHS_TYPE) \ #define opEqOperator(OPSIGN, RHS_TYPE) \
DLL_LINKAGE ResourceSet& operator OPSIGN ## =(const RHS_TYPE &rhs) \ ResourceSet& operator OPSIGN ## =(const RHS_TYPE &rhs) \
{ \ { \
return *this = *this OPSIGN rhs; \ return *this = *this OPSIGN rhs; \
} }
@ -70,7 +70,7 @@ namespace Res
#undef opEqOperator #undef opEqOperator
//to be used for calculations of type "how many units of sth can I afford?" //to be used for calculations of type "how many units of sth can I afford?"
DLL_LINKAGE int operator/(const ResourceSet &rhs) int operator/(const ResourceSet &rhs)
{ {
int ret = INT_MAX; int ret = INT_MAX;
for(int i = 0; i < size(); i++) for(int i = 0; i < size(); i++)
@ -80,7 +80,7 @@ namespace Res
return ret; return ret;
} }
DLL_LINKAGE ResourceSet & operator=(const TResource &rhs) ResourceSet & operator=(const TResource &rhs)
{ {
for(int i = 0; i < size(); i++) for(int i = 0; i < size(); i++)
at(i) = rhs; at(i) = rhs;