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