file_system.rst 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. File System
  2. ===========
  3. Introduction
  4. ------------
  5. Filesystem usage is yet another hot topic in engine development. This
  6. means, where are assets stored, how are they accessed, how do multiple
  7. programmers edit the same repository, etc.
  8. Initial versions of the engine (and previous iterations before it was
  9. named Godot) used a database. Assets were stored there and assigned an
  10. ID. Other approaches were tested, too, with local databases, files with
  11. metadata, etc. To say truth, and after a long time, simplicity proved to
  12. be best and Godot stores all assets as files in the flesystem.
  13. Implementation
  14. --------------
  15. Godot stores resources to disk. Anything, from a script, to a scene or a
  16. PNG image is a resource to the engine. If a resource contains properties
  17. that referece other resources on disk, the path to that resource is
  18. included. If it has sub-resources that are built-in, the resource is
  19. saved in a single file together with all the bundled sub-resources. For
  20. example, a font resource is often saved with the character textures
  21. bundled inside.
  22. Metadata files were also dropped and the whole engine design tries to
  23. avoid them. The reason for this is simple, existing asset managers and
  24. VCSs are just much better than anything we can implement, so Godot tries
  25. the best to play along with SVN, Git, Mercurial, Perforce, etc.
  26. engine.cfg
  27. ----------
  28. | The mere existence of this file marks that there is a Godot project in
  29. that directory and all sub-directories.
  30. | This file contains the project configuration in plain text, win.ini
  31. style, though it will work to mark the existence of a project even if
  32. the file is empty.
  33. Example of a filesystem:
  34. ::
  35. /engine.cfg
  36. /enemy/enemy.scn
  37. /enemy/enemy.gd
  38. /enemy/enemysprite.png
  39. /player/player.gd
  40. Directory Delimiter
  41. -------------------
  42. Godot only supports "/" as a directory delimiter. This is done for
  43. portability reasons. All operating systems support this, even Windows,
  44. so a path such as c:\\\\project\\\\engine.cfg needs to be typed as
  45. c:/project/engine.cfg.
  46. Resource Path
  47. -------------
  48. For accessing resources, using the host OS filesystem layout can be
  49. cumbersome and non portable. To solve this problem, the specal path
  50. \`"res://"\` was created.
  51. The path \`"res://"\` will always point at the project root (where
  52. engine.cfg is located, so in fact \`"res://engine.cfg"\` is always
  53. valid).
  54. This filesystem is read-write only when running the project locally from
  55. the editor. When exported or when running on different devices (such as
  56. phones or consoles, or running from DVD), the filesystem will become
  57. read-only and writing will no longer be permitted.
  58. User Path
  59. ---------
  60. Writing to disk is still needed often, from doing a savegame to
  61. downloading content packs. For this, the engine ensures that there is a
  62. special path \`"user://"\` that is always writable.
  63. Host Filesystem
  64. ---------------
  65. Of course, opening the host filesystem always works, as this is always
  66. useful when Godot is used to write tools, but for shipped projects this
  67. is discouraged and may not even be supported in some platforms.
  68. Drawbacks
  69. ---------
  70. Not everything is rosy. Using resources and files and the plain
  71. filesystem has two main drawbacks. The first is that moving assets
  72. around (renaming them or moving them from a directory to another inside
  73. the project) once they are referenced is not that easy. If this is done,
  74. then dependencies will need to be re-satisfied upon load.
  75. The second is that under Windows or OSX, file access is case
  76. insensitive. If a developer works in this operating system and saves a
  77. file like "myfile.PNG", then references it as "myfile.png", it will work
  78. there, but not on any other platform, such as Linux, Android, etc. It
  79. may also not work on exported binaries, which use a compressed package
  80. for files.
  81. Because of this, please instruct your team to use a specific naming
  82. convention for files when working with Godot!
  83. *Juan Linietsky, Ariel Manzur, Distributed under the terms of the `CC
  84. By <https://creativecommons.org/licenses/by/3.0/legalcode>`__ license.*