summaryrefslogtreecommitdiff
path: root/include/egg/core/eggSystem.h
blob: 2adc5351d4e71b4ad508d37686e41bc810af9924 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#ifndef EGG_SYSTEM_H
#define EGG_SYSTEM_H

#include "common.h"
#include "egg/core/eggVideo.h"

namespace EGG {

// TODO Proper definition of PerformanceView
class PerformanceView {
public:
    u8 placeholder[0x4c];
    /* 0x4c */ u32 _4c;
};

class Display;
class Heap;
class PerformanceView;
class SceneManager;
class SimpleAudioMgr;
class Thread;
class Video;
class XfbManager;

class ConfigurationData {
public:
    inline ConfigurationData() : mSystemHeapSize(0x89000) {}

    // vtable at 0x0
    /* vt 0x08 */ virtual Video *getVideo() = 0;
    /* vt 0x0C */ virtual Heap *getSystemHeap() = 0;
    /* vt 0x10 */ virtual Display *getDisplay() = 0;
    /* vt 0x14 */ virtual XfbManager *getXfbMgr() = 0;
    /* vt 0x18 */ virtual PerformanceView *getPerfView() = 0;
    /* vt 0x1C */ virtual SceneManager *getSceneMgr() = 0;
    /* vt 0x20 */ virtual SimpleAudioMgr *getAudioMgr() = 0;
    /* vt 0x24 */ virtual void onBeginFrame();
    /* vt 0x28 */ virtual void onEndFrame();
    /* vt 0x2C */ virtual void initRenderMode();
    /* vt 0x30 */ virtual void initMemory();
    /* vt 0x34 */ virtual void run();
    /* vt 0x38 */ virtual void initialize() = 0;

public:
    /* 0x04 */ u32 mRoot1HeapStart;
    /* 0x08 */ u32 mRoot1HeapEnd;
    /* 0x0C */ u32 mRoot2HeapStart;
    /* 0x10 */ u32 mRoot2HeapEnd;
    /* 0x14 */ u32 mMemSize;
    /* 0x18 */ Heap *mRootHeapMem1;
    /* 0x1C */ Heap *mRootHeapMem2;
    /* 0x20 */ Heap *mRootHeapDebug;
    /* 0x24 */ Heap *mSystemHeap;
    /* 0x28 */ Thread *mSystemThread;
    /* 0x2C */ u32 field_0x2C;
    /* 0x30 */ u32 mSystemHeapStart;
    /* 0x34 */ u32 mSystemHeapSize;
};
class BaseSystem {
public:
    static ConfigurationData *mConfigData;
    
    static XfbManager *getXfbMgr() {
        return mConfigData->getXfbMgr();
    }
    static Display *getDisplay() {
        return mConfigData->getDisplay();
    }
    static Video *getVideo() {
        return mConfigData->getVideo();
    }
};

template <class TVideo, class TDisplay, class TXfbManager, class TAudioManager, class TSceneManager, class TPerfView>
class TSystem : public ConfigurationData {
public:
    inline TSystem() : mGraphicsFifoSize(0x80000), mRenderMode() {}

    void onBeginFrame() override {}
    void onEndFrame() override {}

    void initRenderMode() override {}
    void initialize() override {}
    
    Video *getVideo() override {
        return static_cast<Video *>(mVideo);
    }

    Heap *getSystemHeap() override {
        return static_cast<Heap *>(mSystemHeap);
    }

    Display *getDisplay() override {
        return static_cast<Display *>(mDisplay);
    }

    XfbManager *getXfbMgr() override {
        return static_cast<XfbManager *>(mXfbMgr);
    }

    PerformanceView *getPerfView() override {
        if (!mPerfView)
            return mPerfView;
        // TODO remove cast hack if/when more is known about PerformanceView
        return static_cast<PerformanceView *>((void *)&mPerfView->_4c);
    }

    SceneManager *getSceneMgr() override {
        return static_cast<SceneManager *>(mSceneMgr);
    }

    SimpleAudioMgr *getAudioMgr() override {
        return static_cast<SimpleAudioMgr *>(mAudioMgr);
    }

public:
    /* 0x38 */ u32 mGraphicsFifoSize;
    /* 0x3C */ GXRenderModeObj *mRenderMode;
    /* 0x40 */ TAudioManager *mAudioMgr;
    /* 0x44 */ TVideo *mVideo;
    /* 0x48 */ TXfbManager *mXfbMgr;
    /* 0x4c */ TDisplay *mDisplay;
    /* 0x50 */ TPerfView *mPerfView;
    /* 0x54 */ TSceneManager *mSceneMgr;
};

} // namespace EGG

#endif