Panagiotis Christopoulos Charitos 14 anos atrás
pai
commit
0bd9c174f1

+ 4 - 4
src/Main.cpp

@@ -26,7 +26,7 @@
 #include "r/MainRenderer.h"
 #include "phys/Character.h"
 #include "phys/RigidBody.h"
-#include "script/ScriptingEngine.h"
+#include "script/Engine.h"
 #include "core/StdinListener.h"
 #include "scene/ModelNode.h"
 #include "rsrc/Model.h"
@@ -335,7 +335,7 @@ void mainLoopExtra()
 	if(InputSingleton::get().getKey(SDL_SCANCODE_Y) == 1)
 	{
 		INFO("Exec script");
-		ScriptingEngineSingleton::get().execScript(util::readFile("test.py").c_str());
+		script::EngineSingleton::get().execScript(util::readFile("test.py").c_str());
 	}
 
 	mover->getLocalTransform().getRotation().reorthogonalize();
@@ -512,7 +512,7 @@ void initSubsystems(int argc, char* argv[])
 		"sys.stdout = StdoutCatcher()\n"
 		"sys.stderr = StderrCatcher()\n";
 
-	ScriptingEngineSingleton::get().execScript(commonPythonCode);
+	script::EngineSingleton::get().execScript(commonPythonCode);
 
 	// Stdin listener
 	StdinListenerSingleton::get().start();
