|
OpenTTD Source 20260815-master-gdf55704e7d
|
Code for automatically following vehicles for a screensaver effect. More...
#include "screensaver.h"#include "stdafx.h"#include "core/random_func.hpp"#include "company_base.h"#include "timer/timer.h"#include "timer/timer_game_tick.h"#include "vehicle_base.h"#include "vehicle_func.h"#include "vehicle_type.h"#include "window_func.h"#include "window_gui.h"#include "safeguards.h"Go to the source code of this file.
Functions | |
| static const Vehicle * | PickRandomVehicle () |
| Selects a random vehicle of any type. | |
| static void | SwitchVehicle (bool exit_on_invalid=true) |
| Switches the current followed vehicle to a new random one. | |
| void | ExitScreensaverMode () |
| Exits "Screensaver Mode". | |
| void | ToggleScreensaverMode () |
| Enters or exits "Screensaver Mode". | |
Variables | |
| static const auto | _screensaver_check_interval = TimerGameTick::TPeriod(TimerGameTick::Priority::None, 128) |
| We use a fixed period for updating the screensaver's followed vehicle, stored in this variable. | |
| static std::unique_ptr< IntervalTimer< TimerGameTick > > | _switch_timer |
| The screensaver runs on an interval timer, stored in this pointer when it is running and freed when it is no longer in use. | |
Code for automatically following vehicles for a screensaver effect.
Definition in file screensaver.cpp.
| void ExitScreensaverMode | ( | ) |
Exits "Screensaver Mode".
This function always disables screensaver mode, which is useful for any automated actions that should exit the screensaver.
If the screensaver is not enabled, this function is a no-op.
Definition at line 150 of file screensaver.cpp.
References _switch_timer, GetMainWindow(), and Window::viewport.
Referenced by SwitchVehicle(), and ToggleScreensaverMode().
|
static |
Selects a random vehicle of any type.
This function can return nullptr if it cannot find any valid vehicles to pick from.
nullptr if there are no vehicles. Definition at line 33 of file screensaver.cpp.
References Begin, CompanyEnd, and IsCompanyBuildableVehicleType().
Referenced by SwitchVehicle().
|
static |
Switches the current followed vehicle to a new random one.
This is intended to be used as the callback of an IntervalTimer object to periodically update the main window's followed vehicle so that it rotates between randomly selected vehicles in a "screensaver" effect.
| exit_on_invalid | if true (the default) this function exits screensaver mode if following was cancelled |
Definition at line 76 of file screensaver.cpp.
References Chance16I(), ExitScreensaverMode(), GetMainWindow(), Menu, PickRandomVehicle(), and Window::viewport.
Referenced by ToggleScreensaverMode().
| void ToggleScreensaverMode | ( | ) |
Enters or exits "Screensaver Mode".
Screensaver mode is simply rotating the main window's followed vehicle every so often to show off a world full of moving trains, planes, boats, and automobiles.
If not activated, the function allocates a new IntervalTimer which fires every so often to pick new vehicles to follow. There is some randomness in this to keep things interesting.
If "Screensaver Mode" was previously activated, this instead deletes the aforementioned timer and stops following vehicles, returning the camera to the original position.
Definition at line 172 of file screensaver.cpp.
References _screensaver_check_interval, _switch_timer, ExitScreensaverMode(), and SwitchVehicle().
Referenced by MenuClickHelp().
|
static |
We use a fixed period for updating the screensaver's followed vehicle, stored in this variable.
Definition at line 131 of file screensaver.cpp.
Referenced by ToggleScreensaverMode().
|
static |
The screensaver runs on an interval timer, stored in this pointer when it is running and freed when it is no longer in use.
Definition at line 139 of file screensaver.cpp.
Referenced by ExitScreensaverMode(), and ToggleScreensaverMode().