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