The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
synced_checkup.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://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 #include "global.hpp"
15 #include "synced_checkup.hpp"
16 #include "log.hpp"
17 #include "replay.hpp"
18 #include "synced_user_choice.hpp"
19 #include "resources.hpp"
20 
21 static lg::log_domain log_replay("replay");
22 #define DBG_REPLAY LOG_STREAM(debug, log_replay)
23 #define LOG_REPLAY LOG_STREAM(info, log_replay)
24 #define WRN_REPLAY LOG_STREAM(warn, log_replay)
25 #define ERR_REPLAY LOG_STREAM(err, log_replay)
26 
28 
30 
32 {
33 }
34 
36 {
37 
38 }
39 
41 {
42 }
43 
45 {
46 }
47 
48 bool ignored_checkup::local_checkup(const config& /*expected_data*/, config& real_data)
49 {
50  assert(real_data.empty());
51  LOG_REPLAY << "ignored_checkup::local_checkup called\n";
52  return true;
53 }
54 
56  : buffer_(buffer), pos_(0)
57 {
58 }
59 
61 {
62 }
63 
64 bool synced_checkup::local_checkup(const config& expected_data, config& real_data)
65 {
66  assert(real_data.empty());
67  if(buffer_.child_count("result") > pos_)
68  {
69  //copying objects :o
70  real_data = buffer_.child("result",pos_);
71  pos_ ++;
72  return real_data == expected_data;
73  }
74  else
75  {
76  assert(buffer_.child_count("result") == pos_);
77  buffer_.add_child("result", expected_data);
78  pos_++;
79  return true;
80  }
81 }
82 
83 
84 namespace
85 {
86  struct checkup_choice : public mp_sync::user_choice
87  {
88  checkup_choice(const config& cfg) : cfg_(cfg)
89  {
90  }
91  virtual ~checkup_choice()
92  {
93  }
94  virtual config random_choice(int /*side*/) const override
95  {
96  throw "not implemented";
97  }
98  virtual bool is_visible() const override
99  {
100  return false;
101  }
102  virtual config query_user(int /*side*/) const override
103  {
104  return cfg_;
105  }
106  const config& cfg_;
107  };
108 }
109 
111 {
112 }
113 
115 {
116 }
117 
118 bool mp_debug_checkup::local_checkup(const config& expected_data, config& real_data)
119 {
120  assert(real_data.empty());
121  real_data = get_user_choice("mp_checkup", checkup_choice(expected_data));
122  return real_data == expected_data;
123 }
config get_user_choice(const std::string &name, const user_choice &uch, int side=0)
static lg::log_domain log_replay("replay")
Replay control code.
bool empty() const
Definition: config.cpp:1105
virtual config random_choice(int side) const =0
unsigned int pos_
static ignored_checkup default_instnce
virtual bool local_checkup(const config &expected_data, config &real_data)
Compares data to the results calculated during the original game.
virtual bool is_visible() const
whether the choice is visible for the user like an advacement choice a non-visible choice is for exam...
Interface for querying local choices.
config & add_child(const std::string &key)
Definition: config.cpp:743
virtual ~synced_checkup()
checkup * checkup_instance
virtual ~checkup()
virtual config query_user(int side) const =0
GLuint buffer
Definition: glew.h:1648
virtual bool local_checkup(const config &expected_data, config &real_data)
Compares data to the results calculated during the original game.
A class to check whether the results that were calculated in the replay match the results calculated ...
virtual ~ignored_checkup()
virtual bool local_checkup(const config &expected_data, config &real_data)
always returns true
unsigned child_count(const std::string &key) const
Definition: config.cpp:635
synced_checkup(config &buffer)
config & child(const std::string &key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
Definition: config.cpp:658
Standard logging facilities (interface).
#define LOG_REPLAY
virtual ~mp_debug_checkup()
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83