1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3#ifndef GAME_CLIENT_GAMECLIENT_H
4#define GAME_CLIENT_GAMECLIENT_H
5
6#include "render.h"
7
8#include <base/color.h>
9#include <base/types.h>
10#include <base/vmath.h>
11
12#include <engine/client.h>
13#include <engine/client/enums.h>
14#include <engine/console.h>
15#include <engine/shared/config.h>
16#include <engine/shared/snapshot.h>
17
18#include <generated/protocol7.h>
19#include <generated/protocolglue.h>
20
21#include <game/client/prediction/gameworld.h>
22#include <game/client/race.h>
23#include <game/collision.h>
24#include <game/gamecore.h>
25#include <game/layers.h>
26#include <game/map/render_map.h>
27#include <game/mapbugs.h>
28#include <game/teamscore.h>
29
30// components
31#include "components/background.h"
32#include "components/binds.h"
33#include "components/broadcast.h"
34#include "components/camera.h"
35#include "components/censor.h"
36#include "components/chat.h"
37#include "components/console.h"
38#include "components/controls.h"
39#include "components/countryflags.h"
40#include "components/damageind.h"
41#include "components/debughud.h"
42#include "components/effects.h"
43#include "components/emoticon.h"
44#include "components/flow.h"
45#include "components/freezebars.h"
46#include "components/ghost.h"
47#include "components/hud.h"
48#include "components/important_alert.h"
49#include "components/infomessages.h"
50#include "components/items.h"
51#include "components/key_binder.h"
52#include "components/local_server.h"
53#include "components/mapimages.h"
54#include "components/maplayers.h"
55#include "components/mapsounds.h"
56#include "components/menu_background.h"
57#include "components/menus.h"
58#include "components/motd.h"
59#include "components/multiview.h"
60#include "components/nameplates.h"
61#include "components/particles.h"
62#include "components/players.h"
63#include "components/race_demo.h"
64#include "components/scoreboard.h"
65#include "components/skins.h"
66#include "components/skins7.h"
67#include "components/sounds.h"
68#include "components/spectator.h"
69#include "components/statboard.h"
70#include "components/touch_controls.h"
71#include "components/voting.h"
72
73#include <memory>
74#include <vector>
75
76class IMap;
77
78class CGameInfo
79{
80public:
81 bool m_FlagStartsRace;
82 bool m_TimeScore;
83 bool m_UnlimitedAmmo;
84 bool m_DDRaceRecordMessage;
85 bool m_RaceRecordMessage;
86 bool m_RaceSounds;
87
88 bool m_AllowEyeWheel;
89 bool m_AllowHookColl;
90 bool m_AllowZoom;
91
92 bool m_BugDDRaceGhost;
93 bool m_BugDDRaceInput;
94 bool m_BugFNGLaserRange;
95 bool m_BugVanillaBounce;
96
97 bool m_PredictFNG;
98 bool m_PredictDDRace;
99 bool m_PredictDDRaceTiles;
100 bool m_PredictVanilla;
101
102 bool m_EntitiesDDNet;
103 bool m_EntitiesDDRace;
104 bool m_EntitiesRace;
105 bool m_EntitiesFNG;
106 bool m_EntitiesVanilla;
107 bool m_EntitiesBW;
108 bool m_EntitiesFDDrace;
109
110 bool m_Race;
111 bool m_Pvp;
112
113 bool m_DontMaskEntities;
114 bool m_AllowXSkins;
115
116 bool m_HudHealthArmor;
117 bool m_HudAmmo;
118 bool m_HudDDRace;
119
120 bool m_NoWeakHookAndBounce;
121 bool m_NoSkinChangeForFrozen;
122
123 bool m_DDRaceTeam;
124
125 bool m_PredictEvents;
126
127 bool m_OldLaser;
128
129 // zero if the server does not send them
130 int m_MinTeamSize;
131 int m_MaxTeamSize;
132
133 int m_NumDDRaceTeams;
134};
135
136class CSnapEntities
137{
138public:
139 IClient::CSnapItem m_Item;
140 const CNetObj_EntityEx *m_pDataEx;
141};
142
143enum class EClientIdFormat
144{
145 NO_INDENT,
146 INDENT_AUTO,
147 INDENT_FORCE, // for rendering settings preview
148};
149
150class CGameClient : public IGameClient
151{
152public:
153 // all components
154 CInfoMessages m_InfoMessages;
155 CCamera m_Camera;
156 CChat m_Chat;
157 CCensor m_Censor;
158 CMotd m_Motd;
159 CBroadcast m_Broadcast;
160 CGameConsole m_GameConsole;
161 CBinds m_Binds;
162 CKeyBinder m_KeyBinder;
163 CParticles m_Particles;
164 CMenus m_Menus;
165 CSkins m_Skins;
166 CSkins7 m_Skins7;
167 CCountryFlags m_CountryFlags;
168 CFlow m_Flow;
169 CHud m_Hud;
170 CImportantAlert m_ImportantAlert;
171 CDebugHud m_DebugHud;
172 CControls m_Controls;
173 CEffects m_Effects;
174 CScoreboard m_Scoreboard;
175 CStatboard m_Statboard;
176 CSounds m_Sounds;
177 CEmoticon m_Emoticon;
178 CDamageInd m_DamageInd;
179 CTouchControls m_TouchControls;
180 CVoting m_Voting;
181 CSpectator m_Spectator;
182 CMultiView m_MultiView;
183
184 CPlayers m_Players;
185 CNamePlates m_NamePlates;
186 CFreezeBars m_FreezeBars;
187 CItems m_Items;
188 CMapImages m_MapImages;
189
190 CMapLayers m_MapLayersBackground = CMapLayers{ERenderType::RENDERTYPE_BACKGROUND};
191 CMapLayers m_MapLayersForeground = CMapLayers{ERenderType::RENDERTYPE_FOREGROUND};
192 CBackground m_Background;
193 CMenuBackground m_MenuBackground;
194
195 CMapSounds m_MapSounds;
196
197 CRaceDemo m_RaceDemo;
198 CGhost m_Ghost;
199 CLocalServer m_LocalServer;
200
201private:
202 std::vector<class CComponent *> m_vpAll;
203 std::vector<class CComponent *> m_vpInput;
204 CNetObjHandler m_NetObjHandler;
205 protocol7::CNetObjHandler m_NetObjHandler7;
206
207 class IEngine *m_pEngine;
208 class IInput *m_pInput;
209 class IGraphics *m_pGraphics;
210 class ITextRender *m_pTextRender;
211 class IClient *m_pClient;
212 class ISound *m_pSound;
213 class IConfigManager *m_pConfigManager;
214 class CConfig *m_pConfig;
215 class IConsole *m_pConsole;
216 class IStorage *m_pStorage;
217 class IDemoPlayer *m_pDemoPlayer;
218 class IFavorites *m_pFavorites;
219 class IServerBrowser *m_pServerBrowser;
220 class IEditor *m_pEditor;
221 class IFriends *m_pFriends;
222 class IFriends *m_pFoes;
223 class IDiscord *m_pDiscord;
224#if defined(CONF_AUTOUPDATE)
225 class IUpdater *m_pUpdater;
226#endif
227 class IHttp *m_pHttp;
228
229 CLayers m_Layers;
230 CCollision m_Collision;
231 CUi m_UI;
232 CRaceHelper m_RaceHelper;
233
234 void ProcessEvents();
235 void UpdatePositions();
236
237 int m_EditorMovementDelay = 5;
238 void UpdateEditorIngameMoved();
239
240 int m_PredictedTick;
241 int m_aLastNewPredictedTick[NUM_DUMMIES];
242
243 int m_LastRoundStartTick;
244 int m_LastRaceTick;
245
246 int m_LastFlagCarrierRed;
247 int m_LastFlagCarrierBlue;
248
249 int m_aCheckInfo[NUM_DUMMIES];
250
251 char m_aDDNetVersionStr[64];
252
253 static void ConTeam(IConsole::IResult *pResult, void *pUserData);
254 static void ConKill(IConsole::IResult *pResult, void *pUserData);
255 static void ConReadyChange7(IConsole::IResult *pResult, void *pUserData);
256
257 static void ConchainLanguageUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
258 static void ConchainSpecialInfoupdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
259 static void ConchainSpecialDummyInfoupdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
260 static void ConchainRefreshSkins(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
261 static void ConchainRefreshEventSkins(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
262 static void ConchainSpecialDummy(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
263
264 static void ConTuneParam(IConsole::IResult *pResult, void *pUserData);
265 static void ConTuneZone(IConsole::IResult *pResult, void *pUserData);
266 static void ConMapbug(IConsole::IResult *pResult, void *pUserData);
267
268 static void ConchainMenuMap(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
269
270 static std::function<bool(int, int, int, int)> GetScoreComparator(bool TimeScore, bool ReceivedMillisecondFinishTimes, bool Race7);
271
272 // only used in OnPredict
273 vec2 m_aLastPos[MAX_CLIENTS];
274 bool m_aLastActive[MAX_CLIENTS];
275
276 // only used in OnNewSnapshot
277 bool m_GameOver = false;
278 bool m_GamePaused = false;
279
280public:
281 IKernel *Kernel() { return IInterface::Kernel(); }
282 IEngine *Engine() const { return m_pEngine; }
283 class IGraphics *Graphics() const { return m_pGraphics; }
284 class IClient *Client() const { return m_pClient; }
285 class CUi *Ui() { return &m_UI; }
286 class ISound *Sound() const { return m_pSound; }
287 class IInput *Input() const { return m_pInput; }
288 class IStorage *Storage() const { return m_pStorage; }
289 class IConfigManager *ConfigManager() const { return m_pConfigManager; }
290 class CConfig *Config() const { return m_pConfig; }
291 class IConsole *Console() { return m_pConsole; }
292 class ITextRender *TextRender() const { return m_pTextRender; }
293 class IDemoPlayer *DemoPlayer() const { return m_pDemoPlayer; }
294 class IDemoRecorder *DemoRecorder(int Recorder) const { return Client()->DemoRecorder(Recorder); }
295 class IFavorites *Favorites() const { return m_pFavorites; }
296 class IServerBrowser *ServerBrowser() const { return m_pServerBrowser; }
297 class CRenderTools *RenderTools() { return &m_RenderTools; }
298 class CRenderMap *RenderMap() { return &m_RenderMap; }
299 class CLayers *Layers() { return &m_Layers; }
300 CCollision *Collision() { return &m_Collision; }
301 const CCollision *Collision() const { return &m_Collision; }
302 const CRaceHelper *RaceHelper() const { return &m_RaceHelper; }
303 class IEditor *Editor() { return m_pEditor; }
304 class IFriends *Friends() { return m_pFriends; }
305 class IFriends *Foes() { return m_pFoes; }
306#if defined(CONF_AUTOUPDATE)
307 class IUpdater *Updater()
308 {
309 return m_pUpdater;
310 }
311#endif
312 class IHttp *Http()
313 {
314 return m_pHttp;
315 }
316
317 int NetobjNumCorrections()
318 {
319 return m_NetObjHandler.NumObjCorrections();
320 }
321 const char *NetobjCorrectedOn() { return m_NetObjHandler.CorrectedObjOn(); }
322
323 bool m_SuppressEvents;
324 bool m_NewTick;
325 bool m_NewPredictedTick;
326 int m_aFlagDropTick[2];
327
328 enum
329 {
330 SERVERMODE_PURE = 0,
331 SERVERMODE_MOD,
332 SERVERMODE_PUREMOD,
333 };
334 int m_ServerMode;
335 CGameInfo m_GameInfo;
336
337 int m_DemoSpecId;
338
339 vec2 m_LocalCharacterPos;
340
341 /**
342 * Our prediction for the local character at tick
343 * `IClient::PredGameTick() - 1`.
344 */
345 CCharacterCore m_PredictedPrevChar;
346 /**
347 * Our prediction for the local character at tick
348 * `IClient::PredGameTick()`.
349 */
350 CCharacterCore m_PredictedChar;
351
352 // snap pointers
353 class CSnapState
354 {
355 public:
356 const CNetObj_Character *m_pLocalCharacter;
357 const CNetObj_Character *m_pLocalPrevCharacter;
358 const CNetObj_PlayerInfo *m_pLocalInfo;
359 const CNetObj_SpectatorInfo *m_pSpectatorInfo;
360 const CNetObj_SpectatorInfo *m_pPrevSpectatorInfo;
361 const CNetObj_SpectatorCount *m_pSpectatorCount;
362 int m_NumFlags;
363 const CNetObj_Flag *m_apFlags[CSnapshot::MAX_ITEMS];
364 const CNetObj_Flag *m_apPrevFlags[CSnapshot::MAX_ITEMS];
365 const CNetObj_GameInfo *m_pGameInfoObj;
366 const CNetObj_GameData *m_pGameDataObj;
367 const CNetObj_GameData *m_pPrevGameDataObj;
368
369 const CNetObj_PlayerInfo *m_apPlayerInfos[MAX_CLIENTS];
370 const CNetObj_PlayerInfo *m_apPrevPlayerInfos[MAX_CLIENTS];
371
372 const CNetObj_PlayerInfo *m_apInfoByScore[MAX_CLIENTS];
373 const CNetObj_PlayerInfo *m_apInfoByName[MAX_CLIENTS];
374 const CNetObj_PlayerInfo *m_apInfoByDDTeamScore[MAX_CLIENTS];
375 const CNetObj_PlayerInfo *m_apInfoByDDTeamName[MAX_CLIENTS];
376
377 int m_LocalClientId;
378 int m_NumPlayers;
379 int m_aTeamSize[2];
380 int m_HighestClientId;
381
382 class CSpectateInfo
383 {
384 public:
385 bool m_Active;
386 int m_SpectatorId;
387 bool m_UsePosition;
388 vec2 m_Position;
389
390 bool m_HasCameraInfo;
391 float m_Zoom;
392 int m_Deadzone;
393 int m_FollowFactor;
394 };
395 CSpectateInfo m_SpecInfo;
396
397 class CCharacterInfo
398 {
399 public:
400 bool m_Active;
401
402 // snapshots
403 CNetObj_Character m_Prev;
404 CNetObj_Character m_Cur;
405
406 CNetObj_DDNetCharacter m_ExtendedData;
407 const CNetObj_DDNetCharacter *m_pPrevExtendedData;
408 bool m_HasExtendedData;
409 bool m_HasExtendedDisplayInfo;
410 };
411 CCharacterInfo m_aCharacters[MAX_CLIENTS];
412 };
413
414 CSnapState m_Snap;
415 int m_aLocalTuneZone[NUM_DUMMIES]; // current tunezone (0-255)
416 bool m_aReceivedTuning[NUM_DUMMIES]; // was tuning message received after zone change
417 int m_aExpectingTuningForZone[NUM_DUMMIES]; // tunezone changed, waiting for tuning for that zone
418 int m_aExpectingTuningSince[NUM_DUMMIES]; // how many snaps received since tunezone changed
419 CTuningParams m_aTuning[NUM_DUMMIES]; // current local player tuning, only what the player/dummy has
420
421 std::bitset<RECORDER_MAX> m_ActiveRecordings;
422
423 // spectate cursor data
424 class CCursorInfo
425 {
426 friend class CGameClient;
427 static constexpr int CURSOR_SAMPLES = 8; // how many samples to keep
428 static constexpr int SAMPLE_FRAME_WINDOW = 3; // how many samples should be used for polynomial interpolation
429 static constexpr int SAMPLE_FRAME_OFFSET = 2; // how many samples in the past should be included
430 static constexpr double INTERP_DELAY = 4.25; // how many ticks in the past to show, enables extrapolation with smaller value (<= SAMPLE_FRAME_WINDOW - SAMPLE_FRAME_OFFSET + 3)
431 static constexpr double REST_THRESHOLD = 3.0; // how many ticks of the same samples are considered to be resting
432
433 int m_CursorOwnerId;
434 double m_aTargetSamplesTime[CURSOR_SAMPLES];
435 vec2 m_aTargetSamplesData[CURSOR_SAMPLES];
436 int m_NumSamples;
437
438 bool m_Available;
439 int m_Weapon;
440 vec2 m_Target;
441 vec2 m_WorldTarget;
442 vec2 m_Position;
443
444 public:
445 bool IsAvailable() const { return m_Available; }
446 int Weapon() const { return m_Weapon; }
447 vec2 Target() const { return m_Target; }
448 vec2 WorldTarget() const { return m_WorldTarget; }
449 vec2 Position() const { return m_Position; }
450 } m_CursorInfo;
451
452 // client data
453 class CClientData
454 {
455 friend class CGameClient;
456 CGameClient *m_pGameClient;
457 int m_ClientId;
458
459 public:
460 int m_UseCustomColor;
461 int m_ColorBody;
462 int m_ColorFeet;
463
464 char m_aName[MAX_NAME_LENGTH];
465 char m_aClan[MAX_CLAN_LENGTH];
466 /**
467 * Country code in ISO 3166-1 numeric.
468 */
469 int m_Country;
470 char m_aSkinName[MAX_SKIN_LENGTH];
471 int m_Team;
472 int m_Emoticon;
473 float m_EmoticonStartFraction;
474 int m_EmoticonStartTick;
475
476 bool m_Solo;
477 bool m_Jetpack;
478 bool m_CollisionDisabled;
479 bool m_EndlessHook;
480 bool m_EndlessJump;
481 bool m_HammerHitDisabled;
482 bool m_GrenadeHitDisabled;
483 bool m_LaserHitDisabled;
484 bool m_ShotgunHitDisabled;
485 bool m_HookHitDisabled;
486 bool m_Super;
487 bool m_Invincible;
488 bool m_HasTelegunGun;
489 bool m_HasTelegunGrenade;
490 bool m_HasTelegunLaser;
491 int m_FreezeEnd;
492 bool m_DeepFrozen;
493 bool m_LiveFrozen;
494
495 CCharacterCore m_Predicted;
496 CCharacterCore m_PrevPredicted;
497
498 std::shared_ptr<CManagedTeeRenderInfo> m_pSkinInfo = nullptr; // this is what the server reports
499 CTeeRenderInfo m_RenderInfo; // this is what we use
500
501 float m_Angle;
502 bool m_Active;
503 bool m_ChatIgnore;
504 bool m_EmoticonIgnore;
505 bool m_Friend;
506 bool m_Foe;
507
508 int m_AuthLevel;
509 bool m_Afk;
510 bool m_Paused;
511 bool m_Spec;
512
513 int m_FinishTimeSeconds;
514 int m_FinishTimeMillis;
515
516 // Editor allows 256 switches for now.
517 bool m_aSwitchStates[256];
518
519 CNetObj_Character m_Snapped;
520 CNetObj_Character m_Evolved;
521
522 CNetMsg_Sv_PreInput m_aPreInputs[200];
523
524 // rendered characters
525 CNetObj_Character m_RenderCur;
526 CNetObj_Character m_RenderPrev;
527 vec2 m_RenderPos;
528 bool m_IsPredicted;
529 bool m_IsPredictedLocal;
530 int64_t m_aSmoothStart[2];
531 int64_t m_aSmoothLen[2];
532 vec2 m_aPredPos[200];
533 int m_aPredTick[200];
534 bool m_SpecCharPresent;
535 vec2 m_SpecChar;
536
537 void UpdateSkinInfo();
538 void UpdateSkin7HatSprite(int Dummy);
539 void UpdateSkin7BotDecoration(int Dummy);
540 void UpdateRenderInfo();
541 void Reset();
542 CSkinDescriptor ToSkinDescriptor() const;
543
544 int ClientId() const { return m_ClientId; }
545
546 class CSixup
547 {
548 public:
549 void Reset();
550
551 char m_aaSkinPartNames[protocol7::NUM_SKINPARTS][protocol7::MAX_SKIN_LENGTH];
552 int m_aUseCustomColors[protocol7::NUM_SKINPARTS];
553 int m_aSkinPartColors[protocol7::NUM_SKINPARTS];
554 };
555
556 // 0.7 Skin
557 CSixup m_aSixup[NUM_DUMMIES];
558 };
559
560 CClientData m_aClients[MAX_CLIENTS];
561
562 class CClientStats
563 {
564 int m_IngameTicks;
565 int m_JoinTick;
566 bool m_Active;
567
568 public:
569 CClientStats();
570
571 int m_aFragsWith[NUM_WEAPONS];
572 int m_aDeathsFrom[NUM_WEAPONS];
573 int m_Frags;
574 int m_Deaths;
575 int m_Suicides;
576 int m_BestSpree;
577 int m_CurrentSpree;
578
579 int m_FlagGrabs;
580 int m_FlagCaptures;
581
582 void Reset();
583
584 bool IsActive() const { return m_Active; }
585 void JoinGame(int Tick)
586 {
587 m_Active = true;
588 m_JoinTick = Tick;
589 }
590 void JoinSpec(int Tick)
591 {
592 m_Active = false;
593 m_IngameTicks += Tick - m_JoinTick;
594 }
595 int GetIngameTicks(int Tick) const { return m_IngameTicks + Tick - m_JoinTick; }
596 float GetFPM(int Tick, int TickSpeed) const { return (float)(m_Frags * TickSpeed * 60) / GetIngameTicks(Tick); }
597 };
598
599 CClientStats m_aStats[MAX_CLIENTS];
600
601 CRenderTools m_RenderTools;
602 CRenderMap m_RenderMap;
603
604 bool m_BackButtonHandledKeyBind = false;
605
606 void OnReset();
607
608 size_t ComponentCount() const { return m_vpAll.size(); }
609
610 // hooks
611 void OnConnected() override;
612 void OnRender() override;
613 void OnUpdate() override;
614 void OnDummyDisconnect() override;
615 virtual void OnRelease();
616 void OnInit() override;
617 void OnConsoleInit() override;
618 void OnStateChange(int NewState, int OldState) override;
619 template<typename T>
620 void ApplySkin7InfoFromGameMsg(const T *pMsg, int ClientId, int Conn);
621 void ApplySkin7InfoFromSnapObj(const protocol7::CNetObj_De_ClientInfo *pObj, int ClientId) override;
622 int OnDemoRecSnap7(CSnapshot *pFrom, CSnapshotBuffer *pTo, int Conn) override;
623 void *TranslateGameMsg(int *pMsgId, CUnpacker *pUnpacker, int Conn);
624 int TranslateSnap(CSnapshotBuffer *pSnapDstSix, CSnapshot *pSnapSrcSeven, int Conn, bool Dummy) override;
625 void OnMessage(int MsgId, CUnpacker *pUnpacker, int Conn, bool Dummy) override;
626 void InvalidateSnapshot() override;
627 void OnNewSnapshot(bool DummySwapped) override;
628 void OnPredict() override;
629 void OnActivateEditor() override;
630 void OnDummySwap() override;
631 int OnSnapInput(int *pData, bool Dummy, bool Force) override;
632 void OnShutdown() override;
633 void OnEnterGame() override;
634 void OnRconType(bool UsernameReq) override;
635 void OnRconLine(const char *pLine) override;
636 virtual void OnGameOver();
637 virtual void OnStartGame();
638 virtual void OnStartRound();
639 virtual void OnFlagGrab(int TeamId);
640 void OnWindowResize() override;
641
642 void InitializeLanguage() override;
643 bool m_LanguageChanged = false;
644 void OnLanguageChange();
645 void HandleLanguageChanged();
646
647 void ForceUpdateConsoleRemoteCompletionSuggestions() override;
648
649 void RefreshSkin(const std::shared_ptr<CManagedTeeRenderInfo> &pManagedTeeRenderInfo);
650 void RefreshSkins(int SkinDescriptorFlags);
651 void OnSkinUpdate(const char *pSkinName);
652 std::shared_ptr<CManagedTeeRenderInfo> CreateManagedTeeRenderInfo(const CTeeRenderInfo &TeeRenderInfo, const CSkinDescriptor &SkinDescriptor);
653 std::shared_ptr<CManagedTeeRenderInfo> CreateManagedTeeRenderInfo(const CClientData &Client);
654 void CollectManagedTeeRenderInfos(const std::function<void(const char *pSkinName)> &ActiveSkinAcceptor);
655
656 void RenderShutdownMessage() override;
657 void ProcessDemoSnapshot(CSnapshot *pSnap) override;
658
659 const char *GetItemName(int Type) const override;
660 const char *Version() const override;
661 const char *NetVersion() const override;
662 const char *NetVersion7() const override;
663 int DDNetVersion() const override;
664 const char *DDNetVersionStr() const override;
665 int ClientVersion7() const override;
666
667 void DoTeamChangeMessage7(const char *pName, int ClientId, int Team, const char *pPrefix = "");
668
669 // actions
670 // TODO: move these
671 void SendSwitchTeam(int Team) const;
672 void SendStartInfo7(bool Dummy);
673 void SendSkinChange7(bool Dummy);
674 // Returns true if the requested skin change got applied by the server
675 bool GotWantedSkin7(bool Dummy);
676 void SendInfo(bool Start);
677 void SendDummyInfo(bool Start) override;
678 void SendKill() const;
679 void SendReadyChange7(); // NOLINT(readability-make-member-function-const)
680
681 void ApplyPreInputs(int Tick, bool Direct, CGameWorld &GameWorld);
682
683 int m_aNextChangeInfo[NUM_DUMMIES];
684
685 // DDRace
686
687 int m_aLocalIds[NUM_DUMMIES];
688 CNetObj_PlayerInput m_DummyInput;
689 CNetObj_PlayerInput m_HammerInput;
690 unsigned int m_DummyFire;
691 bool m_ReceivedDDNetPlayer;
692 bool m_ReceivedDDNetPlayerFinishTimes;
693 bool m_ReceivedDDNetPlayerFinishTimesMillis;
694
695 CTeamsCore m_Teams;
696
697 int IntersectCharacter(vec2 HookPos, vec2 NewPos, vec2 &NewPos2, int OwnId, vec2 *pPlayerPosition = nullptr);
698
699 int LastRaceTick() const;
700 int CurrentRaceTime() const;
701
702 bool IsTeamPlay() const;
703 int MinTeamSize() const;
704 int MaxTeamSize() const;
705 bool IsWorldPaused() const;
706 bool IsDemoPlaybackPaused() const;
707 float GetAnimationPlaybackSpeed() const;
708
709 int AntiPingPlayers() const;
710 bool AntiPingGrenade() const;
711 bool AntiPingWeapons() const;
712 bool AntiPingGunfire() const;
713 bool Predict() const;
714 bool PredictDummy() const;
715
716 const CTuningParams *GetTuning(int i) const { return &m_aTuningList[i]; }
717 ColorRGBA GetDDTeamColor(int DDTeam, float Lightness = 0.5f) const;
718 void FormatClientId(int ClientId, char (&aClientId)[16], EClientIdFormat Format) const;
719
720 CGameWorld m_GameWorld;
721 CGameWorld m_PredictedWorld;
722 CGameWorld m_PrevPredictedWorld;
723
724 std::vector<SSwitchers> &Switchers() { return m_GameWorld.m_Core.m_vSwitchers; }
725 std::vector<SSwitchers> &PredSwitchers() { return m_PredictedWorld.m_Core.m_vSwitchers; }
726
727 void DummyResetInput() override;
728 void Echo(const char *pString) override;
729 bool IsOtherTeam(int ClientId) const;
730 int SwitchStateTeam() const;
731 bool IsLocalCharSuper() const;
732 bool CanDisplayWarning() const override;
733
734 IMap *Map() override { return m_pMap.get(); }
735 const IMap *Map() const override { return m_pMap.get(); }
736 CNetObjHandler *GetNetObjHandler() override;
737 protocol7::CNetObjHandler *GetNetObjHandler7() override;
738
739 void LoadGameSkin(const char *pPath, bool AsDir = false);
740 void LoadEmoticonsSkin(const char *pPath, bool AsDir = false);
741 void LoadParticlesSkin(const char *pPath, bool AsDir = false);
742 void LoadHudSkin(const char *pPath, bool AsDir = false);
743 void LoadExtrasSkin(const char *pPath, bool AsDir = false);
744
745 class CGameSkin
746 {
747 public:
748 bool m_Loaded = false;
749
750 // health armor hud
751 IGraphics::CTextureHandle m_SpriteHealthFull;
752 IGraphics::CTextureHandle m_SpriteHealthEmpty;
753 IGraphics::CTextureHandle m_SpriteArmorFull;
754 IGraphics::CTextureHandle m_SpriteArmorEmpty;
755
756 // cursors
757 IGraphics::CTextureHandle m_SpriteWeaponHammerCursor;
758 IGraphics::CTextureHandle m_SpriteWeaponGunCursor;
759 IGraphics::CTextureHandle m_SpriteWeaponShotgunCursor;
760 IGraphics::CTextureHandle m_SpriteWeaponGrenadeCursor;
761 IGraphics::CTextureHandle m_SpriteWeaponNinjaCursor;
762 IGraphics::CTextureHandle m_SpriteWeaponLaserCursor;
763
764 IGraphics::CTextureHandle m_aSpriteWeaponCursors[6];
765
766 // weapons and hook
767 IGraphics::CTextureHandle m_SpriteHookChain;
768 IGraphics::CTextureHandle m_SpriteHookHead;
769 IGraphics::CTextureHandle m_SpriteWeaponHammer;
770 IGraphics::CTextureHandle m_SpriteWeaponGun;
771 IGraphics::CTextureHandle m_SpriteWeaponShotgun;
772 IGraphics::CTextureHandle m_SpriteWeaponGrenade;
773 IGraphics::CTextureHandle m_SpriteWeaponNinja;
774 IGraphics::CTextureHandle m_SpriteWeaponLaser;
775
776 IGraphics::CTextureHandle m_aSpriteWeapons[6];
777
778 // particles
779 IGraphics::CTextureHandle m_aSpriteParticles[9];
780
781 // stars
782 IGraphics::CTextureHandle m_aSpriteStars[3];
783
784 // projectiles
785 IGraphics::CTextureHandle m_SpriteWeaponGunProjectile;
786 IGraphics::CTextureHandle m_SpriteWeaponShotgunProjectile;
787 IGraphics::CTextureHandle m_SpriteWeaponGrenadeProjectile;
788 IGraphics::CTextureHandle m_SpriteWeaponHammerProjectile;
789 IGraphics::CTextureHandle m_SpriteWeaponNinjaProjectile;
790 IGraphics::CTextureHandle m_SpriteWeaponLaserProjectile;
791
792 IGraphics::CTextureHandle m_aSpriteWeaponProjectiles[6];
793
794 // muzzles
795 IGraphics::CTextureHandle m_aSpriteWeaponGunMuzzles[3];
796 IGraphics::CTextureHandle m_aSpriteWeaponShotgunMuzzles[3];
797 IGraphics::CTextureHandle m_aaSpriteWeaponNinjaMuzzles[3];
798
799 IGraphics::CTextureHandle m_aaSpriteWeaponsMuzzles[6][3];
800
801 // pickups
802 IGraphics::CTextureHandle m_SpritePickupHealth;
803 IGraphics::CTextureHandle m_SpritePickupFreeze;
804 IGraphics::CTextureHandle m_SpritePickupArmor;
805 IGraphics::CTextureHandle m_SpritePickupArmorShotgun;
806 IGraphics::CTextureHandle m_SpritePickupArmorGrenade;
807 IGraphics::CTextureHandle m_SpritePickupArmorNinja;
808 IGraphics::CTextureHandle m_SpritePickupArmorLaser;
809 IGraphics::CTextureHandle m_SpritePickupGrenade;
810 IGraphics::CTextureHandle m_SpritePickupShotgun;
811 IGraphics::CTextureHandle m_SpritePickupLaser;
812 IGraphics::CTextureHandle m_SpritePickupNinja;
813 IGraphics::CTextureHandle m_SpritePickupGun;
814 IGraphics::CTextureHandle m_SpritePickupHammer;
815
816 IGraphics::CTextureHandle m_aSpritePickupWeapons[6];
817 IGraphics::CTextureHandle m_aSpritePickupWeaponArmor[4];
818
819 // flags
820 IGraphics::CTextureHandle m_SpriteFlagBlue;
821 IGraphics::CTextureHandle m_SpriteFlagRed;
822
823 // ninja bar (0.7)
824 IGraphics::CTextureHandle m_SpriteNinjaBarFullLeft;
825 IGraphics::CTextureHandle m_SpriteNinjaBarFull;
826 IGraphics::CTextureHandle m_SpriteNinjaBarEmpty;
827 IGraphics::CTextureHandle m_SpriteNinjaBarEmptyRight;
828
829 bool IsSixup() const
830 {
831 return m_SpriteNinjaBarFullLeft.IsValid();
832 }
833 };
834 CGameSkin m_GameSkin;
835
836 class CParticlesSkin
837 {
838 public:
839 bool m_Loaded = false;
840 IGraphics::CTextureHandle m_SpriteParticleSlice;
841 IGraphics::CTextureHandle m_SpriteParticleBall;
842 IGraphics::CTextureHandle m_aSpriteParticleSplat[3];
843 IGraphics::CTextureHandle m_SpriteParticleSmoke;
844 IGraphics::CTextureHandle m_SpriteParticleShell;
845 IGraphics::CTextureHandle m_SpriteParticleExpl;
846 IGraphics::CTextureHandle m_SpriteParticleAirJump;
847 IGraphics::CTextureHandle m_SpriteParticleHit;
848 IGraphics::CTextureHandle m_aSpriteParticles[10];
849 };
850 CParticlesSkin m_ParticlesSkin;
851
852 class CEmoticonsSkin
853 {
854 public:
855 bool m_Loaded = false;
856 IGraphics::CTextureHandle m_aSpriteEmoticons[16];
857 };
858 CEmoticonsSkin m_EmoticonsSkin;
859
860 class CHudSkin
861 {
862 public:
863 bool m_Loaded = false;
864 IGraphics::CTextureHandle m_SpriteHudAirjump;
865 IGraphics::CTextureHandle m_SpriteHudAirjumpEmpty;
866 IGraphics::CTextureHandle m_SpriteHudSolo;
867 IGraphics::CTextureHandle m_SpriteHudCollisionDisabled;
868 IGraphics::CTextureHandle m_SpriteHudEndlessJump;
869 IGraphics::CTextureHandle m_SpriteHudEndlessHook;
870 IGraphics::CTextureHandle m_SpriteHudJetpack;
871 IGraphics::CTextureHandle m_SpriteHudFreezeBarFullLeft;
872 IGraphics::CTextureHandle m_SpriteHudFreezeBarFull;
873 IGraphics::CTextureHandle m_SpriteHudFreezeBarEmpty;
874 IGraphics::CTextureHandle m_SpriteHudFreezeBarEmptyRight;
875 IGraphics::CTextureHandle m_SpriteHudNinjaBarFullLeft;
876 IGraphics::CTextureHandle m_SpriteHudNinjaBarFull;
877 IGraphics::CTextureHandle m_SpriteHudNinjaBarEmpty;
878 IGraphics::CTextureHandle m_SpriteHudNinjaBarEmptyRight;
879 IGraphics::CTextureHandle m_SpriteHudHookHitDisabled;
880 IGraphics::CTextureHandle m_SpriteHudHammerHitDisabled;
881 IGraphics::CTextureHandle m_SpriteHudShotgunHitDisabled;
882 IGraphics::CTextureHandle m_SpriteHudGrenadeHitDisabled;
883 IGraphics::CTextureHandle m_SpriteHudLaserHitDisabled;
884 IGraphics::CTextureHandle m_SpriteHudGunHitDisabled;
885 IGraphics::CTextureHandle m_SpriteHudDeepFrozen;
886 IGraphics::CTextureHandle m_SpriteHudLiveFrozen;
887 IGraphics::CTextureHandle m_SpriteHudTeleportGrenade;
888 IGraphics::CTextureHandle m_SpriteHudTeleportGun;
889 IGraphics::CTextureHandle m_SpriteHudTeleportLaser;
890 IGraphics::CTextureHandle m_SpriteHudPracticeMode;
891 IGraphics::CTextureHandle m_SpriteHudLockMode;
892 IGraphics::CTextureHandle m_SpriteHudTeam0Mode;
893 IGraphics::CTextureHandle m_SpriteHudDummyHammer;
894 IGraphics::CTextureHandle m_SpriteHudDummyCopy;
895 };
896 CHudSkin m_HudSkin;
897
898 class CExtrasSkin
899 {
900 public:
901 bool m_Loaded = false;
902 IGraphics::CTextureHandle m_SpriteParticleSnowflake;
903 IGraphics::CTextureHandle m_SpriteParticleSparkle;
904 IGraphics::CTextureHandle m_SpritePulley;
905 IGraphics::CTextureHandle m_SpriteHectagon;
906 IGraphics::CTextureHandle m_aSpriteParticles[4];
907 };
908 CExtrasSkin m_ExtrasSkin;
909
910 const std::vector<CSnapEntities> &SnapEntities() { return m_vSnapEntities; }
911
912 int m_MapBestTimeSeconds;
913 int m_MapBestTimeMillis;
914 char m_aMapDescription[512];
915
916private:
917 std::unique_ptr<IMap> m_pMap;
918
919 std::vector<CSnapEntities> m_vSnapEntities;
920 void SnapCollectEntities();
921
922 bool m_aDDRaceMsgSent[NUM_DUMMIES];
923 int m_aShowOthers[NUM_DUMMIES];
924 int m_aEnableSpectatorCount[NUM_DUMMIES]; // current setting as sent to the server, -1 if not yet sent
925
926 class CImageAsset
927 {
928 public:
929 bool IsLoaded() const { return m_ImageInfo.m_pData != nullptr; }
930
931 char m_aPath[IO_MAX_PATH_LENGTH];
932 bool m_IsDefault;
933 CImageInfo m_ImageInfo;
934 std::optional<CImageInfo> m_FallbackImageInfo;
935 };
936
937 CImageAsset LoadAssetFromPath(const char *pPath, bool AsDir, int AssetId, const char *pDirectory) const;
938
939 std::vector<std::shared_ptr<CManagedTeeRenderInfo>> m_vpManagedTeeRenderInfos;
940 void UpdateManagedTeeRenderInfos();
941
942 void UpdateLocalTuning();
943 void UpdatePrediction();
944 void UpdateSpectatorCursor();
945 void UpdateRenderedCharacters();
946 void HandlePredictedEvents(int Tick);
947
948 void OnInput(const IInput::CEvent &Event);
949
950 int m_aLastUpdateTick[MAX_CLIENTS] = {0};
951 void DetectStrongHook();
952
953 vec2 GetSmoothPos(int ClientId);
954
955 int m_IsDummySwapping;
956 CCharOrder m_CharOrder;
957 int m_aSwitchStateTeam[NUM_DUMMIES];
958
959 void LoadMapSettings();
960 CMapBugs m_MapBugs;
961
962 // tunings for every zone on the map, 0 is a global tune
963 CTuningParams m_aTuningList[TuneZone::NUM];
964 CTuningParams *TuningList() { return m_aTuningList; }
965
966 float m_LastShowDistanceZoom;
967 float m_LastZoom;
968 float m_LastScreenAspect;
969 float m_LastDeadzone;
970 float m_LastFollowFactor;
971 bool m_LastDummyConnected;
972
973 void OnSaveCodeNetMessage(const CNetMsg_Sv_SaveCode *pMsg);
974 void StoreSave(const char *pTeamMembers, const char *pGeneratedCode) const;
975};
976
977ColorRGBA CalculateNameColor(ColorHSLA TextColorHSL);
978
979#endif
980