| 1 |
/*************************************************************************** |
| 2 |
* Copyright (C) 2005-2019 by the FIFE team * |
| 3 |
* http://www.fifengine.net * |
| 4 |
* This file is part of FIFE. * |
| 5 |
* * |
| 6 |
* FIFE is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Lesser General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2.1 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
| 14 |
* Lesser General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Lesser General Public * |
| 17 |
* License along with this library; if not, write to the * |
| 18 |
* Free Software Foundation, Inc., * |
| 19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * |
| 20 |
***************************************************************************/ |
| 21 |
/*************************************************************************** |
| 22 |
* Note! FIFE event channel borrows heavily from ideas of Guichan library * |
| 23 |
* version 0.6 * |
| 24 |
***************************************************************************/ |
| 25 |
|
| 26 |
|
| 27 |
#ifndef FIFE_EVENTCHANNEL_EVENT_H |
| 28 |
#define FIFE_EVENTCHANNEL_EVENT_H |
| 29 |
|
| 30 |
// Standard C++ library includes |
| 31 |
// |
| 32 |
#include <string> |
| 33 |
#include <sstream> |
| 34 |
|
| 35 |
// 3rd party library includes |
| 36 |
// |
| 37 |
#include <SDL.h> |
| 38 |
|
| 39 |
// FIFE includes |
| 40 |
// These includes are split up in two parts, separated by one empty line |
| 41 |
// First block: files included from the FIFE root src directory |
| 42 |
// Second block: files included from the same folder |
| 43 |
// |
| 44 |
#include "eventchannel/source/ieventsource.h" |
| 45 |
|
| 46 |
namespace FIFE { |
| 47 |
/** Base class for all events |
| 48 |
*/ |
| 49 |
class Event { |
| 50 |
public: |
| 51 |
/** Constructor. |
| 52 |
*/ |
| 53 |
Event(): |
| 54 |
m_isConsumed(false), |
| 55 |
m_eventSource(NULL), |
| 56 |
m_timestamp(SDL_GetTicks()) {} |
| 57 |
|
| 58 |
/** Destructor. |
| 59 |
*/ |
| 60 |
virtual ~Event() {} |
| 61 |
|
| 62 |
/** Marks the event as consumed. |
| 63 |
*/ |
| 64 |
virtual void consume() { m_isConsumed = true; } |
| 65 |
|
| 66 |
/** Checks if the event is consumed. |
| 67 |
* @return true if the event is consumed, false otherwise. |
| 68 |
*/ |
| 69 |
virtual bool isConsumed() const { return m_isConsumed; } |
| 70 |
|
| 71 |
/** Gets the source of the event. |
| 72 |
*/ |
| 73 |
virtual IEventSource* getSource() const { return m_eventSource; } |
| 74 |
|
| 75 |
/** Sets the source of the event. |
| 76 |
*/ |
| 77 |
virtual void setSource(IEventSource* source) { m_eventSource = source; } |
| 78 |
|
| 79 |
/** Gets the timestamp of the event |
| 80 |
*/ |
| 81 |
virtual int32_t getTimeStamp() const { return m_timestamp; } |
| 82 |
|
| 83 |
/** Sets the timestamp of the event |
| 84 |
*/ |
| 85 |
virtual void setTimeStamp(int32_t timestamp ) { m_timestamp = timestamp; } |
| 86 |
|
| 87 |
/** Gets the name of the event |
| 88 |
*/ |
| 89 |
virtual const std::string& getName() const { |
| 90 |
const static std::string eventName("Event"); |
| 91 |
return eventName; |
| 92 |
} |
| 93 |
|
| 94 |
/** Gets attribute string of the event |
| 95 |
*/ |
| 96 |
virtual std::string getAttrStr() const { |
| 97 |
std::stringstream ss; |
| 98 |
ss << "consumed = " << m_isConsumed << ", "; |
| 99 |
ss << "src = " << m_eventSource << ", "; |
| 100 |
ss << "timestamp = " << m_timestamp; |
| 101 |
return ss.str(); |
| 102 |
} |
| 103 |
|
| 104 |
/** Gets the debugstring of the event |
| 105 |
*/ |
| 106 |
virtual std::string getDebugString() const { |
| 107 |
std::stringstream ss; |
| 108 |
ss << getName() << std::endl; |
| 109 |
ss << getAttrStr() << std::endl; |
| 110 |
return ss.str(); |
| 111 |
} |
| 112 |
|
| 113 |
private: |
| 114 |
//! Indicates if the event is consumed. |
| 115 |
bool m_isConsumed; |
| 116 |
//! The source of the event. |
| 117 |
IEventSource* m_eventSource; |
| 118 |
//! Timestamp of the event. |
| 119 |
int32_t m_timestamp; |
| 120 |
}; |
| 121 |
|
| 122 |
} //FIFE |
| 123 |
|
| 124 |
#endif |