RemoteEvent.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #ifndef SCENE_REMOTEEVENT_H
  24. #define SCENE_REMOTEEVENT_H
  25. #include "Object.h"
  26. class Connection;
  27. class Deserializer;
  28. class Scene;
  29. class Serializer;
  30. //! An event to be sent over the network
  31. struct RemoteEvent
  32. {
  33. //! Construct as undefined
  34. RemoteEvent()
  35. {
  36. }
  37. //! Construct with parameters
  38. RemoteEvent(StringHash eventType, const VariantMap& eventData, Connection* receiver, unsigned short timeToLive) :
  39. nodeID_(0),
  40. eventType_(eventType),
  41. eventData_(eventData),
  42. receiver_(receiver),
  43. timeToLive_(timeToLive)
  44. {
  45. }
  46. //! Construct with target entity and parameters
  47. RemoteEvent(unsigned nodeID, StringHash eventType, const VariantMap& eventData, Connection* receiver, unsigned short timeToLive) :
  48. nodeID_(nodeID),
  49. eventType_(eventType),
  50. eventData_(eventData),
  51. receiver_(receiver),
  52. timeToLive_(timeToLive)
  53. {
  54. }
  55. //! Write to a stream
  56. void Write(Serializer& dest) const;
  57. //! Read from a stream
  58. void Read(Deserializer& source, bool hasEntity);
  59. //! Dispatch at the remote end
  60. bool Dispatch(Connection* sender, Scene* scene);
  61. //! Frame number
  62. unsigned short frameNumber_;
  63. //! Event type
  64. StringHash eventType_;
  65. //! Event parameters
  66. VariantMap eventData_;
  67. //! Target entity ID
  68. unsigned nodeID_;
  69. //! Receiving connection. If null on the server, broadcast to all. On client has no significance
  70. Connection* receiver_;
  71. //! Time to live in network frames. If not acked when expires, will no longer be sent. 0 is infinite
  72. unsigned short timeToLive_;
  73. };
  74. #endif // SCENE_REMOTEEVENT_H