Browse Source

Code refactoring

Paul A 4 years ago
parent
commit
620d2d4ee9

BIN
.vs/Praxis3D/v16/.suo


+ 5 - 5
Praxis3D/Source/GraphicsObject.h

@@ -175,24 +175,24 @@ public:
 	inline void setWorldScale(const Math::Vec3f &p_scale)								{ setUpdateNeeded(true); m_worldSpace.m_spatialData.m_scale = p_scale;												}
 	inline void setWorldScale(const Math::Vec3f &p_scale)								{ setUpdateNeeded(true); m_worldSpace.m_spatialData.m_scale = p_scale;												}
 	
 	
 	// Component functions
 	// Component functions
-	void addComponent(DirectionalLightDataSet &p_lightDataSet)
+	/*void addComponent(DirectionalLightDataSet &p_lightDataSet)
 	{
 	{
 		// Make sure that this component isn't assigned already
 		// Make sure that this component isn't assigned already
 		removeComponent(GraphicsComponentType::GraphicsComponentType_Light);
 		removeComponent(GraphicsComponentType::GraphicsComponentType_Light);
-		m_lightComponent = new LightComponent(p_lightDataSet);
+		//m_lightComponent = new LightComponent(p_lightDataSet);
 	}
 	}
 	void addComponent(PointLightDataSet &p_lightDataSet)
 	void addComponent(PointLightDataSet &p_lightDataSet)
 	{
 	{
 		// Make sure that this component isn't assigned already
 		// Make sure that this component isn't assigned already
 		removeComponent(GraphicsComponentType::GraphicsComponentType_Light);
 		removeComponent(GraphicsComponentType::GraphicsComponentType_Light);
-		m_lightComponent = new LightComponent(p_lightDataSet);
+		//m_lightComponent = new LightComponent(p_lightDataSet);
 	}
 	}
 	void addComponent(SpotLightDataSet &p_lightDataSet)
 	void addComponent(SpotLightDataSet &p_lightDataSet)
 	{
 	{
 		// Make sure that this component isn't assigned already
 		// Make sure that this component isn't assigned already
 		removeComponent(GraphicsComponentType::GraphicsComponentType_Light);
 		removeComponent(GraphicsComponentType::GraphicsComponentType_Light);
-		m_lightComponent = new LightComponent(p_lightDataSet);
-	}	
+		//m_lightComponent = new LightComponent(p_lightDataSet);
+	}*/	
 	void addComponent(LightComponent *p_component)
 	void addComponent(LightComponent *p_component)
 	{
 	{
 		// Make sure that this component isn't assigned already
 		// Make sure that this component isn't assigned already

+ 139 - 46
Praxis3D/Source/LightComponent.h

@@ -50,8 +50,8 @@ public:
 		}
 		}
 	}
 	}
 
 
-	BitMask getDesiredSystemChanges() { return Systems::Changes::Spatial::AllWorld | Systems::Changes::Graphics::All; }
-	BitMask getPotentialSystemChanges() { return Systems::Changes::Spatial::WorldTransform; }
+	BitMask getDesiredSystemChanges()	{ return Systems::Changes::Spatial::AllWorld | Systems::Changes::Graphics::All; }
+	BitMask getPotentialSystemChanges() { return Systems::Changes::Spatial::WorldTransform;								}
 
 
 	~LightComponent() 
 	~LightComponent() 
 	{
 	{
@@ -67,54 +67,61 @@ public:
 		}
 		}
 	}
 	}
 
 
