summaryrefslogtreecommitdiff
path: root/src/f_op/f_op_scene_req.cpp
blob: 17dd3c40598c20013a9075002fe842a185f3c801 (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
/**
 * f_op_scene_req.cpp
 * Scene Process Request
 */

#include "f_op/f_op_scene_req.h"
#include "f_op/f_op_overlap_mng.h"
#include "f_op/f_op_scene.h"
#include "f_op/f_op_scene_pause.h"
#include "f_pc/f_pc_executor.h"
#include "f_pc/f_pc_manager.h"

static cPhs_Step fopScnRq_phase_ClearOverlap(scene_request_class* i_sceneReq) {
    return fopOvlpM_ClearOfReq() == 1 ? cPhs_NEXT_e : cPhs_INIT_e;
    UNUSED(i_sceneReq);
}

static cPhs_Step fopScnRq_phase_Execute(scene_request_class* i_sceneReq) {
    return fpcNdRq_Execute(&i_sceneReq->create_request);
}

static cPhs_Step fopScnRq_phase_IsDoingOverlap(scene_request_class* i_sceneReq) {
    return fopOvlpM_IsDoingReq() == 1 ? cPhs_NEXT_e : cPhs_INIT_e;
    UNUSED(i_sceneReq);
}

static cPhs_Step fopScnRq_phase_IsDoneOverlap(scene_request_class* i_sceneReq) {
    return fopOvlpM_IsDone() == 1 ? cPhs_NEXT_e : cPhs_INIT_e;
    UNUSED(i_sceneReq);
}

static BOOL l_fopScnRq_IsUsingOfOverlap;

static cPhs_Step fopScnRq_phase_Done(scene_request_class* i_sceneReq) {
    
    if (i_sceneReq->create_request.parameters != 1) {
        scene_class* scene = (scene_class*)fpcM_SearchByID(i_sceneReq->create_request.creating_id);
        (void)scene;
        fopScnPause_Disable(scene);
    }

    l_fopScnRq_IsUsingOfOverlap = FALSE;
    return cPhs_NEXT_e;
}

static cPhs_Step fopScnRq_Execute(scene_request_class* i_sceneReq) {
    cPhs_Step phase_state = cPhs_Do(&i_sceneReq->phase_request, i_sceneReq);

    switch (phase_state) {
    case cPhs_NEXT_e:
        return fopScnRq_Execute(i_sceneReq);
        break;
    default:
        break;
    }

    return phase_state;
}

static int fopScnRq_PostMethod(void* i_scene, scene_request_class* i_sceneReq) {
    if (i_sceneReq->fade_request != NULL) {
        fopScnPause_Enable((scene_class*)i_scene);
        fopOvlpM_ToldAboutID(((scene_class*)i_scene)->base.base.id);
    }
    return 1;
}

static int fopScnRq_Cancel(scene_request_class* i_sceneReq) {
    if (i_sceneReq->fade_request != NULL && !fopOvlpM_Cancel()) {
        return 0;
    } else {
        return 1;
    }
}

static scene_request_class* fopScnRq_FadeRequest(s16 i_procname, u16 i_peektime) {
    overlap_request_class* req = NULL;

    if (!l_fopScnRq_IsUsingOfOverlap) {
        req = fopOvlpM_Request(i_procname, i_peektime);
        if (req != NULL) {
            l_fopScnRq_IsUsingOfOverlap = TRUE;
        }
    }

    return (scene_request_class*)req;
}

fpc_ProcID fopScnRq_Request(int i_reqType, scene_class* i_scene, s16 i_procName, void* i_data, s16 i_fadename,
                     u16 i_peektime) {
    static node_create_request_method_class submethod = {
        (process_method_func)fopScnRq_Execute,
        (process_method_func)fopScnRq_Cancel,
        NULL,
        (process_method_func)fopScnRq_PostMethod,
    };

    static cPhs__Handler noFadeFase[8] = {
        (cPhs__Handler)fopScnRq_phase_Execute,
        (cPhs__Handler)fopScnRq_phase_Done,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
        NULL,
    };

    static cPhs__Handler fadeFase[8] = {
        (cPhs__Handler)fopScnRq_phase_IsDoingOverlap,
        (cPhs__Handler)fopScnRq_phase_IsDoneOverlap,
        (cPhs__Handler)fopScnRq_phase_Execute,
        (cPhs__Handler)fopScnRq_phase_ClearOverlap,
        (cPhs__Handler)fopScnRq_phase_IsDoneOverlap,
        (cPhs__Handler)fopScnRq_phase_Done,
        NULL,
        NULL,
    };

    scene_request_class* fade_req = NULL;
    cPhs__Handler* phase_handler = noFadeFase;

    scene_request_class* req = (scene_request_class*)fpcNdRq_Request(
        sizeof(scene_request_class), i_reqType, (process_node_class*)i_scene, i_procName, i_data,
        &submethod);

    if (req == NULL) {
        return fpcM_ERROR_PROCESS_ID_e;
    }

    if (i_fadename != 0x7FFF) {
        phase_handler = fadeFase;
        fade_req = fopScnRq_FadeRequest(i_fadename, i_peektime);
        if (fade_req == NULL) {
            fpcNdRq_Delete(&req->create_request);
            return fpcM_ERROR_PROCESS_ID_e;
        }
    }

    req->fade_request = fade_req;
    cPhs_Set(&req->phase_request, phase_handler);
    return req->create_request.request_id;
}

s32 fopScnRq_ReRequest(fpc_ProcID i_requestId, s16 i_procName, void* i_data) {
    return fpcNdRq_ReRequest(i_requestId, i_procName, i_data);
}

int fopScnRq_Handler() {
    return fpcNdRq_Handler();
}