File: TileSet.h

package info (click to toggle)
jazz2-native 3.5.0-1
  • links: PTS, VCS
  • area: contrib
  • in suites:
  • size: 16,836 kB
  • sloc: cpp: 172,557; xml: 113; python: 36; makefile: 5; sh: 2
file content (95 lines) | stat: -rw-r--r-- 2,704 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#pragma once

#include "../../Main.h"

#include "../../nCine/Base/BitArray.h"
#include "../../nCine/Graphics/Texture.h"

#include <memory>

#include <Containers/ArrayView.h>
#include <Containers/String.h>
#include <Containers/StringView.h>

using namespace Death::Containers;
using namespace nCine;

namespace Jazz2::Tiles
{
	/** @brief Represents tile set used by tile map, consists of texture and collision mask */
	class TileSet
	{
	public:
		/** @brief Size of a tile */
		static constexpr std::int32_t DefaultTileSize = 32;

		TileSet(StringView path, std::uint16_t tileCount, std::unique_ptr<Texture> textureDiffuse, std::unique_ptr<std::uint8_t[]> mask, std::uint32_t maskSize, std::unique_ptr<Color[]> captionTile);

		/** @brief Relative path to source file */
		String FilePath;
		/** @brief Main (diffuse) texture */
		std::unique_ptr<Texture> TextureDiffuse;
		/** @brief Total number of tiles */
		std::int32_t TileCount;
		/** @brief Number of tiles per row */
		std::int32_t TilesPerRow;

		/** @brief Returns mask for specified tile */
		std::uint8_t* GetTileMask(std::int32_t tileId) const
		{
			if (tileId >= TileCount) {
				return nullptr;
			}

			return &_mask[tileId * DefaultTileSize * DefaultTileSize];
		}

		/** @brief Returns `true` if the mask of a tile is completely empty */
		bool IsTileMaskEmpty(std::int32_t tileId) const
		{
			if (tileId >= TileCount) {
				return true;
			}

			return _isMaskEmpty[tileId];
		}

		/** @brief Returns `true` if the mask of a tile is completely filled (non-empty) */
		bool IsTileMaskFilled(std::int32_t tileId) const
		{
			if (tileId >= TileCount) {
				return false;
			}

			return _isMaskFilled[tileId];
		}

		/** @brief Returns `true` if the texture of a tile is completely opaque (non-transparent) */
		bool IsTileFilled(std::int32_t tileId) const
		{
			if (tileId >= TileCount) {
				return false;
			}

			return _isTileFilled[tileId];
		}

		/** @brief Returns a caption tile */
		StaticArrayView<DefaultTileSize * DefaultTileSize, Color> GetCaptionTile() const
		{
			return staticArrayView<DefaultTileSize * DefaultTileSize>(_captionTile.get());
		}

		/** @brief Overrides the diffuse texture of the specified tile */
		bool OverrideTileDiffuse(std::int32_t tileId, StaticArrayView<(DefaultTileSize + 2) * (DefaultTileSize + 2), std::uint32_t> tileDiffuse);
		/** @brief Overrides the collision mask of the specified tile */
		bool OverrideTileMask(std::int32_t tileId, StaticArrayView<DefaultTileSize * DefaultTileSize, std::uint8_t> tileMask);

	private:
		std::unique_ptr<uint8_t[]> _mask;
		std::unique_ptr<Color[]> _captionTile;
		BitArray _isMaskEmpty;
		BitArray _isMaskFilled;
		BitArray _isTileFilled;
	};
}