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
4 changes: 2 additions & 2 deletions engine/includes/components/actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ class ENGINE_EXPORT Actor : public Object {
Prefab *prefab() const;
void setPrefab(Prefab *prefab);

Object *clone(Object *parent = nullptr) override;

private:
Object *cloneStructure(Object::ObjectPairs &pairs) override;

void loadObjectData(const VariantMap &data) override;

void loadUserData(const VariantMap &data) override;
Expand Down
4 changes: 2 additions & 2 deletions engine/includes/components/component.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ class ENGINE_EXPORT Component : public Object {
void loadUserData(const VariantMap &data) override;
VariantMap saveUserData() const override;

virtual void onReferenceDestroyed();

private:
bool isSerializable() const override;

virtual void onReferenceDestroyed();

private:
bool m_enable;

Expand Down
6 changes: 5 additions & 1 deletion engine/includes/resources/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ class ENGINE_EXPORT Resource : public Object {
private:
friend class ResourceSystem;

std::list<std::pair<Resource::ResourceUpdatedCallback, void *>> m_observers;
typedef std::list<std::pair<Resource::ResourceUpdatedCallback, void *>> Callbacks;

Callbacks m_observers;
Callbacks m_toSubscribe;
std::list<void *> m_toUnsubscribe;

State m_state;
State m_last;
Expand Down
57 changes: 14 additions & 43 deletions engine/src/components/actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ bool Actor::isSerializable() const {
/*!
\internal
*/
Object *Actor::clone(Object *parent) {
Object *Actor::cloneStructure(ObjectPairs &pairs) {
PROFILE_FUNCTION();
Actor *result = static_cast<Actor *>(Object::clone(parent));
Actor *result = static_cast<Actor *>(Object::cloneStructure(pairs));
Prefab *prefab = dynamic_cast<Prefab *>(Object::parent());
if(prefab) {
result->setPrefab(prefab);
Expand Down Expand Up @@ -638,7 +638,6 @@ VariantMap Actor::saveUserData() const {
if(!prop.empty()) {
list.push_back(VariantList({static_cast<int32_t>(cloned), prop}));
}

}

fixed.push_back(VariantList({cloned, it->uuid()}));
Expand Down Expand Up @@ -692,19 +691,21 @@ void Actor::prefabUpdated(int state, void *ptr) {
p->m_transform = nullptr;
Object::ObjectList prefabObjects;
Object::enumObjects(p->m_prefab->actor(), prefabObjects);
prefabObjects.pop_front();

Object::ObjectList deleteObjects;
Object::enumObjects(p, deleteObjects);
deleteObjects.pop_front();

std::list<std::pair<Object *, Object *>> array;
ObjectPairs pairs;

for(auto prefabObject : prefabObjects) {
bool create = true;
auto it = deleteObjects.begin();
while(it != deleteObjects.end()) {
Object *clone = *it;
if(prefabObject->uuid() == clone->clonedFrom()) {
array.push_back(std::make_pair(prefabObject, clone));
pairs.push_back(std::make_pair(prefabObject, clone));
it = deleteObjects.erase(it);
create = false;
break;
Expand All @@ -715,49 +716,19 @@ void Actor::prefabUpdated(int state, void *ptr) {
}
++it;
}
if(create) {
Object *parent = System::findObject(prefabObject->parent()->uuid(), p);
Object *result = prefabObject->clone(parent ? parent : p);

array.push_back(std::make_pair(prefabObject, result));
if(create) { // New object
static_cast<Actor *>(prefabObject)->cloneStructure(pairs);
}
}

for(auto it : array) {
const MetaObject *meta = it.first->metaObject();
for(int i = 0; i < meta->propertyCount(); i++) {
MetaProperty origin = meta->property(i);
MetaProperty target = it.second->metaObject()->property(i);
if(origin.isValid() && target.isValid()) {
Variant data = origin.read(it.first);
if(origin.type().flags() & MetaType::BASE_OBJECT) {
Object *ro = *(reinterpret_cast<Object **>(data.data()));

for(auto &item : array) {
if(item.first == ro) {
ro = item.second;
break;
}
}
Actor::syncProperties(p, pairs);

data = Variant(data.userType(), &ro);
}
target.write(it.second, data);
}
}

for(auto item : it.first->getReceivers()) {
MetaMethod signal = it.second->metaObject()->method(item.signal);
MetaMethod method = item.receiver->metaObject()->method(item.method);
Object::connect(it.second, (std::to_string(1) + signal.signature()).c_str(),
item.receiver, (std::to_string((method.type() == MetaMethod::Signal) ? 1 : 2) + method.signature()).c_str());
}
}

deleteObjects.reverse();
for(auto it : deleteObjects) {
delete it;
}
/// \todo Incomlete filter for new added and removed elements from prefab
//deleteObjects.reverse();
//for(auto it : deleteObjects) {
// delete it;
//}

p->loadUserData(p->m_data);
} break;
Expand Down
35 changes: 24 additions & 11 deletions engine/src/components/skinnedmeshrender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include "gizmos.h"

namespace {
const char *gArmature= "Armature";
const char *gMatrices = "skinMatrices";
const char *gArmature("Armature");
const char *gMatrices("skinMatrices");
}

/*!
Expand Down Expand Up @@ -68,10 +68,12 @@ void SkinnedMeshRender::setMaterial(Material *material) {
Renderable::setMaterial(material);

for(auto it : m_materials) {
if(it && m_armature) {
it->setTexture(gMatrices, m_armature->texture());
if(it) {
if(m_armature) {
it->setTexture(gMatrices, m_armature->texture());
}
it->setTransform(transform());
}
it->setTransform(transform());
}
}
/*!
Expand All @@ -84,12 +86,18 @@ Armature *SkinnedMeshRender::armature() const {
Attaches an \a armature skeleton.
*/
void SkinnedMeshRender::setArmature(Armature *armature) {
m_armature = armature;
if(m_armature) {
connect(m_armature, _SIGNAL(destroyed()), this, _SLOT(onReferenceDestroyed()));
for(auto it : m_materials) {
if(it) {
it->setTexture(gMatrices, m_armature->texture());
if(m_armature != armature) {
if(m_armature) {
disconnect(m_armature, _SIGNAL(destroyed()), this, _SLOT(onReferenceDestroyed()));
}

m_armature = armature;
if(m_armature) {
connect(m_armature, _SIGNAL(destroyed()), this, _SLOT(onReferenceDestroyed()));
for(auto it : m_materials) {
if(it) {
it->setTexture(gMatrices, m_armature->texture());
}
}
}
}
Expand All @@ -102,6 +110,9 @@ void SkinnedMeshRender::setMaterialsList(const std::list<Material *> &materials)

for(auto it : m_materials) {
if(it) {
if(m_armature) {
it->setTexture(gMatrices, m_armature->texture());
}
it->setTransform(transform());
}
}
Expand Down Expand Up @@ -135,6 +146,8 @@ VariantMap SkinnedMeshRender::saveUserData() const {
\internal
*/
void SkinnedMeshRender::onReferenceDestroyed() {
MeshRender::onReferenceDestroyed();

if(sender() == m_armature) {
setArmature(nullptr);
}
Expand Down
4 changes: 4 additions & 0 deletions engine/src/components/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ Transform *Transform::parentTransform() const {
In case of \a force flag provided as true, no recalculations of transform happen.
*/
void Transform::setParentTransform(Transform *parent, bool force) {
if(parent == this) {
return;
}

Vector3 p;
Vector3 e;
Vector3 s;
Expand Down
3 changes: 2 additions & 1 deletion engine/src/editor/converters/assimpconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ std::string pathTo(Object *root, Object *dst) {
}

void stabilizeUUID(Object *object) {
Engine::replaceUUID(object, hash_str(pathTo(nullptr, object)));
std::string path = pathTo(nullptr, object);
Engine::replaceUUID(object, hash_str(path));

for(auto it : object->getChildren()) {
stabilizeUUID(it);
Expand Down
36 changes: 23 additions & 13 deletions engine/src/resources/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,17 @@ Resource::~Resource() {
Increases reference count.
*/
void Resource::subscribe(ResourceUpdatedCallback callback, void *object) {
std::unique_lock<std::mutex> locker(m_mutex);
m_observers.push_back(std::make_pair(callback, object));
locker.unlock();
m_toSubscribe.push_back(std::make_pair(callback, object));

incRef();
}
/*!
Unsubscribes an \a object to stop handle resource status.
Decreases reference count.
*/
void Resource::unsubscribe(void *object) {
std::unique_lock<std::mutex> locker(m_mutex);
auto it = m_observers.begin();
while(it != m_observers.end()) {
if((it->second) == object) {
it = m_observers.erase(it);
} else {
++it;
}
}
locker.unlock();
m_toUnsubscribe.push_back(object);

decRef();
}
/*!
Expand Down Expand Up @@ -119,6 +110,25 @@ void Resource::notifyCurrentState() {
std::unique_lock<std::mutex> locker(m_mutex, std::defer_lock);

if(locker.try_lock()) {
if(!m_toSubscribe.empty()) {
for(auto it : m_toSubscribe) {
m_observers.push_back(it);
}
m_toSubscribe.clear();
}

for(auto object : m_toUnsubscribe) {
auto it = m_observers.begin();
while(it != m_observers.end()) {
if((it->second) == object) {
it = m_observers.erase(it);
} else {
++it;
}
}
}
m_toUnsubscribe.clear();

for(auto it : m_observers) {
(*it.first)(m_state, it.second);
}
Expand Down
6 changes: 4 additions & 2 deletions modules/renders/rendergl/src/resources/materialgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace {
const char *gParticle("Particle");

const char *gGeometry("Geometry");

const char *gSkinMatrices("skinMatrices");
};

void MaterialGL::loadUserData(const VariantMap &data) {
Expand Down Expand Up @@ -176,7 +178,7 @@ uint32_t MaterialGL::buildProgram(const std::vector<uint32_t> &shaders, uint16_t
uint8_t t = 0;

if(vertex == VertexSkinned) {
int32_t location = glGetUniformLocation(result, "skinMatrices");
int32_t location = glGetUniformLocation(result, gSkinMatrices);
if(location > -1) {
glUniform1i(location, t);
t++;
Expand Down Expand Up @@ -387,7 +389,7 @@ bool MaterialInstanceGL::bind(CommandBufferGL *buffer, uint32_t layer, uint32_t
uint8_t i = 0;

if(m_surfaceType == Material::Skinned) {
Texture *skinMatrices = texture("skinMatrices");
Texture *skinMatrices = texture(gSkinMatrices);

if(skinMatrices) {
glActiveTexture(GL_TEXTURE0 + i);
Expand Down
8 changes: 7 additions & 1 deletion thirdparty/next/inc/core/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class NEXT_LIBRARY_EXPORT Object {

typedef std::list<Object *> ObjectList;

typedef std::list<std::pair<Object *, Object *>> ObjectPairs;

typedef std::list<Link> LinkList;

public:
Expand All @@ -100,7 +102,7 @@ class NEXT_LIBRARY_EXPORT Object {
static const MetaObject *metaClass();
virtual const MetaObject *metaObject() const;

virtual Object *clone(Object *parent = nullptr);
Object *clone(Object *parent = nullptr);

Object *parent() const;

Expand Down Expand Up @@ -193,6 +195,10 @@ class NEXT_LIBRARY_EXPORT Object {
virtual VariantList saveData() const;
virtual VariantMap saveUserData() const;

virtual Object *cloneStructure(ObjectPairs &pairs);

static void syncProperties(Object *parent, ObjectPairs &pairs);

virtual void setType(const std::string &type);

virtual void processEvents();
Expand Down
Loading