Skip to content

Commit 29caf0d

Browse files
committed
Add trace for a marine (Pure client effects). This will help new players to find where a marine goes.
You can mark a player in lobby as your tracing target. This is still a WIP
1 parent f1ed077 commit 29caf0d

3 files changed

Lines changed: 135 additions & 1 deletion

File tree

src/game/client/swarm/c_asw_marine.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
#include <vgui/IScheme.h>
5050
#include "stats_report.h"
5151
#include "asw_weapon_night_vision.h"
52+
#ifdef CLIENT_DLL
53+
#include <vector>
54+
#include <list>
55+
#endif
5256

5357
// memdbgon must be the last include file in a .cpp file!!!
5458
#include "tier0/memdbgon.h"
@@ -103,6 +107,11 @@ extern ConVar rd_team_color_ally;
103107
extern ConVar rd_team_color_enemy;
104108
extern float g_fMarinePoisonDuration;
105109

110+
#ifdef CLIENT_DLL
111+
std::vector<bool> g_bShouldTracePlayer = std::vector<bool>(MAX_PLAYERS, true); // whether we have a trace position for this player
112+
const float TRACE_FADE_TIME = 60.0f; // how long to keep the trace positions for
113+
#endif
114+
106115
#define FLASHLIGHT_DISTANCE 1000
107116
#define ASW_PROJECTOR_FLASHLIGHT 1
108117

@@ -859,6 +868,8 @@ void C_ASW_Marine::ClientThink()
859868
TickEmotes( deltatime );
860869
TickRedName( deltatime );
861870

871+
TickTracePlayerMovement(deltatime);
872+
862873
UpdateFireEmitters();
863874
UpdateJumpJetEffects();
864875
UpdateElectrifiedArmor();
@@ -973,7 +984,28 @@ void C_ASW_Marine::DoWaterRipples()
973984
DispatchEffect( "aswwatersplash", data );
974985
//static Vector s_MarineWaterSplashColor( 0.5, 0.5, 0.5 );
975986
//FX_ASWWaterRipple(data.m_vOrigin, 1.0f, &s_MarineWaterSplashColor, 1.5f, 0.1f);
976-
}
987+
}
988+
}
989+
990+
void C_ASW_Marine::TickTracePlayerMovement(float d)
991+
{
992+
// insert current time marine position
993+
struct TracePlayerMovement_t movement;
994+
//get current time
995+
movement.m_flTraceTime = TRACE_FADE_TIME;
996+
movement.m_vecPosition = GetAbsOrigin() + Vector(0, 0, 5);
997+
m_lstTracePlayerMovementList.push_back(movement);
998+
999+
// update the trace time for each movement trace
1000+
for (auto iter = m_lstTracePlayerMovementList.begin(); iter != m_lstTracePlayerMovementList.end(); ++iter)
1001+
{
1002+
iter->m_flTraceTime -= d;
1003+
}
1004+
1005+
// remove any traces that have expired
1006+
m_lstTracePlayerMovementList.remove_if([](const auto& item) {
1007+
return item.m_flTraceTime <= 0;
1008+
});
9771009
}
9781010

9791011
void C_ASW_Marine::CreateWeaponEmitters()

src/game/client/swarm/c_asw_marine.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@
1616
#include "asw_deathmatch_mode.h"
1717
#include "dlight.h"
1818
#include "rd_inventory_shared.h"
19+
#ifdef CLIENT_DLL
20+
#include <vector>
21+
#include <list>
22+
23+
struct TracePlayerMovement_t
24+
{
25+
float m_flTraceTime;
26+
Vector m_vecPosition;
27+
};
28+
#endif
29+
30+
1931

2032
class C_ASW_Player;
2133
class C_ASW_Marine_Resource;
@@ -293,6 +305,10 @@ class C_ASW_Marine : public C_ASW_VPhysics_NPC, public IASWPlayerAnimStateHelper
293305
// emote system
294306
void TickEmotes( float d );
295307
bool TickEmote( float d, int bit, float &fEmoteTime );
308+
#ifdef CLIENT_DLL
309+
void TickTracePlayerMovement(float d);
310+
std::list<TracePlayerMovement_t> m_lstTracePlayerMovementList = std::list<TracePlayerMovement_t>(); // list of positions and times for the last few frames
311+
#endif
296312
CNetworkVar( int, m_iEmote );
297313
int m_iClientEmote;
298314
float m_fEmoteMedicTime;

src/game/client/swarm/vgui/asw_hud_emotes.cpp

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
#include "engine/IVDebugOverlay.h"
3131
#include "vguimatsurface/imatsystemsurface.h"
3232
#include "tier1/fmtstr.h"
33+
#ifdef CLIENT_DLL
34+
#include <vector>
35+
#include <list>
36+
#endif
3337

3438
// memdbgon must be the last include file in a .cpp file!!!
3539
#include "tier0/memdbgon.h"
@@ -38,6 +42,11 @@ using namespace vgui;
3842

3943
extern ConVar asw_draw_hud;
4044

