Пример #1
0
	//-------------------------------------------------------------------------------
	void GameApp::updateFrame()
	{	
		//processSystemEvents();
		updateSimulation();
		updateDisplay();		
		updateFPS();

		ProfileSystem::getInstance()->clearFrameData();
	}
Пример #2
0
void display()
{
    static double gflops = 0;
    static double ifps = 0;
    static double interactionsPerSecond = 0;

    // update the simulation
    if (!bPause)
    {
        if (cycleDemo && (sdkGetTimerValue(&demoTimer) > demoTime))
        {
            activeDemo = (activeDemo + 1) % numDemos;
            selectDemo(activeDemo);
        }

        updateSimulation();

        if (!useCpu)
        {
            cudaEventRecord(hostMemSyncEvent, 0);    // insert an event to wait on before rendering
        }
    }

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    if (displayEnabled)
    {
        // view transform
        {
            glMatrixMode(GL_MODELVIEW);
            glLoadIdentity();

            for (int c = 0; c < 3; ++c)
            {
                camera_trans_lag[c] += (camera_trans[c] - camera_trans_lag[c]) * inertia;
                camera_rot_lag[c] += (camera_rot[c] - camera_rot_lag[c]) * inertia;
            }

            glTranslatef(camera_trans_lag[0], camera_trans_lag[1], camera_trans_lag[2]);
            glRotatef(camera_rot_lag[0], 1.0, 0.0, 0.0);
            glRotatef(camera_rot_lag[1], 0.0, 1.0, 0.0);
        }

        displayNBodySystem();

        // display user interface
        if (bShowSliders)
        {
            glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); // invert color
            glEnable(GL_BLEND);
            paramlist->Render(0, 0);
            glDisable(GL_BLEND);
        }

        if (bFullscreen)
        {
            beginWinCoords();
            char msg0[256], msg1[256], msg2[256];

            if (bDispInteractions)
            {
                sprintf(msg1, "%0.2f billion interactions per second", interactionsPerSecond);
            }
            else
            {
                sprintf(msg1, "%0.2f GFLOP/s", gflops);
            }

            sprintf(msg0, "%s", deviceName);
            sprintf(msg2, "%0.2f FPS [%s | %d bodies]",
                    ifps, fp64 ? "double precision" : "single precision", numBodies);

            glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); // invert color
            glEnable(GL_BLEND);
            glColor3f(0.46f, 0.73f, 0.0f);
            glPrint(80, glutGet(GLUT_WINDOW_HEIGHT) - 122, msg0, GLUT_BITMAP_TIMES_ROMAN_24);
            glColor3f(1.0f, 1.0f, 1.0f);
            glPrint(80, glutGet(GLUT_WINDOW_HEIGHT) - 96, msg2, GLUT_BITMAP_TIMES_ROMAN_24);
            glColor3f(1.0f, 1.0f, 1.0f);
            glPrint(80, glutGet(GLUT_WINDOW_HEIGHT) - 70, msg1, GLUT_BITMAP_TIMES_ROMAN_24);
            glDisable(GL_BLEND);

            endWinCoords();
        }

        glutSwapBuffers();
    }

    fpsCount++;

    // this displays the frame rate updated every second (independent of frame rate)
    if (fpsCount >= fpsLimit)
    {
        char fps[256];

        float milliseconds = 1;

        // stop timer
        if (useCpu)
        {
            milliseconds = sdkGetTimerValue(&timer);
            sdkResetTimer(&timer);
        }
        else
        {
            checkCudaErrors(cudaEventRecord(stopEvent, 0));
            checkCudaErrors(cudaEventSynchronize(stopEvent));
            checkCudaErrors(cudaEventElapsedTime(&milliseconds, startEvent, stopEvent));
        }

        milliseconds /= (float)fpsCount;
        computePerfStats(interactionsPerSecond, gflops, milliseconds, 1);

        ifps = 1.f / (milliseconds / 1000.f);
        sprintf(fps,
                "CUDA N-Body (%d bodies): "
                "%0.1f fps | %0.1f BIPS | %0.1f GFLOP/s | %s",
                numBodies, ifps, interactionsPerSecond, gflops,
                fp64 ? "double precision" : "single precision");

        glutSetWindowTitle(fps);
        fpsCount = 0;
        fpsLimit = (ifps > 1.f) ? (int)ifps : 1;

        if (bPause)
        {
            fpsLimit = 0;
        }

        // restart timer
        if (!useCpu)
        {
            checkCudaErrors(cudaEventRecord(startEvent, 0));
        }
    }

    glutReportErrors();
}
Пример #3
0
// based on http://www.willusher.io/sdl2%20tutorials/2013/08/17/lesson-1-hello-world/
int main( int argc, char* args[] )
{
	if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
	{
		std::cout << "SDL_Init Error: " << SDL_GetError() << std::endl;
		cleanExit(1);
	}
	std::cout << "SDL initialised OK!\n";

	// Initialise the audio mixer and also explained the variables.
	// 44100 - Common hertz level for these things
	// MIX_DEFAULT_FORMAT - Like the SDL_INIT_EVERYTHING, some init settings
	// 2 - Audio Channels for stereo play
	// 2048 - Sample size, can affect lag time for effect to play
	// != 0 - Same as other init stuff, not sure why, just needs it.
	if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) != 0)
	{
		std::cout << "SDL_Mixer init error: " << Mix_GetError() << std::endl;
		cleanExit(1);
	}
	std::cout << "SDP_Mixer Initialised OK!" << std::endl;
	//create window
	win = SDL_CreateWindow("SDL Hello World!", 100, 100, screenW, screenH, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);

	//error handling
	if (win == nullptr)	
	{
		std::cout << "SDL_CreateWindow Error: " << SDL_GetError() << std::endl;
		cleanExit(1);
	}
	std::cout << "SDL CreatedWindow OK!\n";

	ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
	if (ren == nullptr)
	{
		std::cout << "SDL_CreateRenderer Error: " << SDL_GetError() << std::endl;
		cleanExit(1);
	}

	player = new sprite("./assets/spritesheet.png", 50.0f, 520.0f, 24.0f, 32.0f, ren);
	player->srcRect.x = 0.0f;
	player->srcRect.y = 96.0f;
	player->srcRect.w = 24.0f;
	player->srcRect.h = 32.0f;
	player->playerScore = 0;
	player->bufferMax = 5;

