wavelength 1.0.0
Loading...
Searching...
No Matches
welcomepkt.h
Go to the documentation of this file.
1#pragma once
2
5#include "os/mem.h"
6
13extern int g_nWelcomePktType;
14
22class WelcomePkt : public InternalPacket {
23public:
29 WelcomePkt() = default;
30
40 WelcomePkt(int nReceiver, int nColor, const NetGameParams &params)
41 : InternalPacket(kFlagOrdered | kFlagGuaranteed, nReceiver), mColor(nColor),
42 mParams(params) {
43 }
44
52 static Message *New();
53
60 void *operator new(size_t nSize) {
61 return PoolMemAlloc(static_cast<int>(nSize), "WelcomePkt", 0);
62 }
63
69 void operator delete(void *pBlock) {
70 PoolMemFree(pBlock);
71 }
72
78 Message *Clone() override {
79 return new WelcomePkt(*this);
80 }
81
87 int Type() override {
88 return g_nWelcomePktType;
89 }
90
96 const char *GetName() const override {
97 return "WelcomePkt";
98 }
99
107 void PrintExtra(PrnStream &stream) const override;
108
116 void saveGuts(BinStream &stream) const override;
117
125 void restoreGuts(BinStream &stream) override;
126
128 int GetColor() const {
129 return mColor;
130 }
131
133 const NetGameParams &GetParams() const {
134 return mParams;
135 }
136
137private:
138 int mColor;
139 NetGameParams mParams;
140};
Stream of raw bytes, the base of the memory, file, and network streams.
Definition binstream.h:22
InternalPacket(unsigned char nFlags=0, int nReceiver=kUnset)
Construct a packet from an unset sender.
Definition internalpacket.h:33
Base of every event the game passes between a MsgSource and a MsgSink.
Definition message.h:40
The settings of an online game that the host publishes with its session.
Definition netgameparams.h:13
static constexpr unsigned char kFlagGuaranteed
Bit of mFlags that NetTransport::Send() turns into its guaranteed delivery bit.
Definition packet.h:28
static constexpr unsigned char kFlagOrdered
Bit of mFlags that LaunchpadRT::Send() turns into the second delivery bit of the session library.
Definition packet.h:25
Text output stream.
Definition prnstream.h:16
const char * GetName() const override
Report this packet's class name.
Definition welcomepkt.h:96
void PrintExtra(PrnStream &stream) const override
Write the sender, the receiver, the colour, and the settings.
WelcomePkt()=default
Construct a packet with the default settings.
WelcomePkt(int nReceiver, int nColor, const NetGameParams &params)
Construct a packet for one peer, ordered and guaranteed.
Definition welcomepkt.h:40
int GetColor() const
Definition welcomepkt.h:128
static Message * New()
Produce a default-constructed packet on the heap.
Message * Clone() override
Produce a heap copy of this packet.
Definition welcomepkt.h:78
const NetGameParams & GetParams() const
Definition welcomepkt.h:133
int Type() override
Report this packet's registered identity.
Definition welcomepkt.h:87
void saveGuts(BinStream &stream) const override
Write the colour as a byte and the settings.
void restoreGuts(BinStream &stream) override
Read what saveGuts() wrote.
void * PoolMemAlloc(int nSize, const char *pszTag, int nAlign)
Allocate a block from the pool heaps and bill it to a tag.
void PoolMemFree(void *pBlock)
Return a block PoolMemAlloc() handed out to the pool heap that owns it.
int g_nWelcomePktType
Identity that WelcomePkt::Type() reports.