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 138 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 45 of file Event.cpp.

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

◆ 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:166
BaseEventData * Data
Direct pointer to the data.
Definition: Event.h:169

◆ ~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:169
#define SAFE_DELETE(x)
Definition: Define.h:141

Member Function Documentation

◆ AddDataToPacket()

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

Saves this event to a packet.

Definition at line 35 of file Event.cpp.

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

◆ GetDataForClientInterpolationEvent()

DLLEXPORT ClientInterpolationEventData * Event::GetDataForClientInterpolationEvent ( ) const

Definition at line 77 of file Event.cpp.

78 {
80  return static_cast<ClientInterpolationEventData*>(Data);
81  return NULL;
82 }
EVENT_TYPE Type
Events type.
Definition: Event.h:166
BaseEventData * Data
Direct pointer to the data.
Definition: Event.h:169
Data for EVENT_TYPE_CLIENT_INTERPOLATION.
Definition: Event.h:93

◆ 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 84 of file Event.cpp.

85 {
88  return static_cast<IntegerEventData*>(Data);
89  return NULL;
90 }
EVENT_TYPE Type
Events type.
Definition: Event.h:166
BaseEventData * Data
Direct pointer to the data.
Definition: Event.h:169
Data for EVENT_TYPE_ENGINE_TICK and all others that have only int data.
Definition: Event.h:122

◆ 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:166

◆ 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 169 of file Event.h.

◆ Type

EVENT_TYPE Leviathan::Event::Type
protected

Events type.

Definition at line 166 of file Event.h.


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