Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

182 lines
6.9 KiB

  1. //========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. //
  8. //-----------------------------------------------------------------------------
  9. // $Log: $
  10. //
  11. // $NoKeywords: $
  12. //=============================================================================//
  13. #if !defined( CLIENT_CLASS_H )
  14. #define CLIENT_CLASS_H
  15. #ifdef _WIN32
  16. #pragma once
  17. #endif
  18. #include "interface.h"
  19. #include "dt_recv.h"
  20. //-----------------------------------------------------------------------------
  21. // forward declarations
  22. //-----------------------------------------------------------------------------
  23. class Vector;
  24. class CMouthInfo;
  25. //-----------------------------------------------------------------------------
  26. // represents a handle used only by the client DLL
  27. //-----------------------------------------------------------------------------
  28. #include "iclientrenderable.h"
  29. #include "iclientnetworkable.h"
  30. class ClientClass;
  31. // Linked list of all known client classes
  32. extern ClientClass *g_pClientClassHead;
  33. // The serial number that gets passed in is used for ehandles.
  34. typedef IClientNetworkable* (*CreateClientClassFn)( int entnum, int serialNum );
  35. typedef IClientNetworkable* (*CreateEventFn)();
  36. //-----------------------------------------------------------------------------
  37. // Purpose: Client side class definition
  38. //-----------------------------------------------------------------------------
  39. class ClientClass
  40. {
  41. public:
  42. ClientClass( char *pNetworkName, CreateClientClassFn createFn, CreateEventFn createEventFn, RecvTable *pRecvTable )
  43. {
  44. m_pNetworkName = pNetworkName;
  45. m_pCreateFn = createFn;
  46. m_pCreateEventFn= createEventFn;
  47. m_pRecvTable = pRecvTable;
  48. m_pMapClassname = NULL;
  49. // Link it in
  50. m_pNext = g_pClientClassHead;
  51. g_pClientClassHead = this;
  52. }
  53. const char* GetName()
  54. {
  55. return m_pNetworkName;
  56. }
  57. public:
  58. CreateClientClassFn m_pCreateFn;
  59. CreateEventFn m_pCreateEventFn; // Only called for event objects.
  60. char *m_pNetworkName;
  61. RecvTable *m_pRecvTable;
  62. ClientClass *m_pNext;
  63. int m_ClassID; // Managed by the engine.
  64. const char *m_pMapClassname;
  65. };
  66. #define DECLARE_CLIENTCLASS() \
  67. virtual int YouForgotToImplementOrDeclareClientClass();\
  68. virtual ClientClass* GetClientClass();\
  69. static RecvTable *m_pClassRecvTable; \
  70. DECLARE_CLIENTCLASS_NOBASE()
  71. // This can be used to give all datatables access to protected and private members of the class.
  72. #define ALLOW_DATATABLES_PRIVATE_ACCESS() \
  73. template <typename T> friend int ClientClassInit(T *);
  74. #define DECLARE_CLIENTCLASS_NOBASE ALLOW_DATATABLES_PRIVATE_ACCESS
  75. // This macro adds a ClientClass to the linked list in g_pClientClassHead (so
  76. // the list can be given to the engine).
  77. // Use this macro to expose your client class to the engine.
  78. // networkName must match the network name of a class registered on the server.
  79. #define IMPLEMENT_CLIENTCLASS(clientClassName, dataTable, serverClassName) \
  80. INTERNAL_IMPLEMENT_CLIENTCLASS_PROLOGUE(clientClassName, dataTable, serverClassName) \
  81. static IClientNetworkable* _##clientClassName##_CreateObject( int entnum, int serialNum ) \
  82. { \
  83. clientClassName *pRet = new clientClassName; \
  84. if ( !pRet ) \
  85. return 0; \
  86. pRet->Init( entnum, serialNum ); \
  87. return pRet; \
  88. } \
  89. ClientClass __g_##clientClassName##ClientClass(#serverClassName, \
  90. _##clientClassName##_CreateObject, \
  91. NULL,\
  92. &dataTable::g_RecvTable);
  93. // Implement a client class and provide a factory so you can allocate and delete it yourself
  94. // (or make it a singleton).
  95. #define IMPLEMENT_CLIENTCLASS_FACTORY(clientClassName, dataTable, serverClassName, factory) \
  96. INTERNAL_IMPLEMENT_CLIENTCLASS_PROLOGUE(clientClassName, dataTable, serverClassName) \
  97. ClientClass __g_##clientClassName##ClientClass(#serverClassName, \
  98. factory, \
  99. NULL,\
  100. &dataTable::g_RecvTable);
  101. // The IMPLEMENT_CLIENTCLASS_DT macros do IMPLEMENT_CLIENT_CLASS and also do BEGIN_RECV_TABLE.
  102. #define IMPLEMENT_CLIENTCLASS_DT(clientClassName, dataTable, serverClassName)\
  103. IMPLEMENT_CLIENTCLASS(clientClassName, dataTable, serverClassName)\
  104. BEGIN_RECV_TABLE(clientClassName, dataTable)
  105. #define IMPLEMENT_CLIENTCLASS_DT_NOBASE(clientClassName, dataTable, serverClassName)\
  106. IMPLEMENT_CLIENTCLASS(clientClassName, dataTable, serverClassName)\
  107. BEGIN_RECV_TABLE_NOBASE(clientClassName, dataTable)
  108. // Using IMPLEMENT_CLIENTCLASS_EVENT means the engine thinks the entity is an event so the entity
  109. // is responsible for freeing itself.
  110. #define IMPLEMENT_CLIENTCLASS_EVENT(clientClassName, dataTable, serverClassName)\
  111. INTERNAL_IMPLEMENT_CLIENTCLASS_PROLOGUE(clientClassName, dataTable, serverClassName)\
  112. static clientClassName __g_##clientClassName; \
  113. static IClientNetworkable* _##clientClassName##_CreateObject() {return &__g_##clientClassName;}\
  114. ClientClass __g_##clientClassName##ClientClass(#serverClassName, \
  115. NULL,\
  116. _##clientClassName##_CreateObject, \
  117. &dataTable::g_RecvTable);
  118. #define IMPLEMENT_CLIENTCLASS_EVENT_DT(clientClassName, dataTable, serverClassName)\
  119. namespace dataTable {extern RecvTable g_RecvTable;}\
  120. IMPLEMENT_CLIENTCLASS_EVENT(clientClassName, dataTable, serverClassName)\
  121. BEGIN_RECV_TABLE(clientClassName, dataTable)
  122. // Register a client event singleton but specify a pointer to give to the engine rather than
  123. // have a global instance. This is useful if you're using Initializers and your object's constructor
  124. // uses some other global object (so you must use Initializers so you're constructed afterwards).
  125. #define IMPLEMENT_CLIENTCLASS_EVENT_POINTER(clientClassName, dataTable, serverClassName, ptr)\
  126. INTERNAL_IMPLEMENT_CLIENTCLASS_PROLOGUE(clientClassName, dataTable, serverClassName)\
  127. static IClientNetworkable* _##clientClassName##_CreateObject() {return ptr;}\
  128. ClientClass __g_##clientClassName##ClientClass(#serverClassName, \
  129. NULL,\
  130. _##clientClassName##_CreateObject, \
  131. &dataTable::g_RecvTable);
  132. #define IMPLEMENT_CLIENTCLASS_EVENT_NONSINGLETON(clientClassName, dataTable, serverClassName)\
  133. static IClientNetworkable* _##clientClassName##_CreateObject() \
  134. { \
  135. clientClassName *p = new clientClassName; \
  136. if ( p ) \
  137. p->Init( -1, 0 ); \
  138. return p; \
  139. } \
  140. ClientClass __g_##clientClassName##ClientClass(#serverClassName, \
  141. NULL,\
  142. _##clientClassName##_CreateObject, \
  143. &dataTable::g_RecvTable);
  144. // Used internally..
  145. #define INTERNAL_IMPLEMENT_CLIENTCLASS_PROLOGUE(clientClassName, dataTable, serverClassName) \
  146. namespace dataTable {extern RecvTable g_RecvTable;}\
  147. extern ClientClass __g_##clientClassName##ClientClass;\
  148. RecvTable* clientClassName::m_pClassRecvTable = &dataTable::g_RecvTable;\
  149. int clientClassName::YouForgotToImplementOrDeclareClientClass() {return 0;}\
  150. ClientClass* clientClassName::GetClientClass() {return &__g_##clientClassName##ClientClass;}
  151. #endif // CLIENT_CLASS_H