@@ -544,7 +544,7 @@ void execStdinScpripts()
 
 		try
 		{
-			ScriptingEngineSingleton::get().execScript(cmd.c_str(),
+			script::EngineSingleton::get().execScript(cmd.c_str(),
 				"command line input");
 		}
 		catch(Exception& e)

+ 4 - 1
src/core/Globals.h

@@ -16,7 +16,10 @@ typedef Singleton<class Scene> SceneSingleton;
 typedef Singleton<class App> AppSingleton;
 typedef Singleton<class StdinListener> StdinListenerSingleton;
 typedef Singleton<class GlStateMachine> GlStateMachineSingleton;
-typedef Singleton<class ScriptingEngine> ScriptingEngineSingleton;
+
+namespace script {
+typedef Singleton<class Engine> EngineSingleton;
+}
 
 namespace event {
 typedef Singleton<class Manager> ManagerSingleton;

+ 0 - 1
src/core/StdinListener.h

@@ -5,7 +5,6 @@
 #include <boost/thread/mutex.hpp>
 #include <string>
 #include <queue>
-#include "util/Singleton.h"
 
 
 /// The listener of the stdin.

+ 0 - 1
src/i/Input.h

@@ -2,7 +2,6 @@
 #define INPUT_H
 
 #include "m/Math.h"
-#include "util/Singleton.h"
 #include "util/Accessors.h"
 #include <SDL/SDL_scancode.h>
 #include <boost/array.hpp>

+ 0 - 1
src/r/MainRenderer.h

@@ -2,7 +2,6 @@
 #define R_MAIN_RENDERER_H
 
 #include "Renderer.h"
-#include "util/Singleton.h"
 #include <boost/scoped_ptr.hpp>
 
 

+ 1 - 1
src/rsrc/ShaderProgramPrePreprocessor.cpp

@@ -349,7 +349,7 @@ void ShaderProgramPrePreprocessor::parseTrffbVarying(scanner::Scanner& scanner,
 // addLinePreProcExpression                                                    =
 //==============================================================================
 void ShaderProgramPrePreprocessor::addLinePreProcExpression(
-	uint line, uint depth, const char* cmnt)
+	uint /*line*/, uint /*depth*/, const char* /*cmnt*/)
 {
 	/*sourceLines.push_back("#line " +
 		boost::lexical_cast<std::string>(line) +

+ 0 - 40
src/script/BoostPythonInterfaces.cpp

@@ -1,40 +0,0 @@
-#include <boost/python.hpp>
-#include "ScriptingCommon.h"
-
-
-BOOST_PYTHON_MODULE(Anki)
-{
-	CALL_WRAP(HighRezTimer);
-
-	CALL_WRAP(Vec2);
-	CALL_WRAP(Vec3);
-	CALL_WRAP(Vec4);
-
-	CALL_WRAP(Logger);
-
-	CALL_WRAP(SceneNode);
-	CALL_WRAP(Camera);
-	CALL_WRAP(MaterialRuntimeVariable);
-	CALL_WRAP(MaterialRuntime);
-	CALL_WRAP(PatchNode);
-	CALL_WRAP(ModelPatchNode);
-	CALL_WRAP(ModelNode);
-	CALL_WRAP(Scene);
-
-	CALL_WRAP(Hdr);
-	CALL_WRAP(Bl);
-	CALL_WRAP(Pps);
-	CALL_WRAP(Renderer);
-	CALL_WRAP(Dbg);
-	CALL_WRAP(MainRenderer);
-
-	CALL_WRAP(EventSceneColor);
-	CALL_WRAP(EventMainRendererPpsHdr);
-	CALL_WRAP(EventManager);
-
-	CALL_WRAP(App);
-
-	CALL_WRAP(Input);
-
-	CALL_WRAP(AllGlobals);
-}

+ 4 - 23
src/script/ScriptingCommon.h → src/script/Common.h

@@ -1,3 +1,6 @@
+#ifndef SCRIPT_COMMON_H
+#define SCRIPT_COMMON_H
+
 /// @file
 /// This file is included by all the *.bpi.cpp files
 #include <boost/python.hpp>
@@ -59,26 +62,4 @@ void setterSv(ClassType* t, InType in)
 		&setterSv<Class__, Type__, &Class__::setter__>)
 
 
-//==============================================================================
-// Math library stuff                                                          =
-//==============================================================================
-
-template<typename ClassType, typename RetType,
-	RetType (ClassType::* accessor)() const>
-RetType getM(const ClassType* t)
-{
-	return (t->*accessor)();
-}
-
-
-template<typename ClassType, typename InType, InType& (ClassType::* accessor)()>
-void setM(ClassType* t, InType in)
-{
-	(t->*accessor)() = in;
-}
-
-
-#define BP_PROPERTY_MATH(ClassType__, name__) \
-	.add_property(#name__, &getM<ClassType__, float, &ClassType__::name__>, \
-		&setM<ClassType__, float, &ClassType__::name__>)
-
+#endif

+ 89 - 0
src/script/Engine.cpp

@@ -0,0 +1,89 @@
+#include "Engine.h"
+#include "util/Exception.h"
+#include "core/Logger.h"
+#include "core/Globals.h"
+#include "Common.h"
+#include <Python.h>
+
+
+/// Define the classes
+BOOST_PYTHON_MODULE(Anki)
+{
+	CALL_WRAP(HighRezTimer);
+
+	CALL_WRAP(Vec2);
+	CALL_WRAP(Vec3);
+	CALL_WRAP(Vec4);
+
+	CALL_WRAP(Logger);
+
+	CALL_WRAP(SceneNode);
+	CALL_WRAP(Camera);
+	CALL_WRAP(MaterialRuntimeVariable);
+	CALL_WRAP(MaterialRuntime);
+	CALL_WRAP(PatchNode);
+	CALL_WRAP(ModelPatchNode);
+	CALL_WRAP(ModelNode);
+	CALL_WRAP(Scene);
+
+	CALL_WRAP(Hdr);
+	CALL_WRAP(Bl);
+	CALL_WRAP(Pps);
+	CALL_WRAP(Renderer);
+	CALL_WRAP(Dbg);
+	CALL_WRAP(MainRenderer);
+
+	CALL_WRAP(EventSceneColor);
+	CALL_WRAP(EventMainRendererPpsHdr);
+	CALL_WRAP(EventManager);
+
+	CALL_WRAP(App);
+
+	CALL_WRAP(Input);
+
+	CALL_WRAP(AllGlobals);
+}
+
+
+namespace script {
+
+
+using namespace boost::python;
+
+
+//==============================================================================
+// init                                                                        =
+//==============================================================================
+void Engine::init()
+{
+	INFO("Initializing scripting engine...");
+
+	PyImport_AppendInittab((char*)("Anki"), &initAnki);
+	Py_Initialize();
+	mainModule = object(handle<>(borrowed(PyImport_AddModule("__main__"))));
+	mainNamespace = mainModule.attr("__dict__");
+	ankiModule = object(handle<>(PyImport_ImportModule("Anki")));
+
+	INFO("Scripting engine initialized");
+}
+
+
+//==============================================================================
+// execScript                                                                  =
+//==============================================================================
+void Engine::execScript(const char* script, const char* scriptName)
+{
+	try
+	{
+		handle<>ignored(PyRun_String(script, Py_file_input,
+			mainNamespace.ptr(), mainNamespace.ptr()));
+	}
+	catch(error_already_set)
+	{
+		PyErr_Print();
+		throw EXCEPTION("Script \"" + scriptName + "\" failed with error");
+	}
+}
+
+
+} // end namespace

+ 11 - 6
src/script/ScriptingEngine.h → src/script/Engine.h

@@ -1,15 +1,17 @@
-#ifndef SCRIPTING_ENGINE_H
-#define SCRIPTING_ENGINE_H
+#ifndef SCRIPT_ENGINE_H
+#define SCRIPT_ENGINE_H
 
 #include <boost/python.hpp>
-#include "util/Singleton.h"
+
+
+namespace script {
 
 
 /// The scripting engine using Python
-class ScriptingEngine
+class Engine
 {
 	public:
-		ScriptingEngine() {init();}
+		Engine() {init();}
 
 		/// Execute python script
 		/// @param script Script source
@@ -32,10 +34,13 @@ class ScriptingEngine
 
 
 template<typename Type>
-inline void ScriptingEngine::exposeVar(const char* varName, Type* var)
+inline void Engine::exposeVar(const char* varName, Type* var)
 {
 	boost::python::scope(ankiModule).attr(varName) = boost::python::ptr(var);
 }
 
 
+} // end namespace
+
+
 #endif

+ 0 - 47
src/script/ScriptingEngine.cpp

@@ -1,47 +0,0 @@
-#include <Python.h>
-#include "ScriptingEngine.h"
-#include "util/Exception.h"
-#include "core/Logger.h"
-#include "core/Globals.h"
-
-
-/// Defined in BoostPythonInterfaces.cpp by boost::python
-extern "C" void initAnki();
-
-
-//==============================================================================
-// init                                                                        =
-//==============================================================================
-void ScriptingEngine::init()
-{
-	INFO("Initializing scripting engine...");
-
-	PyImport_AppendInittab((char*)("Anki"), &initAnki);
-	Py_Initialize();
-	mainModule = boost::python::object(boost::python::handle<>(
-		boost::python::borrowed(PyImport_AddModule("__main__"))));
-	mainNamespace = mainModule.attr("__dict__");
-	ankiModule = boost::python::object(
-		boost::python::handle<>(PyImport_ImportModule("Anki")));
-
-	INFO("Scripting engine initialized");
-}
-
-
-//==============================================================================
-// execScript                                                                  =
-//==============================================================================
-void ScriptingEngine::execScript(const char* script, const char* scriptName)
-{
-	try
-	{
-		boost::python::handle<>ignored(PyRun_String(script, Py_file_input,
-			mainNamespace.ptr(), mainNamespace.ptr()));
-	}
-	catch(boost::python::error_already_set)
-	{
-		PyErr_Print();
-		throw EXCEPTION("Script \"" + scriptName + "\" failed with error");
-	}
-}
-

+ 1 - 1
src/script/core/App.bpi.cpp → src/script/core/App.cpp

@@ -1,4 +1,4 @@
-#include "ScriptingCommon.h"
+#include "Common.h"
 #include "core/App.h"
 
 

+ 1 - 1
src/script/core/Globals.bpi.cpp → src/script/core/Globals.cpp

@@ -1,4 +1,4 @@
-#include "ScriptingCommon.h"
+#include "Common.h"
 #include "core/Globals.h"
 #include "core/Logger.h"
 #include "r/MainRenderer.h"

+ 1 - 1
src/script/core/Logger.bpi.cpp → src/script/core/Logger.cpp

@@ -1,4 +1,4 @@
-#include "ScriptingCommon.h"
+#include "Common.h"
 #include "core/Logger.h"
 
 

+ 1 - 1
src/script/event/MainRendererPpsHdr.bpi.cpp → src/script/event/MainRendererPpsHdr.cpp

@@ -1,4 +1,4 @@
-#include "ScriptingCommon.h"
+#include "Common.h"
 #include "event/MainRendererPpsHdr.h"
 
 

+ 1 - 1
src/script/event/Manager.bpi.cpp → src/script/event/Manager.cpp

@@ -1,4 +1,4 @@
-#include "ScriptingCommon.h"
+#include "Common.h"
 #include "event/Manager.h"
 
 #include "event/SceneColor.h"

+ 1 - 1
src/script/event/SceneColor.bpi.cpp → src/script/event/SceneColor.cpp

@@ -1,4 +1,4 @@
-#include "ScriptingCommon.h"
+#include "Common.h"
 #include "event/SceneColor.h"
 
 

+ 1 - 1
src/script/i/Input.bpi.cpp → src/script/i/Input.cpp

@@ -1,4 +1,4 @@
-#include "ScriptingCommon.h"
+#include "Common.h"
 #include "i/Input.h"
 
 

+ 27 - 0
src/script/m/Common.h

@@ -0,0 +1,27 @@
+#ifndef SCRIPT_M_COMMON_H
+#define SCRIPT_M_COMMON_H
+
+#include "../Common.h"
+
+
+template<typename ClassType, typename RetType,
+	RetType (ClassType::* accessor)() const>
+RetType getM(const ClassType* t)
+{
+	return (t->*accessor)();
+}
+
+
+template<typename ClassType, typename InType, InType& (ClassType::* accessor)()>
+void setM(ClassType* t, InType in)
+{
+	(t->*accessor)() = in;
+}
+
+
+#define BP_PROPERTY_MATH(ClassType__, name__) \
+	.add_property(#name__, &getM<ClassType__, float, &ClassType__::name__>, \
+		&setM<ClassType__, float, &ClassType__::name__>)
+
+
+#endif

+ 1 - 1
src/script/m/Vec2.bpi.cpp → src/script/m/Vec2.cpp

@@ -1,4 +1,4 @@
-#include "ScriptingCommon.h"
+#include "Common.h"
 #include "m/Math.h"
 
 

+ 1 - 1
src/script/m/Vec3.bpi.cpp → src/script/m/Vec3.cpp

@@ -1,4 +1,4 @@
-#include "ScriptingCommon.h"
+#include "Common.h"
 #include "m/Math.h"
 
 

+ 1 - 1
src/script/m/Vec4.bpi.cpp → src/script/m/Vec4.cpp

@@ -1,4 +1,4 @@
-#include "ScriptingCommon.h"
+#include "Common.h"
 #include "m/Math.h"
 
 

+ 1 - 1
src/script/r/Bl.bpi.cpp → src/script/r/Bl.cpp

@@ -1,4 +1,4 @@
-#include "ScriptingCommon.h"
+#include "Common.h"
 #include "r/Bl.h"
 
 

+ 1 - 1
src/script/r/Dbg.bpi.cpp → src/script/r/Dbg.cpp

@@ -1,4 +1,4 @@
-#include "ScriptingCommon.h"
+#include "Common.h"
 #include "r/Dbg.h"
 
 

+ 1 - 1
src/script/r/Hdr.bpi.cpp → src/script/r/Hdr.cpp

@@ -1,4 +1,4 @@
-#include "ScriptingCommon.h"
+#include "Common.h"
 #include "r/Hdr.h"
 
 

+ 1 - 1
src/script/r/MainRenderer.bpi.cpp → src/script/r/MainRenderer.cpp

@@ -1,4 +1,4 @@
-#include "ScriptingCommon.h"
+#include "Common.h"
 #include "r/MainRenderer.h"
 #include "r/Dbg.h"
 

+ 1 - 1
src/script/r/Pps.bpi.cpp → src/script/r/Pps.cpp

@@ -1,4 +1,4 @@
-#include "ScriptingCommon.h"
+#include "Common.h"
 #include "r/Pps.h"
 #include "r/Hdr.h"
 #include "r/Bl.h"

+ 1 - 1
src/script/r/Renderer.bpi.cpp → src/script/r/Renderer.cpp

@@ -1,4 +1,4 @@
-#include "ScriptingCommon.h"
+#include "Common.h"
 #include "r/Renderer.h"
 
 

+ 1 - 1
src/script/scene/Camera.bpi.cpp → src/script/scene/Camera.cpp

@@ -1,4 +1,4 @@
-#include "ScriptingCommon.h"
+#include "Common.h"
 #include "scene/Camera.h"
 
 

+ 1 - 1
src/script/scene/MaterialRuntime.bpi.cpp → src/script/scene/MaterialRuntime.cpp

@@ -1,4 +1,4 @@
-#include "ScriptingCommon.h"
+#include "Common.h"
 #include "scene/MaterialRuntime.h"
 
 

+ 1 - 1
src/script/scene/MaterialRuntimeVariable.bpi.cpp → src/script/scene/MaterialRuntimeVariable.cpp

@@ -1,4 +1,4 @@
-#include "ScriptingCommon.h"
+#include "Common.h"
 #include "scene/MaterialRuntimeVariable.h"
 
 

+ 1 - 1
src/script/scene/ModelNode.bpi.cpp → src/script/scene/ModelNode.cpp

@@ -1,4 +1,4 @@
-#include "ScriptingCommon.h"
+#include "Common.h"
 #include "scene/ModelNode.h"
 
 

+ 1 - 1
src/script/scene/ModelPatchNode.bpi.cpp → src/script/scene/ModelPatchNode.cpp

@@ -1,4 +1,4 @@
-#include "ScriptingCommon.h"
+#include "Common.h"
 #include "scene/ModelPatchNode.h"
 
 

+ 1 - 1
src/script/scene/PatchNode.bpi.cpp → src/script/scene/PatchNode.cpp

@@ -1,4 +1,4 @@
-#include "ScriptingCommon.h"
+#include "Common.h"
 #include "scene/PatchNode.h"
 
 

+ 1 - 1
src/script/scene/Scene.bpi.cpp → src/script/scene/Scene.cpp

@@ -1,4 +1,4 @@
-#include "ScriptingCommon.h"
+#include "Common.h"
 #include "scene/Scene.h"
 #include "scene/Camera.h"
 #include "scene/ModelNode.h"

+ 1 - 1
src/script/scene/SceneNode.bpi.cpp → src/script/scene/SceneNode.cpp

@@ -1,4 +1,4 @@
-#include "ScriptingCommon.h"
+#include "Common.h"
 #include "scene/SceneNode.h"
 
 

+ 1 - 1
src/script/util/HighRezTimer.bpi.cpp → src/script/util/HighRezTimer.cpp

@@ -1,4 +1,4 @@
-#include "ScriptingCommon.h"
+#include "Common.h"
 #include "util/HighRezTimer.h"
 
 

+ 8 - 4
src/util/Exception.cpp

@@ -1,5 +1,5 @@
-#include <boost/lexical_cast.hpp>
 #include "util/Exception.h"
+#include <sstream>
 
 
 //==============================================================================
@@ -30,8 +30,10 @@ Exception::Exception(const Exception& e):
 //==============================================================================
 std::string Exception::getInfoStr() const
 {
-	return std::string("(") + file + ":" + 
-		boost::lexical_cast<std::string>(line) + " " + func + ")";
+	std::stringstream ss;
+	
+	ss << '(' << file << ':' << line << ' ' << func << ')';
+	return ss.str();
 }
 
 
@@ -40,6 +42,8 @@ std::string Exception::getInfoStr() const
 //==============================================================================
 const char* Exception::what() const throw()
 {
-	errWhat = "\n" + getInfoStr() + " " + err;
+	std::stringstream ss(errWhat);
+
+	ss << "AnKi exception: " << getInfoStr() << " " << err;
 	return errWhat.c_str();
 }