Skip to content

Commit

Permalink
refactor(VNpc): convert slots to unique_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
lmichaelis committed Jan 14, 2024
1 parent a7e3157 commit 28ee035
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion include/zenkit/vobs/Misc.hh
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ namespace zenkit {

std::string packed[packed_count];
std::vector<std::shared_ptr<VItem>> items;
std::vector<Slot> slots;
std::vector<std::unique_ptr<Slot>> slots;

bool current_state_valid;
std::string current_state_name;
Expand Down
21 changes: 11 additions & 10 deletions src/vobs/Misc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -376,12 +376,13 @@ namespace zenkit {
auto inv_slot_count = static_cast<uint32_t>(r.read_int()); // numInvSlots
this->slots.resize(inv_slot_count);
for (auto i = 0u; i < inv_slot_count; ++i) {
this->slots[i].used = r.read_bool(); // used
this->slots[i].name = r.read_string(); // name
this->slots[i] = std::make_unique<Slot>();
this->slots[i]->used = r.read_bool(); // used
this->slots[i]->name = r.read_string(); // name

if (this->slots[i].used) {
this->slots[i].item = r.read_object<VItem>(version);
this->slots[i].in_inventory = r.read_bool(); // inInv
if (this->slots[i]->used) {
this->slots[i]->item = r.read_object<VItem>(version);
this->slots[i]->in_inventory = r.read_bool(); // inInv
}
}

Expand Down Expand Up @@ -526,12 +527,12 @@ namespace zenkit {

w.write_int("numInvSlots", this->slots.size());
for (auto& slot : this->slots) {
w.write_bool("used", slot.used);
w.write_string("name", slot.name);
w.write_bool("used", slot->used);
w.write_string("name", slot->name);

if (slot.used) {
w.write_object("vob", slot.item, version);
w.write_bool("inInv", slot.in_inventory);
if (slot->used) {
w.write_object("vob", slot->item, version);
w.write_bool("inInv", slot->in_inventory);
}
}

Expand Down

0 comments on commit 28ee035

Please sign in to comment.