collection.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #pragma once
  2. #include "filemap.h"
  3. #include <stddef.h>
  4. struct IFile {
  5. size_t size;
  6. /* read size bytes into buffer
  7. * returns bytes read, or < 0 on error. error codes aren't specified */
  8. size_t (*read)(struct IFile *file, size_t offset, size_t size, void *buffer);
  9. /* free any internal resources.
  10. * will not free memory associated with this structure itself */
  11. void (*close)();
  12. };
  13. enum CollectionOpenResult {
  14. CollectionOpen_Success,
  15. CollectionOpen_NotFound, /* such item was not found in collection */
  16. CollectionOpen_TooManyFiles, /* collection limit on open files exceeded (regardless of was the item found or not) */
  17. CollectionOpen_Internal /* collection data is inconsistent internally, e.g. corrupted archive */
  18. };
  19. enum FileType {
  20. File_Map,
  21. File_Material,
  22. File_Texture,
  23. File_Model
  24. };
  25. struct ICollection {
  26. /* free any internal resources, but don't deallocate this structure itself */
  27. void (*close)();
  28. enum CollectionOpenResult (*open)(struct ICollection *collection,
  29. const char *name, enum FileType type, struct IFile **out_file);
  30. struct ICollection *next;
  31. };
  32. enum CollectionOpenResult collectionChainOpen(struct ICollection *collection,
  33. const char *name, enum FileType type, struct IFile **out_file);
  34. #define FilesystemCollectionFileSlots 16
  35. struct FilesystemCollectionFile_ {
  36. struct IFile head;
  37. struct AFile file;
  38. int opened;
  39. };
  40. struct FilesystemCollection {
  41. struct ICollection head;
  42. char path[256];
  43. struct FilesystemCollectionFile_ files[FilesystemCollectionFileSlots];
  44. };
  45. void filesystemCollectionCreate(struct FilesystemCollection *collection, const char *dir);