Browse Source

GLFW: Lowered CPU use.

Camilla Berglund 9 years ago
parent
commit
8b4f495225
1 changed files with 11 additions and 1 deletions
  1. 11 1
      examples/common/entry/entry_glfw.cpp

+ 11 - 1
examples/common/entry/entry_glfw.cpp

@@ -412,7 +412,7 @@ namespace entry
 
 
 			while (!glfwWindowShouldClose(m_windows[0]))
 			while (!glfwWindowShouldClose(m_windows[0]))
 			{
 			{
-				glfwPollEvents();
+				glfwWaitEvents();
 
 
 				for (uint32_t ii = 0; ii < ENTRY_CONFIG_MAX_GAMEPADS; ++ii)
 				for (uint32_t ii = 0; ii < ENTRY_CONFIG_MAX_GAMEPADS; ++ii)
 				{
 				{
@@ -670,11 +670,13 @@ namespace entry
 
 
 	const Event* poll()
 	const Event* poll()
 	{
 	{
+		glfwPostEmptyEvent();
 		return s_ctx.m_eventQueue.poll();
 		return s_ctx.m_eventQueue.poll();
 	}
 	}
 
 
 	const Event* poll(WindowHandle _handle)
 	const Event* poll(WindowHandle _handle)
 	{
 	{
+		glfwPostEmptyEvent();
 		return s_ctx.m_eventQueue.poll(_handle);
 		return s_ctx.m_eventQueue.poll(_handle);
 	}
 	}
 
 
@@ -694,6 +696,7 @@ namespace entry
 		msg->m_title = _title;
 		msg->m_title = _title;
 		msg->m_handle.idx = s_ctx.m_windowAlloc.alloc();
 		msg->m_handle.idx = s_ctx.m_windowAlloc.alloc();
 		s_ctx.m_msgs.push(msg);
 		s_ctx.m_msgs.push(msg);
+		glfwPostEmptyEvent();
 		return msg->m_handle;
 		return msg->m_handle;
 	}
 	}
 
 
@@ -702,6 +705,7 @@ namespace entry
 		Msg* msg = new Msg(GLFW_WINDOW_DESTROY);
 		Msg* msg = new Msg(GLFW_WINDOW_DESTROY);
 		msg->m_handle = _handle;
 		msg->m_handle = _handle;
 		s_ctx.m_msgs.push(msg);
 		s_ctx.m_msgs.push(msg);
+		glfwPostEmptyEvent();
 	}
 	}
 
 
 	void setWindowPos(WindowHandle _handle, int32_t _x, int32_t _y)
 	void setWindowPos(WindowHandle _handle, int32_t _x, int32_t _y)
@@ -711,6 +715,7 @@ namespace entry
 		msg->m_y = _y;
 		msg->m_y = _y;
 		msg->m_handle = _handle;
 		msg->m_handle = _handle;
 		s_ctx.m_msgs.push(msg);
 		s_ctx.m_msgs.push(msg);
+		glfwPostEmptyEvent();
 	}
 	}
 
 
 	void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height)
 	void setWindowSize(WindowHandle _handle, uint32_t _width, uint32_t _height)
@@ -720,6 +725,7 @@ namespace entry
 		msg->m_height = _height;
 		msg->m_height = _height;
 		msg->m_handle = _handle;
 		msg->m_handle = _handle;
 		s_ctx.m_msgs.push(msg);
 		s_ctx.m_msgs.push(msg);
+		glfwPostEmptyEvent();
 	}
 	}
 
 
 	void setWindowTitle(WindowHandle _handle, const char* _title)
 	void setWindowTitle(WindowHandle _handle, const char* _title)
@@ -728,6 +734,7 @@ namespace entry
 		msg->m_title = _title;
 		msg->m_title = _title;
 		msg->m_handle = _handle;
 		msg->m_handle = _handle;
 		s_ctx.m_msgs.push(msg);
 		s_ctx.m_msgs.push(msg);
+		glfwPostEmptyEvent();
 	}
 	}
 
 
 	void toggleWindowFrame(WindowHandle _handle)
 	void toggleWindowFrame(WindowHandle _handle)
@@ -735,6 +742,7 @@ namespace entry
 		Msg* msg = new Msg(GLFW_WINDOW_TOGGLE_FRAME);
 		Msg* msg = new Msg(GLFW_WINDOW_TOGGLE_FRAME);
 		msg->m_handle = _handle;
 		msg->m_handle = _handle;
 		s_ctx.m_msgs.push(msg);
 		s_ctx.m_msgs.push(msg);
+		glfwPostEmptyEvent();
 	}
 	}
 
 
 	void toggleFullscreen(WindowHandle _handle)
 	void toggleFullscreen(WindowHandle _handle)
@@ -742,6 +750,7 @@ namespace entry
 		Msg* msg = new Msg(GLFW_WINDOW_TOGGLE_FULL_SCREEN);
 		Msg* msg = new Msg(GLFW_WINDOW_TOGGLE_FULL_SCREEN);
 		msg->m_handle = _handle;
 		msg->m_handle = _handle;
 		s_ctx.m_msgs.push(msg);
 		s_ctx.m_msgs.push(msg);
+		glfwPostEmptyEvent();
 	}
 	}
 
 
 	void setMouseLock(WindowHandle _handle, bool _lock)
 	void setMouseLock(WindowHandle _handle, bool _lock)
@@ -750,6 +759,7 @@ namespace entry
 		msg->m_value = _lock;
 		msg->m_value = _lock;
 		msg->m_handle = _handle;
 		msg->m_handle = _handle;
 		s_ctx.m_msgs.push(msg);
 		s_ctx.m_msgs.push(msg);
+		glfwPostEmptyEvent();
 	}
 	}
 
 
 	int32_t MainThreadEntry::threadFunc(void* _userData)
 	int32_t MainThreadEntry::threadFunc(void* _userData)