Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions engine/includes/components/baselight.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ class ENGINE_EXPORT BaseLight : public NativeBehaviour {

virtual void cleanDirty();

private:
void setSystem(ObjectSystem *system) override;

protected:
static std::vector<Quaternion> s_directions;

Expand Down
12 changes: 12 additions & 0 deletions engine/includes/components/component.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ class ENGINE_EXPORT Component : public Object {
A_METHOD(Component *, Component::component),
A_METHOD(Actor *, Component::instantiate),
A_METHOD(TString, Component::tr),
A_METHOD(void, Component::addTag),
A_METHOD(void, Component::removeTag),
A_METHOD(bool, Component::hasTag),
A_METHOD(void, Component::deleteLater),
A_SLOT(Component::onReferenceDestroyed)
)

public:
Component();
~Component();

Actor *actor() const;
Scene *scene() const;
Expand Down Expand Up @@ -57,13 +61,21 @@ class ENGINE_EXPORT Component : public Object {
TString tr(const TString &source);

void addTag(const TString &tag);
void addTagByHash(uint32_t hash);

void removeTag(const TString &tag);
void removeTagByHash(uint32_t hash);

bool hasTag(const TString &tag);
bool hasTagByHash(uint32_t hash);

virtual void composeComponent();

virtual void drawGizmos();
virtual void drawGizmosSelected();

void setParent(Object *parent, int32_t position = -1, bool force = false) override;

protected:
void loadUserData(const VariantMap &data) override;
VariantMap saveUserData() const override;
Expand Down
2 changes: 0 additions & 2 deletions engine/includes/components/postprocessvolume.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class ENGINE_EXPORT PostProcessVolume : public Component {
private:
void setProperty(const char *name, const Variant &value) override;

void setSystem(ObjectSystem *system) override;

void drawGizmos() override;

private:
Expand Down
3 changes: 0 additions & 3 deletions engine/includes/components/renderable.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ class ENGINE_EXPORT Renderable : public NativeBehaviour {

virtual void setMaterialsList(const std::list<Material *> &materials);

private:
void setSystem(ObjectSystem *system) override;

protected:
friend class PipelineContext;
friend class PipelineTask;
Expand Down
23 changes: 0 additions & 23 deletions engine/includes/systems/rendersystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#include "system.h"

class PipelineContext;
class Widget;
class BaseLight;
class Renderable;
class PostProcessVolume;

Expand All @@ -31,21 +29,6 @@ class ENGINE_EXPORT RenderSystem : public System {
PipelineContext *pipelineContext() const;
void setPipelineContext(PipelineContext *context);

void addRenderable(Renderable *renderable);
void removeRenderable(Renderable *renderable);

static std::list<Renderable *> &renderables();

void addLight(BaseLight *light);
void removeLight(BaseLight *light);

static std::list<BaseLight *> &lights();

void addPostProcessVolume(PostProcessVolume *volume);
void removePostProcessVolume(PostProcessVolume *volume);

static std::list<PostProcessVolume *> &postProcessVolumes();

#if defined(SHARED_DEFINE)
virtual QWindow *createRhiWindow(Viewport *viewport);
#endif
Expand All @@ -57,12 +40,6 @@ class ENGINE_EXPORT RenderSystem : public System {
static void *m_windowHandle;

private:
static int32_t m_registered;

static std::list<BaseLight *> m_lightComponents;
static std::list<Renderable *> m_renderableComponents;
static std::list<PostProcessVolume *> m_postProcessVolumes;

PipelineContext *m_pipelineContext;

bool m_frameDirty;
Expand Down
27 changes: 10 additions & 17 deletions engine/src/components/baselight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,20 @@ Matrix4 BaseLight::s_scale = Matrix4(Vector3(0.5f), Quaternion(), Vector3(0.5f))
*/

BaseLight::BaseLight() :
m_params(1.0f, 1.0f, 0.5f, 1.0f),
m_color(1.0f),
m_materialInstance(nullptr),
m_hash(0),
m_lod(0),
m_shadows(false),
m_dirty(true) {
m_params(1.0f, 1.0f, 0.5f, 1.0f),
m_color(1.0f),
m_materialInstance(nullptr),
m_hash(0),
m_lod(0),
m_shadows(false),
m_dirty(true) {

static uint32_t hash = Mathf::hashString("lights");
addTagByHash(hash);
}

BaseLight::~BaseLight() {
static_cast<RenderSystem *>(system())->removeLight(this);

}

/*!
Expand Down Expand Up @@ -219,15 +221,6 @@ void BaseLight::setParams(Vector4 &params) {
/*!
\internal
*/
void BaseLight::setSystem(ObjectSystem *system) {
Object::setSystem(system);

RenderSystem *render = static_cast<RenderSystem *>(system);
render->addLight(this);
}
/*!
\internal
*/
Vector4 BaseLight::gizmoColor() const {
return Vector4(1.0f, 1.0f, 0.5f, 1.0f);
}
69 changes: 58 additions & 11 deletions engine/src/components/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ Component::Component() :
m_enable(true) {

}

Component::~Component() {
Scene *scene = Component::scene();
if(scene) {
for(auto it : m_tags) {
scene->removeFromGroupByHash(this, it);
}
}
}

/*!
Returns an Actor which the Component is attached to.
*/
Expand Down Expand Up @@ -124,25 +134,38 @@ TString Component::tr(const TString &source) {
return Engine::translate(source);
}
/*!
Adds a \a tag for current component.
Adds \a tag for current component.
Automatically adds component to specific Scene group.
*/
void Component::addTag(const TString &tag) {
uint32_t hash = Mathf::hashString(tag);
auto it = std::find(m_tags.begin(), m_tags.end(), hash);
if(it == m_tags.end()) {
addTagByHash(Mathf::hashString(tag));
}
/*!
Adds a tag for current component by tag \a hash.
Automatically adds component to specific Scene group.
*/
void Component::addTagByHash(uint32_t hash) {
if(!hasTagByHash(hash)) {
m_tags.push_back(hash);

Scene *scene = Component::scene();
if(scene) {
scene->addToGroupByHash(this, hash);
}
}
}
/*!
Removes a \a tag for current component.
Removes \a tag for current component.
Automatically removes component from specific Scene group.
*/
void Component::removeTag(const TString &tag) {
uint32_t hash = Mathf::hashString(tag);
removeTagByHash(Mathf::hashString(tag));
}
/*!
Removes a tag for current component by tag \a hash.
Automatically removes component from specific Scene group.
*/
void Component::removeTagByHash(uint32_t hash) {
auto it = std::find(m_tags.begin(), m_tags.end(), hash);
if(it != m_tags.end()) {
m_tags.erase(it);
Expand All @@ -153,6 +176,18 @@ void Component::removeTag(const TString &tag) {
}
}
}
/*!
Returns true if component has a \a tag; otherwise returns false.
*/
bool Component::hasTag(const TString &tag) {
return hasTagByHash(Mathf::hashString(tag));
}
/*!
Returns true if component has a tag provided by its \a hash; otherwise returns false.
*/
bool Component::hasTagByHash(uint32_t hash) {
return std::find(m_tags.begin(), m_tags.end(), hash) != m_tags.end();
}
/*!
\internal
*/
Expand Down Expand Up @@ -320,6 +355,12 @@ VariantMap Component::saveUserData() const {
}
}
return result;
}
/*!
\internal
*/
void Component::onReferenceDestroyed() {

}
/*!
This method will be called automatically when \a current scene will be \a changed to a new one.
Expand All @@ -329,14 +370,20 @@ void Component::changeScene(Scene *current, Scene *changed) {
if(current) {
current->removeFromGroupByHash(this, it);
}
if(current) {
if(changed) {
changed->addToGroupByHash(this, it);
}
}
}
/*!
\internal
*/
void Component::onReferenceDestroyed() {

void Component::setParent(Object *parent, int32_t position, bool force) {
Scene *currentScene = Component::scene();

Object::setParent(parent, position, force);

Scene *changedScene = Component::scene();

if(currentScene != changedScene) {
changeScene(currentScene, changedScene);
}
}
13 changes: 4 additions & 9 deletions engine/src/components/postprocessvolume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ PostProcessVolume::PostProcessVolume() :
for(auto &it : m_settings->settings()) {
Object::setProperty(it.first.c_str(), it.second);
}

static uint32_t hash = Mathf::hashString("postProcess");
addTagByHash(hash);
}

PostProcessVolume::~PostProcessVolume() {
static_cast<RenderSystem *>(system())->removePostProcessVolume(this);

}
/*!
Returns the priority of volume in the list.
Expand Down Expand Up @@ -94,14 +97,6 @@ void PostProcessVolume::setProperty(const char *name, const Variant &value) {
/*!
\internal
*/
void PostProcessVolume::setSystem(ObjectSystem *system) {
Component::setSystem(system);

static_cast<RenderSystem *>(system)->addPostProcessVolume(this);
}
/*!
\internal
*/
void PostProcessVolume::drawGizmos() {
Transform *t = transform();

Expand Down
13 changes: 2 additions & 11 deletions engine/src/components/renderable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ Renderable::Renderable() :
m_lod(0),
m_transformHash(0) {

static uint32_t hash = Mathf::hashString("renderable");
addTagByHash(hash);
}

Renderable::~Renderable() {
static_cast<RenderSystem *>(system())->removeRenderable(this);

for(auto it : m_materials) {
delete it;
}
Expand Down Expand Up @@ -145,15 +145,6 @@ void Renderable::setMaterialsList(const std::list<Material *> &materials) {
AABBox Renderable::localBound() {
return AABBox();
}
/*!
\internal
*/
void Renderable::setSystem(ObjectSystem *system) {
Object::setSystem(system);

RenderSystem *render = static_cast<RenderSystem *>(system);
render->addRenderable(this);
}
/*!
Filters \a out an \a in renderable components by it's material \a layer.
*/
Expand Down
2 changes: 1 addition & 1 deletion engine/src/components/world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void World::addChild(Object *child, int32_t position) {
Scene *scene = dynamic_cast<Scene *>(child);
if(scene) {
auto it = std::find(m_scenes.begin(), m_scenes.end(), scene);
if(it != m_scenes.end()) {
if(it == m_scenes.end()) {
m_scenes.push_back(scene);
}
}
Expand Down
Loading
Loading