ScriptResource.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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.find(id);
  13. if (stream != NULL)
  14. {
  15. ScriptResource* resource = (ScriptResource*)allocator.allocate(sizeof(ScriptResource));
  16. size_t size = stream->size() - stream->position();
  17. resource->m_data = (uint8_t*)allocator.allocate(sizeof(uint8_t) * size);
  18. stream->read(resource->m_data, size);
  19. return resource;
  20. }
  21. return NULL;
  22. }
  23. //-----------------------------------------------------------------------------
  24. void ScriptResource::online(void* resource)
  25. {
  26. (void) resource;
  27. }
  28. //-----------------------------------------------------------------------------
  29. void ScriptResource::unload(Allocator& allocator, void* resource)
  30. {
  31. assert(resource != NULL);
  32. allocator.deallocate(((ScriptResource*)resource)->m_data);
  33. allocator.deallocate(resource);
  34. }
  35. //-----------------------------------------------------------------------------
  36. void ScriptResource::offline()
  37. {
  38. }
  39. } // namespace crown