Browse Source

Delete 2 files and documentation updates

Panagiotis Christopoulos Charitos 14 năm trước cách đây
mục cha
commit
824797dc27

+ 2 - 0
CMakeLists.txt

@@ -136,6 +136,8 @@ ELSEIF(${CMAKE_SYSTEM_NAME} STREQUAL Windows)
 	ADD_DEFINITIONS("-DPLATFORM_WINDOWS")
 ENDIF()
 
+ADD_DEFINITIONS("-std=c++0x")
+
 IF(CMAKE_BUILD_TYPE STREQUAL Debug)
 	# Removed because they do not work with boost::regexpr and who knows what
 	# else

+ 13 - 9
anki/scene/Property.h

@@ -46,6 +46,7 @@ public:
 		return tid;
 	}
 
+	/// Get the property value. Throws if the @a T is incorrect
 	template<typename T>
 	const T& getValue() const
 	{
@@ -53,6 +54,7 @@ public:
 		return static_cast<const Property<T>*>(this)->getValue();
 	}
 
+	/// Set the property value. Throws if the @a T is incorrect
 	template<typename T>
 	void setValue(const T& x)
 	{
@@ -61,7 +63,7 @@ public:
 	}
 	/// @}
 
-	/// Upcast to property
+	/// Upcast to property. It makes a runtime check
 	template<typename Prop>
 	Prop& upCast()
 	{
@@ -71,7 +73,7 @@ public:
 
 private:
 	std::string name;
-	uint tid;
+	uint tid; ///< Type ID
 
 	/// Runtime type checking
 	template<typename Prop>
@@ -95,7 +97,7 @@ public:
 
 	/// Unique id for every type of property
 	/// @note Don't even think of defining a default value in this or any other
-	///       header
+	///       .h file
 	static const uint TYPE_ID;
 
 	/// @name Constructors/Destructor
@@ -121,6 +123,7 @@ public:
 	}
 	/// @}
 
+	/// Signal that it is emitted when the value gets changed
 	ANKI_SIGNAL(const Value&, valueChanged)
 };
 
@@ -218,7 +221,7 @@ public:
 	/// @}
 
 private:
-	const Value* ptr; ///< Have only one const pointer for size saving
+	const Value* ptr;
 };
 
 
@@ -255,7 +258,7 @@ public:
 	/// @}
 
 private:
-	Value* ptr; ///< Have only one const pointer for size saving
+	Value* ptr;
 };
 
 
@@ -317,7 +320,8 @@ public:
 	typedef boost::ptr_vector<PropertyBase> Container;
 	typedef ConstCharPtrHashMap<PropertyBase*>::Type NameToPropertyMap;
 
-	/// Create a new property
+	/// Add new property to the map. The map gets the ownership of this
+	/// property
 	template<typename T>
 	Property<T>& addNewProperty(Property<T>* newp)
 	{
@@ -332,7 +336,7 @@ public:
 		return *newp;
 	}
 
-	/// XXX
+	/// Self explanatory
 	const PropertyBase& findPropertyBaseByName(const char* name) const
 	{
 		NameToPropertyMap::const_iterator it = map.find(name);
@@ -343,7 +347,7 @@ public:
 		return *(it->second);
 	}
 
-	/// XXX
+	/// Self explanatory
 	PropertyBase& findPropertyBaseByName(const char* name)
 	{
 		NameToPropertyMap::iterator it = map.find(name);
@@ -372,7 +376,7 @@ public:
 		return map.find(name) != map.end();
 	}
 
