载入中...
搜索中...
未找到
WorldHitProbe.cpp
浏览该文件的文档.
1// eve-hot-path
3
4#include <exception>
5#include <utility>
6#include "common/Diagnostic.h"
7
8namespace eve::weapon {
9WorldHitProbe::WorldHitProbe(std::unique_ptr<IWorldSphereSweep> sweep) : sweep_(std::move(sweep)) {}
10WorldHitProbe::WorldHitProbe(std::unique_ptr<IWorldSphereSweep> sweep, std::unique_ptr<IWorldHitTargetMapper> mapper)
11 : sweep_(std::move(sweep)), mapper_(std::move(mapper)) {}
12
14 const CarrierMotion& current) const {
15 using Output = Result<std::vector<Contact>>;
16 if (!sweep_)
17 return Output::failure(Diagnostic::error(DiagnosticCode::Unsupported, "No world sweep session", "worldSweep"));
18 auto hits = sweep_->query(previous.position.x, previous.position.y, previous.position.z, current.position.x,
19 current.position.y, current.position.z);
20 if (!hits) return Output::failure(hits.status());
21 std::vector<Contact> contacts;
22 contacts.reserve(hits.value().size());
23 for (const auto& hit : hits.value()) {
25 contact.point = {hit.x, hit.y, hit.z};
26 contact.normal = {hit.nx, hit.ny, hit.nz};
27 contact.fraction = hit.fraction;
29 if (mapper_) {
30 try {
31 auto mapped = mapper_->target(hit);
32 if (!mapped) return Output::failure(mapped.status());
33 if (mapped.value()) {
34 if (mapped.value()->id == 0 || mapped.value()->generation == 0)
35 return Output::failure(Diagnostic::error(
37 "Mapped target requires a non-null generation-qualified entity", "target"));
38 contact.target = *mapped.value();
39 }
40 } catch (const std::exception& error) {
41 return Output::failure(Diagnostic::error(DiagnosticCode::Failed, error.what(), "targetMapper"));
42 } catch (...) {
43 return Output::failure(
44 Diagnostic::error(DiagnosticCode::Failed, "World target mapper threw", "targetMapper"));
45 }
46 }
47 contacts.push_back(std::move(contact));
48 }
49 return Output::success(std::move(contacts));
50}
51} // namespace eve::weapon
Stable, structured diagnostics shared by engine modules.
std::shared_ptr< const OceanSprayFrame > previous
std::string error
Definition Package.cpp:174
bool hit
double current
Contact contact
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
WorldHitProbe(std::unique_ptr< IWorldSphereSweep > sweep)
Take ownership of an optional query session; no entity mapping is installed.
Result< std::vector< Contact > > query(CarrierHandle handle, const CarrierMotion &previous, const CarrierMotion &current) const override
Project physical contacts without applying damage or forces. @cost One sweep per proposed segment plu...
载具模块入口(eve.Vehicle):定义注册 / 实体工厂 / RTS 命令 / 帧调度。 设计文档:docs/dev/通用载具系统设计.md
Generation-qualified reference to one pooled carrier slot.
Live motion snapshot for one carrier.
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...