void update_shapes(void){ /* Select the random shape */ int r = rand()%4; /* Get random values */ vec2 randoms = random_ints(); GLfloat x_r = randoms.x; GLfloat y_r = randoms.y; /* Update coordinates holded shape */ hold_shape->x_origin = ROBOT_X_ORIGIN + x_r; hold_shape->y_origin = ROBOT_Y_ORIGIN + y_r; hold_shape->update = update_shape; /* Get new random values */ randoms = random_ints(); x_r = randoms.x; y_r = randoms.y; /* Update hold shape */ hold_shape = shapes[r][0].model; hold_shape->update = update_holded; /* Update true shape */ true_shape = shapes[r][1].model; true_shape->x_origin = ROBOT_X_ORIGIN + x_r; true_shape->y_origin = ROBOT_Y_ORIGIN + y_r; /* Update colors */ update_colors(); }
Model* new_shape(int i){ /* Create random ints */ vec2 randoms = random_ints(); int x_r = randoms.x; int y_r = randoms.y; /* Parse the shape files to models */ Parser parser(shape_files[i]); Model* m1 = parser.parse_to_model(RED, ROBOT_X_ORIGIN+x_r, ROBOT_Y_ORIGIN+y_r, ROBOT_Z_ORIGIN, update_shape); m1->size_c = shape_sizes[i]; return m1; }
float time_random_sort(int n, int repititions) { // Return time in seconds it takes to mergesort a random array of // given size, averaged over the given number of repititions. float seconds = 0.0; int reps; if (n > MAXSIZE) { printf(" ERROR in time_random_sort : %i is too big.\n", n); return(-1.0); } for (reps=0; reps < repititions; reps++) { random_ints(n, list); reset_timer(); mergesort(n, list, scratch); seconds += elapsed_time(); } return seconds/repititions; }
int main(void) { int *s,*d; char msg[255]; unsigned int fselect; Stopwatch sw; void (*transfuncs[2])(int *, int *, int) = {transpose, transpose_O}; printf(" Choose transpose (0=original, 1=optimized)\n"); scanf("%d",&fselect); if (fselect > 1 ) { puts("Invalid transpose function"); return(-1); } // initialize data` s = random_ints(((TEST_DIM) * (TEST_DIM)), RANDOM_M_SEED, 4); d = (int *)malloc(sizeof(int) * ((TEST_DIM) * (TEST_DIM))); sw = new_stopwatch(); if (d == NULL || s == NULL || sw == NULL) return -1; // performance test given transpose stopwatch_start(sw); transfuncs[fselect](d,s,TEST_DIM); stopwatch_stop(sw); snprintf(msg, 255, "%s transform: %li ms\n", (fselect) ? "Optimized" : "Original", stopwatch_milliseconds(sw)); puts(msg); // superfluous memory deallocation activities free(s); free(d); destroy_stopwatch(sw); return 0; }
static bool test_int(const char *version_string) { GLint loc; bool pass = true; int values[4]; int got[ARRAY_SIZE(values)]; GLuint prog; static const char subtest_name[] = "integer scalar and vectors"; const char *const shader_strings[] = { version_string, int_code, common_body }; BUILD_SHADER(version_string == NULL); /* Try int */ random_ints(values, ARRAY_SIZE(values)); loc = glGetUniformLocation(prog, "v1"); glProgramUniform1i(prog, loc, values[0]); pass = piglit_check_gl_error(0) && pass; glGetUniformiv(prog, loc, got); pass = piglit_check_gl_error(0) && pass; pass = check_int_values(values, got, 1) && pass; random_ints(values, ARRAY_SIZE(values)); glProgramUniform1iv(prog, loc, 1, values); pass = piglit_check_gl_error(0) && pass; glGetUniformiv(prog, loc, got); pass = piglit_check_gl_error(0) && pass; pass = check_int_values(values, got, 1) && pass; /* Try ivec2 */ random_ints(values, ARRAY_SIZE(values)); loc = glGetUniformLocation(prog, "v2"); glProgramUniform2i(prog, loc, values[0], values[1]); pass = piglit_check_gl_error(0) && pass; glGetUniformiv(prog, loc, got); pass = piglit_check_gl_error(0) && pass; pass = check_int_values(values, got, 2) && pass; random_ints(values, ARRAY_SIZE(values)); glProgramUniform2iv(prog, loc, 1, values); pass = piglit_check_gl_error(0) && pass; glGetUniformiv(prog, loc, got); pass = piglit_check_gl_error(0) && pass; pass = check_int_values(values, got, 2) && pass; /* Try ivec3 */ random_ints(values, ARRAY_SIZE(values)); loc = glGetUniformLocation(prog, "v3"); glProgramUniform3i(prog, loc, values[0], values[1], values[2]); pass = piglit_check_gl_error(0) && pass; glGetUniformiv(prog, loc, got); pass = piglit_check_gl_error(0) && pass; pass = check_int_values(values, got, 3) && pass; random_ints(values, ARRAY_SIZE(values)); glProgramUniform3iv(prog, loc, 1, values); pass = piglit_check_gl_error(0) && pass; glGetUniformiv(prog, loc, got); pass = piglit_check_gl_error(0) && pass; pass = check_int_values(values, got, 3) && pass; /* Try ivec4 */ random_ints(values, ARRAY_SIZE(values)); loc = glGetUniformLocation(prog, "v4"); glProgramUniform4i(prog, loc, values[0], values[1], values[2], values[3]); pass = piglit_check_gl_error(0) && pass; glGetUniformiv(prog, loc, got); pass = piglit_check_gl_error(0) && pass; pass = check_int_values(values, got, 4) && pass; random_ints(values, ARRAY_SIZE(values)); glProgramUniform4iv(prog, loc, 1, values); pass = piglit_check_gl_error(0) && pass; glGetUniformiv(prog, loc, got); pass = piglit_check_gl_error(0) && pass; pass = check_int_values(values, got, 4) && pass; piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL, subtest_name); glDeleteProgram(prog); return pass; }
static void random_uints(unsigned int *v, unsigned count) { random_ints((int *) v, count); }