Guest User

entity.cpp

a guest
May 23rd, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.29 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "char.h"
  3. #include "desc.h"
  4. #include "sectree_manager.h"
  5.  
  6. CEntity::CEntity()
  7. {
  8.     Initialize();
  9. }
  10.  
  11. CEntity::~CEntity()
  12. {
  13.     if (!m_bIsDestroyed)
  14.         assert(!"You must call CEntity::destroy() method in your derived class destructor");
  15. }
  16.  
  17. void CEntity::Initialize(int type)
  18. {
  19.     m_bIsDestroyed = false;
  20.  
  21.     m_iType = type;
  22.     m_iViewAge = 0;
  23.     m_pos.x = m_pos.y = m_pos.z = 0;
  24.     m_map_view.clear();
  25.  
  26.     m_pSectree = NULL;
  27.     m_lpDesc = NULL;
  28.     m_lMapIndex = 0;
  29.     m_bIsObserver = false;
  30.     m_bObserverModeChange = false;
  31. }
  32.  
  33. void CEntity::Destroy()
  34. {
  35.     if (m_bIsDestroyed) {
  36.         return;
  37.     }
  38.     ViewCleanup();
  39.     m_bIsDestroyed = true;
  40. }
  41.  
  42. void CEntity::SetType(int type)
  43. {
  44.     m_iType = type;
  45. }
  46.  
  47. int CEntity::GetType() const
  48. {
  49.     return m_iType;
  50. }
  51.  
  52. bool CEntity::IsType(int type) const
  53. {
  54.     return (m_iType == type ? true : false);
  55. }
  56.  
  57. struct FuncPacketAround
  58. {
  59.     const void *        m_data;
  60.     int                 m_bytes;
  61.     LPENTITY            m_except;
  62.  
  63.     FuncPacketAround(const void * data, int bytes, LPENTITY except = NULL) :m_data(data), m_bytes(bytes), m_except(except)
  64.     {
  65.     }
  66.  
  67.     void operator () (LPENTITY ent)
  68.     {
  69.         if (ent == m_except)
  70.             return;
  71.  
  72.         if (ent->GetDesc())
  73.             ent->GetDesc()->Packet(m_data, m_bytes);
  74.     }
  75. };
  76.  
  77. struct FuncPacketView : public FuncPacketAround
  78. {
  79.     FuncPacketView(const void * data, int bytes, LPENTITY except = NULL) : FuncPacketAround(data, bytes, except)
  80.     {}
  81.  
  82.     void operator() (const CEntity::ENTITY_MAP::value_type& v)
  83.     {
  84.         FuncPacketAround::operator() (v.first);
  85.     }
  86. };
  87.  
  88. void CEntity::PacketAround(const void * data, int bytes, LPENTITY except)
  89. {
  90.     PacketView(data, bytes, except);
  91. }
  92.  
  93. void CEntity::PacketView(const void * data, int bytes, LPENTITY except)
  94. {
  95.     if (!GetSectree())
  96.         return;
  97.  
  98.     FuncPacketView f(data, bytes, except);
  99.  
  100.     // 옵저버 상태에선 내 패킷은 나만 받는다.
  101.     if (!m_bIsObserver)
  102.         for_each(m_map_view.begin(), m_map_view.end(), f);
  103.  
  104.     f(std::make_pair(this, 0));
  105. }
  106.  
  107. void CEntity::SetObserverMode(bool bFlag)
  108. {
  109.     if (m_bIsObserver == bFlag)
  110.         return;
  111.  
  112.     m_bIsObserver = bFlag;
  113.     m_bObserverModeChange = true;
  114.     UpdateSectree();
  115.  
  116.     if (IsType(ENTITY_CHARACTER))
  117.     {
  118.         LPCHARACTER ch = (LPCHARACTER) this;
  119.         ch->ChatPacket(CHAT_TYPE_COMMAND, "ObserverMode %d", m_bIsObserver ? 1 : 0);
  120.     }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment