MCPcopy Create free account
hub / github.com/ddnet/ddnet / SnapCollectEntities

Method SnapCollectEntities

src/game/client/gameclient.cpp:4795–4839  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4793}
4794
4795void CGameClient::SnapCollectEntities()
4796{
4797 int NumSnapItems = Client()->SnapNumItems(IClient::SNAP_CURRENT);
4798
4799 std::vector<CSnapEntities> vItemData;
4800 std::vector<CSnapEntities> vItemEx;
4801
4802 for(int Index = 0; Index < NumSnapItems; Index++)
4803 {
4804 const IClient::CSnapItem Item = Client()->SnapGetItem(IClient::SNAP_CURRENT, Index);
4805 if(Item.m_Type == NETOBJTYPE_ENTITYEX)
4806 vItemEx.push_back({Item, nullptr});
4807 else if(Item.m_Type == NETOBJTYPE_PICKUP || Item.m_Type == NETOBJTYPE_DDNETPICKUP || Item.m_Type == NETOBJTYPE_LASER || Item.m_Type == NETOBJTYPE_DDNETLASER || Item.m_Type == NETOBJTYPE_PROJECTILE || Item.m_Type == NETOBJTYPE_DDRACEPROJECTILE || Item.m_Type == NETOBJTYPE_DDNETPROJECTILE)
4808 vItemData.push_back({Item, nullptr});
4809 }
4810
4811 // sort by id
4812 class CEntComparer
4813 {
4814 public:
4815 bool operator()(const CSnapEntities &Lhs, const CSnapEntities &Rhs) const
4816 {
4817 return Lhs.m_Item.m_Id < Rhs.m_Item.m_Id;
4818 }
4819 };
4820
4821 std::sort(vItemData.begin(), vItemData.end(), CEntComparer());
4822 std::sort(vItemEx.begin(), vItemEx.end(), CEntComparer());
4823
4824 // merge extended items with items they belong to
4825 m_vSnapEntities.clear();
4826
4827 size_t IndexEx = 0;
4828 for(const CSnapEntities &Ent : vItemData)
4829 {
4830 while(IndexEx < vItemEx.size() && vItemEx[IndexEx].m_Item.m_Id < Ent.m_Item.m_Id)
4831 IndexEx++;
4832
4833 const CNetObj_EntityEx *pDataEx = nullptr;
4834 if(IndexEx < vItemEx.size() && vItemEx[IndexEx].m_Item.m_Id == Ent.m_Item.m_Id)
4835 pDataEx = (const CNetObj_EntityEx *)vItemEx[IndexEx].m_Item.m_pData;
4836
4837 m_vSnapEntities.push_back({Ent.m_Item, pDataEx});
4838 }
4839}
4840
4841void CGameClient::HandleMultiView()
4842{

Callers

nothing calls this directly

Calls 6

CEntComparerClass · 0.85
beginMethod · 0.80
endMethod · 0.80
ClientFunction · 0.50
SnapNumItemsMethod · 0.45
SnapGetItemMethod · 0.45

Tested by

no test coverage detected