载入中...
搜索中...
未找到
VehicleTypes.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
16#include "common/ECS.h"
17#include "common/Revision.h"
19
20#include <cstdint>
21#include <memory>
22#include <ostream>
23#include <string>
24#include <vector>
25
26// 只持有指针,不需要完整类型;physics 开启时才包含对应头文件。
27namespace eve::physics {
28class Body;
29class Body3D;
30} // namespace eve::physics
31
32namespace eve::weapon {
33class WeaponMountEntity;
34} // namespace eve::weapon
35
36namespace eve::vehicle {
37
38class VehicleOrderQueueAdapter;
39class VehiclePhysicsBinding;
40
42enum class VehicleOrderType : uint8_t { Move, AttackMove, Attack, Stop, Hold };
43
53
55inline std::ostream& operator<<(std::ostream& stream, VehicleOrderType type) {
57 return stream << vehicleOrderTypeName(type);
58}
59
63 float x = 0.f;
64 float y = 0.f;
65 int targetId = 0;
66 float arriveRadius = 12.f;
67};
68
71 float throttle = 0.f; // -1..1
72 float steer = 0.f; // -1..1
73 float brake = 0.f; // 0..1
74 bool handbrake = false;
75 bool fire = false; // 武器座开火请求
76 float aimYaw = 0.f; // 武器座瞄准(度)
77 float aimPitch = 0.f;
78};
79
81struct ArmorZone {
82 std::string name;
83 float mult = 1.f;
84 std::string node;
85};
86
88struct MountDef {
89 std::string name;
90 std::string weapon; // weapon 模板 id
91 std::string type = "turret";
92 float yawMin = -180.f;
93 float yawMax = 180.f;
94 float pitchMin = -45.f;
95 float pitchMax = 45.f;
96 float rotSpeed = 0.f;
97 float firingArc = 0.f;
98 std::string aimMode = "auto"; // "auto" | "manual"
99};
100
104 float x = 0.f;
105 float y = 0.f;
106 float z = 0.f;
107 float radius = 0.3f;
108 float restLength = 0.4f; // 悬架静止长度
109 float stiffness = 60.f; // 弹簧刚度
110 float damping = 8.f; // 阻尼
111 bool drive = true;
112 bool steer = true;
113};
114
118 float maxTravel = 0.3f;
120 float driveForce = 2000.f;
122 float lateralGrip = 12.f;
123 std::vector<SuspensionWheel> wheels;
124};
125
127struct SeatDef {
128 std::string name = "passenger";
129 std::string driver = "player"; // IVehicleDriver 注册名
130 std::string cameraMode = "third"; // "first" | "third" | "orbit"
131 int mountIndex = -1; // 该座位控制的挂点下标(-1 = 无武器)
132};
133
136 std::string id;
137 std::string category = "vehicle";
139 std::string mobility = "kinematic";
140 float maxSpeed = 120.f; // 像素/秒
141 float accel = 80.f; // 像素/秒²
142 float turnRate = 90.f; // 度/秒
143 float radius = 16.f; // 选择/碰撞半径
144 float maxHealth = 100.f;
145 std::vector<ArmorZone> armorZones;
146 std::vector<MountDef> mounts;
148 std::vector<SeatDef> seats;
149 std::vector<std::string> tags;
150};
151
154
164
168 std::string vehicleId;
169 std::string defId;
170 std::string orderType;
171 float x = 0.f;
172 float y = 0.f;
173};
174
176class EVENGINE_API_DOMAINS VehicleEntity : public ecs::Entity {
177public:
179 ENTITY(VehicleEntity, ecs::Entity)
180
181
182 void release() override { ecs::DestroyEntity(this); }
183
185 struct Identity {
186 std::string id;
187 std::string defId;
188 std::string faction;
189 };
190
192 struct Definition {
193 const VehicleDefinition* def = nullptr;
195 std::shared_ptr<const VehicleDefinition> owned;
196 };
197
211
213 struct Input {
214 float throttle = 0.f;
215 float steer = 0.f;
216 float brake = 0.f;
217 bool handbrake = false;
218 bool fire = false;
219 float aimYaw = 0.f;
220 float aimPitch = 0.f;
221 };
222
224 struct Motion {
225 float x = 0.f;
226 float y = 0.f;
227 float heading = 0.f; // 度,0 = +X
228 float speed = 0.f; // 像素/秒
229 bool arrived = false;
230 };
231
233 struct Health {
234 float hp = 0.f;
235 float maxHp = 0.f;
236 };
237
248
257 std::vector<VehicleOrder> queue;
258 int current = -1;
259
260 std::unique_ptr<VehicleOrderQueueAdapter> adapter;
261
263 Orders();
267 Orders(const Orders& other);
269 Orders& operator=(const Orders& other);
271 Orders(Orders&&) noexcept;
273 Orders& operator=(Orders&&) noexcept;
274 };
275
277 struct MountSlot {
279 std::string aimMode = "auto"; // "auto" | "manual"
280 };
281
283 struct Mounts {
284 std::vector<MountSlot> list;
285 };
286
293 struct PhysicsBody {
294 std::shared_ptr<VehiclePhysicsBinding> binding;
295 std::string space; // "2d" | "3d" | ""
296 };
297
301 struct WheelState {
302 float prevCompression = 0.f;
303 bool grounded = false;
304 };
305 std::vector<WheelState> wheels;
306 };
307
309 struct SeatSlot {
310 std::string name;
311 std::string driver = "player";
312 std::string cameraMode = "third";
313 int mountIndex = -1;
314 int occupant = 0; // 玩家/实体 id,0 = 空
315 bool occupied = false;
316 };
317
319 struct Seats {
320 std::vector<SeatSlot> list;
323 };
324
326 struct Flags {
327 bool destroyed = false;
328 };
329
330 COMPONENT(Identity, identity)
331 COMPONENT(Definition, definition)
332 COMPONENT(DefinitionBinding, definitionBinding)
333 COMPONENT(Input, input)
334 COMPONENT(Motion, motion)
335 COMPONENT(Health, health)
336 COMPONENT(Attributes, attributes)
337 COMPONENT(Orders, orders)
338 COMPONENT(Mounts, mounts)
339 COMPONENT(PhysicsBody, physicsBody)
340 COMPONENT(SuspensionState, suspension)
341 COMPONENT(Seats, seats)
342 COMPONENT(Flags, stateFlags)
343
344
352 static VehicleEntity* createVehicle();
353};
354
357public:
358 static constexpr const char* capabilityName = "IVehicleDamageModifier";
359
361 virtual ~IVehicleDamageModifier() = default;
362
364 virtual float modifyDamage(VehicleEntity& v, float amount, const std::string& zone, int sourceId) = 0;
365};
366
367} // namespace eve::vehicle
bool & active
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
Owner-aware canonical attribute state shared by gameplay adapters.
Common identity and hot-reload contract for typed runtime instances.
std::uint64_t sourceId
EvpackChunkInput input
Definition Evpack.cpp:170
#define EVENGINE_API_DOMAINS
Definition Export.h:110
float v
std::uint64_t revision
std::function< eve::Result< void >()> release
Definition Procgen.cpp:86
Monotonic state revision for concurrency and change checks.
double current
bool occupied
LogicalId definition
V3 heading
Definition TreeMesh.cpp:292
Canonical selected-attribute storage with owner and revision checks.
static constexpr StrongUint64 zero() noexcept
Returns the zero value for this strong type.
伤害修饰器(游戏侧注册,多重监听,按优先级调用)。
virtual float modifyDamage(VehicleEntity &v, float amount, const std::string &zone, int sourceId)=0
返回修正后的伤害(默认原值;装甲区倍率在修饰器之后应用)。
virtual ~IVehicleDamageModifier()=default
Releases IVehicleDamageModifier resources.
载具实体:数据全部在组件里,行为在 VehicleSystem。
武器挂点实体:可持有武器并限制旋转(炮塔 / 机枪座 / 固定挂架)。
ReloadPolicy
Policy used when a live definition is replaced.
@ RebuildInstance
Let the consumer atomically construct a new state from the new definition.
Optional physics backend for vehicle mobility and body attach.
Definition Climbing.h:36
驾驶者接口与玩家控制状态。
const char * vehicleOrderTypeName(VehicleOrderType type)
命令类型的字符串名("move" | "attack_move" | ...)。
Definition Vehicle.cpp:79
std::ostream & operator<<(std::ostream &stream, VehicleOrderType type)
Writes the stable vehicle-order protocol name.
VehicleEventType
载具事件类型。
const char * vehicleEventTypeName(VehicleEventType type)
事件类型的字符串名。
Definition Vehicle.cpp:90
VehicleOrderType
RTS 命令类型。
载具模块入口(eve.Vehicle):定义注册 / 实体工厂 / RTS 命令 / 帧调度。 设计文档:docs/dev/通用载具系统设计.md
Canonical identity carried by every typed runtime instance.
装甲区(Phase 4 伤害管线使用;Phase 2 仅作为定义数据保留)。
武器挂点声明(载具模板的一部分)。
座位声明(载具模板的一部分,FPS 面)。
3D 悬架参数(车辆模板的一部分)。
float driveForce
驱动轮满油门牵引力(牛顿)。
float lateralGrip
侧向抓地系数(越大越不容易侧滑)。
float maxTravel
悬架最大行程(米)。
std::vector< SuspensionWheel > wheels
3D 悬架车轮配置(raycast 悬架用)。
float x
相对车体原点的局部偏移(米,+Y 向上)。
载具模板(registerVehiclesFromJson 注册,进程级注册表)。
std::vector< MountDef > mounts
std::string mobility
IVehicleMobility 注册名;默认 "kinematic"。
std::vector< std::string > tags
std::vector< ArmorZone > armorZones
std::vector< SeatDef > seats
Canonical selected combat attributes for this vehicle.
eve::attributes::AttributeProjection values
Canonical definition identity projected onto this ECS entity.
eve::definition::InstanceIdentity identity
模板指针(Vehicle 模块注册表持有,实体不拥有)。
std::shared_ptr< const VehicleDefinition > owned
Immutable projection owner used by typed adapters.
生命值(Phase 4 伤害管线增强)。
稳定实例 id / 模板 id / 阵营。
每帧输入(命令系统 / 驾驶者写入,移动模型消费)。
2D 运动状态(kinematic 直接持有;物理模式由 body 回写)。
一个挂点槽位:挂点实体 + 瞄准模式。
武器挂点槽位列表(不拥有挂点;weapon 模块管理生命周期)。
std::vector< MountSlot > list
Vehicle order lifecycle adapter and compatibility projection.
Orders(Orders &&) noexcept
Transfers the adapter and compatibility projection.
std::unique_ptr< VehicleOrderQueueAdapter > adapter
std::vector< VehicleOrder > queue
~Orders()
Releases the adapter-owned generic queue.
跨帧物理绑定;不透明实现持有 generation link 和弱 world 生命周期。
std::shared_ptr< VehiclePhysicsBinding > binding
座位槽位(运行时,与模板 seats 一一对应)。
座位列表(FPS 面)。
std::vector< SeatSlot > list
悬架运行时状态(与模板 wheels 一一对应)。
载具事件(帧缓存,脚本轮询)。
每帧驾驶输入(由 PlayerDriver / OrderSystem / 脚本写入)。
一条 Vehicle 领域命令(生命周期由 Vehicle order adapter 执行)。