-	/// XXX
+	/// Set the value of a property. It may throw
 	template<typename T>
 	void setValue(const char* name, const T& v)
 	{

+ 15 - 12
anki/scene/Renderable.cpp

@@ -16,19 +16,18 @@ struct CreateNewPropertyVisitor: boost::static_visitor<void>
 {
 	const MaterialVariable* mvar;
 	PropertyMap* pmap;
-
-	CreateNewPropertyVisitor(const MaterialVariable* mvar_, PropertyMap* pmap_)
-		: mvar(mvar_), pmap(pmap_)
-	{}
+	Renderable::Properties* rprops;
 
 	template<typename T>
-	void operator()(const T& x) const
+	void operator()(const T&) const
 	{
-		typedef MaterialVariableReadCowPointerProperty<T> Prop;
-
-		Prop* prop = new Prop(mvar->getName().c_str(), &(mvar->getValue<T>()));
+		MaterialVariableProperty<T>* prop = new MaterialVariableProperty<T>(
+			mvar->getName().c_str(),
+			&(mvar->getValue<T>()),
+			!mvar->getInitialized());
 
 		pmap->addNewProperty(prop);
+		rprops->push_back(prop);
 	}
 };
 
@@ -38,14 +37,18 @@ struct CreateNewPropertyVisitor: boost::static_visitor<void>
 //==============================================================================
 
 //==============================================================================
-void Renderable::init(PropertyMap& pmap) const
+void Renderable::init(PropertyMap& pmap)
 {
 	const Material& mtl = getMaterial();
 
-	BOOST_FOREACH(const MaterialVariable& mv, mtl.getVariables())
+	CreateNewPropertyVisitor vis;
+	vis.pmap = &pmap;
+	vis.rprops = &props;
+
+	for(const MaterialVariable& mv : mtl.getVariables())
 	{
-		boost::apply_visitor(CreateNewPropertyVisitor(&mv, &pmap),
-			mv.getVariant());
+		vis.mvar = &mv;
+		boost::apply_visitor(vis, mv.getVariant());
 	}
 }
 

+ 33 - 4
anki/scene/Renderable.h

@@ -2,6 +2,8 @@
 #define ANKI_SCENE_RENDERABLE_H
 
 #include "anki/scene/Property.h"
+#include <vector>
+#include <boost/range/iterator_range.hpp>
 
 
 namespace anki {
@@ -18,7 +20,7 @@ class MaterialVariable;
 
 /// XXX
 template<typename T>
-class MaterialVariableReadCowPointerProperty: public ReadCowPointerProperty<T>
+class MaterialVariableProperty: public ReadCowPointerProperty<T>
 {
 public:
 	typedef T Value;
@@ -26,11 +28,21 @@ public:
 
 	/// @name Constructors/Destructor
 	/// @{
-	MaterialVariableReadCowPointerProperty(const char* name, const Value* x)
-		: Base(name, x)
+	MaterialVariableProperty(const char* name, const Value* x, bool buildin_)
+		: Base(name, x), buildin(buildin_)
 	{}
 	/// @}
+
+	/// @name Accessors
+	/// @{
+	bool isBuildIn() const
+	{
+		return buildin;
+	}
+	/// @}
+
 private:
+	bool buildin;
 };
 
 
@@ -40,14 +52,31 @@ private:
 class Renderable
 {
 public:
+	typedef std::vector<PropertyBase*> Properties;
+	typedef boost::iterator_range<Properties::iterator> MutableRange;
+	typedef boost::iterator_range<Properties::const_iterator> ConstRange;
+
 	/// Access to VAOs
 	virtual const ModelPatchBase& getModelPatchBase() const = 0;
 
 	/// Access the material
 	virtual const Material& getMaterial() const = 0;
 
+	MutableRange getProperties()
+	{
+		return MutableRange(props.begin(), props.end());
+	}
+
+	ConstRange getProperties() const
+	{
+		return ConstRange(props.begin(), props.end());
+	}
+
 protected:
-	void init(PropertyMap& pmap) const;
+	void init(PropertyMap& pmap);
+
+private:
+	Properties props;
 };
 /// @}
 

+ 2 - 10
anki/scene/SkinNode.h

@@ -26,7 +26,7 @@ public:
 		VBO_TF_POSITIONS, ///< VBO never empty
 		VBO_TF_NORMALS, ///< VBO never empty
 		VBO_TF_TANGENTS, ///< VBO never empty
-		VBOS_TF_NUMBER
+		VBOS_TF_COUNT
 	};
 
 	/// Create the @a tfVbos with empty data
@@ -76,7 +76,7 @@ public:
 	/// @}
 
 private:
-	boost::array<Vbo, TFV_NUM> tfVbos;
+	boost::array<Vbo, VBOS_TF_COUNT> tfVbos;
 	const Mesh* mesh; ///< The resource
 };
 
