CARLA
 
载入中...
搜索中...
未找到
LibCarla/source/carla/rpc/ActorAttribute.h
浏览该文件的文档.
1// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7// 防止头文件重复包含
8#pragma once
9
10// 引入Carla的MsgPack相关头文件,用于序列化等操作
11#include "carla/MsgPack.h"
12// 引入ActorAttributeType相关头文件,可能定义了属性类型的枚举等内容
14// 引入String相关头文件,可能用于处理字符串相关操作
15#include "carla/rpc/String.h"
16
17// 引入标准库的vector容器头文件,用于存储一组元素,比如字符串列表等
18#include <vector>
19
20// 将carla::rpc::ActorAttributeType枚举类型添加到MsgPack序列化机制中,以便可以正确地对其进行序列化和反序列化操作
22
23// 如果是从UE4中包含此头文件(定义了相关宏来判断这种情况)
24#ifdef LIBCARLA_INCLUDED_FROM_UE4
25// 引入UE4相关宏启用的头文件,可能是为了适配UE4环境做一些前置处理
27// 引入ActorAttribute相关头文件,可能是UE4中对Actor属性定义的相关类
29// 引入UE4相关宏禁用的头文件,结束UE4相关特定处理
31#endif // LIBCARLA_INCLUDED_FROM_UE4
32
33// 定义在carla命名空间下的rpc子命名空间,用于组织相关的RPC(远程过程调用)相关的类和类型等
34namespace carla {
35namespace rpc {
36
37 // ActorAttribute类,用于表示Actor的属性相关信息
39 public:
40 // 默认构造函数,使用编译器自动生成的默认行为
41 ActorAttribute() = default;
42
43 // 表示属性的唯一标识符,通常是一个字符串,用于区分不同的属性
44 std::string id;
45
46 // 属性的类型,通过ActorAttributeType枚举来指定,初始化为ActorAttributeType::Int类型
48
49 // 属性的值,以字符串形式存储,具体的格式可能根据type来解析不同含义
50 std::string value;
51
52 // 推荐的属性值列表,比如对于某些属性可能有一组限定的可选值,就存储在这里
53 std::vector<std::string> recommended_values;
54
55 // 表示该属性是否可修改,初始值为true,表示默认是可修改的
56 bool is_modifiable = true;
57
58 // 是否限制属性值只能从推荐的值中选取,初始值为false,表示不限制
60
61#ifdef LIBCARLA_INCLUDED_FROM_UE4
62 // 从UE4中的FActorAttribute类型构造ActorAttribute对象的转换构造函数
63 // 用于将UE4中的相关属性结构转换为本类的对象,方便在不同环境下统一处理属性信息
65 : id(FromFString(Attribute.Id)),
66 type(static_cast<ActorAttributeType>(Attribute.Type)),
67 value(FromFString(Attribute.Value)),
68 is_modifiable(false) {}
69
70 // 从UE4中的FActorVariation类型构造ActorAttribute对象的转换构造函数
71 // 同样是进行不同环境下属性相关结构的转换,根据FActorVariation中的信息来初始化本类对象的各个成员
73 : id(FromFString(Variation.Id)),
74 type(static_cast<ActorAttributeType>(Variation.Type)),
76 restrict_to_recommended(Variation.bRestrictToRecommended) {
77 // 预留足够的空间,避免在后续插入元素时频繁重新分配内存,提高效率
78 recommended_values.reserve(Variation.RecommendedValues.Num());
79 for (const auto &Item : Variation.RecommendedValues) {
80 recommended_values.push_back(FromFString(Item));
81 }
82 if (!recommended_values.empty()) {
84 }
85 }
86#endif // LIBCARLA_INCLUDED_FROM_UE4
87
88 // 使用MsgPack的宏来定义如何对ActorAttribute类的对象进行序列化和反序列化操作
89 // 指定了按照id、type、value、recommended_values、is_modifiable、restrict_to_recommended这些成员的顺序进行处理
91 };
92
93 // ActorAttributeValue类,用于表示Actor属性的值相关信息(可能是简化版,只关注关键的属性标识、类型和值)
95 public:
96 // 默认构造函数,使用编译器自动生成的默认行为
98
99 // 从ActorAttribute对象构造ActorAttributeValue对象的构造函数
100 // 用于提取ActorAttribute中的关键信息(id、type、value)来初始化本对象
102 : id(attribute.id),
103 type(attribute.type),
104 value(attribute.value) {}
105
106 // 表示属性的唯一标识符,与ActorAttribute中的id对应,用于区分不同的属性
107 std::string id;
108
109 // 属性的类型,与ActorAttribute中的type对应,通过ActorAttributeType枚举来指定,初始化为ActorAttributeType::Int类型
111
112 // 属性的值,与ActorAttribute中的value对应,以字符串形式存储,具体的格式可能根据type来解析不同含义
113 std::string value;
114
115#ifdef LIBCARLA_INCLUDED_FROM_UE4
116 // 从UE4中的FActorAttribute类型构造ActorAttributeValue对象的转换构造函数
117 // 借助ActorAttribute的转换构造函数来实现从UE4相关类型到本类对象的转换
120
121 // 类型转换运算符重载,用于将ActorAttributeValue对象转换为UE4中的FActorAttribute类型
122 // 方便在需要的地方将本类对象作为UE4相关类型来使用,实现不同环境下类型的兼容
123 operator FActorAttribute() const {
124 FActorAttribute Attribute;
125 Attribute.Id = ToFString(id);
126 Attribute.Type = static_cast<EActorAttributeType>(type);
127 Attribute.Value = ToFString(value);
128 return Attribute;
129 }
130#endif // LIBCARLA_INCLUDED_FROM_UE4
131
132 // 使用MsgPack的宏来定义如何对ActorAttributeValue类的对象进行序列化和反序列化操作
133 // 指定了按照id、type、value这些成员的顺序进行处理
135 };
136
137} // namespace rpc
138} // namespace carla
return true
MSGPACK_ADD_ENUM(carla::rpc::ActorAttributeType)
EActorAttributeType
List of valid types for actor attributes.(角色属性有效类型的列表)
MSGPACK_DEFINE_ARRAY(id, type, value)
ActorAttribute(const FActorAttribute &Attribute)
MSGPACK_DEFINE_ARRAY(id, type, value, recommended_values, is_modifiable, restrict_to_recommended)
ActorAttribute(const FActorVariation &Variation)
CARLA模拟器的主命名空间。
Definition Carla.cpp:139
An actor attribute, may be an intrinsic (non-modifiable) attribute of the actor or an user-defined ac...