freg
0.3
Free-Roaming Elementary Game
|
This class is used for creating and deleting blocks, also for loading them from file. More...
#include <BlockManager.h>
Public Member Functions | |
BlockManager () | |
~BlockManager () | |
Block * | Normal (int sub) const |
Use this to receive a pointer to normal block. More... | |
void | DeleteBlock (Block *) const |
Does not actually delete normal blocks. More... | |
Block * | ReplaceWithNormal (Block *block) const |
For memory economy. More... | |
Static Public Member Functions | |
static Block * | NewBlock (int kind, int sub) |
Use this to receive a pointer to new not-normal block. More... | |
static Block * | BlockFromFile (QDataStream &, int kind, int sub) |
Use this to load block from file. More... | |
static bool | KindSubFromFile (QDataStream &, quint8 *kind, quint8 *sub) |
Returns true if block is normal. More... | |
static QString | KindToString (int kind) |
If kind is unknown, returns "unknown_kind". More... | |
static QString | SubToString (int sub) |
If substance is unknown, returns "unknown_sub". More... | |
static int | StringToKind (QString) |
If string is not convertible to kind, returns LAST_KIND. More... | |
static int | StringToSub (QString) |
If string is not convertible to substance, returns LAST_SUB. More... | |
static constexpr int | MakeId (const int kind, const int sub) |
static int | KindFromId (int id) |
static int | SubFromId (int id) |
static bool | IsValid (int kind, int sub) |
Private Member Functions | |
BlockManager (const BlockManager &)=delete | |
BlockManager & | operator= (const BlockManager &)=delete |
Private Attributes | |
Block * | normals [LAST_SUB] |
Static Private Attributes | |
static const QByteArray | kinds [] |
static const QByteArray | subs [] |
This class is used for creating and deleting blocks, also for loading them from file.
Memory management, if any, should be implemented in this class. At the current moment no special memory management is used.
Normal blocks: blocks that are not special, e.g. usual stone, air, soil are actually one block (for each substance). One can receive a pointer to such block with Block * Normal(int sub). Normal blocks are not needed to be deleted. Use Block * NewBlock(int kind, int sub) to receive a pointer to block that will be changed (damaged, inscribed, etc).
Definition at line 43 of file BlockManager.h.
BlockManager::BlockManager | ( | ) |
Definition at line 119 of file BlockManager.cpp.
BlockManager::~BlockManager | ( | ) |
Definition at line 137 of file BlockManager.cpp.
|
privatedelete |
|
static |
Use this to load block from file.
Definition at line 188 of file BlockManager.cpp.
void BlockManager::DeleteBlock | ( | Block * | block | ) | const |
Does not actually delete normal blocks.
Definition at line 247 of file BlockManager.cpp.
|
static |
Definition at line 285 of file BlockManager.cpp.
|
static |
Definition at line 282 of file BlockManager.cpp.
|
static |
Returns true if block is normal.
Definition at line 233 of file BlockManager.cpp.
|
static |
If kind is unknown, returns "unknown_kind".
Definition at line 257 of file BlockManager.cpp.
|
inlinestatic |
Definition at line 72 of file BlockManager.h.
|
static |
Use this to receive a pointer to new not-normal block.
Definition at line 145 of file BlockManager.cpp.
Block * BlockManager::Normal | ( | int | sub | ) | const |
Use this to receive a pointer to normal block.
Definition at line 143 of file BlockManager.cpp.
|
privatedelete |
For memory economy.
Checks and replaces block with corresponding normal block. Can delete block, use carefully.
Definition at line 272 of file BlockManager.cpp.
|
static |
If string is not convertible to kind, returns LAST_KIND.
Definition at line 260 of file BlockManager.cpp.
|
static |
If string is not convertible to substance, returns LAST_SUB.
Definition at line 266 of file BlockManager.cpp.
|
static |
Definition at line 283 of file BlockManager.cpp.
|
static |
If substance is unknown, returns "unknown_sub".
Definition at line 258 of file BlockManager.cpp.
|
staticprivate |
Definition at line 86 of file BlockManager.h.
Definition at line 85 of file BlockManager.h.
|
staticprivate |
Definition at line 87 of file BlockManager.h.