예제 #1
0
/**
 * @name	core_tick
 * @brief	moves the game forward by a single tick, defined by a time delta of
 *			last tick to this tick
 * @param	dt - (int) elapsed time from last tick to this tick in milliseconds
 * @retval	NONE
 */
void core_tick(int dt) {
	if (js_ready) {
		core_timer_tick(dt);
		js_tick(dt);
	}

	// Tick the texture manager (load pending textures)
	texture_manager_tick(texture_manager_get());
	/*
	 * we need to wait 2 frames before removing the preloader after we get the
	 * core_hide_preloader call from JS.  Only on the second frame after the
	 * callback are the images that were preloaded actually drawn.
	 */

	if (show_preload || preload_hide_frame_count < 2) {
		//if we've gotten the core_hide_preloader cb, start counting frames
		if (!show_preload) {
			preload_hide_frame_count++;
		}

		texture_2d *tex = texture_manager_get_texture(texture_manager_get(), "loading.png");

		if (tex && tex->loaded) {
			if (do_sizing) {
				calculate_size(tex);
				do_sizing = false;
			}

			context_2d *ctx = context_2d_get_onscreen(tealeaf_canvas_get());
			context_2d_loadIdentity(ctx);
			context_2d_clear(ctx);
			context_2d_drawImage(ctx, 0, "loading.png", &tex_size, &size, 0);
			// we're the first, last, and only thing to draw, so flush the buffer
			context_2d_flush(ctx);
		}
	}

    // check the gl error and send it to java to be logged
    if (js_ready) {
        core_check_gl_error();
    }
}
예제 #2
0
/**
 * @name	core_tick
 * @brief	moves the game forward by a single tick, defined by a time delta of
 *			last tick to this tick
 * @param	dt - (int) elapsed time from last tick to this tick in milliseconds
 * @retval	NONE
 */
void core_tick(int dt) {
	if (js_ready) {
		core_timer_tick(dt);
		js_tick(dt);
	}

	// Tick the texture manager (load pending textures)
	texture_manager_tick(texture_manager_get());
	/*
	 * we need to wait 2 frames before removing the preloader after we get the
	 * core_hide_preloader call from JS.  Only on the second frame after the
	 * callback are the images that were preloaded actually drawn.
	 */

	if (show_preload || preload_hide_frame_count < 2) {
		//if we've gotten the core_hide_preloader cb, start counting frames
		if (!show_preload) {
			preload_hide_frame_count++;

			// May have never loaded the splash image, so hide splash here too
			device_hide_splash();
		}

		// If splash is defined,
		const char *splash = config_get_splash();
		if (splash) {
			texture_2d *tex = texture_manager_get_texture(texture_manager_get(), splash);
			if (!tex) {
				tex = texture_manager_load_texture(texture_manager_get(), splash);
			}

			if (tex && tex->loaded) {
				if (do_sizing) {
					// Calculate rotation
					tealeaf_canvas *canvas = tealeaf_canvas_get();
					int canvas_width = canvas->framebuffer_width;
					int canvas_height = canvas->framebuffer_height;
					rotate = canvas_width > canvas_height;
					rotate ^= tex->originalWidth > tex->originalHeight;

					calculate_size(tex, rotate);
					do_sizing = false;
				}

				context_2d *ctx = context_2d_get_onscreen(tealeaf_canvas_get());
				context_2d_loadIdentity(ctx);
				context_2d_clear(ctx);
				if (rotate) {
					context_2d_save(ctx);
					context_2d_translate(ctx, size.y + (size.height)/2.f/tex->scale, size.x + (size.width)/2.f/tex->scale);
					context_2d_rotate(ctx, (tex->originalWidth > tex->originalHeight)? -3.14f/2.f : 3.14f/2.f);
					context_2d_translate(ctx, -size.x -(size.width)/2.f/tex->scale, -size.y - (size.height)/2.f/tex->scale);
				}
				context_2d_setGlobalCompositeOperation(ctx, source_over);
				context_2d_drawImage(ctx, 0, splash, &tex_size, &size);
				if (rotate) {
					context_2d_restore(ctx);
				}
				// we're the first, last, and only thing to draw, so flush the buffer
				context_2d_flush(ctx);

				device_hide_splash();
			}
		}
	}

    // check the gl error and send it to java to be logged
    if (js_ready) {
        core_check_gl_error();
    }
}