int main(int argc, char *argv[]){ char c; time_t rawtime; struct tm *timeinfo; FILE *fp; c = getopt (argc, argv, "v"); switch (c) { case 'v': printf("Updatable version 4.0 extended\nDynamically updatable. Compatible from 1.4\n"); return 0; } sprintf(PROGRAM_NAME,"loop_d"); check_update_status(); container_2 *data; data=(container_2 *) malloc(sizeof(container_2)); if(up_var->updated_from==0){ data->num_executions=0; data->name=argv[1]; } if(up_var->updated_from<=1){ //Every if starts with the update_point function update_point(1,(void *)data); } while(1) { sleep(5); data->num_executions++; data=update_point(3,(void *)data); if(data==NULL) { return 0;} time (&rawtime); timeinfo = localtime (&rawtime); fp=fopen("version_record.txt","a"); fprintf(fp,"Version 4.0 .Executed on %s's device %d times on %s ",data->name,data->num_executions,asctime(timeinfo)); fclose(fp); } //free(data); return 0; }
int execute_move(int *move, int do_flag, int algo) { int next[2], i; //Make sure the move is valid if (move[0] < 0 || move[0] > 999 || move[1] < 0 || move[1] > 999) return -1; if (do_flag) { //Make sure stone can be placed if (abs(board[move[0]][move[1]]) == INF) return -1; //Place the stone if (next_to_set) board[move[0]][move[1]] = INF; else board[move[0]][move[1]] = -INF; } else { //Make sure stone can be removed if (abs(board[move[0]][move[1]]) != INF) return -1; //Restore its value board[move[0]][move[1]] = exact_pull(move); //is this necessary? } //Update the board for(i = 0; i < MAX_NUMBER_OF_POINTS; i++) { if (!next_point(next, i, 1)) break; //If we are not next_to_set subtract the pull update_point(next, next_to_set, move); } //Flip the player next_to_set = next_to_set > 0 ? 0 : 1; //Store the move, and adjust number of moves remaining i = MAX_NUMBER_OF_MOVES - NUM_MOVES_REMAINING; if (do_flag) { moves[i * 2] = move[0]; moves[(i * 2) + 1] = move[1]; NUM_MOVES_REMAINING--; } else { i = i - 1; moves[i * 2] = -1; moves[(i * 2) + 1] = -1; NUM_MOVES_REMAINING++; } return our_area(); }
void main_loop() { // the time of the previous frame double old_time = glfwGetTime(); // point that the mouse grabs Point *mouse_point = malloc(sizeof(Point)); // temporary int mouse_held = 0; // boolean // this just loops as long as the program runs while(1) { // calculate time elapsed double current_time = glfwGetTime(), delta_time = (current_time - old_time); old_time = current_time; // escape to quit, arrow keys to rotate view if (glfwGetKey(GLFW_KEY_ESC) == GLFW_PRESS) { break; } if (glfwGetKey(GLFW_KEY_LEFT) == GLFW_PRESS) { rotate_y += delta_time*30; } if (glfwGetKey(GLFW_KEY_RIGHT) == GLFW_PRESS) { rotate_y -= delta_time*30; } //randomly push the mesh in a random direction with SPACE if(glfwGetKey(GLFW_KEY_SPACE) == GLFW_PRESS) { int random_point = rand()%(NUM_POINTS-NUM_POINTS_X-1) + NUM_POINTS_X+1; Point *p = point_array[random_point]; p->x += rand()%10000 / 10000.0 - .5; p->y += rand()%10000 / 10000.0 - .5; p->z += rand()%10000 / 10000.0 - .5; } //update link constraints multiple times for(int q = 0; q < 3; q++) { for(int i = 0; i < NUM_LINKS; i++) { if(!link_array[i]->broken) { update_link(link_array[i]); } } } //update all points except top row (fixed points) for(int i = 0; i < NUM_POINTS; i++) { if(!point_array[i]->anchor) { update_point(point_array[i], delta_time); } } // clear the buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // draw the figure draw(link_array); // mouse stuffs update_mouse(&mouse_point, &mouse_held); // swap back and front buffers glfwSwapBuffers(); } }
int ScopePanel::cursor_motion_event() { if(is_dragging) { int x = get_cursor_x(); int y = get_cursor_y(); CLAMP(x, 0, get_w() - 1); CLAMP(y, 0, get_h() - 1); update_point(x, y); return 1; } return 0; }
int ScopePanel::button_press_event() { if(is_event_win() && cursor_inside()) { gui->clear_points(1); is_dragging = 1; int x = get_cursor_x(); int y = get_cursor_y(); CLAMP(x, 0, get_w() - 1); CLAMP(y, 0, get_h() - 1); update_point(x, y); return 1; } return 0; }
/* intercept mouse input */ void mouse_input(int button, int state, int x, int y) { if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { int point_found = update_point(x, SCREEN_HEIGHT - y); if (point_found) left_button_down = 1; if (!point_found && num_points < MAX_POINTS) { points[num_points].x = x; points[num_points].y = SCREEN_HEIGHT - y; current_point = num_points; num_points++; } } else if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) { remove_point(x, SCREEN_HEIGHT - y); } else if (button==GLUT_LEFT_BUTTON && state == GLUT_UP) { left_button_down = 0; } draw_screen(); }