Fixed automatic Ref<> to Variant conversions.

This commit is contained in:
Relintai 2023-12-31 19:57:59 +01:00
parent 96ae4a1f7e
commit bb7ebfe362
2 changed files with 70 additions and 3 deletions

View File

@ -2,8 +2,8 @@
#include "render_core/application.h"
#include "render_core/3rd_glad.h"
#include "core/memory.h"
#include "render_core/3rd_glad.h"
#include "render_core/mesh_utils.h"
void GameScene::event() {
@ -104,7 +104,6 @@ void GameScene::render() {
rot += 0.01;
Ref<Image> d = texture->get_data();
texture->create_from_image(d);
camera->bind();

View File

@ -7,8 +7,9 @@
/*************************************************************************/
#include "core/memory.h"
#include "object/object.h"
#include "core/safe_refcount.h"
#include "object/object.h"
#include "object/ref_ptr.h"
class Reference : public Object {
SFW_OBJECT(Reference, Object);
@ -169,6 +170,73 @@ public:
ref(memnew(T));
}
RefPtr get_ref_ptr() const {
RefPtr refptr;
Ref<Reference> *irr = reinterpret_cast<Ref<Reference> *>(refptr.get_data());
*irr = *this;
return refptr;
};
operator Variant() const {
return Variant(get_ref_ptr());
}
void operator=(const RefPtr &p_refptr) {
Ref<Reference> *irr = reinterpret_cast<Ref<Reference> *>(p_refptr.get_data());
Reference *refb = irr->ptr();
if (!refb) {
unref();
return;
}
Ref r;
r.reference = Object::cast_to<T>(refb);
ref(r);
r.reference = nullptr;
}
void operator=(const Variant &p_variant) {
RefPtr refptr = p_variant;
Ref<Reference> *irr = reinterpret_cast<Ref<Reference> *>(refptr.get_data());
Reference *refb = irr->ptr();
if (!refb) {
unref();
return;
}
Ref r;
r.reference = Object::cast_to<T>(refb);
ref(r);
r.reference = nullptr;
}
Ref(const Variant &p_variant) {
RefPtr refptr = p_variant;
Ref<Reference> *irr = reinterpret_cast<Ref<Reference> *>(refptr.get_data());
reference = nullptr;
Reference *refb = irr->ptr();
if (!refb) {
unref();
return;
}
Ref r;
r.reference = Object::cast_to<T>(refb);
ref(r);
r.reference = nullptr;
}
Ref(const RefPtr &p_refptr) {
Ref<Reference> *irr = reinterpret_cast<Ref<Reference> *>(p_refptr.get_data());
reference = nullptr;
Reference *refb = irr->ptr();
if (!refb) {
unref();
return;
}
Ref r;
r.reference = Object::cast_to<T>(refb);
ref(r);
r.reference = nullptr;
}
Ref() {
reference = nullptr;
}