freg  0.3
Free-Roaming Elementary Game
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
BlockManager Class Referencefinal

This class is used for creating and deleting blocks, also for loading them from file. More...

#include <BlockManager.h>

Collaboration diagram for BlockManager:
Collaboration graph
[legend]

Public Member Functions

 BlockManager ()
 
 ~BlockManager ()
 
BlockNormal (int sub) const
 Use this to receive a pointer to normal block. More...
 
void DeleteBlock (Block *) const
 Does not actually delete normal blocks. More...
 
BlockReplaceWithNormal (Block *block) const
 For memory economy. More...
 

Static Public Member Functions

static BlockNewBlock (int kind, int sub)
 Use this to receive a pointer to new not-normal block. More...
 
static BlockBlockFromFile (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
 
BlockManageroperator= (const BlockManager &)=delete
 

Private Attributes

Blocknormals [LAST_SUB]
 

Static Private Attributes

static const QByteArray kinds []
 
static const QByteArray subs []
 

Detailed Description

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.

Constructor & Destructor Documentation

BlockManager::BlockManager ( )

Definition at line 119 of file BlockManager.cpp.

BlockManager::~BlockManager ( )

Definition at line 137 of file BlockManager.cpp.

BlockManager::BlockManager ( const BlockManager )
privatedelete

Member Function Documentation

Block * BlockManager::BlockFromFile ( QDataStream &  str,
int  kind,
int  sub 
)
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.

bool BlockManager::IsValid ( int  kind,
int  sub 
)
static

Definition at line 285 of file BlockManager.cpp.

int BlockManager::KindFromId ( int  id)
static

Definition at line 282 of file BlockManager.cpp.

bool BlockManager::KindSubFromFile ( QDataStream &  str,
quint8 *  kind,
quint8 *  sub 
)
static

Returns true if block is normal.

Definition at line 233 of file BlockManager.cpp.

QString BlockManager::KindToString ( int  kind)
static

If kind is unknown, returns "unknown_kind".

Definition at line 257 of file BlockManager.cpp.

static constexpr int BlockManager::MakeId ( const int  kind,
const int  sub 
)
inlinestatic

Definition at line 72 of file BlockManager.h.

Block * BlockManager::NewBlock ( int  kind,
int  sub 
)
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.

BlockManager& BlockManager::operator= ( const BlockManager )
privatedelete
Block * BlockManager::ReplaceWithNormal ( Block block) const

For memory economy.

Checks and replaces block with corresponding normal block. Can delete block, use carefully.

Definition at line 272 of file BlockManager.cpp.

int BlockManager::StringToKind ( QString  str)
static

If string is not convertible to kind, returns LAST_KIND.

Definition at line 260 of file BlockManager.cpp.

int BlockManager::StringToSub ( QString  str)
static

If string is not convertible to substance, returns LAST_SUB.

Definition at line 266 of file BlockManager.cpp.

int BlockManager::SubFromId ( int  id)
static

Definition at line 283 of file BlockManager.cpp.

QString BlockManager::SubToString ( int  sub)
static

If substance is unknown, returns "unknown_sub".

Definition at line 258 of file BlockManager.cpp.

Member Data Documentation

const QByteArray BlockManager::kinds
staticprivate

Definition at line 86 of file BlockManager.h.

Block* BlockManager::normals[LAST_SUB]
private

Definition at line 85 of file BlockManager.h.

const QByteArray BlockManager::subs
staticprivate

Definition at line 87 of file BlockManager.h.


The documentation for this class was generated from the following files: