filesystem.rst 3.8 KB

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