Coding style fixes.

This commit is contained in:
hiker 2015-10-21 07:51:53 +11:00
parent 54a0e50fe3
commit 94e87796f5
2 changed files with 53 additions and 42 deletions

View File

@ -23,6 +23,9 @@
#include <string.h> #include <string.h>
/** \brief Constructor
* \param event : The event that needs to be translated.
*/
Event::Event(ENetEvent* event) Event::Event(ENetEvent* event)
{ {
switch (event->type) switch (event->type)
@ -42,15 +45,17 @@ Event::Event(ENetEvent* event)
} }
if (type == EVENT_TYPE_MESSAGE) if (type == EVENT_TYPE_MESSAGE)
{ {
m_data = NetworkString(std::string((char*)(event->packet->data), event->packet->dataLength-1)); m_data = NetworkString(std::string((char*)(event->packet->data),
event->packet->dataLength-1));
} }
m_packet = NULL; m_packet = NULL;
if (event->packet) if (event->packet)
{
m_packet = event->packet; m_packet = event->packet;
// we got all we need, just remove the data.
if (m_packet) enet_packet_destroy(m_packet);
enet_packet_destroy(m_packet); // we got all we need, just remove the data. }
m_packet = NULL; m_packet = NULL;
std::vector<STKPeer*> peers = NetworkManager::getInstance()->getPeers(); std::vector<STKPeer*> peers = NetworkManager::getInstance()->getPeers();
@ -61,7 +66,8 @@ Event::Event(ENetEvent* event)
if (peers[i]->m_peer == event->peer) if (peers[i]->m_peer == event->peer)
{ {
*peer = peers[i]; *peer = peers[i];
Log::verbose("Event", "The peer you sought has been found on %p", peer); Log::verbose("Event", "The peer you sought has been found on %p",
peer);
return; return;
} }
} }
@ -70,28 +76,38 @@ Event::Event(ENetEvent* event)
STKPeer* new_peer = new STKPeer(); STKPeer* new_peer = new STKPeer();
new_peer->m_peer = event->peer; new_peer->m_peer = event->peer;
*peer = new_peer; *peer = new_peer;
Log::debug("Event", "Creating a new peer, address are STKPeer:%p, Peer:%p", new_peer, event->peer); Log::debug("Event",
"Creating a new peer, address are STKPeer:%p, Peer:%p",
new_peer, event->peer);
} }
} } // Event(ENetEvent)
// ----------------------------------------------------------------------------
/** \brief Constructor
* \param event : The event to copy.
*/
Event::Event(const Event& event) Event::Event(const Event& event)
{ {
m_packet = NULL;
m_data = event.m_data;
// copy the peer
peer = event.peer;
type = event.type; type = event.type;
} m_packet = NULL;
m_data = event.m_data;
// copy the peer
peer = event.peer;
} // Event(Event)
// ----------------------------------------------------------------------------
/** \brief Destructor that frees the memory of the package.
*/
Event::~Event() Event::~Event()
{ {
delete peer; delete peer;
peer = NULL; peer = NULL;
m_packet = NULL; m_packet = NULL;
} } // ~Event
// ----------------------------------------------------------------------------
void Event::removeFront(int size) void Event::removeFront(int size)
{ {
m_data.removeFront(size); m_data.removeFront(size);
} } // removeFront

View File

@ -51,37 +51,32 @@ enum EVENT_TYPE
*/ */
class Event class Event
{ {
public: private:
/*! \brief Constructor /** Copy of the data passed by the event. */
* \param event : The event that needs to be translated. NetworkString m_data;
*/
Event(ENetEvent* event);
/*! \brief Constructor
* \param event : The event to copy.
*/
Event(const Event& event);
/*! \brief Destructor
* frees the memory of the ENetPacket.
*/
~Event();
/*! \brief Remove bytes at the beginning of data. /** A pointer on the ENetPacket to be deleted. */
* \param size : The number of bytes to remove. ENetPacket* m_packet;
*/
void removeFront(int size);
/*! \brief Get a copy of the data. public:
* \return A copy of the message data. This is empty for events like Event(ENetEvent* event);
* connection or disconnections. Event(const Event& event);
*/ ~Event();
NetworkString data() const { return m_data; }
EVENT_TYPE type; //!< Type of the event. /*! \brief Remove bytes at the beginning of data.
STKPeer** peer; //!< Pointer to the peer that triggered that event. * \param size : The number of bytes to remove.
*/
void removeFront(int size);
private: /*! \brief Get a copy of the data.
NetworkString m_data; //!< Copy of the data passed by the event. * \return A copy of the message data. This is empty for events like
ENetPacket* m_packet; //!< A pointer on the ENetPacket to be deleted. * connection or disconnections.
}; */
NetworkString data() const { return m_data; }
EVENT_TYPE type; //!< Type of the event.
STKPeer** peer; //!< Pointer to the peer that triggered that event.
}; // class Event
#endif // EVENT_HPP #endif // EVENT_HPP