载入中...
搜索中...
未找到
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;
124 float wheelInertia = .01f;
126 float tireFriction = 1.f, longitudinalStiffness = 10000.f, corneringStiffness = 10000.f;
128 float rollingResistance = .015f, brakeTorque = 1000.f;
130 float maxSteerAngle = .6f;
135 std::vector<SuspensionWheel> wheels;
136};
137
139struct SeatDef {
140 std::string name = "passenger";
141 std::string driver = "player"; // IVehicleDriver 注册名
142 std::string cameraMode = "third"; // "first" | "third" | "orbit"
143 int mountIndex = -1; // 该座位控制的挂点下标(-1 = 无武器)
144};
145
148 std::string id;
149 std::string category = "vehicle";
151 std::string mobility = "kinematic";
152 float maxSpeed = 120.f; // 像素/秒
153 float accel = 80.f; // 像素/秒²
154 float turnRate = 90.f; // 度/秒
155 float radius = 16.f; // 选择/碰撞半径
156 float maxHealth = 100.f;
157 std::vector<ArmorZone> armorZones;
158 std::vector<MountDef> mounts;
160 std::vector<SeatDef> seats;
161 std::vector<std::string> tags;
162};
163
166
176
180 std::string vehicleId;
181 std::string defId;
182 std::string orderType;
183 float x = 0.f;
184 float y = 0.f;
185};
186
188class EVENGINE_API_DOMAINS VehicleEntity : public ecs::Entity {
189public:
191 ENTITY(VehicleEntity, ecs::Entity)
192
193
194 void release() override { ecs::DestroyEntity(this); }
195
197 struct Identity {
198 std::string id;
199 std::string defId;
200 std::string faction;
201 };
202
204 struct Definition {
205 const VehicleDefinition* def = nullptr;
207 std::shared_ptr<const VehicleDefinition> owned;
208 };
209
223
225 struct Input {
226 float throttle = 0.f;
227 float steer = 0.f;
228 float brake = 0.f;
229 bool handbrake = false;
230 bool fire = false;
231 float aimYaw = 0.f;
232 float aimPitch = 0.f;
233 };
234
236 struct Motion {
237 float x = 0.f;
238 float y = 0.f;
239 float heading = 0.f; // 度,0 = +X
240 float speed = 0.f; // 像素/秒
241 bool arrived = false;
242 };
243
245 struct Health {
246 float hp = 0.f;
247 float maxHp = 0.f;
248 };
249
260
269 std::vector<VehicleOrder> queue;
270 int current = -1;
271
272 std::unique_ptr<VehicleOrderQueueAdapter> adapter;
273
275 Orders();
279 Orders(const Orders& other);
281 Orders& operator=(const Orders& other);
283 Orders(Orders&&) noexcept;
285 Orders& operator=(Orders&&) noexcept;
286 };
287
289 struct MountSlot {
291 std::string aimMode = "auto"; // "auto" | "manual"
292 };
293
295 struct Mounts {
296 std::vector<MountSlot> list;
297 };
298
305 struct PhysicsBody {
306 std::shared_ptr<VehiclePhysicsBinding> binding;
307 std::string space; // "2d" | "3d" | ""
308 };
309
313 struct WheelState {
315 double angularVelocity = 0;
317 double longitudinalForce = 0, lateralForce = 0, normalLoad = 0, slipRatio = 0, slipAngle = 0;
318 float prevCompression = 0.f;
319 bool grounded = false;
320 };
321 std::vector<WheelState> wheels;
322 };
323
325 struct SeatSlot {
326 std::string name;
327 std::string driver = "player";
328 std::string cameraMode = "third";
329 int mountIndex = -1;
330 int occupant = 0; // 玩家/实体 id,0 = 空
331 bool occupied = false;
332 };
333
335 struct Seats {
336 std::vector<SeatSlot> list;
339 };
340
342 struct Flags {
343 bool destroyed = false;
344 };
345
346 COMPONENT(Identity, identity)
347 COMPONENT(Definition, definition)
348 COMPONENT(DefinitionBinding, definitionBinding)
349 COMPONENT(Input, input)
350 COMPONENT(Motion, motion)
351 COMPONENT(Health, health)
352 COMPONENT(Attributes, attributes)
353 COMPONENT(Orders, orders)
354 COMPONENT(Mounts, mounts)
355 COMPONENT(PhysicsBody, physicsBody)
356 COMPONENT(SuspensionState, suspension)
357 COMPONENT(Seats, seats)
358 COMPONENT(Flags, stateFlags)
359
360
368 static VehicleEntity* createVehicle();
369};
370
373public:
374 static constexpr const char* capabilityName = "IVehicleDamageModifier";
375
377 virtual ~IVehicleDamageModifier() = default;
378
380 virtual float modifyDamage(VehicleEntity& v, float amount, const std::string& zone, int sourceId) = 0;
381};
382
383} // namespace eve::vehicle
double y
double x
bool & active
Owner-aware canonical attribute state shared by gameplay adapters.
std::uint64_t revision
Common identity and hot-reload contract for typed runtime instances.
EnvironmentTest definition
std::uint64_t sourceId
EvpackChunkInput input
Definition Evpack.cpp:170
#define EVENGINE_API_DOMAINS
Definition Export.h:110
float angularVelocity
float normalLoad
float v
std::map< std::string, double > attributes
Monotonic state revision for concurrency and change checks.
double current
bool occupied
Definition Shadow.cpp:155
V3 heading
Definition TreeMesh.cpp:429
uint64_t identity
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:85
std::ostream & operator<<(std::ostream &stream, VehicleOrderType type)
Writes the stable vehicle-order protocol name.
VehicleEventType
载具事件类型。
const char * vehicleEventTypeName(VehicleEventType type)
事件类型的字符串名。
Definition Vehicle.cpp:96
VehicleOrderType
RTS 命令类型。
载具模块入口(eve.Vehicle):定义注册 / 实体工厂 / RTS 命令 / 帧调度。 设计文档:docs/dev/通用载具系统设计.md
Canonical identity carried by every typed runtime instance.
装甲区(Phase 4 伤害管线使用;Phase 2 仅作为定义数据保留)。
武器挂点声明(载具模板的一部分)。
座位声明(载具模板的一部分,FPS 面)。
Suspension and tire parameters owned by the immutable vehicle definition.
float tireFriction
Tire friction coefficient and longitudinal / cornering stiffness in N.
float supportAcceleration2D
Virtual support acceleration for top-down XY tires in m/s^2; zero means airborne. Independent of plan...
float driveForce
驱动轮满油门牵引力(牛顿)。
float lateralGrip
侧向抓地系数(越大越不容易侧滑)。
float rollingResistance
Rolling-resistance coefficient and maximum brake torque per wheel in Nm.
float maxSteerAngle
Steering wheel deflection limit in radians, in [0, 1.4].
float maxTravel
悬架最大行程(米)。
float wheelInertia
Tire inertia in kg*m^2; all wheels use this definition value.
std::vector< SuspensionWheel > wheels
Wheel mount for 3D ray suspension or 2D top-down tire contact.
float x
Local mount in meters: 3D uses +Y up; top-down 2D uses XY with z = 0.
载具模板(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
Completed wheel state in configured mount order, or the generated default layout order.
载具事件(帧缓存,脚本轮询)。
每帧驾驶输入(由 PlayerDriver / OrderSystem / 脚本写入)。
一条 Vehicle 领域命令(生命周期由 Vehicle order adapter 执行)。