@@ -86,14 +86,6 @@ class SkinPatchNode: public SceneNode, public Movable, public Renderable,
 	public Spatial
 {
 	public:
-		enum TransformFeedbackVbo
-		{
-			TFV_POSITIONS,
-			TFV_NORMALS,
-			TFV_TANGENTS,
-			TFV_NUM
-		};
-
 		/// See TfHwSkinningGeneric.glsl for the locations
 		enum TfShaderProgAttribLoc
 		{

+ 0 - 23
anki/scene/SpotLight.cpp

@@ -1,23 +0,0 @@
-#include "anki/scene/SpotLight.h"
-
-
-namespace anki {
-
-
-//==============================================================================
-// init                                                                        =
-//==============================================================================
-void SpotLight::init(const char* filename)
-{
-	Light::init(filename);
-	if(lightData->getType() != LightRsrc::LT_SPOT)
-	{
-		throw ANKI_EXCEPTION("Light data is wrong type");
-	}
-	camera = new PerspectiveCamera(getScene(), SNF_NONE, this);
-	camera->setAll(lightData->getFovX(), lightData->getFovY(), 0.02,
-		lightData->getDistance());
-}
-
-
-} // end namespace

+ 0 - 84
anki/scene/SpotLight.h

@@ -1,84 +0,0 @@
-#ifndef ANKI_SCENE_SPOT_LIGHT_H
-#define ANKI_SCENE_SPOT_LIGHT_H
-
-#include "anki/scene/Light.h"
-#include "anki/scene/PerspectiveCamera.h"
-
-
-namespace anki {
-
-
-/// Spot light
-class SpotLight: public Light
-{
-	public:
-		SpotLight(Scene& scene, ulong flags, SceneNode* parent);
-		~SpotLight()
-		{}
-
-		void init(const char* filename);
-
-		/// @name Accessors
-		/// @{
-		float getDistance() const
-		{
-			return camera->getZFar();
-		}
-		void setDistance(float d)
-		{
-			camera->setZFar(d);
-		}
-
-		float getFovX() const
-		{
-			return camera->getFovX();
-		}
-		void setFovX(float f)
-		{
-			camera->setFovX(f);
-		}
-
-		float getFovY() const
-		{
-			return camera->getFovY();
-		}
-		void setFovY(float f)
-		{
-			camera->setFovY(f);
-		}
-
-		const Texture& getTexture() const
-		{
-			return lightData->getTexture();
-		}
-
-		const Camera& getCamera() const
-		{
-			return *camera;
-		}
-		Camera& getCamera()
-		{
-			return *camera;
-		}
-		/// @}
-
-		const CollisionShape*
-			getVisibilityCollisionShapeWorldSpace() const
-		{
-			return camera->getVisibilityCollisionShapeWorldSpace();
-		}
-
-	private:
-		PerspectiveCamera* camera;
-};
-
-
-inline SpotLight::SpotLight(Scene& scene, ulong flags, SceneNode* parent)
-:	Light(LT_SPOT, scene, flags, parent)
-{}
-
-
-} // end namespace
-
-
-#endif

+ 19 - 19
anki/util/Observer.h

@@ -17,6 +17,24 @@ struct Observer
 };
 
 
+/// An over-qualified observer
+template<typename ObservingType, typename Value,
+	void (ObservingType::*method)(Value)>
+struct SuperObserver: Observer<Value>
+{
+	ObservingType* reveiver;
+
+	SuperObserver(ObservingType* reveiver_)
+		: reveiver(reveiver_)
+	{}
+
+	void notify(Value x)
+	{
+		(reveiver->*method)(x);
+	}
+};
+
+
 /// Basically a container of observers
 template<typename T>
 class Observable
@@ -54,24 +72,6 @@ private:
 };
 
 
-/// An over-qualified observer
-template<typename ObservingType, typename Value,
-	void (ObservingType::*method)(Value)>
-struct Observing: Observer<Value>
-{
-	ObservingType* reveiver;
-
-	Observing(ObservingType* reveiver_)
-		: reveiver(reveiver_)
-	{}
-
-	void notify(Value x)
-	{
-		(reveiver->*method)(x);
-	}
-};
-
-
 /// If a class has slots it should include this
 #define ANKI_OBSERVING(_class) \
 	typedef _class ObservingType;
@@ -88,7 +88,7 @@ struct Observing: Observer<Value>
 
 /// Define a slot. This should follow the method declaration
 #define ANKI_SLOT(_name, _type) \
-	typedef Observing<ObservingType, _type, &ObservingType::_name> \
+	typedef SuperObserver<ObservingType, _type, &ObservingType::_name> \
 		Observing_##_name;