|
|
@@ -14,9 +14,10 @@
|
|
|
Actor::Actor(Game* game)
|
|
|
:mState(EActive)
|
|
|
,mPosition(Vector3::Zero)
|
|
|
- , mRotation(Quaternion::Identity)
|
|
|
+ ,mRotation(Quaternion::Identity)
|
|
|
,mScale(1.0f)
|
|
|
,mGame(game)
|
|
|
+ ,mRecomputeWorldTransform(true)
|
|
|
{
|
|
|
mGame->AddActor(this);
|
|
|
}
|
|
|
@@ -36,8 +37,12 @@ void Actor::Update(float deltaTime)
|
|
|
{
|
|
|
if (mState == EActive)
|
|
|
{
|
|
|
+ ComputeWorldTransform();
|
|
|
+
|
|
|
UpdateComponents(deltaTime);
|
|
|
UpdateActor(deltaTime);
|
|
|
+
|
|
|
+ ComputeWorldTransform();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -53,20 +58,60 @@ void Actor::UpdateActor(float deltaTime)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
+void Actor::ProcessInput(const uint8_t* keyState)
|
|
|
+{
|
|
|
+ if (mState == EActive)
|
|
|
+ {
|
|
|
+ // First process input for components
|
|
|
+ for (auto comp : mComponents)
|
|
|
+ {
|
|
|
+ comp->ProcessInput(keyState);
|
|
|
+ }
|
|
|
+
|
|
|
+ ActorInput(keyState);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void Actor::ActorInput(const uint8_t* keyState)
|
|
|
+{
|
|
|
+}
|
|
|
+
|
|
|
void Actor::ComputeWorldTransform()
|
|
|
{
|
|
|
- // Scale, then rotate, then translate
|
|
|
- mWorldTransform = Matrix4::CreateScale(mScale);
|
|
|
- mWorldTransform *= Matrix4::CreateFromQuaternion(mRotation);
|
|
|
- mWorldTransform *= Matrix4::CreateTranslation(mPosition);
|
|
|
+ if (mRecomputeWorldTransform)
|
|
|
+ {
|
|
|
+ mRecomputeWorldTransform = false;
|
|
|
+ // Scale, then rotate, then translate
|
|
|
+ mWorldTransform = Matrix4::CreateScale(mScale);
|
|
|
+ mWorldTransform *= Matrix4::CreateFromQuaternion(mRotation);
|
|
|
+ mWorldTransform *= Matrix4::CreateTranslation(mPosition);
|
|
|
+
|
|
|
+ // Inform components world transform updated
|
|
|
+ for (auto comp : mComponents)
|
|
|
+ {
|
|
|
+ comp->OnUpdateWorldTransform();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void Actor::AddComponent(Component* component)
|
|
|
{
|
|
|
- mComponents.emplace_back(component);
|
|
|
- std::sort(mComponents.begin(), mComponents.end(), [](Component* a, Component* b) {
|
|
|
- return a->GetUpdateOrder() < b->GetUpdateOrder();
|
|
|
- });
|
|
|
+ // Find the insertion point in the sorted vector
|
|
|
+ // (The first element with a order higher than me)
|
|
|
+ int myOrder = component->GetUpdateOrder();
|
|
|
+ auto iter = mComponents.begin();
|
|
|
+ for (;
|
|
|
+ iter != mComponents.end();
|
|
|
+ ++iter)
|
|
|
+ {
|
|
|
+ if (myOrder < (*iter)->GetUpdateOrder())
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Inserts element before position of iterator
|
|
|
+ mComponents.insert(iter, component);
|
|
|
}
|
|
|
|
|
|
void Actor::RemoveComponent(Component* component)
|