second life代码初研究

来源:互联网 发布:mpp数据库 百科 编辑:程序博客网 时间:2024/06/03 20:59

second life这种非拘束的 允许客户上传物体从而建立一个庞大的虚拟世界的游戏是很有前途的.这里开始初步分析其代码.其client已经go public

second life 的client 端的通信代码是包装在
llmessage项目里的各个类
然后如果是命令的话
在不同的实际功能的类里包含了不同的 packmessage 与unpackmessage的方法,
要进行同步对象的话则包装了pack 和unpack的方法

其中最重要的人物是通过agent类来进行管理的在 newview项目里的llagent类.
这个是客户自身可以操作的类

// forward declarations

//

class LLAgent : public LLObservable
{

 

}
从agent的teleportViaLandmark可以知道server是怎么存储和管理不同的
场景的.每个场景都有一个uuid

// Landmark ID = LLUUID::null means teleport home
void LLAgent::teleportViaLandmark(const LLUUID& landmark_id)
{
 LLViewerRegion *regionp = getRegion();
 if(regionp && teleportCore())
 {
  LLMessageSystem* msg = gMessageSystem;
  msg->newMessageFast(_PREHASH_TeleportLandmarkRequest);
  msg->nextBlockFast(_PREHASH_Info);
  msg->addUUIDFast(_PREHASH_AgentID, getID());
  msg->addUUIDFast(_PREHASH_SessionID, getSessionID());
  msg->addUUIDFast(_PREHASH_LandmarkID, landmark_id);
  sendReliableMessage();
 }
}


//对于大量的资源文件是通过一个独立的虚拟文件系统vfs来操作的.这里
每个image通过一个独立的uuid来表示.在这里上层系统从vfs里得到要操作的image

//BOOL LLViewerImage::loadLocalImage(const LLUUID &image_id)
{
 LLMemType mt1(LLMemType::MTYPE_APPFMTIMAGE);
 
 // first look for this image in the static VFS
 LLAssetType::EType asset_type = LLAssetType::AT_NONE;
 // Try TGA first
 if (gStaticVFS->getExists(image_id, LLAssetType::AT_TEXTURE_TGA))
 {
  asset_type = LLAssetType::AT_TEXTURE_TGA;
  //RN: force disable discards for TGA files because they can't decode at different quality levels
  dontDiscard();
  mDataCodec = IMG_CODEC_TGA;
 }
 else if (gStaticVFS->getExists(image_id, LLAssetType::AT_TEXTURE))
 {
  // then try for a J2C version
  asset_type = LLAssetType::AT_TEXTURE;
  mDataCodec = IMG_CODEC_J2C;
  LLImageJ2C* imagej2c = new LLImageJ2C();
  setFormattedImage(imagej2c);
 }

 if (asset_type != LLAssetType::AT_NONE)
 {
  S32 size = gStaticVFS->getSize(image_id, asset_type);
  U8* buffer = new U8[size];
  BOOL success = LLVFSThread::sLocal->readImmediate(gStaticVFS, image_id, asset_type, buffer, 0, size);

  if (!success)
  {
   llwarns << "loadLocalImage() - vfs read failed" << llendl;
   return FALSE;
  }

  mInStaticVFS = TRUE;
  mFullyLoaded = TRUE;
  setNeedsDecode(TRUE); // Loading a local image
  mID = image_id;
  setDecodeData(buffer, size);
  mTotalBytes = size;
  mLastBytesProcessed = size;
  return TRUE;
 }

 return FALSE;
}