Panagiotis Christopoulos Charitos 14 anni fa
parent
commit
45b55d9951

File diff suppressed because it is too large
+ 0 - 0
build/debug/Makefile


+ 4 - 0
src/Core/Globals.h

@@ -14,5 +14,9 @@ typedef Singleton<class StdinListener> StdinListenerSingleton;
 typedef Singleton<class GlStateMachine> GlStateMachineSingleton;
 typedef Singleton<class ScriptingEngine> ScriptingEngineSingleton;
 
+namespace Event {
+typedef Singleton<class Manager> ManagerSingleton;
+}
+
 
 #endif

+ 7 - 5
src/Events/Event.cpp

@@ -30,13 +30,15 @@ Event& Event::operator=(const Event& b)
 //======================================================================================================================
 // update                                                                                                              =
 //======================================================================================================================
-void Event::update(uint timeUpdate)
+void Event::update(uint prevUpdateTime, uint crntTime)
 {
-	ASSERT(!isFinished());
+	ASSERT(!isDead(crntTime));
 
-	updateSp(timeUpdate);
-
-	duration -= timeUpdate;
+	// Dont update if its not the right time yet
+	if(startTime >= crntTime)
+	{
+		updateSp(prevUpdateTime, crntTime);
+	}
 }
 
 

+ 8 - 6
src/Events/Event.h

@@ -31,21 +31,23 @@ class Event
 		GETTER_R(uint, startTime, getStartTime)
 		GETTER_R(int, duration, getDuration)
 		GETTER_R(EventType, type, getEventType)
-		bool isFinished() const {return duration < 0;}
+		bool isDead(uint crntTime) const {return crntTime >= startTime + duration;}
 		/// @}
 
 		/// Copy
 		Event& operator=(const Event& b);
 
-		/// @param[in] timeUpdate The time between this update and the previous
-		void update(uint timeUpdate);
-		virtual void updateSp(uint timeUpdate) = 0;
+		/// @param[in] prevUpdateTime The time of the previous update (ms)
+		/// @param[in] crntTime The current time (ms)
+		void update(uint prevUpdateTime, uint crntTime);
+
+	protected:
+		virtual void updateSp(uint prevUpdateTime, uint crntTime) = 0;
 
 	private:
 		EventType type; ///< Self explanatory
 		uint startTime; ///< The time the event will start. Eg 23:00
-		/// The duration of the event. < 0 means finished, 0 means no limit and > 0 is the actual duration
-		int duration;
+		int duration; ///< The duration of the event
 };
 
 

+ 23 - 0
src/Events/EventManager.cpp

@@ -0,0 +1,23 @@
+#include <boost/foreach.hpp>
+#include "EventManager.h"
+
+
+namespace Event {
+
+
+//======================================================================================================================
+// updateAllEvents                                                                                                     =
+//======================================================================================================================
+void Manager::updateAllEvents(uint prevUpdateTime, uint crntTime)
+{
+	BOOST_FOREACH(Event& event, events)
+	{
+		if(!event.isDead(crntTime))
+		{
+			event.update(prevUpdateTime, crntTime);
+		}
+	}
+}
+
+
+} // end namespace

+ 17 - 1
src/Events/EventManager.h

@@ -1,19 +1,35 @@
 #ifndef EVENT_MANAGER_H
 #define EVENT_MANAGER_H
 
+#include <boost/ptr_container/ptr_deque.hpp>
+#include "Event.h"
+
 
 namespace Event {
 
 
-/// @todo
+/// This manager creates the events ands keeps tracks of them
 class Manager
 {
 	public:
+		typedef boost::ptr_deque<Event> EventsContainer;
+
+		/// Create a new event
+		template<typename EventType>
+		void createEvent(const EventType& event);
+
+		/// Update
+		void updateAllEvents(uint prevUpdateTime, uint crntTime);
+
 	private:
+		EventsContainer events;
 };
 
 
 } // end namespace
 
 
+#include "EventManager.inl.h"
+
+
 #endif

+ 17 - 0
src/Events/EventManager.inl.h

@@ -0,0 +1,17 @@
+#include "EventManager.h"
+
+
+namespace Event {
+
+
+//======================================================================================================================
+//  createEvent                                                                                                        =
+//======================================================================================================================
+template<typename EventType>
+void Manager::createEvent(const EventType& event)
+{
+	events.push_back(new EventType(event));
+}
+
+
+} // end namespace

+ 19 - 3
src/Events/EventSceneColor.cpp

