| 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_SHARED_MAP_H |
| 4 | #define ENGINE_SHARED_MAP_H |
| 5 | |
| 6 | #include "datafile.h" |
| 7 | |
| 8 | #include <base/types.h> |
| 9 | |
| 10 | #include <engine/map.h> |
| 11 | |
| 12 | #include <set> |
| 13 | |
| 14 | class CMapItemLayerTilemap; |
| 15 | class CMapItemLayerTilemap_v2; |
| 16 | |
| 17 | class CMap : public IMap |
| 18 | { |
| 19 | CDataFileReader m_DataFile; |
| 20 | |
| 21 | public: |
| 22 | CMap(); |
| 23 | ~CMap() override; |
| 24 | |
| 25 | int GetDataSize(int Index) const override; |
| 26 | void *GetData(int Index) override; |
| 27 | void *GetDataSwapped(int Index) override; |
| 28 | const char *GetDataString(int Index) override; |
| 29 | void UnloadData(int Index) override; |
| 30 | int NumData() const override; |
| 31 | |
| 32 | int GetItemSize(int Index) override; |
| 33 | void *GetItem(int Index, int *pType = nullptr, int *pId = nullptr, CUuid *pUuid = nullptr) override; |
| 34 | void GetType(int Type, int *pStart, int *pNum) override; |
| 35 | int FindItemIndex(int Type, int Id) override; |
| 36 | void *FindItem(int Type, int Id) override; |
| 37 | int NumItems() const override; |
| 38 | |
| 39 | [[nodiscard]] bool Load(const char *pFullName, IStorage *pStorage, const char *pPath, int StorageType) override; |
| 40 | [[nodiscard]] bool Load(IStorage *pStorage, const char *pPath, int StorageType) override; |
| 41 | void Unload() override; |
| 42 | bool IsLoaded() const override; |
| 43 | IOHANDLE File() const override; |
| 44 | |
| 45 | const char *FullName() const override; |
| 46 | const char *BaseName() const override; |
| 47 | const char *Path() const override; |
| 48 | SHA256_DIGEST Sha256() const override; |
| 49 | unsigned Crc() const override; |
| 50 | int Size() const override; |
| 51 | |
| 52 | private: |
| 53 | static bool ValidateMapVersion(CDataFileReader &NewDataFile); |
| 54 | static bool (class CTile *pDest, size_t DestSize, const class CTile *pSrc, size_t SrcSize); |
| 55 | bool UpgradeAndValidateTilesLayerItem(CDataFileReader &NewDataFile, int GroupIndex, int LayerIndex, |
| 56 | CMapItemLayerTilemap_v2 *pLayerTilemapBase, int LayerItemIndex, size_t LayerItemSize); |
| 57 | bool ValidateAndUnpackTilesLayerData(CDataFileReader &NewDataFile, int GroupIndex, int LayerIndex, const CMapItemLayerTilemap *pLayerTilemap, |
| 58 | const CMapItemLayerTilemap &GameLayer, std::set<int> &UsedDataIndices); |
| 59 | }; |
| 60 | |
| 61 | #endif |
| 62 | |