summaryrefslogtreecommitdiffstats
path: root/src/ItemGrid.h
diff options
context:
space:
mode:
authorpeterbell10 <peterbell10@live.co.uk>2018-01-21 19:45:13 +0100
committerGitHub <noreply@github.com>2018-01-21 19:45:13 +0100
commitab350d1e43edef1a39f48d2771a9f136b3c4ae5f (patch)
treed0c89fd7b5a4dfc58999835074576175c72cee54 /src/ItemGrid.h
parentUpdate libevent to 2.1.8 (#4152) (diff)
downloadcuberite-ab350d1e43edef1a39f48d2771a9f136b3c4ae5f.tar
cuberite-ab350d1e43edef1a39f48d2771a9f136b3c4ae5f.tar.gz
cuberite-ab350d1e43edef1a39f48d2771a9f136b3c4ae5f.tar.bz2
cuberite-ab350d1e43edef1a39f48d2771a9f136b3c4ae5f.tar.lz
cuberite-ab350d1e43edef1a39f48d2771a9f136b3c4ae5f.tar.xz
cuberite-ab350d1e43edef1a39f48d2771a9f136b3c4ae5f.tar.zst
cuberite-ab350d1e43edef1a39f48d2771a9f136b3c4ae5f.zip
Diffstat (limited to 'src/ItemGrid.h')
-rw-r--r--src/ItemGrid.h21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/ItemGrid.h b/src/ItemGrid.h
index e744afd87..ee2dc79f3 100644
--- a/src/ItemGrid.h
+++ b/src/ItemGrid.h
@@ -9,6 +9,7 @@
#pragma once
#include "Item.h"
+#include "LazyArray.h"
@@ -33,12 +34,10 @@ public:
cItemGrid(int a_Width, int a_Height);
- ~cItemGrid();
-
// tolua_begin
int GetWidth (void) const { return m_Width; }
int GetHeight (void) const { return m_Height; }
- int GetNumSlots(void) const { return m_NumSlots; }
+ int GetNumSlots(void) const { return m_Slots.size(); }
/** Converts XY coords into slot number; returns -1 on invalid coords */
int GetSlotNum(int a_X, int a_Y) const;
@@ -49,7 +48,6 @@ public:
void GetSlotCoords(int a_SlotNum, int & a_X, int & a_Y) const;
/** Copies all items from a_Src to this grid.
- Both grids must be the same size (asserts).
Doesn't copy the listeners. */
void CopyFrom(const cItemGrid & a_Src);
@@ -84,21 +82,21 @@ public:
/** Adds as many items out of a_ItemStack as can fit.
If a_AllowNewStacks is set to false, only existing stacks can be topped up;
If a_AllowNewStacks is set to true, empty slots can be used for the rest.
- If a_PrioritarySlot is set to a positive value, then the corresponding slot will be used first (if empty or compatible with added items).
- If a_PrioritarySlot is set to -1, regular order applies.
+ If a_PrioritySlot is set to a positive value, then the corresponding slot will be used first (if empty or compatible with added items).
+ If a_PrioritySlot is set to -1, regular order applies.
Returns the number of items that fit.
*/
- int AddItem(cItem & a_ItemStack, bool a_AllowNewStacks = true, int a_PrioritarySlot = -1);
+ int AddItem(cItem & a_ItemStack, bool a_AllowNewStacks = true, int a_PrioritySlot = -1);
/** Same as AddItem, but works on an entire list of item stacks.
The a_ItemStackList is modified to reflect the leftover items.
If a_AllowNewStacks is set to false, only existing stacks can be topped up;
If a_AllowNewStacks is set to true, empty slots can be used for the rest.
- If a_PrioritarySlot is set to a positive value, then the corresponding slot will be used first (if empty or compatible with added items).
- If a_PrioritarySlot is set to -1, regular order applies.
+ If a_PrioritySlot is set to a positive value, then the corresponding slot will be used first (if empty or compatible with added items).
+ If a_PrioritySlot is set to -1, regular order applies.
Returns the total number of items that fit.
*/
- int AddItems(cItems & a_ItemStackList, bool a_AllowNewStacks = true, int a_PrioritarySlot = -1);
+ int AddItems(cItems & a_ItemStackList, bool a_AllowNewStacks = true, int a_PrioritySlot = -1);
/** Removes the specified item from the grid, as many as possible, up to a_ItemStack.m_ItemCount.
Returns the number of items that were removed. */
@@ -185,8 +183,7 @@ public:
protected:
int m_Width;
int m_Height;
- int m_NumSlots; // m_Width * m_Height, for easier validity checking in the access functions
- cItem * m_Slots; // x + m_Width * y
+ cLazyArray<cItem> m_Slots;
cListeners m_Listeners; ///< Listeners which should be notified on slot changes; the pointers are not owned by this object
cCriticalSection m_CSListeners; ///< CS that guards the m_Listeners against multi-thread access