BVB Source Codes

CRYENGINE Show CET_ClassRegistry.cpp Source code

Return Download CRYENGINE: download CET_ClassRegistry.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #include "StdAfx.h"
  4. #include "CET_ClassRegistry.h"
  5. #include "GameClientChannel.h"
  6. #include <CryNetwork/NetHelpers.h>
  7.  
  8. /*
  9.  * Register Classes
  10.  */
  11.  
  12. class CCET_RegisterClasses : public CCET_Base
  13. {
  14. public:
  15.         CCET_RegisterClasses(CClassRegistryReplicator* pRep) : m_pRep(pRep) {}
  16.  
  17.         const char*                 GetName() { return "RegisterClasses"; }
  18.  
  19.         EContextEstablishTaskResult OnStep(SContextEstablishState& state)
  20.         {
  21.                 // setup our class database
  22.                 IEntityClassRegistry* pClassRegistry = gEnv->pEntitySystem->GetClassRegistry();
  23.                 IEntityClass* pClass;
  24.                 pClassRegistry->IteratorMoveFirst();
  25.                 while (pClass = pClassRegistry->IteratorNext())
  26.                 {
  27.                         m_pRep->RegisterClassName(pClass->GetName(), ~uint16(0));
  28.                 }
  29.                 return eCETR_Ok;
  30.         }
  31.  
  32. private:
  33.         CClassRegistryReplicator* m_pRep;
  34. };
  35.  
  36. void AddRegisterAllClasses(IContextEstablisher* pEst, EContextViewState state, CClassRegistryReplicator* pRep)
  37. {
  38.         pEst->AddTask(state, new CCET_RegisterClasses(pRep));
  39. }
  40.  
  41. /*
  42.  * Send Classes
  43.  */
  44.  
  45. class CCET_SendClasses : public CCET_Base
  46. {
  47. public:
  48.         CCET_SendClasses(CClassRegistryReplicator* pRep) : m_pRep(pRep)
  49.         {
  50.         }
  51.  
  52.         const char*                 GetName() { return "SendClasses"; }
  53.  
  54.         EContextEstablishTaskResult OnStep(SContextEstablishState& state)
  55.         {
  56.                 // setup a class-name to id mapping
  57.                 m_waitFor.reserve(m_pRep->NumClassIds());
  58.                 for (size_t i = 0; i < m_pRep->NumClassIds(); i++)
  59.                 {
  60.                         string name;
  61.                         if (m_pRep->ClassNameFromId(name, static_cast<uint16>(i)))
  62.                         {
  63.                                 INetSendable* pMsg = new CSimpleNetMessage<SEntityClassRegistration>(SEntityClassRegistration(uint16(i), name), CGameClientChannel::RegisterEntityClass);
  64.                                 pMsg->SetGroup('clas');
  65.                                 SSendableHandle hdl;
  66.                                 state.pSender->AddSendable(pMsg, 0, NULL, &hdl);
  67.                                 m_waitFor.push_back(hdl);
  68.                         }
  69.                 }
  70.                 return eCETR_Ok;
  71.         }
  72.  
  73.         std::vector<SSendableHandle> m_waitFor;
  74.  
  75. private:
  76.         CClassRegistryReplicator* m_pRep;
  77. };
  78.  
  79. void AddSendClassRegistration(IContextEstablisher* pEst, EContextViewState state, CClassRegistryReplicator* pRep, std::vector<SSendableHandle>** ppWaitFor)
  80. {
  81.         CCET_SendClasses* pCET = new CCET_SendClasses(pRep);
  82.         *ppWaitFor = &pCET->m_waitFor;
  83.         pEst->AddTask(state, pCET);
  84. }
  85.  
  86. /*
  87.  * Send Classes Hash
  88.  */
  89.  
  90. class CCET_SendClassesHash : public CCET_Base
  91. {
  92. public:
  93.         CCET_SendClassesHash(CClassRegistryReplicator* pRep) : m_pRep(pRep)
  94.         {
  95.         }
  96.  
  97.         const char*                 GetName() { return "SendClassesHash"; }
  98.  
  99.         EContextEstablishTaskResult OnStep(SContextEstablishState& state)
  100.         {
  101.                 uint32 crc = m_pRep->GetHash();
  102.                 INetSendable* pMsg = new CSimpleNetMessage<SEntityClassHashRegistration>(SEntityClassHashRegistration(crc), CGameClientChannel::RegisterEntityClassHash);
  103.                 pMsg->SetGroup('clsh');
  104.                 SSendableHandle hdl;
  105.                 state.pSender->AddSendable(pMsg, 0, NULL, &hdl);
  106.                 m_waitFor.push_back(hdl);
  107.                 return eCETR_Ok;
  108.         }
  109.  
  110.         std::vector<SSendableHandle> m_waitFor;
  111.  
  112. private:
  113.         CClassRegistryReplicator* m_pRep;
  114. };
  115.  
  116. void AddSendClassHashRegistration(IContextEstablisher* pEst, EContextViewState state, CClassRegistryReplicator* pRep, std::vector<SSendableHandle>** ppWaitFor)
  117. {
  118.         CCET_SendClassesHash* pCET = new CCET_SendClassesHash(pRep);
  119.         *ppWaitFor = &pCET->m_waitFor;
  120.         pEst->AddTask(state, pCET);
  121. }
  122.  
downloadCET_ClassRegistry.cpp Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top