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