Player12
An open source football management simulator
Loading...
Searching...
No Matches
match_render_snapshot.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2// Football Management Project
3// Copyright (c) 2025 - 2026 Flavio Milinanni. All Rights Reserved.
4//
5// This file is part of the Football Management Project.
6// See the LICENSE file in the project root.
7// -----------------------------------------------------------------------------
8
9#pragma once
10
11#include <cmath>
12#include <vector>
13
14#include "model/match_engine.h"
15
63
87
117
122inline void fillMatchRenderSnapshot(const MatchEngine& engine,
123 MatchRenderSnapshot& snapshot)
124{
125 const auto& players = engine.getPlayers();
126 const auto& previousPositions = engine.getPreviousPlayerPositions();
127 const auto& previousFacingAngles = engine.getPreviousPlayerFacingAngles();
128 snapshot.players.clear();
129 snapshot.players.reserve(players.size());
130 for (std::size_t index = 0; index < players.size(); ++index)
131 {
132 const MatchPlayer& source = players[index];
133 MatchRenderPlayer& renderPlayer = snapshot.players.emplace_back();
134 renderPlayer.player = source.player;
135 renderPlayer.isHomeTeam = source.isHomeTeam;
136 renderPlayer.currentPosition = source.position;
137 renderPlayer.movementTarget = source.movementTarget;
138 renderPlayer.intent = source.intent;
139 renderPlayer.currentFacingAngle = source.facingAngle;
140 renderPlayer.stamina = source.stamina;
141 renderPlayer.possessesBall = source.player != nullptr &&
142 engine.getBall().possessedBy == source.player;
143 renderPlayer.onPitch = source.onPitch;
144 renderPlayer.isGoalkeeper = source.isGoalkeeper;
145 renderPlayer.isDiving = source.isDiving;
146 renderPlayer.isInjured = source.isInjured;
147 renderPlayer.yellowCards = source.yellowCards;
148 renderPlayer.heightMetres = source.heightMetres;
149 renderPlayer.speedMetresPerSecond =
150 std::sqrt(source.velocity.x * source.velocity.x +
151 source.velocity.y * source.velocity.y);
152 renderPlayer.tackleCooldown = source.tackleCooldown;
153 renderPlayer.previousPosition = index < previousPositions.size()
154 ? previousPositions[index]
155 : renderPlayer.currentPosition;
156 renderPlayer.previousFacingAngle = index < previousFacingAngles.size()
157 ? previousFacingAngles[index]
158 : renderPlayer.currentFacingAngle;
159 }
160
161 const MatchBall& ball = engine.getBall();
162 snapshot.ball.currentPosition = ball.position;
164 snapshot.ball.currentZ = ball.z;
165 snapshot.ball.previousZ = engine.getPreviousBallZ();
166 snapshot.ball.possessedBy = ball.possessedBy;
167 snapshot.ball.currentHeightMetres =
169 snapshot.ball.previousHeightMetres =
171 snapshot.ball.isShot = ball.isShot;
172 snapshot.ball.isAerialDelivery = ball.isAerialDelivery;
173 snapshot.ball.fromThrowIn = ball.fromThrowIn;
174 snapshot.ball.kicker = ball.kicker;
175 snapshot.ball.kickerLockout = ball.kickerLockout;
176
177 snapshot.state = engine.getState();
178 snapshot.homePhase = engine.getHomePhase();
179 snapshot.awayPhase = engine.getAwayPhase();
181 snapshot.homeScore = engine.getHomeScore();
182 snapshot.awayScore = engine.getAwayScore();
183 snapshot.goalScoredByHome = engine.getGoalScoredByHome();
186 snapshot.matchTimeMinutes = engine.getMatchTimeMinutes();
187 snapshot.events = &engine.getEvents();
188 snapshot.stats = &engine.getStats();
189 snapshot.interpolationAlpha = engine.getInterpolationAlpha();
190 snapshot.period = engine.getPeriod();
191 snapshot.addedMinutesFirstHalf = engine.getAddedMinutes(1);
192 snapshot.addedMinutesSecondHalf = engine.getAddedMinutes(2);
195 snapshot.playerStats = &engine.getPlayerStats();
196}
197
200{
201 MatchRenderSnapshot snapshot;
202 fillMatchRenderSnapshot(engine, snapshot);
203 return snapshot;
204}
205
207inline Vector2F lerpRenderPosition(Vector2F first, Vector2F second, float alpha)
208{
209 return {first.x + (second.x - first.x) * alpha,
210 first.y + (second.y - first.y) * alpha};
211}
Definition match_engine.h:517
float getPreviousBallZ() const
Definition match_engine.h:904
Vector2F getPreviousBallPosition() const
Definition match_engine.h:903
bool getGoalScoredByHome() const
Definition match_engine.h:880
const MatchStats & getStats() const
Definition match_engine.h:751
const std::vector< PlayerMatchStats > & getPlayerStats() const
Definition match_engine.h:796
const MatchBall & getBall() const
Definition match_engine.h:743
TeamPhase getAwayPhase() const
Definition match_engine.h:753
int getPeriod() const
Definition match_engine.h:821
const std::vector< Vector2F > & getPreviousPlayerPositions() const
Definition match_engine.h:895
MatchState getState() const
Definition match_engine.h:750
float getGoalCelebrationDuration() const
Definition match_engine.h:884
GoalkeeperState getAwayGoalkeeperState() const
Definition match_engine.h:912
const std::vector< float > & getPreviousPlayerFacingAngles() const
Definition match_engine.h:899
TeamPhase getHomePhase() const
Definition match_engine.h:752
const std::vector< MatchPlayer > & getPlayers() const
Definition match_engine.h:742
float getTransitionSecondsRemaining() const
Definition match_engine.h:754
const std::vector< MatchEvent > & getEvents() const
Definition match_engine.h:744
int getHomeScore() const
Definition match_engine.h:868
float getGoalCelebrationRemaining() const
Definition match_engine.h:883
float getInterpolationAlpha() const
Definition match_engine.cpp:1614
float getMatchTimeMinutes() const
Definition match_engine.h:870
int getAwayScore() const
Definition match_engine.h:869
GoalkeeperState getHomeGoalkeeperState() const
Definition match_engine.h:911
int getAddedMinutes(int half) const
Definition match_engine.h:823
Persistent career identity, attributes, traits and day-to-day state.
Definition player.h:104
PlayerIntent
Definition match_engine.h:64
TeamPhase
Definition match_engine.h:52
GoalkeeperState
Definition match_engine.h:119
MatchState
Definition match_engine.h:34
MatchRenderSnapshot buildMatchRenderSnapshot(const MatchEngine &engine)
Definition match_render_snapshot.h:199
void fillMatchRenderSnapshot(const MatchEngine &engine, MatchRenderSnapshot &snapshot)
Definition match_render_snapshot.h:122
Vector2F lerpRenderPosition(Vector2F first, Vector2F second, float alpha)
Definition match_render_snapshot.h:207
int index
Definition runtime_editor.cpp:94
Definition match_engine.h:220
float z
Definition match_engine.h:222
const Player * kicker
Definition match_engine.h:231
float kickerLockout
Definition match_engine.h:233
Vector2F position
Definition match_engine.h:221
bool isAerialDelivery
Definition match_engine.h:260
bool fromThrowIn
Definition match_engine.h:262
bool isShot
Definition match_engine.h:246
const Player * possessedBy
Definition match_engine.h:227
Definition match_engine.h:151
int yellowCards
Definition match_engine.h:209
float stamina
Definition match_engine.h:178
Vector2F position
Definition match_engine.h:154
bool isInjured
Definition match_engine.h:205
bool isHomeTeam
Definition match_engine.h:153
bool isDiving
Definition match_engine.h:172
float heightMetres
Definition match_engine.h:199
float facingAngle
Definition match_engine.h:166
const Player * player
Definition match_engine.h:152
bool onPitch
Definition match_engine.h:202
Vector2F velocity
Definition match_engine.h:155
bool isGoalkeeper
Definition match_engine.h:204
float tackleCooldown
Definition match_engine.h:186
Vector2F movementTarget
Definition match_engine.h:157
PlayerIntent intent
Definition match_engine.h:159
Definition match_render_snapshot.h:65
bool fromThrowIn
Definition match_render_snapshot.h:78
float currentZ
Definition match_render_snapshot.h:71
const Player * possessedBy
Definition match_render_snapshot.h:72
const Player * kicker
Definition match_render_snapshot.h:84
float currentHeightMetres
Definition match_render_snapshot.h:74
float kickerLockout
Definition match_render_snapshot.h:85
Vector2F previousPosition
Definition match_render_snapshot.h:66
bool isShot
Definition match_render_snapshot.h:75
bool isAerialDelivery
Definition match_render_snapshot.h:76
Vector2F currentPosition
Definition match_render_snapshot.h:68
float previousZ
Definition match_render_snapshot.h:70
float previousHeightMetres
Definition match_render_snapshot.h:73
Definition match_render_snapshot.h:36
Vector2F currentPosition
Definition match_render_snapshot.h:41
Vector2F previousPosition
Definition match_render_snapshot.h:39
float currentFacingAngle
Definition match_render_snapshot.h:47
bool onPitch
Definition match_render_snapshot.h:51
float tackleCooldown
Definition match_render_snapshot.h:61
bool isHomeTeam
Definition match_render_snapshot.h:38
PlayerIntent intent
Definition match_render_snapshot.h:45
Vector2F movementTarget
Definition match_render_snapshot.h:43
bool isDiving
Definition match_render_snapshot.h:53
float heightMetres
Definition match_render_snapshot.h:56
float speedMetresPerSecond
Definition match_render_snapshot.h:58
const Player * player
Definition match_render_snapshot.h:37
bool possessesBall
Definition match_render_snapshot.h:49
bool isGoalkeeper
Definition match_render_snapshot.h:52
int yellowCards
Definition match_render_snapshot.h:55
float previousFacingAngle
Definition match_render_snapshot.h:46
float stamina
Definition match_render_snapshot.h:48
bool isInjured
Definition match_render_snapshot.h:54
Definition match_render_snapshot.h:89
float transitionSecondsRemaining
Definition match_render_snapshot.h:99
TeamPhase awayPhase
Definition match_render_snapshot.h:98
const std::vector< MatchEvent > * events
Definition match_render_snapshot.h:106
MatchRenderBall ball
Definition match_render_snapshot.h:95
TeamID homeTeam
Definition match_render_snapshot.h:93
bool goalScoredByHome
Definition match_render_snapshot.h:102
float goalCelebrationRemaining
Definition match_render_snapshot.h:103
const std::vector< PlayerMatchStats > * playerStats
Definition match_render_snapshot.h:115
int awayScore
Definition match_render_snapshot.h:101
TeamPhase homePhase
Definition match_render_snapshot.h:97
MatchState state
Definition match_render_snapshot.h:96
int addedMinutesSecondHalf
Definition match_render_snapshot.h:112
const MatchStats * stats
Definition match_render_snapshot.h:107
std::vector< MatchRenderPlayer > players
Definition match_render_snapshot.h:90
TeamID awayTeam
Definition match_render_snapshot.h:94
float matchTimeMinutes
Definition match_render_snapshot.h:105
int homeScore
Definition match_render_snapshot.h:100
int period
Definition match_render_snapshot.h:110
int addedMinutesFirstHalf
Definition match_render_snapshot.h:111
float interpolationAlpha
Definition match_render_snapshot.h:108
GoalkeeperState homeGoalkeeperState
Definition match_render_snapshot.h:113
GoalkeeperState awayGoalkeeperState
Definition match_render_snapshot.h:114
float goalCelebrationDuration
Definition match_render_snapshot.h:104
Definition match_engine.h:266
static constexpr float CENTRE
Definition match_tuning.h:37
static constexpr float GOAL_CELEBRATION_SECONDS
Definition match_tuning.h:126
static constexpr float BALL_Z_METRES
Definition match_tuning.h:900
static constexpr float DEFAULT_PLAYER_HEIGHT_METRES
Definition match_tuning.h:903
A simple 2D float vector for pitch coordinates.
Definition types.h:84
float y
Definition types.h:86
float x
Definition types.h:85
uint16_t TeamID
Type alias for Team identifiers.
Definition types.h:18