//
// Generated by dtk
// Translation Unit: f_pc_layer.cpp
//

#include "f_pc/f_pc_layer.h"
#include "f_pc/f_pc_layer_tag.h"
#include "f_pc/f_pc_method_iter.h"
#include "f_pc/f_pc_method_tag.h"

/* 8003D800-8003D820       .text fpcLy_CancelQTo__FP24process_method_tag_class */
void fpcLy_CancelQTo(process_method_tag_class* i_methods) {
    fpcMtdTg_MethodQTo(i_methods);
}

/* 8003D820-8003D844       .text fpcLy_ToCancelQ__FP11layer_classP24process_method_tag_class */
s32 fpcLy_ToCancelQ(layer_class* i_layer, process_method_tag_class* i_methods) {
    return fpcMtdTg_ToMethodQ(&i_layer->mCancelList, i_methods);
}

/* 8003D844-8003D870       .text fpcLy_CancelMethod__FP24process_method_tag_class */
bool fpcLy_CancelMethod(process_method_tag_class* i_layer) {
    return fpcMtdTg_Do(i_layer) == 1;
}

/* 8003D870-8003D894       .text fpcLy_IntoQueue__FP11layer_classiP16create_tag_classi */
s32 fpcLy_IntoQueue(layer_class* i_layer, int i_treeListNo, create_tag_class* i_createTag, int i_no) {
    return cTg_InsertToTree(&i_layer->mNodeListTree, i_treeListNo, i_createTag, i_no);
}

/* 8003D894-8003D8B8       .text fpcLy_ToQueue__FP11layer_classiP16create_tag_class */
s32 fpcLy_ToQueue(layer_class* i_layer, int i_treeListNo, create_tag_class* i_createTag) {
    return cTg_AdditionToTree(&i_layer->mNodeListTree, i_treeListNo, i_createTag);
}

/* 8003D8B8-8003D8DC       .text fpcLy_QueueTo__FP11layer_classP16create_tag_class */
s32 fpcLy_QueueTo(layer_class* i_layer, create_tag_class* i_createTag) {
    return cTg_SingleCutFromTree(i_createTag);
}

/* 8003D8DC-8003D8F0       .text fpcLy_IsDeletingMesg__FP11layer_class */
BOOL fpcLy_IsDeletingMesg(layer_class* i_layer) {
    return i_layer->counts.mDeletingCount > 0;
}

/* 8003D8F0-8003D900       .text fpcLy_DeletingMesg__FP11layer_class */
void fpcLy_DeletingMesg(layer_class* i_layer) {
    i_layer->counts.mDeletingCount++;
}

/* 8003D900-8003D918       .text fpcLy_DeletedMesg__FP11layer_class */
void fpcLy_DeletedMesg(layer_class* i_layer) {
    if (i_layer->counts.mDeletingCount > 0) {
        i_layer->counts.mDeletingCount--;
    }
}

/* 8003D918-8003D92C       .text fpcLy_IsCreatingMesg__FP11layer_class */
BOOL fpcLy_IsCreatingMesg(layer_class* i_layer) {
    return i_layer->counts.mCreatingCount > 0;
}

/* 8003D92C-8003D93C       .text fpcLy_CreatingMesg__FP11layer_class */
void fpcLy_CreatingMesg(layer_class* i_layer) {
    i_layer->counts.mCreatingCount++;
}

/* 8003D93C-8003D954       .text fpcLy_CreatedMesg__FP11layer_class */
void fpcLy_CreatedMesg(layer_class* i_layer) {
    if (i_layer->counts.mCreatingCount > 0) {
        i_layer->counts.mCreatingCount--;
    }
}

layer_class l_fpcLy_Crear = {
    NULL, NULL, 0, 0xFFFFFFFF, NULL, 0, NULL, NULL, NULL, 0, 0, 0,
};

node_list_class l_fpcLy_LayerList = {
    NULL,
    NULL,
    0,
};

/* 8003D954-8003D964       .text fpcLy_RootLayer__Fv */
layer_class* fpcLy_RootLayer(void) {
    return (layer_class*)l_fpcLy_LayerList.mpHead;
}

static layer_class* l_fpcLy_CurrLayer_p;

/* 8003D964-8003D96C       .text fpcLy_SetCurrentLayer__FP11layer_class */
void fpcLy_SetCurrentLayer(layer_class* i_layer) {
    l_fpcLy_CurrLayer_p = i_layer;
}

/* 8003D96C-8003D974       .text fpcLy_CurrentLayer__Fv */
layer_class* fpcLy_CurrentLayer() {
    return l_fpcLy_CurrLayer_p;
}

/* 8003D974-8003D9C4       .text fpcLy_Search__FUi */
layer_class* fpcLy_Search(unsigned int i_id) {
    layer_class* layer_p = fpcLy_RootLayer();
    while (layer_p != NULL) {
        if (layer_p->mLayerID == i_id) {
            return layer_p;
        }
        layer_p = (layer_class*)layer_p->mNode.mpNextNode;
    }
    return NULL;
}

/* 8003D9C4-8003DA34       .text fpcLy_Layer__FUi */
layer_class* fpcLy_Layer(unsigned int i_id) {
    if (i_id == fpcLy_ROOT_e || fpcLy_RootLayer()->mLayerID == i_id) {
        return fpcLy_RootLayer();
    } else if (i_id == fpcLy_CURRENT_e || fpcLy_CurrentLayer()->mLayerID == i_id) {
        return fpcLy_CurrentLayer();
    } else {
        return fpcLy_Search(i_id);
    }
}

/* 8003DA34-8003DA60       .text fpcLy_Regist__FP11layer_class */
void fpcLy_Regist(layer_class* i_layer) {
    cLs_Addition(&l_fpcLy_LayerList, (node_class*)i_layer);
}

/* 8003DA60-8003DB14       .text fpcLy_Delete__FP11layer_class */
s32 fpcLy_Delete(layer_class* i_layer) {
    if (i_layer->mNodeListTree.mpLists->mSize == 0 && i_layer->mCancelList.mSize == 0) {
        cLs_SingleCut((node_class*)i_layer);
        *i_layer = l_fpcLy_Crear;
        return 1;
    } else {
        return 0;
    }
}

/* 8003DB14-8003DB40       .text fpcLy_Cancel__FP11layer_class */
s32 fpcLy_Cancel(layer_class* i_layer) {
    return fpcMtdIt_Method(&i_layer->mCancelList, (fpcMtdIt_MethodFunc)fpcLy_CancelMethod);
}

/* 8003DB40-8003DC78       .text fpcLy_Create__FP11layer_classPvP15node_list_classi */
void fpcLy_Create(layer_class* i_layer, void* i_node, node_list_class* i_nodeList, int i_numLists) {
    static int IsInitOfLayerList = 1;
    static int layer_id = 0;
    *i_layer = l_fpcLy_Crear;
    cNd_Create((node_class*)i_layer, NULL);
    i_layer->mLayerID = layer_id++;
    i_layer->mpPcNode = static_cast<process_node_class*>(i_node);
    if (IsInitOfLayerList == 1) {
        IsInitOfLayerList = 0;
        cLs_Create(&l_fpcLy_LayerList);
        fpcLy_SetCurrentLayer(i_layer);
    }
    i_layer->mNodeListTree.mpLists = i_nodeList;
    i_layer->mNodeListTree.mNumLists = i_numLists;
    cTr_Create(&i_layer->mNodeListTree, i_layer->mNodeListTree.mpLists, i_layer->mNodeListTree.mNumLists);
    fpcLy_Regist(i_layer);
}
