/Code/CryEngine/CryLiveCreate/LiveCreateHost.h

https://gitlab.com/dahbearz/CRYENGINE · C Header · 206 lines · 135 code · 46 blank · 25 comment · 2 complexity · cd82c644ad6bba0eba7b6f1fb540e561 MD5 · raw file

  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2. #ifndef _H_LIVECREATEHOST_H_
  3. #define _H_LIVECREATEHOST_H_
  4. //////////////////////////////////////////////////////////////////////////
  5. //////////////////////////////////////////////////////////////////////////
  6. #include <CryLiveCreate/ILiveCreateHost.h>
  7. #include <CryNetwork/IServiceNetwork.h>
  8. #include <CryLiveCreate/ILiveCreateCommon.h>
  9. #include <CryThreading/IThreadManager.h>
  10. #include <CryNetwork/CrySocks.h>
  11. struct IServiceNetworkListener;
  12. struct IServiceNetworkConnection;
  13. struct IServiceNetworkMessage;
  14. struct IRemoteCommandServer;
  15. #ifndef NO_LIVECREATE
  16. namespace LiveCreate
  17. {
  18. //-----------------------------------------------------------------------------
  19. struct SSelectedObject
  20. {
  21. Vec3 m_position;
  22. uint8 m_flags;
  23. string m_name;
  24. Matrix34 m_matrix;
  25. AABB m_box;
  26. ILINE SSelectedObject()
  27. : m_flags(0)
  28. , m_position(0, 0, 0)
  29. {
  30. }
  31. template<class T>
  32. friend T& operator<<(T& stream, SSelectedObject& obj)
  33. {
  34. stream << obj.m_flags;
  35. stream << obj.m_position;
  36. if (obj.m_flags & 1)
  37. {
  38. stream << obj.m_name;
  39. }
  40. if (obj.m_flags & 2)
  41. {
  42. stream << obj.m_matrix;
  43. stream << obj.m_box.min;
  44. stream << obj.m_box.max;
  45. }
  46. return stream;
  47. }
  48. };
  49. //-----------------------------------------------------------------------------
  50. /// LiveCreate "are you there" service with basic file transfer functionality
  51. class CPlatformService : public IThread
  52. {
  53. private:
  54. class CHost* m_pHost;
  55. CRYSOCKET m_socket;
  56. uint16 m_port;
  57. volatile bool m_bQuiet;
  58. public:
  59. CPlatformService(class CHost* pHost, const uint16 listeningPort);
  60. virtual ~CPlatformService();
  61. virtual void ThreadEntry();
  62. void SignalStopWork() { m_bQuiet = true; }
  63. bool Bind();
  64. bool Process(IDataReadStream& reader, IDataWriteStream& writer);
  65. };
  66. //-----------------------------------------------------------------------------
  67. /// LiveCreate file transfer and utility service
  68. class CUtilityService : public IThread
  69. {
  70. private:
  71. class CHost* m_pHost;
  72. // TCP/IP listener for file-based traffic
  73. IServiceNetworkListener* m_pListener;
  74. volatile bool m_bQuit;
  75. // File transfer (a single connection)
  76. class FileTransferInProgress
  77. {
  78. private:
  79. IServiceNetworkConnection* m_pConnection;
  80. FILE* m_destFile;
  81. string m_destFilePath;
  82. uint32 m_fileSize;
  83. uint32 m_fileDataLeft;
  84. CTimeValue m_startTime;
  85. public:
  86. inline const string& GetFileName() const
  87. {
  88. return m_destFilePath;
  89. }
  90. public:
  91. FileTransferInProgress(IServiceNetworkConnection* pConnection, const string& destFilePath, FILE* destFile, const uint32 fileSize);
  92. ~FileTransferInProgress();
  93. // update (returns true if finished)
  94. bool Update();
  95. };
  96. typedef std::vector<FileTransferInProgress*> TFileTransferList;
  97. TFileTransferList m_fileTransfers;
  98. public:
  99. CUtilityService(class CHost* pHost, const uint16 listeningPort);
  100. virtual ~CUtilityService();
  101. virtual void ThreadEntry();
  102. void SignalStopWork() { m_bQuiet = true; }
  103. };
  104. //-----------------------------------------------------------------------------
  105. /// LiveCreate host interface
  106. class CHost : public IHost
  107. , public IRemoteCommandListenerSync
  108. , public IRemoteCommandListenerAsync
  109. {
  110. public:
  111. CHost();
  112. virtual ~CHost();
  113. // IHost interface
  114. virtual bool Initialize(const uint16 listeningPort = kDefaultHostListenPort,
  115. const uint16 discoveryServiceListeningPort = kDefaultDiscoverySerivceListenPost,
  116. const uint16 fileTransferServiceListeningPort = kDefaultFileTransferServicePort);
  117. virtual void Close();
  118. virtual void SuppressCommandExecution();
  119. virtual void ResumeCommandExecution();
  120. virtual void ExecuteCommands();
  121. virtual void DrawOverlay();
  122. // IRemoteCommandListener interface implementation
  123. virtual bool OnRawMessageSync(const ServiceNetworkAddress& remoteAddress, struct IDataReadStream& msg, struct IDataWriteStream& response);
  124. virtual bool OnRawMessageAsync(const ServiceNetworkAddress& remoteAddress, struct IDataReadStream& msg, struct IDataWriteStream& response);
  125. private:
  126. IRemoteCommandServer* m_pCommandServer;
  127. // Entity CRC
  128. typedef std::map<EntityId, uint> TEntityCRCMap;
  129. TEntityCRCMap m_entityCrc;
  130. // Sync&Refresh
  131. bool m_updateTimeOfDay;
  132. bool m_bCommandsSuppressed;
  133. // Selection data
  134. typedef std::vector<SSelectedObject> TSelectionObjects;
  135. TSelectionObjects m_selection;
  136. // General host platform service (UDP listening socket)
  137. CPlatformService* m_pPlatformService;
  138. // General file-transfer and utility service (CopyFrom/CopyTo)
  139. CUtilityService* m_pUtilityService;
  140. // IDs of executed console commands - (prevents from executing the same command twice in case it was resent)
  141. typedef std::set<CryGUID> TLastCommandIDs;
  142. TLastCommandIDs m_lastConsoleCommandsExecuted;
  143. public:
  144. // Entity CRC management
  145. bool GetEntityCRC(EntityId id, uint32& outCrc) const;
  146. void SetEntityCRC(EntityId id, const uint32 outCrc);
  147. void RemoveEntityCRC(EntityId id);
  148. // FullSync level data parsing
  149. bool SyncFullLevelState(const char* szFileName);
  150. // Selection display
  151. void ClearSelectionData();
  152. void SetSelectionData(const std::vector<SSelectedObject>& selectedObjects);
  153. void DrawSelection();
  154. void RequestTimeOfDayUpdate();
  155. void FillHostInfo(CHostInfoPacket& outHostInfo) const;
  156. };
  157. //-----------------------------------------------------------------------------
  158. }
  159. #endif
  160. #endif