#pragma region Hens
	hen1 = new enemy("./assets/spritesheet.png", 500, 100, 24, 40, ren);
	hens.push_back(hen1);
	hen1->state = enemy::moveRight;
	hen1->flipDirection = true;
	hen1->xTarget1 = 200.0f;
	hen1->xTarget2 = 250.0f;
	hen1->srcRect.x = 0.0f;
	hen1->srcRect.y = 0.0f;
	hen1->srcRect.w = 24.0f;
	hen1->srcRect.h = 40.0f;

	hen2 = new enemy("./assets/spritesheet.png", 700, 530, 24, 40, ren);
	hens.push_back(hen2);
	hen2->state = enemy::moveLeft;
	hen2->xTarget1 = 100.0f;
	hen2->xTarget2 = 750.0f;
	hen2->srcRect.x = 0.0f;
	hen2->srcRect.y = 0.0f;
	hen2->srcRect.w = 24.0f;
	hen2->srcRect.h = 40.0f;

	hen3 = new enemy("./assets/spritesheet.png", 600, 280, 24, 40, ren);
	hens.push_back(hen3);
	hen3->state = enemy::moveRight;
	hen3->xTarget1 = 100.0f;
	hen3->xTarget2 = 750.0f;
	hen3->srcRect.x = 0.0f;
	hen3->srcRect.y = 0.0f;
	hen3->srcRect.w = 24.0f;
	hen3->srcRect.h = 40.0f;
#pragma endregion

#pragma region Audio stuff
	// This is formatted in the same way to the default code from John as it makes sense and I want to stick to it.
	jumpEffect = Mix_LoadWAV("./assets/jump.wav");
	if (jumpEffect == nullptr)
	{
		std::cout << "Mix_LoadWAV Error: " << Mix_GetError() << std::endl;
		cleanExit(1);
	}

	pickup1 = Mix_LoadWAV("./assets/pickup1.wav");
	if (pickup1 == nullptr)
	{
		std::cout << "Mix_LoadWAV Error: " << Mix_GetError() << std::endl;
		cleanExit(1);
	}

	pickup2 = Mix_LoadWAV("./assets/pickup2.wav");
	if (pickup2 == nullptr)
	{
		std::cout << "Mix_LoadWAV Error: " << Mix_GetError() << std::endl;
		cleanExit(1);
	}

	background = Mix_LoadMUS("./assets/background_music.wav");
	if (background == nullptr)
	{
		std::cout << "Mix_LoadWAV Error: " << Mix_GetError() << std::endl;
		cleanExit(1);
	}
