Mac OS X

OmniStudent
Member
Posts: 261
Joined: Sat Nov 03, 2012 06:40

Re: Mac OS X

by OmniStudent » Post

Morn76 wrote:StackOverflow also links to this monster: http://www.aao.gov.au/local/www/ks/uplo ... imedwait.c , but I don't even know how I would integrate this thing into the existing code. More fiddling with cmake would probably be needed.
That looks promising though, I will have a look at it.

Morn76
Member
Posts: 659
Joined: Sun Feb 16, 2014 19:45

Re: Mac OS X

by Morn76 » Post

OmniStudent wrote:That's strange, 97723226 is supposed to be before semaphores where added. Are you sure you got the correct commit? Can't find 122875c30cc2 on github but that's just because one can't search for sha numbers there.
Yes, unfortunately OS X's git does not seem to come with gitk. Maybe install the Homebrew git? GitHub is nice but it does not replace the functionality of gitk.

122875c30cc2553a4db41308e597e928c8e6e7ad
Bump version to 0.4.8 by kwolekr (2013-11-24)
This one works for me.

jsemaphore was introduced in
2e66aca35722e7fee786027d545fe371786fc01f
Fix modstore/favourites hang by adding asynchronous lua job support by sapier (2013-11-26)

977232261388fa80bd6ab3bb849ae4d7a8ade73e
Add alpha setting to font shadow by BlockMen (2013-12-12)
This already has the jsemaphore stuff in the tree, so it's no wonder it doesn't work for me.
OmniStudent wrote:
Morn76 wrote:StackOverflow also links to this monster: http://www.aao.gov.au/local/www/ks/uplo ... imedwait.c , but I don't even know how I would integrate this thing into the existing code. More fiddling with cmake would probably be needed.
That looks promising though, I will have a look at it.
It needs "sem_timedwait.h" apparently though, and I can't find that anywhere online.

Basically it should be enough to include mach/semaphore.h instead of semaphore.h and then call semaphore_timedwait() because the Mach kernel on OS X actually has this function. Like it's done here: https://github.com/constcast/vermont/tr ... /osdep/osx Unfortunately I have not been able to do this with the MT code successfully though, I always get lots of compilation errors when I change the include file to mach.

If Sapier could rewrite his MT code so sem_getvalue() and sem_timedwait() were no longer needed, we could use the Apple macros to transform the remaining sem_*() calls and everything should be solved. I don't know if this is possible though.

The devs have really painted themselves into the proverbial corner with all this jsemaphore stuff in MT. IMO Sapier's commit should have been rejected in November as non-portable, but unfortunately nobody seems to have checked portability at the time. So now we are a bit stuck.

OmniStudent
Member
Posts: 261
Joined: Sat Nov 03, 2012 06:40

Re: Mac OS X

by OmniStudent » Post

Morn76 wrote: It needs "sem_timedwait.h" apparently though, and I can't find that anywhere online.
It should be possible to look at the cpp file and write the h file from this. I'm trying to include an arbitrary file in my xcode mt project now, and am writing a small h file for this.
Morn76 wrote: Basically it should be enough to include mach/semaphore.h instead of semaphore.h and then call semaphore_timedwait() because the Mach kernel on OS X actually has this function. Like it's done here: https://github.com/constcast/vermont/tr ... /osdep/osx Unfortunately I have not been able to do this with the MT code successfully though, I always get lots of compilation errors when I change the include file to mach.
Does it help that I have succesfully included these from porting.h line 225 ?

Code: Select all

#else // Posix
	#include <sys/time.h>
	#include <time.h>

#include <mach/mach_time.h>
#include <mach/mach.h>
#include <mach/mach_init.h>
#include <mach/thread_policy.h>
#define CLOCK_REALTIME 0
#define CLOCK_MONOTONIC 0
	
	inline u32 getTimeS()
