Jelajahi Sumber

- Event system
- Scripting of the event system

Panagiotis Christopoulos Charitos 14 tahun lalu
induk
melakukan
68111b7cd4

File diff ditekan karena terlalu besar
+ 0 - 1
build/debug/Makefile


+ 16 - 0
src/Events/Event.h

@@ -12,6 +12,7 @@ namespace Event {
 enum EventType
 {
 	SCENE_COLOR,
+	MAIN_RENDERER_PPS_HDR,
 	EVENT_TYPES_NUM
 };
 
@@ -42,8 +43,16 @@ class Event
 		void update(uint prevUpdateTime, uint crntTime);
 
 	protected:
+		/// This method should be implemented by the derived classes
 		virtual void updateSp(uint prevUpdateTime, uint crntTime) = 0;
 
+		/// Linear interpolation between values
+		/// @param[in] from Starting value
+		/// @param[in] to Ending value
+		/// @param[in] delta The percentage from the from "from" value. Values from [0.0, 1.0]
+		template<typename Type>
+		static Type interpolate(const Type& from, const Type& to, float delta);
+
 	private:
 		EventType type; ///< Self explanatory
 		uint startTime; ///< The time the event will start. Eg 23:00
@@ -51,6 +60,13 @@ class Event
 };
 
 
+template<typename Type>
+Type Event::interpolate(const Type& from, const Type& to, float delta)
+{
+	return from * (1.0 - delta) + to * delta;
+}
+
+
 } // end namespace
 
 

+ 68 - 0
src/Events/EventMainRendererPpsHdr.cpp

@@ -0,0 +1,68 @@
+#include "EventMainRendererPpsHdr.h"
+#include "MainRenderer.h"
+#include "Globals.h"
+
+
+namespace Event {
+
+
+//======================================================================================================================
+// Constructor                                                                                                         =
+//======================================================================================================================
+MainRendererPpsHdr::MainRendererPpsHdr(uint startTime, int duration,
+                                       float exposure_, uint blurringIterationsNum_, float blurringDist_):
+	Event(MAIN_RENDERER_PPS_HDR, startTime, duration)
+{
+	finalData.exposure = exposure_;
+	finalData.blurringIterationsNum = blurringIterationsNum_;
+	finalData.blurringDist = blurringDist_;
+
+	originalData.exposure = MainRendererSingleton::getInstance().getPps().getHdr().getExposure();
+	originalData.blurringIterationsNum =
+		MainRendererSingleton::getInstance().getPps().getHdr().getBlurringIterationsNum();
+	originalData.blurringDist = MainRendererSingleton::getInstance().getPps().getHdr().getBlurringDist();
+}
+
+
+//======================================================================================================================
+// Constructor                                                                                                         =
+//======================================================================================================================
+MainRendererPpsHdr::MainRendererPpsHdr(const MainRendererPpsHdr& b):
+	Event(MAIN_RENDERER_PPS_HDR, 0.0, 0.0)
+{
+	*this = b;
+}
+
+
+//======================================================================================================================
+// operator=                                                                                                           =
+//======================================================================================================================
+MainRendererPpsHdr& MainRendererPpsHdr::operator=(const MainRendererPpsHdr& b)
+{
+	Event::operator=(b);
+	finalData = b.finalData;
+	originalData = b.originalData;
+	return *this;
+}
+
+
+//======================================================================================================================
+// updateSp                                                                                                            =
+//======================================================================================================================
+void MainRendererPpsHdr::updateSp(uint /*prevUpdateTime*/, uint crntTime)
+{
+	float d = crntTime - getStartTime(); // delta
+	float dp = d / getDuration(); // delta as persentage
+
+	MainRendererSingleton::getInstance().getPps().getHdr().setExposure(
+		interpolate(originalData.exposure, finalData.exposure, dp));
+
+	MainRendererSingleton::getInstance().getPps().getHdr().setBlurringIterationsNum(
+		interpolate(originalData.blurringIterationsNum, finalData.blurringIterationsNum, dp));
+
+	MainRendererSingleton::getInstance().getPps().getHdr().setBlurringDist(
+		interpolate(originalData.blurringDist, finalData.blurringDist, dp));
+}
+
+
+} // end namespace

