summaryrefslogtreecommitdiff
path: root/src/KingSystem/System/ProductReporter.cpp
diff options
context:
space:
mode:
authorConorB <11508137+ConorBobbleHat@users.noreply.github.com>2022-06-19 12:52:59 +0100
committerGitHub <noreply@github.com>2022-06-19 13:52:59 +0200
commite1c1cfe79e025e108715923ec01af06c27ddb067 (patch)
tree8210972edd4b9a4ce1c364465d86d598a189123b /src/KingSystem/System/ProductReporter.cpp
parent2eeae37cf787e8ab1cf64b98db35de4b1b0fca3f (diff)
ksys::ProductReporter (#93)
Co-authored-by: ConorBobbleHat <ConorBobbleHat>
Diffstat (limited to 'src/KingSystem/System/ProductReporter.cpp')
-rw-r--r--src/KingSystem/System/ProductReporter.cpp233
1 files changed, 233 insertions, 0 deletions
diff --git a/src/KingSystem/System/ProductReporter.cpp b/src/KingSystem/System/ProductReporter.cpp
index 92333196..c6589b8b 100644
--- a/src/KingSystem/System/ProductReporter.cpp
+++ b/src/KingSystem/System/ProductReporter.cpp
@@ -1 +1,234 @@
#include "KingSystem/System/ProductReporter.h"
+
+#include <gfx/seadCamera.h>
+#include <heap/seadExpHeap.h>
+#include <heap/seadHeap.h>
+#include <nn/account.h>
+#include <nn/oe.h>
+
+#include "KingSystem/Framework/Framework.h"
+#include "KingSystem/Map/mapPlacementMgr.h"
+#include "KingSystem/Sound/sndMgr.h"
+#include "KingSystem/System/CameraMgr.h"
+#include "KingSystem/System/PlayReportMgr.h"
+#include "KingSystem/System/VFR.h"
+
+namespace ksys {
+
+static WorkTimes sWorkTimes;
+
+auto& getWorkTimes() {
+ return sWorkTimes;
+};
+
+[[gnu::noinline]] void ProductReporter::terminate() {
+ if (mIsInitalized) {
+ gdt::Manager::instance()->removeReinitCallback(mSlot);
+ mIsInitalized = false;
+ }
+}
+
+ProductReporter::~ProductReporter() {
+ terminate();
+}
+
+void ProductReporter::init(sead::Heap* heap) {
+ if (mIsInitalized)
+ return;
+
+ mHeap = sead::ExpHeap::create(0x18000, "ProductReporter Heap", heap, sizeof(void*),
+ sead::Heap::cHeapDirection_Forward, true);
+
+ nn::account::Initialize();
+
+ s32 listAllUsersRet = -1;
+ nn::account::Uid uid[8];
+ nn::account::ListAllUsers(&listAllUsersRet, uid, 8);
+
+ if (0 < listAllUsersRet) {
+ for (int i = 0; i < PlayReportKey::size(); i++)
+ mGameDataHandles[i] = gdt::InvalidHandle;
+
+ mPlayerTrackReporter = new (heap) PlayerTrackReporter;
+ mPlayerTrackReporter->init(heap);
+
+ mContainer1.init(heap, 0x20, 0x30);
+ mContainer2.init(heap, 0x20, 0x30);
+ mContainer3.init(heap, 0x20, 0x30);
+ mContainer4.init(heap, 0x20, 0x30);
+
+ mIsInitalized = true;
+ }
+}
+
+void ProductReporter::initGameDataIterators() {
+ for (int i = 0; i < PlayReportKey::size(); i++) {
+ mGameDataHandles[i] = gdt::Manager::instance()->getS32Handle(PlayReportKey::text(i));
+ }
+}
+
+bool ProductReporter::isEnabled() const {
+ return mEnabled;
+}
+
+s32 ProductReporter::getRomWorkTime() const {
+ return sWorkTimes.rom;
+}
+
+s32 ProductReporter::getSceneWorkTime() const {
+ return sWorkTimes.scene;
+}
+
+void ProductReporter::resetSceneWorkTime() {
+ sWorkTimes.scene = 0;
+}
+
+void ProductReporter::updateTimers() {
+ if (!mEnabled)
+ return;
+
+ mIncrementWorkTimesTimer += VFR::instance()->getIntervalRatio();
+
+ if (mIncrementWorkTimesTimer >= 30.0f) {
+ mIncrementWorkTimesTimer -= 30.0f;
+ if (incrementSceneAndRomWorkTime()) {
+ mPlayerTrackReporter->setPosTrackEnd();
+ }
+ }
+
+ mNinetyTickTimer += VFR::instance()->getIntervalRatio();
+ if (!(90.0f > mNinetyTickTimer)) {
+ mNinetyTickTimer -= 90.0f;
+ }
+}
+
+bool ProductReporter::saveReport(PlayReport* playReport) const {
+ if (playReport != nullptr && mEnabled) {
+ return playReport->save();
+ }
+
+ return false;
+}
+
+// NON_MATCHING: minor reordering & deduplication
+bool ProductReporter::incrementSceneAndRomWorkTime() {
+ if (map::PlacementMgr::instance() == nullptr)
+ return false;
+
+ s32 value = 0;
+ sWorkTimes.rom++;
+ sWorkTimes.scene++;
+
+ auto* camera = CameraMgr::instance()->getLookAtCamera();
+
+ if (camera != nullptr && mPos != camera->getPos()) {
+ mCameraIdleTimer = 0.0f;
+ mPos = camera->getPos();
+ }
+
+ if (!(mCameraIdleTimer < 300.0f))
+ return false;
+
+ mCameraIdleTimer += 1.0f;
+
+ increment(PlayReportKey::PlayReport_AllPlayTime, &value);
+ increment(PlayReportKey::PlayReport_PlayTime, &value);
+
+ {
+ s32 value = 0;
+ auto* framework = frm::Framework::instance();
+
+ switch (framework->mOperationMode) {
+ case nn::oe::OperationMode_Handheld:
+ increment(PlayReportKey::PlayReport_PlayTime_Handheld, &value);
+
+ switch (mCtrlMode) {
+ case 1:
+ increment(PlayReportKey::PlayReport_CtrlMode_Free, &value);
+ break;
+ case 2:
+ increment(PlayReportKey::PlayReport_CtrlMode_Ext, &value);
+ break;
+ case 3:
+ increment(PlayReportKey::PlayReport_CtrlMode_FullKey, &value);
+ break;
+ case 4:
+ increment(PlayReportKey::PlayReport_CtrlMode_Handheld, &value);
+ break;
+ default:
+ break;
+ }
+
+ break;
+
+ case nn::oe::OperationMode_Docked:
+ increment(PlayReportKey::PlayReport_PlayTime_Console, &value);
+
+ switch (mCtrlMode) {
+ case 1:
+ increment(PlayReportKey::PlayReport_CtrlMode_Console_Free, &value);
+ break;
+ case 2:
+ increment(PlayReportKey::PlayReport_CtrlMode_Console_Ext, &value);
+ break;
+ case 3:
+ increment(PlayReportKey::PlayReport_CtrlMode_Console_FullKey, &value);
+ break;
+ default:
+ break;
+ }
+
+ break;
+ }
+ }
+
+ {
+ s32 value = 0;
+
+ auto* snd = snd::SoundMgr::instance();
+ if (snd == nullptr)
+ return true;
+
+ switch (snd->mAudioChannelType) {
+ case snd::AudioChannelType::Mono:
+ increment(PlayReportKey::PlayReport_AudioChannel_Mono, &value);
+ break;
+ case snd::AudioChannelType::Stereo:
+ increment(PlayReportKey::PlayReport_AudioChannel_Stereo, &value);
+ break;
+ case snd::AudioChannelType::_5_1ch:
+ increment(PlayReportKey::PlayReport_AudioChannel_5_1ch, &value);
+ break;
+ default:
+ increment(PlayReportKey::PlayReport_AudioChannel_Other, &value);
+ break;
+ }
+ }
+
+ return true;
+}
+
+#define PRODUCT_REPORTER_S32_GETTER(NAME, PLAY_REPORT_KEY) \
+ s32 ProductReporter::NAME() const { \
+ s32 out = 0; \
+ gdt::Manager::instance()->getS32(mGameDataHandles[PLAY_REPORT_KEY], &out); \
+ return out; \
+ }
+
+PRODUCT_REPORTER_S32_GETTER(getPlayTime, PlayReportKey::PlayReport_PlayTime)
+PRODUCT_REPORTER_S32_GETTER(getAllPlayTime, PlayReportKey::PlayReport_AllPlayTime)
+PRODUCT_REPORTER_S32_GETTER(getCtrlModeFree, PlayReportKey::PlayReport_CtrlMode_Free)
+PRODUCT_REPORTER_S32_GETTER(getCtrlModeExt, PlayReportKey::PlayReport_CtrlMode_Ext)
+PRODUCT_REPORTER_S32_GETTER(getCtrlModeFullKey, PlayReportKey::PlayReport_CtrlMode_FullKey)
+PRODUCT_REPORTER_S32_GETTER(getCtrlModeHandheld, PlayReportKey::PlayReport_CtrlMode_Handheld)
+PRODUCT_REPORTER_S32_GETTER(getCtrlModeConsoleFree, PlayReportKey::PlayReport_CtrlMode_Console_Free)
+PRODUCT_REPORTER_S32_GETTER(getCtrlModeConsoleExt, PlayReportKey::PlayReport_CtrlMode_Console_Ext)
+PRODUCT_REPORTER_S32_GETTER(getCtrlModeConsoleFullKey,
+ PlayReportKey::PlayReport_CtrlMode_Console_FullKey)
+PRODUCT_REPORTER_S32_GETTER(getCtrlModePlayTimeHandheld,
+ PlayReportKey::PlayReport_PlayTime_Handheld)
+PRODUCT_REPORTER_S32_GETTER(getPlayTimeConsole, PlayReportKey::PlayReport_PlayTime_Console)
+
+#undef PRODUCT_REPORTER_S32_GETTER
+
+} // namespace ksys \ No newline at end of file