(svn r22788) -Codechange: move modal progress related functions and variables to progress.cpp/h
This commit is contained in:
		| @@ -343,6 +343,7 @@ | |||||||
|     <ClCompile Include="..\src\order_backup.cpp" /> |     <ClCompile Include="..\src\order_backup.cpp" /> | ||||||
|     <ClCompile Include="..\src\os_timer.cpp" /> |     <ClCompile Include="..\src\os_timer.cpp" /> | ||||||
|     <ClCompile Include="..\src\pbs.cpp" /> |     <ClCompile Include="..\src\pbs.cpp" /> | ||||||
|  |     <ClCompile Include="..\src\progress.cpp" /> | ||||||
|     <ClCompile Include="..\src\rail.cpp" /> |     <ClCompile Include="..\src\rail.cpp" /> | ||||||
|     <ClCompile Include="..\src\rev.cpp" /> |     <ClCompile Include="..\src\rev.cpp" /> | ||||||
|     <ClCompile Include="..\src\road.cpp" /> |     <ClCompile Include="..\src\road.cpp" /> | ||||||
| @@ -514,6 +515,7 @@ | |||||||
|     <ClInclude Include="..\src\order_func.h" /> |     <ClInclude Include="..\src\order_func.h" /> | ||||||
|     <ClInclude Include="..\src\order_type.h" /> |     <ClInclude Include="..\src\order_type.h" /> | ||||||
|     <ClInclude Include="..\src\pbs.h" /> |     <ClInclude Include="..\src\pbs.h" /> | ||||||
|  |     <ClInclude Include="..\src\progress.h" /> | ||||||
|     <ClInclude Include="..\src\querystring_gui.h" /> |     <ClInclude Include="..\src\querystring_gui.h" /> | ||||||
|     <ClInclude Include="..\src\rail.h" /> |     <ClInclude Include="..\src\rail.h" /> | ||||||
|     <ClInclude Include="..\src\rail_gui.h" /> |     <ClInclude Include="..\src\rail_gui.h" /> | ||||||
|   | |||||||
| @@ -249,6 +249,9 @@ | |||||||
|     <ClCompile Include="..\src\pbs.cpp"> |     <ClCompile Include="..\src\pbs.cpp"> | ||||||
|       <Filter>Source Files</Filter> |       <Filter>Source Files</Filter> | ||||||
|     </ClCompile> |     </ClCompile> | ||||||
|  |     <ClCompile Include="..\src\progress.cpp"> | ||||||
|  |       <Filter>Source Files</Filter> | ||||||
|  |     </ClCompile> | ||||||
|     <ClCompile Include="..\src\rail.cpp"> |     <ClCompile Include="..\src\rail.cpp"> | ||||||
|       <Filter>Source Files</Filter> |       <Filter>Source Files</Filter> | ||||||
|     </ClCompile> |     </ClCompile> | ||||||
| @@ -762,6 +765,9 @@ | |||||||
|     <ClInclude Include="..\src\pbs.h"> |     <ClInclude Include="..\src\pbs.h"> | ||||||
|       <Filter>Header Files</Filter> |       <Filter>Header Files</Filter> | ||||||
|     </ClInclude> |     </ClInclude> | ||||||
|  |     <ClInclude Include="..\src\progress.h"> | ||||||
|  |       <Filter>Header Files</Filter> | ||||||
|  |     </ClInclude> | ||||||
|     <ClInclude Include="..\src\querystring_gui.h"> |     <ClInclude Include="..\src\querystring_gui.h"> | ||||||
|       <Filter>Header Files</Filter> |       <Filter>Header Files</Filter> | ||||||
|     </ClInclude> |     </ClInclude> | ||||||
|   | |||||||
| @@ -642,6 +642,10 @@ | |||||||
| 				RelativePath=".\..\src\pbs.cpp" | 				RelativePath=".\..\src\pbs.cpp" | ||||||
| 				> | 				> | ||||||
| 			</File> | 			</File> | ||||||
|  | 			<File | ||||||
|  | 				RelativePath=".\..\src\progress.cpp" | ||||||
|  | 				> | ||||||
|  | 			</File> | ||||||
| 			<File | 			<File | ||||||
| 				RelativePath=".\..\src\rail.cpp" | 				RelativePath=".\..\src\rail.cpp" | ||||||
| 				> | 				> | ||||||
| @@ -1330,6 +1334,10 @@ | |||||||
| 				RelativePath=".\..\src\pbs.h" | 				RelativePath=".\..\src\pbs.h" | ||||||
| 				> | 				> | ||||||
| 			</File> | 			</File> | ||||||
|  | 			<File | ||||||
|  | 				RelativePath=".\..\src\progress.h" | ||||||
|  | 				> | ||||||
|  | 			</File> | ||||||
| 			<File | 			<File | ||||||
| 				RelativePath=".\..\src\querystring_gui.h" | 				RelativePath=".\..\src\querystring_gui.h" | ||||||
| 				> | 				> | ||||||
|   | |||||||
| @@ -639,6 +639,10 @@ | |||||||
| 				RelativePath=".\..\src\pbs.cpp" | 				RelativePath=".\..\src\pbs.cpp" | ||||||
| 				> | 				> | ||||||
| 			</File> | 			</File> | ||||||
|  | 			<File | ||||||
|  | 				RelativePath=".\..\src\progress.cpp" | ||||||
|  | 				> | ||||||
|  | 			</File> | ||||||
| 			<File | 			<File | ||||||
| 				RelativePath=".\..\src\rail.cpp" | 				RelativePath=".\..\src\rail.cpp" | ||||||
| 				> | 				> | ||||||
| @@ -1327,6 +1331,10 @@ | |||||||
| 				RelativePath=".\..\src\pbs.h" | 				RelativePath=".\..\src\pbs.h" | ||||||
| 				> | 				> | ||||||
| 			</File> | 			</File> | ||||||
|  | 			<File | ||||||
|  | 				RelativePath=".\..\src\progress.h" | ||||||
|  | 				> | ||||||
|  | 			</File> | ||||||
| 			<File | 			<File | ||||||
| 				RelativePath=".\..\src\querystring_gui.h" | 				RelativePath=".\..\src\querystring_gui.h" | ||||||
| 				> | 				> | ||||||
|   | |||||||
| @@ -51,6 +51,7 @@ openttd.cpp | |||||||
| order_backup.cpp | order_backup.cpp | ||||||
| os_timer.cpp | os_timer.cpp | ||||||
| pbs.cpp | pbs.cpp | ||||||
|  | progress.cpp | ||||||
| rail.cpp | rail.cpp | ||||||
| rev.cpp | rev.cpp | ||||||
| road.cpp | road.cpp | ||||||
| @@ -247,6 +248,7 @@ order_base.h | |||||||
| order_func.h | order_func.h | ||||||
| order_type.h | order_type.h | ||||||
| pbs.h | pbs.h | ||||||
|  | progress.h | ||||||
| querystring_gui.h | querystring_gui.h | ||||||
| rail.h | rail.h | ||||||
| rail_gui.h | rail_gui.h | ||||||
|   | |||||||
| @@ -32,6 +32,7 @@ | |||||||
| #include "newgrf.h" | #include "newgrf.h" | ||||||
| #include "core/random_func.hpp" | #include "core/random_func.hpp" | ||||||
| #include "core/backup_type.hpp" | #include "core/backup_type.hpp" | ||||||
|  | #include "progress.h" | ||||||
|  |  | ||||||
| #include "table/sprites.h" | #include "table/sprites.h" | ||||||
|  |  | ||||||
| @@ -54,11 +55,6 @@ void InitializeGame(uint size_x, uint size_y, bool reset_date, bool reset_settin | |||||||
|  */ |  */ | ||||||
| GenWorldInfo _gw; | GenWorldInfo _gw; | ||||||
|  |  | ||||||
| /** Rights for the performing work. */ |  | ||||||
| ThreadMutex *_modal_progress_work_mutex = ThreadMutex::New(); |  | ||||||
| /** Rights for the painting. */ |  | ||||||
| ThreadMutex *_modal_progress_paint_mutex = ThreadMutex::New(); |  | ||||||
|  |  | ||||||
| /** Whether we are generating the map or not. */ | /** Whether we are generating the map or not. */ | ||||||
| bool _generating_world; | bool _generating_world; | ||||||
|  |  | ||||||
| @@ -82,7 +78,7 @@ static void CleanupGeneration() | |||||||
| 	if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE); | 	if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE); | ||||||
| 	/* Show all vital windows again, because we have hidden them */ | 	/* Show all vital windows again, because we have hidden them */ | ||||||
| 	if (_gw.threaded && _game_mode != GM_MENU) ShowVitalWindows(); | 	if (_gw.threaded && _game_mode != GM_MENU) ShowVitalWindows(); | ||||||
| 	_gw.active   = false; | 	SetModalProgress(false); | ||||||
| 	_gw.proc     = NULL; | 	_gw.proc     = NULL; | ||||||
| 	_gw.abortp   = NULL; | 	_gw.abortp   = NULL; | ||||||
| 	_gw.threaded = false; | 	_gw.threaded = false; | ||||||
| @@ -280,11 +276,11 @@ void HandleGeneratingWorldAbortion() | |||||||
|  */ |  */ | ||||||
| void GenerateWorld(GenWorldMode mode, uint size_x, uint size_y, bool reset_settings) | void GenerateWorld(GenWorldMode mode, uint size_x, uint size_y, bool reset_settings) | ||||||
| { | { | ||||||
| 	if (_gw.active) return; | 	if (HasModalProgress()) return; | ||||||
| 	_gw.mode   = mode; | 	_gw.mode   = mode; | ||||||
| 	_gw.size_x = size_x; | 	_gw.size_x = size_x; | ||||||
| 	_gw.size_y = size_y; | 	_gw.size_y = size_y; | ||||||
| 	_gw.active = true; | 	SetModalProgress(true); | ||||||
| 	_gw.abort  = false; | 	_gw.abort  = false; | ||||||
| 	_gw.abortp = NULL; | 	_gw.abortp = NULL; | ||||||
| 	_gw.lc     = _local_company; | 	_gw.lc     = _local_company; | ||||||
|   | |||||||
| @@ -23,7 +23,6 @@ enum LandscapeGenerator { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| static const uint GENERATE_NEW_SEED = UINT_MAX; ///< Create a new random seed | static const uint GENERATE_NEW_SEED = UINT_MAX; ///< Create a new random seed | ||||||
| static const uint MODAL_PROGRESS_REDRAW_TIMEOUT = 200; ///< Timeout between redraws |  | ||||||
|  |  | ||||||
| /** Modes for GenerateWorld */ | /** Modes for GenerateWorld */ | ||||||
| enum GenWorldMode { | enum GenWorldMode { | ||||||
| @@ -42,7 +41,6 @@ typedef void GWAbortProc(); ///< Called when genworld is aborted | |||||||
|  |  | ||||||
| /** Properties of current genworld process */ | /** Properties of current genworld process */ | ||||||
| struct GenWorldInfo { | struct GenWorldInfo { | ||||||
| 	bool active;           ///< Is generating world active |  | ||||||
| 	bool abort;            ///< Whether to abort the thread ASAP | 	bool abort;            ///< Whether to abort the thread ASAP | ||||||
| 	bool quit_thread;      ///< Do we want to quit the active thread | 	bool quit_thread;      ///< Do we want to quit the active thread | ||||||
| 	bool threaded;         ///< Whether we run _GenerateWorld threaded | 	bool threaded;         ///< Whether we run _GenerateWorld threaded | ||||||
| @@ -71,16 +69,6 @@ enum GenWorldProgress { | |||||||
| 	GWP_CLASS_COUNT | 	GWP_CLASS_COUNT | ||||||
| }; | }; | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * Check if we are currently in the process of generating a world. |  | ||||||
|  * @return are we generating world? |  | ||||||
|  */ |  | ||||||
| static inline bool HasModalProgress() |  | ||||||
| { |  | ||||||
| 	extern GenWorldInfo _gw; |  | ||||||
| 	return _gw.active; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| /* genworld.cpp */ | /* genworld.cpp */ | ||||||
| bool IsGenerateWorldThreaded(); | bool IsGenerateWorldThreaded(); | ||||||
| void GenerateWorldSetCallback(GWDoneProc *proc); | void GenerateWorldSetCallback(GWDoneProc *proc); | ||||||
| @@ -101,8 +89,6 @@ void StartNewGameWithoutGUI(uint seed); | |||||||
| void ShowCreateScenario(); | void ShowCreateScenario(); | ||||||
| void StartScenarioEditor(); | void StartScenarioEditor(); | ||||||
|  |  | ||||||
| extern class ThreadMutex *_modal_progress_work_mutex; |  | ||||||
| extern class ThreadMutex *_modal_progress_paint_mutex; |  | ||||||
| extern bool _generating_world; | extern bool _generating_world; | ||||||
|  |  | ||||||
| #endif /* GENWORLD_H */ | #endif /* GENWORLD_H */ | ||||||
|   | |||||||
| @@ -29,6 +29,7 @@ | |||||||
| #include "settings_func.h" | #include "settings_func.h" | ||||||
| #include "core/geometry_func.hpp" | #include "core/geometry_func.hpp" | ||||||
| #include "core/random_func.hpp" | #include "core/random_func.hpp" | ||||||
|  | #include "progress.h" | ||||||
|  |  | ||||||
| #include "table/strings.h" | #include "table/strings.h" | ||||||
| #include "table/sprites.h" | #include "table/sprites.h" | ||||||
|   | |||||||
| @@ -12,7 +12,7 @@ | |||||||
| #include "stdafx.h" | #include "stdafx.h" | ||||||
| #include "gfx_func.h" | #include "gfx_func.h" | ||||||
| #include "fontcache.h" | #include "fontcache.h" | ||||||
| #include "genworld.h" | #include "progress.h" | ||||||
| #include "zoom_func.h" | #include "zoom_func.h" | ||||||
| #include "blitter/factory.hpp" | #include "blitter/factory.hpp" | ||||||
| #include "video/video_driver.hpp" | #include "video/video_driver.hpp" | ||||||
|   | |||||||
| @@ -18,7 +18,7 @@ | |||||||
| #include "viewport_func.h" | #include "viewport_func.h" | ||||||
| #include "command_func.h" | #include "command_func.h" | ||||||
| #include "console_gui.h" | #include "console_gui.h" | ||||||
| #include "genworld.h" | #include "progress.h" | ||||||
| #include "transparency_gui.h" | #include "transparency_gui.h" | ||||||
| #include "map_func.h" | #include "map_func.h" | ||||||
| #include "sound_func.h" | #include "sound_func.h" | ||||||
|   | |||||||
| @@ -40,6 +40,7 @@ | |||||||
| #include "ai/ai_config.hpp" | #include "ai/ai_config.hpp" | ||||||
| #include "settings_func.h" | #include "settings_func.h" | ||||||
| #include "genworld.h" | #include "genworld.h" | ||||||
|  | #include "progress.h" | ||||||
| #include "group.h" | #include "group.h" | ||||||
| #include "strings_func.h" | #include "strings_func.h" | ||||||
| #include "date_func.h" | #include "date_func.h" | ||||||
|   | |||||||
							
								
								
									
										30
									
								
								src/progress.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								src/progress.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,30 @@ | |||||||
|  | /* $Id$ */ | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |  * 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 progress.cpp Functions for modal progress windows. */ | ||||||
|  |  | ||||||
|  | #include "stdafx.h" | ||||||
|  | #include "progress.h" | ||||||
|  | #include "thread/thread.h" | ||||||
|  |  | ||||||
|  | /** Are we in a modal progress or not? */ | ||||||
|  | bool _in_modal_progress = false; | ||||||
|  | /** Rights for the performing work. */ | ||||||
|  | ThreadMutex *_modal_progress_work_mutex = ThreadMutex::New(); | ||||||
|  | /** Rights for the painting. */ | ||||||
|  | ThreadMutex *_modal_progress_paint_mutex = ThreadMutex::New(); | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Set the modal progress state. | ||||||
|  |  * @param state The new state; are we modal or not? | ||||||
|  |  */ | ||||||
|  | void SetModalProgress(bool state) | ||||||
|  | { | ||||||
|  | 	_in_modal_progress = state; | ||||||
|  | } | ||||||
							
								
								
									
										36
									
								
								src/progress.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								src/progress.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,36 @@ | |||||||
|  | /* $Id$ */ | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |  * 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 progress.h Functions related to modal progress. */ | ||||||
|  |  | ||||||
|  | #ifndef PROGRESS_H | ||||||
|  | #define PROGRESS_H | ||||||
|  |  | ||||||
|  | static const uint MODAL_PROGRESS_REDRAW_TIMEOUT = 200; ///< Timeout between redraws | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Check if we are currently in a modal progress state. | ||||||
|  |  * @return Are we in the modal state? | ||||||
|  |  */ | ||||||
|  | static inline bool HasModalProgress() | ||||||
|  | { | ||||||
|  | 	extern bool _in_modal_progress; | ||||||
|  | 	return _in_modal_progress; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * Set the modal progress state. | ||||||
|  |  * @param state The new state; are we modal or not? | ||||||
|  |  */ | ||||||
|  | void SetModalProgress(bool state); | ||||||
|  |  | ||||||
|  | extern class ThreadMutex *_modal_progress_work_mutex; | ||||||
|  | extern class ThreadMutex *_modal_progress_paint_mutex; | ||||||
|  |  | ||||||
|  | #endif /* PROGRESS_H */ | ||||||
| @@ -19,7 +19,7 @@ | |||||||
| #include "../blitter/factory.hpp" | #include "../blitter/factory.hpp" | ||||||
| #include "../network/network.h" | #include "../network/network.h" | ||||||
| #include "../thread/thread.h" | #include "../thread/thread.h" | ||||||
| #include "../genworld.h" | #include "../progress.h" | ||||||
| #include "../core/random_func.hpp" | #include "../core/random_func.hpp" | ||||||
| #include "../core/math_func.hpp" | #include "../core/math_func.hpp" | ||||||
| #include "sdl_v.h" | #include "sdl_v.h" | ||||||
|   | |||||||
| @@ -17,6 +17,7 @@ | |||||||
| #include "console_gui.h" | #include "console_gui.h" | ||||||
| #include "viewport_func.h" | #include "viewport_func.h" | ||||||
| #include "genworld.h" | #include "genworld.h" | ||||||
|  | #include "progress.h" | ||||||
| #include "blitter/factory.hpp" | #include "blitter/factory.hpp" | ||||||
| #include "zoom_func.h" | #include "zoom_func.h" | ||||||
| #include "vehicle_base.h" | #include "vehicle_base.h" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 rubidium
					rubidium