summaryrefslogtreecommitdiff
path: root/src/KingSystem/Resource/resTempResourceLoader.h
blob: 69e42ce1271f8beddc365618fe04d133bb714871 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#pragma once

#include <basis/seadTypes.h>
#include <prim/seadSafeString.h>
#include <prim/seadTypedBitFlag.h>
#include "KingSystem/Resource/resHandle.h"
#include "KingSystem/Resource/resLoadRequest.h"
#include "KingSystem/Resource/resSystem.h"
#include "KingSystem/Utils/Types.h"

namespace sead {
class DirectResource;
}

namespace ksys::res {

class ArchiveWork;

class TempResourceLoader {
public:
    struct InitArg {
        ArchiveWork* work;
    };

    struct LoadArg {
        bool retry_on_failure = true;
        bool use_handle = true;
        u32 ms_between_attempts = 0;
        LoadRequest load_req;
    };

    TempResourceLoader();
    ~TempResourceLoader();

    void unload();
    bool init(const InitArg& arg);
    bool isLoading() const;
    bool isSuccess() const;
    bool checkLoadStatus() const;
    void requestLoad(LoadArg& arg);
    sead::DirectResource* getResourceForLoadRequest(Context* context);
    sead::DirectResource* load(LoadArg& arg);
    sead::DirectResource* getResource() const;
    Handle::Status getHandleStatus() const;
    sead::FileDevice* getHandleFileDevice() const;
    u32 getWorkHeapSize() const;

private:
    enum class Flag : u8 {
        Loading = 1,
        IsRetryingLoad = 2,
    };

    void setRetryFlag() {
        if (mFlags.isOff(Flag::IsRetryingLoad)) {
            stubbedLogFunction();
            mFlags.set(Flag::IsRetryingLoad);
        } else if (returnFalse()) {
            stubbedLogFunction();
        }
    }

    void resetRetryFlag() {
        if (mFlags.isOn(Flag::IsRetryingLoad)) {
            stubbedLogFunction();
            mFlags.reset(Flag::IsRetryingLoad);
        } else if (returnFalse()) {
            stubbedLogFunction();
        }
    }

    void updateFlagsBeforeLoadingStarts() {
        mFlags.reset(Flag::Loading);
        mFlags.reset(Flag::IsRetryingLoad);
        mFlags.set(Flag::Loading);
    }

    sead::TypedBitFlag<Flag> mFlags;
    sead::DirectResource* mResource{};
    ArchiveWork* mWork{};
    Handle mHandle;
    LoadArg mLoadArg;
    sead::FixedSafeString<128> mPath;
};
KSYS_CHECK_SIZE_NX150(TempResourceLoader, 0x188);

}  // namespace ksys::res