Game Development Reference
In-Depth Information
virtual const EventType& VGetEventType(void) const = 0;
virtual float VGetTimeStamp(void) const = 0;
virtual void VSerialize(std::ostrstream& out) const = 0;
virtual IEventDataPtr VCopy(void) const = 0;
virtual const char* GetName(void) const = 0;
};
class BaseEventData : public IEventData
{
const float m_timeStamp;
public:
explicit BaseEventData(const float timeStamp = 0.0f) :
m_timeStamp(timeStamp) { }
virtual
BaseEventData(void) {}
˜
// Returns the type of the event
virtual const EventType& VGetEventType(void) const = 0;
float VGetTimeStamp(void) const { return m_timeStamp; }
// Serializing for network out.
virtual void VSerialize(std::ostrstream &out) const { }
};
Choose Your Stream Implementation Carefully
Did you note the use of std::ostrstream in the previous code snippet? This was chosen to make the
stream human readable, which can be very useful during development, but a big mistake for any
shipping game. For one thing, a human-readable stream is trivial to hack. More importantly, the stream
is large and takes much longer to load and parse than a binary stream. Try using std::ostream
instead or your own custom stream class.
An event encapsulates the event type, the event data, and the time the event
occurred. Event data is defined by you, the programmer, and you are free to create
ad hoc data that will accompany your event. It ' s a little easier to see what ' s going on
with a concrete example. Recall from Chapter 6,
Game Actors and Component
Architecture,
s used for tracking purposes. Now, if
an actor is ever destroyed, this ActorId would get sent along with an event so
other subsystems could remove the actor from their lists. The event data class for
an
that every actor has an ID that
'
actor destroyed
event would look like this:
typedef unsigned long EventType;
class EvtData_Destroy_Actor : public BaseEventData
 
Search WWH ::




Custom Search