Team Fortress 2 Source Code as on 22/4/2020
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.

107 lines
3.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef ICLIENTNETWORKABLE_H
  8. #define ICLIENTNETWORKABLE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "iclientunknown.h"
  13. #include "tier1/bitbuf.h"
  14. class IClientEntity;
  15. class ClientClass;
  16. enum ShouldTransmitState_t
  17. {
  18. SHOULDTRANSMIT_START=0, // The entity is starting to be transmitted (maybe it entered the PVS).
  19. SHOULDTRANSMIT_END // Called when the entity isn't being transmitted by the server.
  20. // This signals a good time to hide the entity until next time
  21. // the server wants to transmit its state.
  22. };
  23. // NOTE: All of these are commented out; NotifyShouldTransmit actually
  24. // has all these in them. Left it as an enum in case we want to go back though
  25. enum DataUpdateType_t
  26. {
  27. DATA_UPDATE_CREATED = 0, // indicates it was created +and+ entered the pvs
  28. // DATA_UPDATE_ENTERED_PVS,
  29. DATA_UPDATE_DATATABLE_CHANGED,
  30. // DATA_UPDATE_LEFT_PVS,
  31. // DATA_UPDATE_DESTROYED, // FIXME: Could enable this, but it's a little worrying
  32. // since it changes a bunch of existing code
  33. };
  34. abstract_class IClientNetworkable
  35. {
  36. public:
  37. // Gets at the containing class...
  38. virtual IClientUnknown* GetIClientUnknown() = 0;
  39. // Called by the engine when the server deletes the entity.
  40. virtual void Release() = 0;
  41. // Supplied automatically by the IMPLEMENT_CLIENTCLASS macros.
  42. virtual ClientClass* GetClientClass() = 0;
  43. // This tells the entity what the server says for ShouldTransmit on this entity.
  44. // Note: This used to be EntityEnteredPVS/EntityRemainedInPVS/EntityLeftPVS.
  45. virtual void NotifyShouldTransmit( ShouldTransmitState_t state ) = 0;
  46. //
  47. // NOTE FOR ENTITY WRITERS:
  48. //
  49. // In 90% of the cases, you should hook OnPreDataChanged/OnDataChanged instead of
  50. // PreDataUpdate/PostDataUpdate.
  51. //
  52. // The DataChanged events are only called once per frame whereas Pre/PostDataUpdate
  53. // are called once per packet (and sometimes multiple times per frame).
  54. //
  55. // OnDataChanged is called during simulation where entity origins are correct and
  56. // attachments can be used. whereas PostDataUpdate is called while parsing packets
  57. // so attachments and other entity origins may not be valid yet.
  58. //
  59. virtual void OnPreDataChanged( DataUpdateType_t updateType ) = 0;
  60. virtual void OnDataChanged( DataUpdateType_t updateType ) = 0;
  61. // Called when data is being updated across the network.
  62. // Only low-level entities should need to know about these.
  63. virtual void PreDataUpdate( DataUpdateType_t updateType ) = 0;
  64. virtual void PostDataUpdate( DataUpdateType_t updateType ) = 0;
  65. // Objects become dormant on the client if they leave the PVS on the server.
  66. virtual bool IsDormant( void ) = 0;
  67. // Ent Index is the server handle used to reference this entity.
  68. // If the index is < 0, that indicates the entity is not known to the server
  69. virtual int entindex( void ) const = 0;
  70. // Server to client entity message received
  71. virtual void ReceiveMessage( int classID, bf_read &msg ) = 0;
  72. // Get the base pointer to the networked data that GetClientClass->m_pRecvTable starts at.
  73. // (This is usually just the "this" pointer).
  74. virtual void* GetDataTableBasePtr() = 0;
  75. // Tells the entity that it's about to be destroyed due to the client receiving
  76. // an uncompressed update that's caused it to destroy all entities & recreate them.
  77. virtual void SetDestroyedOnRecreateEntities( void ) = 0;
  78. virtual void OnDataUnchangedInPVS() = 0;
  79. };
  80. #endif // ICLIENTNETWORKABLE_H