Make thin wrappers non-copyable

This commit is contained in:
Marc Gilleron 2021-12-28 18:30:34 +00:00
parent 541af4a4ad
commit 35b7108d0b
5 changed files with 39 additions and 19 deletions

View File

@ -84,18 +84,6 @@ Ref<Mesh> DirectMeshInstance::get_mesh() const {
return _mesh;
}
// void DirectMeshInstance::set_use_baked_light(bool enable) {
// ERR_FAIL_COND(!_mesh_instance.is_valid());
// RenderingServer &vs = *RenderingServer::get_singleton();
// vs.instance_geometry_set_flag(_mesh_instance, RenderingServer::INSTANCE_FLAG_USE_BAKED_LIGHT, true);
// }
// void DirectMeshInstance::set_use_dynamic_gi(bool enable) {
// ERR_FAIL_COND(!_mesh_instance.is_valid());
// RenderingServer &vs = *RenderingServer::get_singleton();
// vs.instance_geometry_set_flag(_mesh_instance, RenderingServer::INSTANCE_FLAG_USE_DYNAMIC_GI, true);
// }
void DirectMeshInstance::set_gi_mode(GIMode mode) {
ERR_FAIL_COND(!_mesh_instance.is_valid());
RenderingServer &vs = *RenderingServer::get_singleton();
@ -123,3 +111,13 @@ void DirectMeshInstance::set_gi_mode(GIMode mode) {
vs.instance_geometry_set_flag(_mesh_instance, RenderingServer::INSTANCE_FLAG_USE_BAKED_LIGHT, baked_light);
vs.instance_geometry_set_flag(_mesh_instance, RenderingServer::INSTANCE_FLAG_USE_DYNAMIC_GI, dynamic_gi);
}
// void DirectMeshInstance::move_to(DirectMeshInstance &dst) {
// dst.destroy();
// dst._mesh_instance = _mesh_instance;
// dst._mesh = _mesh;
// _mesh_instance = RID();
// _mesh.unref();
// }

View File

@ -1,13 +1,14 @@
#ifndef DIRECT_MESH_INSTANCE_H
#define DIRECT_MESH_INSTANCE_H
#include "../non_copyable.h"
#include <core/templates/rid.h>
#include <scene/resources/mesh.h>
class World3D;
// Thin wrapper around VisualServer mesh instance API
class DirectMeshInstance {
class DirectMeshInstance : public zylann::NonCopyable {
public:
DirectMeshInstance();
~DirectMeshInstance();
@ -21,8 +22,6 @@ public:
void set_material_override(Ref<Material> material);
void set_visible(bool visible);
void set_cast_shadows_setting(RenderingServer::ShadowCastingSetting mode);
// void set_use_baked_light(bool enable);
// void set_use_dynamic_gi(bool enable);
// Convenience
enum GIMode { //
@ -36,6 +35,8 @@ public:
Ref<Mesh> get_mesh() const;
// void move_to(DirectMeshInstance &dst);
private:
RID _mesh_instance;
Ref<Mesh> _mesh;

View File

@ -2,6 +2,7 @@
#define DIRECT_MULTIMESH_INSTANCE_H
#include "../math/color8.h"
#include "../non_copyable.h"
#include "../span.h"
#include <core/templates/rid.h>
@ -10,7 +11,7 @@
class World3D;
// Thin wrapper around VisualServer multimesh instance API
class DirectMultiMeshInstance {
class DirectMultiMeshInstance : public zylann::NonCopyable {
public:
DirectMultiMeshInstance();
~DirectMultiMeshInstance();
@ -33,14 +34,16 @@ public:
Color8 color;
};
static void make_transform_and_color8_3d_bulk_array(Span<const TransformAndColor8> data, PackedFloat32Array &bulk_array);
static void make_transform_and_color8_3d_bulk_array(
Span<const TransformAndColor8> data, PackedFloat32Array &bulk_array);
struct TransformAndColor32 {
Transform3D transform;
Color color;
};
static void make_transform_and_color32_3d_bulk_array(Span<const TransformAndColor32> data, PackedFloat32Array &bulk_array);
static void make_transform_and_color32_3d_bulk_array(
Span<const TransformAndColor32> data, PackedFloat32Array &bulk_array);
private:
RID _multimesh_instance;

View File

@ -1,6 +1,7 @@
#ifndef DIRECT_STATIC_BODY_H
#define DIRECT_STATIC_BODY_H
#include "../non_copyable.h"
#include "direct_mesh_instance.h"
#include <core/templates/rid.h>
@ -9,7 +10,7 @@
class World3D;
// Thin wrapper around static body API
class DirectStaticBody {
class DirectStaticBody : public zylann::NonCopyable {
public:
DirectStaticBody();
~DirectStaticBody();

17
util/non_copyable.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef ZYLANN_NON_COPYABLE_H
#define ZYLANN_NON_COPYABLE_H
namespace zylann {
class NonCopyable {
protected:
NonCopyable() = default;
~NonCopyable() = default;
NonCopyable(NonCopyable const &) = delete;
void operator=(NonCopyable const &x) = delete;
};
} // namespace zylann
#endif // ZYLANN_NON_COPYABLE_H