#ifndef KBE_BASE_ENTITY_H
#define KBE_BASE_ENTITY_H
#include "profile.h"
#include "common/common.h"
#include "helper/debug_helper.h"
#include "pyscript/math.h"
#include "pyscript/scriptobject.h"
#include "entitydef/datatypes.h"
#include "entitydef/entitydef.h"
#include "entitydef/scriptdef_module.h"
#include "entitydef/entity_macro.h"
#include "entitydef/entity_component.h"
#include "server/script_timers.h"
namespace KBEngine{
class EntityCall;
class EntityComponent;
class EntityMessagesForwardCellappHandler;
class BaseMessagesForwardClientHandler;
namespace Network
{
class Channel;
}
class Entity : public script::ScriptObject
{
BASE_SCRIPT_HREADER(Entity, ScriptObject)
ENTITY_HEADER(Entity)
public:
Entity(ENTITY_ID id, const ScriptDefModule* pScriptModule,
PyTypeObject* pyType = getScriptType(), bool isInitialised = true);
~Entity();
是否存储数据库
*/
INLINE bool hasDB() const;
INLINE void hasDB(bool has);
数据库关联ID
*/
INLINE DBID dbid() const;
INLINE void dbid(uint16 dbInterfaceIndex, DBID id);
DECLARE_PY_GET_MOTHOD(pyGetDBID);
数据库关联名称
*/
INLINE uint16 dbInterfaceIndex() const;
DECLARE_PY_GET_MOTHOD(pyGetDBInterfaceName);
销毁cell部分的实体
*/
bool destroyCellEntity(void);
DECLARE_PY_MOTHOD_ARG0(pyDestroyCellEntity);
脚本获取entityCall
*/
DECLARE_PY_GET_MOTHOD(pyGetCellEntityCall);
EntityCall* cellEntityCall(void) const;
void cellEntityCall(EntityCall* entityCall);
脚本获取entityCall
*/
DECLARE_PY_GET_MOTHOD(pyGetClientEntityCall);
EntityCall* clientEntityCall() const;
void clientEntityCall(EntityCall* entityCall);
是否创建过space
*/
INLINE bool isCreatedSpace();
cellData部分
*/
bool installCellDataAttr(PyObject* dictData = NULL, bool installpy = true);
void createCellData(void);
void destroyCellData(void);
void addPersistentsDataToStream(uint32 flags, MemoryStream* s);
PyObject* createCellDataDict(uint32 flags);
INLINE PyObject* getCellData(void) const;
INLINE bool creatingCell(void) const;
请求cell部分将entity的celldata更新一份过来
*/
void reqBackupCellData();
写备份信息到流
*/
void writeBackupData(MemoryStream* s);
void onBackup();
写存档信息到流
*/
void writeArchiveData(MemoryStream* s);
将要保存到数据库之前的通知
*/
void onWriteToDB();
void onCellWriteToDBCompleted(CALLBACK_ID callbackID, int8 shouldAutoLoad, int dbInterfaceIndex);
void onWriteToDBCallback(ENTITY_ID eid, DBID entityDBID, uint16 dbInterfaceIndex,
CALLBACK_ID callbackID, int8 shouldAutoLoad, bool success);
entity第一次写数据库由dbmgr返回的dbid
*/
void onGetDBID(Network::Channel* pChannel, DBID dbid);
创建cell失败回调
*/
void onCreateCellFailure(void);
创建cell成功回调
*/
void onGetCell(Network::Channel* pChannel, COMPONENT_ID componentID);
丢失cell了的通知
*/
void onLoseCell(Network::Channel* pChannel, MemoryStream& s);
当cellapp意外终止后, baseapp如果能找到合适的cellapp则将其恢复后
会调用此方法
*/
void onRestore();
备份cell数据
*/
void onBackupCellData(Network::Channel* pChannel, MemoryStream& s);
客户端丢失
*/
void onClientDeath();
远程呼叫本entity的方法
*/
void onRemoteMethodCall(Network::Channel* pChannel, MemoryStream& s);
销毁这个entity
*/
void onDestroy(bool callScript);
销毁base内部通知
*/
void onDestroyEntity(bool deleteFromDB, bool writeToDB);
为一个baseEntity在指定的cell上创建一个cellEntity
*/
DECLARE_PY_MOTHOD_ARG1(createCellEntity, PyObject_ptr);
为一个baseEntity在指定的cell上还原一个cellEntity
*/
void restoreCell(EntityCallAbstract* cellEntityCall);
INLINE bool inRestore();
创建一个cellEntity在一个新的space上
*/
DECLARE_PY_MOTHOD_ARG1(createCellEntityInNewSpace, PyObject_ptr);
客户端直接发送消息给cell实体
*/
void forwardEntityMessageToCellappFromClient(Network::Channel* pChannel, MemoryStream& s);
发送消息到cellapp上
*/
void sendToCellapp(Network::Bundle* pBundle);
void sendToCellapp(Network::Channel* pChannel, Network::Bundle* pBundle);
传送回调
*/
void onTeleportCB(Network::Channel* pChannel, SPACE_ID spaceID, bool fromCellTeleport);
void onTeleportFailure();
void onTeleportSuccess(SPACE_ID spaceID);
entity请求迁移到另一个cellapp上的过程开始和结束。
*/
void onMigrationCellappStart(Network::Channel* pChannel, COMPONENT_ID sourceCellAppID, COMPONENT_ID targetCellAppID);
void onMigrationCellappEnd(Network::Channel* pChannel, COMPONENT_ID sourceCellAppID, COMPONENT_ID targetCellAppID);
void onMigrationCellappOver(COMPONENT_ID targetCellAppID);
设置获取是否自动存档
*/
INLINE int8 shouldAutoArchive() const;
INLINE void shouldAutoArchive(int8 v);
DECLARE_PY_GETSET_MOTHOD(pyGetShouldAutoArchive, pySetShouldAutoArchive);
设置获取是否自动备份
*/
INLINE int8 shouldAutoBackup() const;
INLINE void shouldAutoBackup(int8 v);
DECLARE_PY_GETSET_MOTHOD(pyGetShouldAutoBackup, pySetShouldAutoBackup);
cellapp宕了
*/
void onCellAppDeath();
转发消息完成
*/
void onBufferedForwardToCellappMessagesOver();
void onBufferedForwardToClientMessagesOver();
INLINE BaseMessagesForwardClientHandler* pBufferedSendToClientMessages();
设置实体持久化数据是否已脏,脏了会自动存档
*/
INLINE void setDirty(uint32* digest = NULL);
INLINE bool isDirty() const;
protected:
定义属性数据被改变了
*/
void onDefDataChanged(EntityComponent* pEntityComponent, const PropertyDescription* propertyDescription,
PyObject* pyData);
从db擦除在线log
*/
void eraseEntityLog();
protected:
EntityCall* clientEntityCall_;
EntityCall* cellEntityCall_;
PyObject* cellDataDict_;
bool hasDB_;
DBID DBID_;
bool isGetingCellData_;
bool isArchiveing_;
int8 shouldAutoArchive_;
int8 shouldAutoBackup_;
bool creatingCell_;
bool createdSpace_;
bool inRestore_;
BaseMessagesForwardClientHandler* pBufferedSendToClientMessages_;
uint32 persistentDigest_[5];
uint16 dbInterfaceIndex_;
};
}
#ifdef CODE_INLINE
#include "entity.inl"
#endif
#endif