aboutsummaryrefslogtreecommitdiff
path: root/src/frontend_common/play_time_manager.h
diff options
context:
space:
mode:
authorinix <Nixy01@proton.me>2025-10-17 22:47:43 +0200
committercrueter <crueter@eden-emu.dev>2025-10-17 22:47:43 +0200
commit6bdf479488dd87a35bf5ccf9ec334f49bf43ffc7 (patch)
tree166376be36272e3177cc2fd474cc24c7eb9d1360 /src/frontend_common/play_time_manager.h
parent9c7ed0f59dd41ec0bbbfbc81678209ae60a36016 (diff)
[core, android] Initial playtime implementation (#2535)
So firstly, playtime code is moved to src/common and qt specific code to yuzu/utils.cpp. The dependency on ProfileManager was removed because it was working properly on Android, and I think a shared playtime is better behavior. Now, playtime is stored in a file called "playtime.bin". JNI code is from Azahar although modified by me, as well as that I added code to reset the game's playtime which was missing for some reason on there. Before this gets merged, I plan to add the ability to manually edit the database as well. Note: Code still needs a bit of cleanup. Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/2535 Reviewed-by: CamilleLaVey <camillelavey99@gmail.com> Reviewed-by: Lizzie <lizzie@eden-emu.dev> Reviewed-by: crueter <crueter@eden-emu.dev> Reviewed-by: MaranBr <maranbr@eden-emu.dev> Co-authored-by: inix <Nixy01@proton.me> Co-committed-by: inix <Nixy01@proton.me>
Diffstat (limited to 'src/frontend_common/play_time_manager.h')
-rw-r--r--src/frontend_common/play_time_manager.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/frontend_common/play_time_manager.h b/src/frontend_common/play_time_manager.h
new file mode 100644
index 0000000000..a99ccebb1e
--- /dev/null
+++ b/src/frontend_common/play_time_manager.h
@@ -0,0 +1,56 @@
+// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+#include <map>
+
+#include "common/common_funcs.h"
+#include "common/common_types.h"
+#include <common/polyfill_thread.h>
+
+// TODO(crueter): Extract this into frontend_common
+namespace Service::Account {
+class ProfileManager;
+}
+
+namespace PlayTime {
+
+using ProgramId = u64;
+using PlayTime = u64;
+using PlayTimeDatabase = std::map<ProgramId, PlayTime>;
+
+class PlayTimeManager {
+public:
+ explicit PlayTimeManager();
+ ~PlayTimeManager();
+
+ YUZU_NON_COPYABLE(PlayTimeManager);
+ YUZU_NON_MOVEABLE(PlayTimeManager);
+
+ u64 GetPlayTime(u64 program_id) const;
+ void ResetProgramPlayTime(u64 program_id);
+ void SetProgramId(u64 program_id);
+ void SetPlayTime(u64 program_id, u64 play_time);
+ void Start();
+ void Stop();
+
+ static std::string GetReadablePlayTime(u64 time_seconds);
+ static std::string GetPlayTimeHours(u64 time_seconds);
+ static std::string GetPlayTimeMinutes(u64 time_seconds);
+ static std::string GetPlayTimeSeconds(u64 time_seconds);
+
+private:
+ void AutoTimestamp(std::stop_token stop_token);
+ void Save();
+
+ PlayTimeDatabase database;
+ u64 running_program_id;
+ std::jthread play_time_thread;
+};
+
+
+} // namespace PlayTime