Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix todo - i guess #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/game/client/components/tclient/trails.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ void CTrails::OnRender()
for(int i = 0; i < TrimTicks; i++)
Trail.pop_back();

// Stuff breaks if we have less than 3 points because we cannot calculate an angle between segments to preserve constant width
// TODO: Pad the list with generated entries in the same direction as before
if((int)Trail.size() < 3)
continue;

//pad if trailsize < 3
while((int)Trail.size() < 3) {
Trail.insert(Trail.begin(), GenerateTrailPoint(Trail, Trail.size()).back());
}
Trail.at(Trail.size() - 1).Pos = mix(Trail.at(Trail.size() - 1).Pos, Trail.at(Trail.size() - 2).Pos, std::fmod(IntraTick, 1.0f));

// Set progress
Expand Down Expand Up @@ -332,4 +332,14 @@ void CTrails::OnRender()
GameClient()->m_aClients[ClientId].m_aPredPos[PredTick % 200] = SavedTempPredPos;
m_PositionHistory[ClientId][GameTick % 200] = CurServerPos;
}
}

std::vector<STrailPart> CTrails::GenerateTrailPoint(std::vector<STrailPart> &Trail, int Index) {
if (Trail.empty()) return {Trail[Index]};
STrailPart newPoint = Trail[Index];
vec2 direction = normalize(Trail[1].Pos - Trail[0].Pos);
float length = distance(Trail[1].Pos, Trail[0].Pos);
newPoint.Pos -= direction * length;

return {newPoint};
}
2 changes: 2 additions & 0 deletions src/game/client/components/tclient/trails.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class CTrails : public CComponent
virtual void OnReset() override;

private:
//helper function to pad the trail if TrailSize < 3
std::vector<STrailPart> GenerateTrailPoint(std::vector<STrailPart> &Trail, int Index);
vec2 m_PositionHistory[MAX_CLIENTS][200];
int m_PositionTick[MAX_CLIENTS][200];
bool m_HistoryValid[MAX_CLIENTS] = {};
Expand Down