Piggs

From OuroDev
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Piggs are flat archives of game data files. They are usually handled transparently, with game code reading files out of piggs or the local filesystem by searching for the first thing that exists.

When the term absolute paths is used, it has an unusual meaning:

  • Either the path is at least two characters long and the second one is a : (as in c:\foo.txt)
  • Or the first character of the path is . (as in ./foo.txt, which we would normally think of as a relative path)
  • Or the first two characters of the path are \\

Data directories

In development mode, the list of data dirs can be overridden by the first thing in this list which is found:

  • a file "gamedatadir.txt" in the current directory, which is a list of search paths. If this file exists, and a "data" directory also exists in the current directory, then gamedatadir.txt is ignored and the rest of this process is skipped
  • any parent directory of the current directory which contains a subdirectory "data" or "tools", which will add the subdirectories "localdata", "serverdata", and "data to the data dirs. Depending on the path, some hardcoded paths "c:/game", "c:/hotfix", "c:/fix*" are also searched for the same subdirectories.
  • the same search, in all parent directories of the directory where the executable is located
  • if the executable is in a set of well-known paths on c:/ then "c:/game", "c:/gamefix", and some constructed paths will be searched for the same subdirectories

If that process was not used, or did not find anything, then the following paths are added to the search path, if they exist:

  • ./piggs
  • ./data
  • ./ if nothing else has been found yet

In typical usage, when the "data" directory exists in the current directory, then the search path will be just:

  • ./piggs
  • ./data

The "main data directory" will be the last thing found, which is usually "./data".

For everything in the selected search paths, all subdirectories on the local filesystem are scanned for filenames, which are added to the FolderCache. If piggs/texts.pigg exists, then subdirectories will be skipped if they have any of these names:

  • scenes
  • ent_types
  • object_library
  • geobin

This means these directories cannot override pigg contents.

The main data directory will then be searched for paths matching ./piggs/*.*gg. All pigg and hogg files found will be opened, and their paths will be added to the FolderCache.

APIs

fopen

fopen has been overridden to add more file modes. When opening a file for read, if the ~ character is not present in the mode, then it can open paths like c:/game/data/piggs/file.pigg:/myfile.txt or ./piggs/file.pigg:/myfile.txt. This will result in transparently reading the file out of the pigg.

FolderCache

Most files are looked up via FolderCache, including opens with fopen and fileLocateRead. FolderCache can be in one of three modes. At initial startup, or when overridden by FolderCacheSetMode, it will be in "filesystem only" mode:

  • Absolute paths will be looked up in the filesystem
  • Other paths will be searched in all data dirs, and the first match will be used.

If the file ./piggs/texts.pigg exists then FolderCache will be in "I like pigs" (semi-production) mode after startup, which reads from pigg files but allows local files to verride them. Otherwise, FolderCache will be in "development dynamic" mode, which will use the version from the pigg only if it has the same timestamp as the filesystem copy, otherwise it will use the one from the local filesystem.