summaryrefslogtreecommitdiff
path: root/src/f_pc/f_pc_base.cpp
blob: 36af52f9052832f1c8bb7d9c70ce2c50dbc4a027 (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
/**
 * f_pc_base.cpp
 * Framework - Process Base
 */

#include "f_pc/f_pc_base.h"
#include "SSystem/SComponent/c_malloc.h"
#include "SSystem/SComponent/c_phase.h"
#include "SSystem/SStandard/s_basic.h"
#include "d/d_stage.h"
#include "f_pc/f_pc_layer.h"
#include "f_pc/f_pc_method.h"
#include "f_pc/f_pc_pause.h"
#include "f_pc/f_pc_profile.h"
#include "f_pc/f_pc_debug_sv.h"
#include "Z2AudioLib/Z2AudioMgr.h"

BOOL fpcBs_Is_JustOfType(int i_typeA, int i_typeB) {
    if (i_typeB == i_typeA) {
        return TRUE;
    } else {
        return FALSE;
    }
}

int g_fpcBs_type;

int fpcBs_MakeOfType(int* i_type) {
    static int t_type = 0x9130000;
    if (*i_type == 0) {
        *i_type = ++t_type;
    }
    return *i_type;
}

int fpcBs_MakeOfId() {
    static int process_id = 1;
    return process_id++;
}

int fpcBs_Execute(base_process_class* i_proc) {
    int result = 1;

#if DEBUG
    if (!fpcBs_Is_JustOfType(g_fpcBs_type, i_proc->type)) {
        if (g_fpcDbSv_service[10] != NULL) {
            g_fpcDbSv_service[10](i_proc);
        }
        
        return 0;
    }
#endif

    if (result == 1) {
        layer_class* save_layer = fpcLy_CurrentLayer();

        fpcLy_SetCurrentLayer(i_proc->layer_tag.layer);
        result = fpcMtd_Execute(i_proc->methods, i_proc);

        fpcLy_SetCurrentLayer(save_layer);
    }
    
    return result;
}

void fpcBs_DeleteAppend(base_process_class* i_proc) {
    if (i_proc->append != NULL) {
        cMl::free(i_proc->append);
        i_proc->append = NULL;
    }
}

int fpcBs_IsDelete(base_process_class* i_proc) {
    int result;
    layer_class* save_layer = fpcLy_CurrentLayer();

    fpcLy_SetCurrentLayer(i_proc->layer_tag.layer);
    result = fpcMtd_IsDelete(i_proc->methods, i_proc);

    fpcLy_SetCurrentLayer(save_layer);
    return result;
}

int fpcBs_Delete(base_process_class* i_proc) {
    BOOL result = TRUE;
    if (result == TRUE) {
        result = fpcMtd_Delete(i_proc->methods, i_proc);
        if (result == 1) {
            s16 profname = i_proc->profname;
            fpcBs_DeleteAppend(i_proc);
            i_proc->type = 0;
            cMl::free(i_proc);

            #if DEBUG
            JSUList<Z2SoundObjBase>* allList = Z2GetAudioMgr()->getAllList();

            for (JSUListIterator<Z2SoundObjBase> it(allList->getFirst()); it != allList->getEnd(); it++) {
                static JSULink<Z2SoundObjBase>* DUMMY_FILL_IT = (JSULink<Z2SoundObjBase>*)0xdddddddd;
                static Z2SoundObjBase* DUMMY_FILL_P = (Z2SoundObjBase*)0xdddddddd;
                if (it == DUMMY_FILL_IT || it.getObject() == DUMMY_FILL_P) {
                    const char* stageName = dStage_getName2(profname, 0);
                    if (stageName == NULL) {
                        JUT_PANIC_F(341, "Sound Object Not Delete !! <%d>\n", profname);
                    } else {
                        JUT_PANIC_F(345, "Sound Object Not Delete !! <%s>\n", stageName);
                    }
                }
            }
            #endif
        }
    }
    return result;
}

base_process_class* fpcBs_Create(s16 i_profname, fpc_ProcID i_procID, void* i_append) {
    process_profile_definition* pprofile;
    base_process_class* pprocess;
    u32 size;

    pprofile = (process_profile_definition*)fpcPf_Get(i_profname);
    size = pprofile->process_size + pprofile->unk_size;

    pprocess = (base_process_class*)cMl::memalignB(-4, size);
    if (pprocess == NULL) {
        return NULL;
    }

    sBs_ClearArea(pprocess, size);
    fpcLyTg_Init(&pprocess->layer_tag, pprofile->layer_id, pprocess);
    fpcLnTg_Init(&pprocess->line_tag_, pprocess);
    fpcDtTg_Init(&pprocess->delete_tag, pprocess);
    fpcPi_Init(&pprocess->priority, pprocess, pprofile->layer_id, pprofile->list_id,
                pprofile->list_priority);

    pprocess->state.init_state = 0;
    pprocess->unk_0xA = 0;
    pprocess->id = i_procID;
    pprocess->profname = i_profname;
    pprocess->type = fpcBs_MakeOfType(&g_fpcBs_type);
    pprocess->name = pprofile->name;
    fpcPause_Init(pprocess);
    pprocess->methods = pprofile->methods;
    pprocess->profile = pprofile;
    pprocess->append = i_append;
    pprocess->parameters = pprofile->parameters;
    return pprocess;
}

int fpcBs_SubCreate(base_process_class* i_proc) {
    switch (fpcMtd_Create(i_proc->methods, i_proc)) {
    case cPhs_NEXT_e:
    case cPhs_COMPLEATE_e:
        fpcBs_DeleteAppend(i_proc);
        i_proc->state.create_phase = cPhs_NEXT_e;
        return cPhs_NEXT_e;
    case cPhs_INIT_e:
    case cPhs_LOADING_e:
        i_proc->state.init_state = 1;
        i_proc->state.create_phase = cPhs_INIT_e;
        return cPhs_INIT_e;
    case cPhs_UNK3_e:
        i_proc->state.create_phase = cPhs_UNK3_e;
        return cPhs_UNK3_e;
    case cPhs_ERROR_e:
    default:
        i_proc->state.create_phase = cPhs_ERROR_e;
        return cPhs_ERROR_e;
    }
}