/*!**************************************************************************************
 @Function	 	main
 @Return		void
 @Description 		Main function invoked after Application launch.
******************************************************************************************/
int main(void)
{
	int n=-1;
	pthread_t thread1;
	pthread_t thread2;

	/* Ensure the contents are erased and file is created if doesn't exist*/
	FILE *fd_instance = fopen( INSTANCEID_FIFO_NAME, "w");
	fprintf(fd_instance,"%d",-1);
	fclose(fd_instance);

	printf("Initializing egl..\n\n");
	if( 0 == initApplication())
	{
		printf("EGL init failed");
		return 0;
	}
	initView();

	/* Launch user and pipe control threads */
	n = pthread_create(&thread1, NULL, pipe_ctrl_thread, NULL);
	n = pthread_create(&thread2, NULL, user_ctrl_thread, NULL);

	while(1)
	{
		if(id != -1)
			setup_channel();

		/* If any of the bc_cat devices are alive render */
		if( (dev_fd0 != -1) || (dev_fd1 != -1) || (dev_fd2 != -1)  || (dev_fd3 != -1) )
		{
			render_thread(dev_fd0,0);
			render_thread(dev_fd1,1);
			render_thread(dev_fd2,2);
			render_thread(dev_fd3,3);

			/* eglswapbuffers must be called only after all active devices have finished rendering
			   inorder to avoid any artifacts due to incomplete/partial frame updates*/
			eglSwapBuffers(dpy, surface);
		}
		else
		{
			sleep(2);
		}
		
	}
	return 0;
}
Example #2
0
File: core.cpp Project: jeaye/clam
  void core::run()
  {
    std::thread accept_thread(std::bind(&core::accept, this));
    std::thread render_thread(std::bind(&core::render_impl, this));
    try
    {
      while(m_running)
      {
        while(generic_pool_t::global().poll()) ;

        m_reader(m_workers);
        m_pinger(m_workers);
        m_stat_collector(m_workers);

        render();
        std::this_thread::sleep_for(std::chrono::milliseconds(100));
      }
    }
    catch(std::exception const &e)
    {
      log_system("core exception: %%", e.what());
      m_running = false;

      /* Wake up the render thread. */
      render();
      accept_thread.detach();
      render_thread.join();
    }
    /* TODO: shared::thread for more RAII. */
    if(accept_thread.joinable())
    { accept_thread.detach(); }
    if(render_thread.joinable())
    { render_thread.join(); }
  }
// render image
extern "C" void render(uchar* output, uint2 imageExtent, uint3 volumeSize, float w, uint filterMethod, uint nrOfThreads)
{
	float3 volumeExtent = make_float3((float)volumeSize.x, (float)volumeSize.y, (float)volumeSize.z);
	params p = {output, imageExtent, volumeSize, volumeExtent, w, filterMethod, 0, imageExtent.y};

#ifdef _NO_MULTITHREADING
	render_thread(&p);
#else
	HANDLE* hndls = new HANDLE[nrOfThreads];
	params* prms = new params[nrOfThreads];

	for (uint thread = 0; thread < nrOfThreads; thread++)
	{
		prms[thread] = p;
		prms[thread].y_start = thread * imageExtent.y / nrOfThreads;
		prms[thread].y_end = (thread+1) * imageExtent.y / nrOfThreads;
		DWORD threadId = 0;
		hndls[thread] = CreateThread(NULL, 0, render_thread, &prms[thread], 0, &threadId);
	}

	WaitForMultipleObjects(nrOfThreads, hndls, TRUE, INFINITE);
	delete[] hndls;
	delete[] prms;
#endif
}
Example #4
0
int main(int argc, char **argv)
{
    logl("start");

    /* wayland init */
    window = wayland_init();
    pthread_t pid;
    pthread_create(&pid, NULL, display_dispatch_thread, NULL);

    render_thread(NULL);

    logl("end");

    return 0;
}
void StateBasedGame::run_threaded()
{
	window.setActive(false);
	
	std::thread render_thread(
		[this]()
		{	
			sf::Clock dtimer;

			sf::Font font;
			font.loadFromFile("sansation.ttf");
			sf::Text text;
			text.setFont(font);
			text.setCharacterSize(24);
			text.setColor(sf::Color::Cyan);

			window.setActive(true);

			window.setVerticalSyncEnabled(winState.vSync);

			while (window.isOpen())
			{
				// Store the time elapsed since the last frame began
				const float currentTime = dtimer.restart().asSeconds();
				window.clear();
				render(window, 0.0f);

#ifdef DEBUG
				window.setView(window.getDefaultView());
				text.setString(static_cast<std::ostringstream*>( &(std::ostringstream() << (1/currentTime) ) )->str());
				window.draw(text);
#endif //DEBUG

				window.display();
			}
		}
	);

	std::thread udpate_thread(
		[this]()
		{
			sf::Clock dtimer;

			const float fps = 120;
			const float dt = 1 / fps;
			float accumulator = 0;

			while (window.isOpen())
			{
				// Store the time elapsed since the last frame began
				const float currentTime = dtimer.restart().asSeconds();
				accumulator += currentTime;

				// Avoid spiral of death and clamp dt, thus clamping
				// how many times the update can be called in
				// a single game loop.
				if(accumulator > 0.2f)
				{
					accumulator = 0.2f;
				}

				while(accumulator > dt)
				{
					window.setTitle(static_cast<std::ostringstream*>( &(std::ostringstream() << (1.f/accumulator) ) )->str());
					update(window, dt);
					accumulator -= dt;
				}

				const float alpha = accumulator / dt;
			}
		}
	);

	while(window.isOpen())
	{
		handleEvents(window);
	}

	udpate_thread.join();
	render_thread.join();
}