wavelength 1.0.0
Loading...
Searching...
No Matches
bumperpacket.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4
6#include "os/mem.h"
7
14extern int g_nBumperPacketType;
15
23public:
30 ~BumperPacket() override = default;
31
33 class VictimData {
34 public:
36 VictimData() = default;
37
46 VictimData(int nNetOrder, int nTrack) : mNetOrder(nNetOrder), mTrack(nTrack) {
47 }
48
50 int mTrack;
51 };
52
60
68 BumperPacket(const BumperPacket &other) = default;
69
77 static Message *New();
78
85 void *operator new(size_t nSize) {
86 return PoolMemAlloc(static_cast<int>(nSize), "BumperPacket", 0);
87 }
88
94 void operator delete(void *pBlock) {
95 PoolMemFree(pBlock);
96 }
97
105 Message *Clone() override {
106 return new BumperPacket(*this);
107 }
108
116 int Type() override {
117 return g_nBumperPacketType;
118 }
119
127 const char *GetName() const override {
128 return "BumperPacket";
129 }
130
138 void saveGuts(BinStream &stream) const override;
139
147 void restoreGuts(BinStream &stream) override;
148
156 void PrintExtra(PrnStream &stream) const override;
157
159 const std::vector<VictimData> &GetVictims() const {
160 return mVictims;
161 }
162
164 std::vector<VictimData> &GetVictims() {
165 return mVictims;
166 }
167
168private:
169 std::vector<VictimData> mVictims;
170};
int g_nBumperPacketType
Identity that BumperPacket::Type() reports.
Stream of raw bytes, the base of the memory, file, and network streams.
Definition binstream.h:22
VictimData(int nNetOrder, int nTrack)
Construct an entry.
Definition bumperpacket.h:46
int mNetOrder
Definition bumperpacket.h:49
int mTrack
Definition bumperpacket.h:50
VictimData()=default
Construct an entry with every field unset.
void saveGuts(BinStream &stream) const override
Write the victims, at most three.
const std::vector< VictimData > & GetVictims() const
Definition bumperpacket.h:159
static Message * New()
Produce a default-constructed packet on the heap.
Message * Clone() override
Produce a heap copy of this packet.
Definition bumperpacket.h:105
void restoreGuts(BinStream &stream) override
Read the victims saveGuts() writes, after the victims are removed.
std::vector< VictimData > & GetVictims()
Definition bumperpacket.h:164
BumperPacket(const BumperPacket &other)=default
Copy another packet.
const char * GetName() const override
Report this packet's class name.
Definition bumperpacket.h:127
~BumperPacket() override=default
Destroy the object.
void PrintExtra(PrnStream &stream) const override
Write each victim's player and track.
BumperPacket()
Construct a packet with no victims.
Definition bumperpacket.h:58
int Type() override
Report this packet's registered identity.
Definition bumperpacket.h:116
ExternalPacket(unsigned char nFlags=0, int nReceiver=kAllPeers)
Construct a packet from an unset sender.
Definition externalpacket.h:21
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
Text output stream.
Definition prnstream.h:16
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.