diff options
author | Mattes D <github@xoft.cz> | 2020-01-03 17:31:13 +0100 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2020-01-07 06:53:17 +0100 |
commit | 4aef80b47eb6941d7fc41e57efe147af0ece1f9b (patch) | |
tree | 4aeb7c9e8e4aa3ae2ceed1cc60155d868852c5cd /src/Protocol/ProtocolPalettes.h | |
parent | StringUtils: Added note to StringsConcat about StringJoin. (diff) | |
download | cuberite-4aef80b47eb6941d7fc41e57efe147af0ece1f9b.tar cuberite-4aef80b47eb6941d7fc41e57efe147af0ece1f9b.tar.gz cuberite-4aef80b47eb6941d7fc41e57efe147af0ece1f9b.tar.bz2 cuberite-4aef80b47eb6941d7fc41e57efe147af0ece1f9b.tar.lz cuberite-4aef80b47eb6941d7fc41e57efe147af0ece1f9b.tar.xz cuberite-4aef80b47eb6941d7fc41e57efe147af0ece1f9b.tar.zst cuberite-4aef80b47eb6941d7fc41e57efe147af0ece1f9b.zip |
Diffstat (limited to 'src/Protocol/ProtocolPalettes.h')
-rw-r--r-- | src/Protocol/ProtocolPalettes.h | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/Protocol/ProtocolPalettes.h b/src/Protocol/ProtocolPalettes.h new file mode 100644 index 000000000..fad093a04 --- /dev/null +++ b/src/Protocol/ProtocolPalettes.h @@ -0,0 +1,63 @@ +#pragma once + +#include "../OSSupport/CriticalSection.h" + + + + + +// fwd: +class BlockTypePalette; + + + + + +/** Loads the protocol-specific palettes on startup and provides them to the individual protocol +instances when they are created. +Uses the data in the $/Server/Protocol folder. Each protocol version has a subfolder there, +containing possibly multiple palette files. All the files are loaded in sequence (alpha-sorted), +into the palette corresponding to the file's extension (*.btp.txt -> BlockTypePalette). +Provides thread safety for the data properly. */ +class ProtocolPalettes +{ +public: + + /** Loads all the per-protocol palettes. + aProtocolFolder is the folder that contains a subfolder for each protocol version; + each subfolder contains the protocol-specific palettes (as in $/Server/Protocol) + If a protocol version is already loaded, yet present in the folder, the newly loaded data is merged + into the current data. + Always succeeds (even when there are no palettes). */ + void load(const AString & aProtocolFolder); + + /** Returns the BlockTypePalette for the specified protocol. + Returns nullptr if no such palette has been loaded. */ + std::shared_ptr<const BlockTypePalette> blockTypePalette(const AString & aProtocolVersion) const; + + /** Returns the version names of all protocols that have been loaded. */ + std::vector<AString> protocolVersions() const; + + +protected: + + /** Container for all palettes for a single protocol. */ + struct Palettes + { + std::shared_ptr<BlockTypePalette> mBlockTypePalette; + // TODO: ItemTypePalette + + Palettes(); + }; + + + /** The CS protecting all members against multithreaded access. */ + mutable cCriticalSection mCS; + + /** The map of protocol version -> all its palettes. */ + std::map<AString, Palettes> mPalettes; + + + /** Loads all the palettes from the specified folder into mPalettes under the aProtocolVersion key. */ + void loadSingleVersion(const AString & aProtocolVersion, const AString & aFolder); +}; |