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
4#include "players.h"
5
6#include <base/color.h>
7#include <base/math.h>
8
9#include <engine/client/enums.h>
10#include <engine/demo.h>
11#include <engine/graphics.h>
12#include <engine/shared/config.h>
13
14#include <generated/client_data.h>
15#include <generated/client_data7.h>
16#include <generated/protocol.h>
17
18#include <game/client/animstate.h>
19#include <game/client/components/controls.h>
20#include <game/client/components/effects.h>
21#include <game/client/components/flow.h>
22#include <game/client/components/skins.h>
23#include <game/client/components/sounds.h>
24#include <game/client/gameclient.h>
25#include <game/gamecore.h>
26#include <game/mapitems.h>
27
28static float CalculateHandAngle(vec2 Dir, float AngleOffset)
29{
30 const float Angle = angle(a: Dir);
31 if(Dir.x < 0.0f)
32 {
33 return Angle - AngleOffset;
34 }
35 else
36 {
37 return Angle + AngleOffset;
38 }
39}
40
41static vec2 CalculateHandPosition(vec2 CenterPos, vec2 Dir, vec2 PostRotOffset)
42{
43 vec2 DirY = vec2(-Dir.y, Dir.x);
44 if(Dir.x < 0.0f)
45 {
46 DirY = -DirY;
47 }
48 return CenterPos + Dir + Dir * PostRotOffset.x + DirY * PostRotOffset.y;
49}
50
51void CPlayers::RenderHand(const CTeeRenderInfo *pInfo, vec2 CenterPos, vec2 Dir, float AngleOffset, vec2 PostRotOffset, float Alpha)
52{
53 const vec2 HandPos = CalculateHandPosition(CenterPos, Dir, PostRotOffset);
54 const float HandAngle = CalculateHandAngle(Dir, AngleOffset);
55 if(pInfo->m_aSixup[g_Config.m_ClDummy].PartTexture(Part: protocol7::SKINPART_HANDS).IsValid())
56 {
57 RenderHand7(pInfo, HandPos, HandAngle, Alpha);
58 }
59 else
60 {
61 RenderHand6(pInfo, HandPos, HandAngle, Alpha);
62 }
63}
64
65void CPlayers::RenderHand7(const CTeeRenderInfo *pInfo, vec2 HandPos, float HandAngle, float Alpha)
66{
67 // in-game hand size is 15 when tee size is 64
68 const float BaseSize = 15.0f * (pInfo->m_Size / 64.0f);
69 IGraphics::CQuadItem QuadOutline(HandPos.x, HandPos.y, 2 * BaseSize, 2 * BaseSize);
70 IGraphics::CQuadItem QuadHand = QuadOutline;
71
72 Graphics()->TextureSet(Texture: pInfo->m_aSixup[g_Config.m_ClDummy].PartTexture(Part: protocol7::SKINPART_HANDS));
73 Graphics()->QuadsBegin();
74 Graphics()->SetColor(pInfo->m_aSixup[g_Config.m_ClDummy].m_aColors[protocol7::SKINPART_HANDS].WithAlpha(alpha: Alpha));
75 Graphics()->QuadsSetRotation(Angle: HandAngle);
76 Graphics()->SelectSprite7(Id: client_data7::SPRITE_TEE_HAND_OUTLINE);
77 Graphics()->QuadsDraw(pArray: &QuadOutline, Num: 1);
78 Graphics()->SelectSprite7(Id: client_data7::SPRITE_TEE_HAND);
79 Graphics()->QuadsDraw(pArray: &QuadHand, Num: 1);
80 Graphics()->QuadsEnd();
81}
82
83void CPlayers::RenderHand6(const CTeeRenderInfo *pInfo, vec2 HandPos, float HandAngle, float Alpha)
84{
85 const CSkin::CSkinTextures *pSkinTextures = pInfo->m_CustomColoredSkin ? &pInfo->m_ColorableRenderSkin : &pInfo->m_OriginalRenderSkin;
86
87 Graphics()->SetColor(pInfo->m_ColorBody.WithAlpha(alpha: Alpha));
88 Graphics()->QuadsSetRotation(Angle: HandAngle);
89 Graphics()->TextureSet(Texture: pSkinTextures->m_HandsOutline);
90 Graphics()->RenderQuadContainerAsSprite(ContainerIndex: m_WeaponEmoteQuadContainerIndex, QuadOffset: NUM_WEAPONS * 2, X: HandPos.x, Y: HandPos.y);
91 Graphics()->TextureSet(Texture: pSkinTextures->m_Hands);
92 Graphics()->RenderQuadContainerAsSprite(ContainerIndex: m_WeaponEmoteQuadContainerIndex, QuadOffset: NUM_WEAPONS * 2 + 1, X: HandPos.x, Y: HandPos.y);
93}
94
95float CPlayers::GetPlayerTargetAngle(
96 const CNetObj_Character *pPrevChar,
97 const CNetObj_Character *pPlayerChar,
98 int ClientId,
99 float Intra)
100{
101 if(GameClient()->PredictDummy() && GameClient()->m_aLocalIds[!g_Config.m_ClDummy] == ClientId)
102 {
103 const CNetObj_PlayerInput &Input = g_Config.m_ClDummyHammer ? GameClient()->m_HammerInput : GameClient()->m_DummyInput;
104 return angle(a: vec2(Input.m_TargetX, Input.m_TargetY));
105 }
106
107 // with dummy copy, use the same angle as local player
108 if((GameClient()->m_Snap.m_LocalClientId == ClientId || (GameClient()->PredictDummy() && g_Config.m_ClDummyCopyMoves && GameClient()->m_aLocalIds[!g_Config.m_ClDummy] == ClientId)) &&
109 !GameClient()->m_Snap.m_SpecInfo.m_Active && Client()->State() != IClient::STATE_DEMOPLAYBACK)
110 {
111 // calculate what would be sent to the server from our current input
112 vec2 Direction = normalize(v: vec2((int)GameClient()->m_Controls.m_aMousePos[g_Config.m_ClDummy].x, (int)GameClient()->m_Controls.m_aMousePos[g_Config.m_ClDummy].y));
113
114 // fix direction if mouse is exactly in the center
115 if(Direction == vec2(0.0f, 0.0f))
116 Direction = vec2(1.0f, 0.0f);
117
118 return angle(a: Direction);
119 }
120
121 // using unpredicted angle when rendering other players in-game
122 if(ClientId >= 0)
123 Intra = Client()->IntraGameTick(Conn: g_Config.m_ClDummy);
124
125 if(ClientId >= 0 && GameClient()->m_Snap.m_aCharacters[ClientId].m_HasExtendedDisplayInfo)
126 {
127 const CNetObj_DDNetCharacter *pExtendedData = &GameClient()->m_Snap.m_aCharacters[ClientId].m_ExtendedData;
128 const CNetObj_DDNetCharacter *pPrevExtendedData = GameClient()->m_Snap.m_aCharacters[ClientId].m_pPrevExtendedData;
129 if(pPrevExtendedData)
130 {
131 float MixX = mix(a: (float)pPrevExtendedData->m_TargetX, b: (float)pExtendedData->m_TargetX, amount: Intra);
132 float MixY = mix(a: (float)pPrevExtendedData->m_TargetY, b: (float)pExtendedData->m_TargetY, amount: Intra);
133 return angle(a: vec2(MixX, MixY));
134 }
135 else
136 {
137 return angle(a: vec2(pExtendedData->m_TargetX, pExtendedData->m_TargetY));
138 }
139 }
140 else
141 {
142 // If the player moves their weapon through top, then change
143 // the end angle by 2*Pi, so that the mix function will use the
144 // short path and not the long one.
145 if(pPlayerChar->m_Angle > (256.0f * pi) && pPrevChar->m_Angle < 0)
146 {
147 return mix(a: (float)pPrevChar->m_Angle, b: (float)(pPlayerChar->m_Angle - 256.0f * 2 * pi), amount: Intra) / 256.0f;
148 }
149 else if(pPlayerChar->m_Angle < 0 && pPrevChar->m_Angle > (256.0f * pi))
150 {
151 return mix(a: (float)pPrevChar->m_Angle, b: (float)(pPlayerChar->m_Angle + 256.0f * 2 * pi), amount: Intra) / 256.0f;
152 }
153 else
154 {
155 return mix(a: (float)pPrevChar->m_Angle, b: (float)pPlayerChar->m_Angle, amount: Intra) / 256.0f;
156 }
157 }
158}
159
160void CPlayers::RenderHookCollLine(
161 const CNetObj_Character *pPrevChar,
162 const CNetObj_Character *pPlayerChar,
163 int ClientId)
164{
165 CNetObj_Character Prev;
166 CNetObj_Character Player;
167 Prev = *pPrevChar;
168 Player = *pPlayerChar;
169
170 dbg_assert(in_range(ClientId, MAX_CLIENTS - 1), "invalid client id (%d)", ClientId);
171
172 if(!GameClient()->m_GameInfo.m_AllowHookColl)
173 return;
174
175 bool Local = GameClient()->m_Snap.m_LocalClientId == ClientId;
176
177#if defined(CONF_VIDEORECORDER)
178 if(IVideo::Current() && !g_Config.m_ClVideoShowHookCollOther && !Local)
179 return;
180#endif
181
182 bool Aim = (Player.m_PlayerFlags & PLAYERFLAG_AIM);
183 if(!Client()->ServerCapAnyPlayerFlag())
184 {
185 for(int i = 0; i < NUM_DUMMIES; i++)
186 {
187 if(ClientId == GameClient()->m_aLocalIds[i])
188 {
189 Aim = GameClient()->m_Controls.m_aShowHookColl[i];
190 break;
191 }
192 }
193 }
194
195 if(GameClient()->PredictDummy() && g_Config.m_ClDummyCopyMoves && GameClient()->m_aLocalIds[!g_Config.m_ClDummy] == ClientId)
196 Aim = false; // don't use unpredicted with copy moves
197
198 bool AlwaysRenderHookColl = (Local ? g_Config.m_ClShowHookCollOwn : g_Config.m_ClShowHookCollOther) == 2;
199 bool RenderHookCollPlayer = Aim && (Local ? g_Config.m_ClShowHookCollOwn : g_Config.m_ClShowHookCollOther) > 0;
200 if(Local && Client()->State() != IClient::STATE_DEMOPLAYBACK)
201 RenderHookCollPlayer = GameClient()->m_Controls.m_aShowHookColl[g_Config.m_ClDummy] && g_Config.m_ClShowHookCollOwn > 0;
202
203 if(GameClient()->PredictDummy() && g_Config.m_ClDummyCopyMoves &&
204 GameClient()->m_aLocalIds[!g_Config.m_ClDummy] == ClientId && GameClient()->m_Controls.m_aShowHookColl[g_Config.m_ClDummy] &&
205 Client()->State() != IClient::STATE_DEMOPLAYBACK)
206 {
207 RenderHookCollPlayer = g_Config.m_ClShowHookCollOther > 0;
208 }
209
210 if(!AlwaysRenderHookColl && !RenderHookCollPlayer)
211 return;
212
213 float Intra = GameClient()->m_aClients[ClientId].m_IsPredicted ? Client()->PredIntraGameTick(Conn: g_Config.m_ClDummy) : Client()->IntraGameTick(Conn: g_Config.m_ClDummy);
214 float Angle = GetPlayerTargetAngle(pPrevChar: &Prev, pPlayerChar: &Player, ClientId, Intra);
215
216 vec2 Direction = direction(angle: Angle);
217 vec2 Position = GameClient()->m_aClients[ClientId].m_RenderPos;
218
219 static constexpr float HOOK_START_DISTANCE = CCharacterCore::PhysicalSize() * 1.5f;
220 float HookLength = (float)GameClient()->m_aClients[ClientId].m_Predicted.m_Tuning.m_HookLength;
221 float HookFireSpeed = (float)GameClient()->m_aClients[ClientId].m_Predicted.m_Tuning.m_HookFireSpeed;
222
223 // janky physics
224 if(HookLength < HOOK_START_DISTANCE || HookFireSpeed <= 0.0f)
225 return;
226
227 vec2 QuantizedDirection = Direction;
228 vec2 StartOffset = Direction * HOOK_START_DISTANCE;
229 vec2 BasePos = Position;
230 vec2 LineStartPos = BasePos + StartOffset;
231 vec2 SegmentStartPos = LineStartPos;
232
233 ColorRGBA HookCollColor = color_cast<ColorRGBA>(hsl: ColorHSLA(g_Config.m_ClHookCollColorNoColl));
234 std::vector<IGraphics::CLineItem> vLineSegments;
235
236 const int MaxHookTicks = 5 * Client()->GameTickSpeed(); // calculating above 5 seconds is very expensive and unlikely to happen
237
238 auto AddHookPlayerSegment = [&](const vec2 &StartPos, const vec2 &EndPos, const vec2 &HookablePlayerPosition, const vec2 &HitPos) {
239 HookCollColor = color_cast<ColorRGBA>(hsl: ColorHSLA(g_Config.m_ClHookCollColorTeeColl));
240
241 // stop hookline at player circle so it looks better
242 vec2 aIntersections[2];
243 int NumIntersections = intersect_line_circle(LineStart: StartPos, LineEnd: EndPos, CircleCenter: HookablePlayerPosition, Radius: CCharacterCore::PhysicalSize() * 1.45f / 2.0f, aIntersections);
244 if(NumIntersections == 2)
245 {
246 if(distance(a: Position, b: aIntersections[0]) < distance(a: Position, b: aIntersections[1]))
247 vLineSegments.emplace_back(args: StartPos, args&: aIntersections[0]);
248 else
249 vLineSegments.emplace_back(args: StartPos, args&: aIntersections[1]);
250 }
251 else if(NumIntersections == 1)
252 vLineSegments.emplace_back(args: StartPos, args&: aIntersections[0]);
253 else
254 vLineSegments.emplace_back(args: StartPos, args: HitPos);
255 };
256
257 // simulate the hook into the future
258 int HookTick;
259 bool HookEnteredTelehook = false;
260 for(HookTick = 0; HookTick < MaxHookTicks; ++HookTick)
261 {
262 int Tele;
263 vec2 HitPos, IntersectedPlayerPosition;
264 vec2 SegmentEndPos = SegmentStartPos + QuantizedDirection * HookFireSpeed;
265
266 // check if a hook would enter retracting state in this tick
267 if(distance(a: BasePos, b: SegmentEndPos) > HookLength)
268 {
269 // check if the retracting hook hits a player
270 if(!HookEnteredTelehook)
271 {
272 vec2 RetractingHookEndPos = BasePos + normalize(v: SegmentEndPos - BasePos) * HookLength;
273 if(GameClient()->IntersectCharacter(HookPos: SegmentStartPos, NewPos: RetractingHookEndPos, NewPos2&: HitPos, OwnId: ClientId, pPlayerPosition: &IntersectedPlayerPosition) != -1)
274 {
275 AddHookPlayerSegment(LineStartPos, SegmentEndPos, IntersectedPlayerPosition, HitPos);
276 break;
277 }
278 }
279
280 // the line is too long here, and the hook retracts, use old position
281 vLineSegments.emplace_back(args&: LineStartPos, args&: SegmentStartPos);
282 break;
283 }
284
285 // check for map collisions
286 int Hit = Collision()->IntersectLineTeleHook(Pos0: SegmentStartPos, Pos1: SegmentEndPos, pOutCollision: &HitPos, pOutBeforeCollision: nullptr, pTeleNr: &Tele);
287
288 // check if we intersect a player
289 if(GameClient()->IntersectCharacter(HookPos: SegmentStartPos, NewPos: HitPos, NewPos2&: SegmentEndPos, OwnId: ClientId, pPlayerPosition: &IntersectedPlayerPosition) != -1)
290 {
291 AddHookPlayerSegment(LineStartPos, HitPos, IntersectedPlayerPosition, SegmentEndPos);
292 break;
293 }
294
295 // we hit nothing, continue calculating segments
296 if(!Hit)
297 {
298 SegmentStartPos = SegmentEndPos;
299 SegmentStartPos.x = round_to_int(f: SegmentStartPos.x);
300 SegmentStartPos.y = round_to_int(f: SegmentStartPos.y);
301
302 // direction is always the same after the first tick quantization
303 if(HookTick == 0)
304 {
305 QuantizedDirection.x = round_to_int(f: QuantizedDirection.x * 256.0f) / 256.0f;
306 QuantizedDirection.y = round_to_int(f: QuantizedDirection.y * 256.0f) / 256.0f;
307 }
308 continue;
309 }
310
311 // we hit a solid / hook stopper
312 if(Hit != TILE_TELEINHOOK)
313 {
314 if(Hit != TILE_NOHOOK)
315 HookCollColor = color_cast<ColorRGBA>(hsl: ColorHSLA(g_Config.m_ClHookCollColorHookableColl));
316 vLineSegments.emplace_back(args&: LineStartPos, args&: HitPos);
317 break;
318 }
319
320 // we are hitting TILE_TELEINHOOK
321 vLineSegments.emplace_back(args&: LineStartPos, args&: HitPos);
322 HookEnteredTelehook = true;
323
324 // check tele outs
325 const std::vector<vec2> &vTeleOuts = Collision()->TeleOuts(Number: Tele - 1);
326 if(vTeleOuts.empty())
327 {
328 // the hook gets stuck, this is a feature or a bug
329 HookCollColor = color_cast<ColorRGBA>(hsl: ColorHSLA(g_Config.m_ClHookCollColorHookableColl));
330 break;
331 }
332 else if(vTeleOuts.size() > 1)
333 {
334 // we don't know which teleout the hook takes, just invert the color
335 HookCollColor = color_invert(col: color_cast<ColorRGBA>(hsl: ColorHSLA(g_Config.m_ClHookCollColorTeeColl)));
336 break;
337 }
338
339 // go through one teleout, update positions and continue
340 BasePos = vTeleOuts[0];
341 LineStartPos = BasePos; // make the line start in the teleporter to prevent a gap
342 SegmentStartPos = BasePos + Direction * HOOK_START_DISTANCE;
343 SegmentStartPos.x = round_to_int(f: SegmentStartPos.x);
344 SegmentStartPos.y = round_to_int(f: SegmentStartPos.y);
345
346 // direction is always the same after the first tick quantization
347 if(HookTick == 0)
348 {
349 QuantizedDirection.x = round_to_int(f: QuantizedDirection.x * 256.0f) / 256.0f;
350 QuantizedDirection.y = round_to_int(f: QuantizedDirection.y * 256.0f) / 256.0f;
351 }
352 }
353
354 // The hook line is too expensive to calculate and didn't hit anything before, just set a straight line
355 if(HookTick >= MaxHookTicks && vLineSegments.empty())
356 {
357 // we simply don't know if we hit anything or not
358 HookCollColor = color_invert(col: color_cast<ColorRGBA>(hsl: ColorHSLA(g_Config.m_ClHookCollColorTeeColl)));
359 vLineSegments.emplace_back(args&: LineStartPos, args: BasePos + QuantizedDirection * HookLength);
360 }
361
362 // add a line from the player to the start position to prevent a visual gap
363 vLineSegments.emplace_back(args&: Position, args: Position + StartOffset);
364
365 if(AlwaysRenderHookColl && RenderHookCollPlayer)
366 {
367 // invert the hook coll colors when using cl_show_hook_coll_always and +showhookcoll is pressed
368 HookCollColor = color_invert(col: HookCollColor);
369 }
370
371 // Render hook coll line
372 const int HookCollSize = Local ? g_Config.m_ClHookCollSize : g_Config.m_ClHookCollSizeOther;
373
374 float Alpha = GameClient()->IsOtherTeam(ClientId) ? g_Config.m_ClShowOthersAlpha / 100.0f : 1.0f;
375 Alpha *= (float)g_Config.m_ClHookCollAlpha / 100;
376 if(Alpha <= 0.0f)
377 return;
378
379 Graphics()->TextureClear();
380 if(HookCollSize > 0)
381 {
382 std::vector<IGraphics::CFreeformItem> vLineQuadSegments;
383 vLineQuadSegments.reserve(n: vLineSegments.size());
384
385 float LineWidth = 0.5f + (float)(HookCollSize - 1) * 0.25f;
386 const vec2 PerpToAngle = normalize(v: vec2(Direction.y, -Direction.x)) * GameClient()->m_Camera.m_Zoom;
387
388 for(const auto &LineSegment : vLineSegments)
389 {
390 vec2 DrawInitPos(LineSegment.m_X0, LineSegment.m_Y0);
391 vec2 DrawFinishPos(LineSegment.m_X1, LineSegment.m_Y1);
392 vec2 Pos0 = DrawFinishPos + PerpToAngle * -LineWidth;
393 vec2 Pos1 = DrawFinishPos + PerpToAngle * LineWidth;
394 vec2 Pos2 = DrawInitPos + PerpToAngle * -LineWidth;
395 vec2 Pos3 = DrawInitPos + PerpToAngle * LineWidth;
396 vLineQuadSegments.emplace_back(args&: Pos0.x, args&: Pos0.y, args&: Pos1.x, args&: Pos1.y, args&: Pos2.x, args&: Pos2.y, args&: Pos3.x, args&: Pos3.y);
397 }
398 Graphics()->QuadsBegin();
399 Graphics()->SetColor(HookCollColor.WithAlpha(alpha: Alpha));
400 Graphics()->QuadsDrawFreeform(pArray: vLineQuadSegments.data(), Num: vLineQuadSegments.size());
401 Graphics()->QuadsEnd();
402 }
403 else
404 {
405 Graphics()->LinesBegin();
406 Graphics()->SetColor(HookCollColor.WithAlpha(alpha: Alpha));
407 Graphics()->LinesDraw(pArray: vLineSegments.data(), Num: vLineSegments.size());
408 Graphics()->LinesEnd();
409 }
410}
411
412void CPlayers::RenderHook(
413 const CNetObj_Character *pPrevChar,
414 const CNetObj_Character *pPlayerChar,
415 const CTeeRenderInfo *pRenderInfo,
416 int ClientId,
417 float Intra)
418{
419 if(pPrevChar->m_HookState <= 0 || pPlayerChar->m_HookState <= 0)
420 return;
421
422 CNetObj_Character Prev;
423 CNetObj_Character Player;
424 Prev = *pPrevChar;
425 Player = *pPlayerChar;
426
427 CTeeRenderInfo RenderInfo = *pRenderInfo;
428
429 // don't render hooks to not active character cores
430 if(pPlayerChar->m_HookedPlayer != -1 && !GameClient()->m_Snap.m_aCharacters[pPlayerChar->m_HookedPlayer].m_Active)
431 return;
432
433 if(ClientId >= 0)
434 Intra = GameClient()->m_aClients[ClientId].m_IsPredicted ? Client()->PredIntraGameTick(Conn: g_Config.m_ClDummy) : Client()->IntraGameTick(Conn: g_Config.m_ClDummy);
435
436 bool OtherTeam = GameClient()->IsOtherTeam(ClientId);
437 float Alpha = (OtherTeam || ClientId < 0) ? g_Config.m_ClShowOthersAlpha / 100.0f : 1.0f;
438 if(ClientId == -2) // ghost
439 Alpha = g_Config.m_ClRaceGhostAlpha / 100.0f;
440
441 RenderInfo.m_Size = 64.0f;
442
443 vec2 Position;
444 if(in_range(a: ClientId, upper: MAX_CLIENTS - 1))
445 Position = GameClient()->m_aClients[ClientId].m_RenderPos;
446 else
447 Position = mix(a: vec2(Prev.m_X, Prev.m_Y), b: vec2(Player.m_X, Player.m_Y), amount: Intra);
448
449 // draw hook
450 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: 1.0f);
451 if(ClientId < 0)
452 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: 0.5f);
453
454 vec2 Pos = Position;
455 vec2 HookPos;
456
457 if(in_range(a: pPlayerChar->m_HookedPlayer, upper: MAX_CLIENTS - 1))
458 HookPos = GameClient()->m_aClients[pPlayerChar->m_HookedPlayer].m_RenderPos;
459 else
460 HookPos = mix(a: vec2(Prev.m_HookX, Prev.m_HookY), b: vec2(Player.m_HookX, Player.m_HookY), amount: Intra);
461
462 float d = distance(a: Pos, b: HookPos);
463 vec2 Dir = normalize(v: Pos - HookPos);
464
465 Graphics()->TextureSet(Texture: GameClient()->m_GameSkin.m_SpriteHookHead);
466 Graphics()->QuadsSetRotation(Angle: angle(a: Dir) + pi);
467 // render head
468 int QuadOffset = NUM_WEAPONS * 2 + 2;
469 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: Alpha);
470 Graphics()->RenderQuadContainerAsSprite(ContainerIndex: m_WeaponEmoteQuadContainerIndex, QuadOffset, X: HookPos.x, Y: HookPos.y);
471
472 // render chain
473 ++QuadOffset;
474 static IGraphics::SRenderSpriteInfo s_aHookChainRenderInfo[1024];
475 int HookChainCount = 0;
476 for(float f = 24; f < d && HookChainCount < 1024; f += 24, ++HookChainCount)
477 {
478 vec2 p = HookPos + Dir * f;
479 s_aHookChainRenderInfo[HookChainCount].m_Pos[0] = p.x;
480 s_aHookChainRenderInfo[HookChainCount].m_Pos[1] = p.y;
481 s_aHookChainRenderInfo[HookChainCount].m_Scale = 1;
482 s_aHookChainRenderInfo[HookChainCount].m_Rotation = angle(a: Dir) + pi;
483 }
484 Graphics()->TextureSet(Texture: GameClient()->m_GameSkin.m_SpriteHookChain);
485 Graphics()->RenderQuadContainerAsSpriteMultiple(ContainerIndex: m_WeaponEmoteQuadContainerIndex, QuadOffset, DrawCount: HookChainCount, pRenderInfo: s_aHookChainRenderInfo);
486
487 Graphics()->QuadsSetRotation(Angle: 0);
488 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: 1.0f);
489
490 RenderHand(pInfo: &RenderInfo, CenterPos: Position, Dir: normalize(v: HookPos - Pos), AngleOffset: -pi / 2, PostRotOffset: vec2(20, 0), Alpha);
491}
492
493void CPlayers::RenderPlayer(
494 const CNetObj_Character *pPrevChar,
495 const CNetObj_Character *pPlayerChar,
496 const CTeeRenderInfo *pRenderInfo,
497 int ClientId,
498 float Intra)
499{
500 CNetObj_Character Prev;
501 CNetObj_Character Player;
502 Prev = *pPrevChar;
503 Player = *pPlayerChar;
504
505 CTeeRenderInfo RenderInfo = *pRenderInfo;
506
507 bool Local = GameClient()->m_Snap.m_LocalClientId == ClientId;
508 bool OtherTeam = GameClient()->IsOtherTeam(ClientId);
509 float Alpha = (OtherTeam || ClientId < 0) ? g_Config.m_ClShowOthersAlpha / 100.0f : 1.0f;
510 if(ClientId == -2) // ghost
511 Alpha = g_Config.m_ClRaceGhostAlpha / 100.0f;
512 // TODO: snd_game_volume_others
513 const float Volume = 1.0f;
514
515 // set size
516 RenderInfo.m_Size = 64.0f;
517
518 if(ClientId >= 0)
519 Intra = GameClient()->m_aClients[ClientId].m_IsPredicted ? Client()->PredIntraGameTick(Conn: g_Config.m_ClDummy) : Client()->IntraGameTick(Conn: g_Config.m_ClDummy);
520
521 static float s_LastGameTickTime = Client()->GameTickTime(Conn: g_Config.m_ClDummy);
522 static float s_LastPredIntraTick = Client()->PredIntraGameTick(Conn: g_Config.m_ClDummy);
523 if(GameClient()->m_Snap.m_pGameInfoObj && !(GameClient()->m_Snap.m_pGameInfoObj->m_GameStateFlags & GAMESTATEFLAG_PAUSED))
524 {
525 s_LastGameTickTime = Client()->GameTickTime(Conn: g_Config.m_ClDummy);
526 s_LastPredIntraTick = Client()->PredIntraGameTick(Conn: g_Config.m_ClDummy);
527 }
528
529 bool PredictLocalWeapons = false;
530 float AttackTime = (Client()->PrevGameTick(Conn: g_Config.m_ClDummy) - Player.m_AttackTick) / (float)Client()->GameTickSpeed() + Client()->GameTickTime(Conn: g_Config.m_ClDummy);
531 float LastAttackTime = (Client()->PrevGameTick(Conn: g_Config.m_ClDummy) - Player.m_AttackTick) / (float)Client()->GameTickSpeed() + s_LastGameTickTime;
532 if(ClientId >= 0 && GameClient()->m_aClients[ClientId].m_IsPredictedLocal && GameClient()->AntiPingGunfire())
533 {
534 PredictLocalWeapons = true;
535 AttackTime = (Client()->PredIntraGameTick(Conn: g_Config.m_ClDummy) + (Client()->PredGameTick(Conn: g_Config.m_ClDummy) - 1 - Player.m_AttackTick)) / (float)Client()->GameTickSpeed();
536 LastAttackTime = (s_LastPredIntraTick + (Client()->PredGameTick(Conn: g_Config.m_ClDummy) - 1 - Player.m_AttackTick)) / (float)Client()->GameTickSpeed();
537 }
538 float AttackTicksPassed = AttackTime * (float)Client()->GameTickSpeed();
539
540 float Angle = GetPlayerTargetAngle(pPrevChar: &Prev, pPlayerChar: &Player, ClientId, Intra);
541
542 vec2 Direction = direction(angle: Angle);
543 vec2 Position;
544 if(in_range(a: ClientId, upper: MAX_CLIENTS - 1))
545 Position = GameClient()->m_aClients[ClientId].m_RenderPos;
546 else
547 Position = mix(a: vec2(Prev.m_X, Prev.m_Y), b: vec2(Player.m_X, Player.m_Y), amount: Intra);
548 vec2 Vel = mix(a: vec2(Prev.m_VelX / 256.0f, Prev.m_VelY / 256.0f), b: vec2(Player.m_VelX / 256.0f, Player.m_VelY / 256.0f), amount: Intra);
549
550 GameClient()->m_Flow.Add(Pos: Position, Vel: Vel * 100.0f, Size: 10.0f);
551
552 RenderInfo.m_GotAirJump = Player.m_Jumped & 2 ? false : true;
553
554 RenderInfo.m_FeetFlipped = false;
555
556 bool Stationary = Player.m_VelX <= 1 && Player.m_VelX >= -1;
557 bool InAir = !Collision()->CheckPoint(x: Player.m_X, y: Player.m_Y + 16);
558 bool Running = Player.m_VelX >= 5000 || Player.m_VelX <= -5000;
559 bool WantOtherDir = (Player.m_Direction == -1 && Vel.x > 0) || (Player.m_Direction == 1 && Vel.x < 0);
560 bool Inactive = ClientId >= 0 && (GameClient()->m_aClients[ClientId].m_Afk || GameClient()->m_aClients[ClientId].m_Paused);
561
562 // evaluate animation
563 float WalkTime = std::fmod(x: Position.x, y: 100.0f) / 100.0f;
564 float RunTime = std::fmod(x: Position.x, y: 200.0f) / 200.0f;
565
566 // Don't do a moon walk outside the left border
567 if(WalkTime < 0.0f)
568 WalkTime += 1.0f;
569 if(RunTime < 0.0f)
570 RunTime += 1.0f;
571
572 CAnimState State;
573 State.Set(pAnim: &g_pData->m_aAnimations[ANIM_BASE], Time: 0.0f);
574
575 if(InAir)
576 State.Add(pAnim: &g_pData->m_aAnimations[ANIM_INAIR], Time: 0.0f, Amount: 1.0f); // TODO: some sort of time here
577 else if(Stationary)
578 {
579 if(Inactive)
580 {
581 State.Add(pAnim: Direction.x < 0.0f ? &g_pData->m_aAnimations[ANIM_SIT_LEFT] : &g_pData->m_aAnimations[ANIM_SIT_RIGHT], Time: 0.0f, Amount: 1.0f); // TODO: some sort of time here
582 RenderInfo.m_FeetFlipped = true;
583 }
584 else
585 State.Add(pAnim: &g_pData->m_aAnimations[ANIM_IDLE], Time: 0.0f, Amount: 1.0f); // TODO: some sort of time here
586 }
587 else if(!WantOtherDir)
588 {
589 if(Running)
590 State.Add(pAnim: Player.m_VelX < 0 ? &g_pData->m_aAnimations[ANIM_RUN_LEFT] : &g_pData->m_aAnimations[ANIM_RUN_RIGHT], Time: RunTime, Amount: 1.0f);
591 else
592 State.Add(pAnim: &g_pData->m_aAnimations[ANIM_WALK], Time: WalkTime, Amount: 1.0f);
593 }
594
595 if(Player.m_Weapon == WEAPON_HAMMER)
596 State.Add(pAnim: &g_pData->m_aAnimations[ANIM_HAMMER_SWING], Time: std::clamp(val: LastAttackTime * 5.0f, lo: 0.0f, hi: 1.0f), Amount: 1.0f);
597 if(Player.m_Weapon == WEAPON_NINJA)
598 State.Add(pAnim: &g_pData->m_aAnimations[ANIM_NINJA_SWING], Time: std::clamp(val: LastAttackTime * 2.0f, lo: 0.0f, hi: 1.0f), Amount: 1.0f);
599
600 // do skidding
601 if(!InAir && WantOtherDir && length(a: Vel * 50) > 500.0f)
602 GameClient()->m_Effects.SkidTrail(Pos: Position, Vel, Direction: Player.m_Direction, Alpha, Volume);
603
604 // draw gun
605 if(Player.m_Weapon >= 0)
606 {
607 if(!(RenderInfo.m_TeeRenderFlags & TEE_NO_WEAPON))
608 {
609 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: Alpha);
610
611 // normal weapons
612 int CurrentWeapon = std::clamp(val: Player.m_Weapon, lo: 0, hi: NUM_WEAPONS - 1);
613 Graphics()->TextureSet(Texture: GameClient()->m_GameSkin.m_aSpriteWeapons[CurrentWeapon]);
614 int QuadOffset = CurrentWeapon * 2 + (Direction.x < 0.0f ? 1 : 0);
615
616 float Recoil = 0.0f;
617 vec2 WeaponPosition;
618 bool IsSit = Inactive && !InAir && Stationary;
619
620 if(Player.m_Weapon == WEAPON_HAMMER)
621 {
622 // static position for hammer
623 WeaponPosition = Position + vec2(State.GetAttach()->m_X, State.GetAttach()->m_Y);
624 WeaponPosition.y += g_pData->m_Weapons.m_aId[CurrentWeapon].m_Offsety;
625 if(Direction.x < 0.0f)
626 WeaponPosition.x -= g_pData->m_Weapons.m_aId[CurrentWeapon].m_Offsetx;
627 if(IsSit)
628 WeaponPosition.y += 3.0f;
629
630 // if active and attack is under way, bash stuffs
631 if(!Inactive || LastAttackTime < GameClient()->m_aClients[ClientId].m_Predicted.m_Tuning.GetWeaponFireDelay(Weapon: Player.m_Weapon))
632 {
633 if(Direction.x < 0)
634 Graphics()->QuadsSetRotation(Angle: -pi / 2.0f - State.GetAttach()->m_Angle * pi * 2.0f);
635 else
636 Graphics()->QuadsSetRotation(Angle: -pi / 2.0f + State.GetAttach()->m_Angle * pi * 2.0f);
637 }
638 else
639 Graphics()->QuadsSetRotation(Angle: Direction.x < 0.0f ? 100.0f : 500.0f);
640
641 Graphics()->RenderQuadContainerAsSprite(ContainerIndex: m_WeaponEmoteQuadContainerIndex, QuadOffset, X: WeaponPosition.x, Y: WeaponPosition.y);
642 }
643 else if(Player.m_Weapon == WEAPON_NINJA)
644 {
645 WeaponPosition = Position;
646 WeaponPosition.y += g_pData->m_Weapons.m_aId[CurrentWeapon].m_Offsety;
647 if(IsSit)
648 WeaponPosition.y += 3.0f;
649
650 if(Direction.x < 0.0f)
651 {
652 Graphics()->QuadsSetRotation(Angle: -pi / 2 - State.GetAttach()->m_Angle * pi * 2.0f);
653 WeaponPosition.x -= g_pData->m_Weapons.m_aId[CurrentWeapon].m_Offsetx;
654 GameClient()->m_Effects.PowerupShine(Pos: WeaponPosition + vec2(32.0f, 0.0f), Size: vec2(32.0f, 12.0f), Alpha);
655 }
656 else
657 {
658 Graphics()->QuadsSetRotation(Angle: -pi / 2 + State.GetAttach()->m_Angle * pi * 2.0f);
659 GameClient()->m_Effects.PowerupShine(Pos: WeaponPosition - vec2(32.0f, 0.0f), Size: vec2(32.0f, 12.0f), Alpha);
660 }
661 Graphics()->RenderQuadContainerAsSprite(ContainerIndex: m_WeaponEmoteQuadContainerIndex, QuadOffset, X: WeaponPosition.x, Y: WeaponPosition.y);
662
663 // HADOKEN
664 if(AttackTime <= 1.0f / 6.0f && g_pData->m_Weapons.m_aId[CurrentWeapon].m_NumSpriteMuzzles)
665 {
666 int IteX = rand() % g_pData->m_Weapons.m_aId[CurrentWeapon].m_NumSpriteMuzzles;
667 static int s_LastIteX = IteX;
668 if(Client()->State() == IClient::STATE_DEMOPLAYBACK)
669 {
670 const IDemoPlayer::CInfo *pInfo = DemoPlayer()->BaseInfo();
671 if(pInfo->m_Paused)
672 IteX = s_LastIteX;
673 else
674 s_LastIteX = IteX;
675 }
676 else
677 {
678 if(GameClient()->m_Snap.m_pGameInfoObj && GameClient()->m_Snap.m_pGameInfoObj->m_GameStateFlags & GAMESTATEFLAG_PAUSED)
679 IteX = s_LastIteX;
680 else
681 s_LastIteX = IteX;
682 }
683 if(g_pData->m_Weapons.m_aId[CurrentWeapon].m_aSpriteMuzzles[IteX])
684 {
685 vec2 HadokenDirection;
686 if(PredictLocalWeapons || ClientId < 0)
687 HadokenDirection = vec2(pPlayerChar->m_X, pPlayerChar->m_Y) - vec2(pPrevChar->m_X, pPrevChar->m_Y);
688 else
689 HadokenDirection = vec2(GameClient()->m_Snap.m_aCharacters[ClientId].m_Cur.m_X, GameClient()->m_Snap.m_aCharacters[ClientId].m_Cur.m_Y) - vec2(GameClient()->m_Snap.m_aCharacters[ClientId].m_Prev.m_X, GameClient()->m_Snap.m_aCharacters[ClientId].m_Prev.m_Y);
690 float HadokenAngle = 0.0f;
691 if(absolute(a: HadokenDirection.x) > 0.0001f || absolute(a: HadokenDirection.y) > 0.0001f)
692 {
693 HadokenDirection = normalize(v: HadokenDirection);
694 HadokenAngle = angle(a: HadokenDirection);
695 }
696 else
697 {
698 HadokenDirection = vec2(1.0f, 0.0f);
699 }
700 Graphics()->QuadsSetRotation(Angle: HadokenAngle);
701 QuadOffset = IteX * 2;
702 WeaponPosition = Position;
703 float OffsetX = g_pData->m_Weapons.m_aId[CurrentWeapon].m_Muzzleoffsetx;
704 WeaponPosition -= HadokenDirection * OffsetX;
705 Graphics()->TextureSet(Texture: GameClient()->m_GameSkin.m_aaSpriteWeaponsMuzzles[CurrentWeapon][IteX]);
706 Graphics()->RenderQuadContainerAsSprite(ContainerIndex: m_aWeaponSpriteMuzzleQuadContainerIndex[CurrentWeapon], QuadOffset, X: WeaponPosition.x, Y: WeaponPosition.y);
707 }
708 }
709 }
710 else
711 {
712 // TODO: should be an animation
713 Recoil = 0.0f;
714 float a = AttackTicksPassed / 5.0f;
715 if(a < 1.0f)
716 Recoil = std::sin(x: a * pi);
717 WeaponPosition = Position + Direction * g_pData->m_Weapons.m_aId[CurrentWeapon].m_Offsetx - Direction * Recoil * 10.0f;
718 WeaponPosition.y += g_pData->m_Weapons.m_aId[CurrentWeapon].m_Offsety;
719 if(IsSit)
720 WeaponPosition.y += 3.0f;
721 if(Player.m_Weapon == WEAPON_GUN && g_Config.m_ClOldGunPosition)
722 WeaponPosition.y -= 8.0f;
723 Graphics()->QuadsSetRotation(Angle: State.GetAttach()->m_Angle * pi * 2.0f + Angle);
724 Graphics()->RenderQuadContainerAsSprite(ContainerIndex: m_WeaponEmoteQuadContainerIndex, QuadOffset, X: WeaponPosition.x, Y: WeaponPosition.y);
725 }
726
727 if(Player.m_Weapon == WEAPON_GUN || Player.m_Weapon == WEAPON_SHOTGUN)
728 {
729 // check if we're firing stuff
730 if(g_pData->m_Weapons.m_aId[CurrentWeapon].m_NumSpriteMuzzles) // prev.attackticks)
731 {
732 float AlphaMuzzle = 0.0f;
733 if(AttackTicksPassed < g_pData->m_Weapons.m_aId[CurrentWeapon].m_Muzzleduration + 3.0f)
734 {
735 float t = AttackTicksPassed / g_pData->m_Weapons.m_aId[CurrentWeapon].m_Muzzleduration;
736 AlphaMuzzle = mix(a: 2.0f, b: 0.0f, amount: minimum(a: 1.0f, b: maximum(a: 0.0f, b: t)));
737 }
738
739 int IteX = rand() % g_pData->m_Weapons.m_aId[CurrentWeapon].m_NumSpriteMuzzles;
740 static int s_LastIteX = IteX;
741 if(Client()->State() == IClient::STATE_DEMOPLAYBACK)
742 {
743 const IDemoPlayer::CInfo *pInfo = DemoPlayer()->BaseInfo();
744 if(pInfo->m_Paused)
745 IteX = s_LastIteX;
746 else
747 s_LastIteX = IteX;
748 }
749 else
750 {
751 if(GameClient()->m_Snap.m_pGameInfoObj && GameClient()->m_Snap.m_pGameInfoObj->m_GameStateFlags & GAMESTATEFLAG_PAUSED)
752 IteX = s_LastIteX;
753 else
754 s_LastIteX = IteX;
755 }
756 if(AlphaMuzzle > 0.0f && g_pData->m_Weapons.m_aId[CurrentWeapon].m_aSpriteMuzzles[IteX])
757 {
758 float OffsetY = -g_pData->m_Weapons.m_aId[CurrentWeapon].m_Muzzleoffsety;
759 QuadOffset = IteX * 2 + (Direction.x < 0.0f ? 1 : 0);
760 if(Direction.x < 0.0f)
761 OffsetY = -OffsetY;
762
763 vec2 DirectionY(-Direction.y, Direction.x);
764 vec2 MuzzlePos = WeaponPosition + Direction * g_pData->m_Weapons.m_aId[CurrentWeapon].m_Muzzleoffsetx + DirectionY * OffsetY;
765 Graphics()->TextureSet(Texture: GameClient()->m_GameSkin.m_aaSpriteWeaponsMuzzles[CurrentWeapon][IteX]);
766 Graphics()->RenderQuadContainerAsSprite(ContainerIndex: m_aWeaponSpriteMuzzleQuadContainerIndex[CurrentWeapon], QuadOffset, X: MuzzlePos.x, Y: MuzzlePos.y);
767 }
768 }
769 }
770 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: 1.0f);
771 Graphics()->QuadsSetRotation(Angle: 0.0f);
772
773 switch(Player.m_Weapon)
774 {
775 case WEAPON_GUN: RenderHand(pInfo: &RenderInfo, CenterPos: WeaponPosition, Dir: Direction, AngleOffset: -3.0f * pi / 4.0f, PostRotOffset: vec2(-15.0f, 4.0f), Alpha); break;
776 case WEAPON_SHOTGUN: RenderHand(pInfo: &RenderInfo, CenterPos: WeaponPosition, Dir: Direction, AngleOffset: -pi / 2.0f, PostRotOffset: vec2(-5.0f, 4.0f), Alpha); break;
777 case WEAPON_GRENADE: RenderHand(pInfo: &RenderInfo, CenterPos: WeaponPosition, Dir: Direction, AngleOffset: -pi / 2.0f, PostRotOffset: vec2(-4.0f, 7.0f), Alpha); break;
778 }
779 }
780 }
781
782 // render the "shadow" tee
783 if(Local && ((g_Config.m_Debug && g_Config.m_ClUnpredictedShadow >= 0) || g_Config.m_ClUnpredictedShadow == 1))
784 {
785 vec2 ShadowPosition = Position;
786 if(ClientId >= 0)
787 ShadowPosition = mix(
788 a: vec2(GameClient()->m_Snap.m_aCharacters[ClientId].m_Prev.m_X, GameClient()->m_Snap.m_aCharacters[ClientId].m_Prev.m_Y),
789 b: vec2(GameClient()->m_Snap.m_aCharacters[ClientId].m_Cur.m_X, GameClient()->m_Snap.m_aCharacters[ClientId].m_Cur.m_Y),
790 amount: Client()->IntraGameTick(Conn: g_Config.m_ClDummy));
791
792 RenderTools()->RenderTee(pAnim: &State, pInfo: &RenderInfo, Emote: Player.m_Emote, Dir: Direction, Pos: ShadowPosition, Alpha: 0.5f); // render ghost
793 }
794
795 RenderTools()->RenderTee(pAnim: &State, pInfo: &RenderInfo, Emote: Player.m_Emote, Dir: Direction, Pos: Position, Alpha);
796
797 float TeeAnimScale, TeeBaseSize;
798 CRenderTools::GetRenderTeeAnimScaleAndBaseSize(pInfo: &RenderInfo, AnimScale&: TeeAnimScale, BaseSize&: TeeBaseSize);
799 vec2 BodyPos = Position + vec2(State.GetBody()->m_X, State.GetBody()->m_Y) * TeeAnimScale;
800 if(RenderInfo.m_TeeRenderFlags & TEE_EFFECT_FROZEN)
801 {
802 GameClient()->m_Effects.FreezingFlakes(Pos: BodyPos, Size: vec2(32, 32), Alpha);
803 }
804 if(RenderInfo.m_TeeRenderFlags & TEE_EFFECT_SPARKLE)
805 {
806 GameClient()->m_Effects.SparkleTrail(Pos: BodyPos, Alpha);
807 }
808
809 if(ClientId < 0)
810 return;
811
812 int QuadOffsetToEmoticon = NUM_WEAPONS * 2 + 2 + 2;
813 if((Player.m_PlayerFlags & PLAYERFLAG_CHATTING) && !GameClient()->m_aClients[ClientId].m_Afk)
814 {
815 int CurEmoticon = (SPRITE_DOTDOT - SPRITE_OOP);
816 Graphics()->TextureSet(Texture: GameClient()->m_EmoticonsSkin.m_aSpriteEmoticons[CurEmoticon]);
817 int QuadOffset = QuadOffsetToEmoticon + CurEmoticon;
818 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: Alpha);
819 Graphics()->RenderQuadContainerAsSprite(ContainerIndex: m_WeaponEmoteQuadContainerIndex, QuadOffset, X: Position.x + 24.f, Y: Position.y - 40.f);
820
821 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: 1.0f);
822 Graphics()->QuadsSetRotation(Angle: 0);
823 }
824
825 if(g_Config.m_ClAfkEmote && GameClient()->m_aClients[ClientId].m_Afk && ClientId != GameClient()->m_aLocalIds[!g_Config.m_ClDummy])
826 {
827 int CurEmoticon = (SPRITE_ZZZ - SPRITE_OOP);
828 Graphics()->TextureSet(Texture: GameClient()->m_EmoticonsSkin.m_aSpriteEmoticons[CurEmoticon]);
829 int QuadOffset = QuadOffsetToEmoticon + CurEmoticon;
830 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: Alpha);
831 Graphics()->RenderQuadContainerAsSprite(ContainerIndex: m_WeaponEmoteQuadContainerIndex, QuadOffset, X: Position.x + 24.f, Y: Position.y - 40.f);
832
833 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: 1.0f);
834 Graphics()->QuadsSetRotation(Angle: 0);
835 }
836
837 if(g_Config.m_ClShowEmotes && !GameClient()->m_aClients[ClientId].m_EmoticonIgnore && GameClient()->m_aClients[ClientId].m_EmoticonStartTick != -1)
838 {
839 float SinceStart = (Client()->GameTick(Conn: g_Config.m_ClDummy) - GameClient()->m_aClients[ClientId].m_EmoticonStartTick) + (Client()->IntraGameTickSincePrev(Conn: g_Config.m_ClDummy) - GameClient()->m_aClients[ClientId].m_EmoticonStartFraction);
840 float FromEnd = (2 * Client()->GameTickSpeed()) - SinceStart;
841
842 if(0 <= SinceStart && FromEnd > 0)
843 {
844 float a = 1;
845
846 if(FromEnd < Client()->GameTickSpeed() / 5)
847 a = FromEnd / (Client()->GameTickSpeed() / 5.0f);
848
849 float h = 1;
850 if(SinceStart < Client()->GameTickSpeed() / 10)
851 h = SinceStart / (Client()->GameTickSpeed() / 10.0f);
852
853 float Wiggle = 0;
854 if(SinceStart < Client()->GameTickSpeed() / 5)
855 Wiggle = SinceStart / (Client()->GameTickSpeed() / 5.0f);
856
857 float WiggleAngle = std::sin(x: 5 * Wiggle);
858
859 Graphics()->QuadsSetRotation(Angle: pi / 6 * WiggleAngle);
860
861 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: a * Alpha);
862 // client_datas::emoticon is an offset from the first emoticon
863 int QuadOffset = QuadOffsetToEmoticon + GameClient()->m_aClients[ClientId].m_Emoticon;
864 Graphics()->TextureSet(Texture: GameClient()->m_EmoticonsSkin.m_aSpriteEmoticons[GameClient()->m_aClients[ClientId].m_Emoticon]);
865 Graphics()->RenderQuadContainerAsSprite(ContainerIndex: m_WeaponEmoteQuadContainerIndex, QuadOffset, X: Position.x, Y: Position.y - 23.f - 32.f * h, ScaleX: 1.f, ScaleY: (64.f * h) / 64.f);
866
867 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: 1.0f);
868 Graphics()->QuadsSetRotation(Angle: 0);
869 }
870 }
871}
872
873inline bool CPlayers::IsPlayerInfoAvailable(int ClientId) const
874{
875 return GameClient()->m_Snap.m_aCharacters[ClientId].m_Active &&
876 GameClient()->m_Snap.m_apPrevPlayerInfos[ClientId] != nullptr &&
877 GameClient()->m_Snap.m_apPlayerInfos[ClientId] != nullptr;
878}
879
880void CPlayers::OnRender()
881{
882 if(Client()->State() != IClient::STATE_ONLINE && Client()->State() != IClient::STATE_DEMOPLAYBACK)
883 return;
884
885 // update render info for ninja
886 CTeeRenderInfo aRenderInfo[MAX_CLIENTS];
887 const bool IsTeamPlay = GameClient()->IsTeamPlay();
888 for(int i = 0; i < MAX_CLIENTS; ++i)
889 {
890 aRenderInfo[i] = GameClient()->m_aClients[i].m_RenderInfo;
891 aRenderInfo[i].m_TeeRenderFlags = 0;
892
893 // predict freeze skin only for local players
894 bool Frozen = false;
895 if(i == GameClient()->m_aLocalIds[0] || i == GameClient()->m_aLocalIds[1])
896 {
897 if(GameClient()->m_aClients[i].m_Predicted.m_FreezeEnd != 0)
898 aRenderInfo[i].m_TeeRenderFlags |= TEE_EFFECT_FROZEN | TEE_NO_WEAPON;
899 if(GameClient()->m_aClients[i].m_Predicted.m_LiveFrozen)
900 aRenderInfo[i].m_TeeRenderFlags |= TEE_EFFECT_FROZEN;
901 if(GameClient()->m_aClients[i].m_Predicted.m_Invincible)
902 aRenderInfo[i].m_TeeRenderFlags |= TEE_EFFECT_SPARKLE;
903
904 Frozen = GameClient()->m_aClients[i].m_Predicted.m_FreezeEnd != 0;
905 }
906 else
907 {
908 if(GameClient()->m_aClients[i].m_FreezeEnd != 0)
909 aRenderInfo[i].m_TeeRenderFlags |= TEE_EFFECT_FROZEN | TEE_NO_WEAPON;
910 if(GameClient()->m_aClients[i].m_LiveFrozen)
911 aRenderInfo[i].m_TeeRenderFlags |= TEE_EFFECT_FROZEN;
912 if(GameClient()->m_aClients[i].m_Invincible)
913 aRenderInfo[i].m_TeeRenderFlags |= TEE_EFFECT_SPARKLE;
914
915 Frozen = GameClient()->m_Snap.m_aCharacters[i].m_HasExtendedData && GameClient()->m_Snap.m_aCharacters[i].m_ExtendedData.m_FreezeEnd != 0;
916 }
917
918 if((GameClient()->m_aClients[i].m_RenderCur.m_Weapon == WEAPON_NINJA || (Frozen && !GameClient()->m_GameInfo.m_NoSkinChangeForFrozen)) && g_Config.m_ClShowNinja)
919 {
920 // change the skin for the player to the ninja
921 aRenderInfo[i].m_aSixup[g_Config.m_ClDummy].Reset();
922 aRenderInfo[i].ApplySkin(TeeRenderInfo: NinjaTeeRenderInfo()->TeeRenderInfo());
923 aRenderInfo[i].m_CustomColoredSkin = IsTeamPlay;
924 if(!IsTeamPlay)
925 {
926 aRenderInfo[i].m_ColorBody = ColorRGBA(1, 1, 1);
927 aRenderInfo[i].m_ColorFeet = ColorRGBA(1, 1, 1);
928 }
929 }
930 }
931
932 // get screen edges to avoid rendering offscreen
933 float ScreenX0, ScreenY0, ScreenX1, ScreenY1;
934 Graphics()->GetScreen(pTopLeftX: &ScreenX0, pTopLeftY: &ScreenY0, pBottomRightX: &ScreenX1, pBottomRightY: &ScreenY1);
935 // expand the edges to prevent popping in/out onscreen
936 //
937 // it is assumed that the tee, all its weapons, and emotes fit into a 200x200 box centered on the tee
938 // this may need to be changed or calculated differently in the future
939 float BorderBuffer = 100;
940 ScreenX0 -= BorderBuffer;
941 ScreenX1 += BorderBuffer;
942 ScreenY0 -= BorderBuffer;
943 ScreenY1 += BorderBuffer;
944
945 // render everyone else's hook, then our own
946 const int LocalClientId = GameClient()->m_Snap.m_LocalClientId;
947 for(int ClientId = 0; ClientId < MAX_CLIENTS; ClientId++)
948 {
949 if(ClientId == LocalClientId || !IsPlayerInfoAvailable(ClientId))
950 {
951 continue;
952 }
953 RenderHook(pPrevChar: &GameClient()->m_aClients[ClientId].m_RenderPrev, pPlayerChar: &GameClient()->m_aClients[ClientId].m_RenderCur, pRenderInfo: &aRenderInfo[ClientId], ClientId);
954 }
955 if(LocalClientId != -1 && IsPlayerInfoAvailable(ClientId: LocalClientId))
956 {
957 const CGameClient::CClientData *pLocalClientData = &GameClient()->m_aClients[LocalClientId];
958 RenderHook(pPrevChar: &pLocalClientData->m_RenderPrev, pPlayerChar: &pLocalClientData->m_RenderCur, pRenderInfo: &aRenderInfo[LocalClientId], ClientId: LocalClientId);
959 }
960
961 // render spectating players
962 for(const auto &Client : GameClient()->m_aClients)
963 {
964 if(!Client.m_SpecCharPresent)
965 {
966 continue;
967 }
968
969 const int ClientId = Client.ClientId();
970 float Alpha = (GameClient()->IsOtherTeam(ClientId) || ClientId < 0) ? g_Config.m_ClShowOthersAlpha / 100.f : 1.f;
971 if(ClientId == -2) // ghost
972 {
973 Alpha = g_Config.m_ClRaceGhostAlpha / 100.f;
974 }
975 RenderTools()->RenderTee(pAnim: CAnimState::GetIdle(), pInfo: &SpectatorTeeRenderInfo()->TeeRenderInfo(), Emote: EMOTE_BLINK, Dir: vec2(1, 0), Pos: Client.m_SpecChar, Alpha);
976 }
977
978 // render everyone else's tee, then either our own or the tee we are spectating.
979 const int RenderLastId = (GameClient()->m_Snap.m_SpecInfo.m_SpectatorId != SPEC_FREEVIEW && GameClient()->m_Snap.m_SpecInfo.m_Active) ? GameClient()->m_Snap.m_SpecInfo.m_SpectatorId : LocalClientId;
980
981 for(int ClientId = 0; ClientId < MAX_CLIENTS; ClientId++)
982 {
983 if(ClientId == RenderLastId || !IsPlayerInfoAvailable(ClientId))
984 {
985 continue;
986 }
987
988 RenderHookCollLine(pPrevChar: &GameClient()->m_aClients[ClientId].m_RenderPrev, pPlayerChar: &GameClient()->m_aClients[ClientId].m_RenderCur, ClientId);
989
990 if(!in_range(a: GameClient()->m_aClients[ClientId].m_RenderPos.x, lower: ScreenX0, upper: ScreenX1) || !in_range(a: GameClient()->m_aClients[ClientId].m_RenderPos.y, lower: ScreenY0, upper: ScreenY1))
991 {
992 continue;
993 }
994 RenderPlayer(pPrevChar: &GameClient()->m_aClients[ClientId].m_RenderPrev, pPlayerChar: &GameClient()->m_aClients[ClientId].m_RenderCur, pRenderInfo: &aRenderInfo[ClientId], ClientId);
995 }
996 if(RenderLastId != -1 && IsPlayerInfoAvailable(ClientId: RenderLastId))
997 {
998 const CGameClient::CClientData *pClientData = &GameClient()->m_aClients[RenderLastId];
999 RenderHookCollLine(pPrevChar: &pClientData->m_RenderPrev, pPlayerChar: &pClientData->m_RenderCur, ClientId: RenderLastId);
1000 RenderPlayer(pPrevChar: &pClientData->m_RenderPrev, pPlayerChar: &pClientData->m_RenderCur, pRenderInfo: &aRenderInfo[RenderLastId], ClientId: RenderLastId);
1001 }
1002}
1003
1004void CPlayers::CreateNinjaTeeRenderInfo()
1005{
1006 CTeeRenderInfo NinjaTeeRenderInfo;
1007 NinjaTeeRenderInfo.m_Size = 64.0f;
1008 CSkinDescriptor NinjaSkinDescriptor;
1009 NinjaSkinDescriptor.m_Flags |= CSkinDescriptor::FLAG_SIX;
1010 str_copy(dst&: NinjaSkinDescriptor.m_aSkinName, src: "x_ninja");
1011 m_pNinjaTeeRenderInfo = GameClient()->CreateManagedTeeRenderInfo(TeeRenderInfo: NinjaTeeRenderInfo, SkinDescriptor: NinjaSkinDescriptor);
1012}
1013
1014void CPlayers::CreateSpectatorTeeRenderInfo()
1015{
1016 CTeeRenderInfo SpectatorTeeRenderInfo;
1017 SpectatorTeeRenderInfo.m_Size = 64.0f;
1018 CSkinDescriptor SpectatorSkinDescriptor;
1019 SpectatorSkinDescriptor.m_Flags |= CSkinDescriptor::FLAG_SIX;
1020 str_copy(dst&: SpectatorSkinDescriptor.m_aSkinName, src: "x_spec");
1021 m_pSpectatorTeeRenderInfo = GameClient()->CreateManagedTeeRenderInfo(TeeRenderInfo: SpectatorTeeRenderInfo, SkinDescriptor: SpectatorSkinDescriptor);
1022}
1023
1024void CPlayers::OnInit()
1025{
1026 m_WeaponEmoteQuadContainerIndex = Graphics()->CreateQuadContainer(AutomaticUpload: false);
1027
1028 Graphics()->SetColor(r: 1.f, g: 1.f, b: 1.f, a: 1.f);
1029
1030 for(int i = 0; i < NUM_WEAPONS; ++i)
1031 {
1032 float ScaleX, ScaleY;
1033 Graphics()->GetSpriteScale(pSprite: g_pData->m_Weapons.m_aId[i].m_pSpriteBody, ScaleX, ScaleY);
1034 Graphics()->QuadsSetSubset(TopLeftU: 0, TopLeftV: 0, BottomRightU: 1, BottomRightV: 1);
1035 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_WeaponEmoteQuadContainerIndex, Width: g_pData->m_Weapons.m_aId[i].m_VisualSize * ScaleX, Height: g_pData->m_Weapons.m_aId[i].m_VisualSize * ScaleY);
1036 Graphics()->QuadsSetSubset(TopLeftU: 0, TopLeftV: 1, BottomRightU: 1, BottomRightV: 0);
1037 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_WeaponEmoteQuadContainerIndex, Width: g_pData->m_Weapons.m_aId[i].m_VisualSize * ScaleX, Height: g_pData->m_Weapons.m_aId[i].m_VisualSize * ScaleY);
1038 }
1039 float ScaleX, ScaleY;
1040
1041 // at the end the hand
1042 Graphics()->QuadsSetSubset(TopLeftU: 0, TopLeftV: 0, BottomRightU: 1, BottomRightV: 1);
1043 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_WeaponEmoteQuadContainerIndex, Size: 20.f);
1044 Graphics()->QuadsSetSubset(TopLeftU: 0, TopLeftV: 0, BottomRightU: 1, BottomRightV: 1);
1045 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_WeaponEmoteQuadContainerIndex, Size: 20.f);
1046
1047 Graphics()->QuadsSetSubset(TopLeftU: 0, TopLeftV: 0, BottomRightU: 1, BottomRightV: 1);
1048 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_WeaponEmoteQuadContainerIndex, X: -12.f, Y: -8.f, Width: 24.f, Height: 16.f);
1049 Graphics()->QuadsSetSubset(TopLeftU: 0, TopLeftV: 0, BottomRightU: 1, BottomRightV: 1);
1050 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_WeaponEmoteQuadContainerIndex, X: -12.f, Y: -8.f, Width: 24.f, Height: 16.f);
1051
1052 for(int i = 0; i < NUM_EMOTICONS; ++i)
1053 {
1054 Graphics()->QuadsSetSubset(TopLeftU: 0, TopLeftV: 0, BottomRightU: 1, BottomRightV: 1);
1055 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_WeaponEmoteQuadContainerIndex, Size: 64.f);
1056 }
1057 Graphics()->QuadContainerUpload(ContainerIndex: m_WeaponEmoteQuadContainerIndex);
1058
1059 for(int i = 0; i < NUM_WEAPONS; ++i)
1060 {
1061 m_aWeaponSpriteMuzzleQuadContainerIndex[i] = Graphics()->CreateQuadContainer(AutomaticUpload: false);
1062 for(int n = 0; n < g_pData->m_Weapons.m_aId[i].m_NumSpriteMuzzles; ++n)
1063 {
1064 if(g_pData->m_Weapons.m_aId[i].m_aSpriteMuzzles[n])
1065 {
1066 if(i == WEAPON_GUN || i == WEAPON_SHOTGUN)
1067 {
1068 // TODO: hardcoded for now to get the same particle size as before
1069 Graphics()->GetSpriteScaleImpl(Width: 96, Height: 64, ScaleX, ScaleY);
1070 }
1071 else
1072 Graphics()->GetSpriteScale(pSprite: g_pData->m_Weapons.m_aId[i].m_aSpriteMuzzles[n], ScaleX, ScaleY);
1073 }
1074
1075 float SWidth = (g_pData->m_Weapons.m_aId[i].m_VisualSize * ScaleX) * (4.0f / 3.0f);
1076 float SHeight = g_pData->m_Weapons.m_aId[i].m_VisualSize * ScaleY;
1077
1078 Graphics()->QuadsSetSubset(TopLeftU: 0, TopLeftV: 0, BottomRightU: 1, BottomRightV: 1);
1079 if(WEAPON_NINJA == i)
1080 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_aWeaponSpriteMuzzleQuadContainerIndex[i], Width: 160.f * ScaleX, Height: 160.f * ScaleY);
1081 else
1082 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_aWeaponSpriteMuzzleQuadContainerIndex[i], Width: SWidth, Height: SHeight);
1083
1084 Graphics()->QuadsSetSubset(TopLeftU: 0, TopLeftV: 1, BottomRightU: 1, BottomRightV: 0);
1085 if(WEAPON_NINJA == i)
1086 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_aWeaponSpriteMuzzleQuadContainerIndex[i], Width: 160.f * ScaleX, Height: 160.f * ScaleY);
1087 else
1088 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_aWeaponSpriteMuzzleQuadContainerIndex[i], Width: SWidth, Height: SHeight);
1089 }
1090 Graphics()->QuadContainerUpload(ContainerIndex: m_aWeaponSpriteMuzzleQuadContainerIndex[i]);
1091 }
1092
1093 Graphics()->QuadsSetSubset(TopLeftU: 0.f, TopLeftV: 0.f, BottomRightU: 1.f, BottomRightV: 1.f);
1094 Graphics()->QuadsSetRotation(Angle: 0.f);
1095
1096 CreateNinjaTeeRenderInfo();
1097 CreateSpectatorTeeRenderInfo();
1098}
1099