Leviathan  0.8.0.0
Leviathan game engine
Leviathan::Event Class Reference

Class that represents a statically defined event. More...

#include <Event.h>

+ Inheritance diagram for Leviathan::Event:

Public Member Functions

DLLEXPORT Event (sf::Packet &packet)
 Loads this event from a packet. More...
 
DLLEXPORT Event (EVENT_TYPE type, BaseEventData *data)
 Creates a new event. More...
 
DLLEXPORT ~Event ()
 
DLLEXPORT EVENT_TYPE GetType () const
 Gets the Type of the event. More...
 
DLLEXPORT void AddDataToPacket (sf::Packet &packet) const
 Saves this event to a packet. More...
 
DLLEXPORT ClientInterpolationEventDataGetDataForClientInterpolationEvent () const
 
DLLEXPORT IntegerEventDataGetIntegerDataForEvent () const
 Gets the data if this is an event that has only one integer data member. More...
 
 REFERENCE_COUNTED_PTR_TYPE (Event)
 
- Public Member Functions inherited from Leviathan::ReferenceCounted
 ReferenceCounted (const ReferenceCounted &other)=delete
 
ReferenceCountedoperator= (const ReferenceCounted &other)=delete
 
FORCE_INLINE void AddRef ()
 
FORCE_INLINE void Release ()
 removes a reference and deletes the object if reference count reaches zero More...
 
int32_t GetRefCount () const
 Returns the reference count. More...
 

Protected Attributes

EVENT_TYPE Type
 Events type. More...
 
BaseEventDataData
 Direct pointer to the data. More...
 

Additional Inherited Members

- Public Types inherited from Leviathan::ReferenceCounted
using basepointer = boost::intrusive_ptr< ReferenceCounted >
 
using refcountedpointer = boost::intrusive_ptr< ReferenceCounted >
 
- Static Public Member Functions inherited from Leviathan::ReferenceCounted
template<class ActualType >
static boost::intrusive_ptr< ActualType > WrapPtr (ActualType *ptr)
 Creates an intrusive_ptr from raw pointer. More...
 
template<class ActualType , class... Args>
static boost::intrusive_ptr< ActualType > MakeShared (Args &&... args)
 Constructs a new instance and wraps it. More...
 
- Protected Member Functions inherited from Leviathan::ReferenceCounted
DLLEXPORT ReferenceCounted ()
 
virtual DLLEXPORT ~ReferenceCounted ()
 

Detailed Description

Class that represents a statically defined event.

Definition at line 109 of file Event.h.

Constructor & Destructor Documentation

◆ Event() [1/2]

DLLEXPORT Leviathan::Event::Event ( sf::Packet &  packet)

Loads this event from a packet.

Definition at line 44 of file Event.cpp.

45 {
46  // Get the type from the packet //
47  int tmptype;
48 
49  if(!(packet >> tmptype)) {
50 
51  throw InvalidArgument("packet has invalid format");
52  }
53 
54  // Set our type //
55  Type = static_cast<EVENT_TYPE>(tmptype);
56 
57  // Load based on type //
58  switch(Type) {
61  case EVENT_TYPE_TICK: {
62  Data = new IntegerEventData(packet);
63  break;
64  }
66  Data = new ClientInterpolationEventData(packet);
67  break;
68  }
69  default:
70  // No data required //
71  Data = NULL;
72  }
73 }
EVENT_TYPE Type
Events type.
Definition: Event.h:134
EVENT_TYPE
Engine events that are triggered at certain times.
Definition: Event.h:13
BaseEventData * Data
Direct pointer to the data.
Definition: Event.h:137
Data for EVENT_TYPE_ENGINE_TICK and all others that have only int data.
Definition: Event.h:95
Data for EVENT_TYPE_CLIENT_INTERPOLATION.
Definition: Event.h:68

◆ Event() [2/2]

DLLEXPORT Leviathan::Event::Event ( EVENT_TYPE  type,
BaseEventData data 
)

Creates a new event.

Warning
Funky things can happen if the type doesn't match the type of data

Definition at line 9 of file Event.cpp.

9  :
10  Type(type), Data(data)
11 {
12  // Check that types that require values have values //
13  if(!Data) {
14  // Check that the event has data //
16  Type == EVENT_TYPE_TICK) {
17 
18  throw InvalidArgument("Event that requires data, didn't get it");
19  }
20  }
21 }
EVENT_TYPE Type
Events type.
Definition: Event.h:134
BaseEventData * Data
Direct pointer to the data.
Definition: Event.h:137

◆ ~Event()

Event::~Event ( )

Definition at line 23 of file Event.cpp.

24 {
25  // Delete our data //
27 }
BaseEventData * Data
Direct pointer to the data.
Definition: Event.h:137
#define SAFE_DELETE(x)
Definition: Define.h:116

Member Function Documentation

◆ AddDataToPacket()

DLLEXPORT void Leviathan::Event::AddDataToPacket ( sf::Packet &  packet) const

Saves this event to a packet.

Definition at line 34 of file Event.cpp.

35 {
36  // Add the type first //
37  packet << (int)Type;
38 
39  // Add the data object //
40  if(Data)
41  Data->AddDataToPacket(packet);
42 }
virtual void AddDataToPacket(sf::Packet &packet)=0
Adds this to a packet for retrieving it later.
EVENT_TYPE Type
Events type.
Definition: Event.h:134
BaseEventData * Data
Direct pointer to the data.
Definition: Event.h:137

◆ GetDataForClientInterpolationEvent()

DLLEXPORT ClientInterpolationEventData * Event::GetDataForClientInterpolationEvent ( ) const

Definition at line 75 of file Event.cpp.

76 {
78  return static_cast<ClientInterpolationEventData*>(Data);
79  return NULL;
80 }
EVENT_TYPE Type
Events type.
Definition: Event.h:134
BaseEventData * Data
Direct pointer to the data.
Definition: Event.h:137
Data for EVENT_TYPE_CLIENT_INTERPOLATION.
Definition: Event.h:68

◆ GetIntegerDataForEvent()

DLLEXPORT IntegerEventData * Leviathan::Event::GetIntegerDataForEvent ( ) const

Gets the data if this is an event that has only one integer data member.

Definition at line 82 of file Event.cpp.

83 {
86  return static_cast<IntegerEventData*>(Data);
87  return NULL;
88 }
EVENT_TYPE Type
Events type.
Definition: Event.h:134
BaseEventData * Data
Direct pointer to the data.
Definition: Event.h:137
Data for EVENT_TYPE_ENGINE_TICK and all others that have only int data.
Definition: Event.h:95

◆ GetType()

DLLEXPORT EVENT_TYPE Leviathan::Event::GetType ( ) const

Gets the Type of the event.

Definition at line 29 of file Event.cpp.

30 {
31  return Type;
32 }
EVENT_TYPE Type
Events type.
Definition: Event.h:134

◆ REFERENCE_COUNTED_PTR_TYPE()

Leviathan::Event::REFERENCE_COUNTED_PTR_TYPE ( Event  )

Member Data Documentation

◆ Data

BaseEventData* Leviathan::Event::Data
protected

Direct pointer to the data.

Definition at line 137 of file Event.h.

◆ Type

EVENT_TYPE Leviathan::Event::Type
protected

Events type.

Definition at line 134 of file Event.h.


The documentation for this class was generated from the following files: