//non-POSIX version //Nastavuje, se kterym odkladacim buferem se bude pracovat... //----------------------------------------------------------- int ie_swap(int newswap) //nastavi ten spravny bufer do pameti... { int rc; unsigned i; if(swapnum==newswap) return 1; if(swap2 && newswap>=0) //we are trying to optimize access to virtual memory now: { if(newswap==which1 && swapstr==swap2) // go from 2 to 1 { mod2=swapmod; swapstr=swap1; swapidx=(unsigned *)swap1; swapnum=which1; swapmod=mod1; return 1; } if(newswap==which2 && swapstr==swap1) // go from 1 to 2 { mod1=swapmod; swapstr=swap2; swapidx=(unsigned *)swap2; swapnum=which2; swapmod=mod2; return 1; } //!!JdS: 2004/1/5 {Revised the conditional expression for optimization ...} if(swapstr==swap2 && (swapoptimize || swapcontext[newswap]>=swapcontext[which2] && swapcontext[which1]>=swapcontext[which2]) ) //2 to 1 //if(swapstr==swap2 && (swapoptimize || swapcontext[newswap]<=swapcontext[which1] && // swapcontext[newswap]<=swapcontext[which1]) ) //2 to 1 { mod2=swapmod; swapstr=swap1; swapidx=(unsigned *)swap1; swapnum=which1; swapmod=mod1; } else //!!JdS: 2004/1/5 {Revised the conditional expression for optimization ...} if(swapstr==swap1 && (swapoptimize || swapcontext[newswap]>=swapcontext[which1] && swapcontext[which2]>=swapcontext[which1] || which2==-1)) //1 to 2 //if(swapstr==swap1 && (swapoptimize ||swapcontext[newswap]<=swapcontext[which2] && // swapcontext[newswap]<=swapcontext[which2] || which2==-1)) //1 to 2 { mod1=swapmod; swapstr=swap2; swapidx=(unsigned *)swap2; swapnum=which2; swapmod=mod2; } } //---------------------------------------------------------------------- if(swapmod && swapnum>=0) // byl akt.buffer modifikovan? { //vymazat pripadne stary swap: if(swapbufflag[swapnum]) { delBuf(&swapbuf[swapnum]); swapbufflag[swapnum]=0; } //do prvnich 2048 bytu ulozim pole swapidx //!memcpy(swapstr,swapidx,2048); //do handleru swapf[swapnym] ulozit bufer swapstr rc=saveBuf(swapstr,(unsigned)((IE_SWAPSTART+swapsize[swapnum])),&swapbuf[swapnum]); // printf("swapnum=%d, ulozeno %u bajtu, rc=%d",newswap,(unsigned)(IE_SWAPSTART+swapsize[swapnum]),rc); if(rc!=1) return 2; swapbufflag[swapnum]=1; swapmod=0; swapsavecount++; }//endif if(newswap==-1) return 1; //nacteni noveho akt.bufferu: i=IE_MAXSWAPLEN+IE_SWAPSTART; //!!! tady byla tezka chyba if(swapbufflag[newswap]) { rc=fromBuf(swapstr,0,&i,&swapbuf[newswap]); if(rc!=1) return 2; } else { while(i>0) { i--; swapstr[i]='\0'; }//loop }//endif swapnum=newswap; if(swap2==swapstr) { which2=swapnum; mod2=0; } else { which1=swapnum; mod1=0; } swaploadcount++; return 1; }
void CHLTVClientState::CopyNewEntity( CEntityReadInfo &u, int iClass, int iSerialNum ) { ServerClass *pServerClass = SV_FindServerClass( iClass ); Assert( pServerClass ); ClientClass *pClientClass = GetClientClass( iClass ); Assert( pClientClass ); const int ent = u.m_nNewEntity; // copy class & serial CFrameSnapshot *pSnapshot = u.m_pTo->GetSnapshot(); pSnapshot->m_pEntities[ent].m_nSerialNumber = iSerialNum; pSnapshot->m_pEntities[ent].m_pClass = pServerClass; // Get either the static or instance baseline. const void *pFromData = NULL; int nFromBits = 0; int nFromTick = 0; // MOTODO get tick when baseline last changed PackedEntity *baseline = u.m_bAsDelta ? GetEntityBaseline( u.m_nBaseline, ent ) : NULL; if ( baseline && baseline->m_pClientClass == pClientClass ) { Assert( !baseline->IsCompressed() ); pFromData = baseline->GetData(); nFromBits = baseline->GetNumBits(); } else { // Every entity must have a static or an instance baseline when we get here. ErrorIfNot( GetClassBaseline( iClass, &pFromData, &nFromBits ), ("HLTV_CopyNewEntity: GetDynamicBaseline(%d) failed.", iClass) ); nFromBits *= 8; // convert to bits } // create new ChangeFrameList containing all properties set as changed int nFlatProps = SendTable_GetNumFlatProps( pServerClass->m_pTable ); IChangeFrameList *pChangeFrame = NULL; if ( !m_bSaveMemory ) { pChangeFrame = AllocChangeFrameList( nFlatProps, nFromTick ); } // Now make a PackedEntity and store the new packed data in there. PackedEntity *pPackedEntity = framesnapshotmanager->CreatePackedEntity( pSnapshot, ent ); pPackedEntity->SetChangeFrameList( pChangeFrame ); pPackedEntity->SetServerAndClientClass( pServerClass, pClientClass ); // Make space for the baseline data. char packedData[MAX_PACKEDENTITY_DATA]; bf_read fromBuf( "HLTV_ReadEnterPVS1", pFromData, Bits2Bytes( nFromBits ), nFromBits ); bf_write writeBuf( "HLTV_ReadEnterPVS2", packedData, sizeof( packedData ) ); int changedProps[MAX_DATATABLE_PROPS]; // decode basline, is compressed against zero values int nChangedProps = RecvTable_MergeDeltas( pClientClass->m_pRecvTable, &fromBuf, u.m_pBuf, &writeBuf, -1, false, changedProps ); // update change tick in ChangeFrameList if ( pChangeFrame ) { pChangeFrame->SetChangeTick( changedProps, nChangedProps, pSnapshot->m_nTickCount ); } if ( u.m_bUpdateBaselines ) { SetEntityBaseline( (u.m_nBaseline==0)?1:0, pClientClass, u.m_nNewEntity, packedData, writeBuf.GetNumBytesWritten() ); } pPackedEntity->AllocAndCopyPadded( packedData, writeBuf.GetNumBytesWritten() ); // If ent doesn't think it's in PVS, signal that it is Assert( u.m_pTo->last_entity <= ent ); u.m_pTo->last_entity = ent; u.m_pTo->transmit_entity.Set( ent ); }
bool DropCopyAddCommand::Execute() { bool bRet = false; CString droppath = parser.GetVal(_T("droptarget")); if (CTGitPath(droppath).IsAdminDir()) return FALSE; if(!CTGitPath(droppath).HasAdminDir(&g_Git.m_CurrentDir)) return FALSE; int worktreePathLen = g_Git.m_CurrentDir.GetLength(); orgPathList.RemoveAdminPaths(); CTGitPathList copiedFiles; for(int nPath = 0; nPath < orgPathList.GetCount(); ++nPath) { if (orgPathList[nPath].IsEquivalentTo(CTGitPath(droppath))) continue; //copy the file to the new location CString name = orgPathList[nPath].GetFileOrDirectoryName(); if (::PathFileExists(droppath + _T("\\") + name)) { if (::PathIsDirectory(droppath + _T("\\") + name)) { if (orgPathList[nPath].IsDirectory()) continue; } CString strMessage; strMessage.Format(IDS_PROC_OVERWRITE_CONFIRM, (LPCTSTR)(droppath + _T("\\") + name)); CString sBtn1(MAKEINTRESOURCE(IDS_PROC_OVERWRITEEXPORT_OVERWRITE)); CString sBtn2(MAKEINTRESOURCE(IDS_PROC_OVERWRITEEXPORT_KEEP)); CString sBtn3(MAKEINTRESOURCE(IDS_PROC_OVERWRITEEXPORT_CANCEL)); UINT ret = CMessageBox::Show(hwndExplorer, strMessage, _T("TortoiseGit"), 2, IDI_QUESTION, sBtn1, sBtn2, sBtn3); if (ret == 3) return FALSE; //cancel the whole operation if (ret == 1) { if (!::CopyFile(orgPathList[nPath].GetWinPath(), droppath + _T("\\") + name, FALSE)) { //the copy operation failed! Get out of here! ShowErrorMessage(); return FALSE; } } } else { if (orgPathList[nPath].IsDirectory()) { CString fromPath = orgPathList[nPath].GetWinPathString() + L"||"; CString toPath = droppath + L"\\" + name + L"||"; std::unique_ptr<TCHAR[]> fromBuf(new TCHAR[fromPath.GetLength() + 2]); std::unique_ptr<TCHAR[]> toBuf(new TCHAR[toPath.GetLength() + 2]); wcscpy_s(fromBuf.get(), fromPath.GetLength() + 2, fromPath); wcscpy_s(toBuf.get(), toPath.GetLength() + 2, toPath); CStringUtils::PipesToNulls(fromBuf.get(), fromPath.GetLength() + 2); CStringUtils::PipesToNulls(toBuf.get(), toPath.GetLength() + 2); SHFILEOPSTRUCT fileop = {0}; fileop.wFunc = FO_COPY; fileop.pFrom = fromBuf.get(); fileop.pTo = toBuf.get(); fileop.fFlags = FOF_NO_CONNECTED_ELEMENTS | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NOCONFIRMMKDIR | FOF_NOCOPYSECURITYATTRIBS | FOF_SILENT; if (!SHFileOperation(&fileop)) { // add all copied files WITH special handling for repos/submodules (folders which include a .git entry) CDirFileEnum finder(droppath + L"\\" + name); bool isDir = true; CString filepath; CString lastRepo; bool isRepo = false; while (finder.NextFile(filepath, &isDir, !isRepo)) // don't recurse into .git directories { if (!lastRepo.IsEmpty()) { if (filepath.Find(lastRepo) == 0) continue; else lastRepo.Empty(); } int pos = -1; if ((pos = filepath.Find(L"\\" + g_GitAdminDir.GetAdminDirName())) >= 0) isRepo = (pos == filepath.GetLength() - g_GitAdminDir.GetAdminDirName().GetLength() - 1); else isRepo = false; if (isRepo) { lastRepo = filepath.Mid(0, filepath.GetLength() - g_GitAdminDir.GetAdminDirName().GetLength()); CString msg; if (!isDir) msg.Format(IDS_PROC_COPY_SUBMODULE, lastRepo); else msg.Format(IDS_PROC_COPY_REPOSITORY, lastRepo); int ret = CMessageBox::Show(hwndExplorer, msg, _T("TortoiseGit"), 1, IDI_QUESTION, CString(MAKEINTRESOURCE(IDS_DELETEBUTTON)), CString(MAKEINTRESOURCE(IDS_IGNOREBUTTON)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON))); if (ret == 3) return FALSE; if (ret == 1) { CTGitPath(filepath).Delete(false); lastRepo.Empty(); } continue; } if (!isDir) copiedFiles.AddPath(CTGitPath(filepath.Mid(worktreePathLen + 1))); //add the new filepath } } continue; // do not add a directory to copiedFiles } else if (!CopyFile(orgPathList[nPath].GetWinPath(), droppath+_T("\\")+name, FALSE)) { //the copy operation failed! Get out of here! ShowErrorMessage(); return FALSE; } } CString destPath(droppath + _T("\\") + name); copiedFiles.AddPath(CTGitPath(destPath.Mid(worktreePathLen + 1))); //add the new filepath } //now add all the newly copied files to the working copy CGitProgressDlg progDlg; theApp.m_pMainWnd = &progDlg; AddProgressCommand addCommand; progDlg.SetCommand(&addCommand); addCommand.SetPathList(copiedFiles); progDlg.DoModal(); bRet = !progDlg.DidErrorsOccur(); return bRet; }
void CHLTVClientState::ReadDeltaEnt( CEntityReadInfo &u ) { const int i = u.m_nNewEntity; CFrameSnapshot *pFromSnapshot = u.m_pFrom->GetSnapshot(); CFrameSnapshot *pSnapshot = u.m_pTo->GetSnapshot(); Assert( i < pFromSnapshot->m_nNumEntities ); pSnapshot->m_pEntities[i] = pFromSnapshot->m_pEntities[i]; PackedEntity *pToPackedEntity = framesnapshotmanager->CreatePackedEntity( pSnapshot, i ); // WARNING! get pFromPackedEntity after new pPackedEntity has been created, otherwise pointer may be wrong PackedEntity *pFromPackedEntity = framesnapshotmanager->GetPackedEntity( pFromSnapshot, i ); pToPackedEntity->SetServerAndClientClass( pFromPackedEntity->m_pServerClass, pFromPackedEntity->m_pClientClass ); // create a copy of the pFromSnapshot ChangeFrameList IChangeFrameList* pChangeFrame = NULL; if ( !m_bSaveMemory ) { pChangeFrame = pFromPackedEntity->GetChangeFrameList()->Copy(); pToPackedEntity->SetChangeFrameList( pChangeFrame ); } // Make space for the baseline data. char packedData[MAX_PACKEDENTITY_DATA]; const void *pFromData; int nFromBits; if ( pFromPackedEntity->IsCompressed() ) { pFromData = m_pHLTV->UncompressPackedEntity( pFromPackedEntity, nFromBits ); } else { pFromData = pFromPackedEntity->GetData(); nFromBits = pFromPackedEntity->GetNumBits(); } bf_read fromBuf( "HLTV_ReadEnterPVS1", pFromData, Bits2Bytes( nFromBits ), nFromBits ); bf_write writeBuf( "HLTV_ReadEnterPVS2", packedData, sizeof( packedData ) ); int changedProps[MAX_DATATABLE_PROPS]; // decode baseline, is compressed against zero values int nChangedProps = RecvTable_MergeDeltas( pToPackedEntity->m_pClientClass->m_pRecvTable, &fromBuf, u.m_pBuf, &writeBuf, -1, false, changedProps ); // update change tick in ChangeFrameList if ( pChangeFrame ) { pChangeFrame->SetChangeTick( changedProps, nChangedProps, pSnapshot->m_nTickCount ); } if ( m_bSaveMemory ) { int bits = writeBuf.GetNumBitsWritten(); const char *compressedData = m_pHLTV->CompressPackedEntity( pToPackedEntity->m_pServerClass, (char*)writeBuf.GetData(), bits ); // store as compressed data and don't use mem pools pToPackedEntity->AllocAndCopyPadded( compressedData, Bits2Bytes(bits) ); pToPackedEntity->SetCompressed(); } else { // store as normal pToPackedEntity->AllocAndCopyPadded( packedData, writeBuf.GetNumBytesWritten() ); } u.m_pTo->last_entity = u.m_nNewEntity; u.m_pTo->transmit_entity.Set( u.m_nNewEntity ); u.NextOldEntity(); }
bool CClientState::ProcessTempEntities( SVC_TempEntities *msg ) { bool bReliable = false; float fire_time = cl.GetTime(); #ifndef _XBOX // delay firing temp ents by cl_interp in multiplayer or demoplayback if ( cl.m_nMaxClients > 1 || demoplayer->IsPlayingBack() ) { float flInterpAmount = GetClientInterpAmount(); fire_time += flInterpAmount; } #endif if ( msg->m_nNumEntries == 0 ) { bReliable = true; msg->m_nNumEntries = 1; } int flags = bReliable ? FEV_RELIABLE : 0; // Don't actually queue unreliable events if playing a demo and skipping ahead #ifndef _XBOX if ( !bReliable && demoplayer->IsSkipping() ) { return true; } #endif bf_read &buffer = msg->m_DataIn; // shortcut int classID = -1; void *from = NULL; C_ServerClassInfo *pServerClass = NULL; ClientClass *pClientClass = NULL; unsigned char data[CEventInfo::MAX_EVENT_DATA]; bf_write toBuf( data, sizeof(data) ); CEventInfo *ei = NULL; for (int i = 0; i < msg->m_nNumEntries; i++ ) { float delay = 0.0f; if ( buffer.ReadOneBit() ) { delay = (float)buffer.ReadSBitLong( 8 ) / 100.0f; } toBuf.Reset(); if ( buffer.ReadOneBit() ) { from = NULL; // full update classID = buffer.ReadUBitLong( m_nServerClassBits ); // classID // Look up the client class, etc. // Match the server classes to the client classes. pServerClass = m_pServerClasses ? &m_pServerClasses[ classID - 1 ] : NULL; if ( !pServerClass ) { DevMsg("CL_QueueEvent: missing server class info for %i.\n", classID - 1 ); return false; } // See if the client .dll has a handler for this class pClientClass = FindClientClass( pServerClass->m_ClassName ); if ( !pClientClass || !pClientClass->m_pRecvTable ) { DevMsg("CL_QueueEvent: missing client receive table for %s.\n", pServerClass->m_ClassName ); return false; } RecvTable_MergeDeltas( pClientClass->m_pRecvTable, NULL, &buffer, &toBuf ); } else { Assert( ei ); bf_read fromBuf( ei->pData, Bits2Bytes(ei->bits) ); RecvTable_MergeDeltas( pClientClass->m_pRecvTable, &fromBuf, &buffer, &toBuf ); } // Add a slot ei = &cl.events[ cl.events.AddToTail() ]; Assert( ei ); int size = Bits2Bytes(toBuf.GetNumBitsWritten() ); ei->classID = classID; ei->fire_delay = fire_time + delay; ei->flags = flags; ei->pClientClass = pClientClass; ei->bits = toBuf.GetNumBitsWritten(); ei->pData = new byte[size]; // copy raw data Q_memcpy( ei->pData, data, size ); } return true; }