collection.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #pragma once
  2. #include "filemap.h"
  3. #include "mempools.h"
  4. #include <stddef.h>
  5. typedef struct IFile {
  6. size_t size;
  7. /* read size bytes into buffer
  8. * returns bytes read, or < 0 on error. error codes aren't specified */
  9. size_t (*read)(struct IFile *file, size_t offset, size_t size, void *buffer);
  10. /* free any internal resources.
  11. * will not free memory associated with this structure itself */
  12. void (*close)(struct IFile *file);
  13. } IFile;
  14. enum CollectionOpenResult {
  15. CollectionOpen_Success,
  16. CollectionOpen_NotFound, /* such item was not found in collection */
  17. CollectionOpen_NotEnoughMemory,
  18. CollectionOpen_Internal /* collection data is inconsistent internally, e.g. corrupted archive */
  19. };
  20. enum FileType {
  21. File_Map,
  22. File_Material,
  23. File_Texture,
  24. File_Model
  25. };
  26. typedef struct ICollection {
  27. /* free any internal resources, but don't deallocate this structure itself */
  28. void (*close)(struct ICollection *collection);
  29. enum CollectionOpenResult (*open)(struct ICollection *collection,
  30. const char *name, enum FileType type, struct IFile **out_file);
  31. struct ICollection *next;
  32. } ICollection;
  33. enum CollectionOpenResult collectionChainOpen(struct ICollection *collection,
  34. const char *name, enum FileType type, struct IFile **out_file);
  35. struct ICollection *collectionCreateFilesystem(struct Memories *mem, const char *dir);
  36. struct ICollection *collectionCreateVPK(struct Memories *mem, const char *dir_filename);
  37. struct ICollection *collectionCreatePakfile(struct Memories *mem, const void *pakfile, uint32_t size);