summaryrefslogtreecommitdiff
path: root/include/JSystem/JMessage/processor.h
blob: b63e80bef25c00836c43a63313517b7bfb10221a (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#ifndef JMESSAGE_PROCESSOR_H
#define JMESSAGE_PROCESSOR_H

#include "JSystem/JMessage/resource.h"

namespace JMessage {

struct TReference;
struct TControl;
class TResource;

struct TProcessor {
public:
    TProcessor(TControl *control) : mControl(control), mCurrent(NULL) {}

    typedef bool (*ProcessorCallBack)(TProcessor*);
    typedef const char* (*OnSelectBeginCallBack)(TProcessor*);
    typedef const char* (*ProcessOnSelectCallBack)(TProcessor*);

    struct TStack_ {
        TStack_() { clear(); }

        // TStack_(const TStack_& other) {
        //     for (int i = 0; i < mNum; i++) {
        //         mStack[i] = mStack[i];
        //     }
        //     mNum = other.mNum;
        // }

        inline void clear() { mNum = 0; }
        inline void push(const char* str) {
            mStack[mNum] = str;
            mNum++;
        }
        inline bool IsStorable() const { return mNum < 4; }
        inline void pop() { mNum--; }
        inline const char* top() const { return mStack[mNum - 1]; }
        inline bool empty() const { return mNum == 0; }

        /* 0x00 */ const char* mStack[4];
        /* 0x10 */ u32 mNum;
    };

    struct TStatusData_ {
        TStatusData_() { mCallBack = process_onCharacterEnd_normal_; }

        void reset() {} // TODO

        /* 0x00 */ ProcessorCallBack mCallBack;
        /* 0x04 */ void* mCallBackWork[4];
    };

    ~TProcessor();

    virtual void do_character(int);
    virtual bool do_tag(u32, const void*, u32);
    virtual bool do_systemTagCode(u16, const void*, u32);
    virtual void do_select_begin(u32);
    virtual void do_select_end();
    virtual void do_select_separate();
    virtual void do_begin_(const void*, const char*)      = 0;
    virtual void do_end_()                                = 0;
    virtual void do_tag_(u32, const void*, u32)           = 0;
    virtual void do_systemTagCode_(u16, const void*, u32) = 0;

    void setBegin_messageCode(u16, u16);
    void setBegin_messageID(u32, u32, bool*);
    void setBegin_messageCode(u32); // weak
    TResource* getResource_groupID(u16) const;
    u32 toMessageCode_messageID(u32, u32, bool*) const;
    char* on_message(u32) const;                 // weak
    char* getMessageText_messageCode(u32) const; // weak
    static bool process_onCharacterEnd_normal_(TProcessor*);
    static bool process_onCharacterEnd_select_(TProcessor*);
    static const char* process_onSelect_limited_(TProcessor*);
    static const char* process_onSelect_(TProcessor*);
    void reset_(const char*);

    static const char* process_select_limited_(TProcessor*);
    static const char* process_select_(TProcessor*);

    void pushCurrent(const char*);
    void popCurrent();
    void on_select_begin(OnSelectBeginCallBack, const void*, const char*, u32);
    void on_select_end();
    void on_select_separate();
    void on_tag_();
    bool process_character_();

    TControl* getControl() const { return mControl; }
    const char* getCurrent() const { return mCurrent; }
    void setCurrent_(const char* v) { mCurrent = v; }
    void on_character(int character) { do_character(character); }
    void on_tag(u32 tag, const void* data, u32 size) {
        if (!do_tag(tag, data, size)) {
            do_tag_(tag, data, size);
        }
    }
    void on_begin(const void* param_0, const char* param_1) { do_begin_(param_0, param_1); }
    void on_end() { do_end_(); }

    // TODO: these inlines don't work because of circular includes
    // const char* on_message(u32 code) { mControl->on_message(code); }
    // void on_message_limited(u16 messageIndex) { mControl->on_message_limited(messageIndex); }
    // void on_word(u32 messageIndex) { mControl->on_word(messageIndex); }
    // void on_isLeadByte(int param_0) { mControl->on_isLeadByte(param_0); }

    /* 0x00 */ /* vtable */
    /* 0x04 */ TControl* mControl;
    /* 0x08 */ const char* mCurrent;
    /* 0x0C */ TStack_ mStack;
    /* 0x20 */ TStatusData_ mStatusData;
};

struct TSequenceProcessor : public TProcessor {
    typedef bool OnJumpRegisterCallBack(TSequenceProcessor*);
    typedef bool OnBranchRegisterCallBack(TSequenceProcessor*, u32);
    typedef void* ProcessOnJumpCallBack(const TSequenceProcessor*);

    TSequenceProcessor(const TReference*, TControl*);
    TSequenceProcessor(TControl*);

    /* 0x08 */ virtual ~TSequenceProcessor();
    /* 0x30 */ virtual void do_begin_(const void*, const char*);
    /* 0x34 */ virtual void do_end_();
    /* 0x38 */ virtual void do_tag_(u32, const void*, u32);
    /* 0x3C */ virtual void do_systemTagCode_(u16, const void*, u32);
    /* 0x40 */ virtual void do_begin(const void*, const char*);
    /* 0x44 */ virtual void do_end();
    /* 0x48 */ virtual bool do_isReady();
    /* 0x4C */ virtual bool do_jump_isReady();
    /* 0x50 */ virtual void do_jump(const void*, const char*);
    /* 0x54 */ virtual void do_branch_query(u16);
    /* 0x58 */ virtual int do_branch_queryResult();
    /* 0x5C */ virtual void do_branch(const void*, const char*);

    const char* process(const char*);
    bool on_isReady();
    bool on_jump_isReady();
    void on_jump(const void*, const char*);
    int on_branch_queryResult();
    void on_branch(const void*, const char*);

    void reset_(const char*);
    static bool process_jump_limited_(TSequenceProcessor*);
    static bool process_jump_(TSequenceProcessor*);
    static bool process_branch_limited_(TSequenceProcessor*, u32);
    static bool process_branch_(TSequenceProcessor*, u32);

    // Unused/inlined:
    const char* toString_status(int);
    int toValue_status(const char*);
    void on_jump_register(OnJumpRegisterCallBack*, u32);
    void on_branch_register(OnBranchRegisterCallBack*, const void*, u32);
    void on_branch_query(u16);
    void process_setMessageIndex_reserved_(u16);
    void process_setMessageCode_(const TSequenceProcessor*, u16, u16);

    void reset() { reset_(NULL); }
    void setBegin(const void* param_1, const char* param_2) {
        reset_(param_2);
        do_begin_(param_1, param_2);
    }

    enum {
        kStatus_Begin,
        kStatus_End,
        kStatus_Normal,
        kStatus_Jump,
        kStatus_Branch,
    };

    /* 0x00 */ /* TProcessor */
    /* 0x34 */ int mStatus;
};

struct TRenderingProcessor : public TProcessor {
    TRenderingProcessor(const TReference*);
    TRenderingProcessor(TControl*);

    void reset() { reset_(NULL); }
    void setBegin(const void* entry, const char* data) {
        reset_(data);
        do_begin_(entry, data);
    }

    virtual void do_begin_(const void*, const char*);
    virtual void do_end_();
    virtual void do_tag_(u32, const void*, u32);
    virtual void do_systemTagCode_(u16, const void*, u32);
    virtual ~TRenderingProcessor();
    virtual void do_begin(const void*, const char*);
    virtual void do_end();

    const char* process(const char*);

    /* 0x00 */ /* TProcessor */
};
} // namespace JMessage

#endif /* JMESSAGE_PROCESSOR_H */