wavelength 1.0.0
Loading...
Searching...
No Matches
avatarpartset.h
Go to the documentation of this file.
1#pragma once
2
3#include <vector>
4
5#include "game/avatar.h"
6#include "math/color.h"
7#include "os/binstream.h"
8#include "rnd/rndcam.h"
9#include "rnd/rndtex.h"
10#include "script/dataarray.h"
11
24public:
37
39 struct PartSetting {
41 unsigned char GetType() const {
42 return mType;
43 }
44
50 void SetType(unsigned char nType) {
51 mType = nType;
52 }
53
60 unsigned char GetColor(int nComponent) const {
61 return mColor[nComponent];
62 }
63
70 void SetColor(int nComponent, unsigned char nValue) {
71 mColor[nComponent] = nValue;
72 }
73
74 private:
75 unsigned char mType;
76 unsigned char mColor[3];
77 };
78
86 static DataArray *GetParts() {
87 return sParts;
88 }
89
90 static void Init();
91
98 static void Terminate();
99
110 static void Poll(float fTime);
111
120 static void GetPartTypes(int nPart, std::vector<const char *> *pTypes);
121
129 static void GetEmblemTypes(std::vector<const char *> *pTypes);
130
138
144 AvatarPartSet(const AvatarPartSet &other) = default;
145
153
163
174 void Load(DataArray *pData);
175
184 void SetPart(int nPart, const char *pszType);
185
195 void SetColor(int nPart, const Color *pColor);
196
204 void SetEmblem(const char *pszEmblem);
205
214 bool IsIncomplete() const;
215
223 void Clear();
224
233 static unsigned char ColorToByte(float fComponent);
234
243 static float ByteToColor(unsigned char nByte);
244
254 static int FindPartType(int nPart, const char *pszType);
255
264 static int FindEmblem(const char *pszEmblem);
265
273
283 void Save(BinStream &stream) const;
284
294 void Load(BinStream &stream);
295
306
317 void CatchGem(int nLane, int nCatch);
318
330 void SetBaseAnim(const char *pszAnim, int nFlags);
331
341 void SetPose(const char *pszPose);
342
352
362 bool IsWinAnim() const;
363
371 void Render(const Rect *pScreenRect);
372
380 const char *EmblemName() const;
381
390 const char *PartName(int nPart) const;
391
400 Color PartColor(int nPart) const;
401
402private:
403 unsigned char mVersion;
404 PartSetting mParts[kNumParts];
405 unsigned char mEmblem;
406 Avatar *mPlayer;
407 int mFrame;
408 int mPending;
409 const char *mBaseAnim;
410 int mBaseAnimFlags;
411 const char *mPoseAnim;
412
419 static DataArray *sParts;
429 void AcquirePlayer();
430
442 int CountDifferences(Avatar *pAvatar) const;
443
450 static float sLastTime;
451};
static void GetPartTypes(int nPart, std::vector< const char * > *pTypes)
List the choices of a part.
static unsigned char ColorToByte(float fComponent)
Convert a colour component to a byte.
bool IsIncomplete() const
Report whether a part that every avatar needs has no choice.
static DataArray * GetParts()
Prepare the avatars and find the parts array.
Definition avatarpartset.h:86
const char * PartName(int nPart) const
Report the name of the choice of a part.
void Clear()
Remove every part but the instrument and the emblem, grey the colours, and return the avatar player.
~AvatarPartSet()
Return the avatar player and destroy the set.
static float ByteToColor(unsigned char nByte)
Convert a byte to a colour component.
AvatarPartSet(const AvatarPartSet &other)=default
Copy every member of another set, the avatar player included.
void ClearAnims()
Stop the animations of the avatar player and forget mBaseAnim and mPoseAnim.
Color PartColor(int nPart) const
Report the colour of a part.
void CatchGem(int nLane, int nCatch)
Pass a gem catch to the avatar player, when a player draws the set.
void Save(BinStream &stream) const
Write the choices and the colours to the packets of a session.
static int FindPartType(int nPart, const char *pszType)
Find a choice of a part.
void SetColor(int nPart, const Color *pColor)
Colour a part, and the part of the avatar player that draws it.
static int FindEmblem(const char *pszEmblem)
Find an emblem.
const char * EmblemName() const
Report the name of the emblem.
void ReleasePlayer()
Return the avatar player that draws the set, if any.
void SetEmblem(const char *pszEmblem)
Choose the emblem of the torso.
bool UpdatePlayer()
Apply the pending parts to the avatar player once their files have loaded.
void Load(DataArray *pData)
Read the choices and the colours from a description such as a prefab.
static void Terminate()
Delete the avatars.
void Load(BinStream &stream)
Read the choices and the colours Save() wrote.
void Render(const Rect *pScreenRect)
Apply the parts to the avatar and render it into the avatar texture.
bool IsWinAnim() const
Report whether the animation the avatar player plays is a win animation.
Part
The parts of an avatar, the indices of mParts and the keys of the parts array.
Definition avatarpartset.h:26
@ kPartTorso
Definition avatarpartset.h:30
@ kPartHead
Definition avatarpartset.h:29
@ kNumParts
Definition avatarpartset.h:35
@ kPartHeadGear
Definition avatarpartset.h:32
@ kPartLowerBody
Definition avatarpartset.h:31
@ kPartRightArm
Definition avatarpartset.h:28
@ kPartInstrument
Definition avatarpartset.h:34
@ kPartLeftArm
Definition avatarpartset.h:27
@ kPartFaceGear
Definition avatarpartset.h:33
void SetPose(const char *pszPose)
Show a pose on the avatar player, when there is one, and record it in mPoseAnim.
static void Poll(float fTime)
Advance the avatars to a time once the time changes, and take each avatar back from a set that has no...
static void Init()
void SetBaseAnim(const char *pszAnim, int nFlags)
Choose the animation the avatar player plays, and start it at once when a player draws the set.
void SetPart(int nPart, const char *pszType)
Choose a part.
AvatarPartSet & operator=(const AvatarPartSet &other)
Copy the choices and the colours of another set, and return the avatar player.
AvatarPartSet()
Construct the set from the default_settings of the avatar entry of the "db" section.
static void GetEmblemTypes(std::vector< const char * > *pTypes)
List the emblems.
One of the avatars the game can draw at a time, lent to the AvatarPartSet that shows.
Definition avatar.h:24
Stream of raw bytes, the base of the memory, file, and network streams.
Definition binstream.h:22
Reference-counted array of script data nodes.
Definition dataarray.h:20
The choice and the colour of one part.
Definition avatarpartset.h:39
unsigned char GetType() const
Definition avatarpartset.h:41
unsigned char GetColor(int nComponent) const
Report one byte of the colour.
Definition avatarpartset.h:60
void SetType(unsigned char nType)
Set the index of the choice.
Definition avatarpartset.h:50
void SetColor(int nComponent, unsigned char nValue)
Set one byte of the colour.
Definition avatarpartset.h:70
Linear colour with four float components.
Definition color.h:12
Axis-aligned rectangle given by a corner and a size.
Definition rect.h:11