unit_resource.cpp 852 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright (c) 2012-2016 Daniele Bartolini and individual contributors.
  3. * License: https://github.com/taylor001/crown/blob/master/LICENSE
  4. */
  5. #include "allocator.h"
  6. #include "file.h"
  7. #include "filesystem.h"
  8. #include "resource_types.h"
  9. #include "unit_compiler.h"
  10. namespace crown
  11. {
  12. namespace unit_resource_internal
  13. {
  14. void compile(const char* path, CompileOptions& opts)
  15. {
  16. Buffer unit_data(default_allocator());
  17. UnitCompiler uc(opts);
  18. uc.compile_unit(path);
  19. opts.write(uc.blob());
  20. }
  21. void* load(File& file, Allocator& a)
  22. {
  23. const u32 size = file.size();
  24. void* res = a.allocate(size);
  25. file.read(res, size);
  26. CE_ASSERT(*(u32*)res == RESOURCE_VERSION_UNIT, "Wrong version");
  27. return res;
  28. }
  29. void unload(Allocator& a, void* resource)
  30. {
  31. a.deallocate(resource);
  32. }
  33. } // namespace unit_resource_internal
  34. } // namespace crown