as part of earlier experimentation.
Morn76 wrote:
If Sapier could rewrite his MT code so sem_getvalue() and sem_timedwait() were no longer needed, we could use the Apple macros to transform the remaining sem_*() calls and everything should be solved. I don't know if this is possible though.

The devs have really painted themselves into the proverbial corner with all this jsemaphore stuff in MT. IMO Sapier's commit should have been rejected in November as non-portable, but unfortunately nobody seems to have checked portability at the time. So now we are a bit stuck.
There hasn't been much interest in osx, so it's been neglected for a long time. Sapier seems pretty thorough though, so maybe he'll fix this code. Or we :)

Morn76
Member
Posts: 659
Joined: Sun Feb 16, 2014 19:45

Re: Mac OS X

by Morn76 » Post

Yes, I suppose it's possible to construct a .h with just the function definition. Of course there might be other defines and macros in the .h that we don't know about.

My fiddling with mach/semaphore.h in MT's jsemaphore.h looks like this so far:

Code: Select all

#if defined(WIN32)
#include <windows.h>
#include <assert.h>
#define MAX_SEMAPHORE_COUNT 1024
#else
#include <mach/semaphore.h>
#include <pthread.h>
//#include <semaphore.h>
#include <mach/mach.h>
#include <mach/task.h>
#undef sem_t
#define sem_t semaphore_t
#undef sem_init
#define sem_init(s,p,c) semaphore_create(mach_task_self(),s,SYNC_POLICY_FIFO,c)
#undef sem_wait
#define sem_wait(s) semaphore_wait(*s)
#undef sem_post
#define sem_post(s) semaphore_signal(*s)
#undef sem_destroy
#define sem_destroy(s) semaphore_destroy(mach_task_self(),*s)
#undef sem_timedwait
#define sem_timedwait(s,t) semaphore_timedwait(*s,t)
#endif
Strangely enough the other Mach calls like semaphore_wait don't need the mach include file, but semaphore_timedwait does.

The main problem is that Sapier apparently does not have a Mac himself, so coming up with a working fix is not that easy for him. Then again, he is the one who broke portability, so he should fix it. :-)

OmniStudent
Member
Posts: 261
Joined: Sat Nov 03, 2012 06:40

Re: Mac OS X

by OmniStudent » Post

Stumbled into this

Code: Select all

#define sem_init(s, p, v)   fuse_sem_init(s, p, v)
#define sem_destroy(s)      fuse_sem_destroy(s)
#define sem_getvalue(s, v)  fuse_sem_getvalue(s, v)
#define sem_post(s)         fuse_sem_post(s)
#define sem_timedwait(s, t) fuse_sem_timedwait(s, t)
#define sem_trywait(s)      fuse_sem_trywait(s)
#define sem_wait(s)         fuse_sem_wait(s)
in fuse_darwin.h, a file from MacFuse. Perhaps its possible to use this?

Morn76
Member
Posts: 659
Joined: Sun Feb 16, 2014 19:45

Re: Mac OS X

by Morn76 » Post

Interesting! That project is dead though and the code might be broken on current versions of OS X. At least that's what I gather from their homepage on Google Code. Still, it might be worth a try. At least all the calls we need seem to be there.

Morn76
Member
Posts: 659
Joined: Sun Feb 16, 2014 19:45

Re: Mac OS X

by Morn76 » Post

Yay, I've figured out how to use the Mach semaphores. Instead of #include <semaphore.h> in jsemaphore.h:

Code: Select all

#include <mach/semaphore.h>
#include <sys/semaphore.h>
Don't use any of the Apple macros because sem_*() are defined by these include files too!

Now the only showstopper is that sem_timedwait() isn't implemented by Mach either. But at least sem_getvalue() is no longer a problem.

Morn76
Member
Posts: 659
Joined: Sun Feb 16, 2014 19:45

Re: Mac OS X

by Morn76 » Post

Finally!

The latest git version compiles and runs! I'm attaching a ZIP file with my jsemaphore.h and .cpp.

