summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service/hid/irs_ring_lifo.h
diff options
context:
space:
mode:
authorgerman77 <juangerman-13@hotmail.com>2022-06-19 22:54:21 +0200
committergerman77 <juangerman-13@hotmail.com>2022-07-24 22:01:43 +0200
commit3ac4f3a2521e421a625fe1d7dcba05b8441fe056 (patch)
treece7e1f5be8624a8b6d3084b9c4ef522f87ba6ac7 /src/core/hle/service/hid/irs_ring_lifo.h
parentMerge pull request #8484 from german77/irs_release (diff)
downloadyuzu-3ac4f3a2521e421a625fe1d7dcba05b8441fe056.tar
yuzu-3ac4f3a2521e421a625fe1d7dcba05b8441fe056.tar.gz
yuzu-3ac4f3a2521e421a625fe1d7dcba05b8441fe056.tar.bz2
yuzu-3ac4f3a2521e421a625fe1d7dcba05b8441fe056.tar.lz
yuzu-3ac4f3a2521e421a625fe1d7dcba05b8441fe056.tar.xz
yuzu-3ac4f3a2521e421a625fe1d7dcba05b8441fe056.tar.zst
yuzu-3ac4f3a2521e421a625fe1d7dcba05b8441fe056.zip
Diffstat (limited to 'src/core/hle/service/hid/irs_ring_lifo.h')
-rw-r--r--src/core/hle/service/hid/irs_ring_lifo.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/core/hle/service/hid/irs_ring_lifo.h b/src/core/hle/service/hid/irs_ring_lifo.h
new file mode 100644
index 000000000..a31e61037
--- /dev/null
+++ b/src/core/hle/service/hid/irs_ring_lifo.h
@@ -0,0 +1,47 @@
+// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#pragma once
+
+#include <array>
+
+#include "common/common_types.h"
+
+namespace Service::IRS {
+
+template <typename State, std::size_t max_buffer_size>
+struct Lifo {
+ s64 sampling_number{};
+ s64 buffer_count{};
+ std::array<State, max_buffer_size> entries{};
+
+ const State& ReadCurrentEntry() const {
+ return entries[GetBufferTail()];
+ }
+
+ const State& ReadPreviousEntry() const {
+ return entries[GetPreviousEntryIndex()];
+ }
+
+ s64 GetBufferTail() const {
+ return sampling_number % max_buffer_size;
+ }
+
+ std::size_t GetPreviousEntryIndex() const {
+ return static_cast<size_t>((GetBufferTail() + max_buffer_size - 1) % max_buffer_size);
+ }
+
+ std::size_t GetNextEntryIndex() const {
+ return static_cast<size_t>((GetBufferTail() + 1) % max_buffer_size);
+ }
+
+ void WriteNextEntry(const State& new_state) {
+ if (buffer_count < max_buffer_size) {
+ buffer_count++;
+ }
+ sampling_number++;
+ entries[GetBufferTail()] = new_state;
+ }
+};
+
+} // namespace Service::IRS