void rotate(vector<int>& nums, int t) { int n = nums.size(); //if t > n t = t % n; int k = n-t-1; doSwap(nums,0,k); doSwap(nums,k+1,n-1); doSwap(nums,0,n-1); }
clblasStatus clblasZswap( size_t N, cl_mem X, size_t offx, int incx, cl_mem Y, size_t offy, int incy, cl_uint numCommandQueues, cl_command_queue *commandQueues, cl_uint numEventsInWaitList, const cl_event *eventWaitList, cl_event *events) { CLBlasKargs kargs; #ifdef DEBUG_SWAP printf("\nZSWAP Called\n"); #endif memset(&kargs, 0, sizeof(kargs)); kargs.dtype = TYPE_COMPLEX_DOUBLE; return doSwap(&kargs, N, X, offx, incx, Y, offy, incy, numCommandQueues, commandQueues, numEventsInWaitList, eventWaitList, events); }
void IVtkAdaptorService::swapping() throw(fwTools::Failed) { m_connections->disconnect(); m_connections->connect(this->getObject(), this->getSptr(), this->getObjSrvConnections()); doSwap(); requestRender(); }
static BOOL __stdcall mywglSwapBuffers(HDC hdc) { ods("OpenGL: wglSwapBuffers"); doSwap(hdc); hhwglSwapBuffers.restore(); BOOL ret=owglSwapBuffers(hdc); hhwglSwapBuffers.inject(); return ret; }
QString Crypter::desencrypt(const QString &word) { w = word; doXor(); doRot13(); doSwap(); return w; }
bool Board::trySwap( int a, int b ) { bool swapped = false; if (a == b - 1 && b % m_columns != 0) { doSwap(a, b); swapped = true; } else if (a == b + 1 && a % m_columns != 0) { doSwap(a, b); swapped = true; } else if (a == b + m_rows || a == b - m_rows) { doSwap(a, b); swapped = true; } return swapped; }
int CommentWidget::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QDialog::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: doOK(); break; case 1: doCancel(); break; case 2: doComment((*reinterpret_cast< const QString(*)>(_a[1]))); break; case 3: doExtend((*reinterpret_cast< int(*)>(_a[1]))); break; case 4: doFlag((*reinterpret_cast< int(*)>(_a[1]))); break; case 5: doSwap((*reinterpret_cast< bool(*)>(_a[1]))); break; } _id -= 6; } return _id; }
bool doSingleSwapNode(const char *oldip,const char *newip,unsigned nodenum,IPropertyTree *info,const char *timechecked) { if (doSwap(oldip,newip)) { if (info) { StringBuffer times(timechecked); if (times.length()==0) { CDateTime dt; dt.setNow(); dt.getString(times); } // TBD tie up with bad node in auto? IPropertyTree *swap = info->addPropTree("Swap",createPTree("Swap")); swap->setProp("@inNetAddress",newip); swap->setProp("@outNetAddress",oldip); swap->setProp("@time",times.str()); if (UINT_MAX != nodenum) swap->setPropInt("@rank",nodenum-1); } return true; } return false; }
void Board::update() { // First shift all the jewels down to fill empty spaces for (size_t i = 0; i < m_columns; ++i) { for (size_t j = m_rows - 1; j > 0; --j) { int pos = (j * m_columns) + i; int swap = pos; if (m_board[pos] == 0) { while (swap >= m_columns) { if (m_board[swap - m_columns] == 0) { swap -= m_columns; continue; } doSwap(pos, swap - m_columns); break; } } } } // Now generate some new jewels randomly for (size_t i = 0; i < m_board.size(); ++i) { if (m_board[i] == 0) { m_board[i] = generateRandomJewel(); } } }
bool doRedo() { return doSwap(); }
bool doUndo() { return doSwap(); }
static bool getDump (istream& ifile, ostream& ofile, vector<Data2DF*>& u ) // --------------------------------------------------------------------------- // Read next set of field dumps from ifile, put headers on ofile. // --------------------------------------------------------------------------- { static char* hdr_fmt[] = { "%-25s " "Session\n", "%-25s " "Created\n", "%-25s " "Nr, Ns, Nz, Elements\n", "%-25d " "Step\n", "%-25.6g " "Time\n", "%-25.6g " "Time step\n", "%-25.6g " "Kinvis\n", "%-25.6g " "Beta\n", "%-25s " "Fields written\n", "%-25s " "Format\n" }; char buf[StrMax], fmt[StrMax], fields[StrMax]; int_t i, j, swab, nf, np, nz, nel; if (ifile.getline(buf, StrMax).eof()) return false; if (!strstr (buf, "Session")) message (prog, "not a field file", ERROR); ofile << buf << endl; ifile.getline (buf, StrMax); ofile << buf << endl; // -- I/O Numerical description of field sizes. ifile >> np >> nz >> nz >> nel; ifile.getline (buf, StrMax); sprintf (fmt, "%1d %1d %1d %1d", np, np, nz, nel); sprintf (buf, hdr_fmt[2], fmt); ofile << buf; for (i = 0; i < 5; i++) { ifile.getline (buf, StrMax); ofile << buf << endl; } // -- I/O field names. ifile >> fields; nf = strlen (fields); for (j = 0, i = 0; i < nf; i++) fmt[j++] = fields[i]; fmt[j] = '\0'; sprintf (buf, hdr_fmt[8], fmt); ofile << buf; ifile.getline (buf, StrMax); // -- Arrange for byte-swapping if required. ifile.getline (buf, StrMax); swab = doSwap (buf); sprintf (buf, "binary "); Veclib::describeFormat (buf + strlen (buf)); sprintf (fmt, hdr_fmt[9], buf); ofile << fmt; if (u.size() != nf) { u.resize (nf); for (i = 0; i < nf; i++) u[i] = new Data2DF (np, nz, nel, fields[i]); } for (i = 0; i < nf; i++) { ifile >> *u[i]; if (swab) u[i] -> reverse(); } return ifile.good(); }
void Board::init() { // Fill the board with random jewels for (size_t i = 0; i < m_board.size(); ++i) { m_board[i] = generateRandomJewel(); // For every third jewel, make sure it's different from the previous three if (i % 3 == 2) { while (m_board[i] == m_board[i-1]) { m_board[i] = generateRandomJewel(); } } } // Now we know there are no horizontal matches, we need to check for vertical // It's enough if we check every second row std::vector<int> matches; for (size_t i = m_columns; i < m_board.size(); ++i) { if (findVerticalMatches(i, matches)) { // Change every 3rd element so it doesn't match others for (size_t j = 0; j < matches.size(); ++j) { if(j % 3 == 2) { int k = matches[j]; if (k == 0 || k == m_board.size() - 1) { k = matches[j-1]; } while(m_board[k] == m_board[k-1] && m_board[k] == m_board[k+1] && m_board[k] == m_board[k-m_columns]) { m_board[i] = generateRandomJewel(); } } } } // Skip one row if (isFirstColumn(i)) { i += m_columns; } } // Make sure there are some possible moves on the board int pos; int swap; for (size_t i = 0; i < 2; ++i) // change 2 to m_difficulty { pos = generateRandomPosition(); swap = generateRandomSwap(pos); if (swap == pos - m_columns || swap == pos + m_columns) { m_board[pos - 1] = m_board[pos]; m_board[pos + 2] = m_board[pos]; doSwap(pos, swap); } else { m_board[pos - m_columns] = m_board[pos]; m_board[pos + m_columns] = m_board[pos]; doSwap(pos, swap); } } // Validate and remove any remaining matches for (size_t i = 0; i < m_board.size(); ++i) { matches.clear(); while (checkPosition(i, matches)) { for (size_t j = 0; j < matches.size(); ++j) { if (j % 2 == 0) { m_board[matches[j]] = generateRandomJewel(); } } } } }
void redo() { doSwap(m_insert); }
static int_t getDump (ifstream& file, vector<AuxField*>& u , vector<Element*>& Esys, const int_t np , const int_t nz , const int_t nel , int_t& step, real_t& time, real_t& tstp, real_t& kinv, real_t& beta) // --------------------------------------------------------------------------- // Load data from field dump, with byte-swapping if required. // If there is more than one dump in file, it is required that the // structure of each dump is the same as the first. // --------------------------------------------------------------------------- { char buf[StrMax], fields[StrMax]; int_t i, nf, npnew, nznew, nelnew; bool swab; if (file.getline(buf, StrMax).eof()) return 0; if (!strstr (buf, "Session")) message (prog, "not a field file", ERROR); file.getline (buf, StrMax); // -- Input numerical description of field sizes. file >> npnew >> nznew >> nznew >> nelnew; file.getline (buf, StrMax); if (np != npnew || nz != nznew || nel != nelnew) message (prog, "size of dump mismatch with session file", ERROR); file >> step; file.getline (buf, StrMax); file >> time; file.getline (buf, StrMax); file >> tstp; file.getline (buf, StrMax); file >> kinv; file.getline (buf, StrMax); file >> beta; file.getline (buf, StrMax); // -- Input field names, assumed to be written without intervening spaces. file >> fields; nf = strlen (fields); file.getline (buf, StrMax); // -- Arrange for byte-swapping if required. file.getline (buf, StrMax); swab = doSwap (buf); // -- Create AuxFields on first pass. if (u.size() == 0) { u.resize (nf); for (i = 0; i < nf; i++) u[i] = new AuxField (new real_t[Geometry::nTotal()], nz, Esys, fields[i]); } else if (u.size() != nf) message (prog, "number of fields mismatch with first dump in file", ERROR); // -- Read binary field data. for (i = 0; i < nf; i++) { file >> *u[i]; if (swab) u[i] -> reverse(); } return file.good(); }
void undo() { doSwap(!m_insert); }
void MenuState::update(Timer* timer, bool* m_keysHeld) { avatars[0]->cycleSpriteFrame(timer->get_ticks()); avatars[1]->cycleSpriteFrame(timer->get_ticks()); avatars[2]->cycleSpriteFrame(timer->get_ticks()); // these three conditionals are so similiar, i want to abstract this // if we are in the inventory pane do the key handling if (InventoryMenu->selected_huh) { if (m_keysHeld[ SDLK_RETURN ] ) { InventoryMenu->getSelected()->doCallback(); m_keysHeld[ SDLK_RETURN ] = false; } if (m_keysHeld[ SDLK_DOWN ]) { InventoryMenu->decSelected(); m_keysHeld[ SDLK_DOWN ] = false; } if (m_keysHeld[ SDLK_UP ]) { InventoryMenu->incSelected(); m_keysHeld[ SDLK_UP ] = false; } if (m_keysHeld[ SDLK_LEFT ]) { CharMenu->incSelected(); InventoryMenu->selected_huh = false; m_keysHeld[ SDLK_LEFT ] = false; update_select_pane(); } if (m_keysHeld[ SDLK_RIGHT ]) { CharMenu->incSelected(); InventoryMenu->selected_huh = false; m_keysHeld[ SDLK_RIGHT ] = false; update_select_pane(); } if (m_keysHeld[ SDLK_ESCAPE ]) { status = false; m_keysHeld[ SDLK_ESCAPE ] = false; } } // if we are in the char pane do the key handling if (CharMenu->selected_huh) { if (m_keysHeld[ SDLK_RETURN ] ) { CharMenu->getSelected()->doCallback(); m_keysHeld[ SDLK_RETURN ] = false; } if (m_keysHeld[ SDLK_DOWN ]) { CharMenu->decSelected(); m_keysHeld[ SDLK_DOWN ] = false; } if (m_keysHeld[ SDLK_UP ]) { CharMenu->incSelected(); m_keysHeld[ SDLK_UP ] = false; } if (m_keysHeld[ SDLK_LEFT ]) { InventoryMenu->incSelected(); CharMenu->selected_huh = false; m_keysHeld[ SDLK_LEFT ] = false; update_select_pane(); } if (m_keysHeld[ SDLK_RIGHT ]) { InventoryMenu->incSelected(); // fix CharMenu->selected_huh = false; m_keysHeld[ SDLK_RIGHT ] = false; update_select_pane(); } if (m_keysHeld[ SDLK_ESCAPE ]) { status = false; m_keysHeld[ SDLK_ESCAPE ] = false; } } // if we are in the select pane do the key handling if (SelectMenu->selected_huh) { if (m_keysHeld[ SDLK_RETURN ] ) { SelectMenu->getSelected()->doCallback(); m_keysHeld[ SDLK_RETURN ] = false; } if (m_keysHeld[ SDLK_DOWN ]) { SelectMenu->decSelected(); m_keysHeld[ SDLK_DOWN ] = false; } if (m_keysHeld[ SDLK_UP ]) { SelectMenu->incSelected(); m_keysHeld[ SDLK_UP ] = false; } if (m_keysHeld[ SDLK_ESCAPE ]) { SelectMenu->selected_huh = false; if (SelectMenu->getCurrent()->getTitle() == "Inventory") { InventoryMenu->incSelected(); }else { CharMenu->incSelected(); // fixme here and above } m_keysHeld[ SDLK_ESCAPE ] = false; } } // if the character swap is activated if (NotPartyMenu->selected_huh) { if (m_keysHeld[ SDLK_RETURN ] ) { doSwap(timer); m_keysHeld[ SDLK_RETURN ] = false; } if (m_keysHeld[ SDLK_DOWN ]) { NotPartyMenu->decSelected(); m_keysHeld[ SDLK_DOWN ] = false; } if (m_keysHeld[ SDLK_UP ]) { NotPartyMenu->incSelected(); m_keysHeld[ SDLK_UP ] = false; } if (m_keysHeld[ SDLK_ESCAPE ]) { NotPartyMenu->selected_huh = false; SelectMenu->incSelected(); // fixme here and above, using this to change selected_huh and selected item m_keysHeld[ SDLK_ESCAPE ] = false; } } }
void IAdaptor::swapping() throw(fwTools::Failed) { m_connections->disconnect(); m_connections->connect(this->getObject(), this->getSptr(), this->getObjSrvConnections()); doSwap(); }
bool doRedo() override { return doSwap(); }
void ClusterServer::render(RenderActionBase *action) { doSync (false ); doRender(action); doSwap ( ); }
texfnt * readtexfont(char *name) { texfnt *tfnt; unsigned *image; unsigned char *cptr; unsigned short *sbuf, *sptr; short advancecell, xadvance; short llx, lly, urx, ury, ox, oy; int i, y, extralines; texchardesc *cd; int xsize, ysize, components; int swap = doSwap(); int tmp; tfnt = (texfnt *) malloc(sizeof(texfnt)); image = read_texture(name, &xsize, &ysize, &components); if (!image) { fprintf(stderr, "textmap: can't open font image %s\n", name); return 0; } extralines = ysize - xsize; if (extralines < 1) { fprintf(stderr, "textmap: bad input font!!\n"); return 0; } fb = (unsigned char *) malloc(xsize * extralines); sbuf = (unsigned short *) malloc(xsize * sizeof(short)); cptr = fb; for (y = xsize; y < ysize; y++) { int x; for (x = 0; x < xsize; x++) cptr[x] = image[y * xsize + x] >> 16; cptr += xsize; } initget(); tfnt->rasxsize = xsize; tfnt->rasysize = xsize; getbytes(&tfnt->charmin, sizeof(short)); getbytes(&tfnt->charmax, sizeof(short)); getbytes(&tfnt->pixhigh, sizeof(float)); getbytes(&advancecell, sizeof(short)); if (swap) { SWAPS(&tfnt->charmin, tmp); SWAPS(&tfnt->charmax, tmp); SWAPL(&tfnt->pixhigh, tmp); SWAPS(&advancecell, tmp); } tfnt->nchars = tfnt->charmax - tfnt->charmin + 1; tfnt->chars = (texchardesc *) malloc(tfnt->nchars * sizeof(texchardesc)); tfnt->rasdata = (unsigned short *) malloc(tfnt->rasxsize * tfnt->rasysize * sizeof(long)); sptr = tfnt->rasdata; for (y = 0; y < tfnt->rasysize; y++) { int x; for (x = 0; x < xsize; x++) sptr[x] = image[y * xsize + x] >> 16; fixrow(sptr, tfnt->rasxsize); sptr += tfnt->rasxsize; } cd = tfnt->chars; for (i = 0; i < tfnt->nchars; i++) { getbytes(&xadvance, sizeof(short)); getbytes(&llx, sizeof(short)); getbytes(&lly, sizeof(short)); getbytes(&urx, sizeof(short)); getbytes(&ury, sizeof(short)); getbytes(&ox, sizeof(short)); getbytes(&oy, sizeof(short)); if (swap) { SWAPS(&xadvance, tmp); SWAPS(&llx, tmp); SWAPS(&lly, tmp); SWAPS(&urx, tmp); SWAPS(&ury, tmp); SWAPS(&ox, tmp); SWAPS(&oy, tmp); } cd->movex = xadvance / (float) advancecell; if (llx >= 0) { cd->haveimage = 1; cd->llx = (llx - ox) / tfnt->pixhigh; cd->lly = (lly - oy) / tfnt->pixhigh; cd->urx = (urx - ox + 1) / tfnt->pixhigh; cd->ury = (ury - oy + 1) / tfnt->pixhigh; cd->tllx = llx / (float) tfnt->rasxsize; cd->tlly = lly / (float) tfnt->rasysize; cd->turx = (urx + 1) / (float) tfnt->rasxsize; cd->tury = (ury + 1) / (float) tfnt->rasysize; cd->data[0] = cd->tllx; cd->data[1] = cd->tlly; cd->data[2] = cd->llx; cd->data[3] = cd->lly; cd->data[4] = cd->turx; cd->data[5] = cd->tlly; cd->data[6] = cd->urx; cd->data[7] = cd->lly; cd->data[8] = cd->turx; cd->data[9] = cd->tury; cd->data[10] = cd->urx; cd->data[11] = cd->ury; cd->data[12] = cd->tllx; cd->data[13] = cd->tury; cd->data[14] = cd->llx; cd->data[15] = cd->ury; cd->data[16] = cd->llx; cd->data[17] = cd->lly; cd->data[18] = cd->urx; cd->data[19] = cd->lly; cd->data[20] = cd->urx; cd->data[21] = cd->ury; cd->data[22] = cd->llx; cd->data[23] = cd->ury; } else { cd->haveimage = 0; } cd++; } free(fb); free(sbuf); free(image); return tfnt; }