-	void updateSpatialData(const SpatialData &p_data)
-	{
-		// Update each type of light individually, as their spatial data is made up of different attributes
-		switch(m_lightComponentType)
-		{
-		case LightComponent::LightComponentType_directional:
-			m_lightComponent.m_directional.m_direction = p_data.m_rotationEuler;
-			break;
-		case LightComponent::LightComponentType_point:
-			m_lightComponent.m_point.m_position = p_data.m_position;
-			break;
-		case LightComponent::LightComponentType_spot:
-			m_lightComponent.m_spot.m_position = p_data.m_position;
-			m_lightComponent.m_spot.m_direction = p_data.m_rotationEuler;
-			break;
-		}
-	}
-	void updatePosition(const Math::Vec3f &p_position)
-	{
-		// Update each type of light individually, as their spatial data is made up of different attributes
-		switch(m_lightComponentType)
-		{
-		case LightComponent::LightComponentType_point:
-			m_lightComponent.m_point.m_position = p_position;
-			break;
-		case LightComponent::LightComponentType_spot:
-			m_lightComponent.m_spot.m_position = p_position;
-			break;
-		}
-	}
-	void updateRotation(const Math::Vec3f &p_rotation)
-	{
-		// Update each type of light individually, as their spatial data is made up of different attributes
-		switch(m_lightComponentType)
-		{
-		case LightComponent::LightComponentType_directional:
-			m_lightComponent.m_directional.m_direction = p_rotation;
-			break;
-		case LightComponent::LightComponentType_spot:
-			m_lightComponent.m_spot.m_direction = p_rotation;
-			break;
-		}
-	}
-
 	virtual void changeOccurred(ObservedSubject *p_subject, BitMask p_changeType)
 	virtual void changeOccurred(ObservedSubject *p_subject, BitMask p_changeType)
 	{
 	{
 		// Track what data has been modified
 		// Track what data has been modified
 		BitMask newChanges = Systems::Changes::None;
 		BitMask newChanges = Systems::Changes::None;
+		BitMask processedChange = 0;
+
+		// Deal with each change until there are no changes left
+		while(p_changeType)
+		{
+			switch(p_changeType)
+			{
+			case Systems::Changes::Spatial::AllWorld:
+				processedChange = Systems::Changes::Spatial::AllWorld; 
+				updateSpatialData(p_subject->getSpatialData(this, processedChange));
+				newChanges |= processedChange;
+				break;
+			case Systems::Changes::Spatial::AllWorldNoTransform:
+				processedChange = Systems::Changes::Spatial::AllWorldNoTransform;
+				updateSpatialData(p_subject->getSpatialData(this, processedChange));
+				newChanges |= processedChange;
+				break;
+			case Systems::Changes::Spatial::LocalPosition:
+				processedChange = Systems::Changes::Spatial::LocalPosition;
+				newChanges |= processedChange;
+				break;
+			case (Systems::Changes::Spatial::LocalRotation | Systems::Changes::Graphics::Direction):
+				processedChange = (Systems::Changes::Spatial::LocalRotation | Systems::Changes::Graphics::Direction);
+				newChanges |= processedChange;
+				break;
+			case Systems::Changes::Spatial::WorldPosition:
+				processedChange = Systems::Changes::Spatial::WorldPosition;
+				newChanges |= processedChange;
+				break;
+			case Systems::Changes::Spatial::WorldRotation:
+				processedChange = Systems::Changes::Spatial::WorldRotation;
+				newChanges |= processedChange;
+				break;
+			case Systems::Changes::Graphics::Color:
+				processedChange = Systems::Changes::Graphics::Color;
+				newChanges |= processedChange;
+				break;
+			case Systems::Changes::Graphics::CutoffAngle:
+				processedChange = Systems::Changes::Graphics::CutoffAngle;
+				newChanges |= processedChange;
+				break;
+			case Systems::Changes::Graphics::Intensity:
+				processedChange = Systems::Changes::Graphics::Intensity;
+				newChanges |= processedChange;
+				break;
+			}
+
+			// Remove the processed change mask from the bit mask value, and reset the processed change value
+			p_changeType &= ~processedChange;
+			processedChange = 0;
+		}
 
 
 		// Get all of the world spatial data, include the transform matrix; add up the bit-mask of changed data;
 		// Get all of the world spatial data, include the transform matrix; add up the bit-mask of changed data;
 		if(p_changeType & Systems::Changes::Spatial::AllWorld)
 		if(p_changeType & Systems::Changes::Spatial::AllWorld)
@@ -173,5 +180,91 @@ private:
 		SpotLightDataSet m_spot;
 		SpotLightDataSet m_spot;
 	} m_lightComponent;
 	} m_lightComponent;
 
 
+
+	void updateColor(const Math::Vec3f &p_color)
+	{
+		// Update each type of light individually
+		switch(m_lightComponentType)
+		{
+		case LightComponent::LightComponentType_directional:
+			m_lightComponent.m_directional.m_color = p_color;
+			break;
+		case LightComponent::LightComponentType_point:
+			m_lightComponent.m_point.m_color = p_color;
+			break;
+		case LightComponent::LightComponentType_spot:
+			m_lightComponent.m_spot.m_color = p_color;
+			break;
+		}
+	}
+	void updateCutoffAngle(const float p_cutoffAngle)
+	{
+		switch(m_lightComponentType)
+		{
+		case LightComponent::LightComponentType_spot:
+			m_lightComponent.m_spot.m_cutoffAngle = p_cutoffAngle;
+			break;
+		}
+	}
+	void updateIntensity(const float p_intensity)
+	{
+		// Update each type of light individually
+		switch(m_lightComponentType)
+		{
+		case LightComponent::LightComponentType_directional:
+			m_lightComponent.m_directional.m_intensity = p_intensity;
+			break;
+		case LightComponent::LightComponentType_point:
+			m_lightComponent.m_point.m_intensity = p_intensity;
+			break;
+		case LightComponent::LightComponentType_spot:
+			m_lightComponent.m_spot.m_intensity = p_intensity;
+			break;
+		}
+	}
+	void updateSpatialData(const SpatialData &p_data)
+	{
+		// Update each type of light individually, as their spatial data is made up of different attributes
+		switch(m_lightComponentType)
+		{
+		case LightComponent::LightComponentType_directional:
+			m_lightComponent.m_directional.m_direction = p_data.m_rotationEuler;
+			break;
+		case LightComponent::LightComponentType_point:
+			m_lightComponent.m_point.m_position = p_data.m_position;
+			break;
+		case LightComponent::LightComponentType_spot:
+			m_lightComponent.m_spot.m_position = p_data.m_position;
+			m_lightComponent.m_spot.m_direction = p_data.m_rotationEuler;
+			break;
+		}
+	}
+	void updatePosition(const Math::Vec3f &p_position)
+	{
+		// Update each type of light individually, as their spatial data is made up of different attributes
+		switch(m_lightComponentType)
+		{
+		case LightComponent::LightComponentType_point:
+			m_lightComponent.m_point.m_position = p_position;
+			break;
+		case LightComponent::LightComponentType_spot:
+			m_lightComponent.m_spot.m_position = p_position;
+			break;
+		}
+	}
+	void updateRotation(const Math::Vec3f &p_rotation)
+	{
+		// Update each type of light individually, as their spatial data is made up of different attributes
+		switch(m_lightComponentType)
+		{
+		case LightComponent::LightComponentType_directional:
+			m_lightComponent.m_directional.m_direction = p_rotation;
+			break;
+		case LightComponent::LightComponentType_spot:
+			m_lightComponent.m_spot.m_direction = p_rotation;
+			break;
+		}
+	}
+
 	LightComponentType m_lightComponentType;
 	LightComponentType m_lightComponentType;
 };
 };

