Browse Source

device: better paused/resumed logs

Daniele Bartolini 9 tháng trước cách đây
mục cha
commit
6a38785457
2 tập tin đã thay đổi với 13 bổ sung5 xóa
  1. 9 2
      src/device/device.cpp
  2. 4 3
      src/device/device.h

+ 9 - 2
src/device/device.cpp

@@ -344,6 +344,7 @@ Device::Device(const DeviceOptions &opts, ConsoleServer &cs)
 	, _exit_code(EXIT_SUCCESS)
 	, _quit(0)
 	, _paused(0)
+	, _last_paused(0)
 	, _needs_draw(1)
 {
 	list::init_head(_worlds);
@@ -409,6 +410,14 @@ bool Device::frame()
 	if (CE_UNLIKELY(process_events() || _quit != 0))
 		return true;
 
+	if (CE_UNLIKELY(_paused == 0 && _last_paused == 1)) {
+		_last_paused = 0;
+		logi(DEVICE, "Resumed");
+	} else if (CE_UNLIKELY(_paused == 1 && _last_paused == 0)) {
+		_last_paused = 1;
+		logi(DEVICE, "Paused");
+	}
+
 	const s64 time = time::now();
 	const s64 raw_dt_ticks = time - _last_time;
 	const f32 raw_dt = f32(time::seconds(raw_dt_ticks));
@@ -758,13 +767,11 @@ const char **Device::argv() const
 void Device::pause()
 {
 	_paused = 1;
-	logi(DEVICE, "Paused");
 }
 
 void Device::unpause()
 {
 	_paused = 0;
-	logi(DEVICE, "Unpaused");
 }
 
 void Device::resolution(u16 &width, u16 &height)

+ 4 - 3
src/device/device.h

@@ -66,9 +66,10 @@ struct Device
 	u16 _prev_height;
 	s64 _last_time;
 
-	u16 _exit_code : 8;
-	u16 _quit      : 1;
-	u16 _paused    : 1;
+	u16 _exit_code   : 8;
+	u16 _quit        : 1;
+	u16 _paused      : 1;
+	u16 _last_paused : 1;
 
 	std::atomic_int _needs_draw;