Beispiel #1
0
int main(int argc, char *argv[])
{
#ifdef PARSEC_VERSION
#define __PARSEC_STRING(x) #x
#define __PARSEC_XSTRING(x) __PARSEC_STRING(x)
        std::cout << "PARSEC Benchmark Suite Version "__PARSEC_XSTRING(PARSEC_VERSION) << std::endl << std::flush;
#else
        std::cout << "PARSEC Benchmark Suite" << std::endl << std::flush;
#endif //PARSEC_VERSION
#ifdef ENABLE_PARSEC_HOOKS
  __parsec_bench_begin(__parsec_fluidanimate);
#endif

  if(argc < 4 || argc >= 6)
  {
    std::cout << "Usage: " << argv[0] << " <threadnum> <framenum> <.fluid input file> [.fluid output file]" << std::endl;
    return -1;
  }

  int threadnum = atoi(argv[1]);
  int framenum = atoi(argv[2]);

  //Check arguments
  if(threadnum != 1) {
    std::cerr << "<threadnum> must be 1 (serial version)" << std::endl;
    return -1;
  }
  if(framenum < 1) {
    std::cerr << "<framenum> must at least be 1" << std::endl;
    return -1;
  }

#ifdef ENABLE_CFL_CHECK
  std::cout << "WARNING: Check for Courant–Friedrichs–Lewy condition enabled. Do not use for performance measurements." << std::endl;
#endif

  InitSim(argv[3]);
#ifdef ENABLE_VISUALIZATION
  InitVisualizationMode(&argc, argv, &AdvanceFrame, &numCells, &cells, &cnumPars);
#endif

#ifndef ENABLE_VISUALIZATION

//core of benchmark program (the Region-of-Interest)
#ifdef ENABLE_PARSEC_HOOKS
  __parsec_roi_begin();
#endif
  for(int i = 0; i < framenum; ++i) {
    AdvanceFrame();
  }
#ifdef ENABLE_PARSEC_HOOKS
  __parsec_roi_end();
#endif

#else //ENABLE_VISUALIZATION
  Visualize();
#endif //ENABLE_VISUALIZATION

  if(argc > 4)
    SaveFile(argv[4]);
  CleanUpSim();

#ifdef ENABLE_PARSEC_HOOKS
  __parsec_bench_end();
#endif

  return 0;
}
Beispiel #2
0
int main(int argc, char* argv[])
{
	SDL_Init(SDL_INIT_EVERYTHING);

	SDL_Window *window = SDL_CreateWindow("Ritual", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, RES_X, RES_Y, 0);
	SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);

	int ww, hh;
	errorTextures[0] = ImgToTex(renderer, "assets/error1.png", ww, hh);
	errorTextures[1] = ImgToTex(renderer, "assets/error1.png", ww, hh);
	errorTextures[2] = ImgToTex(renderer, "assets/error2.png", ww, hh);
	errorTextures[3] = ImgToTex(renderer, "assets/error3.png", ww, hh);
	errorTextures[4] = ImgToTex(renderer, "assets/error4.png", ww, hh);
	errorTextures[5] = ImgToTex(renderer, "assets/error5.png", ww, hh);
	errorTextures[6] = ImgToTex(renderer, "assets/error6.png", ww, hh);
	errorTextures[7] = ImgToTex(renderer, "assets/error7.png", ww, hh);
	errorTextures[8] = ImgToTex(renderer, "assets/error8.png", ww, hh);
	helpTexture = ImgToTex(renderer, "assets/help.png", ww, hh);
	deathTexture = ImgToTex(renderer, "assets/gameover.png", ww, hh);

	bool quit = false;

	g_world = new World(renderer, "assets/map");
	g_scrub = new Scrub(renderer, g_world);
	//for (int i = 0; i < 5; i++)
	g_buttons[0] = new Button(renderer, "assets/tower3.png", 100, 100 + 0 * 110, 100, 100);
	g_buttons[1] = new Button(renderer, "assets/tower1_icon.png", 100, 100 + 1 * 110, 100, 100);
	g_buttons[2] = new Button(renderer, "assets/tower2_icon.png", 100, 100 + 2 * 110, 100, 100);
	g_buttons[3] = new Button(renderer, "assets/tower4_icon.png", 100, 100 + 3 * 110, 100, 100);

	g_playpause[0] = new Button(renderer, "assets/play.png", RES_X - 280, RES_Y - 200, 80, 80);
	g_playpause[1] = new Button(renderer, "assets/pause.png", RES_X - 180, RES_Y - 200, 80, 80);

	InitNav();
	InitSim();

	unsigned long long perfCnt = SDL_GetPerformanceCounter();
	unsigned long long perfFreq = SDL_GetPerformanceFrequency();
	nowTime = double(perfCnt) / double(perfFreq);

	SDL_Surface *winSurf = SDL_GetWindowSurface(window);

	bool win = false;

	for (;;) {

		double lastTime = nowTime;
		perfCnt = SDL_GetPerformanceCounter();
		perfFreq = SDL_GetPerformanceFrequency();
		nowTime = double(perfCnt) / double(perfFreq);
		double ddeltatime = nowTime - lastTime;
		ddeltatime = ddeltatime > 0.1 ? 0.1 : ddeltatime;

		SDL_Event event;
		while (SDL_PollEvent(&event)) {
			if (event.type == SDL_QUIT) {
				quit = 1;
				break;
			}
			if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE)
				quit = true;
			if (!isDead) {
				if (g_scrub->Event(event)) continue;
				bool eatenByButton = false;
				for (int i = 0; i < nButtons; i++) {
					bool hit = g_buttons[i]->Event(event);
					if (hit)
						selectedButton = i;
					eatenByButton |= hit;
				}
				if (eatenByButton)
					continue;
				if (g_playpause[0]->Event(event)) {
					isPlaying = true;
					continue;
				}
				if (g_playpause[1]->Event(event)) {
					isPlaying = false;
					continue;
				}
				if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_SPACE) {
					isPlaying = !isPlaying;
				}
				if (g_scrub->Event(event)) continue;
				if (!win) {
					if (g_world->Event(event, selectedButton)) continue;
				}
			}
		}
		if (quit)
			break;

		if (isPlaying) {
			float t0 = g_scrub->mTime;
			g_scrub->AdvanceTime(float(ddeltatime));
			float t1 = g_scrub->mTime;
			PlaySimulationSounds(t0, t1);
		}

		SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
		SDL_RenderClear(renderer);

		g_world->Draw(renderer);
		if (!g_scrub->mClaimedMouse)
			g_world->DrawMarker(renderer);
		g_scrub->Draw(renderer, selectedButton, float(nowTime));
		for (int i = 0; i < nButtons; i++)
			g_buttons[i]->Draw(renderer, i == selectedButton);
		g_playpause[0]->Draw(renderer, isPlaying);
		g_playpause[1]->Draw(renderer, !isPlaying);
#ifdef _DEBUG
		SimDebugDraw(renderer, g_scrub->mTime);
#endif

		if (win) {
			ShowErrorMessage(errWin);
			static bool firstWin = true;
			if (firstWin) {
				g_world->myAudioManager.PlaySound("assets/audio/win.mp3", false);
				firstWin = false;
			}

		}
		else {
			if (GetGameOverTime() / g_scrub->mTotalTime >= 1.0f)
				win = true;
		}

		DrawErrorMessage(renderer);
		DrawHelp(renderer);
		DrawDeath(renderer);

		SDL_RenderPresent(renderer);
	}

    return 0;
}