The Battle for Wesnoth  1.19.0-dev
synced_checkup.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2024
3  by David White <dave@whitevine.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #include "synced_checkup.hpp"
17 #include "log.hpp"
18 #include "synced_user_choice.hpp"
19 
20 static lg::log_domain log_replay("replay");
21 #define DBG_REPLAY LOG_STREAM(debug, log_replay)
22 #define LOG_REPLAY LOG_STREAM(info, log_replay)
23 #define WRN_REPLAY LOG_STREAM(warn, log_replay)
24 #define ERR_REPLAY LOG_STREAM(err, log_replay)
25 
27 
29 
31 {
32 }
33 
35 {
36 
37 }
38 
40 {
41 }
42 
44 {
45 }
46 
47 bool ignored_checkup::local_checkup(const config& /*expected_data*/, config& real_data)
48 {
49  assert(real_data.empty());
50  LOG_REPLAY << "ignored_checkup::local_checkup called";
51  return true;
52 }
53 
55  : buffer_(buffer), pos_(0)
56 {
57 }
58 
60 {
61 }
62 
63 bool synced_checkup::local_checkup(const config& expected_data, config& real_data)
64 {
65  assert(real_data.empty());
66  if(buffer_.child_count("result") > pos_)
67  {
68  //copying objects :o
69  real_data = buffer_.mandatory_child("result",pos_);
70  pos_ ++;
71  return real_data == expected_data;
72  }
73  else
74  {
75  assert(buffer_.child_count("result") == pos_);
76  buffer_.add_child("result", expected_data);
77  pos_++;
78  return true;
79  }
80 }
81 
82 
83 namespace
84 {
85  struct checkup_choice : public mp_sync::user_choice
86  {
87  checkup_choice(const config& cfg) : cfg_(cfg)
88  {
89  }
90  virtual ~checkup_choice()
91  {
92  }
93  virtual config random_choice(int /*side*/) const override
94  {
95  throw "not implemented";
96  }
97  virtual bool is_visible() const override
98  {
99  return false;
100  }
101  virtual config query_user(int /*side*/) const override
102  {
103  return cfg_;
104  }
105  const config& cfg_;
106  };
107 }
108 
110 {
111 }
112 
114 {
115 }
116 
117 bool mp_debug_checkup::local_checkup(const config& expected_data, config& real_data)
118 {
119  assert(real_data.empty());
120  real_data = get_user_choice("mp_checkup", checkup_choice(expected_data));
121  return real_data == expected_data;
122 }
A class to check whether the results that were calculated in the replay match the results calculated ...
virtual ~checkup()
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:159
config & mandatory_child(config_key_type key, int n=0)
Returns the nth child with the given key, or throws an error if there is none.
Definition: config.cpp:367
std::size_t child_count(config_key_type key) const
Definition: config.cpp:297
bool empty() const
Definition: config.cpp:852
config & add_child(config_key_type key)
Definition: config.cpp:441
virtual ~ignored_checkup()
virtual bool local_checkup(const config &expected_data, config &real_data)
always returns true
virtual ~mp_debug_checkup()
virtual bool local_checkup(const config &expected_data, config &real_data)
Compares data to the results calculated during the original game.
synced_checkup(config &buffer)
unsigned int pos_
virtual bool local_checkup(const config &expected_data, config &real_data)
Compares data to the results calculated during the original game.
virtual ~synced_checkup()
Standard logging facilities (interface).
config get_user_choice(const std::string &name, const user_choice &uch, int side=0)
Interface for querying local choices.
virtual config query_user(int side) const =0
virtual bool is_visible() const
whether the choice is visible for the user like an advancement choice a non-visible choice is for exa...
virtual config random_choice(int side) const =0
checkup * checkup_instance
static lg::log_domain log_replay("replay")
#define LOG_REPLAY
static ignored_checkup default_instnce