So now I've basically lifted the code from vermont for sem_timedwait and combined it with the Apple macros.

It's a bit of a mess and not at all fit for "minetest/minetest" trunk but at least it works.

Image
Attachments
jthread.zip
Jthread for OS X
(26.77 KiB) Downloaded 73 times

OmniStudent
Member
Posts: 261
Joined: Sat Nov 03, 2012 06:40

Re: Mac OS X

by OmniStudent » Post

Great work Morn76! :) :) :)

I'm gonna try it out at once.

Morn76
Member
Posts: 659
Joined: Sun Feb 16, 2014 19:45

Re: Mac OS X

by Morn76 » Post

Could you package this as an app or did you lose your modified cmake files, OmniStudent? I need working keyboard input to actually start a world.

Morn76
Member
Posts: 659
Joined: Sun Feb 16, 2014 19:45

Re: Mac OS X

by Morn76 » Post

BTW, I notice sem_getvalue() is still commented out in jsemaphore.cpp, so this might not work properly yet. Unfortunately Mach unnamed semaphores do not include _getvalue(): http://web.mit.edu/darwin/src/modules/xnu/osfmk/man/

OmniStudent
Member
Posts: 261
Joined: Sat Nov 03, 2012 06:40

Re: Mac OS X

by OmniStudent » Post

Morn76 wrote:Could you package this as an app or did you lose your modified cmake files, OmniStudent? I need working keyboard input to actually start a world.
Yes I've lost the latest cmake file file for this, but I think the cpack commands in the end of his cmakelists do the trick.

https://github.com/toabi/minetest/blob/ ... eLists.txt

Morn76
Member
Posts: 659
Joined: Sun Feb 16, 2014 19:45

Re: Mac OS X

by Morn76 » Post

It works! No really this time, I swear. :-)

Well, maybe not perfectly, I'm seeing some mesh-related timeout messages. But I can dig blocks, I can place blocks, etc.

Shaders don't seem to work on OS X (everything was textured red initially).

I've added a counter for sem_getvalue(). And it turned out jevent.h/.cpp had even more semaphores that also needed to be converted to Mach.

Image
Attachments
jthread_2.zip
New version of jthread directory
(26.54 KiB) Downloaded 65 times

Jordach
Member
Posts: 4534
Joined: Mon Oct 03, 2011 17:58
GitHub: Jordach
IRC: Jordach
In-game: Jordach
Location: Blender Scene

Re: Mac OS X

by Jordach » Post

Shaders don't work because they require OpenGL 3.0+, and GLSL 1.2+, Macs that are as old as yours don't have said capabilities.

Morn76
Member
Posts: 659
Joined: Sun Feb 16, 2014 19:45

Re: Mac OS X

by Morn76 » Post

Purchased it in January 2013 I think. I guess that makes it ancient history by Apple standards?

User avatar
Topywo
Member
Posts: 1721
Joined: Fri May 18, 2012 20:27

Re: Mac OS X

by Topywo » Post

Congratulations!

Although I'm not using Mac OS X, I appreciate the work you have done.

Morn76
Member
Posts: 659
Joined: Sun Feb 16, 2014 19:45

Re: Mac OS X

by Morn76 » Post

Topywo wrote:Congratulations!

Although I'm not using Mac OS X, I appreciate the work you have done.
Support for Windows, Linux, and OS X seems to be a pretty standard feature of established open source projects (like Gimp, Clementine, Stellarium, etc.). To me it always signifies quality and that the devs care about their user base, no matter what their OS of choice is. Plus I like to have my favorite software installed on all my machines, so OS X support for Minetest is a must. :-)

"long waittime = time_ms;" in jsemaphore.cpp seems to have fixed the timout error messages. I forgot about that.

I notice crouching with Shift doesn't work, I just wander right off the node edge. German keyboard issue?

The git version number of the bundle is not set, but this is probably because I downloaded a ZIP of the latest git version.

