PDA

View Full Version : FPC + Mac file handling



dazappa
18-04-2011, 03:04 PM
I've mentioned somewhere here before that I've been able to put OS X in a VM a long while back, and recently I have gotten XCode + FPC/Lazarus working happily.

I'm having trouble trying to get my Tiled project to work under OS X (http://www.pascalgamedevelopment.com/content.php?205-Tiled-CSV-map-loading-(with-ZenGL)

Has anyone been able to? It dies on the line 67 "AssignFile(mapfile, fname);" with a file not found error. I did a fileexists on the file, and indeed for some reason it cannot find the file! I have literally copied this file everywhere -- every subdirectory of the .app, and the root directory the .app is in. I've even tried appending "./" to the filename, with no luck. While ZenGL doesn't complain about whether or not it can find the other resources (which are loaded before this map file is opened), I have no way to tell if it really loaded them successfully yet ;P

Summary: How do I access files, and where do they go under OS X. If I specify a full path to the file, it will run happily, but I would much prefer relative paths for actual distribution.

Andru
18-04-2011, 03:20 PM
While ZenGL doesn't complain about whether or not it can find the other resources (which are loaded before this map file is opened)
Emm... You can get path to YourApp.app/ via zgl_Get and constant DIRECTORY_APP(see demo01). ZenGL by itself will look for resources in YourApp.app/Contents/Resources/, if you set relative paths for textures/etc.


If I specify a full path to the file, it will run happily, but I would much prefer relative paths for actual distribution.
You can try to use Chdir with path to YourApp.app, but I don't remember if it works. Also you can try to use ZenGL file_* functions :)

code_glitch
18-04-2011, 06:23 PM
You wouldnt be using a \ for folders coming from the winows world would you? a \ on unix like systems is an 'ignore next character' type thing... I would double check that they are all / . I had a very similar problem when I first moved to linux ;)

Andru
18-04-2011, 06:39 PM
code_glitch
problem is not in how you write the path... problem is in unavailability term "current path" in MacOS X for applications which are running from bundle :)

code_glitch
18-04-2011, 06:46 PM
Ah... But wouldnt that be the folder where the bin file is? Just like in Win and Linux?

JSoftware
18-04-2011, 06:53 PM
Try to see if the .app isn't in reality a symbolic link

You should never assume starting directory on any platform

Andru
18-04-2011, 07:20 PM
Ah... But wouldnt that be the folder where the bin file is? Just like in Win and Linux?
Yes, it's just a folder, but you can't work with files using relative paths :)

dazappa
18-04-2011, 11:51 PM
You wouldnt be using a \ for folders coming from the winows world would you? a \ on unix like systems is an 'ignore next character' type thing... I would double check that they are all / . I had a very similar problem when I first moved to linux ;)
Nope, you can see in my Tutorial source I use "map_csv.tmx" and the only thing else I tried was "./map_csv.tmx"

Try to see if the .app isn't in reality a symbolic link

You should never assume starting directory on any platform
The default way Lazarus produces apps under OS X is a bit strange, but no that was not the problem ;) I had to create the package myself though.

What Andru suggested (using a ZenGL function to get a var DIRECTORY_APP) has worked for me in this instance, at least. (Nice of you to include that!)

Victory!
http://i.imgur.com/DOYkn.png
As you can see, things are just a tad slow in the VM, and with no hardware acceleration it goes even slower. (It's a nice touch having a software renderer in this instance though) But, the good news is now I can compile to Win/Lin/Mac with a little effort. I only have one other project I'm working on aside from my Isolated Empire remake and port to ZenGL, so I'll post about that in a few weeks most likely.

paul_nicholls
19-04-2011, 03:18 AM
I'm glad you got it working dazappa :)


I've mentioned somewhere here before that I've been able to put OS X in a VM a long while back, and recently I have gotten XCode + FPC/Lazarus working happily.

dazappa, I don't suppose you could share how you did the OS X & VM? I really really want to try playing with a Mac and possibly do some programming too, but I don't have any Mac hardware..

If you want, just PM me.

cheers,
Paul

Andru
19-04-2011, 04:33 AM
And for those people who will search answer without using ZenGL, here the source code:


uses
MacOSAll;
//
var
appBundle : CFBundleRef;
appCFURLRef : CFURLRef;
appCFString : CFStringRef;
appPath : array[ 0..8191 ] of AnsiChar;
begin
appBundle := CFBundleGetMainBundle();
appCFURLRef := CFBundleCopyBundleURL( appBundle );
appCFString := CFURLCopyFileSystemPath( appCFURLRef, kCFURLPOSIXPathStyle );
CFStringGetFileSystemRepresentation( appCFString, @appPath[ 0 ], 8192 );
appWorkDir := appPath + '/';


But if I remember right, ParamString(0) also will return something... :)

paul_nicholls
19-04-2011, 05:56 AM
And for those people who will search answer without using ZenGL, here the source code:


uses
MacOSAll;
//
var
appBundle : CFBundleRef;
appCFURLRef : CFURLRef;
appCFString : CFStringRef;
appPath : array[ 0..8191 ] of AnsiChar;
begin
appBundle := CFBundleGetMainBundle();
appCFURLRef := CFBundleCopyBundleURL( appBundle );
appCFString := CFURLCopyFileSystemPath( appCFURLRef, kCFURLPOSIXPathStyle );
CFStringGetFileSystemRepresentation( appCFString, @appPath[ 0 ], 8192 );
appWorkDir := appPath + '/';


But if I remember right, ParamString(0) also will return something... :)

Nice! Good one Andru :)

cheers,
Paul