[core] Refactor item pointer ownership#9870
Conversation
|
✨ Hello and thanks for the PR! ✨ 🤖: This is a friendly automated reminder that the maintainers won't look at your PR until you've properly completed all of the checkboxes in the pre-filled template. |
| // Badge<T> | ||
| // | ||
| // Pass-key. | ||
| // Only T can construct a Badge<T>, so any method that takes one as a parameter is effectively private to T. |
There was a problem hiding this comment.
Can a Badge be copied or moved? Should probably declare those with our macros:
#define DISALLOW_COPY(TypeName) \
TypeName(const TypeName&) = delete; \
TypeName& operator=(const TypeName&) = delete;
#define DISALLOW_MOVE(TypeName) \
TypeName(TypeName&&) = delete; \
TypeName& operator=(TypeName&&) = delete;
#define DISALLOW_COPY_AND_MOVE(TypeName) \
DISALLOW_COPY(TypeName) \
DISALLOW_MOVE(TypeName)
| friend T; | ||
| Badge() = default; | ||
| }; | ||
| } // namespace xi |
There was a problem hiding this comment.
A little more spacing
namespace xi
{
template <typename T>
class Badge
{
friend T;
Badge() = default;
};
} // namespace xi
| class Badge | ||
| { | ||
| friend T; | ||
| Badge() = default; |
There was a problem hiding this comment.
I'd explicitly list that the contructor is private, to hammer home how this is working:
class Badge
{
private:
friend T;
Badge() = default;
|
|
||
| // Badge<T> | ||
| // | ||
| // Pass-key. |
There was a problem hiding this comment.
Might be nice to leave a link to this post; https://awesomekling.github.io/Serenity-C++-patterns-The-Badge/
| { | ||
| CItem* m_PLuaItem; | ||
| const CItem* m_readItem; // observer; always set | ||
| CItem* m_writeItem; // null when wrapping a read-only template |
|
When this comes around, would probably be nice to have an enum or flags instead of a raw bool onFinish = function(player)
npcUtil.giveKeyItem(player, xi.ki.AIRSHIP_PASS_FOR_KAZHAM)
return xi.tradeFinished.CONSUME_KEYITEM + xi.tradeFinished.CONSUME_ITEM
end, |
af5a0e1 to
99b9846
Compare
|
Addressed comments, added a handful of tests, retested manually what couldn't be easily automated. |
I affirm:
What does this pull request do?
Part 1 of several aimed at streamlining everything that's wrong with items.
xi::itemsnamespace:This overall does not change much but it:
There's a handful of code smells left:
Plan for next steps
Item state
Introduce an ItemState enum on CItem to replace the generic ITEM_LOCKED: Free, Equipped, Bazaar, PlacedFurniture, InTransaction (more on that below). The generic check in the codebase to know "can this item be used" will then be a simpler "item->isBusy()" as opposed to checking ITEM_LOCKED + m_reserve etc.
xi::itemsnamespace will be the only place capable of shifting an item state to ensure competing systems aren't unlocking things they shouldn't.Transactions
Rework the various containers into Transaction-derived classes: NPCTrade / PlayerTrade, Synthesis, ItemUse, DeliveryBox
xi::itemsnamespace being the only place capable of shifting an item from inventory to any transaction and rejecting very loudly out-of-sequence attempts.Declarative trade API for lua
Massively reduce the trade container surface exposed to the lua, prefer a single entrypoint mapping to NPCTrade TX described above.
No confirming trade by hand, no accepting/rejecting items, no items being locked for no reason. A single table that's all.
Steps to test these changes
Retest every single codepath...