int key_hook(int key, void *param) { t_env *env; env = (t_env*)param; if (key == 53) exit(1); if (key == 69) env->position->zoom *= 1.5; if (key == 78) env->position->zoom /= 1.5; if (key == 123) env->position->x_offset -= .5 / env->position->zoom; if (key == 124) env->position->x_offset += .5 / env->position->zoom; if (key == 125) env->position->y_offset += .5 / env->position->zoom; if (key == 126) env->position->y_offset -= .5 / env->position->zoom; if (key == 67) env->position->density *= 1.5; if (key == 75) env->position->density /= 1.5; check_position(env); draw(env); return (0); }
void Game_Utils::move_to_position( float &x, float &y ) { UI::Actor_Layer* al = get_actor_layer(); if(al){ check_position(x, y); al->move_to(x,y); } }
int expose_hook(void *param) { t_env *env; env = (t_env*)param; check_position(env); draw(env); return (0); }
/* ** Quand on arrive en fin de lvl on incremente ou decremente de incr case */ static void select_incr(t_world *world, t_card *pos, int incr) { pos->x += (pos->direction % 2) ? (pos->direction == NORD) ? -incr : incr : (pos->direction == EST) ? 1 : -1 ; pos->y += (pos->direction % 2) ? (pos->direction == NORD) ? -1 : 1 : (pos->direction == EST) ? -incr : incr; check_position(world, &(pos->y), &(pos->x), (pos->direction % 2) ? OUEST : NORD); }
void TraCIClient::do_send_command( const CommandId command, const TraciMessage &out, TraciMessage &in ) const { // Preconditions if ( ! socket_.get() ) { std::cerr << "TraCIClient::do_send_command: no socket" << std::endl; abort(); } // Send command try { socket_->sendExact( out ); socket_->receiveExact( in ); } catch ( SocketException &e ) { std::cerr << "Error in TraCIClient::do_send_command: " << e.what() << std::endl; abort(); } // check response unsigned int command_start = in.position(); unsigned int command_length = read_length( in ); // check received command ID UbyteType rcvdCommandId(in); if ( command != rcvdCommandId ) { std::cerr << sc_->world().scheduler().current_time(); std::cerr << ": Error in method TraCIClient::do_send_command, Server answered to command: "; std::cerr << std::hex << "0x" << static_cast<unsigned int>(rcvdCommandId); std::cerr << ". Expected command: 0x" << static_cast<unsigned int>(command) << std::dec << std::endl; abort(); } // check response status const StatusResponseType response(in); if ( !response.isSuccess() ) { std::cerr << sc_->world().scheduler().current_time() << ": Error in method TraCIClient::do_send_command, Server returned error " << "[0x" << std::hex << std::setfill('0') << std::setw(2) << static_cast<unsigned int>(response.result) << "]: " << response.description << std::dec << std::setfill(' ') << std::endl; abort(); } // Right length? check_position( in, command_start + command_length, "TraCIClient::do_send_command" ); }
void ParameterSetCanvas::pin_deleted() { QValueList<PinCanvas *>::Iterator iter = params.begin(); while (iter != params.end()) { if (!(*iter)->visible()) { disconnect((*iter)->get_bn()->get_data(), SIGNAL(deleted()), this, SLOT(pin_deleted())); iter = params.remove(iter); } else ++iter; } check_position(); }
/************************************************ * axis_position function * During milling time ***********************************************/ place axis_position(place positions) { place pos_prov; pos_prov = check_position(positions); //check if we invalidate the limits if(pos_prov.x_pos==0 && pos_prov.y_pos==0 && pos_prov.z_pos==0) { read_docs();//sd read } else if(pos_prov.x_pos!=0 || pos_prov.y_pos!=0 || pos_prov.z_pos!=0 ) //if does not { result=actual_to_previous(positions); //actualize the positions & return the difference if(result.x_pos!=0) //if x axis has changed { prove.axes=driverx; prove.step=mm_to_steps(result.x_pos); if(result.x_pos>0) prove.direction=pos; else prove.direction=neg; move_motor(prove, 3000); result.x_pos=0; } if(result.y_pos!=0) { prove.axes=drivery; prove.step=mm_to_steps(result.y_pos); if(result.y_pos>0) prove.direction=pos; else prove.direction=neg; move_motor(prove, 3000); result.y_pos=0; } if(result.z_pos!=0) { prove.axes=driverz; prove.step=mm_to_steps(result.z_pos); if(result.z_pos>0) prove.direction=pos; else prove.direction=neg; move_motor(prove, 3000); result.z_pos=0; } //aqui iniciar el timer GIE } return positions; }
/* ** Boucle sur une rangee */ static void look_rank(t_world *world, t_card *pos, int nb_case, t_cli *ia) { int k; k = 0; while (k < nb_case) { if (nb_case != 1 || k) save_cmd(ia, MSG_INTER_VOIR, LEN_INTER_VOIR, 'W'); check_position(world, &(pos->y), &(pos->x), pos->direction); ia_print_content_case(&(world->map[pos->y][pos->x]), ia); if (pos->direction % 2) pos->x += (pos->direction == NORD) ? 1 : -1; else pos->y += (pos->direction == OUEST) ? -1 : 1; k++; } }
//--------------------------------------------------------------------- void TraCIClient::send_command( CommandId command, const traci::TraciType & content, traci::TraciType & answer ) const throw( tcpip::SocketException ) { Storage in; send_command(command, content, in); if ( !in.valid_pos() ) throw std::runtime_error( "traci::TraCIClient::send_command: missing response command" ); const unsigned int commandStart = in.position(); const unsigned int commandLength = read_length(in); answer.read(in); check_position( in, commandStart + commandLength, "TraCIClient::command_get_value" ); }
void ParameterSetCanvas::update() { used_color = (itscolor == UmlDefaultColor) ? the_canvas()->browser_diagram()->get_color(UmlActivityPin) : itscolor; disconnect_pins(); QValueList<PinCanvas *> pincanvas = act->get_pins(); QValueList<PinCanvas *>::ConstIterator iter; QValueList<BrowserPin *> pins = ((ParameterSetData *) browser_node->get_data())->get_pins(); for (iter = pincanvas.begin(); iter != pincanvas.end(); ++iter) { if (pins.findIndex((BrowserPin *) (*iter)->get_bn()) != -1) { params.append(*iter); connect((*iter)->get_bn()->get_data(), SIGNAL(deleted()), this, SLOT(pin_deleted())); } } check_position(); }
void SitesChecks::init(std::vector<std::vector<std::string>> mut) { // convert the rates data to a nested map for (auto line : mut) { mut_dict[line[0]][line[1]] = std::stod(line[2]); } // calculate the length of sequences used in the mutation rate dictionary // This means we can flexibly use 3-mers, 5-mers, 7-mers etc if desired. std::string str = mut_dict.begin()->first; kmer_length = str.length(); mid_pos = kmer_length/2; initialise_choices(); // check the consequence alternates for each base in the coding sequence Region region = _get_gene_range(_tx); for (int i=region.start; i < region.end + 1; i++ ) { check_position(i); } }
bool DFS(unsigned int k) { if(k==-1) return true; unsigned int a=k/N,b=k%N; if(map[a][b]) return DFS(k-1); else { for(unsigned int i=1;i<=N;i++) { if(check_position(a,b,i)) { map[a][b]=i; flag_position(a,b); if(DFS(k-1)) return true; flag_position(a,b); } } map[a][b]=0; } return false; }
int mouse_hook(int x, int y, void *param) { t_env *env; env = (t_env*)param; if (env->fractal == 2) { env->position->julia_x_factor = (double)x / (double)env->window->width; env->position->julia_y_factor = (double)y / (double)env->window->height; if (env->position->julia_x_factor < 0) env->position->julia_x_factor = 0; if (env->position->julia_y_factor < 0) env->position->julia_y_factor = 0; if (env->position->julia_x_factor > 1) env->position->julia_x_factor = 1; if (env->position->julia_y_factor > 1) env->position->julia_y_factor = 1; check_position(env); draw(env); } return (0); }
void ParameterSetCanvas::do_moveBy(double, double) { // action and pins already in position, can check check_position(); }
void ParameterSetCanvas::do_change_scale() { // action and pins already in position, can check check_position(); }
int game ( int *c ) { char title[100]; int **body; int i = 0; int dir = *c; int state = 0; snakesize = 7; food_x = 0; food_y = 0; points = 0; *c = KEY_RIGHT; clear(); body = (int **) malloc(sizeof(int *)*snakesize); for ( i = 0; i != snakesize; i++ ) { body[i] = (int *) malloc(sizeof(int)*2); } attron(COLOR_PAIR(PANEL)); for ( i = 0; i != COLS; i++ ) { mvaddch(0, i, ' '); } sprintf(title," ..:: Snakie v 1.0 ::.. "); mvaddstr(0, COLS/2-strlen(title)/2, title); attroff(COLOR_PAIR(PANEL)); refresh(); for ( i = 0; i!= snakesize; i++ ) { body[i][x] = (COLS/2)-i; body[i][y] = (LINES/2); } pos_food(body); draw_food(); draw_snake(body); while ( 1 ) { clear_snake(body); switch(*c) { case KEY_UP: dir = 'U'; break; case KEY_DOWN: dir = 'D'; break; case KEY_RIGHT: dir = 'R'; break; case KEY_LEFT: dir = 'L'; break; } if ( *c == 'q' ) { if ( confirm() == 1 ) { state = 0; break; } } move_snake(dir, &body); if ( (state = check_position(body)) != 0 ) { dead = 1; break; } eat_food(&body); draw_food(); draw_info(); draw_snake(body); usleep( dir == 'L' || dir == 'R' ? speed*0.75 : speed ); } int ret = quit(&body, state); return ret; }
/*program for the game "tank"*/ int main()/*begin finction main*/ { /*declare variables for this program*/ int size; int x; int y; int counter = 0; int check = 0; int checkpos; int antibomb = 1; printf("\nEnter the grid size: ");/*prompt user to enter a grid size*/ scanf("%d", &size);/*assign value to the variable size*/ srand(time(NULL));/*ranomize the function rand*/ initialize_grid(size);/*initialize the display array*/ set_bomb(size);/*set bombs and open spots on the grid*/ set_antibomb(size);/*set two antibombs on grid*/ while (counter < 5)/*begin game code for 5 rounds of safe tank moves*/ { check = 0;/*set check back to 0*/ while (check == 0) { printf("\nEnter the x position for tank: ");/*promt user to enter x postition to move tank to*/ scanf("%d", &x); printf("Enter the y position for tank: ");/*prompt user to enter y position to move tank to */ scanf("%d", &y); check = error_check(x, y, size); /*check to see that user entered correct coordnance to move tank to*/ } checkpos = check_position(x, y);/*check to see what lies where user chose to move tank*/ if (checkpos == 1)/*case user landed on a bomb*/ { --antibomb;/*remove antibomb*/ if (antibomb == 0)/*if no anti bombs, GAME OVER*/ { printf("\nTank was bombed\nYou lost the game\n\n"); play[y][x] = '$';/*mark where bomb was*/ display_grid(play, size);/*display play grid*/ printf("\n"); return 0;/*game over*/ } else { printf("Tank was bombed but but anti-bomb saved the tank\n\n");/*if user had an anti bomb, game continues*/ display_grid(display, size); } } else if (checkpos == 2)/*case user lands on antibomb*/ { ++antibomb;/*add an antibomb*/ printf("\nAntibomb collected\n\n");/*let user know they collected an antibomb*/ display_grid(display, size);/*display grid with moves marked*/ } else { counter++;/*add one to counter*/ display[y][x] = '+';/*add one to counter and mark spot that user has already moved to*/ printf("\n"); display_grid(display, size);/*display grid with move marked moves*/ } } printf("\nCongratulations you won the game.\nTank survived all the bomb attacks.\n\n");/*prompt the user that they have won the game*/ }/*end function main*/
static void wave_in_test_deviceIn(int device, LPWAVEFORMATEX pwfx, DWORD format, DWORD flags, LPWAVEINCAPS pcaps) { HWAVEIN win; HANDLE hevent; WAVEHDR frag; MMRESULT rc; DWORD res; MMTIME mmt; WORD nChannels = pwfx->nChannels; WORD wBitsPerSample = pwfx->wBitsPerSample; DWORD nSamplesPerSec = pwfx->nSamplesPerSec; hevent=CreateEvent(NULL,FALSE,FALSE,NULL); ok(hevent!=NULL,"CreateEvent(): error=%d\n",GetLastError()); if (hevent==NULL) return; win=NULL; rc=waveInOpen(&win,device,pwfx,(DWORD_PTR)hevent,0,CALLBACK_EVENT|flags); /* Note: Win9x doesn't know WAVE_FORMAT_DIRECT */ ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_BADDEVICEID || rc==MMSYSERR_NOTENABLED || rc==MMSYSERR_NODRIVER || rc==MMSYSERR_ALLOCATED || ((rc==WAVERR_BADFORMAT || rc==MMSYSERR_NOTSUPPORTED) && (flags & WAVE_FORMAT_DIRECT) && !(pcaps->dwFormats & format)) || ((rc==WAVERR_BADFORMAT || rc==MMSYSERR_NOTSUPPORTED) && (!(flags & WAVE_FORMAT_DIRECT) || (flags & WAVE_MAPPED)) && !(pcaps->dwFormats & format)) || (rc==MMSYSERR_INVALFLAG && (flags & WAVE_FORMAT_DIRECT)), "waveInOpen(%s): format=%dx%2dx%d flags=%x(%s) rc=%s\n", dev_name(device),pwfx->nSamplesPerSec,pwfx->wBitsPerSample, pwfx->nChannels,CALLBACK_EVENT|flags, wave_open_flags(CALLBACK_EVENT|flags),wave_in_error(rc)); if ((rc==WAVERR_BADFORMAT || rc==MMSYSERR_NOTSUPPORTED) && (flags & WAVE_FORMAT_DIRECT) && (pcaps->dwFormats & format)) trace(" Reason: The device lists this format as supported in it's " "capabilities but opening it failed.\n"); if ((rc==WAVERR_BADFORMAT || rc==MMSYSERR_NOTSUPPORTED) && !(pcaps->dwFormats & format)) trace("waveInOpen(%s): format=%dx%2dx%d %s rc=%s failed but format " "not supported so OK.\n",dev_name(device),pwfx->nSamplesPerSec, pwfx->wBitsPerSample,pwfx->nChannels, flags & WAVE_FORMAT_DIRECT ? "flags=WAVE_FORMAT_DIRECT" : flags & WAVE_MAPPED ? "flags=WAVE_MAPPED" : "", mmsys_error(rc)); if (rc!=MMSYSERR_NOERROR) { CloseHandle(hevent); return; } res=WaitForSingleObject(hevent,1000); ok(res==WAIT_OBJECT_0,"WaitForSingleObject failed for open\n"); ok(pwfx->nChannels==nChannels && pwfx->wBitsPerSample==wBitsPerSample && pwfx->nSamplesPerSec==nSamplesPerSec, "got the wrong format: %dx%2dx%d instead of %dx%2dx%d\n", pwfx->nSamplesPerSec, pwfx->wBitsPerSample, pwfx->nChannels, nSamplesPerSec, wBitsPerSample, nChannels); /* Check that the position is 0 at start */ check_position(device, win, 0, pwfx); frag.lpData=HeapAlloc(GetProcessHeap(), 0, pwfx->nAvgBytesPerSec); frag.dwBufferLength=pwfx->nAvgBytesPerSec; frag.dwBytesRecorded=0; frag.dwUser=0; frag.dwFlags=0; frag.dwLoops=0; frag.lpNext=0; rc=waveInPrepareHeader(win, &frag, sizeof(frag)); ok(rc==MMSYSERR_NOERROR, "waveInPrepareHeader(%s): rc=%s\n", dev_name(device),wave_in_error(rc)); ok(frag.dwFlags&WHDR_PREPARED,"waveInPrepareHeader(%s): prepared flag " "not set\n",dev_name(device)); if (winetest_interactive && rc==MMSYSERR_NOERROR) { trace("Recording for 1 second at %5dx%2dx%d %s %s\n", pwfx->nSamplesPerSec, pwfx->wBitsPerSample,pwfx->nChannels, get_format_str(pwfx->wFormatTag), flags & WAVE_FORMAT_DIRECT ? "WAVE_FORMAT_DIRECT" : flags & WAVE_MAPPED ? "WAVE_MAPPED" : ""); rc=waveInAddBuffer(win, &frag, sizeof(frag)); ok(rc==MMSYSERR_NOERROR,"waveInAddBuffer(%s): rc=%s\n", dev_name(device),wave_in_error(rc)); /* Check that the position is 0 at start */ check_position(device, win, 0, pwfx); rc=waveInStart(win); ok(rc==MMSYSERR_NOERROR,"waveInStart(%s): rc=%s\n", dev_name(device),wave_in_error(rc)); res = WaitForSingleObject(hevent,1200); ok(res==WAIT_OBJECT_0,"WaitForSingleObject failed for header\n"); ok(frag.dwFlags&WHDR_DONE,"WHDR_DONE not set in frag.dwFlags\n"); ok(frag.dwBytesRecorded==pwfx->nAvgBytesPerSec, "frag.dwBytesRecorded=%d, should=%d\n", frag.dwBytesRecorded,pwfx->nAvgBytesPerSec); mmt.wType = TIME_SAMPLES; rc=waveInGetPosition(win, &mmt, sizeof(mmt)); ok(rc==MMSYSERR_NOERROR,"waveInGetPosition(%s): rc=%s\n", dev_name(device),wave_in_error(rc)); ok(mmt.u.cb == frag.dwBytesRecorded, "Got wrong position: %u\n", mmt.u.cb); /* stop playing on error */ if (res!=WAIT_OBJECT_0) { rc=waveInStop(win); ok(rc==MMSYSERR_NOERROR, "waveInStop(%s): rc=%s\n",dev_name(device),wave_in_error(rc)); } } rc=waveInUnprepareHeader(win, &frag, sizeof(frag)); ok(rc==MMSYSERR_NOERROR,"waveInUnprepareHeader(%s): rc=%s\n", dev_name(device),wave_in_error(rc)); rc=waveInClose(win); ok(rc==MMSYSERR_NOERROR, "waveInClose(%s): rc=%s\n",dev_name(device),wave_in_error(rc)); res=WaitForSingleObject(hevent,1000); ok(res==WAIT_OBJECT_0,"WaitForSingleObject failed for close\n"); if (winetest_interactive) { /* * Now play back what we recorded */ HWAVEOUT wout; trace("Playing back recorded sound\n"); rc=waveOutOpen(&wout,WAVE_MAPPER,pwfx,(DWORD_PTR)hevent,0,CALLBACK_EVENT); ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_BADDEVICEID || rc==MMSYSERR_NOTENABLED || rc==MMSYSERR_NODRIVER || rc==MMSYSERR_ALLOCATED || ((rc==WAVERR_BADFORMAT || rc==MMSYSERR_NOTSUPPORTED) && !(pcaps->dwFormats & format)), "waveOutOpen(%s) format=%dx%2dx%d flags=%x(%s) rc=%s\n", dev_name(device),pwfx->nSamplesPerSec,pwfx->wBitsPerSample, pwfx->nChannels,CALLBACK_EVENT|flags, wave_open_flags(CALLBACK_EVENT),wave_out_error(rc)); if (rc==MMSYSERR_NOERROR) { rc=waveOutPrepareHeader(wout, &frag, sizeof(frag)); ok(rc==MMSYSERR_NOERROR,"waveOutPrepareHeader(%s): rc=%s\n", dev_name(device),wave_out_error(rc)); if (rc==MMSYSERR_NOERROR) { WaitForSingleObject(hevent,INFINITE); rc=waveOutWrite(wout, &frag, sizeof(frag)); ok(rc==MMSYSERR_NOERROR,"waveOutWrite(%s): rc=%s\n", dev_name(device),wave_out_error(rc)); WaitForSingleObject(hevent,INFINITE); rc=waveOutUnprepareHeader(wout, &frag, sizeof(frag)); ok(rc==MMSYSERR_NOERROR,"waveOutUnprepareHeader(%s): rc=%s\n", dev_name(device),wave_out_error(rc)); } rc=waveOutClose(wout); ok(rc==MMSYSERR_NOERROR,"waveOutClose(%s): rc=%s\n", dev_name(device),wave_out_error(rc)); } else trace("Unable to play back the recorded sound\n"); } HeapFree(GetProcessHeap(), 0, frag.lpData); CloseHandle(hevent); }
static bool tree_read(struct view *view, struct buffer *buf) { struct tree_state *state = view->private; struct tree_entry *data; struct line *entry, *line; enum line_type type; char *path; size_t size; if (state->read_date || !buf) return tree_read_date(view, buf, state); if (buf->size <= SIZEOF_TREE_ATTR) return FALSE; if (view->lines == 0 && !tree_entry(view, LINE_HEADER, view->env->directory, NULL, NULL, 0)) return FALSE; size = parse_size(buf->data + SIZEOF_TREE_ATTR); path = strchr(buf->data + SIZEOF_TREE_ATTR, '\t'); if (!path) return FALSE; path++; /* Strip the path part ... */ if (*view->env->directory) { size_t pathlen = strlen(path); size_t striplen = strlen(view->env->directory); if (pathlen > striplen) memmove(path, path + striplen, pathlen - striplen + 1); /* Insert "link" to parent directory. */ if (view->lines == 1 && !tree_entry(view, LINE_DIRECTORY, "..", "040000", view->ref, 0)) return FALSE; } type = buf->data[SIZEOF_TREE_MODE] == 't' ? LINE_DIRECTORY : LINE_FILE; entry = tree_entry(view, type, path, buf->data, buf->data + TREE_ID_OFFSET, size); if (!entry) return FALSE; data = entry->data; view_column_info_update(view, entry); /* Skip "Directory ..." and ".." line. */ for (line = &view->line[1 + !!*view->env->directory]; line < entry; line++) { if (tree_compare_entry(line, entry) <= 0) continue; memmove(line + 1, line, (entry - line) * sizeof(*entry)); line->data = data; line->type = type; line->dirty = line->cleareol = 1; for (line++; line <= entry; line++) { line->dirty = line->cleareol = 1; line->lineno++; } return TRUE; } /* Move the current line to the first tree entry. */ if (!check_position(&view->prev_pos) && !check_position(&view->pos)) goto_view_line(view, 0, 1); return TRUE; }
static void process_char(char ch, int fd) { switch(state) { case StartLine: if (ch == '"') { state = InTime; } else { buffer[buffer_full++] = ch; position++; } break; case InTime: if (ch == '"') { state = InFields; } buffer[buffer_full++] = ch; position++; break; case InFields: if (ch == '"') { buffer[buffer_full++] = '\n'; check_position(fd); state = InMessage; buffer[buffer_full++] = '\t'; position = 0; line_tabbed = 1; } else { buffer[buffer_full++] = ch; position++; } break; case InMessage: if (ch == '\\') { state = Backslash; } else if (ch == '\n') { // Newline never forces a folding break, and position is 0 afterward. buffer[buffer_full++] = '\n'; position = 0; line_tabbed = 0; } else if (ch == '"') { // Unescaped End of the message state = indent ? StartLine : InMessage; position = 0; line_tabbed = 0; } else { // Ordinary characters. check_position(fd); buffer[buffer_full++] = ch; position++; } break; case Backslash: if (ch == '\\') { check_position(fd); buffer[buffer_full++] = '\\'; position++; } else if (ch == 'n') { // Insert newline. buffer[buffer_full++] = '\n'; // Indent the continuation line if it was requested. if (indent) { if (buffer_full == BUFFER_SIZE) { flush_buffer(fd); } buffer[buffer_full++] = '\t'; // Set the position to account for the tab. position = 8; line_tabbed = 1; } else { position = 0; } } else if (ch != 'r') { // Other backslash escapes are output as such. check_position(fd); buffer[buffer_full++] = '\\'; position++; if (buffer_full == BUFFER_SIZE) { flush_buffer(fd); } check_position(fd); buffer[buffer_full++] = ch; position++; } state = InMessage; break; } if (buffer_full == BUFFER_SIZE) flush_buffer(fd); }