Line data Source code
1 : /* Copyright (C) 2025 Wildfire Games. 2 : * This file is part of 0 A.D. 3 : * 4 : * 0 A.D. is free software: you can redistribute it and/or modify 5 : * it under the terms of the GNU General Public License as published by 6 : * the Free Software Foundation, either version 2 of the License, or 7 : * (at your option) any later version. 8 : * 9 : * 0 A.D. is distributed in the hope that it will be useful, 10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 : * GNU General Public License for more details. 13 : * 14 : * You should have received a copy of the GNU General Public License 15 : * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 : */ 17 : 18 : #ifndef INCLUDED_ICMPCOMMANDQUEUE 19 : #define INCLUDED_ICMPCOMMANDQUEUE 20 : 21 : #include "simulation2/helpers/Player.h" 22 : #include "simulation2/system/Component.h" 23 : #include "simulation2/system/Interface.h" 24 : 25 : #include <js/TypeDecls.h> 26 : #include <js/Value.h> 27 : #include <vector> 28 : 29 : struct SimulationCommand; 30 : 31 : /** 32 : * Command queue, for sending orders to entities. 33 : * Each command is associated with a player ID (who triggered the command, in some sense) 34 : * and an arbitrary script value. 35 : * 36 : * Commands can be added to the local queue at any time, and will all be executed at the start 37 : * of the next turn. (This will typically be used by AI scripts.) 38 : * 39 : * Alternatively, commands can be sent to the networking system, and they will be executed 40 : * at the start of some later turn by all players simultaneously. (This will typically be 41 : * used for user inputs.) 42 : */ 43 10 : class ICmpCommandQueue : public IComponent 44 : { 45 : public: 46 : /** 47 : * Pushes a new command onto the local queue. @p cmd does not need to be rooted. 48 : */ 49 : virtual void PushLocalCommand(player_id_t player, JS::HandleValue cmd) = 0; 50 : 51 : /** 52 : * Send a command associated with the current player to the networking system. 53 : */ 54 : virtual void PostNetworkCommand(JS::HandleValue cmd) = 0; 55 : 56 : /** 57 : * Calls the ProcessCommand(player, cmd) global script function for each command in the 58 : * local queue and in @p commands, and empties the local queue. 59 : */ 60 : virtual void FlushTurn(const std::vector<SimulationCommand>& commands) = 0; 61 : 62 360 : DECLARE_INTERFACE_TYPE(CommandQueue) 63 : }; 64 : 65 : #endif // INCLUDED_ICMPCOMMANDQUEUE