+ 17 - 15
Praxis3D/Source/ObserverBase.h

@@ -62,12 +62,13 @@ public:
 	const virtual Math::Vec4f &getVec4(const Observer *p_observer, BitMask p_changedBits) const { return m_nullVec4; }
 	const virtual Math::Vec4f &getVec4(const Observer *p_observer, BitMask p_changedBits) const { return m_nullVec4; }
 	const virtual Math::Mat4f &getMat4(const Observer *p_observer, BitMask p_changedBits) const	{ return m_nullMat4; }
 	const virtual Math::Mat4f &getMat4(const Observer *p_observer, BitMask p_changedBits) const	{ return m_nullMat4; }
 
 
-	const virtual bool			getBool(const Observer *p_observer, BitMask p_changedBits) const			{ return m_nullBool;		}
-	const virtual int			getInt(const Observer *p_observer, BitMask p_changedBits) const				{ return m_nullInt;			}
-	const virtual float			getFloat(const Observer *p_observer, BitMask p_changedBits) const			{ return m_nullFloat;		}
-	const virtual double		&getDouble(const Observer *p_observer, BitMask p_changedBits) const			{ return m_nullDouble;		}
-	const virtual std::string	&getString(const Observer *p_observer, BitMask p_changedBits) const			{ return m_nullString;		}
-	const virtual SpatialData	&getSpatialData(const Observer *p_observer, BitMask p_changedBits) const	{ return m_nullSpacialData;	}
+	const virtual bool					getBool(const Observer *p_observer, BitMask p_changedBits) const					{ return m_nullBool;					}
+	const virtual int					getInt(const Observer *p_observer, BitMask p_changedBits) const						{ return m_nullInt;						}
+	const virtual float					getFloat(const Observer *p_observer, BitMask p_changedBits) const					{ return m_nullFloat;					}
+	const virtual double				&getDouble(const Observer *p_observer, BitMask p_changedBits) const					{ return m_nullDouble;					}
+	const virtual std::string			&getString(const Observer *p_observer, BitMask p_changedBits) const					{ return m_nullString;					}
+	const virtual SpatialData			&getSpatialData(const Observer *p_observer, BitMask p_changedBits) const			{ return m_nullSpacialData;				}
+	const virtual SpatialTransformData	&getSpatialTransformData(const Observer *p_observer, BitMask p_changedBits) const	{ return m_nullSpacialTransformData;	}
 
 
 	// Stores observer information required for postChanges messages
 	// Stores observer information required for postChanges messages
 	struct ObserverData
 	struct ObserverData
@@ -98,13 +99,14 @@ private:
 		SpinWait m_observerListMutex;
 		SpinWait m_observerListMutex;
 	#endif
 	#endif
 
 
-	const static Math::Vec3f m_nullVec3;
-	const static Math::Vec4f m_nullVec4;
-	const static Math::Mat4f m_nullMat4;
-	const static bool		 m_nullBool;
-	const static int		 m_nullInt;
-	const static float		 m_nullFloat;
-	const static double		 m_nullDouble;
-	const static std::string m_nullString;
-	const static SpatialData m_nullSpacialData;
+	const static Math::Vec3f			m_nullVec3;
+	const static Math::Vec4f			m_nullVec4;
+	const static Math::Mat4f			m_nullMat4;
+	const static bool					m_nullBool;
+	const static int					m_nullInt;
+	const static float					m_nullFloat;
+	const static double					m_nullDouble;
+	const static std::string			m_nullString;
+	const static SpatialData			m_nullSpacialData;
+	const static SpatialTransformData	m_nullSpacialTransformData;
 };
 };