[Bf-blender-cvs] [9121c80] object_nodes: Cleanup: Moved some classes out of the typedesc utility file.

Lukas Tönne noreply at git.blender.org
Wed Jan 6 11:50:20 CET 2016


Commit: 9121c804a71196cd6e39353b750d7c931ac59f59
Author: Lukas Tönne
Date:   Wed Jan 6 11:29:16 2016 +0100
Branches: object_nodes
https://developer.blender.org/rB9121c804a71196cd6e39353b750d7c931ac59f59

Cleanup: Moved some classes out of the typedesc utility file.

===================================================================

M	source/blender/blenvm/CMakeLists.txt
A	source/blender/blenvm/util/bvm_util_data_ptr.h
M	source/blender/blenvm/util/bvm_util_math.h
M	source/blender/blenvm/util/bvm_util_typedesc.h

===================================================================

diff --git a/source/blender/blenvm/CMakeLists.txt b/source/blender/blenvm/CMakeLists.txt
index fddccd5..2cb78d0 100644
--- a/source/blender/blenvm/CMakeLists.txt
+++ b/source/blender/blenvm/CMakeLists.txt
@@ -46,6 +46,7 @@ set(INC_SYS
 set(SRC
 	intern/bvm_api.cc
 
+	util/bvm_util_data_ptr.h
 	util/bvm_util_debug.h
 	util/bvm_util_hash.h
 	util/bvm_util_map.h
diff --git a/source/blender/blenvm/util/bvm_util_data_ptr.h b/source/blender/blenvm/util/bvm_util_data_ptr.h
new file mode 100644
index 0000000..2644ad3
--- /dev/null
+++ b/source/blender/blenvm/util/bvm_util_data_ptr.h
@@ -0,0 +1,203 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) Blender Foundation
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Lukas Toenne
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenvm/intern/bvm_type_data_ptr.h
+ *  \ingroup bvm
+ */
+
+#ifndef __BVM_TYPE_DATA_PTR_H__
+#define __BVM_TYPE_DATA_PTR_H__
+
+#include "MEM_guardedalloc.h"
+
+extern "C" {
+#include "BKE_DerivedMesh.h"
+#include "BKE_cdderivedmesh.h"
+}
+
+#include "bvm_util_math.h"
+
+namespace bvm {
+
+/* generic default deletor, using 'delete' operator */
+template <typename T>
+struct DeleteDestructor {
+	static void destroy(T *data)
+	{
+		delete data;
+	}
+};
+
+/* reference-counted pointer for managing transient data on the stack */
+template <typename T, typename DestructorT = DeleteDestructor<T> >
+struct node_data_ptr {
+	typedef T element_type;
+	typedef node_data_ptr<T> self_type;
+	
+	node_data_ptr() :
+	    m_data(0),
+	    m_refs(0)
+	{}
+	
+	explicit node_data_ptr(element_type *data) :
+	    m_data(data),
+	    m_refs(0)
+	{}
+	
+	~node_data_ptr()
+	{
+	}
+	
+	element_type* get() const { return m_data; }
+	void set(element_type *data)
+	{
+		if (m_data != data) {
+			if (m_data)
+				DestructorT::destroy(m_data);
+			m_data = data;
+		}
+	}
+	
+	element_type& operator * () const { return *m_data; }
+	element_type* operator -> () const { return m_data; }
+	
+	void set_use_count(size_t use_count)
+	{
+		assert(m_refs == 0);
+		if (use_count > 0)
+			m_refs = create_refs(use_count);
+	}
+	
+	void decrement_use_count()
+	{
+		assert(m_refs != 0 && *m_refs > 0);
+		size_t count = --(*m_refs);
+		if (count == 0) {
+			clear();
+		}
+	}
+	
+	void clear()
+	{
+		if (m_data) {
+			DestructorT::destroy(m_data);
+			m_data = 0;
+		}
+		if (m_refs) {
+			destroy_refs(m_refs);
+			m_refs = 0;
+		}
+	}
+	
+protected:
+	/* TODO this could be handled by a common memory manager with a mempool */
+	static size_t *create_refs(size_t use_count) { return new size_t(use_count); }
+	static void destroy_refs(size_t *refs) { delete refs; }
+	
+private:
+	T *m_data;
+	size_t *m_refs;
+};
+
+/* TODO THIS IS IMPORTANT!
+ * In the future we will want to manage references to allocated data
+ * on the stack in a 'manager'. This is because when cancelling a
+ * calculation we want to make sure all temporary data is freed cleanly.
+ * The resulting output data from a kernel function must be registered
+ * in the manager and all the active storage can be removed in one go
+ * if the calculation gets cancelled.
+ * 
+ * We don't want to leave this registration to the kernel itself though,
+ * so it has to happen through another instruction. This instruction has
+ * to be placed _before_ the kernel call though, because otherwise canceling
+ * could still happen in between. Since the actual pointer is still set by
+ * the kernel function, this means the manager has to keep a double pointer.
+ */
+#if 0
+template <typename ptr_type>
+struct NodeDataManager {
+	typedef unordered_set
+	
+	NodeDataManager()
+	{
+	}
+	
+	void insert(T *data, size_t use_count)
+	{
+	}
+	
+	void destroy(T *data)
+	{
+	}
+	
+protected:
+	NodeDataManager()
+	{
+	}
+	
+private:
+	
+};
+#endif
+
+struct DerivedMeshDestructor {
+	static void destroy(DerivedMesh *dm)
+	{
+		dm->release(dm);
+	}
+};
+typedef node_data_ptr<DerivedMesh, DerivedMeshDestructor> mesh_ptr;
+
+struct Dupli {
+	Object *object;
+	matrix44 transform;
+	int index;
+	bool hide;
+	bool recursive;
+};
+typedef std::vector<Dupli> DupliList;
+typedef node_data_ptr<DupliList> duplis_ptr;
+
+inline void create_empty_mesh(mesh_ptr &p)
+{
+	DerivedMesh *dm = CDDM_new(0, 0, 0, 0, 0);
+	/* prevent the DM from getting freed */
+	dm->needsFree = 0;
+	p.set(dm);
+}
+
+inline void destroy_empty_mesh(mesh_ptr &p)
+{
+	DerivedMesh *dm = p.get();
+	/* have to set this back so the DM actually gets freed */
+	dm->needsFree = 1;
+	p.clear();
+}
+
+} /* namespace bvm */
+
+#endif
diff --git a/source/blender/blenvm/util/bvm_util_math.h b/source/blender/blenvm/util/bvm_util_math.h
index a8ec6eb..2f00b65 100644
--- a/source/blender/blenvm/util/bvm_util_math.h
+++ b/source/blender/blenvm/util/bvm_util_math.h
@@ -38,6 +38,133 @@ extern "C" {
 
 namespace bvm {
 
+/* types */
+
+struct float3 {
+	float3()
+	{}
+	
+	float3(float x, float y, float z) :
+	    x(x), y(y), z(z)
+	{}
+	
+	float* data() { return &x; }
+	const float* data() const { return &x; }
+	
+	inline static float3 from_data(const float *values)
+	{
+		float3 f;
+		f.x = values[0];
+		f.y = values[1];
+		f.z = values[2];
+		return f;
+	}
+	
+	float& operator[] (int index)
+	{
+		return ((float*)(&x))[index];
+	}
+	float operator[] (int index) const
+	{
+		return ((float*)(&x))[index];
+	}
+	
+	float x;
+	float y;
+	float z;
+};
+
+struct float4 {
+	float4()
+	{}
+	
+	float4(float x, float y, float z, float w) :
+	    x(x), y(y), z(z), w(w)
+	{}
+	
+	float* data() { return &x; }
+	const float* data() const { return &x; }
+	
+	inline static float4 from_data(const float *values)
+	{
+		float4 f;
+		f.x = values[0];
+		f.y = values[1];
+		f.z = values[2];
+		f.w = values[3];
+		return f;
+	}
+	
+	float& operator[] (int index)
+	{
+		return ((float*)(&x))[index];
+	}
+	float operator[] (int index) const
+	{
+		return ((float*)(&x))[index];
+	}
+	
+	float x;
+	float y;
+	float z;
+	float w;
+};
+
+struct matrix44 {
+	enum Layout {
+		COL_MAJOR,
+		ROW_MAJOR,
+	};
+	
+	matrix44()
+	{}
+	
+	matrix44(const float3 &x, const float3 &y, const float3 &z, const float3 &t)
+	{
+		data[0][0] = x.x;	data[1][0] = y.x;	data[2][0] = z.x;	data[3][0] = t.x;
+		data[0][1] = x.y;	data[1][1] = y.y;	data[2][1] = z.y;	data[3][1] = t.y;
+		data[0][2] = x.z;	data[1][2] = y.z;	data[2][2] = z.z;	data[3][2] = t.z;
+		data[0][3] = 0.0f;	data[1][3] = 0.0f;	data[2][3] = 0.0f;	data[3][3] = 1.0f;
+	}
+	
+	matrix44(const float3 &t)
+	{
+		data[0][0] = 1.0f;	data[1][0] = 0.0f;	data[2][0] = 0.0f;	data[3][0] = t.x;
+		data[0][1] = 0.0f;	data[1][1] = 1.0f;	data[2][1] = 0.0f;	data[3][1] = t.y;
+		data[0][2] = 0.0f;	data[1][2] = 0.0f;	data[2][2] = 1.0f;	data[3][2] = t.z;
+		data[0][3] = 0.0f;	data[1][3] = 0.0f;	data[2][3] = 0.0f;	data[3][3] = 1.0f;
+	}
+	
+	inline static matrix44 from_data(const float *values, Layout layout = COL_MAJOR) {
+		matrix44 m;
+		if (layout == COL_MAJOR) {
+			m.data[0][0] = values[0]; m.data[1][0] = values[1]; m.data[2][0] = values[2]; m.data[3][0] = values[3];
+			m.data[0][1] = values[4]; m.data[1][1] = values[5]; m.data[2][1] = values[6]; m.data[3][1] = values[7];
+			m.data[0][2] = values[8]; m.data[1][2] = values[9]; m.data[2][2] = values[10]; m.data[3][2] = values[11];
+			m.data[0][3] = values[12]; m.data[1][3] = values[13]; m.data[2][3] = values[14]; m.data[3][3] = values[15];
+		}
+		else {
+			m.data[0][0] = values[0]; m.data[1][0] = values[4]; m.data[2][0] = values[8]; m.data[3][0] = values[12];
+			m.data[0][1] = values[1]; m.data[1][1] = values[5]; m.data[2][1] = values[9]; m.data[3][1] = values[13];
+			m.data[0][2] = values[2]; m.data[1][2] = values[6]; m.data[2][2] = values[10]; m.data[3][2] = values[14];
+			m.data[0][3] = values[3]; m.data[1][3] = values[7]; m.data[2][3] = values[11]; m.data[3][3] = values[15];
+		}
+		return m;
+	}
+	
+	inline static matrix44 identity()
+	{
+		return matrix44(float3(1.0f, 0.0f, 0.0f),
+		                float3(0.0f, 1.0f, 0.0f),
+		                float3(0.0f, 0.0f, 1.0f),
+		                float3(0.0f, 0.0f, 0.0f));
+	}
+	
+	float data[4][4];
+};
+
+/* utilities */
+
 typedef enum eEulerRotationOrders {
 	EULER_ORDER_DEFAULT = ::EULER_ORDER_DEFAULT, /* blender classic = XYZ */
 	EULER_ORDER_XYZ = ::EULER_ORDER_XYZ,
diff --git a/source/blender/blenvm/util/bvm_util_typedesc.h b/source/blender/blenvm/util/bvm_util_typedesc.h
index 564a9a7..7ce652d 100644
--- a/source/blender/blenvm/util/bvm_util_typedesc.h
+++ b/source/blender/blenvm/util/bvm_util_typedesc.h
@@ -35,302 +35,18 @@
 #include <cassert>
 #include <vector>
 
-#include "MEM_guardedalloc.h"
-
 extern "C" {
-#include "BLI_listbase.h"
-
-#include "BKE_DerivedMesh.h"
-#include "BKE_cdderivedmesh.h"
-
 #include "RNA_access.h"
 }
 
 #include "BVM_types.h"
+#include "bvm_util_data_ptr.h"
+#include "bvm_util_math.h"
 
 namespace bvm {
 
 struct Value;
 
-struct float3 {
-	float3()
-	{}
-	
-	float3(float x, float y, float z) :
-	    x(x), y(y), z(z)
-	{}
-	
-	float* data() { return &x; }
-	const float* data() const { return &x; }
-	
-	inline static float3 from_data(const float *values)
-	{
-		float3 f;
-		f.x = values[0];
-		f.y = values[1];
-		f.z = values[2];
-		return f;
-	}
-	
-	float& operator[] (int index)
-	{
-		return ((float*)(&x))[index];
-	}
-	float operator[] (int index) const
-	{
-		return ((float*)(&x))[index];
-	}
-	
-	float x;
-	float y;
-	float z;
-};
-
-struct float4 {
-	float4()
-	{}
-	
-	float4(float x, floa

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list