The Battle for Wesnoth  1.17.0-dev
plugin_executor.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017 - 2021
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #pragma once
16 
17 #include "gui/core/timer.hpp"
18 #include "gui/widgets/window.hpp"
21 #include "game_config.hpp"
22 #include <memory>
23 
24 namespace gui2::dialogs
25 {
26 
28 {
29  std::size_t timer_id;
30 
31  void play_slice() {
32  if(plugins_context_) {
33  plugins_context_->play_slice();
34  }
35  }
36 protected:
37  std::unique_ptr<plugins_context> plugins_context_;
38 
39 protected:
41  : timer_id(0u)
42  {
43  if(plugins_manager::get()) {
44  timer_id = add_timer(game_config::lobby_network_timer, std::bind(&plugin_executor::play_slice, this), true);
45  }
46  }
47 
49  {
50  if(plugins_manager::get()) {
51  remove_timer(timer_id);
52  }
53  }
54 };
55 
56 } // 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:88
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:127
static plugins_manager * get()
Definition: manager.cpp:59
bool remove_timer(const std::size_t id)
Removes a timer.
Definition: timer.cpp:168