Beispiel #1
0
/**
 * @name	calculate_size
 * @brief	calclates source and destination size of the loading image
 * @param	tex - (texture_2d*) load screen texture
 * @retval	NONE
 */
void calculate_size(texture_2d *tex) {
	tealeaf_canvas *canvas = tealeaf_canvas_get();
	int scale = use_halfsized_textures ? 2 : 1;
	int width = canvas->framebuffer_width;
	int height = canvas->framebuffer_height;
	float vertical = height * 1.0f / tex->originalHeight;
	float horizontal = width * 1.0f / tex->originalWidth;
	float ratio = (vertical > horizontal ? vertical : horizontal);
	float offsetX = (width - ratio * tex->originalWidth) / 2;
	float offsetY = (height - ratio * tex->originalHeight) / 2;
	tex_size.x = 0;
	tex_size.y = 0;
	tex_size.width = tex->originalWidth * scale;
	tex_size.height = tex->originalHeight * scale;
	size.x = offsetX;
	size.y = offsetY;
	size.width = ratio * tex->originalWidth * scale;
	size.height = ratio * tex->originalHeight * scale;
}
Beispiel #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++;
		}

		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();
    }
}
/**
 * @name	context_2d_get_onscreen
 * @brief
 * @retval	context_2d* -
 */
context_2d *context_2d_get_onscreen() {
	tealeaf_canvas *canvas = tealeaf_canvas_get();
	return canvas->onscreen_ctx;
}
Beispiel #4
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();
    }
}