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
221 // When the other player isn't predicted, we don't know their tunes.
222 // Use our own tunes instead. This is wrong, but a good heuristic.
223 const CCharacterCore &PlayerCore = GameClient()->m_aClients[ClientId].m_IsPredicted ? GameClient()->m_aClients[ClientId].m_Predicted : GameClient()->m_aClients[GameClient()->m_aLocalIds[g_Config.m_ClDummy]].m_Predicted;
224 float HookLength = PlayerCore.m_Tuning.m_HookLength;
225 float HookFireSpeed = PlayerCore.m_Tuning.m_HookFireSpeed;
226
227 // janky physics
228 if(HookLength < HOOK_START_DISTANCE || HookFireSpeed <= 0.0f)
229 return;
230
231 vec2 QuantizedDirection = Direction;
232 vec2 StartOffset = Direction * HOOK_START_DISTANCE;
233 vec2 BasePos = Position;
234 vec2 LineStartPos = BasePos + StartOffset;
235 vec2 SegmentStartPos = LineStartPos;
236
237 ColorRGBA HookCollColor = color_cast<ColorRGBA>(hsl: ColorHSLA(g_Config.m_ClHookCollColorNoColl));
238 std::vector<IGraphics::CLineItem> vLineSegments;
239
240 const int MaxHookTicks = 5 * Client()->GameTickSpeed(); // calculating above 5 seconds is very expensive and unlikely to happen
241
242 auto AddHookPlayerSegment = [&](const vec2 &StartPos, const vec2 &EndPos, const vec2 &HookablePlayerPosition, const vec2 &HitPos) {
243 HookCollColor = color_cast<ColorRGBA>(hsl: ColorHSLA(g_Config.m_ClHookCollColorTeeColl));
244
245 // stop hookline at player circle so it looks better
246 vec2 aIntersections[2];
247 int NumIntersections = intersect_line_circle(LineStart: StartPos, LineEnd: EndPos, CircleCenter: HookablePlayerPosition, Radius: CCharacterCore::PhysicalSize() * 1.45f / 2.0f, aIntersections);
248 if(NumIntersections == 2)
249 {
250 if(distance(a: Position, b: aIntersections[0]) < distance(a: Position, b: aIntersections[1]))
251 vLineSegments.emplace_back(args: StartPos, args&: aIntersections[0]);
252 else
253 vLineSegments.emplace_back(args: StartPos, args&: aIntersections[1]);
254 }
255 else if(NumIntersections == 1)
256 vLineSegments.emplace_back(args: StartPos, args&: aIntersections[0]);
257 else
258 vLineSegments.emplace_back(args: StartPos, args: HitPos);
259 };
260
261 // simulate the hook into the future
262 int HookTick;
263 bool HookEnteredTelehook = false;
264 std::optional<IGraphics::CLineItem> HookTipLineSegment;
265 for(HookTick = 0; HookTick < MaxHookTicks; ++HookTick)
266 {
267 int Tele;
268 vec2 HitPos, IntersectedPlayerPosition;
269 vec2 SegmentEndPos = SegmentStartPos + QuantizedDirection * HookFireSpeed;
270
271 // check if a hook would enter retracting state in this tick
272 if(distance(a: BasePos, b: SegmentEndPos) > HookLength)
273 {
274 // check if the retracting hook hits a player
275 if(!HookEnteredTelehook)
276 {
277 vec2 RetractingHookEndPos = BasePos + normalize(v: SegmentEndPos - BasePos) * HookLength;
278 // you can't hook a player, if the hook is behind solids, however you miss the solids as well
279 int Hit = Collision()->IntersectLineTeleHook(Pos0: SegmentStartPos, Pos1: RetractingHookEndPos, pOutCollision: &HitPos, pOutBeforeCollision: nullptr, pTeleNr: &Tele);
280
281 if(GameClient()->IntersectCharacter(HookPos: SegmentStartPos, NewPos: HitPos, NewPos2&: RetractingHookEndPos, OwnId: ClientId, pPlayerPosition: &IntersectedPlayerPosition) != -1)
282 {
283 AddHookPlayerSegment(LineStartPos, SegmentEndPos, IntersectedPlayerPosition, RetractingHookEndPos);
284 break;
285 }
286
287 // Retracting hooks don't go through hook teleporters
288 if(Hit && Hit != TILE_TELEINHOOK)
289 {
290 // The hook misses the player, but also misses the solid
291 vLineSegments.emplace_back(args&: LineStartPos, args&: SegmentStartPos);
292
293 // The player hook misses due to a solid
294 HookTipLineSegment = IGraphics::CLineItem(SegmentStartPos, HitPos);
295 break;
296 }
297
298 // we are missing the player, the solid hookline stopped already, but we want this extra line segment
299 // the player-hooking-hook is only longer, if we didn't go through a tele hook
300 HookTipLineSegment = IGraphics::CLineItem(SegmentStartPos, RetractingHookEndPos);
301 }
302
303 // the line is too long here, and the hook retracts, use old position
304 vLineSegments.emplace_back(args&: LineStartPos, args&: SegmentStartPos);
305 break;
306 }
307
308 // check for map collisions
309 int Hit = Collision()->IntersectLineTeleHook(Pos0: SegmentStartPos, Pos1: SegmentEndPos, pOutCollision: &HitPos, pOutBeforeCollision: nullptr, pTeleNr: &Tele);
310
311 // check if we intersect a player
312 if(GameClient()->IntersectCharacter(HookPos: SegmentStartPos, NewPos: HitPos, NewPos2&: SegmentEndPos, OwnId: ClientId, pPlayerPosition: &IntersectedPlayerPosition) != -1)
313 {
314 AddHookPlayerSegment(LineStartPos, HitPos, IntersectedPlayerPosition, SegmentEndPos);
315 break;
316 }
317
318 // we hit nothing, continue calculating segments
319 if(!Hit)
320 {
321 SegmentStartPos = SegmentEndPos;
322 SegmentStartPos.x = round_to_int(f: SegmentStartPos.x);
323 SegmentStartPos.y = round_to_int(f: SegmentStartPos.y);
324
325 // direction is always the same after the first tick quantization
326 if(HookTick == 0)
327 {
328 QuantizedDirection.x = round_to_int(f: QuantizedDirection.x * 256.0f) / 256.0f;
329 QuantizedDirection.y = round_to_int(f: QuantizedDirection.y * 256.0f) / 256.0f;
330 }
331 continue;
332 }
333
334 // we hit a solid / hook stopper
335 if(Hit != TILE_TELEINHOOK)
336 {
337 if(Hit != TILE_NOHOOK)
338 HookCollColor = color_cast<ColorRGBA>(hsl: ColorHSLA(g_Config.m_ClHookCollColorHookableColl));
339 vLineSegments.emplace_back(args&: LineStartPos, args&: HitPos);
340 break;
341 }
342
343 // we are hitting TILE_TELEINHOOK
344 vLineSegments.emplace_back(args&: LineStartPos, args&: HitPos);
345 HookEnteredTelehook = true;
346
347 // check tele outs
348 const std::vector<vec2> &vTeleOuts = Collision()->TeleOuts(Number: Tele - 1);
349 if(vTeleOuts.empty())
350 {
351 // the hook gets stuck, this is a feature or a bug
352 HookCollColor = color_cast<ColorRGBA>(hsl: ColorHSLA(g_Config.m_ClHookCollColorHookableColl));
353 break;
354 }
355 else if(vTeleOuts.size() > 1)
356 {
357 // we don't know which teleout the hook takes, just invert the color
358 HookCollColor = color_invert(col: color_cast<ColorRGBA>(hsl: ColorHSLA(g_Config.m_ClHookCollColorTeeColl)));
359 break;
360 }
361
362 // go through one teleout, update positions and continue
363 BasePos = vTeleOuts[0];
364 LineStartPos = BasePos; // make the line start in the teleporter to prevent a gap
365 SegmentStartPos = BasePos + Direction * HOOK_START_DISTANCE;
366 SegmentStartPos.x = round_to_int(f: SegmentStartPos.x);
367 SegmentStartPos.y = round_to_int(f: SegmentStartPos.y);
368
369 // direction is always the same after the first tick quantization
370 if(HookTick == 0)
371 {
372 QuantizedDirection.x = round_to_int(f: QuantizedDirection.x * 256.0f) / 256.0f;
373 QuantizedDirection.y = round_to_int(f: QuantizedDirection.y * 256.0f) / 256.0f;
374 }
375 }
376
377 // The hook line is too expensive to calculate and didn't hit anything before, just set a straight line
378 if(HookTick >= MaxHookTicks && vLineSegments.empty())
379 {
380 // we simply don't know if we hit anything or not
381 HookCollColor = color_invert(col: color_cast<ColorRGBA>(hsl: ColorHSLA(g_Config.m_ClHookCollColorTeeColl)));
382 vLineSegments.emplace_back(args&: LineStartPos, args: BasePos + QuantizedDirection * HookLength);
383 }
384
385 // add a line from the player to the start position to prevent a visual gap
386 vLineSegments.emplace_back(args&: Position, args: Position + StartOffset);
387
388 if(AlwaysRenderHookColl && RenderHookCollPlayer)
389 {
390 // invert the hook coll colors when using cl_show_hook_coll_always and +showhookcoll is pressed
391 HookCollColor = color_invert(col: HookCollColor);
392 }
393
394 // Render hook coll line
395 const int HookCollSize = Local ? g_Config.m_ClHookCollSize : g_Config.m_ClHookCollSizeOther;
396
397 float Alpha = GameClient()->IsOtherTeam(ClientId) ? g_Config.m_ClShowOthersAlpha / 100.0f : 1.0f;
398 Alpha *= (float)g_Config.m_ClHookCollAlpha / 100;
399 if(Alpha <= 0.0f)
400 return;
401 ColorRGBA HookCollTipColor = color_cast<ColorRGBA>(hsl: ColorHSLA(g_Config.m_ClHookCollTipColor, true));
402
403 Graphics()->TextureClear();
404 if(HookCollSize > 0)
405 {
406 std::vector<IGraphics::CFreeformItem> vLineQuadSegments;
407 vLineQuadSegments.reserve(n: vLineSegments.size());
408
409 float LineWidth = 0.5f + (float)(HookCollSize - 1) * 0.25f;
410 const vec2 PerpToAngle = normalize(v: vec2(Direction.y, -Direction.x)) * GameClient()->m_Camera.m_Zoom;
411
412 auto ConvertLineSegments = [&](const IGraphics::CLineItem &LineSegment) {
413 vec2 DrawInitPos(LineSegment.m_X0, LineSegment.m_Y0);
414 vec2 DrawFinishPos(LineSegment.m_X1, LineSegment.m_Y1);
415 vec2 Pos0 = DrawFinishPos + PerpToAngle * -LineWidth;
416 vec2 Pos1 = DrawFinishPos + PerpToAngle * LineWidth;
417 vec2 Pos2 = DrawInitPos + PerpToAngle * -LineWidth;
418 vec2 Pos3 = DrawInitPos + PerpToAngle * LineWidth;
419 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);
420 };
421
422 for(const auto &LineSegment : vLineSegments)
423 {
424 ConvertLineSegments(LineSegment);
425 }
426
427 vLineSegments.clear();
428
429 Graphics()->QuadsBegin();
430 Graphics()->SetColor(HookCollColor.WithAlpha(alpha: Alpha));
431 Graphics()->QuadsDrawFreeform(pArray: vLineQuadSegments.data(), Num: vLineQuadSegments.size());
432 if(HookTipLineSegment.has_value() && HookCollTipColor.a > 0.0f)
433 {
434 vLineQuadSegments.clear();
435 ConvertLineSegments(HookTipLineSegment.value());
436 Graphics()->SetColor(HookCollTipColor.WithMultipliedAlpha(alpha: Alpha));
437 Graphics()->QuadsDrawFreeform(pArray: vLineQuadSegments.data(), Num: vLineQuadSegments.size());
438 }
439 Graphics()->QuadsEnd();
440 }
441 else
442 {
443 Graphics()->LinesBegin();
444 Graphics()->SetColor(HookCollColor.WithAlpha(alpha: Alpha));
445 Graphics()->LinesDraw(pArray: vLineSegments.data(), Num: vLineSegments.size());
446 if(HookTipLineSegment.has_value() && HookCollTipColor.a > 0.0f)
447 {
448 Graphics()->SetColor(HookCollTipColor.WithMultipliedAlpha(alpha: Alpha));
449 Graphics()->LinesDraw(pArray: &HookTipLineSegment.value(), Num: 1);
450 }
451 Graphics()->LinesEnd();
452 }
453}
454
455void CPlayers::RenderHook(
456 const CNetObj_Character *pPrevChar,
457 const CNetObj_Character *pPlayerChar,
458 const CTeeRenderInfo *pRenderInfo,
459 int ClientId,
460 float Intra)
461{
462 if(pPlayerChar->m_HookState <= 0)
463 return;
464
465 CNetObj_Character Prev;
466 CNetObj_Character Player;
467 Prev = *pPrevChar;
468 Player = *pPlayerChar;
469
470 CTeeRenderInfo RenderInfo = *pRenderInfo;
471
472 // don't render hooks to not active character cores
473 if(pPlayerChar->m_HookedPlayer != -1 && !GameClient()->m_Snap.m_aCharacters[pPlayerChar->m_HookedPlayer].m_Active)
474 return;
475
476 if(ClientId >= 0)
477 Intra = GameClient()->m_aClients[ClientId].m_IsPredicted ? Client()->PredIntraGameTick(Conn: g_Config.m_ClDummy) : Client()->IntraGameTick(Conn: g_Config.m_ClDummy);
478
479 bool OtherTeam = GameClient()->IsOtherTeam(ClientId);
480 float Alpha = (OtherTeam || ClientId < 0) ? g_Config.m_ClShowOthersAlpha / 100.0f : 1.0f;
481 if(ClientId == -2) // ghost
482 Alpha = g_Config.m_ClRaceGhostAlpha / 100.0f;
483
484 RenderInfo.m_Size = 64.0f;
485
486 vec2 Position;
487 if(in_range(a: ClientId, upper: MAX_CLIENTS - 1))
488 Position = GameClient()->m_aClients[ClientId].m_RenderPos;
489 else
490 Position = mix(a: vec2(Prev.m_X, Prev.m_Y), b: vec2(Player.m_X, Player.m_Y), amount: Intra);
491
492 // draw hook
493 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: 1.0f);
494 if(ClientId < 0)
495 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: 0.5f);
496
497 vec2 Pos = Position;
498 vec2 HookPos;
499
500 if(in_range(a: pPlayerChar->m_HookedPlayer, upper: MAX_CLIENTS - 1))
501 HookPos = GameClient()->m_aClients[pPlayerChar->m_HookedPlayer].m_RenderPos;
502 else
503 HookPos = mix(a: vec2(Prev.m_HookX, Prev.m_HookY), b: vec2(Player.m_HookX, Player.m_HookY), amount: Intra);
504
505 float d = distance(a: Pos, b: HookPos);
506 vec2 Dir = normalize(v: Pos - HookPos);
507
508 Graphics()->TextureSet(Texture: GameClient()->m_GameSkin.m_SpriteHookHead);
509 Graphics()->QuadsSetRotation(Angle: angle(a: Dir) + pi);
510 // render head
511 int QuadOffset = NUM_WEAPONS * 2 + 2;
512 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: Alpha);
513 Graphics()->RenderQuadContainerAsSprite(ContainerIndex: m_WeaponEmoteQuadContainerIndex, QuadOffset, X: HookPos.x, Y: HookPos.y);
514
515 // render chain
516 ++QuadOffset;
517 static IGraphics::SRenderSpriteInfo s_aHookChainRenderInfo[1024];
518 int HookChainCount = 0;
519 for(float f = 24; f < d && HookChainCount < 1024; f += 24, ++HookChainCount)
520 {
521 vec2 p = HookPos + Dir * f;
522 s_aHookChainRenderInfo[HookChainCount].m_Pos[0] = p.x;
523 s_aHookChainRenderInfo[HookChainCount].m_Pos[1] = p.y;
524 s_aHookChainRenderInfo[HookChainCount].m_Scale = 1;
525 s_aHookChainRenderInfo[HookChainCount].m_Rotation = angle(a: Dir) + pi;
526 }
527 Graphics()->TextureSet(Texture: GameClient()->m_GameSkin.m_SpriteHookChain);
528 Graphics()->RenderQuadContainerAsSpriteMultiple(ContainerIndex: m_WeaponEmoteQuadContainerIndex, QuadOffset, DrawCount: HookChainCount, pRenderInfo: s_aHookChainRenderInfo);
529
530 Graphics()->QuadsSetRotation(Angle: 0);
531 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: 1.0f);
532
533 RenderHand(pInfo: &RenderInfo, CenterPos: Position, Dir: normalize(v: HookPos - Pos), AngleOffset: -pi / 2, PostRotOffset: vec2(20, 0), Alpha);
534}
535
536void CPlayers::RenderPlayer(
537 const CNetObj_Character *pPrevChar,
538 const CNetObj_Character *pPlayerChar,
539 const CTeeRenderInfo *pRenderInfo,
540 int ClientId,
541 float Intra)
542{
543 CNetObj_Character Prev;
544 CNetObj_Character Player;
545 Prev = *pPrevChar;
546 Player = *pPlayerChar;
547
548 CTeeRenderInfo RenderInfo = *pRenderInfo;
549
550 const bool Paused = GameClient()->IsWorldPaused() || GameClient()->IsDemoPlaybackPaused();
551 bool Local = GameClient()->m_Snap.m_LocalClientId == ClientId;
552 bool OtherTeam = GameClient()->IsOtherTeam(ClientId);
553 float Alpha = (OtherTeam || ClientId < 0) ? g_Config.m_ClShowOthersAlpha / 100.0f : 1.0f;
554 if(ClientId == -2) // ghost
555 Alpha = g_Config.m_ClRaceGhostAlpha / 100.0f;
556 // TODO: snd_game_volume_others
557 const float Volume = 1.0f;
558
559 // set size
560 RenderInfo.m_Size = 64.0f;
561
562 if(ClientId >= 0)
563 Intra = GameClient()->m_aClients[ClientId].m_IsPredicted ? Client()->PredIntraGameTick(Conn: g_Config.m_ClDummy) : Client()->IntraGameTick(Conn: g_Config.m_ClDummy);
564
565 static float s_LastGameTickTime = Client()->GameTickTime(Conn: g_Config.m_ClDummy);
566 static float s_LastPredIntraTick = Client()->PredIntraGameTick(Conn: g_Config.m_ClDummy);
567 if(!Paused)
568 {
569 s_LastGameTickTime = Client()->GameTickTime(Conn: g_Config.m_ClDummy);
570 s_LastPredIntraTick = Client()->PredIntraGameTick(Conn: g_Config.m_ClDummy);
571 }
572
573 bool PredictLocalWeapons = false;
574 float AttackTime = (Client()->PrevGameTick(Conn: g_Config.m_ClDummy) - Player.m_AttackTick) / (float)Client()->GameTickSpeed() + Client()->GameTickTime(Conn: g_Config.m_ClDummy);
575 float LastAttackTime = (Client()->PrevGameTick(Conn: g_Config.m_ClDummy) - Player.m_AttackTick) / (float)Client()->GameTickSpeed() + s_LastGameTickTime;
576 if(ClientId >= 0 && GameClient()->m_aClients[ClientId].m_IsPredictedLocal && GameClient()->AntiPingGunfire())
577 {
578 PredictLocalWeapons = true;
579 AttackTime = (Client()->PredIntraGameTick(Conn: g_Config.m_ClDummy) + (Client()->PredGameTick(Conn: g_Config.m_ClDummy) - 1 - Player.m_AttackTick)) / (float)Client()->GameTickSpeed();
580 LastAttackTime = (s_LastPredIntraTick + (Client()->PredGameTick(Conn: g_Config.m_ClDummy) - 1 - Player.m_AttackTick)) / (float)Client()->GameTickSpeed();
581 }
582 float AttackTicksPassed = AttackTime * (float)Client()->GameTickSpeed();
583
584 float Angle = GetPlayerTargetAngle(pPrevChar: &Prev, pPlayerChar: &Player, ClientId, Intra);
585
586 vec2 Direction = direction(angle: Angle);
587 vec2 Position;
588 if(in_range(a: ClientId, upper: MAX_CLIENTS - 1))
589 Position = GameClient()->m_aClients[ClientId].m_RenderPos;
590 else
591 Position = mix(a: vec2(Prev.m_X, Prev.m_Y), b: vec2(Player.m_X, Player.m_Y), amount: Intra);
592 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);
593
594 GameClient()->m_Flow.Add(Pos: Position, Vel: Vel * 100.0f, Size: 10.0f);
595
596 RenderInfo.m_GotAirJump = Player.m_Jumped & 2 ? false : true;
597
598 RenderInfo.m_FeetFlipped = false;
599
600 bool Stationary = Player.m_VelX <= 1 && Player.m_VelX >= -1;
601 bool InAir = !Collision()->CheckPoint(x: Player.m_X, y: Player.m_Y + 16);
602 bool Running = Player.m_VelX >= 5000 || Player.m_VelX <= -5000;
603 bool WantOtherDir = (Player.m_Direction == -1 && Vel.x > 0) || (Player.m_Direction == 1 && Vel.x < 0);
604 bool Inactive = ClientId >= 0 && (GameClient()->m_aClients[ClientId].m_Afk || GameClient()->m_aClients[ClientId].m_Paused);
605
606 // evaluate animation
607 float WalkTime = std::fmod(x: Position.x, y: 100.0f) / 100.0f;
608 float RunTime = std::fmod(x: Position.x, y: 200.0f) / 200.0f;
609
610 // Don't do a moon walk outside the left border
611 if(WalkTime < 0.0f)
612 WalkTime += 1.0f;
613 if(RunTime < 0.0f)
614 RunTime += 1.0f;
615
616 CAnimState State;
617 State.Set(pAnim: &g_pData->m_aAnimations[ANIM_BASE], Time: 0.0f);
618
619 if(InAir)
620 State.Add(pAnim: &g_pData->m_aAnimations[ANIM_INAIR], Time: 0.0f, Amount: 1.0f); // TODO: some sort of time here
621 else if(Stationary)
622 {
623 if(Inactive)
624 {
625 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
626 RenderInfo.m_FeetFlipped = true;
627 }
628 else
629 State.Add(pAnim: &g_pData->m_aAnimations[ANIM_IDLE], Time: 0.0f, Amount: 1.0f); // TODO: some sort of time here
630 }
631 else if(!WantOtherDir)
632 {
633 if(Running)
634 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);
635 else
636 State.Add(pAnim: &g_pData->m_aAnimations[ANIM_WALK], Time: WalkTime, Amount: 1.0f);
637 }
638
639 const float HammerAnimationTimeScale = 5.0f;
640 if(Player.m_Weapon == WEAPON_HAMMER)
641 State.Add(pAnim: &g_pData->m_aAnimations[ANIM_HAMMER_SWING], Time: std::clamp(val: LastAttackTime * HammerAnimationTimeScale, lo: 0.0f, hi: 1.0f), Amount: 1.0f);
642 if(Player.m_Weapon == WEAPON_NINJA)
643 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);
644
645 // do skidding
646 if(!InAir && WantOtherDir && length(a: Vel * 50) > 500.0f)
647 GameClient()->m_Effects.SkidTrail(Pos: Position, Vel, Direction: Player.m_Direction, Alpha, Volume);
648
649 // draw gun
650 if(Player.m_Weapon >= 0)
651 {
652 if(!(RenderInfo.m_TeeRenderFlags & TEE_NO_WEAPON))
653 {
654 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: Alpha);
655
656 // normal weapons
657 int CurrentWeapon = std::clamp(val: Player.m_Weapon, lo: 0, hi: NUM_WEAPONS - 1);
658 Graphics()->TextureSet(Texture: GameClient()->m_GameSkin.m_aSpriteWeapons[CurrentWeapon]);
659 int QuadOffset = CurrentWeapon * 2 + (Direction.x < 0.0f ? 1 : 0);
660
661 float Recoil = 0.0f;
662 vec2 WeaponPosition;
663 bool IsSit = Inactive && !InAir && Stationary;
664
665 if(Player.m_Weapon == WEAPON_HAMMER)
666 {
667 // static position for hammer
668 WeaponPosition = Position + vec2(State.GetAttach()->m_X, State.GetAttach()->m_Y);
669 WeaponPosition.y += g_pData->m_Weapons.m_aId[CurrentWeapon].m_Offsety;
670 if(Direction.x < 0.0f)
671 WeaponPosition.x -= g_pData->m_Weapons.m_aId[CurrentWeapon].m_Offsetx;
672 if(IsSit)
673 WeaponPosition.y += 3.0f;
674
675 // if active and attack is under way, bash stuffs
676 if(!Inactive || LastAttackTime * HammerAnimationTimeScale < 1.0f)
677 {
678 if(Direction.x < 0)
679 Graphics()->QuadsSetRotation(Angle: -pi / 2.0f - State.GetAttach()->m_Angle * pi * 2.0f);
680 else
681 Graphics()->QuadsSetRotation(Angle: -pi / 2.0f + State.GetAttach()->m_Angle * pi * 2.0f);
682 }
683 else
684 Graphics()->QuadsSetRotation(Angle: Direction.x < 0.0f ? 100.0f : 500.0f);
685
686 Graphics()->RenderQuadContainerAsSprite(ContainerIndex: m_WeaponEmoteQuadContainerIndex, QuadOffset, X: WeaponPosition.x, Y: WeaponPosition.y);
687 }
688 else if(Player.m_Weapon == WEAPON_NINJA)
689 {
690 WeaponPosition = Position;
691 WeaponPosition.y += g_pData->m_Weapons.m_aId[CurrentWeapon].m_Offsety;
692 if(IsSit)
693 WeaponPosition.y += 3.0f;
694
695 if(Direction.x < 0.0f)
696 {
697 Graphics()->QuadsSetRotation(Angle: -pi / 2 - State.GetAttach()->m_Angle * pi * 2.0f);
698 WeaponPosition.x -= g_pData->m_Weapons.m_aId[CurrentWeapon].m_Offsetx;
699 GameClient()->m_Effects.PowerupShine(Pos: WeaponPosition + vec2(32.0f, 0.0f), Size: vec2(32.0f, 12.0f), Alpha);
700 }
701 else
702 {
703 Graphics()->QuadsSetRotation(Angle: -pi / 2 + State.GetAttach()->m_Angle * pi * 2.0f);
704 GameClient()->m_Effects.PowerupShine(Pos: WeaponPosition - vec2(32.0f, 0.0f), Size: vec2(32.0f, 12.0f), Alpha);
705 }
706 Graphics()->RenderQuadContainerAsSprite(ContainerIndex: m_WeaponEmoteQuadContainerIndex, QuadOffset, X: WeaponPosition.x, Y: WeaponPosition.y);
707
708 // HADOKEN
709 if(AttackTime <= 1.0f / 6.0f && g_pData->m_Weapons.m_aId[CurrentWeapon].m_NumSpriteMuzzles)
710 {
711 int IteX = rand() % g_pData->m_Weapons.m_aId[CurrentWeapon].m_NumSpriteMuzzles;
712 static int s_LastIteX = IteX;
713 if(Paused)
714 {
715 IteX = s_LastIteX;
716 }
717 else
718 {
719 s_LastIteX = IteX;
720 }
721 if(g_pData->m_Weapons.m_aId[CurrentWeapon].m_aSpriteMuzzles[IteX])
722 {
723 vec2 HadokenDirection;
724 if(PredictLocalWeapons || ClientId < 0)
725 HadokenDirection = vec2(pPlayerChar->m_X, pPlayerChar->m_Y) - vec2(pPrevChar->m_X, pPrevChar->m_Y);
726 else
727 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);
728 float HadokenAngle = 0.0f;
729 if(absolute(a: HadokenDirection.x) > 0.0001f || absolute(a: HadokenDirection.y) > 0.0001f)
730 {
731 HadokenDirection = normalize(v: HadokenDirection);
732 HadokenAngle = angle(a: HadokenDirection);
733 }
734 else
735 {
736 HadokenDirection = vec2(1.0f, 0.0f);
737 }
738 Graphics()->QuadsSetRotation(Angle: HadokenAngle);
739 QuadOffset = IteX * 2;
740 WeaponPosition = Position;
741 float OffsetX = g_pData->m_Weapons.m_aId[CurrentWeapon].m_Muzzleoffsetx;
742 WeaponPosition -= HadokenDirection * OffsetX;
743 Graphics()->TextureSet(Texture: GameClient()->m_GameSkin.m_aaSpriteWeaponsMuzzles[CurrentWeapon][IteX]);
744 Graphics()->RenderQuadContainerAsSprite(ContainerIndex: m_aWeaponSpriteMuzzleQuadContainerIndex[CurrentWeapon], QuadOffset, X: WeaponPosition.x, Y: WeaponPosition.y);
745 }
746 }
747 }
748 else
749 {
750 // TODO: should be an animation
751 Recoil = 0.0f;
752 float a = AttackTicksPassed / 5.0f;
753 if(a < 1.0f)
754 Recoil = std::sin(x: a * pi);
755 WeaponPosition = Position + Direction * g_pData->m_Weapons.m_aId[CurrentWeapon].m_Offsetx - Direction * Recoil * 10.0f;
756 WeaponPosition.y += g_pData->m_Weapons.m_aId[CurrentWeapon].m_Offsety;
757 if(IsSit)
758 WeaponPosition.y += 3.0f;
759 if(Player.m_Weapon == WEAPON_GUN && g_Config.m_ClOldGunPosition)
760 WeaponPosition.y -= 8.0f;
761 Graphics()->QuadsSetRotation(Angle: State.GetAttach()->m_Angle * pi * 2.0f + Angle);
762 Graphics()->RenderQuadContainerAsSprite(ContainerIndex: m_WeaponEmoteQuadContainerIndex, QuadOffset, X: WeaponPosition.x, Y: WeaponPosition.y);
763 }
764
765 if(Player.m_Weapon == WEAPON_GUN || Player.m_Weapon == WEAPON_SHOTGUN)
766 {
767 // check if we're firing stuff
768 if(g_pData->m_Weapons.m_aId[CurrentWeapon].m_NumSpriteMuzzles) // prev.attackticks)
769 {
770 float AlphaMuzzle = 0.0f;
771 if(AttackTicksPassed < g_pData->m_Weapons.m_aId[CurrentWeapon].m_Muzzleduration + 3.0f)
772 {
773 float t = AttackTicksPassed / g_pData->m_Weapons.m_aId[CurrentWeapon].m_Muzzleduration;
774 AlphaMuzzle = mix(a: 2.0f, b: 0.0f, amount: minimum(a: 1.0f, b: maximum(a: 0.0f, b: t)));
775 }
776
777 int IteX = rand() % g_pData->m_Weapons.m_aId[CurrentWeapon].m_NumSpriteMuzzles;
778 static int s_LastIteX = IteX;
779 if(Paused)
780 {
781 IteX = s_LastIteX;
782 }
783 else
784 {
785 s_LastIteX = IteX;
786 }
787 if(AlphaMuzzle > 0.0f && g_pData->m_Weapons.m_aId[CurrentWeapon].m_aSpriteMuzzles[IteX])
788 {
789 float OffsetY = -g_pData->m_Weapons.m_aId[CurrentWeapon].m_Muzzleoffsety;
790 QuadOffset = IteX * 2 + (Direction.x < 0.0f ? 1 : 0);
791 if(Direction.x < 0.0f)
792 OffsetY = -OffsetY;
793
794 vec2 DirectionY(-Direction.y, Direction.x);
795 vec2 MuzzlePos = WeaponPosition + Direction * g_pData->m_Weapons.m_aId[CurrentWeapon].m_Muzzleoffsetx + DirectionY * OffsetY;
796 Graphics()->TextureSet(Texture: GameClient()->m_GameSkin.m_aaSpriteWeaponsMuzzles[CurrentWeapon][IteX]);
797 Graphics()->RenderQuadContainerAsSprite(ContainerIndex: m_aWeaponSpriteMuzzleQuadContainerIndex[CurrentWeapon], QuadOffset, X: MuzzlePos.x, Y: MuzzlePos.y);
798 }
799 }
800 }
801 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: 1.0f);
802 Graphics()->QuadsSetRotation(Angle: 0.0f);
803
804 switch(Player.m_Weapon)
805 {
806 case WEAPON_GUN: RenderHand(pInfo: &RenderInfo, CenterPos: WeaponPosition, Dir: Direction, AngleOffset: -3.0f * pi / 4.0f, PostRotOffset: vec2(-15.0f, 4.0f), Alpha); break;
807 case WEAPON_SHOTGUN: RenderHand(pInfo: &RenderInfo, CenterPos: WeaponPosition, Dir: Direction, AngleOffset: -pi / 2.0f, PostRotOffset: vec2(-5.0f, 4.0f), Alpha); break;
808 case WEAPON_GRENADE: RenderHand(pInfo: &RenderInfo, CenterPos: WeaponPosition, Dir: Direction, AngleOffset: -pi / 2.0f, PostRotOffset: vec2(-4.0f, 7.0f), Alpha); break;
809 }
810 }
811 }
812
813 // render the "shadow" tee
814 if(g_Config.m_ClUnpredictedShadow == 3 || (Local && g_Config.m_ClUnpredictedShadow == 1) || (!Local && g_Config.m_ClUnpredictedShadow == 2))
815 {
816 vec2 ShadowPosition = Position;
817 if(ClientId >= 0)
818 ShadowPosition = mix(
819 a: vec2(GameClient()->m_Snap.m_aCharacters[ClientId].m_Prev.m_X, GameClient()->m_Snap.m_aCharacters[ClientId].m_Prev.m_Y),
820 b: vec2(GameClient()->m_Snap.m_aCharacters[ClientId].m_Cur.m_X, GameClient()->m_Snap.m_aCharacters[ClientId].m_Cur.m_Y),
821 amount: Client()->IntraGameTick(Conn: g_Config.m_ClDummy));
822
823 RenderTools()->RenderTee(pAnim: &State, pInfo: &RenderInfo, Emote: Player.m_Emote, Dir: Direction, Pos: ShadowPosition, Alpha: g_Config.m_ClUnpredictedShadowAlpha / 100.f); // render ghost
824 }
825
826 RenderTools()->RenderTee(pAnim: &State, pInfo: &RenderInfo, Emote: Player.m_Emote, Dir: Direction, Pos: Position, Alpha);
827
828 float TeeAnimScale, TeeBaseSize;
829 CRenderTools::GetRenderTeeAnimScaleAndBaseSize(pInfo: &RenderInfo, AnimScale&: TeeAnimScale, BaseSize&: TeeBaseSize);
830 vec2 BodyPos = Position + vec2(State.GetBody()->m_X, State.GetBody()->m_Y) * TeeAnimScale;
831 if(RenderInfo.m_TeeRenderFlags & TEE_EFFECT_FROZEN)
832 {
833 GameClient()->m_Effects.FreezingFlakes(Pos: BodyPos, Size: vec2(32, 32), Alpha);
834 }
835 if(RenderInfo.m_TeeRenderFlags & TEE_EFFECT_SPARKLE)
836 {
837 GameClient()->m_Effects.SparkleTrail(Pos: BodyPos, Alpha);
838 }
839
840 if(ClientId < 0)
841 return;
842
843 int QuadOffsetToEmoticon = NUM_WEAPONS * 2 + 2 + 2;
844 if((Player.m_PlayerFlags & PLAYERFLAG_CHATTING) && !GameClient()->m_aClients[ClientId].m_Afk)
845 {
846 int CurEmoticon = (SPRITE_DOTDOT - SPRITE_OOP);
847 Graphics()->TextureSet(Texture: GameClient()->m_EmoticonsSkin.m_aSpriteEmoticons[CurEmoticon]);
848 int QuadOffset = QuadOffsetToEmoticon + CurEmoticon;
849 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: Alpha);
850 Graphics()->RenderQuadContainerAsSprite(ContainerIndex: m_WeaponEmoteQuadContainerIndex, QuadOffset, X: Position.x + 24.f, Y: Position.y - 40.f);
851
852 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: 1.0f);
853 Graphics()->QuadsSetRotation(Angle: 0);
854 }
855
856 if(g_Config.m_ClAfkEmote && GameClient()->m_aClients[ClientId].m_Afk && ClientId != GameClient()->m_aLocalIds[!g_Config.m_ClDummy])
857 {
858 int CurEmoticon = (SPRITE_ZZZ - SPRITE_OOP);
859 Graphics()->TextureSet(Texture: GameClient()->m_EmoticonsSkin.m_aSpriteEmoticons[CurEmoticon]);
860 int QuadOffset = QuadOffsetToEmoticon + CurEmoticon;
861 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: Alpha);
862 Graphics()->RenderQuadContainerAsSprite(ContainerIndex: m_WeaponEmoteQuadContainerIndex, QuadOffset, X: Position.x + 24.f, Y: Position.y - 40.f);
863
864 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: 1.0f);
865 Graphics()->QuadsSetRotation(Angle: 0);
866 }
867
868 if(g_Config.m_ClShowEmotes && !GameClient()->m_aClients[ClientId].m_EmoticonIgnore && GameClient()->m_aClients[ClientId].m_EmoticonStartTick != -1)
869 {
870 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);
871 float FromEnd = (2 * Client()->GameTickSpeed()) - SinceStart;
872
873 if(0 <= SinceStart && FromEnd > 0)
874 {
875 float a = 1;
876
877 if(FromEnd < Client()->GameTickSpeed() / 5)
878 a = FromEnd / (Client()->GameTickSpeed() / 5.0f);
879
880 float h = 1;
881 if(SinceStart < Client()->GameTickSpeed() / 10)
882 h = SinceStart / (Client()->GameTickSpeed() / 10.0f);
883
884 float Wiggle = 0;
885 if(SinceStart < Client()->GameTickSpeed() / 5)
886 Wiggle = SinceStart / (Client()->GameTickSpeed() / 5.0f);
887
888 float WiggleAngle = std::sin(x: 5 * Wiggle);
889
890 Graphics()->QuadsSetRotation(Angle: pi / 6 * WiggleAngle);
891
892 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: a * Alpha);
893 // client_datas::emoticon is an offset from the first emoticon
894 int QuadOffset = QuadOffsetToEmoticon + GameClient()->m_aClients[ClientId].m_Emoticon;
895 Graphics()->TextureSet(Texture: GameClient()->m_EmoticonsSkin.m_aSpriteEmoticons[GameClient()->m_aClients[ClientId].m_Emoticon]);
896 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);
897
898 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: 1.0f);
899 Graphics()->QuadsSetRotation(Angle: 0);
900 }
901 }
902}
903
904inline bool CPlayers::IsPlayerInfoAvailable(int ClientId) const
905{
906 return GameClient()->m_Snap.m_aCharacters[ClientId].m_Active &&
907 GameClient()->m_Snap.m_apPrevPlayerInfos[ClientId] != nullptr &&
908 GameClient()->m_Snap.m_apPlayerInfos[ClientId] != nullptr;
909}
910
911void CPlayers::OnRender()
912{
913 if(Client()->State() != IClient::STATE_ONLINE && Client()->State() != IClient::STATE_DEMOPLAYBACK)
914 return;
915
916 // update render info for ninja
917 CTeeRenderInfo aRenderInfo[MAX_CLIENTS];
918 const bool IsTeamPlay = GameClient()->IsTeamPlay();
919 for(int i = 0; i < MAX_CLIENTS; ++i)
920 {
921 aRenderInfo[i] = GameClient()->m_aClients[i].m_RenderInfo;
922 aRenderInfo[i].m_TeeRenderFlags = 0;
923
924 // predict freeze skin only for local players
925 bool Frozen = false;
926 if(i == GameClient()->m_aLocalIds[0] || i == GameClient()->m_aLocalIds[1])
927 {
928 if(GameClient()->m_aClients[i].m_Predicted.m_FreezeEnd != 0)
929 aRenderInfo[i].m_TeeRenderFlags |= TEE_EFFECT_FROZEN | TEE_NO_WEAPON;
930 if(GameClient()->m_aClients[i].m_Predicted.m_LiveFrozen)
931 aRenderInfo[i].m_TeeRenderFlags |= TEE_EFFECT_FROZEN;
932 if(GameClient()->m_aClients[i].m_Predicted.m_Invincible)
933 aRenderInfo[i].m_TeeRenderFlags |= TEE_EFFECT_SPARKLE;
934
935 Frozen = GameClient()->m_aClients[i].m_Predicted.m_FreezeEnd != 0;
936 }
937 else
938 {
939 if(GameClient()->m_aClients[i].m_FreezeEnd != 0)
940 aRenderInfo[i].m_TeeRenderFlags |= TEE_EFFECT_FROZEN | TEE_NO_WEAPON;
941 if(GameClient()->m_aClients[i].m_LiveFrozen)
942 aRenderInfo[i].m_TeeRenderFlags |= TEE_EFFECT_FROZEN;
943 if(GameClient()->m_aClients[i].m_Invincible)
944 aRenderInfo[i].m_TeeRenderFlags |= TEE_EFFECT_SPARKLE;
945
946 Frozen = GameClient()->m_Snap.m_aCharacters[i].m_HasExtendedData && GameClient()->m_Snap.m_aCharacters[i].m_ExtendedData.m_FreezeEnd != 0;
947 }
948
949 if((GameClient()->m_aClients[i].m_RenderCur.m_Weapon == WEAPON_NINJA || (Frozen && !GameClient()->m_GameInfo.m_NoSkinChangeForFrozen)) && g_Config.m_ClShowNinja)
950 {
951 // change the skin for the player to the ninja
952 aRenderInfo[i].m_aSixup[g_Config.m_ClDummy].Reset();
953 aRenderInfo[i].ApplySkin(TeeRenderInfo: NinjaTeeRenderInfo()->TeeRenderInfo());
954 aRenderInfo[i].m_CustomColoredSkin = IsTeamPlay;
955 if(!IsTeamPlay)
956 {
957 aRenderInfo[i].m_ColorBody = ColorRGBA(1, 1, 1);
958 aRenderInfo[i].m_ColorFeet = ColorRGBA(1, 1, 1);
959 }
960 }
961 }
962
963 // get screen edges to avoid rendering offscreen
964 float ScreenX0, ScreenY0, ScreenX1, ScreenY1;
965 Graphics()->GetScreen(pTopLeftX: &ScreenX0, pTopLeftY: &ScreenY0, pBottomRightX: &ScreenX1, pBottomRightY: &ScreenY1);
966 // expand the edges to prevent popping in/out onscreen
967 //
968 // it is assumed that the tee, all its weapons, and emotes fit into a 200x200 box centered on the tee
969 // this may need to be changed or calculated differently in the future
970 float BorderBuffer = 100;
971 ScreenX0 -= BorderBuffer;
972 ScreenX1 += BorderBuffer;
973 ScreenY0 -= BorderBuffer;
974 ScreenY1 += BorderBuffer;
975
976 // render everyone else's hook, then our own
977 const int LocalClientId = GameClient()->m_Snap.m_LocalClientId;
978 for(int ClientId = 0; ClientId < MAX_CLIENTS; ClientId++)
979 {
980 if(ClientId == LocalClientId || !IsPlayerInfoAvailable(ClientId))
981 {
982 continue;
983 }
984 RenderHook(pPrevChar: &GameClient()->m_aClients[ClientId].m_RenderPrev, pPlayerChar: &GameClient()->m_aClients[ClientId].m_RenderCur, pRenderInfo: &aRenderInfo[ClientId], ClientId);
985 }
986 if(LocalClientId != -1 && IsPlayerInfoAvailable(ClientId: LocalClientId))
987 {
988 const CGameClient::CClientData *pLocalClientData = &GameClient()->m_aClients[LocalClientId];
989 RenderHook(pPrevChar: &pLocalClientData->m_RenderPrev, pPlayerChar: &pLocalClientData->m_RenderCur, pRenderInfo: &aRenderInfo[LocalClientId], ClientId: LocalClientId);
990 }
991
992 // render spectating players
993 for(const auto &Client : GameClient()->m_aClients)
994 {
995 if(!Client.m_SpecCharPresent)
996 {
997 continue;
998 }
999
1000 const int ClientId = Client.ClientId();
1001 float Alpha = (GameClient()->IsOtherTeam(ClientId) || ClientId < 0) ? g_Config.m_ClShowOthersAlpha / 100.f : 1.f;
1002 if(ClientId == -2) // ghost
1003 {
1004 Alpha = g_Config.m_ClRaceGhostAlpha / 100.f;
1005 }
1006 RenderTools()->RenderTee(pAnim: CAnimState::GetIdle(), pInfo: &SpectatorTeeRenderInfo()->TeeRenderInfo(), Emote: EMOTE_BLINK, Dir: vec2(1, 0), Pos: Client.m_SpecChar, Alpha);
1007 }
1008
1009 // render everyone else's tee, then either our own or the tee we are spectating.
1010 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;
1011
1012 for(int ClientId = 0; ClientId < MAX_CLIENTS; ClientId++)
1013 {
1014 if(ClientId == RenderLastId || !IsPlayerInfoAvailable(ClientId))
1015 {
1016 continue;
1017 }
1018
1019 RenderHookCollLine(pPrevChar: &GameClient()->m_aClients[ClientId].m_RenderPrev, pPlayerChar: &GameClient()->m_aClients[ClientId].m_RenderCur, ClientId);
1020
1021 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))
1022 {
1023 continue;
1024 }
1025 RenderPlayer(pPrevChar: &GameClient()->m_aClients[ClientId].m_RenderPrev, pPlayerChar: &GameClient()->m_aClients[ClientId].m_RenderCur, pRenderInfo: &aRenderInfo[ClientId], ClientId);
1026 }
1027 if(RenderLastId != -1 && IsPlayerInfoAvailable(ClientId: RenderLastId))
1028 {
1029 const CGameClient::CClientData *pClientData = &GameClient()->m_aClients[RenderLastId];
1030 RenderHookCollLine(pPrevChar: &pClientData->m_RenderPrev, pPlayerChar: &pClientData->m_RenderCur, ClientId: RenderLastId);
1031 RenderPlayer(pPrevChar: &pClientData->m_RenderPrev, pPlayerChar: &pClientData->m_RenderCur, pRenderInfo: &aRenderInfo[RenderLastId], ClientId: RenderLastId);
1032 }
1033}
1034
1035void CPlayers::CreateNinjaTeeRenderInfo()
1036{
1037 CTeeRenderInfo NinjaTeeRenderInfo;
1038 NinjaTeeRenderInfo.m_Size = 64.0f;
1039 CSkinDescriptor NinjaSkinDescriptor;
1040 NinjaSkinDescriptor.m_Flags |= CSkinDescriptor::FLAG_SIX;
1041 str_copy(dst&: NinjaSkinDescriptor.m_aSkinName, src: "x_ninja");
1042 m_pNinjaTeeRenderInfo = GameClient()->CreateManagedTeeRenderInfo(TeeRenderInfo: NinjaTeeRenderInfo, SkinDescriptor: NinjaSkinDescriptor);
1043}
1044
1045void CPlayers::CreateSpectatorTeeRenderInfo()
1046{
1047 CTeeRenderInfo SpectatorTeeRenderInfo;
1048 SpectatorTeeRenderInfo.m_Size = 64.0f;
1049 CSkinDescriptor SpectatorSkinDescriptor;
1050 SpectatorSkinDescriptor.m_Flags |= CSkinDescriptor::FLAG_SIX;
1051 str_copy(dst&: SpectatorSkinDescriptor.m_aSkinName, src: "x_spec");
1052 m_pSpectatorTeeRenderInfo = GameClient()->CreateManagedTeeRenderInfo(TeeRenderInfo: SpectatorTeeRenderInfo, SkinDescriptor: SpectatorSkinDescriptor);
1053}
1054
1055void CPlayers::OnInit()
1056{
1057 m_WeaponEmoteQuadContainerIndex = Graphics()->CreateQuadContainer(AutomaticUpload: false);
1058
1059 Graphics()->SetColor(r: 1.f, g: 1.f, b: 1.f, a: 1.f);
1060
1061 for(int i = 0; i < NUM_WEAPONS; ++i)
1062 {
1063 float ScaleX, ScaleY;
1064 Graphics()->GetSpriteScale(pSprite: g_pData->m_Weapons.m_aId[i].m_pSpriteBody, ScaleX, ScaleY);
1065 Graphics()->QuadsSetSubset(TopLeftU: 0, TopLeftV: 0, BottomRightU: 1, BottomRightV: 1);
1066 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);
1067 Graphics()->QuadsSetSubset(TopLeftU: 0, TopLeftV: 1, BottomRightU: 1, BottomRightV: 0);
1068 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);
1069 }
1070 float ScaleX, ScaleY;
1071
1072 // at the end the hand
1073 Graphics()->QuadsSetSubset(TopLeftU: 0, TopLeftV: 0, BottomRightU: 1, BottomRightV: 1);
1074 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_WeaponEmoteQuadContainerIndex, Size: 20.f);
1075 Graphics()->QuadsSetSubset(TopLeftU: 0, TopLeftV: 0, BottomRightU: 1, BottomRightV: 1);
1076 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_WeaponEmoteQuadContainerIndex, Size: 20.f);
1077
1078 Graphics()->QuadsSetSubset(TopLeftU: 0, TopLeftV: 0, BottomRightU: 1, BottomRightV: 1);
1079 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_WeaponEmoteQuadContainerIndex, X: -12.f, Y: -8.f, Width: 24.f, Height: 16.f);
1080 Graphics()->QuadsSetSubset(TopLeftU: 0, TopLeftV: 0, BottomRightU: 1, BottomRightV: 1);
1081 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_WeaponEmoteQuadContainerIndex, X: -12.f, Y: -8.f, Width: 24.f, Height: 16.f);
1082
1083 for(int i = 0; i < NUM_EMOTICONS; ++i)
1084 {
1085 Graphics()->QuadsSetSubset(TopLeftU: 0, TopLeftV: 0, BottomRightU: 1, BottomRightV: 1);
1086 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_WeaponEmoteQuadContainerIndex, Size: 64.f);
1087 }
1088 Graphics()->QuadContainerUpload(ContainerIndex: m_WeaponEmoteQuadContainerIndex);
1089
1090 for(int i = 0; i < NUM_WEAPONS; ++i)
1091 {
1092 m_aWeaponSpriteMuzzleQuadContainerIndex[i] = Graphics()->CreateQuadContainer(AutomaticUpload: false);
1093 for(int n = 0; n < g_pData->m_Weapons.m_aId[i].m_NumSpriteMuzzles; ++n)
1094 {
1095 if(g_pData->m_Weapons.m_aId[i].m_aSpriteMuzzles[n])
1096 {
1097 if(i == WEAPON_GUN || i == WEAPON_SHOTGUN)
1098 {
1099 // TODO: hardcoded for now to get the same particle size as before
1100 Graphics()->GetSpriteScaleImpl(Width: 96, Height: 64, ScaleX, ScaleY);
1101 }
1102 else
1103 Graphics()->GetSpriteScale(pSprite: g_pData->m_Weapons.m_aId[i].m_aSpriteMuzzles[n], ScaleX, ScaleY);
1104 }
1105
1106 float SWidth = (g_pData->m_Weapons.m_aId[i].m_VisualSize * ScaleX) * (4.0f / 3.0f);
1107 float SHeight = g_pData->m_Weapons.m_aId[i].m_VisualSize * ScaleY;
1108
1109 Graphics()->QuadsSetSubset(TopLeftU: 0, TopLeftV: 0, BottomRightU: 1, BottomRightV: 1);
1110 if(WEAPON_NINJA == i)
1111 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_aWeaponSpriteMuzzleQuadContainerIndex[i], Width: 160.f * ScaleX, Height: 160.f * ScaleY);
1112 else
1113 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_aWeaponSpriteMuzzleQuadContainerIndex[i], Width: SWidth, Height: SHeight);
1114
1115 Graphics()->QuadsSetSubset(TopLeftU: 0, TopLeftV: 1, BottomRightU: 1, BottomRightV: 0);
1116 if(WEAPON_NINJA == i)
1117 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_aWeaponSpriteMuzzleQuadContainerIndex[i], Width: 160.f * ScaleX, Height: 160.f * ScaleY);
1118 else
1119 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_aWeaponSpriteMuzzleQuadContainerIndex[i], Width: SWidth, Height: SHeight);
1120 }
1121 Graphics()->QuadContainerUpload(ContainerIndex: m_aWeaponSpriteMuzzleQuadContainerIndex[i]);
1122 }
1123
1124 Graphics()->QuadsSetSubset(TopLeftU: 0.f, TopLeftV: 0.f, BottomRightU: 1.f, BottomRightV: 1.f);
1125 Graphics()->QuadsSetRotation(Angle: 0.f);
1126
1127 CreateNinjaTeeRenderInfo();
1128 CreateSpectatorTeeRenderInfo();
1129}
1130