1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// 
// File:   DebugPlot.h
// Author: thomas
//
// Created on 19. march 2008, 21:51
//

#ifndef _DebugPlot_H
#define _DebugPlot_H

#include <cstring>
#include <cmath>

#include <Tools/DataStructures/RingBuffer.h>
#include "Tools/Math/Vector2.h"

#include "Tools/Debug/DebugRequest.h"
#include "Tools/DataStructures/Serializer.h"
#include <DebugCommunication/DebugCommandExecutor.h>

class DebugPlot: public DebugCommandExecutor
{
public:
  static const int maxPlotBufferSize = 1024;
  typedef RingBuffer<Vector2d, maxPlotBufferSize> PlotStrokeBuffer;
  typedef std::map<std::string, PlotStrokeBuffer> PlotStrokesMap;

  void addPlot(const std::string& name, double x, double y) {
    plotStrokes[name].add(Vector2d(x,y));
  }

  const PlotStrokesMap& getPlots() const {
    return plotStrokes;
  }

  void clear() {
    for(PlotStrokesMap::iterator iter = plotStrokes.begin(); iter != plotStrokes.end(); ++iter) {
      iter->second.clear();
    }
  }
  
  virtual void executeDebugCommand(
      const std::string& command, const ArgumentMap& arguments,
      std::ostream &outstream);

private:
  PlotStrokesMap plotStrokes;
};

namespace naoth
{
template<>
class Serializer<DebugPlot>
{
  public:
  static void serialize(const DebugPlot& object, std::ostream& stream);<--- Function 'serialize' argument 1 names different: declaration 'object' definition 'r'.
  static void deserialize(std::istream& stream, DebugPlot& object);
};
}

#ifdef DEBUG
/** Debug output stream, usage like "DOUT("ball_pos:" << x << ", " << y */
// HACK: std::isfinite doen't work for integral types in VS2013
#define PLOT_GENERIC(id,x,y) { ASSERT(std::isfinite(static_cast<double>(x))); ASSERT(std::isfinite(static_cast<double>(y))); getDebugPlot().addPlot(id,x,y); } ((void)0)
#define PLOT(id,value) DEBUG_REQUEST_SLOPPY(std::string("Plot:")+std::string(id), PLOT_GENERIC(id, getFrameInfo().getTime() ,value); )
#else
/* ((void)0) - that's a do-nothing statement */
#define PLOT_GENERIC(id,x,y) ((void)0)
#define PLOT(id,value) ((void)0)
#endif //DEBUG

#endif  /* _DebugBufferedOutput_H */