SimpleAI
 All Classes Namespaces Files Functions Variables Typedefs Macros Groups Pages
AICharacterStaticMessage.h
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include "AIStubTypes.h"
7 #include <vector>
8 
9 namespace ai {
10 
12 private:
13  CharacterId _chrId;
14  const std::vector<AIStateNodeStatic>* _nodeStaticDataPtr;
15  std::vector<AIStateNodeStatic> _nodeStaticData;
16 public:
21  AICharacterStaticMessage(const CharacterId& id, const std::vector<AIStateNodeStatic>& nodeStaticData) :
22  IProtocolMessage(PROTO_CHARACTER_STATIC), _chrId(id), _nodeStaticDataPtr(&nodeStaticData) {
23  }
24 
25  explicit AICharacterStaticMessage(streamContainer& in) :
26  IProtocolMessage(PROTO_CHARACTER_STATIC), _nodeStaticDataPtr(nullptr) {
27  _chrId = readInt(in);
28  const std::size_t size = readInt(in);
29  _nodeStaticData.reserve(size);
30  for (std::size_t i = 0; i < size; ++i) {
31  const int32_t id = readInt(in);
32  const std::string& name = readString(in);
33  const std::string& type = readString(in);
34  const std::string& parameters = readString(in);
35  const std::string& conditionType = readString(in);
36  const std::string& conditionParameters = readString(in);
37  const AIStateNodeStatic staticData(id, name, type, parameters, conditionType, conditionParameters);
38  _nodeStaticData.push_back(staticData);
39  }
40  }
41 
42  void serialize(streamContainer& out) const override {
43  addByte(out, _id);
44  addInt(out, _chrId);
45  const std::size_t size = _nodeStaticDataPtr->size();
46  addInt(out, static_cast<int>(size));
47  for (std::size_t i = 0; i < size; ++i) {
48  addInt(out, (*_nodeStaticDataPtr)[i].getId());
49  addString(out, (*_nodeStaticDataPtr)[i].getName());
50  addString(out, (*_nodeStaticDataPtr)[i].getType());
51  addString(out, (*_nodeStaticDataPtr)[i].getParameters());
52  addString(out, (*_nodeStaticDataPtr)[i].getConditionType());
53  addString(out, (*_nodeStaticDataPtr)[i].getConditionParameters());
54  }
55  }
56 
57  inline const std::vector<AIStateNodeStatic>& getStaticNodeData() const {
58  if (_nodeStaticDataPtr)
59  return *_nodeStaticDataPtr;
60  return _nodeStaticData;
61  }
62 };
63 
64 }
A protocol message is used for the serialization of the ai states for remote debugging.
Definition: IProtocolMessage.h:60
Definition: AICharacterStaticMessage.h:11
AICharacterStaticMessage(const CharacterId &id, const std::vector< AIStateNodeStatic > &nodeStaticData)
Definition: AICharacterStaticMessage.h:21
Definition: AIStubTypes.h:48