VCMI on mac os x

Hi,

Here my changes for rev 772, that helps successfully compile and run vcmi on mac. Also, I included my workaround for deadlock in CGameHandler, that works for my. of course eventually the game crashes after some period.

$ svn diff
Index: hch/CBuildingHandler.cpp

— hch/CBuildingHandler.cpp (revision 772)
+++ hch/CBuildingHandler.cpp (working copy)
@@ -99,7 +99,7 @@
{
box = it = 0;
ofs.getline(line,100);

  •   	if(!line[0])
    
  •   	if(!line[0] || line[0] == '\n' || line[0] == '\r')
      		ofs.getline(line,100);
      	std::string linia(line);
      	bool areboxes=true;
    

@@ -152,4 +152,4 @@
return VLC->generaltexth->buildings[tid][bid].second;
tlog2 << "Warning: Cannot find description text for building " << bid << "for " << tid << “town.\n”;
return “”;
-}
\ No newline at end of file
+}
Index: hch/CVideoHandler.h

— hch/CVideoHandler.h (revision 772)
+++ hch/CVideoHandler.h (working copy)
@@ -114,7 +114,7 @@
class DLLHandler
{
public:
-#if !defined(amigaos4) && !defined(unix)
+#if !defined(amigaos4) && !defined(unix) && !defined(APPLE)
HINSTANCE dll;
#else
void *dll;
@@ -131,7 +131,7 @@
public:
DLLHandler ourLib;
int newmode;
-#if !defined(amigaos4) && !defined(unix)
+#if !defined(amigaos4) && !defined(unix) && !defined(APPLE)
HANDLE hBinkFile;
#else
void *hBinkFile;
Index: server/CGameHandler.h

— server/CGameHandler.h (revision 772)
+++ server/CGameHandler.h (working copy)
@@ -39,7 +39,7 @@
{
public:
std::map<ui8,PlayerStatus> players;

  • boost::mutex mx;
  • boost::mutex mx,mx2;
    boost::condition_variable cv; //notifies when any changes are made

    void addPlayer(ui8 player);
    Index: server/CGameHandler.cpp
    ===================================================================
    — server/CGameHandler.cpp (revision 772)
    +++ server/CGameHandler.cpp (working copy)
    @@ -485,7 +485,8 @@
    void CGameHandler::prepareAttack(BattleAttack &bat, CStack *att, CStack *def)
    {
    bat.stackAttacking = att->ID;

  • std::set::iterator bsa = bat.bsa.insert(BattleStackAttacked()).first;
  • std::set::iterator i = bat.bsa.insert(BattleStackAttacked()).first;

  • BattleStackAttacked *bsa = (BattleStackAttacked *) &*i;

    bsa->stackAttacked = def->ID;
    bsa->damageAmount = BattleInfo::calculateDmg(att, def, gs->getHero(att->attackerOwned ? gs->curB->hero1 : gs->curB->hero2), gs->getHero(def->attackerOwned ? gs->curB->hero1 : gs->curB->hero2), bat.shot());//counting dealt damage
    @@ -831,7 +832,7 @@
    }

    	//wait till turn is done
    
  •   	boost::unique_lock<boost::mutex> lock(states.mx);
    
  •   	boost::unique_lock<boost::mutex> lock(states.mx2);
      	while(states.players*.makingTurn && !end2)
      	{
      		boost::posix_time::time_duration p;
    

@@ -2399,4 +2400,4 @@
gs->map->events.pop_front();
}
}
-}
\ No newline at end of file
+}
Index: lib/NetPacksLib.cpp

— lib/NetPacksLib.cpp (revision 772)
+++ lib/NetPacksLib.cpp (working copy)
@@ -428,7 +428,7 @@
attacker->counterAttacks–;
if(shot())
attacker->shots–;

  • BOOST_FOREACH(BattleStackAttacked &stackAttacked, bsa)
  • BOOST_FOREACH(BattleStackAttacked stackAttacked, bsa)
    stackAttacked.applyGs(gs);
    }

@@ -484,4 +484,4 @@
DLL_EXPORT void SetSelection::applyGs( CGameState *gs )
{
gs->getPlayer(player)->currentSelection = id;
-}
\ No newline at end of file
+}
Index: lib/NetPacks.h

— lib/NetPacks.h (revision 772)
+++ lib/NetPacks.h (working copy)
@@ -668,11 +668,11 @@
ui8 flags; //1 - is stack killed; 2 - is there special effect to be shown;
ui32 effect; //set only if flag 2 is present

  • bool killed() //if target stack was killed
  • bool killed() const//if target stack was killed
    {
    return flags & 1;
    }
  • bool isEffect() //if target stack was killed
  • bool isEffect() const//if target stack was killed
    {
    return flags & 2;
    }
    @@ -1083,4 +1083,4 @@
    }
    };

-#endif //NETPACKS_H
\ No newline at end of file
+#endif //NETPACKS_H*

Hi!
Thanks for contribution! I’m happy to see VCMI becoming available to new platforms. :slight_smile:

Could you please repost your patch within the [code] / code] tags or adding it as attachment? Forum seems to not keep whitespaces in the usual posts.

Why it’s causing problems? Doesn’t set iterators provide -> operator?

Which compiler (and what version) are you using?

Because I got compiler errors:
server/CGameHandler.cpp: In member function ‘void CGameHandler::prepareAttack(BattleAttack&, CStack*, CStack*)’:
server/CGameHandler.cpp:490: error: assignment of data-member ‘BattleStackAttacked::stackAttacked’ in read-only structure
server/CGameHandler.cpp:491: error: assignment of data-member ‘BattleStackAttacked::damageAmount’ in read-only structure
server/CGameHandler.cpp:494: error: assignment of data-member ‘BattleStackAttacked::damageAmount’ in read-only structure
server/CGameHandler.cpp:495: error: assignment of data-member ‘BattleStackAttacked::flags’ in read-only structure

Xcode with gcc version 4.0.1 (Apple Inc. build 5488). Same error messages appears in gcc version 4.3.2 (Ubuntu 4.3.2-1ubuntu12).

I find, that “timed_wait hack” in server/CGameHandler.cpp didn’t work for me niter in mac no in linux, but _MSC_VER part of code work grate with boost v1.38. I just commented it, and now my deadlock workaround is no longer needed

PS:
I can’t send replays with untagged word “gcc” :))
vcmi_r773.patch.gz (2.62 KB)

I’ve committed your patch (r774).
Thanks again :slight_smile:

Hmm, so the operator-> products can be used only as rvalue… good to know, I won’t make such errors again :slight_smile:

Strange… but if it works now, so be it :slight_smile:

Strange issue. I’m also observing it, but not always…
Maybe I’ll take a closer look on it, when I have more time (though it’s the forum engine problem). By that time the tagging workaround will have to be used.

Is this port still being actively pursued?

If we had a developer that uses Mac OS we would have Mac port of VCMI. Unfortunately you have to wait till we find one.