@@ -12,9 +12,20 @@ namespace Event {
 SceneColor::SceneColor(uint startTime, int duration, const Vec3& finalColor_):
 	Event(SCENE_COLOR, startTime, duration),
 	finalColor(finalColor_)
-{}
+{
+	originalColor = SceneSingleton::getInstance().getAmbientCol();
+}
 
 
+//======================================================================================================================
+// Constructor copy                                                                                                    =
+//======================================================================================================================
+SceneColor::SceneColor(const SceneColor& b):
+	Event(SCENE_COLOR, 0.0, 0.0)
+{
+	*this = b;
+}
+
 
 //======================================================================================================================
 // operator=                                                                                                           =
@@ -23,15 +34,20 @@ SceneColor& SceneColor::operator=(const SceneColor& b)
 {
 	Event::operator=(b);
 	finalColor = b.finalColor;
+	return *this;
 }
 
 
 //======================================================================================================================
 // updateSp                                                                                                            =
 //======================================================================================================================
-void SceneColor::updateSp(uint timeUpdate)
+void SceneColor::updateSp(uint /*prevUpdateTime*/, uint crntTime)
 {
-	SceneColor();
+	float d = crntTime - getStartTime(); // delta
+	float dp = d / getDuration(); // delta as persentage
+
+	Vec3 col = originalColor * (1.0 - dp) + finalColor * dp;
+	SceneSingleton::getInstance().setAmbientCol(col);
 }
 
 

+ 3 - 2
src/Events/EventSceneColor.h

@@ -16,15 +16,16 @@ class SceneColor: public Event
 		SceneColor(uint startTime, int duration, const Vec3& finalColor);
 
 		/// Copy constructor
-		SceneColor(const SceneColor& b) {*this = b;}
+		SceneColor(const SceneColor& b);
 
 		/// Copy
 		SceneColor& operator=(const SceneColor& b);
 
 		/// Implements Event::updateSp
-		void updateSp(uint timeUpdate);
+		void updateSp(uint prevUpdateTime, uint crntTime);
 
 	private:
+		Vec3 originalColor; ///< Original scene color. The constructor sets it
 		Vec3 finalColor;
 };
 

+ 17 - 7
src/Main.cpp

@@ -42,6 +42,8 @@
 #include "Globals.h"
 #include "UiFtFontLoader.h"
 #include "UiFont.h"
+#include "EventManager.h"
+#include "EventSceneColor.h"
 
 
 // map (hard coded)
@@ -312,6 +314,13 @@ void mainLoopExtra()
 	}
 
 
+	if(InputSingleton::getInstance().getKey(SDL_SCANCODE_F))
+	{
+		Event::ManagerSingleton::getInstance().createEvent(Event::SceneColor(HighRezTimer::getCrntTime() + 4000, 5000,
+		                                                                     Vec3(1.0, 0.0, 0.0)));
+	}
+
+
 	if(InputSingleton::getInstance().getKey(SDL_SCANCODE_O) == 1)
 	{
 		btRigidBody* body = static_cast<btRigidBody*>(boxes[0]);
@@ -351,8 +360,13 @@ void mainLoop()
 
 	HighRezTimer mainLoopTimer;
 	mainLoopTimer.start();
+	uint prevUpdateTime = HighRezTimer::getCrntTime();
+	uint crntTime = prevUpdateTime;
 	do
 	{
+		prevUpdateTime = crntTime;
+		crntTime = HighRezTimer::getCrntTime();
+
 		HighRezTimer timer;
 		timer.start();
 
@@ -362,12 +376,8 @@ void mainLoop()
 		SceneSingleton::getInstance().getPhysics().update(timer.getCrntTime());
 		SceneSingleton::getInstance().updateAllWorldStuff();
 		SceneSingleton::getInstance().doVisibilityTests(*AppSingleton::getInstance().getActiveCam());
-		/*SceneSingleton::getInstance().doVisibilityTests(spot_lights[0]->getCamera());
-		AppSingleton::getInstance().getActiveCam()->getVisibleMsRenderableNodes().clear();
-		AppSingleton::getInstance().getActiveCam()->getVisibleMsRenderableNodes() = spot_lights[0]->getCamera().getVisibleMsRenderableNodes();
-		AppSingleton::getInstance().getActiveCam()->getVisiblePointLights() = spot_lights[0]->getCamera().getVisiblePointLights();
-		AppSingleton::getInstance().getActiveCam()->getVisibleSpotLights() = spot_lights[0]->getCamera().getVisibleSpotLights();*/
 		SceneSingleton::getInstance().updateAllControllers();
+		Event::ManagerSingleton::getInstance().updateAllEvents(prevUpdateTime, crntTime);
 
 		MainRendererSingleton::getInstance().render(*AppSingleton::getInstance().getActiveCam());
 
@@ -375,7 +385,7 @@ void mainLoop()
 		painter->setColor(Vec4(1.0));
 
 		//painter->drawText("A");
-		painter->drawText("Once uppon a time in a place called Kickapoo.");
+		painter->drawText("Once upon a time in a place called Kickapoo.");
 
 		if(InputSingleton::getInstance().getKey(SDL_SCANCODE_ESCAPE))
 		{
@@ -435,7 +445,7 @@ void mainLoop()
 //======================================================================================================================
 int main(int argc, char* argv[])
 {
-	/*FT_Vector s = {100, 100};
+	/*FT_Vector s = {25, 25};
 	Ui::FtFontLoader fnt("engine-rsrc/ModernAntiqua.ttf", s);
 	fnt.saveImage("/tmp/test.tga");
 

+ 1 - 1
src/Util/HighRezTimer.h

@@ -19,7 +19,7 @@ class HighRezTimer
 		/// Get the time elapsed between start and stop (if its stopped) or between start and the current time
 		uint getElapsedTime() const;
 
-		/// Get the current date's millisecond
+		/// Get the current date's milliseconds
 		static uint getCrntTime();
 
 	private:

Some files were not shown because too many files changed in this diff