InsertPosition BufferManager::GetInsertPosition(Table& table){ InsertPosition ip; if(!table.blockNum){ ip.bufferID=AddBlock(table); ip.position=0; return ip; } string filename=table.name+".table"; int length=table.totalLength+1; int recordamount=BLOCKSIZE/length; int blockoffset=table.blockNum-1; int bufferID=IfinBuffer(filename,blockoffset); if(bufferID==-1){ bufferID=GetEmptyBlock(); LoadBlock(filename,blockoffset,bufferID); } for(int i=0;i<recordamount;i++){ int pos=i*length; char ifempty=bufferblocks[bufferID].getcontent(pos); if(ifempty==EMPTY){ ip.bufferID=bufferID; ip.position=pos; return ip; } } ip.bufferID=AddBlock(table); ip.position=0; return ip; }
Sidebar::Sidebar(wxWindow *parent, wxMenu *suggestionsMenu) : wxPanel(parent, wxID_ANY), m_selectedItem(nullptr) { SetBackgroundColour(SIDEBAR_BACKGROUND); Bind(wxEVT_PAINT, &Sidebar::OnPaint, this); #ifdef __WXOSX__ SetWindowVariant(wxWINDOW_VARIANT_SMALL); #endif auto *topSizer = new wxBoxSizer(wxVERTICAL); topSizer->SetMinSize(wxSize(300, -1)); m_blocksSizer = new wxBoxSizer(wxVERTICAL); topSizer->Add(m_blocksSizer, wxSizerFlags(1).Expand().DoubleBorder(wxTOP|wxBOTTOM)); m_topBlocksSizer = new wxBoxSizer(wxVERTICAL); m_bottomBlocksSizer = new wxBoxSizer(wxVERTICAL); m_blocksSizer->Add(m_topBlocksSizer, wxSizerFlags(1).Expand().ReserveSpaceEvenIfHidden()); m_blocksSizer->Add(m_bottomBlocksSizer, wxSizerFlags().Expand()); AddBlock(new SuggestionsSidebarBlock(this, suggestionsMenu), Top); AddBlock(new OldMsgidSidebarBlock(this), Bottom); AddBlock(new AutoCommentSidebarBlock(this), Bottom); AddBlock(new CommentSidebarBlock(this), Bottom); AddBlock(new AddCommentSidebarBlock(this), Bottom); SetSizerAndFit(topSizer); SetSelectedItem(nullptr, nullptr); }
void OpenALThread::AddData(const void* src, ALsizei size) { const char* bsrc = (const char*)src; ALuint buffer; ALint buffers_count; alGetSourcei(m_source, AL_BUFFERS_PROCESSED, &buffers_count); checkForAlError("alGetSourcei"); while(size) { if(buffers_count-- <= 0) { Play(); alGetSourcei(m_source, AL_BUFFERS_PROCESSED, &buffers_count); checkForAlError("alGetSourcei"); continue; } alSourceUnqueueBuffers(m_source, 1, &buffer); checkForAlError("alSourceUnqueueBuffers"); int bsize = size < m_buffer_size ? size : m_buffer_size; AddBlock(buffer, bsize, bsrc); alSourceQueueBuffers(m_source, 1, &buffer); checkForAlError("alSourceQueueBuffers"); size -= bsize; bsrc += bsize; } Play(); }
void Field::addJunk(int nr) { for (auto& block : blocks_) { block.setY(block.getY() + nr); block.setAnimationY(block.getAnimationY() - nr); } if (tetromino_) { tetromino_->moveUp(nr); } std::uniform_int_distribution<int> dist(0, width_ - 1); std::mt19937 colorRandom; std::uniform_int_distribution<int> colorDist(0, 255); for (int i = 0; i < nr; ++i) { int leaveOut = dist(random); for (int x = 0; x < width_; ++x) { if (x != leaveOut) { jngl::Color color(colorDist(colorRandom), colorDist(colorRandom), colorDist(colorRandom)); Block block(x, i, color); block.setAnimationY(-nr); AddBlock(block); } } } }
void DBufferLFRU::Strategy(int fileId,int segId,int &ofileId,int &osegId){ double Fk; double Rk; double tt,tr; double weight; list<Block>::iterator it, maxIt; double maxWeight =0.0; recallTime = getRelativeTime(); maxIt = buf.begin(); tt = recallTime - t0; if( tt < 0 ) tt= 0; if( tt > (double) _period) tt = _period; for(it = buf.begin();it !=buf.end();it++){ tr = recallTime - it->hitTime; if( tr < 0 ) tr = 0; Fk = tt/it->counts; Rk = tr; weight =(double )_period- tt; weight = weight * Rk /(double)_period ; weight += tt*Fk/ _period ; // cout << fileId << "," << it->segId << "Fk:" << Fk << ",Rk:" << Rk << ",period:" << _period << ",recallTime:" << recallTime << ",weight:" << it->weight << ",t0:" << t0 << ",counts:" << it->counts << ",accessTime:" << it->hitTime << endl; if(weight > maxWeight){ maxWeight = weight; maxIt=it; } } ofileId = maxIt->fileId; osegId = maxIt->segId; buf.erase(maxIt); //cout<<"eliminate "<<ofileId<<","<<osegId<<endl; AddBlock(fileId,segId); }
void CW::CeilingTerrain::Init(void) { PhysicsBody* b = new PhysicsBody(); VerletPoint* V1 = new VerletPoint(0, 0); VerletPoint* V2 = new VerletPoint(60, 0); VerletPoint* V3 = new VerletPoint(60, 100); VerletPoint* V4 = new VerletPoint(0, 100); b->AddVertex(V1); b->AddVertex(V2); b->AddVertex(V3); b->AddVertex(V4); for (VerletPoint* p : b->Vertices) { p->IsStatic = true; } blocks.push_back(b); for (int i=0;i<20;++i) { AddBlock(); } }
void DBufferLFRU::Strategy(int fileId,int segId,int &ofileId,int &osegId){ double Fk; unsigned long Rk; list<LFRUBlockInfoo>::iterator it, maxIt; double maxWeight =0.0; gettimeofday(&recallTime,NULL); // recallTime = tv.tv_sec * 1000000 + tv.tv_usec; for(it = buf.begin();it !=buf.end();it++){ if(it->segId == segId && it->fileId == fileId ){ it->weight = 0.0; it->periodCounter = 1; gettimeofday(&(it->lastAccessTime),NULL); return; } if(it->periodCounter ==0){ cout<<"counter error"<<endl; exit(1); } Fk = getTimeIntervallfru(&recallTime,&t0)/(double)(it->periodCounter * 1000000.0); Rk = getTimeIntervallfru(&recallTime ,&(it->lastAccessTime))/1000000.0; it->weight =((long long)_period- getTimeIntervallfru(&recallTime,&t0)/ 1000000.0) ; it->weight = it->weight * Rk /(double)_period ; it->weight += (getTimeIntervallfru(&recallTime ,&t0)*Fk/ (1000000.0 * (double)_period )); //cout << fileId << "," << segId << "Fk:" << Fk << ",Rk:" << Rk << ",period:" << _period << ",recallTime:" << recallTime.tv_sec<<":"<<recallTime.tv_usec << ",weight:" << it->weight << ",t0:" << t0.tv_sec<<":"<<t0.tv_usec << ",periodCounter:" << it->periodCounter << ",accessTime:" << it->lastAccessTime.tv_sec<<":"<<it->lastAccessTime.tv_usec << endl; if(it->weight > maxWeight){ maxWeight = it->weight; maxIt=it; } } ofileId = maxIt->fileId; osegId = maxIt->segId; buf.erase(maxIt); AddBlock(fileId,segId); }
int FName::NameManager::AddName (const char *text, unsigned int hash, unsigned int bucket) { char *textstore; NameBlock *block = Blocks; size_t len = strlen (text) + 1; // Get a block large enough for the name. Only the first block in the // list is ever considered for name storage. if (block == NULL || block->NextAlloc + len >= BLOCK_SIZE) { block = AddBlock (len); } // Copy the string into the block. textstore = (char *)block + block->NextAlloc; strcpy (textstore, text); block->NextAlloc += len; // Add an entry for the name to the NameArray if (NumNames >= MaxNames) { // If no names have been defined yet, make the first allocation // large enough to hold all the predefined names. MaxNames += MaxNames == 0 ? countof(PredefinedNames) + NAME_GROW_AMOUNT : NAME_GROW_AMOUNT; NameArray = (NameEntry *)M_Realloc (NameArray, MaxNames * sizeof(NameEntry)); } NameArray[NumNames].Text = textstore; NameArray[NumNames].Hash = hash; NameArray[NumNames].NextHash = Buckets[bucket]; Buckets[bucket] = NumNames; return NumNames++; }
UListItem* UList<UListItem, options, tstacksize, tblocksize>::OneLine(){ if(!size_used) return VString(); if(data == data_end) return VString(data->data, size_used * sizeof(UListItem)); AddBlock(size_used); UListData<UListItem> *p = data, *d; int pos = 0; while(p != data_end){ memcpy(data_end->data + pos, p->data, p->size_used * sizeof(UListItem)); pos += p->size_used; size_all -= p->size_all; d = p; p = p->next; if(d != (void*)stackdata) free(d); } data = data_end; data->size_used = pos; return data->data; }
void BuildBannedIPBlocks( char *filename ) { FILE*fp; char buffer[1024]; struct in_addr blocktoAdd ; fp = fopen(filename,"rt"); if( fp == NULL ) { eprintf("Cannot open banned log file %s\n",filename ); return ; } dprintf("loading banned IP addresses\n"); do { if(fgets(buffer,1023,fp) != NULL ) { /* lets be cautious */ if(strlen(buffer)>0) { if( ( blocktoAdd.s_addr = inet_addr( buffer ) ) != -1 ) { AddBlock( -1, &blocktoAdd ); dprintf("Banned IP address %s\n", inet_ntoa( blocktoAdd ) ); } else { eprintf("Warning invalid entry in %s is [%s]\n",filename,buffer); } } } } while( !feof( fp ) ); fclose( fp ); }
void DBufferDWS::Write(int fileId,int segId,int &ofileId,int &osegId){ ofileId = -1; osegId = -1; if(lruQueue.size() >= mBlockNums){ Strategy(fileId,segId,ofileId,osegId); } else{ AddBlock(fileId,segId); } }
void DBufferLFRU::Write(int fileId,int segId,int &ofileId,int &osegId){ ofileId = -1; osegId = -1; if(buf.size() >= mBlockNums){ Strategy(fileId,segId,ofileId,osegId); } else{ AddBlock(fileId,segId); } }
LPMIMEBLOCK CMime::AddFile( LPCTSTR pFile, LPBYTE buf, DWORD size, DWORD flags ) {_STT(); // Allocate memory LPMIMEBLOCK node = new MIMEBLOCK; if ( node == NULL ) return NULL; ZeroMimeBlock( node ); // Get the file name if ( pFile != NULL ) { strcpy_sz( node->fname, pFile ); } // Get MIME type GetContentType( node->fname, node->ctype ); // Create Content-Type string char typestr[ MIME_STRSIZE ]; wsprintf( typestr, "%s;\r\n\tname=\"%s\"", node->ctype, node->fname ); // Save header information node->var.AddVar( "Content-Type", typestr ); node->var.AddVar( "Content-Transfer-Encoding", "base64" ); if ( ( flags & MBF1_ATTACHMENT ) != 0 ) { char disp[ MIME_STRSIZE ]; wsprintf( disp, "attachment;\r\n\tfilename=\"%s\"", node->fname ); node->var.AddVar( "Content-Disposition", disp ); } // end if // Save flags node->f1 = flags; node->f1 |= MBF1_DECODED; // Use base64 encoding node->encode = MBEN_BASE64; // Any data? if ( size > 0 ) { // Allocate memory node->pdata = new char[ size + 1 ]; if ( node->pdata == NULL ) { delete node; return FALSE; } // Copy the data memcpy( node->pdata, buf, size ); node->dsize = size; // NULL terminate (just in case) ( (LPBYTE)node->pdata )[ size ] = 0; } // end if return AddBlock( node ); }
MemoryPool::MemoryPool(SIZE_T elementSize, SIZE_T initGrowth, SIZE_T initCount) : m_elementSize(elementSize), m_growCount(initGrowth), m_blocks(NULL), m_freeList(NULL) { _ASSERTE(elementSize >= sizeof(Element)); _ASSERTE((elementSize & ((sizeof(PVOID)-1))) == 0); if (initCount > 0) AddBlock(initCount); }
int CFreeLists::FindBlock(SHORT nHandle, DWORD dwBlockSize, DWORD * pdwFoundOffset) { int nFindRetVal, nRetVal; DWORD dwCurrentBlockSize, dwOffset, dwNewBlockSize, dwNewOffset; COffsetKey offsetKey; ASSERT(pdwFoundOffset); if(pdwFoundOffset == NULL) return ERRORCODE_BadParameter; nFindRetVal = m_pIndexFile->Find( dwBlockSize, // Key is block size NULL, 0, // No data associated with key 0, // Don't know offset (record #) so supply 0 nHandle); // Index file ID if(nFindRetVal != CCIndexFile::success && nFindRetVal != CCIndexFile::keyMatch && nFindRetVal != CCIndexFile::keyGreaterFound) return ERRORCODE_Fail; nRetVal = m_pIndexFile->GetCurrentKey(&dwCurrentBlockSize); // We should be able to get current key since find was successful if(nRetVal != CCIndexFile::success) CCIndexFileException::Throw(nRetVal); dwOffset = m_pIndexFile->GetRecordNum(); *pdwFoundOffset = dwOffset; // Delete keys thus freeing up block for client to use nRetVal = DeleteKeys( nHandle, dwCurrentBlockSize, dwOffset, FALSE, // Find block key TRUE); // Find offset key if(nRetVal != CCIndexFile::success) CCIndexFileException::Throw(nRetVal); // If requested block size doesn't exactly match requested (Most cases), // Use it anyway by breaking up into 2 blocks with // 1st block matching requested size and second block is remainder // 1st block is marked as free if(nFindRetVal == CCIndexFile::keyGreaterFound) { dwNewBlockSize = dwCurrentBlockSize - dwBlockSize; dwNewOffset = dwOffset + dwBlockSize; nRetVal = AddBlock(nHandle, dwNewBlockSize, dwNewOffset); // Should always be able to add ASSERT(nRetVal == ERRORCODE_None); } return ERRORCODE_None; }
void CNamedIndexes::Init(CDurableFileController* pcController, int iCacheSize, int iBlockChunkSize) { macBlocks.Init(2); mcCache.Init(iCacheSize); mcFiles.Init(pcController, "NAM", "Names.IDX", "_Names.IDX"); AddBlock( 32, 1, 23, iBlockChunkSize); AddBlock( 64, 23, 55, iBlockChunkSize); AddBlock( 96, 55, 87, iBlockChunkSize); AddBlock( 128, 87, 119, iBlockChunkSize); AddBlock( 192, 119, 183, iBlockChunkSize); AddBlock( 256, 183, 247, iBlockChunkSize); AddBlock( 512, 247, 503, iBlockChunkSize); AddBlock(1024, 503, 1015, iBlockChunkSize); AddBlock(4096, 1015, 4087, iBlockChunkSize); //mcFiles.Open(); Open(); }
Sidebar::Sidebar(wxWindow *parent, wxMenu *suggestionsMenu) : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL | wxNO_BORDER | DoubleBufferingWindowStyle()), m_catalog(nullptr), m_selectedItem(nullptr) { SetBackgroundColour(SIDEBAR_BACKGROUND); #ifdef __WXMSW__ if (!IsWindowsXP()) SetDoubleBuffered(true); #endif Bind(wxEVT_PAINT, &Sidebar::OnPaint, this); #ifdef __WXOSX__ SetWindowVariant(wxWINDOW_VARIANT_SMALL); #endif auto *topSizer = new wxBoxSizer(wxVERTICAL); topSizer->SetMinSize(wxSize(PX(300), -1)); m_blocksSizer = new wxBoxSizer(wxVERTICAL); topSizer->Add(m_blocksSizer, wxSizerFlags(1).Expand().PXDoubleBorder(wxTOP|wxBOTTOM)); m_topBlocksSizer = new wxBoxSizer(wxVERTICAL); m_bottomBlocksSizer = new wxBoxSizer(wxVERTICAL); m_blocksSizer->Add(m_topBlocksSizer, wxSizerFlags(1).Expand().ReserveSpaceEvenIfHidden()); m_blocksSizer->Add(m_bottomBlocksSizer, wxSizerFlags().Expand()); AddBlock(new SuggestionsSidebarBlock(this, suggestionsMenu), Top); AddBlock(new OldMsgidSidebarBlock(this), Bottom); AddBlock(new ExtractedCommentSidebarBlock(this), Bottom); AddBlock(new CommentSidebarBlock(this), Bottom); AddBlock(new AddCommentSidebarBlock(this), Bottom); SetSizerAndFit(topSizer); SetSelectedItem(nullptr, nullptr); }
void *FMemArena::Alloc(size_t size) { Block *block; for (block = TopBlock; block != NULL; block = block->NextBlock) { void *res = block->Alloc(size); if (res != NULL) { return res; } } block = AddBlock(size); return block->Alloc(size); }
void DBufferDWS::Strategy(int fileId,int segId,int &ofileId,int &osegId){ // unsigned int fileId,segId; int minWeight =111111111; DWSBlockInfo eliminateBlockPtr; list<DWSBlockInfo>::iterator it,minHistIt,minHistNewIt,minIt; double pfnew ,pfold; //struct timeval cur_tv; int minHistNew; minHistNew = minWeight; //gettimeofday(&cur_tv,NULL); //pfnew = getTimeInterval(&cur_tv,&_t0)/(double)(_period*1000000.0); // pfold = 1- pfnew*pfnew; // pfnew = pow(pfnew,0.25); for(it = lruQueue.begin();it != lruQueue.end();it++){ (*it).weight = (*it).m_histOld + (*it).m_histNew ; (*it).weight = (*it).weight * getWeight((*it).fileId); // cout<<"for file <"<<it->fileId<<","<<it->segId<<">,"<<"old hist = "<<(*it).m_histOld<<",new hist ="<<(*it).m_histNew<<",weight = "<<it->weight<<",the weight of file "<<it->fileId<<" is "<<getWeight(it->fileId)<<endl; // <<",weight = "<<(*it).weight<<endl; /*if(minHistNew > (*it).m_histNew){ minHistNewIt = it; minHistNew = (*it).m_histNew; }*/ if( (*it).weight < minWeight){ minWeight = (*it).weight; minHistIt = it; } } /* if(minHistNew == 0){ eliminateBlockPtr = *minHistNewIt; minIt = minHistNewIt; }else{ eliminateBlockPtr = *minHistIt; minIt = minHistIt; }*/ eliminateBlockPtr = *minHistIt; minIt = minHistIt; // cout<<"delete "<< (*minIt).fileId <<" "<<(*minIt).segId<<endl; ofileId = eliminateBlockPtr.fileId; osegId = eliminateBlockPtr.segId; // delete eliminateBlockPtr; lruQueue.erase(minIt); AddBlock(fileId,segId); }
void *MemoryPool::AllocateElement() { void *element = m_freeList; if (element == NULL) { AddBlock(m_growCount); element = m_freeList; if (element == NULL) return NULL; } m_freeList = m_freeList->next; return element; }
void* Allocator::_Malloc(size_t size, const char* file_name, unsigned int line_num) { //LOG("%s:%d malloc(%d)\n", file_name, line_num, size); size_t total = size + sizeof(Header) + sizeof(Footer); byte* pBlock = (byte*)malloc(total); byte* ptr = pBlock + sizeof(Header); Header* pHeader = reinterpret_cast<Header*>(pBlock); Footer* pFooter = reinterpret_cast<Footer*>(ptr+size); pHeader->Init(size, file_name, line_num); pFooter->Init(size, file_name, line_num); AddBlock(pBlock); return ptr; }
UListItem* UList<UListItem, options, tstacksize, tblocksize>::Add(UListItem *item, int count, int nofragment){ int size_free = size_all - size_used; UListItem * ritem = 0; if(!count) return 0; if(size_free && nofragment && size_free < count){ size_all -= data_end->size_all - data_end->size_used; data_end->size_all = data_end->size_used; size_free = 0; } if(size_free){ ritem = data_end->data + data_end->size_used; if(size_free > count) size_free = count; Copy(ritem, item, size_free); count -= size_free; size_used += size_free; data_end->size_used += size_free; } if(count){ AddBlock(count); if(item) item += size_free; //count -= size_free; Copy(data_end->data, item, count); size_used += count; data_end->size_used += count; if(!ritem) ritem = data_end->data; } return ritem; }
void CXTPReportSelectedRows::Add(CXTPReportRow* pRow) { if (NULL == pRow) { return; } if (_NotifySelChanging(xtpReportSelectionAdd, pRow)) { return; // Handled / Cancel } int nIndex = pRow->GetIndex(); if (nIndex != -1) { AddBlock(nIndex, nIndex); } }
void CW::CeilingTerrain::Scroll(float value) { if (blocks[blocks.size()-1]->Vertices[1]->Position.x < 1600) { AddBlock(); } while (blocks[0]->Vertices[0]->Position.x < -60) { blocks.pop_front(); } for (PhysicsBody* b : blocks) { for (VerletPoint* p : b->Vertices) { p->Position.x += value; } } }
LPMIMEBLOCK CMime::AddPlainText(LPCTSTR pText, DWORD dwSize) {_STT(); if ( pText == NULL ) return NULL; if ( dwSize == 0 ) dwSize = strlen( pText ); if ( dwSize == 0 ) return NULL; // Allocate memory LPMIMEBLOCK node = new MIMEBLOCK; if ( node == NULL ) return NULL; ZeroMimeBlock( node ); // Plain text strcpy( node->ctype, "text/plain" ); node->var.AddVar( "Content-Type", "text/plain;\r\n\tcharset=\"iso-8859-1\"" ); node->var.AddVar( "Content-Transfer-Encoding", "7bit" ); // Allocate memory for text node->pdata = new char[ dwSize /*+ dots*/ + 1 ]; if ( node->pdata == NULL ) { delete node; return FALSE; } char *buf = (char*)node->pdata; DWORD c = 0; for ( DWORD i = 0; i < dwSize && pText[ i ] != 0; i++ ) { char ch = pText[ i ]; // Ignore non 7-bit characters if ( ch <= 0 ); // Just save the character else buf[ c++ ] = ch; } // end for // Save size and NULL terminate node->dsize = c; buf[ c ] = 0; return AddBlock( node ); }
void OpenALThread::Open(const void* src, ALsizei size) { alGenSources(1, &m_source); checkForAlError("alGenSources"); alGenBuffers(g_al_buffers_count, m_buffers); checkForAlError("alGenBuffers"); alSourcei(m_source, AL_LOOPING, AL_FALSE); checkForAlError("OpenALThread::Open ->alSourcei"); m_buffer_size = size; for(uint i=0; i<g_al_buffers_count; ++i) { AddBlock(m_buffers[i], m_buffer_size, src); } alSourceQueueBuffers(m_source, g_al_buffers_count, m_buffers); checkForAlError("alSourceQueueBuffers"); Play(); }
Field::Field(int seed) : blockSize_(60), counter_(0), gameOver_(false), score_(0), level_(GetOptions().Get<int>("startLevel")), lines_(0), maxY_(0), pause_(false), control_(new Control{std::make_shared<KeyboardControl>(), std::make_shared<GamepadControl>(0)}), randomSeed(seed), linesCleared(0) { random.seed(seed); NewTetromino(); NewTetromino(); score_ = 0; std::uniform_int_distribution<int> dist(0, width_ - 1); std::mt19937 colorRandom; std::uniform_int_distribution<int> colorDist(0, 255); for (int i = 0; i < GetOptions().Get<int>("startJunks"); ++i) { int leaveOut = dist(random); for (int x = 0; x < width_; ++x) { if (x != leaveOut) { jngl::Color color(colorDist(colorRandom), colorDist(colorRandom), colorDist(colorRandom)); AddBlock(Block(x, i, color)); } } } }
void CGraphView::DirtyRect(int x1,int y1,int x2,int y2) { RECT r = { x1,y1,x2,y2 }; if (r.left>r.right) std::swap(r.left,r.right); if (r.top>r.bottom) std::swap(r.top,r.bottom); int startx=r.left; int starty=r.top; int endx=r.right+nDIBsize; // round up, goddammit int endy=r.bottom+nDIBsize; startx/=nDIBsize; starty/=nDIBsize; endx/=nDIBsize; endy/=nDIBsize; for (int y=starty; y<=endy; y++) for (int x=startx; x<=endx; x++) AddBlock(x,y); }
void Tetris::AddPiece(game_info* gi, int start_x, int start_y) { switch (gi->curpiece) { case 0: if (gi->curdir % 2) { AddBlock(gi, start_x, start_y, gi->curpiece); AddBlock(gi, start_x-1, start_y, gi->curpiece); AddBlock(gi, start_x-2, start_y, gi->curpiece); AddBlock(gi, start_x+1, start_y, gi->curpiece); } else { AddBlock(gi, start_x, start_y+1, gi->curpiece); AddBlock(gi, start_x, start_y+2, gi->curpiece); AddBlock(gi, start_x, start_y-1, gi->curpiece); AddBlock(gi, start_x, start_y, gi->curpiece); } break; case 1: if (gi->curdir % 2) { AddBlock(gi, start_x+1, start_y, gi->curpiece); AddBlock(gi, start_x+1, start_y-1, gi->curpiece); AddBlock(gi, start_x, start_y, gi->curpiece); AddBlock(gi, start_x, start_y+1, gi->curpiece); } else { AddBlock(gi, start_x+1, start_y, gi->curpiece); AddBlock(gi, start_x, start_y-1, gi->curpiece); AddBlock(gi, start_x, start_y, gi->curpiece); AddBlock(gi, start_x-1, start_y-1, gi->curpiece); } break; case 2: if (gi->curdir % 2) { AddBlock(gi, start_x-1, start_y, gi->curpiece); AddBlock(gi, start_x, start_y+1, gi->curpiece); AddBlock(gi, start_x, start_y, gi->curpiece); AddBlock(gi, start_x-1, start_y-1, gi->curpiece); } else { AddBlock(gi, start_x-1, start_y, gi->curpiece); AddBlock(gi, start_x, start_y-1, gi->curpiece); AddBlock(gi, start_x, start_y, gi->curpiece); AddBlock(gi, start_x+1, start_y-1, gi->curpiece); } break; case 3: AddBlock(gi, start_x+1, start_y, gi->curpiece); AddBlock(gi, start_x, start_y+1, gi->curpiece); AddBlock(gi, start_x, start_y, gi->curpiece); AddBlock(gi, start_x+1, start_y+1, gi->curpiece); break; case 4: if (gi->curdir == 0) { AddBlock(gi, start_x, start_y, gi->curpiece); AddBlock(gi, start_x, start_y+1, gi->curpiece); AddBlock(gi, start_x, start_y-1, gi->curpiece); AddBlock(gi, start_x+1, start_y+1, gi->curpiece); } else if (gi->curdir == 1) { AddBlock(gi, start_x, start_y, gi->curpiece); AddBlock(gi, start_x+1, start_y, gi->curpiece); AddBlock(gi, start_x-1, start_y, gi->curpiece); AddBlock(gi, start_x-1, start_y+1, gi->curpiece); } else if (gi->curdir == 2) { AddBlock(gi, start_x, start_y, gi->curpiece); AddBlock(gi, start_x, start_y+1, gi->curpiece); AddBlock(gi, start_x, start_y-1, gi->curpiece); AddBlock(gi, start_x-1, start_y-1, gi->curpiece); } else { AddBlock(gi, start_x, start_y, gi->curpiece); AddBlock(gi, start_x+1, start_y, gi->curpiece); AddBlock(gi, start_x-1, start_y, gi->curpiece); AddBlock(gi, start_x+1, start_y-1, gi->curpiece); } break; case 5: if (gi->curdir == 0) { AddBlock(gi, start_x, start_y, gi->curpiece); AddBlock(gi, start_x, start_y+1, gi->curpiece); AddBlock(gi, start_x, start_y-1, gi->curpiece); AddBlock(gi, start_x-1, start_y+1, gi->curpiece); } else if (gi->curdir == 1) { AddBlock(gi, start_x, start_y, gi->curpiece); AddBlock(gi, start_x+1, start_y, gi->curpiece); AddBlock(gi, start_x-1, start_y, gi->curpiece); AddBlock(gi, start_x-1, start_y-1, gi->curpiece); } else if (gi->curdir == 2) { AddBlock(gi, start_x, start_y, gi->curpiece); AddBlock(gi, start_x, start_y+1, gi->curpiece); AddBlock(gi, start_x, start_y-1, gi->curpiece); AddBlock(gi, start_x+1, start_y-1, gi->curpiece); } else { AddBlock(gi, start_x, start_y, gi->curpiece); AddBlock(gi, start_x+1, start_y, gi->curpiece); AddBlock(gi, start_x-1, start_y, gi->curpiece); AddBlock(gi, start_x+1, start_y+1, gi->curpiece); } break; case 6: if (gi->curdir == 0) { AddBlock(gi, start_x, start_y, gi->curpiece); AddBlock(gi, start_x, start_y-1, gi->curpiece); AddBlock(gi, start_x+1, start_y, gi->curpiece); AddBlock(gi, start_x-1, start_y, gi->curpiece); } else if (gi->curdir == 1) { AddBlock(gi, start_x, start_y, gi->curpiece); AddBlock(gi, start_x, start_y+1, gi->curpiece); AddBlock(gi, start_x+1, start_y, gi->curpiece); AddBlock(gi, start_x, start_y-1, gi->curpiece); } else if (gi->curdir == 2) { AddBlock(gi, start_x, start_y, gi->curpiece); AddBlock(gi, start_x-1, start_y, gi->curpiece); AddBlock(gi, start_x+1, start_y, gi->curpiece); AddBlock(gi, start_x, start_y+1, gi->curpiece); } else { AddBlock(gi, start_x, start_y, gi->curpiece); AddBlock(gi, start_x-1, start_y, gi->curpiece); AddBlock(gi, start_x, start_y-1, gi->curpiece); AddBlock(gi, start_x, start_y+1, gi->curpiece); } break; } if (gi->side == -1) { engine.PassMessage(MSG_UPDATEPIECE, gi->pos, gi->curdir, gi->curpiece); //engine.PassMessage(MSG_UPDATEPIECEY, , 0, 0); engine.PassMessage(MSG_ADDPIECE, start_x, start_y,0); int lines = ClearLines(gi); gi->state_lines += lines; gi->total_lines += lines; GetNewPiece(gi); if (lines > 1) { engine.SendAttack(lines-1); } if (gi->state_lines >= TETRIS_LINES_NEEDED) { gi->state_lines = 0; engine.DisplayMessage(STR_TRANSITION); engine.audio.PlaySound(SND_CHANGEVIEW); engine.ChangeState(gi, STATE_TETRIS_TRANS); } } }
inline void _Occupy( const OccID& id, GInt x, GInt y, BlockMask block ) { GridCell& cell = m_Grid[x][y]; cell.occupy.push_back( id ); AddBlock( x, y, block, &cell ); }