-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCameraSystem.cpp
More file actions
116 lines (103 loc) · 4.6 KB
/
Copy pathCameraSystem.cpp
File metadata and controls
116 lines (103 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "CameraSystem.h"
#include "LifecycleTrace.h"
#include "CameraComponent.h"
#include "Entity.h"
#include "Scene.h"
#include <algorithm>
#include <limits>
void CameraComponent::OnAddedToScene()
{
Entity* owner = GetOwner();
Scene* scene = nullptr != owner ? owner->GetScene() : nullptr;
if (nullptr != scene) scene->Cameras().Register(this);
}
void CameraComponent::OnRemovingFromScene()
{
Entity* owner = GetOwner();
Scene* scene = nullptr != owner ? owner->GetScene() : nullptr;
if (nullptr != scene) scene->Cameras().Unregister(this);
}
void CameraSystem::Register(CameraComponent* camera)
{
if (nullptr == camera) return;
if (std::ranges::find(m_cameras, camera) != m_cameras.end()) return;
m_cameras.push_back(camera);
}
void CameraSystem::Unregister(CameraComponent* camera)
{
if (nullptr == camera) return;
// swap-and-pop — AnimatorSystem::Unregister와 같은 규약(단일 조밀 벡터라
// 순서 보존은 애초에 불필요하고, erase는 O(n) 시프트라 씬 전환마다 비용이
// 쌓인다).
for (size_t i = 0; i < m_cameras.size(); ++i)
{
if (m_cameras[i] != camera) continue;
m_cameras[i] = m_cameras.back();
m_cameras.pop_back();
return;
}
}
void CameraSystem::Update(float tick, const std::function<void()>& midTraversalProbe)
{
// 옛 Scene::RegistryTick이 공통으로 해주던 가드(owner 없음/파괴 표시/
// 비활성 스킵)를 이 시스템이 대신 적용한다 — CameraComponent가 더 이상
// m_schedule.UpdateList()를 거치지 않으므로 그 가드도 함께 옮겨왔다.
bool firedMidTraversalProbe = false;
for (CameraComponent* camera : m_cameras)
{
// 트랙 C·C2-0 — 순회 중 재진입 시험의 발화점(클래스 상단 "고유 사정 3"
// 참고). 루프에 진입한 첫 반복에서, 이 원소가 가드에 걸려 스킵되든
// 아니든 무조건 한 번 부른다 — 아래 가드 뒤에 두면 m_cameras[0]이
// 마침 비활성/파괴 표시인 프레임에는 이 창이 통째로 사라진다(순회
// 자체는 여전히 일어나는데도). m_cameras는 회귀 씬 4종 실측상 원소가
// 보통 1개뿐이라 "첫 원소 뒤 · 마지막 원소 전"을 문자 그대로 만족시킬
// 여지가 없다 — "순회 중"이라는 조건만 충족시키면 된다. 콜백이
// 비무장이면 bool 하나 읽고 끝나 나머지 반복의 비용은 없다.
if (!firedMidTraversalProbe)
{
firedMidTraversalProbe = true;
if (midTraversalProbe) midTraversalProbe();
}
if (nullptr == camera) continue;
Entity* owner = camera->GetOwner();
if (nullptr == owner || owner->IsDestroyMark()) continue;
Scene* ownerScene = owner->GetScene();
if (nullptr == ownerScene || &ownerScene->Cameras() != this) continue;
if (!camera->IsEnabled()) continue;
// 트랙 렌더 — 틱이 시스템으로 옮겨오면서 생명주기 트레이스의 발생지도
// 함께 옮긴다. 안 남기면 이관할수록 기준선의 커버리지가 조용히 준다
// (같은 문자열을 써야 대조가 성립하므로 Lifecycle::Trace::TypeNameOf
// 공용 함수를 쓴다).
LIFECYCLE_TRACE(Lifecycle::Phase::Update, Lifecycle::Trace::TypeNameOf(camera),
owner->m_name.ToString().c_str(), camera->GetInstanceID());
// 자세는 소비 시점에 Entity Transform에서 값으로 해석한다. 이 틱은 기존
// 생명주기 순서·재진입 시험의 발화점만 보존하며 공유 Camera를 갱신하지 않는다.
}
}
CameraComponent* CameraSystem::GetPrimaryCamera() const noexcept
{
CameraComponent* selectedPrimary = nullptr;
CameraComponent* selectedFallback = nullptr;
uint64_t primaryId = (std::numeric_limits<uint64_t>::max)();
uint64_t fallbackId = (std::numeric_limits<uint64_t>::max)();
for (CameraComponent* camera : m_cameras)
{
if (nullptr == camera || !camera->IsEnabled()) continue;
Entity* owner = camera->GetOwner();
if (nullptr == owner || owner->IsDestroyMark()) continue;
Scene* ownerScene = owner->GetScene();
if (nullptr == ownerScene || &ownerScene->Cameras() != this) continue;
const uint64_t instanceId = static_cast<uint64_t>(camera->GetInstanceID());
if (instanceId < fallbackId)
{
fallbackId = instanceId;
selectedFallback = camera;
}
if (camera->IsPrimary() && instanceId < primaryId)
{
primaryId = instanceId;
selectedPrimary = camera;
}
}
return nullptr != selectedPrimary ? selectedPrimary : selectedFallback;
}