ソースを参照

device: add ability to queue multiple frame() requests

Daniele Bartolini 2 年 前
コミット
98f1a0ecd3
2 ファイル変更9 行追加5 行削除
  1. 7 4
      src/device/device.cpp
  2. 2 1
      src/device/device.h

+ 7 - 4
src/device/device.cpp

@@ -209,7 +209,7 @@ static void device_message_resize(ConsoleServer & /*cs*/, u32 /*client_id*/, con
 
 
 static void device_message_frame(ConsoleServer & /*cs*/, u32 /*client_id*/, const char * /*json*/, void *user_data)
 static void device_message_frame(ConsoleServer & /*cs*/, u32 /*client_id*/, const char * /*json*/, void *user_data)
 {
 {
-	((Device *)user_data)->_needs_draw = true;
+	++((Device *)user_data)->_needs_draw;
 }
 }
 
 
 static void device_message_quit(ConsoleServer &cs, u32 client_id, const char *json, void *user_data)
 static void device_message_quit(ConsoleServer &cs, u32 client_id, const char *json, void *user_data)
@@ -246,7 +246,7 @@ Device::Device(const DeviceOptions &opts, ConsoleServer &cs)
 	, _height(CROWN_DEFAULT_WINDOW_HEIGHT)
 	, _height(CROWN_DEFAULT_WINDOW_HEIGHT)
 	, _quit(false)
 	, _quit(false)
 	, _paused(false)
 	, _paused(false)
-	, _needs_draw(true)
+	, _needs_draw(1)
 {
 {
 	list::init_head(_worlds);
 	list::init_head(_worlds);
 }
 }
@@ -301,7 +301,6 @@ bool Device::frame()
 	const s64 time = time::now();
 	const s64 time = time::now();
 	const f32 dt   = f32(time::seconds(time - _last_time));
 	const f32 dt   = f32(time::seconds(time - _last_time));
 	_last_time = time;
 	_last_time = time;
-	_needs_draw = !_options._pumped;
 
 
 	profiler_globals::clear();
 	profiler_globals::clear();
 
 
@@ -316,7 +315,7 @@ bool Device::frame()
 		bgfx::frame();
 		bgfx::frame();
 
 
 		// Force redraw.
 		// Force redraw.
-		_needs_draw = true;
+		++_needs_draw;
 	}
 	}
 
 
 	// Only block if redraw is not needed.
 	// Only block if redraw is not needed.
@@ -364,6 +363,10 @@ bool Device::frame()
 	_pipeline->render(*_shader_manager, STRING_ID_32("blit", UINT32_C(0x045f02bb)), VIEW_BLIT, _width, _height);
 	_pipeline->render(*_shader_manager, STRING_ID_32("blit", UINT32_C(0x045f02bb)), VIEW_BLIT, _width, _height);
 
 
 	bgfx::frame();
 	bgfx::frame();
+
+	if (_needs_draw-- == 1)
+		_needs_draw = (int)!_options._pumped;
+
 	return false;
 	return false;
 }
 }
 
 

+ 2 - 1
src/device/device.h

@@ -23,6 +23,7 @@
 #include "resource/types.h"
 #include "resource/types.h"
 #include "resource/types.h"
 #include "resource/types.h"
 #include "world/types.h"
 #include "world/types.h"
+#include <atomic>
 
 
 /// @defgroup Device Device
 /// @defgroup Device Device
 namespace crown
 namespace crown
@@ -64,7 +65,7 @@ struct Device
 
 
 	bool _quit;
 	bool _quit;
 	bool _paused;
 	bool _paused;
-	bool _needs_draw;
+	std::atomic_int _needs_draw;
 
 
 	///
 	///
 	bool process_events();
 	bool process_events();