+ 43 - 0
src/Events/EventMainRendererPpsHdr.h

@@ -0,0 +1,43 @@
+#ifndef EVENT_MAIN_RENDERER_PPS_HDR_H
+#define EVENT_MAIN_RENDERER_PPS_HDR_H
+
+#include "Event.h"
+
+
+namespace Event {
+
+
+/// Change the HDR properties
+class MainRendererPpsHdr: public Event
+{
+	public:
+		/// Constructor
+		MainRendererPpsHdr(uint startTime, int duration,
+		                   float exposure, uint blurringIterationsNum, float blurringDist);
+
+		/// Copy constructor
+		MainRendererPpsHdr(const MainRendererPpsHdr& b);
+
+		/// Copy
+		MainRendererPpsHdr& operator=(const MainRendererPpsHdr& b);
+
+	private:
+		struct Data
+		{
+			float exposure; ///< @see Hdr::exposure
+			uint blurringIterationsNum; ///< @see Hdr::blurringIterationsNum
+			float blurringDist; ///< @see Hdr::blurringDist
+		};
+
+		Data originalData; ///< From where do we start
+		Data finalData; ///< Where do we want to go
+
+		/// Implements Event::updateSp
+		void updateSp(uint prevUpdateTime, uint crntTime);
+};
+
+
+} // end namespace
+
+
+#endif

+ 1 - 2
src/Events/EventSceneColor.cpp

@@ -46,8 +46,7 @@ void SceneColor::updateSp(uint /*prevUpdateTime*/, uint crntTime)
 	float d = crntTime - getStartTime(); // delta
 	float dp = d / getDuration(); // delta as persentage
 
-	Vec3 col = originalColor * (1.0 - dp) + finalColor * dp;
-	SceneSingleton::getInstance().setAmbientCol(col);
+	SceneSingleton::getInstance().setAmbientCol(interpolate(originalColor, finalColor, dp));
 }
 
 

+ 3 - 3
src/Renderer/Pps.h

@@ -26,9 +26,9 @@ class Pps: private RenderingPass
 
 		/// @name Accessors
 		/// @{
-		GETTER_R(Hdr, hdr, getHdr)
-		GETTER_R(Ssao, ssao, getSsao)
-		GETTER_R(Bl, bl, getBl)
+		GETTER_RW(Hdr, hdr, getHdr)
+		GETTER_RW(Ssao, ssao, getSsao)
+		GETTER_RW(Bl, bl, getBl)
 		GETTER_R(Texture, prePassFai, getPrePassFai)
 		GETTER_R(Texture, postPassFai, getPostPassFai)
 		/// @}

+ 14 - 0
src/Resources/Core/ResourceManager.cpp

@@ -17,6 +17,20 @@
 #include "Logger.h"
 
 
+//======================================================================================================================
+// Constructor                                                                                                         =
+//======================================================================================================================
+ResourceManager::ResourceManager()
+{}
+
+
+//======================================================================================================================
+// Destructor                                                                                                          =
+//======================================================================================================================
+ResourceManager::~ResourceManager()
+{}
+
+
 // Because we are bored to write the same
 #define SPECIALIZE_TEMPLATE_STUFF(type__, container__) \
 	template<> \

+ 7 - 3
src/Resources/Core/ResourceManager.h

@@ -2,7 +2,7 @@
 #define RESOURCE_MANAGER_H
 
 #include <boost/ptr_container/ptr_vector.hpp>
-#include <memory.h>
+#include <boost/scoped_ptr.hpp>
 #include <string>
 #include "Singleton.h"
 #include "AsyncLoader.h"
@@ -39,6 +39,10 @@ class ResourceManager
 			typedef typename Container::const_iterator ConstIterator;
 		};
 
+		ResourceManager();
+		~ResourceManager();
+
+
 		/// Load a resource
 		/// See if its already loaded, if its not:
 		/// - Create an instance
