Files

202 lines
5.6 KiB
C
Raw Permalink Normal View History

2025-01-09 17:45:40 +08:00
#pragma once
/***************************************************************/
/*
/* 实体的观察者子系统
/* 定时更新实体可视范围的实体的实体出现和消失,玩家视野出现,消失实体要通知客户端
/* 1)维护实体的可视实体列表
/* 2)实体出现,消失通知
/* 3)可视范围范围的广播接口
/***************************************************************/
#pragma once
class CObserverTag{}; ///< 没有实质用途的类
/// 实体的出现,消失,删除标记
enum tagEntityAppear
{
eENTITY_APPEAR_UNCHANGE, ///< 没有变化
eENTITY_APPEAR_NEW, ///< 新出现的
eENTITY_APPEAR_DELETE, ///< 删除的
};
/// 实体的handle + 标记的结构体
struct EntityHandleTag
{
EntityHandle m_handle;
BYTE m_tag;
};
/// 实体的handle + 标记的结构体
struct EntityHandleTagEx
{
EntityHandle m_handle;
BYTE m_tag;
BYTE type;
};
enum
{
eENTITY_SPC_NULL,
eENTITY_SPC_NEW_DEL,
eENTITY_SPC_OLD_DEL,
eENTITY_SPC_FULL_DEL,
};
/// 附近的一些玩家的一些事件,通过OnEvent接口转过来
enum tagNearEntityEvent
{
neEventMove, ///< 跳跃
};
typedef CHandleList<EntityHandleTag,CObserverTag> CObserverEntityList;
class CObserverSystem:
public CEntitySubSystem<enObserverSystemID,CObserverSystem,CAnimal>
{
public:
/// 定时调用
VOID OnTimeCheck(TICKCOUNT nTickCount) ;//check
/**
* @brief 广
* @param pBuff
* @param nSize
* @param bToSelf
* @param bToNewAppearEntity
* @return void
*/
void BroadCast (char * pBuff,SIZE_T nSize,bool bToSelf =false,bool bToNewAppearEntity =true);
/// 广播实体消息,@param boToSelf 是否向自己发送
void BroadCastEntityMsg(const CEntityMsg &msg, bool boToSelf = true);
/// 销毁的时候调用
void Destroy() {
m_sEntityList.clear();
} ///< 这里要清除自己的观察者列表
void Clear();
void ClearEntityList();
/**
* @brief
* @param nEventID ID
* @param nParam1 1
* @param nParam2 2
* @param pData
* @return void
*/
void OnEvent(INT_PTR nEventID,INT_PTR nParam1=0,INT_PTR nParam2=0,void * pData=NULL);
EntityHandle FindEntityByName(const char *pEntityName);
/**
* @brief
* @return CObserverEntityList&:
*/
CVector<EntityHandleTag>& GetVisibleList()
{
return m_sEntityList;
}
////能否看到一个实体
//inline bool CanSee(CEntity * pEntity);
/// 视野里出现了一个实体
void EntityAppear(const EntityHandle &handle, CEntity* pEntity);
/// 视野里消失了一个实体
void EntityDisappear(const EntityHandle &handle) ;
/**
* @brief
* @return void
*/
void SendPosChangeToOwner();
/**
* @brief
* @return void
*/
void ClearObserveList();
/**
* @brief
* @return void
* @Remark
*/
void UpdateActorEntityProp();
private:
void EntityAppearActor(const EntityHandle &handle, CActor* pOtherActor);
void EntityAppearDropItem(const EntityHandle &handle, CEntity* pItem);
void EntityAppearSpecialEntity(const EntityHandle &handle, CEntity* pSpecialEntity);
void EntityAppearMonster(const EntityHandle &handle, CEntity* pEntity);
void EntityAppearPet(const EntityHandle &handle, CEntity* pEntity);
void EntityAppearSlave(const EntityHandle &handle, CEntity* pEntity);
void EntityAppearNpc(const EntityHandle &handle, CEntity* pEntity);
void EntityAppearDefault(const EntityHandle &handle, CEntity* pEntity);
/**
* @brief
* @param nOldUserCount
* @param vecVisiblePlayers
* @return void
*/
void CheckEntitypPropery(INT_PTR nOldUserCount, CVector<EntityHandleTag>& vecVisiblePlayers);
/**
* @brief owner是否是玩家
* @return bool
* @remark
*/
bool IsOwnerActor();
/*
* @brief 广
* @return void
* @remark 广
*/
void SendPropChangeToOwner();
////////////////////////////////////////////////////////////////////////////////
/// 这部分用于怪物观察者子系统的优化,玩家在更新周围实体列表的时候直接处理新出现的
/// 和消失的,直接更新对方的观察者列表
/// 注意:只针对怪物和采集怪
/// 玩家进入怪物视野
void onActorAppear(CActor* pActor);
/// 玩家离开怪物视野
void onActorDisappear(CActor* pActor);
////////////////////////////////////////////////////////////////////////////////
/*
* Comments:push的方式玩家列表
* Param INT_PTR nEntityType:
* @Return bool:使true
*/
inline bool NeedPushActor(INT_PTR nEntityType)
{
switch (nEntityType)
{
case enMonster:
case enGatherMonster:
case enPet:
case enHero:
return true;
}
return false;
}
VOID CheckList(EntityHandle ignore, EntityVector& appear, EntityVector& disappear, CVector<EntityHandleTag>* intersection);
void NetworkCutDown(TICKCOUNT nTick);//跨服领主减少玩家
public:
static SequenceEntityList s_orderVisibleSet;
static CVector<EntityHandleTag> *s_OBEntityList; // 观察者实体列表,静态数组,用于数据中转用
static EntityVector* s_seqVisibleList;
private:
CVector<EntityHandleTag> m_sEntityList; // 周围实体列表(采取数组的方式存储)
};