summaryrefslogtreecommitdiffstats
path: root/src/BlockTypePalette.h
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2019-08-28 08:29:02 +0200
committerGitHub <noreply@github.com>2019-08-28 08:29:02 +0200
commit2504538a3a164f27a96f413f5b389f8dad6b2cac (patch)
treee3478f6779a4dab9ed835edea23c83d1a019a31b /src/BlockTypePalette.h
parentImproved testing framework. (#4376) (diff)
downloadcuberite-2504538a3a164f27a96f413f5b389f8dad6b2cac.tar
cuberite-2504538a3a164f27a96f413f5b389f8dad6b2cac.tar.gz
cuberite-2504538a3a164f27a96f413f5b389f8dad6b2cac.tar.bz2
cuberite-2504538a3a164f27a96f413f5b389f8dad6b2cac.tar.lz
cuberite-2504538a3a164f27a96f413f5b389f8dad6b2cac.tar.xz
cuberite-2504538a3a164f27a96f413f5b389f8dad6b2cac.tar.zst
cuberite-2504538a3a164f27a96f413f5b389f8dad6b2cac.zip
Diffstat (limited to 'src/BlockTypePalette.h')
-rw-r--r--src/BlockTypePalette.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/BlockTypePalette.h b/src/BlockTypePalette.h
new file mode 100644
index 000000000..47318f171
--- /dev/null
+++ b/src/BlockTypePalette.h
@@ -0,0 +1,44 @@
+#pragma once
+
+#include <utility>
+#include "BlockState.h"
+
+
+
+
+
+/** Holds a palette that maps block type + state into numbers.
+Used primarily by PalettedBlockArea to translate between numeric and stringular block representation.
+The object itself provides no thread safety, users of this class need to handle locking, if required. */
+class BlockTypePalette
+{
+public:
+
+ /** Create a new empty instance. */
+ BlockTypePalette();
+
+ /** Returns the index of the specified block type name and state.
+ If the combination is not found, it is added to the palette and the new index is returned. */
+ UInt32 index(const AString & aBlockTypeName, const BlockState & aBlockState);
+
+ /** Returns the <index, true> of the specified block type name and state, if it exists.
+ If the combination is not found, returns <undefined, false>. */
+ std::pair<UInt32, bool> maybeIndex(const AString & aBlockTypeName, const BlockState & aBlockState) const;
+
+ /** Returns the total number of entries in the palette. */
+ UInt32 count() const;
+
+ /** Returns the blockspec represented by the specified palette index.
+ The index must be valid (ASSERTed). */
+ const std::pair<AString, BlockState> & entry(UInt32 aIndex) const;
+
+ /** Adds missing entries from aOther to this, and returns an index-transform map from aOther to this.
+ Used when pasting two areas, to transform the src palette to dst palette. */
+ std::map<UInt32, UInt32> createTransformMap(const BlockTypePalette & aOther);
+
+
+protected:
+
+ /** The palette. Each item in the vector represents a single entry in the palette, the vector index is the palette index. */
+ std::vector<std::pair<AString, BlockState>> mPalette;
+};