Panagiotis Christopoulos Charitos 14 年 前
コミット
c6cec4b632

+ 1 - 1
src/Events/Event.h

@@ -17,7 +17,7 @@ enum EventType
 };
 
 
-/// Abstract class for all events
+/// Abstract class for all events. All Event derived classes should be copy-able
 class Event
 {
 	public:

+ 24 - 1
src/Events/EventManager.cpp

@@ -8,8 +8,11 @@ namespace Event {
 //======================================================================================================================
 // updateAllEvents                                                                                                     =
 //======================================================================================================================
-void Manager::updateAllEvents(uint prevUpdateTime, uint crntTime)
+void Manager::updateAllEvents(uint prevUpdateTime_, uint crntTime_)
 {
+	prevUpdateTime = prevUpdateTime_;
+	crntTime = crntTime_;
+
 	BOOST_FOREACH(Event& event, events)
 	{
 		if(!event.isDead(crntTime))
@@ -20,4 +23,24 @@ void Manager::updateAllEvents(uint prevUpdateTime, uint crntTime)
 }
 
 
+//======================================================================================================================
+// findADeadEvent                                                                                                      =
+//======================================================================================================================
+Manager::EventsContainer::iterator Manager::findADeadEvent(EventType type)
+{
+	EventsContainer::iterator it = events.begin();
+
+	while(it != events.end())
+	{
+		if(it->isDead(crntTime) && it->getEventType() == type)
+		{
+			break;
+		}
+		++it;
+	}
+
+	return it;
+}
+
+
 } // end namespace

+ 10 - 0
src/Events/EventManager.h

@@ -22,7 +22,17 @@ class Manager
 		void updateAllEvents(uint prevUpdateTime, uint crntTime);
 
 	private:
+		enum
+		{
+			MAX_EVENTS_SIZE = 1000
+		};
+
 		EventsContainer events;
+		uint prevUpdateTime;
+		uint crntTime;
+
+		/// Find a dead event of a certain type
+		EventsContainer::iterator findADeadEvent(EventType type);
 };
 
 

+ 11 - 1
src/Events/EventManager.inl.h

@@ -10,7 +10,17 @@ namespace Event {
 template<typename EventType>
 void Manager::createEvent(const EventType& event)
 {
-	events.push_back(new EventType(event));
+	EventsContainer::iterator it = findADeadEvent(event.getEventType());
+
+	if(it == events.end()) // No dead event found
+	{
+		events.push_back(new EventType(event));
+	}
+	else // Re-use a dead event
+	{
+		Event& ev = *it;
+		static_cast<EventType&>(ev) = event;
+	}
 }
 
 

+ 3 - 3
src/Events/EventSceneColor.h

@@ -21,12 +21,12 @@ class SceneColor: public Event
 		/// Copy
 		SceneColor& operator=(const SceneColor& b);
 
-		/// Implements Event::updateSp
-		void updateSp(uint prevUpdateTime, uint crntTime);
-
 	private:
 		Vec3 originalColor; ///< Original scene color. The constructor sets it
 		Vec3 finalColor;
+
+		/// Implements Event::updateSp
+		void updateSp(uint prevUpdateTime, uint crntTime);
 };
 
 

+ 1 - 1
src/Resources/Mesh/MeshData.h

@@ -97,7 +97,7 @@ class MeshData
 		void createVertTangents();
 		void createVertIndeces();
 
-		/// This func does some sanity checks and creates normals, tangents, VBOs etc
+		/// This method does some sanity checks and creates normals, tangents, VBOs etc
 		/// @exception Exception
 		void doPostLoad();
 };

+ 0 - 6
src/Scene/VisibilityTester.h

@@ -17,9 +17,6 @@ class SceneNode;
 /// Performs visibility determination tests and fills a few containers with the visible scene nodes
 class VisibilityTester
 {
-	//====================================================================================================================
-	// Public                                                                                                            =
-	//====================================================================================================================
 	public:
 		/// Constructor
 		VisibilityTester(Scene& scene);
@@ -31,9 +28,6 @@ class VisibilityTester
 		/// - For every spot light that casts shadow get the visible renderables
 		void test(Camera& cam);
 
-	//====================================================================================================================
-	// Private                                                                                                           =
-	//====================================================================================================================
 	private:
 		/// Used in sorting. Compare the length of 2 nodes from the camera
 		struct CmpDistanceFromOrigin