bundle_compiler.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) 2012-2015 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/taylor001/crown/blob/master/LICENSE
  4. */
  5. #pragma once
  6. #include "disk_filesystem.h"
  7. #include "container_types.h"
  8. #include "compile_options.h"
  9. namespace crown
  10. {
  11. class BundleCompiler
  12. {
  13. public:
  14. BundleCompiler(const char* source_dir, const char* bundle_dir);
  15. bool compile(const char* type, const char* name, const char* platform);
  16. /// Compiles all the resources found in @a source_dir and puts them in @a bundle_dir.
  17. /// Returns true on success, false otherwise.
  18. bool compile_all(const char* platform);
  19. /// Scans the source directory for resources.
  20. void scan_source_dir(const char* path);
  21. private:
  22. typedef void (*CompileFunction)(const char* path, CompileOptions& opts);
  23. void register_resource_compiler(StringId64 type, uint32_t version, CompileFunction compiler);
  24. void compile(StringId64 type, const char* path, CompileOptions& opts);
  25. // Returns the version of the compiler for @a type.
  26. uint32_t version(StringId64 type);
  27. private:
  28. DiskFilesystem _source_fs;
  29. DiskFilesystem _bundle_fs;
  30. struct ResourceTypeData
  31. {
  32. uint32_t version;
  33. CompileFunction compiler;
  34. };
  35. SortMap<StringId64, ResourceTypeData> _compilers;
  36. Vector<DynamicString> _files;
  37. };
  38. namespace bundle_compiler
  39. {
  40. bool main(bool do_compile, bool do_continue, const char* platform);
  41. } // namespace bundle_compiler
  42. namespace bundle_compiler_globals
  43. {
  44. /// Creates the global resource compiler.
  45. void init(const char* source_dir, const char* bundle_dir);
  46. /// Destroys the global resource compiler.
  47. void shutdown();
  48. /// Returns the global resource compiler.
  49. /// Returns NULL if the compiler is not available on the
  50. /// running platform.
  51. BundleCompiler* compiler();
  52. } // namespace bundle_compiler_globals
  53. } // namespace crown