Kaynağa Gözat

Debugging fixes, static method support in bindings

Ivan Safrin 13 yıl önce
ebeveyn
işleme
6fc1529904

+ 16 - 6
Bindings/Scripts/create_lua_library/create_lua_library.py

@@ -137,7 +137,7 @@ def createLUABindings(inputPath, prefix, mainInclude, libSmallName, libName, api
 			f = open(fileName) # Def: Input file handle
 			contents = f.read().replace("_PolyExport", "") # Def: Input file contents, strip out "_PolyExport"
 			cppHeader = CppHeaderParser.CppHeader(contents, "string") # Def: Input file contents, parsed structure
-			ignore_classes = ["PolycodeShaderModule", "Object", "Threaded", "OpenGLCubemap", "ParticleEmitter"]
+			ignore_classes = ["PolycodeShaderModule", "Object", "Threaded", "OpenGLCubemap"]
 
 			# Iterate, check each class in this file.
 			for ckey in cppHeader.classes: 
@@ -148,10 +148,15 @@ def createLUABindings(inputPath, prefix, mainInclude, libSmallName, libName, api
 				inherits = False
 				if len(c["inherits"]) > 0: # Does this class have parents?
 					if c["inherits"][0]["class"] not in ignore_classes:
+
 						if c["inherits"][0]["class"] in inheritInModule: # Parent class is in this module
 							luaClassBindingOut += "require \"%s/%s\"\n\n" % (prefix, c["inherits"][0]["class"])
 						else: # Parent class is in Polycore
 							luaClassBindingOut += "require \"Polycode/%s\"\n\n" % (c["inherits"][0]["class"])
+
+						if (ckey == "ScreenParticleEmitter" or ckey == "SceneParticleEmitter"):
+							luaClassBindingOut += "require \"Polycode/ParticleEmitter\"\n\n"
+
 						luaClassBindingOut += "class \"%s\" (%s)\n\n" % (ckey, c["inherits"][0]["class"])
 						inherits = True
 				if inherits == False: # Class does not have parents
@@ -326,7 +331,9 @@ def createLUABindings(inputPath, prefix, mainInclude, libSmallName, libName, api
 						if pm["rtnType"].find("static ") == -1:
 							wrappersHeaderOut += "\tluaL_checktype(L, 1, LUA_TLIGHTUSERDATA);\n"
 							wrappersHeaderOut += "\t%s *inst = (%s*)lua_topointer(L, 1);\n" % (ckey, ckey)
-						idx = 2
+							idx = 2
+						else:
+							idx = 1
 					
 					if rawMethod:
 						wrappersHeaderOut += "\treturn inst->%s(L);\n" % (pm["name"])
@@ -440,7 +447,7 @@ def createLUABindings(inputPath, prefix, mainInclude, libSmallName, libName, api
 									outfunc = "lua_pushstring"
 									basicType = True
 									retFunc = ".c_str()"
-								if pm["rtnType"] == "int" or pm["rtnType"] == "static int" or  pm["rtnType"] == "size_t" or pm["rtnType"] == "static size_t" or pm["rtnType"] == "long" or pm["rtnType"] == "unsigned int" or pm["rtnType"] == "static long":
+								if pm["rtnType"] == "int" or pm["rtnType"] == "unsigned int" or pm["rtnType"] == "static int" or  pm["rtnType"] == "size_t" or pm["rtnType"] == "static size_t" or pm["rtnType"] == "long" or pm["rtnType"] == "unsigned int" or pm["rtnType"] == "static long":
 									outfunc = "lua_pushinteger"
 									basicType = True
 								if pm["rtnType"] == "bool" or pm["rtnType"] == "static bool" or pm["rtnType"] == "virtual bool":
@@ -497,14 +504,15 @@ def createLUABindings(inputPath, prefix, mainInclude, libSmallName, libName, api
 						luaClassBindingOut += "\t\t__ptr_lookup.%s[self.__ptr] = self\n" % (ckey)
 						luaClassBindingOut += "\tend\n"
 						luaClassBindingOut += "end\n\n"
-					else: # Non-constructors.
-						luaClassBindingOut += "function %s:%s(%s)\n" % (ckey, pm["name"], ", ".join(paramlist))
+					else: # Non-constructors.						
 						if pm["rtnType"].find("static ") == -1: # Non-static method
+							luaClassBindingOut += "function %s:%s(%s)\n" % (ckey, pm["name"], ", ".join(paramlist))						
 							if len(lparamlist):
 								luaClassBindingOut += "\tlocal retVal = %s.%s_%s(self.__ptr, %s)\n" % (libName, ckey, pm["name"], ", ".join(lparamlist))
 							else:
 								luaClassBindingOut += "\tlocal retVal =  %s.%s_%s(self.__ptr)\n" % (libName, ckey, pm["name"])
 						else: # Static method
+							luaClassBindingOut += "function %s_%s(%s)\n" % (ckey, pm["name"], ", ".join(paramlist))
 							if len(lparamlist):
 								luaClassBindingOut += "\tlocal retVal = %s.%s_%s(%s)\n" % (libName, ckey, pm["name"], ", ".join(lparamlist))
 							else:
@@ -532,10 +540,12 @@ def createLUABindings(inputPath, prefix, mainInclude, libSmallName, libName, api
 				wrappersHeaderOut += "\treturn 0;\n"
 				wrappersHeaderOut += "}\n\n"
 
-				# Delete method (Lua side)
+				
 				luaClassBindingOut += "\n\n"
 				luaClassBindingOut += "if not __ptr_lookup then __ptr_lookup = {} end\n"
 				luaClassBindingOut += "__ptr_lookup.%s = {}\n\n" % (ckey)
+				
+				# Delete method (Lua side)
 				luaClassBindingOut += "function %s:__delete()\n" % (ckey)
 				luaClassBindingOut += "\t__ptr_lookup.%s[self.__ptr] = nil\n" % (ckey)
 				luaClassBindingOut += "\t%s.delete_%s(self.__ptr)\n" % (libName, ckey)

+ 22 - 0
Core/Contents/Include/PolyParticleEmitter.h

@@ -277,6 +277,17 @@ namespace Polycode {
 		
 		void dispatchTriggerCompleteEvent();
 		
+			/**
+			* Continuous emitter setting.
+			*/ 																													
+			static const int CONTINUOUS_EMITTER = 0;
+
+			/**
+			* Triggered emitter setting.
+			*/ 																																
+			static const int TRIGGERED_EMITTER = 1;
+		
+		
 	protected:
 		SceneMesh *emitterMesh;		
 		Scene *particleParentScene;
@@ -301,6 +312,17 @@ namespace Polycode {
 		Matrix4 getBaseMatrix();
 		void Update();
 		
+			/**
+			* Continuous emitter setting.
+			*/ 																													
+			static const int CONTINUOUS_EMITTER = 0;
+
+			/**
+			* Triggered emitter setting.
+			*/ 																																
+			static const int TRIGGERED_EMITTER = 1;
+		
+		
 	protected:
 		ScreenMesh *emitterMesh;		
 		Screen *particleParentScreen;

+ 7 - 1
Core/Contents/Include/PolySceneMesh.h

@@ -48,12 +48,18 @@ namespace Polycode {
 			* Construct an empty scene mesh with the specified type.
 			* @param meshType Mesh type to create. Possible values are: Mesh::QUAD_MESH, Mesh::TRI_MESH, Mesh::TRIFAN_MESH, Mesh::TRISTRIP_MESH, Mesh::LINE_MESH, Mesh::POINT_MESH.
 			*/			
-			SceneMesh(int meshType);
+			SceneMesh(int meshType);		
 			
 			/**
 			* Construct scene mesh from an existing Mesh instance.
 			*/
 			SceneMesh(Mesh *mesh);
+			
+			/**
+			* Static wrapper for Lua
+			*/
+			static SceneMesh *SceneMeshFromMesh(Mesh *mesh);
+			
 			virtual ~SceneMesh();
 			
 			void Render();

+ 10 - 0
Core/Contents/Source/PolySceneMesh.cpp

@@ -35,6 +35,10 @@
 
 using namespace Polycode;
 
+SceneMesh *SceneMesh::SceneMeshFromMesh(Mesh *mesh) {
+	return new SceneMesh(mesh);
+}
+
 SceneMesh::SceneMesh(const String& fileName) : SceneEntity(), texture(NULL), material(NULL), skeleton(NULL), localShaderOptions(NULL) {
 	mesh = new Mesh(fileName);
 	bBoxRadius = mesh->getRadius();
@@ -101,6 +105,12 @@ void SceneMesh::setTexture(Texture *texture) {
 }
 
 void SceneMesh::setMaterial(Material *material) {
+	if(!material)
+		return;
+		
+	if(material->getNumShaders() == 0)
+			return;
+		
 	this->material = material;
 	localShaderOptions = material->getShader(0)->createBinding();
 	if(texture) {

+ 3 - 0
Core/Contents/Source/PolyScreen.cpp

@@ -183,6 +183,9 @@ void Screen::setScreenShader(const String& shaderName) {
 	filterShaderMaterial = (Material*)CoreServices::getInstance()->getResourceManager()->getResource(Resource::RESOURCE_MATERIAL, shaderName);
 	if(!filterShaderMaterial)
 		return;
+		
+	if(filterShaderMaterial->getNumShaders() == 0)
+		return;
 	
 	if(!originalSceneTexture) {
 		CoreServices::getInstance()->getRenderer()->createRenderTextures(&originalSceneTexture, NULL, CoreServices::getInstance()->getCore()->getXRes(), CoreServices::getInstance()->getCore()->getYRes(), filterShaderMaterial->fp16RenderTargets);

+ 1 - 1
IDE/Contents/Include/PolycodeToolLauncher.h

@@ -39,7 +39,7 @@ class PolycodeToolLauncher {
 		PolycodeToolLauncher();
 		~PolycodeToolLauncher();		
 		
-		static String generateTempPath();
+		static String generateTempPath(PolycodeProject *project);
 		static void buildProject(PolycodeProject *project, String destinationPath);
 
 		static void runPolyapp(String polyappPath);

+ 1 - 1
IDE/Contents/Source/PolycodeIDEApp.cpp

@@ -178,7 +178,7 @@ void PolycodeIDEApp::runProject() {
 	stopProject();
 
 	if(projectManager->getActiveProject()) {
-		String outPath = PolycodeToolLauncher::generateTempPath() + ".polyapp";
+		String outPath = PolycodeToolLauncher::generateTempPath(projectManager->getActiveProject()) + ".polyapp";
 		PolycodeToolLauncher::buildProject(projectManager->getActiveProject(), outPath);
 		PolycodeToolLauncher::runPolyapp(outPath);
 	} else {

+ 2 - 2
IDE/Contents/Source/PolycodeToolLauncher.cpp

@@ -48,8 +48,8 @@ PolycodeToolLauncher::~PolycodeToolLauncher() {
 
 }
 
-String PolycodeToolLauncher::generateTempPath() {
-	return "/tmp/"+String::IntToString(rand() % 10000000);
+String PolycodeToolLauncher::generateTempPath(PolycodeProject *project) {
+	return "/tmp/"+project->getProjectName();
 }
 
 void PolycodeToolLauncher::buildProject(PolycodeProject *project, String destinationPath) {

+ 4 - 0
Player/Contents/Include/PolycodePlayer.h

@@ -133,9 +133,13 @@ public:
 	String fullPath;
 	
 	bool useDebugger;	
+	
+	bool crashed;
 		
 protected:
 
+	int errH;
+
 	Timer *debuggerTimer;
 	
 	PolycodeRemoteDebuggerClient *remoteDebuggerClient;

+ 56 - 22
Player/Contents/Source/PolycodePlayer.cpp

@@ -157,7 +157,9 @@ static void dumpstack (lua_State *L) {
 
 	static int customError(lua_State *L) {
 		
+		
 		PolycodePlayer *player = (PolycodePlayer*)CoreServices::getInstance()->getCore()->getUserPointer();		
+		player->crashed = true;
 		
 		std::vector<BackTraceEntry> backTrace;
 		lua_Debug entry;
@@ -180,12 +182,32 @@ static void dumpstack (lua_State *L) {
 			}
 			depth++;
 		}
-		
-		if(backTrace.size() < 1)
-			return 0;
-			
-		backTrace[backTrace.size()-1].fileName = player->fullPath;
 
+		// horrible hack to determine the filenames of things
+		bool stringThatIsTheMainFileSet = false;
+		String stringThatIsTheMainFile;
+		
+		if(backTrace.size() == 0) {
+					
+					BackTraceEntry trace;
+					trace.lineNumber = 0;
+					trace.fileName = player->fullPath;
+					backTrace.push_back(trace);
+		
+		} else {
+			stringThatIsTheMainFileSet = true;
+			stringThatIsTheMainFile = backTrace[backTrace.size()-1].fileName;
+			backTrace[backTrace.size()-1].fileName = player->fullPath;
+		}
+		
+		if(stringThatIsTheMainFileSet) {
+			for(int i=0; i < backTrace.size(); i++) {
+				if(backTrace[i].fileName == stringThatIsTheMainFile) {
+					backTrace[i].fileName = player->fullPath;
+				}
+			}
+		}
+		
 		const char *msg = lua_tostring(L, -1);		
 		if (msg == NULL) msg = "(error with no message)";
 		lua_pop(L, 1);
@@ -227,21 +249,15 @@ static void dumpstack (lua_State *L) {
 	
 	
 	int PolycodePlayer::report (lua_State *L, int status) {
-		const char *msg;			
+		const char *msg;		
+		
+		PolycodePlayer *player = (PolycodePlayer*)CoreServices::getInstance()->getCore()->getUserPointer();					
 			
 		Logger::log("Error status: %d\n", status);
 		if (status) {		
 		
-//			dumpstack(L);
-//	traceback(L);
-
-/*		
-			lua_Debug ar;
-			if(lua_getstack(L, 1, &ar)) {
-				lua_getinfo(L, "Sl", &ar);
-				printf("NEW SHIT: source: %s, line: %d\n", ar.source, ar.currentline);
-			}
-*/		
+			std::vector<BackTraceEntry> backTrace;
+					
 			msg = lua_tostring(L, -1);
 			if (msg == NULL) msg = "(error with no message)";
 			Logger::log("status=%d, %s\n", status, msg);
@@ -249,14 +265,28 @@ static void dumpstack (lua_State *L) {
 			
 			std::vector<String> info = String(msg).split(":");
 			
+			BackTraceEntry trace;
+						
 			PolycodeDebugEvent *event = new PolycodeDebugEvent();			
 			if(info.size() > 2) {
 				event->errorString = info[2];
 				event->lineNumber = atoi(info[1].c_str());
+				event->fileName = player->fullPath; 
+				trace.lineNumber = event->lineNumber;
+				trace.fileName = event->fileName;
 			} else {
 				event->errorString = std::string(msg);
 				event->lineNumber = 0;
+				event->fileName = player->fullPath; 								
+				trace.fileName = event->fileName;
+				trace.lineNumber = 0;
 			}
+			
+			
+			backTrace.push_back(trace);
+			
+			event->backTrace = backTrace;
+			
 			dispatchEvent(event, PolycodeDebugEvent::EVENT_ERROR);
 			
 		}
@@ -393,7 +423,7 @@ static void dumpstack (lua_State *L) {
 		
 
 		lua_getfield (L, LUA_GLOBALSINDEX, "__customError");
-		int errH = lua_gettop(L);
+		errH = lua_gettop(L);
 
 		//CoreServices::getInstance()->getCore()->lockMutex(CoreServices::getRenderMutex());			
 		if (report(L, luaL_loadstring(L, fullScript.c_str()))) {			
@@ -422,6 +452,7 @@ PolycodeDebugEvent::~PolycodeDebugEvent() {
 PolycodePlayer::PolycodePlayer(String fileName, bool knownArchive, bool useDebugger) : EventDispatcher()  {
 	L = NULL;
 
+	crashed = false;
 	doCodeInject = false;
 	this->useDebugger = useDebugger;
 	fileToRun = fileName;
@@ -701,16 +732,19 @@ void PolycodePlayer::handleEvent(Event *event) {
 
 bool PolycodePlayer::Update() {
 	if(L) {
-		
+				
 		if(doCodeInject) {
 			printf("INJECTING CODE:[%s]\n", injectCodeString.c_str());
 			doCodeInject = false;			
-			report(L, luaL_loadstring(L, injectCodeString.c_str()) || lua_pcall(L, 0,0,0));		
+			report(L, luaL_loadstring(L, injectCodeString.c_str()));
+			lua_pcall(L, 0,0,errH);		
 		}
 	
-		lua_getfield(L, LUA_GLOBALSINDEX, "Update");
-		lua_pushnumber(L, core->getElapsed());
-		lua_call(L, 1, 0);
+		if(!crashed) {
+			lua_getfield(L, LUA_GLOBALSINDEX, "Update");
+			lua_pushnumber(L, core->getElapsed());
+			lua_pcall(L, 1,0,errH);
+		}
 	}
 	return core->Update();
 }