Ejemplo n.º 1
0
void BuildCacheCRC()
{
#ifdef ENABLE_DATABLOCK_CACHE
    SimDataBlockGroup* pGroup = Sim::getDataBlockGroup();
    SimDataBlock* pDataBlock = 0;
    const U32 iCount = pGroup->size();
    BitStream* stream = new InfiniteBitStream;
    U32 crc=0;
    for (U32 i = 0; i < iCount; i++)
    {
        pDataBlock = (SimDataBlock*)(*pGroup)[i];
        pDataBlock->packData(stream);
    }
    //U32 crc = CRC::calculateCRCStream(stream); //Stream CRC doesn't seem reliable.

    FileStream* datablocksOut = FileStream::createAndOpen("ServerCRC.dmp", Torque::FS::File::Write );
    if (datablocksOut==NULL)
        Con::errorf("### Datablock Cache: Unable to Build Server Datablock CRC Key File.");
    else
    {
        datablocksOut->writeBitStream(stream);
        datablocksOut->close();
        crc=Con::getFileCRC("ServerCRC.dmp");
        Con::deleteFile("ServerCRC.dmp");
    }
    Con::setVariable("$ServerDatablockCacheCRC", Con::getuIntArg(crc));
    Con::warnf("### Datablock Cache: Server Datablock CRC is %u",crc);

    delete stream;
#endif
}
Ejemplo n.º 2
0
GuiControl* GuiInspectorDatablockField::constructEditControl()
{
   GuiControl* retCtrl = new GuiPopUpMenuCtrl();

   // If we couldn't construct the control, bail!
   if( retCtrl == NULL )
      return retCtrl;

   GuiPopUpMenuCtrl *menu = dynamic_cast<GuiPopUpMenuCtrl*>(retCtrl);

   // Let's make it look pretty.
   retCtrl->setDataField( StringTable->insert("profile"), NULL, "InspectorTypeEnumProfile" );

   menu->setField("text", getData());

   _registerEditControl( retCtrl );

   // Configure it to update our value when the popup is closed
   char szBuffer[512];
   dSprintf( szBuffer, 512, "%d.apply(%d.getText());%d.inspect(%d);",getId(), retCtrl->getId(),mParent->mParent->getId(), mTarget->getId() );
   //dSprintf( szBuffer, 512, "%d.%s = %d.getText();%d.inspect(%d);",mTarget->getId(), getFieldName(), menu->getId(), mParent->mParent->getId(), mTarget->getId() );
   menu->setField("Command", szBuffer );

   Vector<StringTableEntry> entries;

   SimDataBlockGroup * grp = Sim::getDataBlockGroup();
   for(SimDataBlockGroup::iterator i = grp->begin(); i != grp->end(); i++)
   {
      SimDataBlock * datablock = dynamic_cast<SimDataBlock*>(*i);

      // Skip non-datablocks if we somehow encounter them.
      if(!datablock)
         continue;

      // Ok, now we have to figure inheritance info.
      if( datablock && datablock->getClassRep()->isClass(mDesiredClass) )
         entries.push_back(datablock->getName());
   }

   // sort the entries
   dQsort(entries.address(), entries.size(), sizeof(StringTableEntry), stringCompare);

   // add them to our enum
   for(U32 j = 0; j < entries.size(); j++)
      menu->addEntry(entries[j], 0);

   return retCtrl;
}
void SimDataBlockEvent::pack(NetConnection *conn, BitStream *bstream)
{
#ifdef AFX_CAP_DATABLOCK_CACHE // AFX CODE BLOCK (db-cache) <<
	((GameConnection *)conn)->tempDisableStringBuffering(bstream);
#endif // AFX CODE BLOCK (db-cache) >>
   SimDataBlock* obj;
   Sim::findObject(id,obj);
   GameConnection *gc = (GameConnection *) conn;
   if(bstream->writeFlag(gc->getDataBlockModifiedKey() < obj->getModifiedKey()))
   {
      if(obj->getModifiedKey() > gc->getMaxDataBlockModifiedKey())
         gc->setMaxDataBlockModifiedKey(obj->getModifiedKey());

      AssertFatal(obj,
                  "SimDataBlockEvent:: Data blocks cannot be deleted");
      bstream->writeInt(id - DataBlockObjectIdFirst,DataBlockObjectIdBitSize);

      S32 classId = obj->getClassId(conn->getNetClassGroup());
      bstream->writeClassId(classId, NetClassTypeDataBlock, conn->getNetClassGroup());
      bstream->writeInt(mIndex, DataBlockObjectIdBitSize);
      bstream->writeInt(mTotal, DataBlockObjectIdBitSize + 1);
      obj->packData(bstream);
#ifdef TORQUE_DEBUG_NET
      bstream->writeInt(classId ^ DebugChecksum, 32);
#endif
   }
#ifdef AFX_CAP_DATABLOCK_CACHE // AFX CODE BLOCK (db-cache) <<
   ((GameConnection *)conn)->restoreStringBuffering(bstream);
#endif // AFX CODE BLOCK (db-cache) >>
}
void SimDataBlockEvent::process(NetConnection *cptr)
{
   if(mProcess)
   {
      //call the console function to set the number of blocks to be sent
      Con::executef("onDataBlockObjectReceived", Con::getIntArg(mIndex), Con::getIntArg(mTotal));

      SimDataBlock* obj = NULL;
      String &errorBuffer = NetConnection::getErrorBuffer();

      if( Sim::findObject( id,obj ) && dStrcmp( obj->getClassName(),mObj->getClassName() ) == 0 )
      {
         U8 buf[1500];
         BitStream stream(buf, 1500);
         mObj->packData(&stream);
         stream.setPosition(0);
         obj->unpackData(&stream);
         obj->preload(false, errorBuffer);
      }
      else
      {
         if( obj != NULL )
         {
            Con::warnf( "A '%s' datablock with id: %d already existed. "
                        "Clobbering it with new '%s' datablock from server.",
                        obj->getClassName(), id, mObj->getClassName() );
            obj->deleteObject();
         }

         bool ret = mObj->registerObject(id);

         if(ret)
         {
            cptr->addObject(mObj);

            GameConnection *conn = dynamic_cast<GameConnection *>(cptr);
            if(conn)
            {
               conn->preloadDataBlock(mObj);
               mObj = NULL;
            }
         }
      }
   }
}
Ejemplo n.º 5
0
void SimDataBlockEvent::pack(NetConnection *conn, BitStream *bstream)
{
   SimDataBlock* obj;
   Sim::findObject(id,obj);
   GameConnection *gc = (GameConnection *) conn;
   if(bstream->writeFlag(gc->getDataBlockModifiedKey() < obj->getModifiedKey()))
   {
      if(obj->getModifiedKey() > gc->getMaxDataBlockModifiedKey())
         gc->setMaxDataBlockModifiedKey(obj->getModifiedKey());

      AssertFatal(obj,
                  "SimDataBlockEvent:: Data blocks cannot be deleted");
      bstream->writeInt(id - DataBlockObjectIdFirst,DataBlockObjectIdBitSize);

      S32 classId = obj->getClassId(conn->getNetClassGroup());
      bstream->writeClassId(classId, NetClassTypeDataBlock, conn->getNetClassGroup());
      bstream->writeInt(mIndex, DataBlockObjectIdBitSize);
      bstream->writeInt(mTotal, DataBlockObjectIdBitSize + 1);
      obj->packData(bstream);
#ifdef TORQUE_DEBUG_NET
      bstream->writeInt(classId ^ DebugChecksum, 32);
#endif
   }
}