./Game

Sage
Posts: 1,403
Joined: 2005.07
Post: #1
If I go
cd MyAMAZINGGame
./MySUPERgreatAMAZINGGame
It works fine,

but if I go
/MyAMAZINGGame/MySUPERgreatAMAZINGGame
It crashes

This is because It loads resources from the same directory it is run in, but I need to change that to load resources from the directory it is in...
How can I do this?
And also have it work multiplatform if possible (If thats not possible then ill just have to have the code change from the makefile or somthing but ill deal with that stuff later)

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #2
What API/language?

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #3
just C with SDL and OpenGL.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
SDL sets the working directory to the directory containing your application bundle for you. You can change this behavior in SDL_main.m.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #5
I cant find SDL_main, is that a file im supposed to create because I may have called it somthing else. Im linking my .o files together with gcc -o to get a unix application (Im guessing thats what it is, it runs from the terminal)

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
no, that's a file you need to build a mac application with SDL.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #7
I use SDL to make my window to put an OpenGL context in, and it all works multiplatform (Im hoping, very very hoping).
The kind is Unix Executable File, it was compiled from .c and .h file using gcc.

Im looking for a way to get kind of pwd, but inside my program so that I can load files from the resources directory in the same folder as the game.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #8
If you are building this from the command line, then you're using using libSDLmain. That has the code that OneSadCookie is referring to. It doesn't do anything special if you aren't launching it from the finder anyway.

If the program is being launched from the command line, I don't know if it's possible to get the location of the executable. Usually people just put the data in a standard place like /usr/local/share.
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #9
Assuming you have a POSIX-like system, you might try stripping the executable name off of argv[0] and changing the directory to that...

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #10
THATS IT, I knew there was a way!
Gives ./myGame when I do ./myGame, and give me myFolder/myGame when I double run it like that, sweet Cool .

Im not sure what libSDLmain.a is but its in /usr/local along with all my other SDL libraries so am I importing it when I do gcc `sdl-config --libs` ......

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #11
Careful, it could be a relative path, it could be in the user's PATH, and it could contain any number of symbolic links. I have a library here: http://onesadcookie.com/svn/repos/ExecutablePath/ which can resolve that, but...

On Mac OS X it's much easier to use CFBundle or NSBundle to find your executable.

On Linux it's much easier to resolve the /proc/<pid>/exe symlink to find your executable, and

On Windows the CWD seems always to be the one containing your executable.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #12
Thank you very much one sad cookie thats exactly what I have been looking for actually Grin .

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 567
Joined: 2004.07
Post: #13
I just put
Code:
chdir([[[[NSBundle mainBundle] resourcePath] absoluteString] UTF8String]);
into my SDL_Main.m file.

some of those may be wrong, I haven't used any of those in a while.

It's not magic, it's Ruby.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #14
Thats pretty much what im doing in my other game that im writing but im hoping not to have to use any platform specific frameworks/libraries.
whats chdir?
I dont understand this SLD_main file, where is it? Is SDL_main.m the file that contains the in main(int argv, char *argc) { bit, (like the proc. that gets used when the application is started)? Because If it is then ive just called it myGame.c...

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #15
man 2 chdir:
Quote:CHDIR(2) BSD System Calls Manual CHDIR(2)

NAME
chdir, fchdir -- change current working directory

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Post Reply