Game Development Reference
In-Depth Information
slot()
: m_count(0)
, m_maximum(0)
{}
int& Count() { return m_count; }
int& Maximum() { return m_maximum; }
int Count() const { return m_count; }
int Maximum() const { return m_maximum; }
protected:
int m_count;
int m_maximum;
};
Theclass slot willserveasthebaseclassforaversionoftheclassthatwillalsocontainthe
instance of the grid's parameter T .
class slot_item : public slot
{
public:
slot_item()
: slot()
{}
slot_item(T&& item)
{
m_item = std::move(item.Item());
}
slot_item& operator = (slot_item&& rhs)
{
if ( &rhs != this )
{
m_item = std::move(rhs.Item());
}
return *this;
}
T& Item() { return m_item; }
static slot_item Empty;
protected:
T m_item;
};
The slot_item class is defined within the grid class, this allows us to use the T parameter to
store the data for a given slot. When we store things in the grid, we will move the data into
the grid. This simplifies certain grid operations, such as swapping between grid slots.
A swap operation between two slots can be performed with moves.
Search WWH ::




Custom Search