wavelength 1.0.0
Loading...
Searching...
No Matches
gameoverpkt.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4
5#include "game/netgamescore.h"
7#include "os/mem.h"
8
15extern int g_nGameOverPktType;
16
24public:
30 GameOverPkt() = default;
31
39 explicit GameOverPkt(const std::vector<NetGameScore> &scores)
40 : InternalPacket(kFlagGuaranteed, kAllPeers), mScores(scores) {
41 }
42
50 static Message *New();
51
58 void *operator new(size_t nSize) {
59 return PoolMemAlloc(static_cast<int>(nSize), "GameOverPkt", 0);
60 }
61
67 void operator delete(void *pBlock) {
68 PoolMemFree(pBlock);
69 }
70
76 Message *Clone() override {
77 return new GameOverPkt(*this);
78 }
79
85 int Type() override {
86 return g_nGameOverPktType;
87 }
88
94 const char *GetName() const override {
95 return "GameOverPkt";
96 }
97
105 void PrintExtra(PrnStream &stream) const override;
106
114 void saveGuts(BinStream &stream) const override;
115
123 void restoreGuts(BinStream &stream) override;
124
126 const std::vector<NetGameScore> &GetScores() const {
127 return mScores;
128 }
129
130private:
131 std::vector<NetGameScore> mScores;
132};
Stream of raw bytes, the base of the memory, file, and network streams.
Definition binstream.h:22
const char * GetName() const override
Report this packet's class name.
Definition gameoverpkt.h:94
static Message * New()
Produce a default-constructed packet on the heap.
GameOverPkt()=default
Construct a packet with no scores.
void saveGuts(BinStream &stream) const override
Write the scores.
void PrintExtra(PrnStream &stream) const override
Write the sender, the receiver, and the scores.
const std::vector< NetGameScore > & GetScores() const
Definition gameoverpkt.h:126
void restoreGuts(BinStream &stream) override
Read the scores.
int Type() override
Report this packet's registered identity.
Definition gameoverpkt.h:85
GameOverPkt(const std::vector< NetGameScore > &scores)
Construct a packet for every peer, guaranteed.
Definition gameoverpkt.h:39
Message * Clone() override
Produce a heap copy of this packet.
Definition gameoverpkt.h:76
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
static constexpr unsigned char kFlagGuaranteed
Bit of mFlags that NetTransport::Send() turns into its guaranteed delivery bit.
Definition packet.h:28
static constexpr int kAllPeers
Value of mReceiver that addresses every peer.
Definition packet.h:19
Text output stream.
Definition prnstream.h:16
int g_nGameOverPktType
Identity that GameOverPkt::Type() reports.
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.