| 1 | /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ |
| 2 | /* If you are missing that file, acquire a complete release at teeworlds.com. */ |
| 3 | #ifndef ENGINE_MAP_H |
| 4 | #define ENGINE_MAP_H |
| 5 | |
| 6 | #include <base/hash.h> |
| 7 | #include <base/types.h> |
| 8 | |
| 9 | #include <memory> |
| 10 | |
| 11 | class IStorage; |
| 12 | |
| 13 | enum |
| 14 | { |
| 15 | MAX_MAP_LENGTH = 128 |
| 16 | }; |
| 17 | |
| 18 | class IMap |
| 19 | { |
| 20 | public: |
| 21 | virtual ~IMap() = default; |
| 22 | |
| 23 | virtual int GetDataSize(int Index) const = 0; |
| 24 | virtual void *GetData(int Index) = 0; |
| 25 | virtual void *GetDataSwapped(int Index) = 0; |
| 26 | virtual const char *GetDataString(int Index) = 0; |
| 27 | virtual void UnloadData(int Index) = 0; |
| 28 | virtual int NumData() const = 0; |
| 29 | |
| 30 | virtual int GetItemSize(int Index) = 0; |
| 31 | virtual void *GetItem(int Index, int *pType = nullptr, int *pId = nullptr) = 0; |
| 32 | virtual void GetType(int Type, int *pStart, int *pNum) = 0; |
| 33 | virtual int FindItemIndex(int Type, int Id) = 0; |
| 34 | virtual void *FindItem(int Type, int Id) = 0; |
| 35 | virtual int NumItems() const = 0; |
| 36 | |
| 37 | [[nodiscard]] virtual bool Load(const char *pFullName, IStorage *pStorage, const char *pPath, int StorageType) = 0; |
| 38 | [[nodiscard]] virtual bool Load(IStorage *pStorage, const char *pPath, int StorageType) = 0; |
| 39 | virtual void Unload() = 0; |
| 40 | virtual bool IsLoaded() const = 0; |
| 41 | virtual IOHANDLE File() const = 0; |
| 42 | |
| 43 | /** |
| 44 | * Returns the full name of the currently loaded map. |
| 45 | * |
| 46 | * @return Full map name, e.g. `subfolder1/subfolder2/my_map`. |
| 47 | */ |
| 48 | virtual const char *FullName() const = 0; |
| 49 | /** |
| 50 | * Returns the base name of the currently loaded map. |
| 51 | * |
| 52 | * @return Base map name, e.g. `my_map`. |
| 53 | */ |
| 54 | virtual const char *BaseName() const = 0; |
| 55 | /** |
| 56 | * Returns the path of the currently loaded map. |
| 57 | * |
| 58 | * @return Map path, e.g. `maps/subfolder1/subfolder2/my_map.map`. |
| 59 | */ |
| 60 | virtual const char *Path() const = 0; |
| 61 | virtual SHA256_DIGEST Sha256() const = 0; |
| 62 | virtual unsigned Crc() const = 0; |
| 63 | virtual int Size() const = 0; |
| 64 | }; |
| 65 | |
| 66 | extern std::unique_ptr<IMap> CreateMap(); |
| 67 | |
| 68 | #endif |
| 69 | |