On Sat, Mar 29, 2008 at 3:21 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
AMDG

Robert Dailey wrote:
> Is there any reason why the ID needs to be available at runtime?
> Instead of your specialization, I do:
>
> class WalkPacket : Packet
> {
>     static const PacketId ID = PID_WALKPACKET;
> };
>
> Is there any reason why this isn't sufficient?

The dispatcher needs to know what the ID of a packet is to
do its job.  The idea is that instead of passing the ID and the packet
separately,
the packet knows its own ID.  It is possible, though to replace the ID
type with
std::string in the dispatcher and use std::string(typeid(packet).name())
avoiding the ID's entirely inside the dispatcher.

It seems that so far we've gotten everything done without RTTI, I would hate to introduce it here. I see what you're saying now. Something like this might be in order:

struct Packet
{
    virtual PacketId GetId() const = 0;
};

struct WalkPacket : Packet
{
    static const PacketId ID = PID_WALKPACKET;
    virtual PacketId GetId() const { return ID; }
};