Changeset - r25710:60c9c8536270
[Not reviewed]
master
0 2 0
Patric Stout - 3 years ago 2021-06-17 16:58:59
truebrain@openttd.org
Fix: thread safety issue during exiting the game (#9380)

_exit_game is read by the draw-thread to know when to exit, but
most of the time written by the game-thread.
2 files changed with 3 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/gfx.cpp
Show inline comments
 
@@ -32,25 +32,25 @@ byte _dirkeys;        ///< 1 = left, 2 =
 
bool _fullscreen;
 
byte _support8bpp;
 
CursorVars _cursor;
 
bool _ctrl_pressed;   ///< Is Ctrl pressed?
 
bool _shift_pressed;  ///< Is Shift pressed?
 
uint16 _game_speed = 100; ///< Current game-speed; 100 is 1x, 0 is infinite.
 
bool _left_button_down;     ///< Is left mouse button pressed?
 
bool _left_button_clicked;  ///< Is left mouse button clicked?
 
bool _right_button_down;    ///< Is right mouse button pressed?
 
bool _right_button_clicked; ///< Is right mouse button clicked?
 
DrawPixelInfo _screen;
 
bool _screen_disable_anim = false;   ///< Disable palette animation (important for 32bpp-anim blitter during giant screenshot)
 
bool _exit_game;
 
std::atomic<bool> _exit_game;
 
GameMode _game_mode;
 
SwitchMode _switch_mode;  ///< The next mainloop command.
 
PauseMode _pause_mode;
 
Palette _cur_palette;
 

	
 
static byte _stringwidth_table[FS_END][224]; ///< Cache containing width of often used characters. @see GetCharacterWidth()
 
DrawPixelInfo *_cur_dpi;
 
byte _colour_gradient[COLOUR_END][8];
 

	
 
static void GfxMainBlitterViewport(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub = nullptr, SpriteID sprite_id = SPR_CURSOR_MOUSE);
 
static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub = nullptr, SpriteID sprite_id = SPR_CURSOR_MOUSE, ZoomLevel zoom = ZOOM_LVL_NORMAL);
 

	
src/openttd.h
Show inline comments
 
/*
 
 * This file is part of OpenTTD.
 
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file openttd.h Some generic types. */
 

	
 
#ifndef OPENTTD_H
 
#define OPENTTD_H
 

	
 
#include <atomic>
 
#include "core/enum_type.hpp"
 

	
 
/** Mode which defines the state of the game. */
 
enum GameMode {
 
	GM_MENU,
 
	GM_NORMAL,
 
	GM_EDITOR,
 
	GM_BOOTSTRAP
 
};
 

	
 
/** Mode which defines what mode we're switching to. */
 
enum SwitchMode {
 
@@ -43,25 +44,25 @@ enum SwitchMode {
 
enum DisplayOptions {
 
	DO_SHOW_TOWN_NAMES     = 0, ///< Display town names.
 
	DO_SHOW_STATION_NAMES  = 1, ///< Display station names.
 
	DO_SHOW_SIGNS          = 2, ///< Display signs.
 
	DO_FULL_ANIMATION      = 3, ///< Perform palette animation.
 
	DO_FULL_DETAIL         = 5, ///< Also draw details of track and roads.
 
	DO_SHOW_WAYPOINT_NAMES = 6, ///< Display waypoint names.
 
	DO_SHOW_COMPETITOR_SIGNS = 7, ///< Display signs, station names and waypoint names of opponent companies. Buoys and oilrig-stations are always shown, even if this option is turned off.
 
};
 

	
 
extern GameMode _game_mode;
 
extern SwitchMode _switch_mode;
 
extern bool _exit_game;
 
extern std::atomic<bool> _exit_game;
 
extern bool _save_config;
 

	
 
/** Modes of pausing we've got */
 
enum PauseMode : byte {
 
	PM_UNPAUSED              = 0,      ///< A normal unpaused game
 
	PM_PAUSED_NORMAL         = 1 << 0, ///< A game normally paused
 
	PM_PAUSED_SAVELOAD       = 1 << 1, ///< A game paused for saving/loading
 
	PM_PAUSED_JOIN           = 1 << 2, ///< A game paused for 'pause_on_join'
 
	PM_PAUSED_ERROR          = 1 << 3, ///< A game paused because a (critical) error
 
	PM_PAUSED_ACTIVE_CLIENTS = 1 << 4, ///< A game paused for 'min_active_clients'
 
	PM_PAUSED_GAME_SCRIPT    = 1 << 5, ///< A game paused by a game script
 
	PM_PAUSED_LINK_GRAPH     = 1 << 6, ///< A game paused due to the link graph schedule lagging
0 comments (0 inline, 0 general)