@@ -76,9 +80,9 @@ class ResourceManager
 		
 		/// This will be used in every new texture until the async loader is finished with the loading of the actual
 		/// texture. Its initialized when its first needed so that we wont have conflicts with opengl initialization.
-		std::auto_ptr<Texture> dummyTex;
+		boost::scoped_ptr<Texture> dummyTex;
 
-		std::auto_ptr<Texture> dummyNormTex; ///< The same as dummyTex but for normals
+		boost::scoped_ptr<Texture> dummyNormTex; ///< The same as dummyTex but for normals
 
 		/// Find a resource using the filename
 		template<typename Type>

+ 1 - 1
src/Scene/ParticleEmitter.h

@@ -2,8 +2,8 @@
 #define PARTICLEEMITTER_H
 
 #include <boost/ptr_container/ptr_vector.hpp>
-#include <btBulletCollisionCommon.h>
 #include <memory>
+#include <btBulletCollisionCommon.h>
 #include "SceneNode.h"
 #include "GhostNode.h"
 #include "ParticleEmitterProps.h"

+ 3 - 3
src/Scene/PatchNode.h

@@ -1,7 +1,7 @@
 #ifndef PATCH_NODE_H
 #define PATCH_NODE_H
 
-#include <memory>
+#include <boost/scoped_ptr.hpp>
 #include "Vao.h"
 #include "Vbo.h"
 #include "Mesh.h" // For the Vbos enum
@@ -44,8 +44,8 @@ class PatchNode: public RenderableNode
 		const ModelPatch& rsrc;
 		Vao dpVao; /// VAO for depth passes. All VBOs could be attached except for the vert weights
 		Vao cpVao; /// VAO for MS and BS. All VBOs could be attached except for the vert weights
-		std::auto_ptr<MaterialRuntime> cpMtlRun;
-		std::auto_ptr<MaterialRuntime> dpMtlRun;
+		boost::scoped_ptr<MaterialRuntime> cpMtlRun;
+		boost::scoped_ptr<MaterialRuntime> dpMtlRun;
 
 		/// Create a VAO given a material and an array of VBOs
 		static void createVao(const Material& material, const boost::array<const Vbo*, Mesh::VBOS_NUM>& vbos, Vao& vao);

+ 3 - 3
src/Scene/Scene.h

@@ -1,7 +1,7 @@
 #ifndef SCENE_H
 #define SCENE_H
 
-#include <memory>
+#include <boost/scoped_ptr.hpp>
 #include "Physics.h"
 #include "Assert.h"
 #include "Accessors.h"
@@ -73,8 +73,8 @@ class Scene
 		/// @}
 
 		Vec3 ambientCol; ///< The global ambient color
-		std::auto_ptr<Physics> physics; ///< Connection with Bullet wrapper
-		std::auto_ptr<VisibilityTester> visibilityTester;
+		boost::scoped_ptr<Physics> physics; ///< Connection with Bullet wrapper
+		boost::scoped_ptr<VisibilityTester> visibilityTester;
 
 		/// Adds a node in a container
 		template<typename ContainerType, typename Type>

+ 4 - 0
src/Scripting/BoostPythonInterfaces.cpp

@@ -25,6 +25,10 @@ BOOST_PYTHON_MODULE(Anki)
 	CALL_WRAP(Dbg);
 	CALL_WRAP(MainRenderer);
 
+	CALL_WRAP(EventSceneColor);
+	CALL_WRAP(EventMainRendererPpsHdr);
+	CALL_WRAP(EventManager);
+
 	CALL_WRAP(App);
 
 	CALL_WRAP(Input);

+ 5 - 0
src/Scripting/Core/Globals.bpi.cpp

@@ -5,6 +5,7 @@
 #include "Input.h"
 #include "Scene.h"
 #include "App.h"
+#include "EventManager.h"
 
 
 WRAP_SINGLETON(LoggerSingleton)
@@ -13,6 +14,9 @@ WRAP_SINGLETON(InputSingleton)
 WRAP_SINGLETON(SceneSingleton)
 WRAP_SINGLETON(AppSingleton)
 
