예제 #1
0
void finalize()
{
    // Free allocated resources.
    if (_vertices) {
        free(_vertices);
        _vertices = NULL;
    }

    if (_indices) {
        free(_indices);
        _indices = NULL;
    }

    if (_textureCoords) {
        free(_textureCoords);
        _textureCoords = NULL;
    }

    // Destroy the font.
    bbutil_destroy_font(_font);

    // Stop requesting events from libscreen.
    SCREEN_API(screen_stop_events(_screen_ctx), "stop_events");

    // Shut down BPS library for this process.
    bps_shutdown();

    // Use utility code to terminate EGL setup.
    bbutil_terminate();

    // Destroy libscreen context.
    SCREEN_API(screen_destroy_context(_screen_ctx), "destroy_context");
}
예제 #2
0
static void fina(void *data)
{
  App *app = (App*)data;

  Game::Fina();

  if(app->mainFont)
    bbutil_destroy_font(app->mainFont);
}
예제 #3
0
int main(int argc, char **argv) {
    int rc;

    //Create a screen context that will be used to create an EGL surface to to receive libscreen events
    screen_create_context(&screen_cxt, 0);

    //Initialize BPS library
    bps_initialize();

    //Use utility code to initialize EGL for rendering with GL ES 1.1
    if (EXIT_SUCCESS != bbutil_init_egl(screen_cxt)) {
        fprintf(stderr, "Unable to initialize EGL\n");
        screen_destroy_context(screen_cxt);
        return 0;
    }

    //Initialize app data
    if (EXIT_SUCCESS != init()) {
        fprintf(stderr, "Unable to initialize app logic\n");
        bbutil_terminate();
        screen_destroy_context(screen_cxt);
        return 0;
    }

    //Signal BPS library that navigator orientation is to be locked
    if (BPS_SUCCESS != navigator_rotation_lock(true)) {
        fprintf(stderr, "navigator_rotation_lock failed\n");
        bbutil_terminate();
        screen_destroy_context(screen_cxt);
        return 0;
    }

    //Signal BPS library that navigator and screen events will be requested
    if (BPS_SUCCESS != screen_request_events(screen_cxt)) {
        fprintf(stderr, "screen_request_events failed\n");
        bbutil_terminate();
        screen_destroy_context(screen_cxt);
        return 0;
    }

    if (BPS_SUCCESS != navigator_request_events(0)) {
        fprintf(stderr, "navigator_request_events failed\n");
        bbutil_terminate();
        screen_destroy_context(screen_cxt);
        return 0;
    }

    for (;;) {
        //Request and process BPS next available event
        bps_event_t *event = NULL;
        rc = bps_get_event(&event, 0);
        assert(rc == BPS_SUCCESS);

        if ((event) && (bps_event_get_domain(event) == navigator_get_domain())
                && (NAVIGATOR_EXIT == bps_event_get_code(event))) {
            break;
        }

        render();
    }

    //Stop requesting events from libscreen
    screen_stop_events(screen_cxt);

    //Shut down BPS library for this process
    bps_shutdown();

    //Destroy the font
    bbutil_destroy_font(font);

    //Use utility code to terminate EGL setup
    bbutil_terminate();

    //Destroy libscreen context
    screen_destroy_context(screen_cxt);
    return 0;
}
예제 #4
0
파일: bbmain.cpp 프로젝트: jwalkoski/Box2D
int main(int argc, char *argv[])
{
    int exit_application = 0;
    int rc;

    //Create a screen context that will be used to create an EGL surface to to receive libscreen events
    screen_create_context(&screen_cxt, 0);

    initGestures();

    //Initialize BPS library
	bps_initialize();

	//Use utility code to initialize EGL for 2D rendering with GL ES 1.1
	if (EXIT_SUCCESS != bbutil_init_egl(screen_cxt, GL_ES_1, AUTO))
	{
		fprintf(stderr, "bbutil_init_egl failed\n");
		bbutil_terminate();
		screen_destroy_context(screen_cxt);
		return 0;
	}

	//Initialize application logic
	if (EXIT_SUCCESS != initialize())
	{
		fprintf(stderr, "initialize failed\n");
		bbutil_terminate();
		screen_destroy_context(screen_cxt);
		return 0;
	}

	//Signal BPS library that navigator and screen events will be requested
	if (BPS_SUCCESS != screen_request_events(screen_cxt))
	{
		fprintf(stderr, "screen_request_events failed\n");
		bbutil_terminate();
		screen_destroy_context(screen_cxt);
		return 0;
	}

	if (BPS_SUCCESS != navigator_request_events(0))
	{
		fprintf(stderr, "navigator_request_events failed\n");
		bbutil_terminate();
		screen_destroy_context(screen_cxt);
		return 0;
	}

	//Signal BPS library that navigator orientation is not to be locked
	if (BPS_SUCCESS != navigator_rotation_lock(false))
	{
		fprintf(stderr, "navigator_rotation_lock failed\n");
		bbutil_terminate();
		screen_destroy_context(screen_cxt);
		return 0;
	}

	// set up our box2D tests
	fprintf(stderr, "Box2D Version %d.%d.%d\n", b2_version.major, b2_version.minor, b2_version.revision);

	testCount = 0;
	while (g_testEntries[testCount].createFcn != NULL)
	{
		++testCount;
	}

	testIndex = b2Clamp(testIndex, 0, testCount-1);
	testSelection = testIndex;

	entry = g_testEntries + testIndex;
	test = entry->createFcn();
	test->m_debugDraw.SetFont(font);
	test->m_debugDraw.SetScreenSize(width, height);

	struct timespec time_struct;

	clock_gettime(CLOCK_REALTIME, &time_struct);
	long update_time = time2millis(&time_struct);
	long current_time, last_time;

#ifdef FPS
	int frames = 0;
	last_time = update_time;
#endif

    for (;;)
    {
    	//Request and process BPS next available event
        bps_event_t *event = NULL;
        rc = bps_get_event(&event, 1);
        assert(rc == BPS_SUCCESS);

        if (event)
        {
            int domain = bps_event_get_domain(event);

            if (domain == screen_get_domain())
            {
                handleScreenEvent(event);
            }
            else if ((domain == navigator_get_domain()) && (NAVIGATOR_EXIT == bps_event_get_code(event)))
            {
            	exit_application = 1;
            }
        }

		clock_gettime(CLOCK_REALTIME, &time_struct);
		current_time = time2millis(&time_struct);

		if ((current_time - update_time) > framePeriod)
		{
			update_time = current_time;
			render();
#ifdef FPS
			frames++;
#endif
		}
		else
		{
			sleep(0);
		}

#ifdef FPS
		if (current_time - last_time > 1000)
		{
			fprintf(stderr, "fps: %d\n", frames);
			frames = 0;
			last_time = current_time;
		}
#endif

        if (exit_application)
        	break;
    }

    // clean up gestures
    gesturesCleanup();

    //Stop requesting events from libscreen
    screen_stop_events(screen_cxt);

    //Shut down BPS library for this process
    bps_shutdown();

	//Destroy the font
	bbutil_destroy_font(font);

    //Use utility code to terminate EGL setup
    bbutil_terminate();

    //Destroy libscreen context
    screen_destroy_context(screen_cxt);
    return 0;
}