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

📄 rpgbase.cc

📁 五行MMORPG引擎系统V1.0
💻 CC
📖 第 1 页 / 共 2 页
字号:
//RPGBase.cc
/*/////////////////////////////////////////////////////////////////

   李亦
	liease@163.com 4040719
	2006-7-16
/*/////////////////////////////////////////////////////////////////

#include "platform/platform.h"
#include "rpg/gobjects/RPGBase.h"
#include "rpg/RPGProcess.h"
#include "console/consoleTypes.h"
#include "console/consoleInternal.h"
#include "core/bitStream.h"
#include "sim/netConnection.h"
#include "game/gameConnection.h"
#include "math/mathIO.h"
#include "dgl/dgl.h"
#include "game/gameBase.h"



namespace RPG
{
//static RPGBaseData& _New()
//{
//	static RPGBaseData bd;
//	return bd;
//}
//
//static RPGBaseData& _New2()
//{
//	RPGBaseData& aa = _New();
//	return aa;
//}

//----------------------------------------------------------------------------
// Ghost update relative priority values

static F32 sUpFov       = 1.0;
static F32 sUpDistance  = 0.4;
static F32 sUpVelocity  = 0.4;
static F32 sUpSkips     = 0.2;
static F32 sUpOwnership = 0.2;
static F32 sUpInterest  = 0.2;


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

IMPLEMENT_CO_DATABLOCK_V1(RPGBaseData);

RPGBaseData::RPGBaseData()
{
   category = "";
   className = "";
   packed = false;
}

bool RPGBaseData::onAdd()
{
   if (!Parent::onAdd())
      return false;

   // Link our object name to the datablock class name and
   // then onto our C++ class name.
   const char* name = getName();
   if (name && name[0] && getClassRep()) 
	{
      bool linkSuccess = false;
      Namespace *parent = getClassRep()->getNameSpace();
      if (className && className[0] && dStricmp(className, parent->mName)) 
		{
         linkSuccess = Con::linkNamespaces(parent->mName,className);
         if(linkSuccess)
            linkSuccess = Con::linkNamespaces(className,name);
      }
      else
         linkSuccess = Con::linkNamespaces(parent->mName,name);
      if(linkSuccess)
         mNameSpace = Con::lookupNamespace(name);
   }

   // If no className was specified, set it to our C++ class name
   if (!className || !className[0])
      className = getClassRep()->getClassName();

   return true;
}

void RPGBaseData::initPersistFields()
{
   Parent::initPersistFields();
   addField("category",   TypeCaseString,          Offset(category,   RPGBaseData));
   addField("className",  TypeString,              Offset(className,  RPGBaseData));
}

bool RPGBaseData::preload(bool server, char errorBuffer[256])
{
   if (!Parent::preload(server, errorBuffer))
      return false;
   packed = false;
   return true;
}

void RPGBaseData::unpackData(BitStream* stream)
{
   Parent::unpackData(stream);
   packed = true;
}



//----------------------------------------------------------------------------
bool UNPACK_DB_ID(BitStream * stream, U32 & id)
{
   if (stream->readFlag())
   {
      id = stream->readRangedU32(DataBlockObjectIdFirst,DataBlockObjectIdLast);
      return true;
   }
   return false;
}


bool PACK_DB_ID(BitStream * stream, U32 id)
{
   if (stream->writeFlag(id))
   {
      stream->writeRangedU32(id,DataBlockObjectIdFirst,DataBlockObjectIdLast);
      return true;
   }
   return false;
}


bool PRELOAD_DB(U32 & id, SimDataBlock ** data, bool server, const char * clientMissing, const char * serverMissing)
{
   if (server)
   {
      if (*data)
         id = (*data)->getId();
      else if (server && serverMissing)
      {
         Con::errorf(ConsoleLogEntry::General,serverMissing);
         return false;
      }
   }
   else
   {
      if (id && !Sim::findObject(id,*data) && clientMissing)
      {
         Con::errorf(ConsoleLogEntry::General,clientMissing);
         return false;
      }
   }
   return true;
}
//----------------------------------------------------------------------------


//bool RPGBase::gShowBoundingBox;

//----------------------------------------------------------------------------
IMPLEMENT_CO_NETOBJECT_V1(RPGBase);


RPGBase::RPGBase()
{
   mNetFlags.set(Ghostable);
   mTypeMask			|= RPGBaseObjectType;

   m_objectPtrAfter	= 0;
   m_uSequence			= 0;
   m_fLastDelta		= 0;
   m_pDataBlock		= 0;
   m_pGameBase			= 0;
   m_bProcessTick		= true;
   //m_pIDName			= StringTable->getBlank();
   m_pControllingClient = 0;

   m_pLinkNext = this;
	m_pLinkPrev = this;
}

RPGBase::~RPGBase()
{
   PLUnlink();
}




void RPGBase::SetPos(Point3F &ptPos)
{
	if(m_pGameBase)
	{
		m_pGameBase->setPosition(ptPos);
	}
}

void RPGBase::MoveTo(Point3F &ptPos)
{
	if(m_pGameBase)
	{
		m_pGameBase->moveTo(ptPos);
	}
}


void RPGBase::UpdateFromTS()
{
}

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

//bool RPGBase::onAdd()
//{
//	AssertFatal(0,"RPGBase系列不允许在脚本中自动创建,需要由RPGDataMan通过Reg生成");
//	return false;
//}
//
//void RPGBase::onRemove()
//{
//}

bool RPGBase::OnReg()
{
	if(!Parent::OnReg())
		return false;
	//在Dataman Reg成功后,将加到 g_RPGProcess中去
   g_RPGProcess.addObject(this);
   return true;
}

void RPGBase::OnUnreg()
{
   PLUnlink();
}



bool RPGBase::OnNewDataBlock(RPGBaseData* dptr)
{
   m_pDataBlock = dptr;

   if (!m_pDataBlock)
      return false;

   GSetMaskBits(DataBlockMask);
   return true;
}

bool RPGBase::OnNewGameBase(GameBase* dptr)
{
   //m_pGameBase = dptr;

   if (!dptr)
      return false;
	//这是客户端逻辑,可不用mask处理
   //GSetMaskBits(DataBlockMask);
   return true;
}



void RPGBase::inspectPostApply()
{
   Parent::inspectPostApply();
   GSetMaskBits(ExtendedInfoMask);
}


//----------------------------------------------------------------------------
void RPGBase::ProcessTick(const Move*)
{
   m_fLastDelta = 0;
}

void RPGBase::InterpolateTick(F32 delta)
{
   m_fLastDelta = delta;
}

void RPGBase::AdvanceTime(F32)
{
}


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

F32 RPGBase::getUpdatePriority(CameraScopeQuery *camInfo, U32 updateMask, S32 updateSkips)
{
	return 1.f;
   //updateMask;

   //// Calculate a priority used to decide if this object
   //// will be updated on the client.  All the weights
   //// are calculated 0 -> 1  Then weighted together at the
   //// end to produce a priority.
   //Point3F pos;
   //getWorldBox().getCenter(&pos);
   //pos -= camInfo->pos;
   //F32 dist = pos.len();
   //if (dist == 0.0f) dist = 0.001f;
   //pos *= 1.0f / dist;

   //// Weight based on linear distance, the basic stuff.
   //F32 wDistance = (dist < camInfo->visibleDistance)?
   //   1.0f - (dist / camInfo->visibleDistance): 0.0f;

   //// Weight by field of view, objects directly in front
   //// will be weighted 1, objects behind will be 0
   //F32 dot = mDot(pos,camInfo->orientation);
   //bool inFov = dot > camInfo->cosFov;
   //F32 wFov = inFov? 1.0f: 0;

   //// Weight by linear velocity parallel to the viewing plane
   //// (if it's the field of view, 0 if it's not).
   //F32 wVelocity = 0.0f;
   //if (inFov)
   //{
   //   Point3F vec;
   //   mCross(camInfo->orientation,getVelocity(),&vec);
   //   wVelocity = (vec.len() * camInfo->fov) /

⌨️ 快捷键说明

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