/*---------------------------------------------------------------------------*
  Project:  simple particle library
  File:     spl_manager.h

  俽俹俴儅僱乕僕儍

  Revision 1.3  2005/11/09 09:53:26  matsuda
  SPL儔僀僽儔儕偑峏怴偝傟偨偺偱峏怴

  Revision 1.9  2005/08/30 09:15:30  okane_shinji
  SPL_SetDrawOrder傪捛壛

  Revision 1.8  2005/06/27 07:46:14  okane_shinji
  剩眶マネ〖ジャを艰り胺うときでも纷换サイクル肋年が铜跟になるように饯赖

  Revision 1.7  2005/01/20 04:20:48  okane_shinji
  僷乕僥傿僋儖悢偲僄儈僢僞悢傪庢摼偡傞娭悢捛壛

  Revision 1.6  2004/11/26 06:07:31  okane_shinji
  婡擻捛壛

  Revision 1.5  2004/08/17 05:40:39  okane_shinji
  僷乕僥傿僋儖偺億儕僑儞懏惈偺misc僼儔僌傪曄峏偱偒傞傛偆偵曄峏丅

  Revision 1.4  2004/07/05 07:33:02  okane_shinji
  億儕僑儞ID妱傝摉偰傪壜曄偵丅娭悢柤傪曄峏丅

  Revision 1.3  2004/06/23 07:21:21  okane_shinji
  僇儔乕傾僯儊丄儖乕僾嵞惗丄億儕僑儞丄僨傿儗僋僔儑僫儖價儖儃乕僪偺夵椙

  Revision 1.2  2004/05/24 09:44:09  konoh
  仭儊儌儕妋曐偺曽朄傪儐乕僓僐乕儖僶僢僋偱峴偆傛偆偵曄峏

  Revision 1.1  2004/04/08 00:23:26  konoh
  (none)

 *---------------------------------------------------------------------------*/

#ifndef __SPL_MANAGER_H__
#define __SPL_MANAGER_H__

#include "spl_emitter.h"
#include "spl_particle.h"
#include "spl_resource.h"
#include "spl_texture.h"

/* 峔憿懱側偳 -------------------------------------------------------------- */

// 儊儌儕妋曐僐乕儖僶僢僋
typedef void* (*SPLAlloc)(u32);

// 儅僱乕僕儍峔憿懱
typedef struct SPLManager
{
    // 僸乕僾娭學
    SPLAlloc alloc;

    // 儕僗僩娭學
    SPLEmitterList act_emtr_list;
    SPLEmitterList ina_emtr_list;
    SPLParticleList ina_ptcl_list;

    // 儕僜乕僗娭學
    SPLResource* res_ary;
    SPLTexture*  tex_ary;
    u16 res_num;
    u16 tex_num;

    u16 max_emtr_num;
    u16 max_ptcl_num;
    
    //u16 min_polygonID ;
    //u16 max_polygonID ;

    struct
    {
        u32 min:6;
        u32 max:6;
        u32 current:6;
        u32 fix:6;
        u32 drawOrder:1;
        u32 reserved:7;
    } polygonID ;

    s32 misc_flag ;

    // 昤夋丒寁嶼偵昁梫側儅僱乕僕儍偺僇儗儞僩娐嫬傪奿擺偡傞偨傔偺峔憿懱
    struct
    {
        // 尰嵼張棟拞偺僄儈僢僞
        SPLEmitter* p_emtr ;

        // 尰嵼揔梡偝傟偰偄傞僇儊儔
        const MtxFx43*    p_cmr  ;
    } current_state ;


    u16 uCurrentCycle ;
    u16 reserved ;

} SPLManager;

/* ------------------------------------------------------------------------- */

#define SPL_MANAGER_DRAWORDER_INREVERSE 0
#define SPL_MANAGER_DRAWORDER_INTURN    1

/* ------------------------------------------------------
 * 昤夋弴傪愝掕
 *------------------------------------------------------*/
static inline void SPL_SetDrawOrder( SPLManager* p_mgr, int flag )
{
    p_mgr->polygonID.drawOrder = flag ;
}

/* ------------------------------------------------------
 * 億儕僑儞懏惈偺misc僼儔僌傪愝掕
 *------------------------------------------------------*/
static inline void SPL_SetPolygonAttrMiscFlag( SPLManager* p_mgr, int flag )
{
    p_mgr->misc_flag = flag ;
}

/* ------------------------------------------------------
 * 尰嵼桳岠側僄儈僢僞偺悢傪庢摼
 *------------------------------------------------------*/
static inline s32 SPL_GetEmitterNum( SPLManager* p_mgr )
{
    return p_mgr->act_emtr_list.node_num ;
}

/* ------------------------------------------------------
 * 尰嵼桳岠側僷乕僥傿僋儖偺悢傪庢摼
 *------------------------------------------------------*/
static inline s32 SPL_GetWholeParticleNum( SPLManager* p_mgr )
{
    return p_mgr->max_ptcl_num - p_mgr->ina_ptcl_list.node_num ;
}



#endif
