Browse Source

Async pyVaultPlayerInfoList::AddPlayer

This fixes the stutter when adding a buddy to the KI. The return value was
never used, according to grep. There is a delay between hitting enter and the player being added, but that's acceptable.
Adam Johnson 11 years ago
parent
commit
52deaff61a
  1. 40
      Sources/Plasma/FeatureLib/pfPython/pyVaultPlayerInfoListNode.cpp
  2. 4
      Sources/Plasma/FeatureLib/pfPython/pyVaultPlayerInfoListNode.h
  3. 6
      Sources/Plasma/FeatureLib/pfPython/pyVaultPlayerInfoListNodeGlue.cpp

40
Sources/Plasma/FeatureLib/pfPython/pyVaultPlayerInfoListNode.cpp

@ -93,31 +93,37 @@ bool pyVaultPlayerInfoListNode::HasPlayer( uint32_t playerID )
return (rvn != nil); return (rvn != nil);
} }
bool pyVaultPlayerInfoListNode::AddPlayer( uint32_t playerID ) //==================================================================
static void IAddPlayer_NodesFound(ENetError result, void* param, unsigned nodeIdCount, const unsigned nodeIds[])
{ {
if (HasPlayer(playerID)) NetVaultNode* parent = static_cast<NetVaultNode*>(param);
return true; if (nodeIdCount)
VaultAddChildNode(parent->GetNodeId(), nodeIds[0], VaultGetPlayerId(), nullptr, nullptr);
if (!fNode) parent->DecRef();
return false; }
NetVaultNode * templateNode = new NetVaultNode; void pyVaultPlayerInfoListNode::AddPlayer( uint32_t playerID )
{
if (HasPlayer(playerID) || !fNode)
return;
NetVaultNode* templateNode = new NetVaultNode();
templateNode->IncRef(); templateNode->IncRef();
templateNode->SetNodeType(plVault::kNodeType_PlayerInfo); templateNode->SetNodeType(plVault::kNodeType_PlayerInfo);
VaultPlayerInfoNode access(templateNode); VaultPlayerInfoNode access(templateNode);
access.SetPlayerId(playerID); access.SetPlayerId(playerID);
ARRAY(unsigned) nodeIds; ARRAY(uint32_t) nodeIds;
VaultLocalFindNodes(templateNode, &nodeIds); VaultLocalFindNodes(templateNode, &nodeIds);
if (!nodeIds.Count()) // So, if we know about this node, we can take it easy. If not, we lazy load it.
VaultFindNodesAndWait(templateNode, &nodeIds);
if (nodeIds.Count()) if (nodeIds.Count())
VaultAddChildNodeAndWait(fNode->GetNodeId(), nodeIds[0], VaultGetPlayerId()); VaultAddChildNode(fNode->GetNodeId(), nodeIds[0], VaultGetPlayerId(), nullptr, nullptr);
else {
templateNode->DecRef(); fNode->IncRef();
return nodeIds.Count() != 0; VaultFindNodes(templateNode, IAddPlayer_NodesFound, fNode);
}
} }
void pyVaultPlayerInfoListNode::RemovePlayer( uint32_t playerID ) void pyVaultPlayerInfoListNode::RemovePlayer( uint32_t playerID )

4
Sources/Plasma/FeatureLib/pfPython/pyVaultPlayerInfoListNode.h

@ -78,8 +78,8 @@ public:
//================================================================== //==================================================================
// class RelVaultNode : public plVaultFolderNode // class RelVaultNode : public plVaultFolderNode
// //
virtual bool HasPlayer( uint32_t playerID ); bool HasPlayer( uint32_t playerID );
bool AddPlayer( uint32_t playerID ); void AddPlayer( uint32_t playerID );
void RemovePlayer( uint32_t playerID ); void RemovePlayer( uint32_t playerID );
PyObject * GetPlayer( uint32_t playerID ); // returns pyVaultPlayerInfoNode PyObject * GetPlayer( uint32_t playerID ); // returns pyVaultPlayerInfoNode

6
Sources/Plasma/FeatureLib/pfPython/pyVaultPlayerInfoListNodeGlue.cpp

@ -83,7 +83,8 @@ PYTHON_METHOD_DEFINITION(ptVaultPlayerInfoListNode, playerlistAddPlayer, args)
PyErr_SetString(PyExc_TypeError, "playerlistAddPlayer expects an unsigned long"); PyErr_SetString(PyExc_TypeError, "playerlistAddPlayer expects an unsigned long");
PYTHON_RETURN_ERROR; PYTHON_RETURN_ERROR;
} }
PYTHON_RETURN_BOOL(self->fThis->AddPlayer(playerID)); self->fThis->AddPlayer(playerID);
PYTHON_RETURN_NONE;
} }
PYTHON_METHOD_DEFINITION(ptVaultPlayerInfoListNode, playerlistRemovePlayer, args) PYTHON_METHOD_DEFINITION(ptVaultPlayerInfoListNode, playerlistRemovePlayer, args)
@ -128,7 +129,8 @@ PYTHON_METHOD_DEFINITION(ptVaultPlayerInfoListNode, addPlayer, args)
PyErr_SetString(PyExc_TypeError, "addPlayer expects an unsigned long"); PyErr_SetString(PyExc_TypeError, "addPlayer expects an unsigned long");
PYTHON_RETURN_ERROR; PYTHON_RETURN_ERROR;
} }
PYTHON_RETURN_BOOL(self->fThis->AddPlayer(playerID)); self->fThis->AddPlayer(playerID);
PYTHON_RETURN_NONE;
} }
PYTHON_METHOD_DEFINITION(ptVaultPlayerInfoListNode, removePlayer, args) PYTHON_METHOD_DEFINITION(ptVaultPlayerInfoListNode, removePlayer, args)

Loading…
Cancel
Save