ScriptResource.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <cassert>
  2. #include "ScriptResource.h"
  3. #include "ResourceArchive.h"
  4. #include "Log.h"
  5. #include "FileStream.h"
  6. #include "Allocator.h"
  7. namespace crown
  8. {
  9. //-----------------------------------------------------------------------------
  10. void* ScriptResource::load(Allocator& allocator, ResourceArchive& archive, ResourceId id)
  11. {
  12. FileStream* stream = archive.open(id);
  13. if (stream != NULL)
  14. {
  15. ScriptResource* resource = (ScriptResource*)allocator.allocate(sizeof(ScriptResource));
  16. stream->read(&resource->m_length, sizeof(uint32_t));
  17. size_t size = resource->m_length;
  18. resource->m_data = (uint8_t*)allocator.allocate(sizeof(uint8_t) * size);
  19. stream->read(resource->m_data, size);
  20. archive.close(stream);
  21. return resource;
  22. }
  23. return NULL;
  24. }
  25. //-----------------------------------------------------------------------------
  26. void ScriptResource::online(void* resource)
  27. {
  28. (void) resource;
  29. }
  30. //-----------------------------------------------------------------------------
  31. void ScriptResource::unload(Allocator& allocator, void* resource)
  32. {
  33. assert(resource != NULL);
  34. allocator.deallocate(((ScriptResource*)resource)->m_data);
  35. allocator.deallocate(resource);
  36. }
  37. //-----------------------------------------------------------------------------
  38. void ScriptResource::offline()
  39. {
  40. }
  41. } // namespace crown