#pragma endregion


	if( TTF_Init() == -1 )
	{
		std::cout << "TTF_Init Failed: " << TTF_GetError() << std::endl;
		cleanExit(1);
	}

	TTF_Font* sans = TTF_OpenFont("./assets/Hack-Regular.ttf", 96);
	if (sans == nullptr)
	{
		std::cout << "TTF_OpenFont Error: " << TTF_GetError() << std::endl;
		cleanExit(1);
	}
	SDL_Color White = { 255, 255, 255 };
	SDL_Color Purple = { 165, 0, 220 };
	
	std::string lives = "Lives: " + std::to_string(player->playerLives);
	const char* lifeCounts = lives.c_str();

	loading = new text(ren, "Loading...", 200, 200, 400, 130, sans, White);
	Load();

	scoreCount = new text(ren, player->playerScore, 0, 0, 180, 60, sans, Purple);
	lifeCount = new text(ren, lifeCounts, 600, 0, 180, 60, sans, Purple);

	drawTileMap();

	loading->isShowing = false;
	Mix_PlayMusic(background, -1);

	while (!done) //loop until done flag is set)
	{
		handleInput(); // this should ONLY SET VARIABLES

		updateSimulation(); // this should ONLY SET VARIABLES according to simulation

		render(); // this should render the world state according to VARIABLES

		SDL_Delay(20); // unless vsync is on??
	}

	cleanExit(0);
	return 0;
}
DMMainWindow::DMMainWindow(QWidget * parent) : QMainWindow(parent), ui(new Ui::DMMainWindow)
{
	// qt init
	Q_INIT_RESOURCE(icons);
	ui->setupUi(this);
	this->setParent(parent);

	// logger init
	log_updater = new GuiLogSink();
	connect(log_updater, SIGNAL(newLogLine(QString)), SLOT(newLogLine(QString)), Qt::QueuedConnection);
#if defined DEBUG || _DEBUG
	DM::Log::init(log_updater,DM::Debug);
#else
	DM::Log::init(log_updater,DM::Standard);
#endif
	// add log export to file
	QString logfilepath = QDir::tempPath() + "/dynamind" 
		+ QDateTime::currentDateTime().toString("_yyMMdd_hhmmss_zzz")+".log";
	if(QFile::exists(logfilepath))
		QFile::remove(logfilepath);

	outputFile = new ofstream(logfilepath.toStdString().c_str());
	DM::Log::addLogSink(new DM::OStreamLogSink(*outputFile));
	DM::Logger() << "logfile: " << logfilepath;

	// init python env
	DM::PythonEnv *env = DM::PythonEnv::getInstance();
	env->addPythonPath(QApplication::applicationDirPath().toStdString());
	env->addOverWriteStdCout();

	// init simulation, we only use one instance
	this->simulation = new GUISimulation(parent, ui->tabWidget_4);
	simulationThread = NULL;
	simulationThreadWrapper = NULL;

	this->simulation->registerModulesFromDefaultLocation();
	this->simulation->registerModulesFromSettings();
	createModuleListView();

	connect( ui->actionRun, SIGNAL( triggered() ), this, SLOT( runSimulation() ), Qt::DirectConnection );
	connect( ui->actionPreferences, SIGNAL ( triggered() ), this, SLOT(preferences() ), Qt::DirectConnection );
	connect(ui->actionSave, SIGNAL(triggered()), this , SLOT(saveSimulation()), Qt::DirectConnection);
	connect(ui->actionSaveAs, SIGNAL(triggered()), this , SLOT(saveAsSimulation()), Qt::DirectConnection);
	connect(ui->actionOpen, SIGNAL(triggered()), this , SLOT(loadSimulation()), Qt::DirectConnection);
	connect(ui->actionNew, SIGNAL(triggered()), this , SLOT(clearSimulation()), Qt::DirectConnection);
	connect(ui->actionReload_Modules, SIGNAL(triggered()), this , SLOT(ReloadModules()), Qt::DirectConnection);
	connect(ui->actionUpdate, SIGNAL(triggered()), this , SLOT(updateSimulation()), Qt::DirectConnection);
	connect(ui->actionReset, SIGNAL(triggered()), this , SLOT(resetSimulation()), Qt::DirectConnection);
	connect(ui->actionCancel, SIGNAL(triggered()), this, SLOT(cancelSimulation()), Qt::DirectConnection);
	connect(ui->actionCancel, SIGNAL(triggered()), this, SLOT(cancelSimulation()), Qt::DirectConnection);
	connect(ui->actionShow_Help, SIGNAL(triggered()), this, SLOT(showHelp()), Qt::DirectConnection);

	QStringList args = QCoreApplication::arguments();
	if (args.size() == 2) {
		this->clearSimulation();
		this->getSimulation()->currentDocument = args[1];
		simulation->loadSimulation(args[1].toStdString());
	}

	ui->actionCancel->setEnabled(false);

	// load from qsettings
	QSettings settings;
	DM::DBConnectorConfig cfg = DM::DBConnector::getInstance()->getConfig();
	qulonglong v = settings.value("cacheBlockwritingSize", -1).toULongLong();
	if (v != (qulonglong)-1)
		cfg.cacheBlockwritingSize = v;

	v = settings.value("queryStackSize", -1).toULongLong();
	if (v != (qulonglong)-1)
		cfg.queryStackSize = v;

	int i = settings.value("peterDatastream", -1).toInt();
	if (i != -1)
		cfg.peterDatastream = (bool)i;
}