2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
8 /** @file script_asyncmode.hpp Switch the script instance to Async Mode. */
10 #ifndef SCRIPT_ASYNCMODE_HPP
11 #define SCRIPT_ASYNCMODE_HPP
13 #include "script_object.hpp"
16 * Class to switch current mode to Async Mode.
17 * If you create an instance of this class, the mode will be switched to
18 * either Asynchronous or Non-Asynchronous mode.
19 * The original mode is stored and recovered from when ever the instance is destroyed.
20 * In Asynchronous mode all the commands you execute are queued for later execution. The
21 * system checks if it would be able to execute your requests, and returns what
22 * the cost would be. The actual cost and whether the command succeeded when the command
23 * is eventually executed may differ from what was reported to the script.
26 class ScriptAsyncMode
: public ScriptObject
{
28 ScriptAsyncModeProc
*last_mode
; ///< The previous mode we were in.
29 ScriptObject
*last_instance
; ///< The previous instance of the mode.
32 static bool AsyncModeProc();
33 static bool NonAsyncModeProc();
38 * The constructor wrapper from Squirrel.
40 ScriptAsyncMode(HSQUIRRELVM vm
);
43 * Creating instance of this class switches the build mode to Asynchronous or Non-Asynchronous (normal).
44 * @note When the instance is destroyed, it restores the mode that was
45 * current when the instance was created!
46 * @param asynchronous Whether the new mode should be Asynchronous, if true, or Non-Asynchronous, if false.
48 ScriptAsyncMode(bool asynchronous
);
49 #endif /* DOXYGEN_API */
52 * Destroying this instance resets the asynchronous mode to the mode it was
53 * in when the instance was created.
60 void FinalRelease() override
;
63 #endif /* SCRIPT_ASYNCMODE_HPP */