Monday, November 25, 2019

filesystem - Determining the location of installed/on disk game assets


I've been thinking a lot about the best way to store and load assets in your filesystem. By this I mean where in the file system to store them, and how to retrieve them when loading etc., as opposed to how their stored when the program is actually running. I would imagine that this would be a fairly common question, but I can't seem to find it anywhere else, perhaps because I'm not asking it properly.


So far, I have found two strategies, and I would like to know what other ones there are.




  1. Storing the assets in an absolute path on the system. You may have to get the users home directory if the user doesn't need to be an admit/root to install the game, and other OS dependant stuff would probably need to be done to ensure that the path is actually valid, but it seems like this could work well.





  2. Get the game's location on the system, and assume that assets can be found in an adjacent directory. I don't think there is any OS independent way to do this, but it does seem feasible. This might be nice as it doesn't require the user to install the game, making it all around more portable, but it does seem like it would destroy an OS paradigm where specific portions of the game when in a certain place in the os (say /usr/games, and the executable would go in a different directory).




Both of these ways do seem a bit clunky, so are there any other ways to get the location of your assets? Otherwise, which is used more in games you've worked on? Thank you.



Answer



You're over-engineering this =)


Windows games have two different storage areas:


The first is for static data with the installed program and these files are almost always referenced relative to the application itself, or defined in a file (XML usually) that the program loads when it starts up so there are no hard-coded references. Using the Windows Registry to store paths has fallen out of favor.



The second is for user data like saved games, and there is a standard API for working with that directory. On recent Windows the standard security setting stops a user from saving data to the program area, which is why this is done. On Linux, which I am no expert, I'd assume this directory would be a convention to use /usr/games or something in the /usr directory space.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...