I want to distribute a game as a p3d, but as a downloadable file, not in a browser.
The idea is to make it portable, write the p3d file to a flash drive and run it wherever you are, on whatever os.
My problem is that I have no idea how to save anything. If I get it right the program run from a .p3d file has no idea where it is, so I can’t write game saves or settings to the same place were the p3d is because I won’t know where the p3d file is. Can’t write to the p3d file cause it’s read only (?). The ‘runtime directory’ is also of no big use, on windows it’s a hidden directory and I can’t expect end users to manually copy the files (finding them is a challenge).
So, is the only way to load/save files is to require the user to type in a full path every time a file is loaded/saved from a p3d file?
Even if you knew where the p3d file is, you couldn’t write to it. The p3d file is meant to be read-only.
So you don’t like the start directory because you want your users to be able to directly access the saved files for some reason? Then prompt the user for a directory that he likes (this is a good design anyway), and save that directory name in a file in the start directory.
The idea is to write the p3d to a flash drive, take it to your girlfriend, work, school etc. Play it from the flash drive, save to that drive and take it all home. You might never work on that computer again, but you don’t have to care, you’ve got all your files saved.
Saving a path in the start directory may give more problems, today the drive if called F:\ but tomorrow it might be E:\ or G:\ (say somebody plugged in two pendrives). It could work, but there’s a chance it could go very wrong.
I’m sure I’m missing something here, it must be something very complicated, because it seems so simple… before I pack the game os.getcwd() returns the current working directory, after packing this only works when running from the command prompt.
Maybe I have to make a starting application that will know where it is and give that info to the p3d file as an argument? Unfortunately I’ve no idea how.
Or maybe just a .bat (.sh for linux?) file that will run “panda3d myapp.p3d”? Would that work?
Note that you can use pdeploy to generate an .exe file that embeds the .p3d file, removing the need to have the Panda3D Runtime installed.
Also, if the Panda3D runtime is installed, you can run p3d files on non-Windows systems as if they were a binary (so no need for a .sh file).
If the exe file knows were it is when I double click it, then that’s just what I need
I’ll have to add osx and linux binary files, but I don’t need to put all the textures and models inside the binary files, the can be read from a common multifile, right?
Yeah, you could read them from a multifile or embed them into the .exe.
pdeploy can generate OSX .app bundles and Linux executables, too.
OK, I’ve just committed changes to the plugin system so that you can query base.appRunner.p3dFilename to determine the actual filename where the p3d file was found. (Note that if you’re running from a web page, this will be a meaningless temporary filename in the web cache.)
This will be available as of the 1.8 release.
The ‘filename’ is a panda Filename object with all the goodies, not just a name-of-the-file string?
Yes, but you can easily convert from a name-of-the-file string to a Filename class, so I’m not sure why it’s important to ask that question.