Browse Source

Also use hsRef for the vault functions which "return" lists

Michael Hansen 10 years ago
parent
commit
8fa9171415
  1. 10
      Sources/Plasma/FeatureLib/pfPython/pyVault.cpp
  2. 12
      Sources/Plasma/FeatureLib/pfPython/pyVaultNode.cpp
  3. 70
      Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp
  4. 43
      Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp
  5. 18
      Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.h

10
Sources/Plasma/FeatureLib/pfPython/pyVault.cpp

@ -206,20 +206,16 @@ PyObject* pyVault::GetKIUsage(void)
break;
// Get child nodes up to two levels deep
ARRAY(RelVaultNode*) nodeArr;
rvnAgeJrnlz->GetChildNodesIncRef(2, &nodeArr);
RelVaultNode::RefList nodeArr;
rvnAgeJrnlz->GetChildNodes(2, &nodeArr);
RelVaultNode ** cur = nodeArr.Ptr();
RelVaultNode ** end = nodeArr.Term();
for (; cur != end; ++cur) {
RelVaultNode * rvn = *cur;
for (const hsRef<RelVaultNode> &rvn : nodeArr) {
if (rvn->GetNodeType() == plVault::kNodeType_Image)
++pictures;
else if (rvn->GetNodeType() == plVault::kNodeType_TextNote)
++notes;
else if (rvn->GetNodeType() == plVault::kNodeType_MarkerGame)
++markerGames;
rvn->UnRef();
}
break;

12
Sources/Plasma/FeatureLib/pfPython/pyVaultNode.cpp

@ -606,17 +606,13 @@ PyObject* pyVaultNode::GetChildNodeRefList()
// fill in the elements list of this folder
if (fNode)
{
ARRAY(RelVaultNode*) nodes;
fNode->GetChildNodesIncRef(
1,
&nodes
);
RelVaultNode::RefList nodes;
fNode->GetChildNodes(1, &nodes);
for (unsigned i = 0; i < nodes.Count(); ++i) {
PyObject* elementObj = pyVaultNodeRef::New(fNode, nodes[i]);
for (const hsRef<RelVaultNode> &node : nodes) {
PyObject* elementObj = pyVaultNodeRef::New(fNode, node);
PyList_Append(pyEL, elementObj);
Py_DECREF(elementObj);
nodes[i]->UnRef();
}
}

70
Sources/Plasma/PubUtilLib/plAvatar/plAvatarClothing.cpp

@ -806,11 +806,11 @@ bool plClothingOutfit::IReadFromVault()
if (!rvn)
return false;
ARRAY(RelVaultNode*) nodes;
rvn->GetChildNodesIncRef(plVault::kNodeType_SDL, 1, &nodes);
RelVaultNode::RefList nodes;
rvn->GetChildNodes(plVault::kNodeType_SDL, 1, &nodes);
for (unsigned i = 0; i < nodes.Count(); ++i) {
VaultSDLNode sdl(nodes[i]);
for (const hsRef<RelVaultNode> &node : nodes) {
VaultSDLNode sdl(node);
if (sdl.GetSDLDataLength()) {
hsRAMStream ram;
ram.Write(sdl.GetSDLDataLength(), sdl.GetSDLData());
@ -831,7 +831,6 @@ bool plClothingOutfit::IReadFromVault()
delete sdlDataRec;
}
}
nodes[i]->UnRef();
}
fSynchClients = true; // set true if the next synch should be bcast
@ -904,12 +903,12 @@ void plClothingOutfit::WriteToVault(const ARRAY(plStateDataRecord*) & SDRs)
}
}
ARRAY(RelVaultNode*) templates;
ARRAY(RelVaultNode*) actuals;
ARRAY(RelVaultNode*) nodes;
RelVaultNode::RefList templates;
RelVaultNode::RefList actuals;
RelVaultNode::RefList nodes;
// Get all existing clothing SDRs
rvn->GetChildNodesIncRef(plVault::kNodeType_SDL, 1, &nodes); // REF: Find
rvn->GetChildNodes(plVault::kNodeType_SDL, 1, &nodes); // REF: Find
const ARRAY(plStateDataRecord*) * arrs[] = {
&SDRs,
@ -921,14 +920,14 @@ void plClothingOutfit::WriteToVault(const ARRAY(plStateDataRecord*) & SDRs)
// Write all SDL to to the outfit folder, reusing existing nodes and creating new ones as necessary
for (unsigned i = 0; i < arr->Count(); ++i) {
hsRef<RelVaultNode> node;
if (nodes.Count()) {
node = nodes[0];
nodes.DeleteUnordered(0);
if (!nodes.empty()) {
node = nodes.front();
nodes.pop_front();
}
else {
node = new RelVaultNode;
node->SetNodeType(plVault::kNodeType_SDL);
templates.Add(node);
templates.push_back(node);
}
VaultSDLNode sdl(node);
@ -937,33 +936,24 @@ void plClothingOutfit::WriteToVault(const ARRAY(plStateDataRecord*) & SDRs)
}
// Delete any leftover nodes
for (unsigned i = 0; i < nodes.Count(); ++i) {
VaultDeleteNode(nodes[i]->GetNodeId());
nodes[i]->UnRef(); // REF: Array
}
for (const hsRef<RelVaultNode> &node : nodes)
VaultDeleteNode(node->GetNodeId());
// Create actual new nodes from their templates
for (unsigned i = 0; i < templates.Count(); ++i) {
for (const hsRef<RelVaultNode> &temp : templates) {
ENetError result;
if (hsRef<RelVaultNode> actual = VaultCreateNodeAndWait(templates[i], &result)) {
actual->Ref();
actuals.Add(actual);
}
templates[i]->UnRef(); // REF: Create
if (hsRef<RelVaultNode> actual = VaultCreateNodeAndWait(temp, &result))
actuals.push_back(actual);
}
// Add new nodes to outfit folder
for (unsigned i = 0; i < actuals.Count(); ++i) {
VaultAddChildNodeAndWait(rvn->GetNodeId(), actuals[i]->GetNodeId(), NetCommGetPlayer()->playerInt);
actuals[i]->UnRef(); // REF: Create
}
for (const hsRef<RelVaultNode> &act : actuals)
VaultAddChildNodeAndWait(rvn->GetNodeId(), act->GetNodeId(), NetCommGetPlayer()->playerInt);
// Cleanup morph SDRs
for (unsigned i = 0; i < morphs.Count(); ++i) {
delete morphs[i];
}
rvn->UnRef();
}
// XXX HACK. DON'T USE (this function exists for the temp console command Clothing.SwapClothTexHACK)
@ -1488,15 +1478,14 @@ bool plClothingOutfit::WriteToFile(const plFileName &filename)
S.WriteByte(fGroup);
ARRAY(RelVaultNode*) nodes;
rvn->GetChildNodesIncRef(plVault::kNodeType_SDL, 1, &nodes);
S.WriteLE32(nodes.Count());
for (size_t i = 0; i < nodes.Count(); i++) {
VaultSDLNode sdl(nodes[i]);
RelVaultNode::RefList nodes;
rvn->GetChildNodes(plVault::kNodeType_SDL, 1, &nodes);
S.WriteLE32(nodes.size());
for (const hsRef<RelVaultNode> &node : nodes) {
VaultSDLNode sdl(node);
S.WriteLE32(sdl.GetSDLDataLength());
if (sdl.GetSDLDataLength())
S.Write(sdl.GetSDLDataLength(), sdl.GetSDLData());
nodes[i]->UnRef();
}
S.Close();
@ -1672,12 +1661,13 @@ void plClothingMgr::GetClosetItems(hsTArray<plClosetItem> &out)
if (!rvn)
return;
ARRAY(RelVaultNode*) nodes;
rvn->GetChildNodesIncRef(plVault::kNodeType_SDL, 1, &nodes);
out.SetCount(nodes.Count());
RelVaultNode::RefList nodes;
rvn->GetChildNodes(plVault::kNodeType_SDL, 1, &nodes);
out.SetCount(nodes.size());
for (unsigned i = 0; i < nodes.Count(); ++i) {
VaultSDLNode sdl(nodes[i]);
auto iter = nodes.begin();
for (unsigned i = 0; i < nodes.size(); ++i, ++iter) {
VaultSDLNode sdl(*iter);
plStateDataRecord * rec = new plStateDataRecord;
if (sdl.GetStateDataRecord(rec, 0))
plClothingSDLModifier::HandleSingleSDR(rec, nil, &out[i]);

43
Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp

@ -1289,9 +1289,9 @@ hsRef<RelVaultNode> RelVaultNode::GetChildAgeInfoListNode (
}
//============================================================================
void RelVaultNode::GetChildNodesIncRef (
void RelVaultNode::GetChildNodes (
unsigned maxDepth,
ARRAY(RelVaultNode*) * nodes
RelVaultNode::RefList * nodes
) {
if (maxDepth == 0)
return;
@ -1299,9 +1299,8 @@ void RelVaultNode::GetChildNodesIncRef (
RelVaultNodeLink * link;
link = state->children.Head();
for (; link; link = state->children.Next(link)) {
nodes->Add(link->node);
link->node->Ref();
link->node->GetChildNodesIncRef(
nodes->push_back(link->node);
link->node->GetChildNodes(
maxDepth - 1,
nodes
);
@ -1309,19 +1308,19 @@ void RelVaultNode::GetChildNodesIncRef (
}
//============================================================================
void RelVaultNode::GetChildNodesIncRef (
void RelVaultNode::GetChildNodes (
NetVaultNode * templateNode,
unsigned maxDepth,
ARRAY(RelVaultNode*) * nodes
RelVaultNode::RefList * nodes
) {
RelVaultNodeLink * link;
link = state->children.Head();
for (; link; link = state->children.Next(link)) {
if (link->node->Matches(templateNode)) {
nodes->Add(link->node);
nodes->push_back(link->node);
link->node->Ref();
}
link->node->GetChildNodesIncRef(
link->node->GetChildNodes(
templateNode,
maxDepth - 1,
nodes
@ -1330,14 +1329,14 @@ void RelVaultNode::GetChildNodesIncRef (
}
//============================================================================
void RelVaultNode::GetChildNodesIncRef (
void RelVaultNode::GetChildNodes (
unsigned nodeType,
unsigned maxDepth,
ARRAY(RelVaultNode*) * nodes
RelVaultNode::RefList * nodes
) {
hsRef<NetVaultNode> templateNode = new NetVaultNode;
templateNode->SetNodeType(nodeType);
GetChildNodesIncRef(
GetChildNodes(
templateNode,
maxDepth,
nodes
@ -1345,16 +1344,16 @@ void RelVaultNode::GetChildNodesIncRef (
}
//============================================================================
void RelVaultNode::GetChildFolderNodesIncRef (
void RelVaultNode::GetChildFolderNodes (
unsigned folderType,
unsigned maxDepth,
ARRAY(RelVaultNode*) * nodes
RelVaultNode::RefList * nodes
) {
hsRef<NetVaultNode> templateNode = new NetVaultNode;
templateNode->SetNodeType(plVault::kNodeType_Folder);
VaultFolderNode fldr(templateNode);
fldr.SetFolderType(folderType);
GetChildNodesIncRef(
GetChildNodes(
templateNode,
maxDepth,
nodes
@ -3606,15 +3605,14 @@ void VaultProcessUnvisitNote(RelVaultNode * rvnUnVisit) {
void VaultProcessPlayerInbox () {
if (hsRef<RelVaultNode> rvnInbox = VaultGetPlayerInboxFolder()) {
{ // Process new visit requests
ARRAY(RelVaultNode*) visits;
RelVaultNode::RefList visits;
hsRef<RelVaultNode> templateNode = new RelVaultNode;
templateNode->SetNodeType(plVault::kNodeType_TextNote);
VaultTextNoteNode tmpAcc(templateNode);
tmpAcc.SetNoteType(plVault::kNoteType_Visit);
rvnInbox->GetChildNodesIncRef(templateNode, 1, &visits);
rvnInbox->GetChildNodes(templateNode, 1, &visits);
for (unsigned i = 0; i < visits.Count(); ++i) {
hsRef<RelVaultNode> rvnVisit = visits[i];
for (const hsRef<RelVaultNode> &rvnVisit : visits) {
VaultTextNoteNode visitAcc(rvnVisit);
plAgeLinkStruct link;
if (visitAcc.GetVisitInfo(link.GetAgeInfo())) {
@ -3626,15 +3624,14 @@ void VaultProcessPlayerInbox () {
}
}
{ // Process new unvisit requests
ARRAY(RelVaultNode*) unvisits;
RelVaultNode::RefList unvisits;
hsRef<RelVaultNode> templateNode = new RelVaultNode;
templateNode->SetNodeType(plVault::kNodeType_TextNote);
VaultTextNoteNode tmpAcc(templateNode);
tmpAcc.SetNoteType(plVault::kNoteType_UnVisit);
rvnInbox->GetChildNodesIncRef(templateNode, 1, &unvisits);
rvnInbox->GetChildNodes(templateNode, 1, &unvisits);
for (unsigned i = 0; i < unvisits.Count(); ++i) {
hsRef<RelVaultNode> rvnUnVisit = unvisits[i];
for (const hsRef<RelVaultNode> &rvnUnVisit : unvisits) {
VaultTextNoteNode unvisitAcc(rvnUnVisit);
plAgeInfoStruct info;
if (unvisitAcc.GetVisitInfo(&info)) {

18
Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.h

@ -94,6 +94,8 @@ void VaultUnregisterCallback (VaultCallback * cb);
*
***/
struct RelVaultNode : NetVaultNode {
typedef std::list<hsRef<RelVaultNode>> RefList;
struct IRelVaultNode * state;
RelVaultNode ();
@ -153,24 +155,24 @@ struct RelVaultNode : NetVaultNode {
);
// returns all matching nodes found
void GetChildNodesIncRef (
void GetChildNodes (
unsigned maxDepth,
ARRAY(RelVaultNode*) * nodes
RefList * nodes
);
void GetChildNodesIncRef (
void GetChildNodes (
NetVaultNode * templateNode,
unsigned maxDepth,
ARRAY(RelVaultNode*) * nodes
RefList * nodes
);
void GetChildNodesIncRef (
void GetChildNodes (
unsigned nodeType,
unsigned maxDepth,
ARRAY(RelVaultNode*) * nodes
RefList * nodes
);
void GetChildFolderNodesIncRef (
void GetChildFolderNodes (
unsigned folderType,
unsigned maxDepth,
ARRAY(RelVaultNode*) * nodes
RefList * nodes
);
unsigned GetRefOwnerId (unsigned parentId);

Loading…
Cancel
Save