The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
playturn_network_adapter.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 - 2025
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 "config.hpp"
18#include <list>
19#include <functional>
20/*
21 The purpose if this class is to preprocess incoming network data, and provide a steam that always returns just one command/action at a time.
22 Especially we want each replay command in his own [turn].
23*/
25{
26public:
27 typedef std::function<bool(config&)> source_type;
28
31
32 //returns true on success.
33 //dst has to be empty before the call.
34 //after the call dst contains one child when returned true otherwise it's empty.
35 bool read(config& dst);
36 //returns false if there is still data in the internal buffer.
37 bool is_at_end() const;
38 void push_front(config&& cfg);
39private:
40 //reads data from the network stream.
41 void read_from_network();
42 //a function to receive data from the network.
44
45 // note: all of the following could be replaced by a simple std::list<config> if we would
46 // split incoming tags right after we rechived them from network_reader_ the reason
47 // why we currently don'T do that is for performance.
48
49 //this always contains one empty config because we want a valid value for next_.
50 std::list<config> data_;
51 //packages that the client could not process at that point.
52 std::list<config> data_front_;
53 //the position of the next to be received element in data_->front().
55 //if we are processing a [turn] with multiple [command] we want to split them.
56 //In this case next_command_num_ is the next to be processed turn into a command otherwise it's 0;
57 unsigned int next_command_num_;
58};
A config object defines a single node in a WML file, with access to child nodes.
Definition config.hpp:157
std::function< bool(config &)> source_type
config::all_children_iterator next_
Definitions for the interface to Wesnoth Markup Language (WML).
const config * cfg
rect dst
Location on the final composed sheet.