45+
#ifdef CLIENT_DLL
46+
extern std::vector<bool> g_bShouldTracePlayer;
47+
extern const float TRACE_FADE_TIME;
48+
#endif
49+
4150
//-----------------------------------------------------------------------------
4251
// Purpose: Shows the marines emote graphics
4352
//-----------------------------------------------------------------------------
@@ -56,6 +65,9 @@ class CASWHudEmotes : public CASW_HudElement, public vgui::Panel
5665
virtual void PaintEmote( C_BaseEntity *pEnt, float fTime, int iTexture, float fScale = 1.0f );
5766
virtual bool ShouldDraw( void ) { return asw_draw_hud.GetBool() && CASW_HudElement::ShouldDraw(); }
5867

68+
virtual void PaintTraces();
69+
virtual void PaintTracesFor(C_ASW_Marine* pMarine);
70+
5971
CPanelAnimationVarAliasType( int, m_nMedicTexture, "MedicEmoteTexture", "vgui/swarm/Emotes/EmoteMedic", "textureid" );
6072
CPanelAnimationVarAliasType( int, m_nAmmoTexture, "AmmoEmoteTexture", "vgui/swarm/Emotes/EmoteAmmo", "textureid" );
6173
CPanelAnimationVarAliasType( int, m_nSmileTexture, "SmileEmoteTexture", "vgui/swarm/Emotes/EmoteSmile", "textureid" );
@@ -100,6 +112,7 @@ void CASWHudEmotes::Paint()
100112
VPROF_BUDGET( "CASWHudEmotes::Paint", VPROF_BUDGETGROUP_ASW_CLIENT );
101113
BaseClass::Paint();
102114
PaintEmotes();
115+
PaintTraces();
103116
}
104117

105118
void CASWHudEmotes::PaintEmotes()
@@ -276,3 +289,76 @@ void CASWHudEmotes::PaintEmote( C_BaseEntity *pEnt, float fTime, int iTexture, f
276289
}
277290
}
278291
}
292+
293+
void CASWHudEmotes::PaintTraces()
294+
{
295+
C_ASW_Game_Resource* pGameResource = ASWGameResource();
296+
if (!pGameResource)
297+
return;
298+
299+
for (int i = 0; i < pGameResource->GetMaxMarineResources(); i++)
300+
{
301+
C_ASW_Marine_Resource* pMR = pGameResource->GetMarineResource(i);
302+
if (!pMR)
303+
continue;
304+
305+
C_ASW_Marine* marine = pMR->GetMarineEntity();
306+
if (!pMR->IsInhabited() || !marine || !g_bShouldTracePlayer[pMR->GetCommanderIndex()])
307+
continue;
308+
309+
PaintTracesFor(marine);
310+
}
311+
}
312+
313+
void CASWHudEmotes::PaintTracesFor(C_ASW_Marine* pMarine)
314+
{
315+
for (auto iter = pMarine->m_lstTracePlayerMovementList.begin(); iter != pMarine->m_lstTracePlayerMovementList.end(); ++iter)
316+
{
317+
float fTime = (*iter).m_flTraceTime;
318+
Vector vecPosition = (*iter).m_vecPosition;
319+
320+
if (fTime <= 0)
321+
{
322+
continue; // no trace to draw
323+
}
324+
325+
// draw a circle at the position of the trace in world space
326+
// and fade it out over time
327+
float fAlpha = pow(((fTime / 3.0) - (int)(fTime / 3.0)),4);
328+
fAlpha = clamp(fAlpha, 0.0f, 1.0f);
329+
int iTexture = m_nSmileTexture;
330+
331+
Vector screenPos;
332+
// 将世界坐标转换为屏幕坐标
333+
if (!debugoverlay->ScreenPosition(vecPosition, screenPos))
334+
{
335+
float xPos = screenPos[0];
336+
float yPos = screenPos[1];
337+
338+
if (iTexture != -1)
339+
{
340+
// 计算大小,随时间略微变化
341+
float fSize = 0.9f + 0.1f * fAlpha;
342+
343+
// 应用屏幕高度比例和自定义缩放
344+
float fScale = (ScreenHeight() / 768.0f);
345+
float HalfW = 16.0f * fScale * fSize;
346+
float HalfH = 16.0f * fScale * fSize;
347+
348+
// 设置颜色和纹理
349+
surface()->DrawSetColor(Color(255, 255, 255, fAlpha * 255.0f));
350+
surface()->DrawSetTexture(iTexture);
351+
352+
// 绘制纹理多边形
353+
Vertex_t points[4] =
354+
{
355+
Vertex_t(Vector2D(xPos - HalfW, yPos - HalfH), Vector2D(0, 0)),
356+
Vertex_t(Vector2D(xPos + HalfW, yPos - HalfH), Vector2D(1, 0)),
357+
Vertex_t(Vector2D(xPos + HalfW, yPos + HalfH), Vector2D(1, 1)),
358+
Vertex_t(Vector2D(xPos - HalfW, yPos + HalfH), Vector2D(0, 1))
359+
};
360+
surface()->DrawTexturedPolygon(4, points);
361+
}
362+
}
363+
}
364+
}

0 commit comments

Comments
 (0)