Example #1
0
WiimoteManager::WiimoteManager() :
    m_quit(false),
    m_cwii(1),
    m_reload_wiimotes(false),
    m_smoothed_gravity(0.0f, 1.0f, 0.0f),
    m_pitch(),
    m_yaw(),
    m_roll(),
    m_accumulated(0.0f, 0.0f, 0.0f),
    m_gyro_pitch(0.0f),
    m_gyro_yaw(0.0f),
    m_gyro_roll(0.0f),
    m_gyro_orientation(1.0f, 0.0f, 0.0f, 0.0f),
    m_accel_pitch(0.0f),
    m_accel_roll(0.0f),
    m_accel_orientation(1.0f, 0.0f, 0.0f, 0.0f),
    m_orientation(),
    m_thread(),
    m_mutex()
{
    std::vector<CWiimote>& m_wiimotes = m_cwii.FindAndConnect();
    if (!m_wiimotes.size())
    {
        throw std::runtime_error("No wiimotes found.");
    }
    else
    {
        for(auto& wm : m_wiimotes)
        {
            wm.SetLEDs(CWiimote::LED_1);
            //wm.IR.SetMode(CIR::ON);
            wm.SetMotionSensingMode(CWiimote::ON);
            //wm.EnableMotionPlus(CWiimote::ON);
        }

        m_thread = std::thread([this] {
            using clock = std::chrono::high_resolution_clock;

            clock::time_point t0 = clock::now();
            clock::time_point t1 = clock::now();

            while(!m_quit)
            {
                t1 = clock::now();
                float dt = std::chrono::duration_cast<chrono::microseconds>(t1 - t0).count() / 1000000.0f;
                t0 = t1;
                update(dt);

                while(m_cwii.Poll())
                {
                    dispatch_events();
                }
            }

            std::cout << ">>> Wiimote thread shutdown" << std::endl;
        });
    }
}
Example #2
0
/*** MAIN LOOP ***/
int main(int argc, char *argv[])
{
#if	DEBUG
	bmem = AvailMem( MEMF_PUBLIC );
#endif

	ParseArgs(&args, argc, argv);

	/* Look first if Jano isn't already running */
	if( find_janoed( &args ) ) cleanup(0, RETURN_OK);

	/* Some global initialization */
	init_searchtable();

	/* Optionnal libraries */
	AslBase      = (struct Library *)    OpenLibrary("asl.library",     36);
	LocaleBase   = (struct LocaleBase *) OpenLibrary("locale.library",  38);
	DiskfontBase = (struct Library *)    OpenLibrary("diskfont.library", 0);
	IFFParseBase = (struct Library *)    OpenLibrary("iffparse.library",36);

	if(LocaleBase) InitLocale();    /* Localize the prog */

	/* Open the required ROM libraries */
	if( (IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 36)) &&
	    (GfxBase       = (struct GfxBase *)       OpenLibrary("graphics.library",  36)) &&
	    (GadToolsBase  = (struct Library *)       OpenLibrary("gadtools.library",  36)) &&
	    (KeymapBase    = (struct Library *)       OpenLibrary("keymap.library",    36)) &&
		 (UtilityBase   = (struct UtilityBase *)   OpenLibrary("utility.library",   36)) )
	{
		init_macros();
		set_default_prefs(&prefs, IntuitionBase->ActiveScreen);
		
		load_prefs(&prefs, NULL);     /* See if it exists a config file */
		sigport = create_port();

		/* Create whether an empty project or an existing one */
		if( ( edit = create_projects(NULL, args.sa_ArgLst, args.sa_NbArgs) ) )
		{
			/* Open the main interface */
			if(setup() == 0)
			{
				/* Makes edit project visible */
				reshape_panel(edit);
				active_project(edit,TRUE);
				clear_brcorner();

				dispatch_events();

			} else cleanup(ErrMsg(ERR_NOGUI), RETURN_FAIL);
		}
	} else cleanup(ErrMsg(ERR_BADOS), RETURN_FAIL);

	/* Hope that all were well... */
	cleanup(0, RETURN_OK);
	
	return 0;
}
Example #3
0
void test_daemon::replication_thread_proc()
{
	fprintf(stdout, "th_repl started\n");

	while (dispatch())
	{
		try
		{
			dispatch_events();
		}
		catch (const std::exception& e)
		{
			fprintf(stderr, "catch exception: %s\n", e.what());
			sleep(1);
		}
	}

	fprintf(stdout, "th_repl finished\n");
}
Example #4
0
struct result
app_run(struct app *app)
{
    sig_t previous_sigwinch_handler = signal(SIGWINCH, terminal_window_did_change);
    if (SIG_ERR == previous_sigwinch_handler) {
        return result_system_error();
    }
    
    struct result result = result_success();
    
    for (int i = 0; i < app->views_count; ++i) {
        result = app->views[i]->create(app->views[i], app);
        if (!result_is_success(result)) break;
    }
    
    if (result_is_success(result)) {
        for (int i = 0; i < app->views_count; ++i) {
            result = app->views[i]->draw(app->views[i], app);
            if (!result_is_success(result)) break;
            wnoutrefresh(app->views[i]->window);
        }
    }
    
    if (!app->active_view) {
        int i = app->views_count - 1;
        result = app_activate_view(app, app->views[i]);
    }
    
    doupdate();
    
    if (result_is_success(result)) {
        result = dispatch_events(app);
    }
    
    for (int i = app->views_count - 1; i >= 0; --i) {
        app->views[i]->destroy(app->views[i], app);
    }
    
    signal(SIGWINCH, previous_sigwinch_handler);
    return result;
}