int applypatch(int argc, char * argv[]){
    if (argc!=4) {
        std::cout<<"patch command parameter:\n oldFileName diffFileName outNewFileName\n";
        return 0;
    }
    const char* oldFileName=argv[1];
    const char* diffFileName=argv[2];
    const char* outNewFileName=argv[3];
    std::cout<<"old :\"" <<oldFileName<< "\"\ndiff:\""<<diffFileName<<"\"\nout :\""<<outNewFileName<<"\"\n";
    clock_t time0=clock();
    {
        TFileStreamInput oldData(oldFileName);
        TFileStreamInput diffData(diffFileName);
        const hpatch_StreamPos_t newDataSize=readNewDataSize(diffData);
        TFileStreamOutput newData(outNewFileName,newDataSize);

        clock_t time1=clock();
        if (!patch_stream(&newData, &oldData, &diffData)){
            std::cout<<"  patch_stream run error!!!\n";
            exit(3);
        }
        clock_t time2=clock();
        std::cout<<"  patch_stream ok!\n";
        std::cout<<"oldDataSize : "<<oldData.streamSize<<"\ndiffDataSize: "<<diffData.streamSize<<"\nnewDataSize : "<<newDataSize<<"\n";
        std::cout<<"\npatch   time:"<<(time2-time1)*(1000.0/CLOCKS_PER_SEC)<<" ms\n";
    }
    clock_t time3=clock();
    std::cout<<"all run time:"<<(time3-time0)*(1000.0/CLOCKS_PER_SEC)<<" ms\n";
    return 0;
}
bool ParticleChannelInt::Spawn(Tab<int>& spawnTable)
{
	SysUtil::NeedToImplementLater(); // optimize the implementation

	int i, checkCount = min(spawnTable.Count(), Count());

	if (isGlobal())
	{
		int newCount = 0;
		for(i=0; i<checkCount; i++)
			if (spawnTable[i] > 0) newCount += spawnTable[i];
		_globalCount() = newCount;
	}
	else
	{
		Tab<int> oldData(data());
		int j, k, newCount = 0;
		for(i=0; i<checkCount; i++)
			if (spawnTable[i] > 0) newCount += spawnTable[i];
		_data().SetCount(newCount);
		for(i=0, j=0; i<checkCount; i++)
			for(k=0; k<spawnTable[i]; k++)
				_data(j++) = oldData[i];
	}
	return true;
}
void
DisturbanceStorage::
addConnectionChange(RoutingNode* fromNode,
                    RoutingNode* toNode,                    
                    const RoutingConnectionData& newData,
                    bool forward)
{
   mc2dbg8 << "[DS]: addConnectionChange" << endl;
   rollBackOne(fromNode->getItemID(), toNode->getItemID());
   RoutingConnection* conn = fromNode->getConnection(toNode, forward);
   // Copy connection data.
   RoutingConnectionData oldData(*conn->getData());

   // Create a diff
   RoutingMapConnChanges diff(fromNode, toNode, oldData, newData, forward);
   // Apply the diff on the node.
   conn->setData(newData);
   
   // Mmmm. STL at its best.
   m_changedNodes.insert(
      make_pair(
         fromToNode_t(fromNode->getItemID(),
                      toNode->getItemID()),
         diff
         ));
   
   // Then update the multinodes
   updateMulti(&diff, false);
}
Exemple #4
0
void csImageMemory::SetFormat (int iFormat)
{
  int pixels = Width * Height * Depth;
  int oldformat = Format;
  Format = iFormat;

  uint8* oldalpha = Alpha;
  Alpha = 0;
  csRef<iDataBuffer> oldData (databuf);
  databuf = 0;

  if ((oldformat & CS_IMGFMT_MASK) == CS_IMGFMT_TRUECOLOR)
    InternalConvertFromRGBA (oldData);
  else if ((oldformat & CS_IMGFMT_MASK) == CS_IMGFMT_PALETTED8)
  {
    uint8* Alpha = 0;
    if (iFormat & CS_IMGFMT_ALPHA)
    {
      if (oldalpha)
	Alpha = oldalpha; 
      else
      {
	Alpha = new uint8[pixels];
	memset (Alpha, 0xff, pixels);
      }
    }
    else
    {
      delete[] oldalpha;
    }
    csRGBpixel* oldPalette = Palette;
    Palette = 0;
    InternalConvertFromPal8 (oldData, Alpha, oldPalette);
  }
}
// WM_NCLBUTTONUP handler 
BOOL cef_dark_window::HandleNcLeftButtonUp(UINT uHitTest, LPPOINT point)
{
    NonClientButtonStateData oldData(mNonClientData);

    mNonClientData.Reset();

    UpdateNonClientButtons();

    switch (oldData.mActiveButton) 
    {
    case HTCLOSE:
        if (oldData.mButtonOver) {
            SendMessage (WM_SYSCOMMAND, SC_CLOSE, (LPARAM)POINTTOPOINTS(*point));
            TrackNonClientMouseEvents(false);
        }
        return TRUE;
    case HTMAXBUTTON:
        if (oldData.mButtonOver) {
            if (IsZoomed()) 
                SendMessage (WM_SYSCOMMAND, SC_RESTORE, (LPARAM)POINTTOPOINTS(*point));
            else 
                SendMessage (WM_SYSCOMMAND, SC_MAXIMIZE, (LPARAM)POINTTOPOINTS(*point));
            TrackNonClientMouseEvents(false);
        }
        return TRUE;
    case HTMINBUTTON:
        if (oldData.mButtonOver) {
            SendMessage (WM_SYSCOMMAND, SC_MINIMIZE, (LPARAM)POINTTOPOINTS(*point));
            TrackNonClientMouseEvents(false);
        }
        return TRUE;
    }
    
    return FALSE;
}
void ActivityTsModel::getActivities()
{   
    QList<ActivityTsEntry*> oldData(mData);
    mData.clear();
    
    QList<QVariantHash> activities;
    QMetaObject::invokeMethod(mAfManager,
                              "activitiesList",
                              Q_RETURN_ARG(QList<QVariantHash>, activities),
                              Q_ARG(int, mMaxItems));

    foreach (const QVariantHash &activityEntry, activities) {
        ActivityTsEntry *reusableEntry = findEntryWithScreenshot(oldData, activityEntry);
        if (reusableEntry) {
            mData.append(reusableEntry);
            oldData.removeAll(reusableEntry);
        } else {
            mData.append(new ActivityTsEntry(activityEntry));
        
            QMetaObject::invokeMethod(
                mAfManager,
                "getThumbnail",
                Q_ARG(QString, activityEntry.value(ActivityScreenshotKeyword).toString()),
                Q_ARG(void *, mData.last()));
        }
    }
int
DisturbanceStorage::
applyAllConnectionChangesToMultiConnection(const fromToNode_t& multi)
{
   int nbrChanges = 0;
   
   pair<nodesInMultiMap_t::iterator, nodesInMultiMap_t::iterator>
      range = m_nodesInMulti.equal_range(multi);

   // Copy the old connectiondata.
   RoutingNode* fromNode   = m_map->getNodeFromTrueNodeNumber(multi.first);
   RoutingNode* toNode     = m_map->getNodeFromTrueNodeNumber(multi.second);
   RoutingConnection* conn = fromNode->getConnection(toNode, true);
   
   RoutingConnectionData oldData( *conn->getData() );
   
   for( nodesInMultiMap_t::iterator it = range.first;
        it != range.second;
        ++it ) {
      // Find change
      changedNodes_t::const_iterator change = m_changedNodes.find(it->second);
      
      // Apply change
      change->second.applyDiff(m_map, fromNode, conn, &(it->second));
      
      ++nbrChanges;
   }

   if ( nbrChanges != 0 ) {
      // Save the old connection data
      RoutingMapConnChanges diff(fromNode, toNode, oldData,
                                 *conn->getData(), true);
      m_changedNodes.insert(
         make_pair(
            fromToNode_t(fromNode->getItemID(),
                         toNode->getItemID()),
            diff
            ));
   }

   mc2dbg << "[DS]: " << nbrChanges << " applied" << endl;
   
   return nbrChanges;
}
Exemple #8
0
void ClipMap::recenter(Point2F center)
{
   bool wantCompleteRefill = false;
   if(mNeedRefill || mForceClipmapPurge || Con::getBoolVariable("$forceFullClipmapPurgeEveryFrame", false))
      wantCompleteRefill = true;

   PROFILE_START(ClipMap_recenter);

   // Reset our budget.
   mMaxTexelUploadPerRecenter = mClipMapSize * mClipMapSize * 2;

   AssertFatal(isPow2(mClipMapSize), 
      "ClipMap::recenter - require pow2 clipmap size!");

   // Clamp the center to the unit square.

   /*
   if(!mTile)
   {
      center.x = mClampF(center.x, 0.f, 1.f);
      center.y = mClampF(center.y, 0.f, 1.f);
   }
   */

   // Ok, we're going to do toroidal updates on each entry of the clipstack
   // (except for the cap, which covers the whole texture), based on this
   // new center point.
   if( !wantCompleteRefill )
   {
      // Calculate the new texel at most detailed level.
      Point2F texelCenterF = center * F32(mClipMapSize) * mLevels[0].mScale;
      Point2I texelCenter((S32)mFloor(texelCenterF.y), (S32)mFloor(texelCenterF.x));
      
      // Update interest region.
      mImageCache->setInterestCenter(texelCenter);
   }

   // Note how many we were at so we can cut off at the right time.
   S32 lastTexelsUpdated = mTexelsUpdated;

   // For each texture...
   for(S32 i=mClipStackDepth-2; i>=0; i--)
   {
      ClipStackEntry &cse = mLevels[i];

      // Calculate new center point for this texture.
      Point2F texelCenterF = center * F32(mClipMapSize) * cse.mScale;

      const S32 texelMin = mClipMapSize/2;
      //const S32 texelMax = S32(F32(mClipMapSize) * cse.mScale) - texelMin;

      Point2I texelTopLeft;

      //if(mTile)
      //{
         texelTopLeft.x = S32(mFloor(texelCenterF.y)) - texelMin;
         texelTopLeft.y = S32(mFloor(texelCenterF.x)) - texelMin;
      //}
      //else
      //{
      //   texelTopLeft.x = mClamp(S32(mFloor(texelCenterF.y)), texelMin, texelMax) - texelMin;
      //   texelTopLeft.y = mClamp(S32(mFloor(texelCenterF.x)), texelMin, texelMax) - texelMin;
      //}

      // Also, prevent very small updates - the RT changes are costly.
      Point2I d = cse.mToroidalOffset - texelTopLeft;
      if(mAbs(d.x) <= 2 && mAbs(d.y) <= 2)
      {
         // Update the center; otherwise we get some weird conditions around
         // edges of the clipmap space.
         cse.mClipCenter = center;
         continue;
      }

      // This + current toroid offset tells us what regions have to be blasted.
      RectI oldData(cse.mToroidalOffset,  Point2I(mClipMapSize, mClipMapSize));
      RectI newData(texelTopLeft,         Point2I(mClipMapSize, mClipMapSize));

      // Update clipstack level.
      cse.mClipCenter      = center;
      cse.mToroidalOffset  = texelTopLeft;

      // If we're refilling, that's all we want; continue with next level.
      if( wantCompleteRefill )
         continue;

      // Make sure we have available data...
      if(!mImageCache->isDataAvailable(getMipLevel(cse.mScale), newData))
		  continue;

      // Alright, determine the set of data we actually need to upload.
      S32   rectCount = 0;
      RectI buffer[8];

      calculateModuloDeltaBounds(oldData, newData, buffer, &rectCount);
      AssertFatal(rectCount < 8, "ClipMap::recenter - got too many rects back!");

      /*if(rectCount)
         Con::printf("    issuing %d updates to clipmap level %d (offset=%dx%d)", 
                        rectCount, i, texelTopLeft.x, texelTopLeft.y); */

      if(rectCount)
      {
         if (!mImageCache->beginRectUpdates(cse))
         {
            mForceClipmapPurge = true;
            return;
         }
         //Con::errorf("layer %x, %d updates", &cse,  rectCount);

         // And GO!
         for(S32 j=0; j<rectCount; j++)
         {
            PROFILE_START(ClipMap_recenter_upload);

            AssertFatal(buffer[j].isValidRect(),"ClipMap::recenter - got invalid rect!");

            // Note the rect, so we can then wrap and let the image cache do its thing.
            RectI srcRegion = buffer[j];
            buffer[j].point.x = srcRegion.point.x % mClipMapSize;
            buffer[j].point.y = srcRegion.point.y % mClipMapSize;

            AssertFatal(newData.contains(srcRegion), 
               "ClipMap::recenter - got update buffer outside of expected new data bounds.");

            mTotalUpdates++;
            mTexelsUpdated += srcRegion.extent.x  * srcRegion.extent.y;

            //Con::printf("updating (%d %d %d %d)",
            //   buffer[j].point.x, buffer[j].point.y, buffer[j].extent.x, buffer[j].extent.y);

            mImageCache->doRectUpdate(getMipLevel(cse.mScale), cse, srcRegion, buffer[j]);

            PROFILE_END();
         }

         mImageCache->finishRectUpdates(cse);
      }

      // Check if we've overrun our budget.
      if((mTexelsUpdated - lastTexelsUpdated) > mMaxTexelUploadPerRecenter)
      {
         //Con::warnf("ClipMap::recenter - exceeded budget for this frame, deferring till next frame.");
         break;
      }

   }

   if( wantCompleteRefill )
   {
      fillWithTextureData();
      mNeedRefill = false;
   }

   PROFILE_END();
}