Просмотр исходного кода

Player exits more gracefully on quit, debuggger improvements in the IDE

Ivan Safrin 13 лет назад
Родитель
Сommit
8a8b1cfa08

+ 2 - 0
Core/Contents/Include/PolyCocoaCore.h

@@ -131,6 +131,8 @@ namespace Polycode {
 		void initGamepad();
 		void shutdownGamepad();
 		
+		void makeApplicationMain();
+		
 		void lockMutex(CoreMutex *mutex);
 		void unlockMutex(CoreMutex *mutex);
 		CoreMutex *createMutex();		

+ 5 - 0
Core/Contents/Include/PolyCore.h

@@ -322,6 +322,11 @@ namespace Polycode {
 		*/
 		String getUserHomeDirectory();	
 		
+		/**
+		* Brings the application on top (Cocoa only for now).
+		*/
+		virtual void makeApplicationMain() {}
+		
 		CoreMutex *getEventMutex();
 		CoreMutex *eventMutex;
 		

+ 1 - 1
Core/Contents/Include/PolySocket.h

@@ -27,7 +27,7 @@ THE SOFTWARE.
 #include "stdio.h"
 
 
-#define MAX_PACKET_SIZE 400
+#define MAX_PACKET_SIZE 1400
 
 // if set to 1, will create a thread for each network socket
 #define USE_THREADED_SOCKETS 0

+ 2 - 0
Core/Contents/PolycodeView/Mac OS X/PolycodeView.mm

@@ -87,6 +87,8 @@
 {	
 	if(core == NULL)
 		return;
+		
+	memset(modifierMap, 0, 512);		
 	
 	core->lockMutex(core->eventMutex);	
 	CocoaEvent newEvent;

+ 4 - 0
Core/Contents/Source/PolyCocoaCore.mm

@@ -467,6 +467,10 @@ void CocoaCore::moveDiskItem(const String& itemPath, const String& destItemPath)
 void CocoaCore::removeDiskItem(const String& itemPath) {
 	[[NSFileManager defaultManager] removeItemAtPath: [NSString stringWithUTF8String: itemPath.c_str()] error:nil];
 }
+
+void CocoaCore::makeApplicationMain() {
+	[NSApp activateIgnoringOtherApps:YES];
+}
 	
 String CocoaCore::openFolderPicker() {
 	unlockMutex(eventMutex);

+ 5 - 0
IDE/Contents/Include/PolycodeConsole.h

@@ -73,6 +73,8 @@ class BackTraceWindow : public UIElement {
 		void handleEvent(Event *event);
 		
 		void addBackTrace(String fileName, int lineNumber, PolycodeProject *project);
+		
+		void clearBackTraces();
 						
 		void Resize(Number width, Number height);
 		
@@ -99,6 +101,9 @@ class PolycodeConsole : public UIElement {
 
 		static void addBacktrace(String fileName, int lineNumber, PolycodeProject *project);
 
+		static void clearBacktraces();
+		void _clearBacktraces();
+		
 		void _addBacktrace(String fileName, int lineNumber, PolycodeProject *project);
 		
 		void Resize(Number width, Number height);

+ 21 - 2
IDE/Contents/Source/PolycodeConsole.cpp

@@ -75,7 +75,8 @@ void BackTraceEntry::Deselect() {
 
 
 BackTraceEntry::~BackTraceEntry() {
-
+	delete label;
+	delete labelBg;
 }
 
 void BackTraceEntry::Resize(Number width, Number height) {
@@ -145,6 +146,16 @@ void BackTraceWindow::addBackTrace(String fileName, int lineNumber, PolycodeProj
 	}
 }
 
+void BackTraceWindow::clearBackTraces() {
+	for(int i=0; i < entries.size(); i++) {
+		removeChild(entries[i]);
+		entries[i]->removeAllHandlers();
+		delete entries[i];
+	}
+	entries.clear();
+	adjustEntries();
+}
+
 BackTraceWindow::~BackTraceWindow() {
 	
 }
@@ -212,10 +223,18 @@ void PolycodeConsole::_addBacktrace(String fileName, int lineNumber, PolycodePro
 	backtraceWindow->addBackTrace(fileName, lineNumber, project);
 }
 
+void PolycodeConsole::clearBacktraces() {
+	instance->_clearBacktraces();
+}
+
+void PolycodeConsole::_clearBacktraces() {
+	backtraceWindow->clearBackTraces();
+}
+
 
 void PolycodeConsole::_print(String msg) {
 	debugTextInput->setText(debugTextInput->getText()+msg);
-	debugTextInput->getScrollContainer()->setScrollValue(0, 1.0);
+	debugTextInput->getScrollContainer()->setScrollValue(0, 1.1);
 }
 
 void PolycodeConsole::Resize(Number width, Number height) {

+ 2 - 0
IDE/Contents/Source/PolycodeIDEApp.cpp

@@ -170,6 +170,8 @@ void PolycodeIDEApp::runProject() {
 		String outPath = PolycodeToolLauncher::generateTempPath() + ".polyapp";
 		PolycodeToolLauncher::buildProject(projectManager->getActiveProject(), outPath);
 		PolycodeToolLauncher::runPolyapp(outPath);
+	} else {
+		PolycodeConsole::print("No active project!\n");
 	}
 }
 

+ 3 - 0
IDE/Contents/Source/PolycodeRemoteDebugger.cpp

@@ -67,6 +67,9 @@ void PolycodeRemoteDebugger::handleEvent(Event *event) {
 							PolycodeConsole::print("Error in file "+String(data->fileName)+" on line "+String::IntToString(data->lineNumber)+"\n");
 							PolycodeConsole::print(String(data->errorMessage)+"\n");
 							PolycodeConsole::print("Backtrace:\n");
+							
+							CoreServices::getInstance()->getCore()->makeApplicationMain();
+							
 						}
 						break;			
 						case EVENT_DEBUG_BACKTRACE_INFO:

+ 10 - 3
IDE/Contents/Source/PolycodeToolLauncher.cpp

@@ -54,6 +54,8 @@ String PolycodeToolLauncher::generateTempPath() {
 
 void PolycodeToolLauncher::buildProject(PolycodeProject *project, String destinationPath) {
 
+	PolycodeConsole::print("Building project: "+project->getProjectName() + "\n");	
+
 	project->saveFile();
 
 	String projectBasePath = project->getRootFolder();
@@ -64,14 +66,17 @@ void PolycodeToolLauncher::buildProject(PolycodeProject *project, String destina
 	
 	String command = "cd "+projectBasePath+" && "+polycodeBasePath+"/Standalone/Bin/polybuild  --config="+projectPath+" --out="+destinationPath;	
 	String ret = CoreServices::getInstance()->getCore()->executeExternalCommand(command);
-	PolycodeConsole::print(ret);	
+//	PolycodeConsole::print(ret);	
 
 }
 
-void PolycodeToolLauncher::runPolyapp(String polyappPath) {		
+void PolycodeToolLauncher::runPolyapp(String polyappPath) {
+
+	PolycodeConsole::clearBacktraces();
+		
 //	PolycodeRunner *runner = new PolycodeRunner(polyappPath);
 //	CoreServices::getInstance()->getCore()->createThread(runner);
-
+							
 #if defined(__APPLE__) && defined(__MACH__)
 	CocoaCore *cocoaCore = (CocoaCore*) CoreServices::getInstance()->getCore();
 
@@ -80,6 +85,8 @@ void PolycodeToolLauncher::runPolyapp(String polyappPath) {
 	
 	cocoaCore->launchApplicationWithFile(command, polyappPath);
 #else
+	PolycodeRunner *runner = new PolycodeRunner(polyappPath);
+	CoreServices::getInstance()->getCore()->createThread(runner);
 
 #endif
 

+ 1 - 1
Modules/Contents/UI/Source/PolyUITextInput.cpp

@@ -702,7 +702,7 @@ String UITextInput::getLineText(unsigned int index) {
 	} else {
 		return "";
 	}
-}
+}       
 
 String UITextInput::getSelectionText() {
 	String totalText = L"";

+ 4 - 2
Player/Contents/Platform/Darwin/MyDocument.mm

@@ -119,14 +119,16 @@ NSMutableAttributedString *str = [[NSMutableAttributedString alloc ]initWithStri
 	}
 }
 
-- (void)canCloseDocumentWithDelegate:(id)delegate shouldCloseSelector:(SEL)shouldCloseSelector contextInfo:(void *)contextInfo
+
+
+- (void)close
 {
 	[timer invalidate];
 	[timer release];	
 	delete player;
 	delete playerProxy;
 	
-	[super canCloseDocumentWithDelegate:delegate shouldCloseSelector:shouldCloseSelector contextInfo:contextInfo];
+	[super close];
 
 }
 

+ 21 - 1
Player/Contents/Source/PolycodePlayer.cpp

@@ -36,6 +36,16 @@ void PolycodeRemoteDebuggerClient::handleEvent(Event *event) {
 		break;
 		case PolycodeDebugEvent::EVENT_ERROR:
 			RemoteErrorData data;
+			
+			if(debugEvent->errorString.length() > 254) {
+				debugEvent->errorString = debugEvent->errorString.substr(0,254);
+			}
+
+			if(debugEvent->fileName.length() > 254) {
+				debugEvent->fileName = debugEvent->fileName.substr(0,254);
+			}
+
+			
 			strcpy(data.errorMessage, debugEvent->errorString.c_str());
 			strcpy(data.fileName, debugEvent->fileName.c_str());
 			data.lineNumber = debugEvent->lineNumber;
@@ -45,6 +55,12 @@ void PolycodeRemoteDebuggerClient::handleEvent(Event *event) {
 			
 			for(int i=0; i < debugEvent->backTrace.size(); i++) {
 				RemoteBacktraceData btData;
+				
+			if(debugEvent->backTrace[i].fileName.length() > 254) {
+				debugEvent->backTrace[i].fileName = debugEvent->backTrace[i].fileName.substr(0,254);
+			}
+				
+				
 				strcpy(btData.fileName, debugEvent->backTrace[i].fileName.c_str());
 				btData.lineNumber = debugEvent->backTrace[i].lineNumber;
 				
@@ -135,7 +151,7 @@ static void dumpstack (lua_State *L) {
 		lua_Debug entry;
 		int depth = 0;		
 		while (lua_getstack(L, depth, &entry)) {
-			int status = lua_getinfo(L, "Sln", &entry);
+			lua_getinfo(L, "Sln", &entry);
 			printf(">>>> %s(%d): %s\n", entry.short_src, entry.currentline, entry.name ? entry.name : "?");
 			std::vector<String> bits = String(entry.short_src).split("\"");
 			if(bits.size() > 1) {
@@ -588,6 +604,10 @@ void PolycodePlayer::loadFile(const char *fileName) {
 	}
 	
 	if(useDebugger) {
+	
+		// clear the other listeners
+		this->removeAllHandlers();
+			
 		remoteDebuggerClient = new PolycodeRemoteDebuggerClient();
 		this->addEventListener(remoteDebuggerClient, PolycodeDebugEvent::EVENT_PRINT);
 		this->addEventListener(remoteDebuggerClient, PolycodeDebugEvent::EVENT_ERROR);