⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rpgbase.h

📁 五行MMORPG引擎系统V1.0
💻 H
字号:
//RPGBase.h
/*/////////////////////////////////////////////////////////////////

   李亦
	liease@163.com 4040719
	2006-7-16
/*/////////////////////////////////////////////////////////////////
#ifndef _RPG__RPGBASE_H_
#define _RPG__RPGBASE_H_



//#ifndef _RPGNETOBJECT_H_
//#include "rpg/RPGNetObject.h"
//#endif
#ifndef _RPG__GOBJECT_H_
#include "GObject.h"
#endif

#ifndef _RESMANAGER_H_
#include "core/resManager.h"
#endif
#ifndef _GTEXMANAGER_H_
#include "dgl/gTexManager.h"
#endif

class NetConnection;
struct Move;
class GameConnection;
class	GameBase;
struct GameBaseData;

//template<class _T>	class OBJDictionary;


namespace RPG
{
class RPGProcess;
//class GPlayer;

//----------------------------------------------------------------------------
//----------------------------------------------------------------------------


struct RPGBaseData : public SimDataBlock 
{
  private:
   typedef SimDataBlock Parent;

public:
   bool					packed;
   StringTableEntry	category;
   StringTableEntry	className;

   bool onAdd();

   RPGBaseData();
   static void initPersistFields();
   bool preload(bool server, char errorBuffer[256]);
   void unpackData(BitStream* stream);

   // The derived class should provide the following:
   DECLARE_CONOBJECT(RPGBaseData);
};

DECLARE_CONSOLETYPE(RPGBaseData)
DECLARE_CONSOLETYPE(GameBase)


//----------------------------------------------------------------------------
// A few utility methods for sending datablocks over the net
//----------------------------------------------------------------------------

bool UNPACK_DB_ID(BitStream *, U32 & id);
bool PACK_DB_ID(BitStream *, U32 id);
bool PRELOAD_DB(U32 & id, SimDataBlock **, bool server, const char * clientMissing = NULL, const char * serverMissing = NULL);



//----------------------------------------------------------------------------

class RPGBase : public GObject
{
   typedef GObject Parent;

   friend class RPGProcess;
	//friend class OBJDictionary<GPlayer>;

   /// @name Datablock
   /// @{
private:
   RPGBaseData*		m_pDataBlock;

	/// 相关联的GameBase数据
   GameBase*			m_pGameBase;
   /// @}


   /// @name Tick Processing Internals
   /// @{
private:
   void PLUnlink();
   void PLLinkAfter(RPGBase*);
   void PLLinkBefore(RPGBase*);
   void PLJoin(RPGBase*);


   U32			m_uSequence;                  ///< Tag used to sort objects for processing.
	RPGBase*		m_pLinkPrev;
	RPGBase*		m_pLinkNext;
   SimObjectPtr<RPGBase>	m_objectPtrAfter;

   bool			m_bProcessTick;
   F32			m_fLastDelta;
   /// @}

   // Control interface
   GameConnection*	m_pControllingClient;


public:
   RPGBase();
   virtual ~RPGBase();

   enum ERPGBaseMasks 
	{
      InitialUpdateMask =     1,//Parent::NextFreeMask,
      DataBlockMask =         InitialUpdateMask << 1,
      ExtendedInfoMask =      DataBlockMask << 1,
      ControlMask =           ExtendedInfoMask << 1,
      NextFreeMask =          ControlMask << 1
   };


public:
	///@name 基本操作
	///@{
	virtual void SetPos(Point3F &ptPos);
	virtual void MoveTo(Point3F &ptPos);
	virtual void UpdateFromTS();
	///@}


   /// @name Inherited Functionality.
   /// @{

	bool OnReg();
	void OnUnreg();

   //bool onAdd();
   //void onRemove();
   void inspectPostApply();
   static void initPersistFields();
   static void consoleInit();
   /// @}


   ///@name Datablock
   ///@{
   bool				SetDataBlock(RPGBaseData* dptr);
   bool				SetGameBase(GameBase* pGBase);
   RPGBaseData*	GetDataBlock()		{ return m_pDataBlock; }
   GameBase*		GetGameBase()		{ return m_pGameBase; }

   virtual bool  OnNewDataBlock(RPGBaseData* dptr);
   virtual bool  OnNewGameBase(GameBase* dptr);

	virtual bool AttachTSDatablock(GameBaseData* pGBDatablock);

   ///@}

   /// @name Script
   /// The scriptOnXX methods are invoked by the leaf classes
   /// @{
	CSTR ScriptThis();
   void ScriptOnAdd();
   void ScriptOnNewDataBlock();
   void ScriptOnRemove();
   /// @}


   /// @name Tick Processing
   /// @{
   void SetProcessTick(bool bSet) { m_bProcessTick = bSet; }
   void ProcessAfter(RPGBase *obj);
   void ClearProcessAfter();
   RPGBase* GetProcessAfter() { return m_objectPtrAfter; }

   /// Removes this object from the tick-processing list
   void RemoveFromRPGProcess() { PLUnlink(); }

   /// Processes a move event and updates object state once every 32 milliseconds.
   ///
   /// This takes place both on the client and server, every 32 milliseconds (1 tick).
   ///
   /// @see    RPGProcess
   /// @param  move   Move event corresponding to this tick, or NULL.
   virtual void ProcessTick(const Move *move);

   /// Interpolates between tick events.  This takes place on the CLIENT ONLY.
   ///
   /// @param   delta   Time since last call to interpolate
   virtual void InterpolateTick(F32 delta);

   /// Advances simulation time for animations. This is called every frame.
   ///
   /// @param   dt   Time since last advance call
   virtual void AdvanceTime(F32 dt);

   /// This is a component system thing, gotta ask Clark about it
   virtual void PreprocessMove(Move *move) {}
   /// @}


   /// Draws a bounding box around this object
   //void drawBoundingBox(bool useRenderTransform = false);

   /// @name Network
   /// @see NetObject, NetConnection
   /// @{

   F32  getUpdatePriority(CameraScopeQuery *focusObject, U32 updateMask, S32 updateSkips);
   U32  packUpdate  (NetConnection *conn, U32 mask, BitStream *stream);
   void unpackUpdate(NetConnection *conn,           BitStream *stream);

   /// Write state information necessary to perform client side prediction of an object.
   ///
   /// This information is sent only to the controling object. For example, if you are a client
   /// controlling a Player, the server uses WritePacketData() instead of packUpdate() to
   /// generate the data you receive.
   ///
   /// @param   conn     Connection for which we're generating this data.
   /// @param   stream   Bitstream for output.
   virtual void WritePacketData(GameConnection *conn, BitStream *stream);

   /// Read data written with WritePacketData() and update the object state.
   ///
   /// @param   conn    Connection for which we're generating this data.
   /// @param   stream  Bitstream to read.
   virtual void ReadPacketData(GameConnection *conn, BitStream *stream);

   /// Gets the checksum for packet data.
   ///
   /// Basically writes a packet, does a CRC check on it, and returns
   /// that CRC.
   ///
   /// @see WritePacketData
   /// @param   conn   Game connection
   virtual U32 GetPacketDataChecksum(GameConnection *conn);
   ///@}


   /// @name User control
   /// @{

   /// Returns the client controling this object
   GameConnection *GetControllingClient() { return m_pControllingClient; }

   /// Sets the client controling this object
   /// @param  client   Client that is now controling this object
   virtual void SetControllingClient(GameConnection *client);
   /// @}


   DECLARE_CONOBJECT(RPGBase);
};


};//namespace RPG
#endif //_RPG__RPGBASE_H_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -