Files
dusklight/src/f/f_pc/f_pc_priority.cpp
T
lepelog 0555115de8 A few f_pc files (#26)
* f_pc_base, one non matching

* some of f_pc_manager

* f_pc_node OK

* f_pc_pause partly

* started node_req

* more progress

* most of node req

* delete unused asm

* node req header and param names

* param renaming

* header for manager

* review comment struct names

* fpcM_Management OK

* int -> s32

* merge master

* most of f_pc_create_iter

* f_pc_stdcreate_req OK

* f_pc_fstcreate OK

* f_pc_leaf OK

* f_pc_draw OK

* f_pc_deletor partly

* fix parameter type in f_pc_pause

* review

* review, use cPh enum and fix process_profile_definition struct

* convert f_pc files to C

* matched more functions

* fix global.h

* fix variable types

* format

* mpre Phs enum

* fix merge errors

* fix gamepad stopPatternedRumble

* format

* delete leftover files from merge

* move asm to correct folder

* revert f_pc from C to CPP

* remove C hacks and format

* format

* OK
2020-12-31 15:12:29 -05:00

149 lines
4.1 KiB
C++

#include "f/f_pc/f_pc_priority.h"
#include "f/f_pc/f_pc_base.h"
#include "f/f_pc/f_pc_layer.h"
#include "f/f_pc/f_pc_layer_tag.h"
// f_pc_priority::crear$2186
extern process_priority_queue_info lbl_804505E8;
// f_pc_priority::l_fpcPi_Queue
extern node_list_class lbl_803F4E58;
extern "C" {
s32 fpcPi_IsInQueue(process_priority_class* pPi) {
return cTg_IsUse(&pPi->mBase);
}
s32 fpcPi_QueueTo(process_priority_class* pPi) {
cTg_SingleCut(&pPi->mBase);
fpcLy_CancelQTo(&pPi->mMtdTag);
return 1;
}
s32 fpcPi_ToQueue(process_priority_class* pPi) {
u32 layer = pPi->mInfoQ.mLayer;
if (cTg_Addition(&lbl_803F4E58, &pPi->mBase)) {
if (layer != 0xFFFFFFFD) {
layer_class* pLayer = fpcLy_Layer(layer);
if (!fpcLy_ToCancelQ(pLayer, &pPi->mMtdTag)) {
cTg_SingleCut(&pPi->mBase);
return 0;
}
}
return 1;
}
return 0;
}
process_priority_class* fpcPi_GetFromQueue(void) {
process_priority_class* pPi = (process_priority_class*)cTg_GetFirst(&lbl_803F4E58);
if (pPi != NULL) {
base_process_class* pProc = (base_process_class*)pPi->mBase.mpTagData;
process_priority_class* pProcPi = &pProc->mPi;
fpcLy_CancelQTo(&pProcPi->mMtdTag);
return pProcPi;
}
return NULL;
}
s32 fpcPi_Delete(process_priority_class* pPi) {
fpcPi_QueueTo(pPi);
pPi->mInfoQ.mLayer = lbl_804505E8.mLayer;
pPi->mInfoQ.mListID = lbl_804505E8.mListID;
pPi->mInfoQ.mListPrio = lbl_804505E8.mListPrio;
return 1;
}
s32 fpcPi_IsNormal(u32 layer, u16 listID, u16 priority) {
if ((layer < 0xFFFFFFFE) && (listID < 0xFFFE) && (priority < 0xFFFE))
return 1;
return 0;
}
s32 fpcPi_Change(process_priority_class* pPi, u32 layer, u16 listID, u16 priority) {
base_process_class* pProc = (base_process_class*)pPi->mBase.mpTagData;
BOOL changed = 0;
if (pProc->mInitState == 3)
return 0;
if (!fpcPi_IsNormal(layer, listID, priority))
return 0;
pPi->mInfoQ.mLayer = pPi->mInfoCurr.mLayer;
pPi->mInfoQ.mListID = pPi->mInfoCurr.mListID;
pPi->mInfoQ.mListPrio = pPi->mInfoCurr.mListPrio;
if (layer != 0xFFFFFFFD && pPi->mInfoCurr.mLayer != layer) {
pPi->mInfoQ.mLayer = layer;
changed = 1;
}
if (listID != 0xFFFD && pPi->mInfoCurr.mListID != listID) {
pPi->mInfoQ.mListID = listID;
changed = 1;
}
if (priority != 0xFFFD && pPi->mInfoCurr.mListPrio != priority) {
pPi->mInfoQ.mListPrio = priority;
changed = 1;
}
if (pProc->mInitState == 0 || pProc->mInitState == 1) {
pPi->mInfoCurr.mLayer = pPi->mInfoQ.mLayer;
pPi->mInfoCurr.mListID = pPi->mInfoQ.mListID;
pPi->mInfoCurr.mListPrio = pPi->mInfoQ.mListPrio;
return 1;
}
if (changed == 1)
return fpcPi_ToQueue(pPi);
else
return 0;
}
s32 fpcPi_Handler(void) {
process_priority_class* pPi;
while (pPi = fpcPi_GetFromQueue()) {
base_process_class* pProc = (base_process_class*)pPi->mBase.mpTagData;
layer_management_tag_class* pLayerTag = &pProc->mLyTg;
line_tag* pLineTag = &pProc->mLnTg;
if (fpcLyTg_Move(pLayerTag, pPi->mInfoQ.mLayer, pPi->mInfoQ.mListID,
pPi->mInfoQ.mListPrio) == 1) {
fpcLnTg_Move(pLineTag, pPi->mInfoCurr.mListID);
pPi->mInfoCurr.mLayer = pPi->mInfoQ.mLayer;
pPi->mInfoCurr.mListID = pPi->mInfoQ.mListID;
pPi->mInfoCurr.mListPrio = pPi->mInfoQ.mListPrio;
} else {
return 0;
}
}
return 1;
}
s32 fpcPi_Init(process_priority_class* pPi, void* pUserData, u32 layer, u16 listID, u16 priority) {
if (!fpcPi_IsNormal(layer, listID, priority))
return 0;
pPi->mInfoQ.mLayer = layer;
pPi->mInfoQ.mListID = listID;
pPi->mInfoQ.mListPrio = priority;
pPi->mInfoCurr.mLayer = pPi->mInfoQ.mLayer;
pPi->mInfoCurr.mListID = pPi->mInfoQ.mListID;
pPi->mInfoCurr.mListPrio = pPi->mInfoQ.mListPrio;
cTg_Create(&pPi->mBase, pUserData);
fpcMtdTg_Init(&pPi->mMtdTag, (process_method_tag_func)fpcPi_Delete, pPi);
return 1;
}
}