Oh well, but generally this is quite nice so far. I guess I should look into packaging a bit more so the support files are copied into the .dmg automatically. And I think the .dmg does not contain the required dynamic libraries either which would be needed to make the bundle fully self contained.

User avatar
hoodedice
Member
Posts: 1374
Joined: Sat Jul 06, 2013 06:33
GitHub: hoodedice
IRC: hoodedice
In-game: hoodedice
Location: world
Contact:

Re: Mac OS X

by hoodedice » Post

Topywo wrote:Congratulations!

Although I'm not using Mac OS X, I appreciate the work you have done.

I have to say it too, you guys are doing a great job! I have been following your posts since the last few days (O.O Stalker!) and I am thoroughly impressed by your speed with fixing this issue =D

Keep it going peeps
7:42 PM - Bauglio: I think if you go to staples you could steal firmware from a fax machine that would run better than win10 does on any platform
7:42 PM - Bauglio: so fudge the stable build
7:43 PM - Bauglio: get the staple build

Morn76
Member
Posts: 659
Joined: Sun Feb 16, 2014 19:45

Re: Mac OS X

by Morn76 » Post

Jordach wrote:Shaders don't work because they require OpenGL 3.0+, and GLSL 1.2+, Macs that are as old as yours don't have said capabilities.
As it turns out, shaders did not work because they were not installed into the application bundle. Oops. I just needed to copy them to /Applications/minetest.app/Contents/Resources/bin/share/client/shaders and now they work just fine.

User avatar
GingerHunter797
Member
Posts: 144
Joined: Sun Oct 13, 2013 15:36
In-game: GingerHunter797
Location: Indiana

Re: Mac OS X

by GingerHunter797 » Post

Congratulations! Minetest can now be run on Mac! :D
I dont use a Mac but I am still happy that it can be done!
http://i.imgur.com/gqXXUaI.png

3DS Friend Code: 2122-7173-2797
Add me as a friend! :D

Want to play a fun game? http://voxelands.com/

Morn76
Member
Posts: 659
Joined: Sun Feb 16, 2014 19:45

Re: Mac OS X

by Morn76 » Post

GingerHunter797 wrote:Congratulations! Minetest can now be run on Mac!
Thanks, GingerHunter797, but actually MT could always run on the Mac (https://github.com/toabi/minetest-mac/downloads). It's just been broken since late November last year when jsemaphore was introduced.

The main difference might be that this time the necessary changes might get polished and tested sufficiently to also get merged into the main repository eventually.

OmniStudent
Member
Posts: 261
Joined: Sat Nov 03, 2012 06:40

Re: Mac OS X

by OmniStudent » Post

Again, great work Morn76, and thanks to all you other guys for the support and cheering on.

I've finally managed to make a github repository with Morn76's changes,

https://github.com/Belugion/minetest
Sorry if its a bit dirty with unneccessary files :(

It compiles with targets build_all and package. Can't get it to run though, probably because all the support files are in the wrong place.

Morn76
Member
Posts: 659
Joined: Sun Feb 16, 2014 19:45

Re: Mac OS X

by Morn76 » Post

Zipped OS X application bundle is available here now:

https://github.com/mdoege/minetest/releases/
Last edited by Morn76 on Tue Apr 22, 2014 15:18, edited 1 time in total.

Morn76
Member
Posts: 659
Joined: Sun Feb 16, 2014 19:45

Re: Mac OS X

by Morn76 » Post

OmniStudent wrote: I've finally managed to make a github repository with Morn76's changes,

https://github.com/Belugion/minetest
Sorry if its a bit dirty with unneccessary files :(
You are missing "long waittime = time_ms;" in jsemaphore.cpp in your repo. " … = 3" was just a test...

OmniStudent
Member
Posts: 261
Joined: Sat Nov 03, 2012 06:40

Re: Mac OS X

by OmniStudent » Post

Thankyou for checking!

Fixed that.

Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests