void RubikGame::gameLoop() { while(_gameState != GameState::EXIT) { frameSetUp(); processInput(); timeProgress(); updateCamera(); drawGame(); frameTearDown(); } }
int main() { // Compute image sample positions SampleGrid pixelGrid; BestCandidate2D(imageSamples, SAMPLE_TABLE_SIZE, &pixelGrid); // Compute time samples ProgressReporter timeProgress(SAMPLE_TABLE_SIZE, "Time samples"); //NOBOOK for (int i = 0; i < SAMPLE_TABLE_SIZE; ++i) timeSamples[i] = (i + RandomFloat()) / SAMPLE_TABLE_SIZE; for (int currentSample = 1; currentSample < SAMPLE_TABLE_SIZE; ++currentSample) { // Select best time sample for current image sample int best = -1; // Find best time relative to neighbors float maxMinDelta = 0.; for (int t = currentSample; t < SAMPLE_TABLE_SIZE; ++t) { // Compute min delta for this time int gu = GRID(imageSamples[currentSample][0]); int gv = GRID(imageSamples[currentSample][1]); float minDelta = INFINITY; for (int du = -1; du <= 1; ++du) { for (int dv = -1; dv <= 1; ++dv) { // Check offset from times of nearby samples // Compute (u,v) grid cell to check int u = gu + du, v = gv + dv; if (u < 0) u += BC_GRID_SIZE; if (u >= BC_GRID_SIZE) u -= BC_GRID_SIZE; if (v < 0) v += BC_GRID_SIZE; if (v >= BC_GRID_SIZE) v -= BC_GRID_SIZE; for (u_int g = 0; g < pixelGrid[u][v].size(); ++g) { int otherSample = pixelGrid[u][v][g]; if (otherSample < currentSample) { float dt = Wrapped1DDist(timeSamples[otherSample], timeSamples[t]); minDelta = min(minDelta, dt); } } } } // Update _best_ if this is best time so far if (minDelta > maxMinDelta) { maxMinDelta = minDelta; best = t; } } Assert(best != -1); // NOBOOK swap(timeSamples[best], timeSamples[currentSample]); timeProgress.Update(); //NOBOOK } timeProgress.Done();; // NOBOOK // Compute lens samples BestCandidate2D(lensSamples, SAMPLE_TABLE_SIZE); Redistribute2D(lensSamples, pixelGrid); // Write sample table to disk FILE *f = fopen("sampledata.cpp", "w"); if (f == NULL) { Severe("Couldn't open sampledata.cpp for writing."); } fprintf(f, "\n/* Automatically generated %dx%d sample " "table (%s @ %s) */\n\n", SQRT_SAMPLE_TABLE_SIZE, SQRT_SAMPLE_TABLE_SIZE, __DATE__, __TIME__); fprintf(f, "const float " "BestCandidateSampler::sampleTable[%d][5] = {\n", SAMPLE_TABLE_SIZE); for (int i = 0; i < SAMPLE_TABLE_SIZE; ++i) { fprintf(f, " { "); fprintf(f, "%10.10ff, %10.10ff, ", imageSamples[i][0], imageSamples[i][1]); fprintf(f, "%10.10ff, ", timeSamples[i]); fprintf(f, "%10.10ff, %10.10ff, ", lensSamples[i][0], lensSamples[i][1]); fprintf(f, "},\n"); } fprintf(f, "};\n"); return 0; }