Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Mac/Xcode current working directory?  (Read 11616 times)

0 Members and 1 Guest are viewing this topic.

drew

  • Newbie
  • *
  • Posts: 11
    • View Profile
Mac/Xcode current working directory?
« on: August 15, 2009, 06:01:30 am »
So I'm working on a cross platform game and have it compiling just fine on windows and mac. However, I can't figure out how to get the proper path when compiling my xcode project. My game compiles fine but none of my images or other data will load. Can't find the right path. Could someone please help me with this?

Do I need to add all my files in the resources folder? When I do this, if I do "show package contents" in the .app file that's made, I can find the files I added under /Contents/Resources. So from figuring out that, I tried to add /Contents/Resources to the path of my files in my source code but still no go. Anyone have any idea? I found some mention of having to use NSBundle to get the path to the bundle but I'm not sure how to use it...

madmark

  • Newbie
  • *
  • Posts: 3
    • View Profile
Mac/Xcode current working directory?
« Reply #1 on: August 15, 2009, 11:58:16 am »
Sounds like you are almost there, you have the content in the bundle.

/Contents/Resources will not work because it is lokking for a mounted volume called "Contents".

I'm afraid I'm not much help because it just seems to work for me (I'm also a Windows guy, well ex-windows anyways). I have my files in folders under "Resources" in the bundle and they are accessible using the same code under Windows and Mac.

My runtime directory under Win:

game.exe
Art/
Scripts/
XML/

The Art, Scripts and XML Directories are copied into the bundle and are accessible using the same code as Windows.

Hope this helps some...

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
Mac/Xcode current working directory?
« Reply #2 on: August 16, 2009, 03:13:35 pm »
Your paths must be relative to the Resources folder. Your path beginning with / is absolute.

For example, if you've a file named "image.png" in your resources folder, to read it, the right path will be "image.png".
Want to play movies in your SFML application? Check out sfeMovie!

drew

  • Newbie
  • *
  • Posts: 11
    • View Profile
Mac/Xcode current working directory?
« Reply #3 on: August 18, 2009, 10:32:40 pm »
Ahhh you're a genius! Finally something so simple and it works. Can't believe I didn't try that before. :?

Terrydil

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Mac/Xcode current working directory?
« Reply #4 on: September 19, 2009, 06:51:04 pm »
So if I have a file that is showing up the Resources folder of my bundle as "Paper.png" I should be able to call image.LoadFromFile("Paper.png") correct?  I get the error Failed to load image "Paper.png". Reason : can't fopen.  Is there a way to ensure that Resources is the working directory?  I get the feeling I'm missing something very simple... :)

Ceylo

  • Hero Member
  • *****
  • Posts: 2325
    • View Profile
    • http://sfemovie.yalir.org/
    • Email
Mac/Xcode current working directory?
« Reply #5 on: September 20, 2009, 02:38:25 pm »
You can check this with something like that :
Code: [Select]
#include <unistd.h>
#include <stdio.h>

void showCurrentWorkingDirectory(void)
{
    char path[1024];
    getcwd(path, sizeof(path));
    puts(path);
}


Note that the Resources folder is the default working directory since SFML 1.5, so if you're using SFML 1.4 you'll need to update your frameworks.
Want to play movies in your SFML application? Check out sfeMovie!

Terrydil

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Mac/Xcode current working directory?
« Reply #6 on: September 20, 2009, 04:52:58 pm »
I was using an old version, I upgraded and everything seems to be working fine. Thanks Ceylo.

 

anything