Allocate item cells for PCs only

CHARACTER_POINT_INSTANT carried the inventory/equipment, dragon soul and
special storage cells (~13 KB) in every CHARACTER, mobs and NPCs included.
They now live in CHARACTER_ITEM_CELLS, allocated in Create(isPC) and freed
in Destroy(); non-PCs read a shared empty set. On channel1/game2's maps a
core drops from 522/442 MB VSZ/RSS to 177/159 MB (live 275c7e52: 341/301).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-24 22:08:16 +09:00
co-authored by Claude Opus 5.5
parent 96f8486306
commit 30ea96f418
4 changed files with 106 additions and 75 deletions
+9
View File
@@ -439,7 +439,10 @@ void CHARACTER::Create(const char * c_pszName, DWORD vid, bool isPC)
m_vid = VID(vid, GetCRC32(crc_string, strlen(crc_string)));
if (isPC)
{
m_stName = c_pszName;
m_pointsInstant.pItemCells = M2_NEW CHARACTER_ITEM_CELLS();
}
}
void CHARACTER::Destroy()
@@ -624,6 +627,12 @@ void CHARACTER::Destroy()
if (m_bMonsterLog)
CHARACTER_MANAGER::instance().UnregisterForMonsterLog(this);
if (m_pointsInstant.pItemCells)
{
M2_DELETE(m_pointsInstant.pItemCells);
m_pointsInstant.pItemCells = NULL;
}
}
const char * CHARACTER::GetName() const
+27 -19
View File
@@ -433,6 +433,31 @@ typedef struct character_point
BYTE skill_group;
} CHARACTER_POINT;
// MT: the inventory/equipment, dragon soul and special storage cells used to sit in every CHARACTER
// (~13 KB). Mobs and NPCs never hold items, so only PCs allocate them; a core keeps ~20k mobs alive.
typedef struct character_item_cells
{
LPITEM pItems[INVENTORY_AND_EQUIP_SLOT_MAX];
WORD bItemGrid[INVENTORY_AND_EQUIP_SLOT_MAX]; // MT: BYTE in 40250; holds cell + 1, and cells reach 302
// 용혼석 인벤토리.
LPITEM pDSItems[DRAGON_SOUL_INVENTORY_MAX_NUM];
WORD wDSItemGrid[DRAGON_SOUL_INVENTORY_MAX_NUM];
#ifdef ENABLE_SPECIAL_STORAGE
LPITEM pSSUItems[SPECIAL_INVENTORY_MAX_NUM];
WORD wSSUItemGrid[SPECIAL_INVENTORY_MAX_NUM];
LPITEM pSSBItems[SPECIAL_INVENTORY_MAX_NUM];
WORD wSSBItemGrid[SPECIAL_INVENTORY_MAX_NUM];
LPITEM pSSSItems[SPECIAL_INVENTORY_MAX_NUM];
WORD wSSSItemGrid[SPECIAL_INVENTORY_MAX_NUM];
LPITEM pSSCItems[SPECIAL_INVENTORY_MAX_NUM];
WORD wSSCItemGrid[SPECIAL_INVENTORY_MAX_NUM];
LPITEM pCostumeItems[SPECIAL_INVENTORY_MAX_NUM];
WORD wCostumeItemGrid[SPECIAL_INVENTORY_MAX_NUM];
#endif
} CHARACTER_ITEM_CELLS;
/* 저장되지 않는 캐릭터 데이터 */
typedef struct character_point_instant
{
@@ -452,28 +477,10 @@ typedef struct character_point_instant
WORD parts[PART_MAX_NUM];
LPITEM pItems[INVENTORY_AND_EQUIP_SLOT_MAX];
WORD bItemGrid[INVENTORY_AND_EQUIP_SLOT_MAX]; // MT: BYTE in 40250; holds cell + 1, and cells reach 302
// 용혼석 인벤토리.
LPITEM pDSItems[DRAGON_SOUL_INVENTORY_MAX_NUM];
WORD wDSItemGrid[DRAGON_SOUL_INVENTORY_MAX_NUM];
CHARACTER_ITEM_CELLS* pItemCells; // MT: PCs only (CHARACTER::Create); mobs/NPCs read the shared empty set
LPITEM pSwitchbotItems[SWITCHBOT_SLOT_COUNT]; // PORT: AVA2 switchbot window (port_switchbot.cpp)
#ifdef ENABLE_SPECIAL_STORAGE
LPITEM pSSUItems[SPECIAL_INVENTORY_MAX_NUM];
WORD wSSUItemGrid[SPECIAL_INVENTORY_MAX_NUM];
LPITEM pSSBItems[SPECIAL_INVENTORY_MAX_NUM];
WORD wSSBItemGrid[SPECIAL_INVENTORY_MAX_NUM];
LPITEM pSSSItems[SPECIAL_INVENTORY_MAX_NUM];
WORD wSSSItemGrid[SPECIAL_INVENTORY_MAX_NUM];
LPITEM pSSCItems[SPECIAL_INVENTORY_MAX_NUM];
WORD wSSCItemGrid[SPECIAL_INVENTORY_MAX_NUM];
LPITEM pCostumeItems[SPECIAL_INVENTORY_MAX_NUM];
WORD wCostumeItemGrid[SPECIAL_INVENTORY_MAX_NUM];
#endif
// by mhh
LPITEM pCubeItems[CUBE_MAX_NUM];
LPCHARACTER pCubeNpc;
@@ -1180,6 +1187,7 @@ class CHARACTER : public CEntity, public CFSM, public CHorseRider
bool PortCubeInstallImage(const PortCube::InventoryImage&,const std::vector<LPITEM>& before,const std::vector<LPITEM>& restored);
bool PortCubePublishFrame(const PortCubeView::Frame&,const PortCubeView::Frame& original);
LPITEM GetItem(TItemPos Cell) const;
const CHARACTER_ITEM_CELLS& ItemCells() const;
LPITEM GetInventoryItem(WORD wCell) const;
#ifdef ENABLE_SPECIAL_STORAGE
LPITEM GetUpgradeInventoryItem(WORD wCell) const;
+65 -52
View File
@@ -267,6 +267,12 @@ LPITEM CHARACTER::GetCostumeInventoryItem(WORD wCell) const
return GetItem(TItemPos(COSTUME_INVENTORY, wCell));
}
#endif
const CHARACTER_ITEM_CELLS& CHARACTER::ItemCells() const
{
static const CHARACTER_ITEM_CELLS s_empty = {};
return m_pointsInstant.pItemCells ? *m_pointsInstant.pItemCells : s_empty;
}
LPITEM CHARACTER::GetItem(TItemPos Cell) const
{
if (!IsValidItemPosition(Cell))
@@ -282,14 +288,14 @@ LPITEM CHARACTER::GetItem(TItemPos Cell) const
sys_err("CHARACTER::GetInventoryItem: invalid item cell %d", wCell);
return NULL;
}
return m_pointsInstant.pItems[wCell];
return ItemCells().pItems[wCell];
case DRAGON_SOUL_INVENTORY:
if (wCell >= DRAGON_SOUL_INVENTORY_MAX_NUM)
{
sys_err("CHARACTER::GetInventoryItem: invalid DS item cell %d", wCell);
return NULL;
}
return m_pointsInstant.pDSItems[wCell];
return ItemCells().pDSItems[wCell];
// PORT: AVA2 ENABLE_SWITCHBOT window (port_switchbot.cpp).
case SWITCHBOT:
if (wCell >= SWITCHBOT_SLOT_COUNT)
@@ -306,35 +312,35 @@ LPITEM CHARACTER::GetItem(TItemPos Cell) const
sys_err("CHARACTER::GetInventoryItem: invalid SSU item cell %d", wCell);
return NULL;
}
return m_pointsInstant.pSSUItems[wCell];
return ItemCells().pSSUItems[wCell];
case BOOK_INVENTORY:
if (wCell >= SPECIAL_INVENTORY_MAX_NUM)
{
sys_err("CHARACTER::GetInventoryItem: invalid SSB item cell %d", wCell);
return NULL;
}
return m_pointsInstant.pSSBItems[wCell];
return ItemCells().pSSBItems[wCell];
case STONE_INVENTORY:
if (wCell >= SPECIAL_INVENTORY_MAX_NUM)
{
sys_err("CHARACTER::GetInventoryItem: invalid SSS item cell %d", wCell);
return NULL;
}
return m_pointsInstant.pSSSItems[wCell];
return ItemCells().pSSSItems[wCell];
case CHANGE_INVENTORY:
if (wCell >= SPECIAL_INVENTORY_MAX_NUM)
{
sys_err("CHARACTER::GetInventoryItem: invalid SSC item cell %d", wCell);
return NULL;
}
return m_pointsInstant.pSSCItems[wCell];
return ItemCells().pSSCItems[wCell];
case COSTUME_INVENTORY:
if (wCell >= SPECIAL_INVENTORY_MAX_NUM)
{
sys_err("CHARACTER::GetInventoryItem: invalid Costume item cell %d", wCell);
return NULL;
}
return m_pointsInstant.pCostumeItems[wCell];
return ItemCells().pCostumeItems[wCell];
#endif
default:
@@ -359,6 +365,13 @@ void CHARACTER::SetItem(TItemPos Cell, LPITEM pItem)
assert(!"GetOwner exist");
return;
}
CHARACTER_ITEM_CELLS* cells = m_pointsInstant.pItemCells;
if (!cells && window_type != SWITCHBOT)
{
if (pItem)
sys_err("CHARACTER::SetItem: %s is not a PC (window %u cell %u)", GetName(), window_type, wCell);
return;
}
// 기본 인벤토리
switch(window_type)
{
@@ -371,7 +384,7 @@ void CHARACTER::SetItem(TItemPos Cell, LPITEM pItem)
return;
}
LPITEM pOld = m_pointsInstant.pItems[wCell];
LPITEM pOld = cells->pItems[wCell];
if (pOld)
{
@@ -384,14 +397,14 @@ void CHARACTER::SetItem(TItemPos Cell, LPITEM pItem)
if (p >= INVENTORY_MAX_NUM)
continue;
if (m_pointsInstant.pItems[p] && m_pointsInstant.pItems[p] != pOld)
if (cells->pItems[p] && cells->pItems[p] != pOld)
continue;
m_pointsInstant.bItemGrid[p] = 0;
cells->bItemGrid[p] = 0;
}
}
else
m_pointsInstant.bItemGrid[wCell] = 0;
cells->bItemGrid[wCell] = 0;
}
if (pItem)
@@ -407,20 +420,20 @@ void CHARACTER::SetItem(TItemPos Cell, LPITEM pItem)
// wCell + 1 로 하는 것은 빈곳을 체크할 때 같은
// 아이템은 예외처리하기 위함
m_pointsInstant.bItemGrid[p] = wCell + 1;
cells->bItemGrid[p] = wCell + 1;
}
}
else
m_pointsInstant.bItemGrid[wCell] = wCell + 1;
cells->bItemGrid[wCell] = wCell + 1;
}
m_pointsInstant.pItems[wCell] = pItem;
cells->pItems[wCell] = pItem;
}
break;
// 용혼석 인벤토리
case DRAGON_SOUL_INVENTORY:
{
LPITEM pOld = m_pointsInstant.pDSItems[wCell];
LPITEM pOld = cells->pDSItems[wCell];
if (pOld)
{
@@ -433,14 +446,14 @@ void CHARACTER::SetItem(TItemPos Cell, LPITEM pItem)
if (p >= DRAGON_SOUL_INVENTORY_MAX_NUM)
continue;
if (m_pointsInstant.pDSItems[p] && m_pointsInstant.pDSItems[p] != pOld)
if (cells->pDSItems[p] && cells->pDSItems[p] != pOld)
continue;
m_pointsInstant.wDSItemGrid[p] = 0;
cells->wDSItemGrid[p] = 0;
}
}
else
m_pointsInstant.wDSItemGrid[wCell] = 0;
cells->wDSItemGrid[wCell] = 0;
}
if (pItem)
@@ -462,14 +475,14 @@ void CHARACTER::SetItem(TItemPos Cell, LPITEM pItem)
// wCell + 1 로 하는 것은 빈곳을 체크할 때 같은
// 아이템은 예외처리하기 위함
m_pointsInstant.wDSItemGrid[p] = wCell + 1;
cells->wDSItemGrid[p] = wCell + 1;
}
}
else
m_pointsInstant.wDSItemGrid[wCell] = wCell + 1;
cells->wDSItemGrid[wCell] = wCell + 1;
}
m_pointsInstant.pDSItems[wCell] = pItem;
cells->pDSItems[wCell] = pItem;
}
break;
case SWITCHBOT:
@@ -511,17 +524,17 @@ void CHARACTER::SetItem(TItemPos Cell, LPITEM pItem)
return;
}
LPITEM* pItemArray = (window_type == UPGRADE_INVENTORY) ? m_pointsInstant.pSSUItems :
(window_type == BOOK_INVENTORY) ? m_pointsInstant.pSSBItems :
(window_type == STONE_INVENTORY) ? m_pointsInstant.pSSSItems :
(window_type == CHANGE_INVENTORY) ? m_pointsInstant.pSSCItems :
m_pointsInstant.pCostumeItems;
LPITEM* pItemArray = (window_type == UPGRADE_INVENTORY) ? cells->pSSUItems :
(window_type == BOOK_INVENTORY) ? cells->pSSBItems :
(window_type == STONE_INVENTORY) ? cells->pSSSItems :
(window_type == CHANGE_INVENTORY) ? cells->pSSCItems :
cells->pCostumeItems;
WORD* pGridArray = (window_type == UPGRADE_INVENTORY) ? m_pointsInstant.wSSUItemGrid :
(window_type == BOOK_INVENTORY) ? m_pointsInstant.wSSBItemGrid :
(window_type == STONE_INVENTORY) ? m_pointsInstant.wSSSItemGrid :
(window_type == CHANGE_INVENTORY) ? m_pointsInstant.wSSCItemGrid :
m_pointsInstant.wCostumeItemGrid;
WORD* pGridArray = (window_type == UPGRADE_INVENTORY) ? cells->wSSUItemGrid :
(window_type == BOOK_INVENTORY) ? cells->wSSBItemGrid :
(window_type == STONE_INVENTORY) ? cells->wSSSItemGrid :
(window_type == CHANGE_INVENTORY) ? cells->wSSCItemGrid :
cells->wCostumeItemGrid;
LPITEM pOld = pItemArray[wCell];
if (pOld)
@@ -634,7 +647,7 @@ LPITEM CHARACTER::GetWear(BYTE bCell) const
return NULL;
}
return m_pointsInstant.pItems[INVENTORY_MAX_NUM + bCell];
return ItemCells().pItems[INVENTORY_MAX_NUM + bCell];
}
void CHARACTER::SetWear(BYTE bCell, LPITEM item)
@@ -740,9 +753,9 @@ bool CHARACTER::IsEmptyItemGrid(TItemPos Cell, BYTE bSize, int iExceptionCell) c
if (false == CBeltInventoryHelper::IsAvailableCell(bCell - BELT_INVENTORY_SLOT_START, beltItem->GetValue(0)))
return false;
if (m_pointsInstant.bItemGrid[bCell])
if (ItemCells().bItemGrid[bCell])
{
if (m_pointsInstant.bItemGrid[bCell] == iExceptionCell)
if (ItemCells().bItemGrid[bCell] == iExceptionCell)
return true;
return false;
@@ -755,9 +768,9 @@ bool CHARACTER::IsEmptyItemGrid(TItemPos Cell, BYTE bSize, int iExceptionCell) c
else if (bCell >= INVENTORY_MAX_NUM)
return false;
if (m_pointsInstant.bItemGrid[bCell])
if (ItemCells().bItemGrid[bCell])
{
if (m_pointsInstant.bItemGrid[bCell] == iExceptionCell)
if (ItemCells().bItemGrid[bCell] == iExceptionCell)
{
if (bSize == 1)
return true;
@@ -775,8 +788,8 @@ bool CHARACTER::IsEmptyItemGrid(TItemPos Cell, BYTE bSize, int iExceptionCell) c
if (p / INVENTORY_PAGE_SIZE != bPage)
return false;
if (m_pointsInstant.bItemGrid[p])
if (m_pointsInstant.bItemGrid[p] != iExceptionCell)
if (ItemCells().bItemGrid[p])
if (ItemCells().bItemGrid[p] != iExceptionCell)
return false;
}
while (++j < bSize);
@@ -805,8 +818,8 @@ bool CHARACTER::IsEmptyItemGrid(TItemPos Cell, BYTE bSize, int iExceptionCell) c
if (p / INVENTORY_PAGE_SIZE != bPage)
return false;
if (m_pointsInstant.bItemGrid[p])
if (m_pointsInstant.bItemGrid[p] != iExceptionCell)
if (ItemCells().bItemGrid[p])
if (ItemCells().bItemGrid[p] != iExceptionCell)
return false;
}
while (++j < bSize);
@@ -825,9 +838,9 @@ bool CHARACTER::IsEmptyItemGrid(TItemPos Cell, BYTE bSize, int iExceptionCell) c
// 따라서 iExceptionCell에 1을 더해 비교한다.
iExceptionCell++;
if (m_pointsInstant.wDSItemGrid[wCell])
if (ItemCells().wDSItemGrid[wCell])
{
if (m_pointsInstant.wDSItemGrid[wCell] == iExceptionCell)
if (ItemCells().wDSItemGrid[wCell] == iExceptionCell)
{
if (bSize == 1)
return true;
@@ -841,8 +854,8 @@ bool CHARACTER::IsEmptyItemGrid(TItemPos Cell, BYTE bSize, int iExceptionCell) c
if (p >= DRAGON_SOUL_INVENTORY_MAX_NUM)
return false;
if (m_pointsInstant.wDSItemGrid[p])
if (m_pointsInstant.wDSItemGrid[p] != iExceptionCell)
if (ItemCells().wDSItemGrid[p])
if (ItemCells().wDSItemGrid[p] != iExceptionCell)
return false;
}
while (++j < bSize);
@@ -867,8 +880,8 @@ bool CHARACTER::IsEmptyItemGrid(TItemPos Cell, BYTE bSize, int iExceptionCell) c
if (p >= DRAGON_SOUL_INVENTORY_MAX_NUM)
return false;
if (m_pointsInstant.bItemGrid[p])
if (m_pointsInstant.wDSItemGrid[p] != iExceptionCell)
if (ItemCells().bItemGrid[p])
if (ItemCells().wDSItemGrid[p] != iExceptionCell)
return false;
}
while (++j < bSize);
@@ -916,11 +929,11 @@ bool CHARACTER::IsEmptyItemGrid(TItemPos Cell, BYTE bSize, int iExceptionCell) c
if (bSize == 3 && wCell + 10 >= SPECIAL_INVENTORY_MAX_NUM)
return false;
#endif
const WORD* pGrid = (Cell.window_type == UPGRADE_INVENTORY) ? m_pointsInstant.wSSUItemGrid :
(Cell.window_type == BOOK_INVENTORY) ? m_pointsInstant.wSSBItemGrid :
(Cell.window_type == STONE_INVENTORY) ? m_pointsInstant.wSSSItemGrid :
(Cell.window_type == CHANGE_INVENTORY) ? m_pointsInstant.wSSCItemGrid :
m_pointsInstant.wCostumeItemGrid;
const WORD* pGrid = (Cell.window_type == UPGRADE_INVENTORY) ? ItemCells().wSSUItemGrid :
(Cell.window_type == BOOK_INVENTORY) ? ItemCells().wSSBItemGrid :
(Cell.window_type == STONE_INVENTORY) ? ItemCells().wSSSItemGrid :
(Cell.window_type == CHANGE_INVENTORY) ? ItemCells().wSSCItemGrid :
ItemCells().wCostumeItemGrid;
iExceptionCell++;
@@ -1013,7 +1026,7 @@ void CHARACTER::CopyDragonSoulItemGrid(std::vector<WORD>& vDragonSoulItemGrid) c
{
vDragonSoulItemGrid.resize(DRAGON_SOUL_INVENTORY_MAX_NUM);
std::copy(m_pointsInstant.wDSItemGrid, m_pointsInstant.wDSItemGrid + DRAGON_SOUL_INVENTORY_MAX_NUM, vDragonSoulItemGrid.begin());
std::copy(ItemCells().wDSItemGrid, ItemCells().wDSItemGrid + DRAGON_SOUL_INVENTORY_MAX_NUM, vDragonSoulItemGrid.begin());
}
#ifdef ENABLE_SPECIAL_STORAGE
+5 -4
View File
@@ -11,9 +11,10 @@
bool CHARACTER::PortCubeInstallImage(const PortCube::InventoryImage& image,const std::vector<LPITEM>& before,const std::vector<LPITEM>& restored)
{
static_assert(INVENTORY_MAX_NUM==225,"Cube normal inventory contract");
if(!PortCubeActorHeld(this)||image.items.size()!=restored.size()||image.gold>uint64_t(PortEconomy::GoldLimit))return false;
auto* cells=m_pointsInstant.pItemCells;
if(!cells||!PortCubeActorHeld(this)||image.items.size()!=restored.size()||image.gold>uint64_t(PortEconomy::GoldLimit))return false;
size_t next=0;std::array<WORD,225> grid={};
for(unsigned cell=0;cell<225;++cell)if(auto* item=m_pointsInstant.pItems[cell]) {
for(unsigned cell=0;cell<225;++cell)if(auto* item=ItemCells().pItems[cell]) {
if(next>=before.size()||before[next++]!=item||item->GetCell()!=cell||item->GetWindow()!=INVENTORY||
item->GetOwner()!=this||item->isLocked()||item->IsExchanging()||item->GetSkipSave()||item->PortCubeHasPendingMutation())return false;
}
@@ -33,9 +34,9 @@ bool CHARACTER::PortCubeInstallImage(const PortCube::InventoryImage& image,const
for(auto& selected:m_pointsInstant.pCubeItems)remap(selected);
for(auto& selected:m_pointsInstant.pSashMaterials)remap(selected);
remap(m_pQuestItem);
for(unsigned cell=0;cell<225;++cell){m_pointsInstant.pItems[cell]=nullptr;m_pointsInstant.bItemGrid[cell]=grid[cell];}
for(unsigned cell=0;cell<225;++cell){cells->pItems[cell]=nullptr;cells->bItemGrid[cell]=grid[cell];}
for(auto* item:before){item->SetCell(nullptr,0);item->SetWindow(RESERVED_WINDOW);item->PortCubeMarkTemplate();}
for(size_t i=0;i<restored.size();++i){const auto cell=image.items[i].cell;m_pointsInstant.pItems[cell]=restored[i];restored[i]->PortCubeAttachRestored(this,cell);}
for(size_t i=0;i<restored.size();++i){const auto cell=image.items[i].cell;cells->pItems[cell]=restored[i];restored[i]->PortCubeAttachRestored(this,cell);}
SetGold(int64_t(image.gold));return true;
}