wavelength 1.0.0
Loading...
Searching...
No Matches
freestylepacket.h
Go to the documentation of this file.
1#pragma once
2
4#include "os/mem.h"
5
12extern int g_nFreestylePacketType;
13
21public:
28 ~FreestylePacket() override = default;
29
35 FreestylePacket() : mActive(0), mButton(0), mX(0.0f), mY(0.0f) {
36 }
37
48 FreestylePacket(bool bActive, int nButton, float fX, float fY)
49 : mActive(bActive), mButton(nButton), mX(fX), mY(fY) {
50 }
51
59 static Message *New();
60
67 void *operator new(size_t nSize) {
68 return PoolMemAlloc(static_cast<int>(nSize), "FreestylePacket", 0);
69 }
70
76 void operator delete(void *pBlock) {
77 PoolMemFree(pBlock);
78 }
79
87 Message *Clone() override {
88 return new FreestylePacket(*this);
89 }
90
98 int Type() override {
100 }
101
109 const char *GetName() const override {
110 return "FreestylePacket";
111 }
112
120 void saveGuts(BinStream &stream) const override;
121
129 void restoreGuts(BinStream &stream) override;
130
138 void PrintExtra(PrnStream &stream) const override;
139
151 static int Quantize(float fValue, int nBits);
152
164 static float Dequantize(int nValue, int nBits);
165
167 int GetActive() const {
168 return mActive;
169 }
170
172 int GetButton() const {
173 return mButton;
174 }
175
177 float GetX() const {
178 return mX;
179 }
180
182 float GetY() const {
183 return mY;
184 }
185
186private:
187 int mActive;
188 int mButton;
189 float mX;
190 float mY;
191};
Stream of raw bytes, the base of the memory, file, and network streams.
Definition binstream.h:22
ExternalPacket(unsigned char nFlags=0, int nReceiver=kAllPeers)
Construct a packet from an unset sender.
Definition externalpacket.h:21
FreestylePacket(bool bActive, int nButton, float fX, float fY)
Construct a packet for a freestyle player.
Definition freestylepacket.h:48
int Type() override
Report this packet's registered identity.
Definition freestylepacket.h:98
float GetX() const
Definition freestylepacket.h:177
int GetButton() const
Definition freestylepacket.h:172
~FreestylePacket() override=default
Destroy the object.
void restoreGuts(BinStream &stream) override
Read the half-word saveGuts() writes back into the fields.
void PrintExtra(PrnStream &stream) const override
Write the state, the button, and the stick position.
const char * GetName() const override
Report this packet's class name.
Definition freestylepacket.h:109
int GetActive() const
Definition freestylepacket.h:167
FreestylePacket()
Construct an inactive packet.
Definition freestylepacket.h:35
void saveGuts(BinStream &stream) const override
Write the state and the button, then each stick position in fixed point, in one half-word.
static int Quantize(float fValue, int nBits)
Convert a value from -1 to 1 to a signed fixed-point value.
static Message * New()
Produce a default-constructed packet on the heap.
float GetY() const
Definition freestylepacket.h:182
static float Dequantize(int nValue, int nBits)
Convert a signed fixed-point value back to a value from -1 to 1.
Message * Clone() override
Produce a heap copy of this packet.
Definition freestylepacket.h:87
Base of every event the game passes between a MsgSource and a MsgSink.
Definition message.h:40
Text output stream.
Definition prnstream.h:16
int g_nFreestylePacketType
Identity that FreestylePacket::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.