+typedef Event::ManagerSingleton EventManagerSingleton;
+WRAP_SINGLETON(EventManagerSingleton)
+
 
 void boostPythonWrapAllGlobals()
 {
@@ -21,4 +25,5 @@ void boostPythonWrapAllGlobals()
 	CALL_WRAP(InputSingleton);
 	CALL_WRAP(SceneSingleton);
 	CALL_WRAP(AppSingleton);
+	CALL_WRAP(EventManagerSingleton);
 }

+ 11 - 0
src/Scripting/Events/EventMainRendererPpsHdr.bpi.cpp

@@ -0,0 +1,11 @@
+#include "ScriptingCommon.h"
+#include "EventMainRendererPpsHdr.h"
+
+
+WRAP(EventMainRendererPpsHdr)
+{
+	class_<Event::MainRendererPpsHdr>("EventMainRendererPpsHdr", no_init)
+		.def(init<uint, int, float, uint, float>())
+		.def(init<const Event::MainRendererPpsHdr&>())
+	;
+}

+ 14 - 0
src/Scripting/Events/EventManager.bpi.cpp

@@ -0,0 +1,14 @@
+#include "ScriptingCommon.h"
+#include "EventManager.h"
+
+#include "EventSceneColor.h"
+#include "EventMainRendererPpsHdr.h"
+
+
+WRAP(EventManager)
+{
+	class_<Event::Manager, noncopyable>("EventManager", no_init)
+		.def("createEvent", &Event::Manager::createEvent<Event::SceneColor>)
+		.def("createEvent", &Event::Manager::createEvent<Event::MainRendererPpsHdr>)
+	;
+}

+ 11 - 0
src/Scripting/Events/EventSceneColor.bpi.cpp

@@ -0,0 +1,11 @@
+#include "ScriptingCommon.h"
+#include "EventSceneColor.h"
+
+
+WRAP(EventSceneColor)
+{
+	class_<Event::SceneColor>("EventSceneColor", no_init)
+		.def(init<uint, int, const Vec3&>())
+		.def(init<const Event::SceneColor&>())
+	;
+}

+ 2 - 2
src/Scripting/Renderer/Pps.bpi.cpp

@@ -7,7 +7,7 @@
 WRAP(Pps)
 {
 	class_<Pps, noncopyable>("Pps", no_init)
-		.def("getHdr", &Pps::getHdr, return_value_policy<reference_existing_object>())
-		.def("getBl", &Pps::getBl, return_value_policy<reference_existing_object>())
+		.def("getHdr", (Hdr& (Pps::*)())(&Pps::getHdr), return_value_policy<reference_existing_object>())
+		.def("getBl", (Bl& (Pps::*)())(&Pps::getBl), return_value_policy<reference_existing_object>())
 	;
 }

+ 2 - 2
src/Ui/UiFont.h

@@ -1,7 +1,7 @@
 #ifndef UI_FONT_H
 #define UI_FONT_H
 
-#include <memory>
+#include <boost/scoped_ptr.hpp>
 #include <boost/ptr_container/ptr_vector.hpp>
 #include "StdTypes.h"
 #include "Math.h"
@@ -45,7 +45,7 @@ class Font
 			int horizAdvance;
 		};
 
-		std::auto_ptr<Texture> map; ///< The texture map that contains all the glyphs
+		boost::scoped_ptr<Texture> map; ///< The texture map that contains all the glyphs
 		boost::ptr_vector<Glyph> glyphs; ///< A set of glyphs from ' ' to ' ' + 128
 		uint lineHeight;
 

+ 2 - 2
src/Ui/UiPainter.h

@@ -1,7 +1,7 @@
 #ifndef UI_PAINTER_H
 #define UI_PAINTER_H
 
-#include <memory>
+#include <boost/scoped_ptr.hpp>
 #include "RsrcPtr.h"
 #include "Math.h"
 #include "Accessors.h"
@@ -34,7 +34,7 @@ class Painter
 	private:
 		/// @name Data
 		/// @{
-		std::auto_ptr<Font> font;
+		boost::scoped_ptr<Font> font;
 		RsrcPtr<ShaderProg> sProg;
 
 		Vec2 pos;

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini