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

Core pausing on lose focus, IDE will now pause core on lose focus

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

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

@@ -340,6 +340,8 @@ namespace Polycode {
 		static const int CURSOR_RESIZE_UP_DOWN = 5;
 		static const int CURSOR_OPEN_HAND = 6;		
 		
+		bool paused;
+		bool pauseOnLoseFocus;
 				
 	protected:	
 	

+ 9 - 5
Core/Contents/Source/PolyCocoaCore.mm

@@ -532,13 +532,17 @@ vector<String> CocoaCore::openFilePicker(vector<CoreFileExtension> extensions, b
 bool CocoaCore::Update() {
 	if(!running)
 		return false;
-		
+	
 	lockMutex(CoreServices::getRenderMutex());	
 	checkEvents();
-	renderer->BeginRender();
-	updateCore();
-	renderer->EndRender();
-	[context flushBuffer];
+	
+	if(!paused) {	
+		renderer->BeginRender();
+		updateCore();
+		renderer->EndRender();
+		[context flushBuffer];
+	}
+	
 	unlockMutex(CoreServices::getRenderMutex());	
 	doSleep();	
 	return running;

+ 10 - 1
Core/Contents/Source/PolyCore.cpp

@@ -63,6 +63,8 @@ namespace Polycode {
 		elapsed = 0;
 		xRes = _xRes;
 		yRes = _yRes;
+		paused = false;
+		pauseOnLoseFocus = false;
 		if (fullScreen && !xRes && !yRes) {
 			getScreenInfo(&xRes, &yRes, NULL);
 		}
@@ -148,11 +150,17 @@ namespace Polycode {
 	}
 	
 	void Core::loseFocus() {
+		if(pauseOnLoseFocus) {
+			paused = true;
+		}
 		input->clearInput();
 		dispatchEvent(new Event(), EVENT_LOST_FOCUS);
 	}
 	
 	void Core::gainFocus() {
+		if(pauseOnLoseFocus) {
+			paused = false;
+		}	
 		input->clearInput();		
 		dispatchEvent(new Event(), EVENT_GAINED_FOCUS);
 	}
@@ -178,8 +186,9 @@ namespace Polycode {
 		
 		if(elapsed > 1000)
 			elapsed = 1000;
+			
 		services->Update(elapsed);
-
+		
 		if(frameTicks-lastFPSTicks >= 1000) {
 			fps = frames;
 			frames = 0;

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

@@ -32,6 +32,8 @@ PolycodeClipboard *globalClipboard;
 
 PolycodeIDEApp::PolycodeIDEApp(PolycodeView *view) : EventDispatcher() {
 	core = new POLYCODE_CORE(view, 900,700,false,true, 0, 0,30, -1);	
+	core->pauseOnLoseFocus = true;
+	
 	core->addEventListener(this, Core::EVENT_CORE_RESIZE);
 	
 	globalClipboard = new PolycodeClipboard();