The Battle for Wesnoth  1.15.12+dev
plugin_executor.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017-2018 by the Battle for Wesnoth Project https://www.wesnoth.org/
3 
4  This program 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  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY.
10 
11  See the COPYING file for more details.
12 */
13 
14 #pragma once
15 
16 #include "gui/core/timer.hpp"
17 #include "gui/widgets/window.hpp"
20 #include "game_config.hpp"
21 #include <memory>
22 
23 namespace gui2::dialogs
24 {
25 
27 {
28  std::size_t timer_id;
29 
30  void play_slice() {
31  if(plugins_context_) {
32  plugins_context_->play_slice();
33  }
34  }
35 protected:
36  std::unique_ptr<plugins_context> plugins_context_;
37 
38 protected:
40  : timer_id(0u)
41  {
42  if(plugins_manager::get()) {
43  timer_id = add_timer(game_config::lobby_network_timer, std::bind(&plugin_executor::play_slice, this), true);
44  }
45  }
46 
48  {
49  if(plugins_manager::get()) {
50  remove_timer(timer_id);
51  }
52  }
53 };
54 
55 } // namespace dialogs
This file contains the window object, this object is a top level container which has the event manage...
std::unique_ptr< plugins_context > plugins_context_
unsigned lobby_network_timer
Definition: game_config.cpp:86
Contains the gui2 timer routines.
std::size_t add_timer(const uint32_t interval, const std::function< void(std::size_t id)> &callback, const bool repeat)
Adds a new timer.
Definition: timer.cpp:126
static plugins_manager * get()
Definition: manager.cpp:58
bool remove_timer(const std::size_t id)
Removes a timer.
Definition: timer.cpp:167