|
Player12
An open source football management simulator
|
#include <match_play_controller.h>
Classes | |
| struct | Options |
Public Member Functions | |
| MatchPlayController ()=default | |
| ~MatchPlayController () | |
| MatchPlayController (const MatchPlayController &)=delete | |
| MatchPlayController & | operator= (const MatchPlayController &)=delete |
| void | begin (MatchEngine &engine, bool homeTeam, const Options &options) |
| void | end (MatchEngine &engine) |
| bool | isActive () const |
| bool | controlsHome () const |
| void | setOptions (const Options &changed) |
| const Options & | options () const |
| bool | handleEvent (const SDL_Event &event) |
| void | clearPresses () |
| bool | takePauseRequest () |
| void | update (MatchEngine &engine, float simulatedSeconds, const PlayScreenBasis &basis) |
| PlayerID | nextSwitch () const |
| float | chargeShare (const MatchEngine &engine) const |
| bool | isCharging () const |
| bool | hasGamepad () const |
| const char * | gamepadName () const |
| const MatchPlayerInput & | lastInput () const |
Static Public Attributes | |
| static constexpr float | FULL_POWER_SECONDS = 1.0f |
Private Types | |
| enum | Control : std::uint8_t { UP , DOWN , LEFT , RIGHT , PASS , SHOOT , THROUGH , LOB , SWITCH , SPRINT , JOCKEY , PAUSE , CONTROL_COUNT } |
Private Member Functions | |
| void | press (Control control) |
| void | release (Control control) |
| bool | held (Control control) const |
| void | openGamepad (SDL_JoystickID which) |
| void | openFirstGamepad () |
| void | closeGamepad () |
| void | readStick (float &x, float &y) const |
| void | switchTo (MatchEngine &engine, PlayerID player) |
| void | applySwitchingRules (MatchEngine &engine, PlayerID current, bool idle) |
Static Private Member Functions | |
| static Control | controlForKey (const SDL_KeyboardEvent &key) |
| static Control | controlForButton (int button) |
Private Attributes | |
| bool | active = false |
| bool | home = true |
| Options | settings |
| std::array< std::uint8_t, SDL_SCANCODE_COUNT > | keys {} |
| std::array< std::uint8_t, CONTROL_COUNT > | keyHolds {} |
| std::array< bool, CONTROL_COUNT > | padHolds {} |
| std::array< bool, CONTROL_COUNT > | pressed {} |
| std::array< bool, CONTROL_COUNT > | released {} |
| bool | pause_requested = false |
| SDL_Gamepad * | gamepad = nullptr |
| bool | gamepad_subsystem = false |
| MatchInputAction | charging = MatchInputAction::NONE |
| std::uint64_t | charge_step = 0 |
| MatchInputAction | pending = MatchInputAction::NONE |
| float | pending_power = 0.0f |
| MatchPlayerInput | submitted |
| bool | submitted_any = false |
| PlayerID | next_switch = 0 |
| double | last_switch_seconds = -1e9 |
| double | last_manual_seconds = -1e9 |
| PlayerID | manual_skip = 0 |
| double | idle_since = 0.0 |
| bool | was_idle = true |
The human's side of play mode: keyboard and gamepad state, the action buttons with their power bar, and who the active footballer is.
Devices are read on every frame, but the engine only receives one sample per simulation step (taken on the frame in which the engine is about to step), as a tick-stamped MatchPlayerInput record; switching goes through MatchEngine::setControlledPlayer. Power comes from how many simulation steps a button was held, so a recorded match replays exactly and the frame rate never changes what happens on the pitch.
|
private |
|
default |
| MatchPlayController::~MatchPlayController | ( | ) |
|
delete |
|
private |
| void MatchPlayController::begin | ( | MatchEngine & | engine, |
| bool | homeTeam, | ||
| const Options & | options | ||
| ) |
Takes control of homeTeam's best placed footballer.
| float MatchPlayController::chargeShare | ( | const MatchEngine & | engine | ) | const |
Filled share of the power bar while a button is held, else 0.
| void MatchPlayController::clearPresses | ( | ) |
Forgets presses and a charging button (after a pause or a dialog).
|
private |
|
staticprivate |
|
staticprivate |
Control a key or gamepad button stands for (CONTROL_COUNT: none); keys follow the bindings of Settings > Controls (sprint is Shift).
|
inline |
| void MatchPlayController::end | ( | MatchEngine & | engine | ) |
Hands every player back to the AI.
| const char * MatchPlayController::gamepadName | ( | ) | const |
Name of the connected gamepad (empty when none).
| bool MatchPlayController::handleEvent | ( | const SDL_Event & | event | ) |
Keyboard and gamepad events (including hot-plug); true when the event was one of the play controls (the caller should not use it for anything else).
|
inline |
True while a gamepad is connected and in use.
|
private |
|
inline |
|
inline |
|
inline |
The last input sent to the engine (tests, presentation).
|
inline |
The footballer a manual switch would pick now (0 when none).
|
private |
|
private |
|
delete |
|
inline |
|
private |
|
private |
Stick direction on screen (x right, y down), magnitude 0..1.
|
private |
|
inline |
|
private |
Hands control to player now, keeping the device state.
| bool MatchPlayController::takePauseRequest | ( | ) |
True once per press of the pause control (Esc, P, Start).
| void MatchPlayController::update | ( | MatchEngine & | engine, |
| float | simulatedSeconds, | ||
| const PlayScreenBasis & | basis | ||
| ) |
Once per frame, before the engine advances by simulatedSeconds: switches the active footballer when the rules say so and, if the engine is about to step, submits the device state as that step's input.
|
private |
|
private |
|
private |
Button being held for power, and the step it was pressed at.
|
staticconstexpr |
Seconds of simulated time to fill the power bar.
|
private |
|
private |
|
private |
|
private |
Simulated seconds since which the stick has been idle.
|
private |
Held state of each control from buttons (keys or pad) and presses and releases since the last update.
|
private |
Control each physical key is holding down (CONTROL_COUNT: none), so its release ends exactly what its press started.
|
private |
|
private |
Simulated seconds of the last switch, and of the last manual one with the player it left (so repeated presses cycle).
|
private |
|
private |
|
private |
|
private |
|
private |
Action (and its power) waiting for the next step's input.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |