2020-04-15 02:03:56 +02:00
|
|
|
#pragma once
|
|
|
|
|
#include "MinimalEngine.h"
|
2020-05-05 01:51:13 +02:00
|
|
|
#include "Math/Transform.h"
|
2022-01-12 14:40:26 +01:00
|
|
|
#include "Scene/Util.h"
|
|
|
|
|
#include "ThreadPool.h"
|
2020-04-15 02:03:56 +02:00
|
|
|
|
|
|
|
|
namespace Seele
|
|
|
|
|
{
|
2021-04-01 16:40:14 +02:00
|
|
|
DECLARE_REF(Actor)
|
|
|
|
|
DECLARE_REF(Scene)
|
|
|
|
|
DECLARE_REF(Component)
|
2020-04-15 02:03:56 +02:00
|
|
|
class Component
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Component();
|
|
|
|
|
virtual ~Component();
|
2022-01-12 14:40:26 +01:00
|
|
|
void launchStart();
|
|
|
|
|
virtual void start() {};
|
|
|
|
|
Array<Job> launchTick(float deltaTime) const;
|
|
|
|
|
virtual Job tick(float deltaTime) const { co_return; }
|
|
|
|
|
Array<Job> launchUpdate();
|
|
|
|
|
virtual Job update() { co_return; }
|
2020-04-15 02:03:56 +02:00
|
|
|
PComponent getParent();
|
|
|
|
|
PActor getOwner();
|
2022-01-12 14:40:26 +01:00
|
|
|
const Array<PComponent>& getChildComponents();
|
2020-09-30 13:48:41 +02:00
|
|
|
void setParent(PComponent parent);
|
|
|
|
|
void setOwner(PActor owner);
|
2022-01-12 14:40:26 +01:00
|
|
|
void addChildComponent(PComponent component);
|
2020-05-05 01:51:13 +02:00
|
|
|
virtual void notifySceneAttach(PScene scene);
|
2020-04-15 02:03:56 +02:00
|
|
|
|
|
|
|
|
void setWorldLocation(Vector location);
|
|
|
|
|
void setWorldRotation(Vector rotation);
|
|
|
|
|
void setWorldRotation(Quaternion rotation);
|
|
|
|
|
void setWorldScale(Vector scale);
|
|
|
|
|
|
|
|
|
|
void setRelativeLocation(Vector location);
|
|
|
|
|
void setRelativeRotation(Vector rotation);
|
|
|
|
|
void setRelativeRotation(Quaternion rotation);
|
|
|
|
|
void setRelativeScale(Vector scale);
|
2020-05-05 01:51:13 +02:00
|
|
|
|
2020-04-15 02:03:56 +02:00
|
|
|
void addWorldTranslation(Vector translation);
|
|
|
|
|
void addWorldRotation(Vector rotation);
|
|
|
|
|
void addWorldRotation(Quaternion rotation);
|
|
|
|
|
|
|
|
|
|
Transform getTransform() const;
|
2020-05-05 01:51:13 +02:00
|
|
|
|
2022-01-12 14:40:26 +01:00
|
|
|
template<typename ComponentType>
|
|
|
|
|
RefPtr<ComponentType> getComponent()
|
|
|
|
|
{
|
|
|
|
|
return tryFindComponent<ComponentType>();
|
|
|
|
|
}
|
2020-04-15 02:03:56 +02:00
|
|
|
private:
|
2022-01-12 14:40:26 +01:00
|
|
|
template<typename ComponentType>
|
|
|
|
|
RefPtr<ComponentType> tryFindComponent()
|
|
|
|
|
{
|
|
|
|
|
for(auto child : children)
|
|
|
|
|
{
|
|
|
|
|
RefPtr<ComponentType> result = child.cast<ComponentType>();
|
|
|
|
|
if(result != nullptr)
|
|
|
|
|
{
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
result = parent->tryFindComponent<ComponentType>();
|
|
|
|
|
if(result != nullptr)
|
|
|
|
|
{
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2020-04-15 02:03:56 +02:00
|
|
|
void internalSetTransform(Vector newLocation, Quaternion newRotation);
|
|
|
|
|
void propagateTransformUpdate();
|
|
|
|
|
void updateComponentTransform(Quaternion relativeRotationQuat);
|
2020-05-05 01:51:13 +02:00
|
|
|
Quaternion getRelativeWorldRotation(Quaternion worldRotation);
|
|
|
|
|
void setRelativeLocationAndRotation(Vector newLocation, Quaternion newRotation);
|
|
|
|
|
uint8 bComponentTransformClean : 1;
|
2020-04-15 02:03:56 +02:00
|
|
|
Vector relativeLocation;
|
|
|
|
|
Vector relativeRotation;
|
|
|
|
|
Vector relativeScale;
|
|
|
|
|
Transform transform;
|
2020-05-05 01:51:13 +02:00
|
|
|
PScene owningScene;
|
2020-04-15 02:03:56 +02:00
|
|
|
PActor owner;
|
|
|
|
|
PComponent parent;
|
|
|
|
|
Array<PComponent> children;
|
2020-05-05 01:51:13 +02:00
|
|
|
friend class Actor;
|
2020-04-15 02:03:56 +02:00
|
|
|
};
|
|
|
|
|
DEFINE_REF(Component)
|
2020-05-05 01:51:13 +02:00
|
|
|
} // namespace Seele
|