载入中...
搜索中...
未找到
CombatCarrier.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
4
5
18#include "common/ECS.h"
19#include "common/Identity.h"
20#include "common/Result.h"
21#include "common/Time.h"
23
24#include <cstdint>
25#include <optional>
26#include <string>
27#include <vector>
28
29namespace eve::weapon {
30
47
49enum class CarrierTriggerKind : std::uint8_t {
50 OnExpire,
51 OnFuse,
53 OnHit,
57 OnApex
58};
59
61enum class CarrierImpactKind : std::uint8_t {
62 EmitHit,
63 Splash,
64 Pierce,
65 Bounce,
66 Release,
69};
70
74 double gravity = 0.0;
75 double maxTurnRateDegrees = 0.0;
76 double acceleration = 0.0;
78 double avoidLookAhead = 0.0;
80 double avoidStrength = 1.0;
82 double avoidRadiusPadding = 0.0;
84 double curveAmplitude = 0.0;
86 double curveFrequencyHz = 0.0;
88 ProjectileVector axis{0.0, 1.0, 0.0};
90 double angularRateDegrees = 0.0;
92 double orbitRadius = 1.0;
94 double drag = 0.0;
96 int randomSeed = 0;
98 double predictionSeconds = 1.0;
100 friend bool operator==(const CarrierMotionOp&, const CarrierMotionOp&) = default;
101};
102
114
136
147 double speed = 0.0;
148 std::vector<CarrierMotionOp> motionOps;
149 std::vector<CarrierTrigger> triggers;
150 std::vector<CarrierImpact> impacts;
151
153 bool collisionEnabled = true;
157 bool physicsWorldSweep = false;
158
160 [[nodiscard]] Result<void> validate() const;
162 friend bool operator==(const CarrierRecipe&, const CarrierRecipe&) = default;
163};
164
167 std::uint32_t slot = 0;
168 std::uint32_t generation = 0;
169
171 friend bool operator==(const CarrierHandle&, const CarrierHandle&) = default;
172};
173
178 std::optional<ecs::EntityHandle> target;
179 ecs::EntityHandle source{};
180};
181
183enum class CarrierVolleyPattern : std::uint8_t {
184 Fan,
185 Ring
186};
187
199
205
215 std::optional<ecs::EntityHandle> target;
216 ecs::EntityHandle source{};
218 ProjectileVector heading{1.0, 0.0, 0.0};
222 std::optional<ProjectilePoint> previousTargetPosition;
223
225 double distanceTravelled = 0.0;
229 std::vector<ecs::EntityHandle> piercedTargets;
231 std::vector<eve::WorldSweepIdentity> piercedWorldBodies;
232};
233
253
260
263 std::vector<CarrierHandle> advanced;
264 std::vector<CarrierHandle> released;
265 std::vector<CarrierEvent> events;
266 std::vector<CarrierChildSpawn> childSpawns;
267};
268
271 std::uint32_t generation = 0;
272 std::optional<CarrierState> state;
273};
274
282 std::uint32_t maxIterations = 256;
283 std::uint32_t maxCollisions = 64;
284 std::uint32_t maxTriggerFirings = 4096;
286 [[nodiscard]] EVENGINE_API_WORLD Result<void> validate() const;
288};
289
292 std::vector<CarrierSlotSnapshot> slots;
294 std::uint32_t schemaVersion = 4;
296 std::vector<CarrierRecipe> recipes;
298};
299
308public:
310 virtual ~ICarrierHitProbe() = default;
311
313 struct Contact {
314 ecs::EntityHandle target{};
316 ProjectileVector normal{0.0, 1.0, 0.0};
321 std::optional<double> fraction;
323 std::optional<eve::WorldSphereContact> worldContact;
324 };
325
331 const CarrierMotion& previous,
332 const CarrierMotion& current) const = 0;
333};
334
348
356public:
358 virtual ~ICarrierBodyDefenseProvider() = default;
359
365 CarrierHandle handle, ecs::EntityHandle target, const CarrierMotion& motion) const = 0;
366};
367
376 const ProjectileDefinition& definition, double damage = 0.0);
377
385public:
387 virtual ~ICarrierMotionFunction() = default;
395 [[nodiscard]] virtual Result<CarrierMotion> evaluate(const CarrierState& before, const CarrierMotion& proposed,
396 Duration step) const = 0;
397};
398
411public:
414
416 [[nodiscard]] Result<void> configurePool(std::uint32_t capacity);
417
423 [[nodiscard]] Result<void> configureSimulation(const CarrierSimulationSettings& settings);
424
430 [[nodiscard]] Result<void> registerRecipe(const CarrierRecipe& recipe);
431
433 [[nodiscard]] std::optional<CarrierRecipe> findRecipe(const LogicalId& id) const;
434
436 [[nodiscard]] Result<CarrierHandle> spawn(const LogicalId& recipeId, const CarrierSpawnRequest& request);
437
439 [[nodiscard]] Result<CarrierHandle> spawn(const CarrierRecipe& recipe, const CarrierSpawnRequest& request);
440
448 [[nodiscard]] Result<std::vector<CarrierHandle>> spawnVolley(const LogicalId& recipeId,
452 [[nodiscard]] Result<std::vector<CarrierHandle>> spawnVolley(const CarrierRecipe& recipe,
455
465 [[nodiscard]] Result<CarrierFrame> update(Duration delta, const IProjectileTargetProvider* targets = nullptr,
466 const ICarrierHitProbe* hits = nullptr,
467 const ICarrierBodyDefenseProvider* bodies = nullptr,
468 const ICarrierHitProbe* worldSweep = nullptr);
469
477 [[nodiscard]] Result<CarrierFrame> updateWithMotion(Duration delta, const ICarrierMotionFunction& motion,
478 const IProjectileTargetProvider* targets = nullptr,
479 const ICarrierHitProbe* hits = nullptr,
480 const ICarrierBodyDefenseProvider* bodies = nullptr,
481 const ICarrierHitProbe* worldSweep = nullptr);
482
484 [[nodiscard]] Result<void> release(CarrierHandle handle);
485
487 [[nodiscard]] std::optional<CarrierState> find(CarrierHandle handle) const;
488
490 [[nodiscard]] std::vector<CarrierState> states() const;
491
493 [[nodiscard]] CarrierRuntimeSnapshot snapshot() const;
494
496 [[nodiscard]] Result<void> restore(const CarrierRuntimeSnapshot& snapshot);
497
499 [[nodiscard]] std::size_t activeCount() const noexcept { return activeCount_; }
500
502 [[nodiscard]] std::size_t capacity() const noexcept { return slots_.size(); }
503
504private:
505 [[nodiscard]] Result<CarrierFrame> updateImpl(Duration delta, const IProjectileTargetProvider* targets,
506 const ICarrierHitProbe* hits,
507 const ICarrierBodyDefenseProvider* bodies,
508 const ICarrierMotionFunction* motion,
509 const ICarrierHitProbe* worldSweep);
510 bool updating_ = false;
511 CarrierSimulationSettings simulation_;
512 struct Slot {
513 std::uint32_t generation = 0;
514 std::optional<CarrierState> state;
515 };
516
517 struct LiveRecipe {
518 CarrierRecipe recipe;
519 int initialPierce = 0;
520 int initialBounce = 0;
521 bool needsHoming = false;
522 bool needsHit = false;
523 bool needsProximity = false;
524 bool needsBodyAvoid = false;
525 };
526
527 [[nodiscard]] Result<CarrierHandle> spawnPrepared(const LiveRecipe& live,
528 const CarrierSpawnRequest& request);
529 [[nodiscard]] static Result<LiveRecipe> prepareRecipe(const CarrierRecipe& recipe);
530 [[nodiscard]] static Result<void> validateSpawn(const CarrierRecipe& recipe,
531 const CarrierSpawnRequest& request);
532
533 std::vector<Slot> slots_;
534 std::vector<LiveRecipe> recipes_;
535 std::size_t activeCount_ = 0;
536};
537
538} // namespace eve::weapon
LogicalId target
std::vector< std::unique_ptr< ScriptClimbingEventSink > > live
Generation generation
Definition ECS.cpp:40
#define EVENGINE_API_WORLD
Definition Export.h:109
std::vector< FieldTarget > targets
const GltfImportRequest & request
std::uint32_t capacity
Strong identity values shared by persistence, content and logical-name APIs.
Snapshot snapshot
OceanWakeSettings settings
std::shared_ptr< const OceanSprayFrame > previous
BakeRecipe recipe
PrimitiveHandle handle
Deterministic pooled projectile simulation.
Move-only, checked operation results for the common layer.
double current
std::optional< CarrierVolleySpec > volley
Common time values and an injectable deterministic simulation clock.
float step
Definition TreeMesh.cpp:451
Signed, fixed-resolution simulation duration in nanoseconds.
Definition Time.h:43
static constexpr Duration zero() noexcept
Return zero duration.
Definition Time.h:60
Human-readable, scoped identifier in the form namespace:name.
Definition Identity.h:414
Move-only operation result carrying either a value or Status.
Definition Result.h:176
Owner-thread deterministic carrier simulator with composable behaviors.
std::size_t capacity() const noexcept
Current fixed pool capacity.
std::size_t activeCount() const noexcept
Number of live carriers.
Optional body/shield boundary for SteerAvoidBody.
virtual Result< std::vector< CarrierBodyDefenseSample > > sample(CarrierHandle handle, ecs::EntityHandle target, const CarrierMotion &motion) const =0
Sample body/shield volumes relevant to one carrier step.
virtual ~ICarrierBodyDefenseProvider()=default
Releases ICarrierBodyDefenseProvider resources.
Optional swept-hit boundary used only by OnHit triggers.
virtual Result< std::vector< Contact > > query(CarrierHandle handle, const CarrierMotion &previous, const CarrierMotion &current) const =0
Query contacts for one candidate step.
virtual ~ICarrierHitProbe()=default
Releases ICarrierHitProbe resources.
Synchronous custom motion strategy, invoked per proposed segment before collisions....
virtual Result< CarrierMotion > evaluate(const CarrierState &before, const CarrierMotion &proposed, Duration step) const =0
Return final position and velocity, or failure to abort the whole frame.
virtual ~ICarrierMotionFunction()=default
Destroy the caller-owned strategy.
Optional target-position boundary used only by homing projectiles.
载具模块入口(eve.Vehicle):定义注册 / 实体工厂 / RTS 命令 / 帧调度。 设计文档:docs/dev/通用载具系统设计.md
CarrierImpactKind
What happens when a matching trigger fires.
CarrierMotionOpKind
Ordered ballistic operators applied each simulation step.
Result< CarrierRecipe > carrierRecipeFromProjectile(const ProjectileDefinition &definition, double damage)
Build a default recipe matching a classic ProjectileDefinition mode.
CarrierTriggerKind
When an impact may fire.
CarrierVolleyPattern
Multi-projectile aim pattern for one salvo.
One body/shield sample used by SteerAvoidBody to curve around defenses.
Deferred child spawn recorded during update.
Owning event emitted by an impact.
ecs::EntityHandle target
Duration age
Carrier age at the event, including substep/contact timing.
std::optional< eve::WorldSphereContact > worldContact
Physics provenance, independent of an optional ECS gameplay target.
ecs::EntityHandle source
CarrierTriggerKind trigger
CarrierImpactKind impact
Owning result of one atomic carrier simulation step.
std::vector< CarrierEvent > events
std::vector< CarrierHandle > released
std::vector< CarrierChildSpawn > childSpawns
std::vector< CarrierHandle > advanced
Generation-qualified reference to one pooled carrier slot.
friend bool operator==(const CarrierHandle &, const CarrierHandle &)=default
Operator ==.
One impact bound to a trigger kind.
double bounceFriction
Bounce tangential velocity loss in [0,1]; restitution scales the remaining vector.
friend bool operator==(const CarrierImpact &, const CarrierImpact &)=default
Compare impact specifications.
int randomSeed
Nonnegative bounce random-stream seed, independent of wander streams.
double bounceSpreadDegrees
Seeded bounce cone half-angle in degrees [0,90]; zero is exact specular reflection.
One ballistic operator plus its parameters.
double drag
ApplyDrag exponential damping coefficient in inverse seconds (>=0).
double curveAmplitude
CurveSway/CurveHelix: lateral amplitude in meters (helix radius).
double avoidLookAhead
SteerAvoidBody: meters ahead at which a body counts as blocking.
double avoidRadiusPadding
SteerAvoidBody: extra meters added to each body radius.
double avoidStrength
SteerAvoidBody: blend weight of avoidance versus current velocity (≥0).
double curveFrequencyHz
CurveSway/CurveHelix: oscillation frequency in Hz (>0).
double angularRateDegrees
RotateVelocity/SteerOrbit signed angular rate in degrees/second.
int randomSeed
SteerWander deterministic stream seed; mixed with carrier slot/generation.
double predictionSeconds
SteerPredictive maximum extrapolation horizon in seconds (>0).
friend bool operator==(const CarrierMotionOp &, const CarrierMotionOp &)=default
Compare complete operator specifications, including stream identity.
CarrierMotionOpKind kind
double orbitRadius
SteerOrbit desired radius in simulation units (>0).
ProjectileVector axis
RotateVelocity/SteerOrbit axis; finite and nonzero.
Live motion snapshot for one carrier.
Data-driven composition recipe for one carrier family.
std::vector< CarrierTrigger > triggers
Result< void > validate() const
Validate finite parameters and composition constraints.
std::vector< CarrierMotionOp > motionOps
bool collisionEnabled
Master collision switch; disabled skips all OnHit queries and actions.
friend bool operator==(const CarrierRecipe &, const CarrierRecipe &)=default
Compare complete immutable recipe content.
std::vector< CarrierImpact > impacts
bool physicsWorldSweep
Select the optional physics-world probe instead of the ordinary hit probe. Inactive when collisionEna...
Complete deterministic carrier-pool state for rollback/save.
std::vector< CarrierSlotSnapshot > slots
std::uint32_t schemaVersion
Schema 4 adds generation-qualified pierced physics bodies; other versions are rejected.
CarrierSimulationSettings simulation
std::vector< CarrierRecipe > recipes
Owning recipe context; restore rejects missing or modified active recipes.
Bounded simulation work per carrier per outer update. Zero maxStep preserves caller-supplied fixed st...
EVENGINE_API_WORLD Result< void > validate() const
Validate finite work budgets and a nonnegative step duration.
friend bool operator==(const CarrierSimulationSettings &, const CarrierSimulationSettings &)=default
One pool slot including generation, retained while empty.
std::optional< CarrierState > state
std::optional< ecs::EntityHandle > target
Owning observable state for one live carrier.
ProjectileVector curveVelocity
Previous step's curve velocity contribution, removed before the next motion stack.
std::optional< ProjectilePoint > previousTargetPosition
Previous owning target sample; predictive steering never retains provider references.
ProjectileVector heading
Last nonzero heading, retained through a stop so speed operators can restart.
std::optional< ecs::EntityHandle > target
std::vector< ecs::EntityHandle > piercedTargets
Generation-qualified targets already pierced; a carrier damages each of these only once.
double distanceTravelled
Integrated path length; owned by this runtime and restored for trigger replay.
Duration previousTargetSampleAge
Age at the previous outer-update target sample, for variable-dt predictive steering.
ecs::EntityHandle source
std::vector< eve::WorldSweepIdentity > piercedWorldBodies
Physics contacts already pierced, using world/body generations rather than fabricated ECS IDs.
One trigger specification.
double threshold
OnDistance path length, or OnSpeedBelow speed threshold; positive.
friend bool operator==(const CarrierTrigger &, const CarrierTrigger &)=default
Compare trigger specifications.
Deterministic multi-direction spawn descriptor.
CarrierVolleyPattern pattern
Owning contact reported between previous and current motion.
std::optional< eve::WorldSphereContact > worldContact
Optional physics provenance; target stays empty unless a gameplay adapter maps it.
std::optional< double > fraction
Canonical normalized impact time in [0,1] along this swept segment. Legacy probes may omit it: compat...
Data-driven trajectory and lifetime definition.
Owning point in projectile simulation space.
Owning velocity or direction vector in projectile simulation space.