Exemplo n.º 1
0
/** Deallocator function for a rdp context.
 *  The function will deallocate the resources from the 'instance' parameter that were allocated from a call
 *  to freerdp_context_new().
 *  If the ContextFree callback is set in the 'instance' parameter, it will be called before deallocation occurs.
 *
 *  @param instance - Pointer to the rdp_freerdp structure that was initialized by a call to freerdp_context_new().
 *  				  On return, the fields associated to the context are invalid.
 */
void freerdp_context_free(freerdp* instance)
{
	if (!instance)
		return;

	if (!instance->context)
		return;

	IFCALL(instance->ContextFree, instance, instance->context);

	rdp_free(instance->context->rdp);
	instance->context->rdp = NULL;

	graphics_free(instance->context->graphics);
	instance->context->graphics = NULL;

	PubSub_Free(instance->context->pubSub);

	metrics_free(instance->context->metrics);

	CloseHandle(instance->context->channelErrorEvent);
	free(instance->context->errorDescription);

	CloseHandle(instance->context->abortEvent);
	instance->context->abortEvent = NULL;

	free(instance->context);
	instance->context = NULL;

}
Exemplo n.º 2
0
/** Deallocator function for a rdp context.
 *  The function will deallocate the resources from the 'instance' parameter that were allocated from a call
 *  to freerdp_context_new().
 *  If the ContextFree callback is set in the 'instance' parameter, it will be called before deallocation occurs.
 *
 *  @param instance - Pointer to the rdp_freerdp structure that was initialized by a call to freerdp_context_new().
 *  				  On return, the fields associated to the context are invalid.
 */
void freerdp_context_free(freerdp* instance)
{
	if (instance->context == NULL)
		return;

	IFCALL(instance->ContextFree, instance, instance->context);

	rdp_free(instance->context->rdp);
	graphics_free(instance->context->graphics);

	free(instance->context);
	instance->context = NULL;
}
void application_free(application_t *app)
{
    DEBUG("application_free()");
    assert(app != 0);

    video_close(app->video);
    gps_free(app->gps);
    imu_free(app->imu);
    graphics_drawable_free(app->image);
    graphics_hud_free(app->hud);
    graphics_atlas_free(app->atlas1);
    graphics_atlas_free(app->atlas2);
    graphics_free(app->graphics);
    free(app);
}
Exemplo n.º 4
0
/**
 * @param load_callback		Responsible for registering all the VFS callbacks
 *							required for the game. After load_callback has been
 *							run, assets are immediately loaded.
 * @param init_callback		Runs after assets are loaded, and should set up game
 *							objects to their initial state.
 * @param release_callback	Runs just before the game quits, and should release
 *							all assets and free dynamically allocated memory.
 */
void core_setup(const char *title, float view_width, float view_height,
		int window_width, int window_height, int window_mode, size_t game_memory_size)
{
	lodge_window_initialize();

	/* Store global references. */
	core_global->view_width = view_width;
	core_global->view_height = view_height;

	/* Set up sound */
	sound_init(&core_global->sound, (float *)core_global->sound_listener, core_global->sound_distance_max);

	/* Allocate game memory */
	core_global->shared_memory.game_memory = malloc(game_memory_size);
	core_global->shared_memory.core = core_global;
	core_global->shared_memory.sound = &core_global->sound;
	core_global->shared_memory.assets = assets;
	core_global->shared_memory.vfs = vfs_global;
	core_global->shared_memory.input = &core_global->input;
	core_global->init_memory_callback(&core_global->shared_memory, 0);

	/* Seed random number generator. */
	srand(time(NULL));

	/* Set up window. */
	core_global->graphics.view_width = view_width;
	core_global->graphics.view_height = view_height;
	core_global->graphics.window = lodge_window_create(title, window_width, window_height, window_mode, &core_window_create);

	if (!core_global->graphics.window) {
		core_error("Could not create window\n");
		return;
	}

	/* Setup input. */
	int ret = input_init(&core_global->input, core_global->graphics.window, &core_key_callback, &core_char_callback, &core_mousebutton_callback);

	if (ret != GRAPHICS_OK) {
		core_error("Input initialization failed (%d)\n", ret);
		graphics_free(&core_global->graphics);
		exit(ret);
	}

	lodge_window_set_resize_callback(core_global->graphics.window, &core_resize_callback);

	/* Load all assets */
	core_load();
}
Exemplo n.º 5
0
void core_run()
{
	/* Setup. */
	core_assets_init();

	/* Loop until the user closes the window */
	graphics_loop(&core_global->graphics);

	/* Release assets. */
	core_release();

	/* Free OpenAL. */
	sound_free(&core_global->sound);

	/* If we reach here, quit the core. */
	graphics_free(&core_global->graphics);

	/* Release game memory */
	free(core_global->shared_memory.game_memory);
}
Exemplo n.º 6
0
/** Deallocator function for a rdp context.
 *  The function will deallocate the resources from the 'instance' parameter that were allocated from a call
 *  to freerdp_context_new().
 *  If the ContextFree callback is set in the 'instance' parameter, it will be called before deallocation occurs.
 *
 *  @param instance - Pointer to the rdp_freerdp structure that was initialized by a call to freerdp_context_new().
 *  				  On return, the fields associated to the context are invalid.
 */
void freerdp_context_free(freerdp* instance)
{
	if (!instance)
		return;

	if (!instance->context)
		return;

	IFCALL(instance->ContextFree, instance, instance->context);

	rdp_free(instance->context->rdp);
	instance->context->rdp = NULL;

	graphics_free(instance->context->graphics);
	instance->context->graphics = NULL;

	PubSub_Free(instance->context->pubSub);

	free(instance->context);
	instance->context = NULL;
}
Exemplo n.º 7
0
void core_window_create(lodge_window_t window)
{
	/* Set up ratio. */
	int w, h;
	lodge_window_get_size(window, &w, &h);
	core_resize_callback(window, w, h);

	/* Set up graphics */
	int ret = graphics_init(&core_global->graphics, &core_think, &core_render, core_global->fps_callback);

	if (ret != GRAPHICS_OK) {
		core_error("Graphics initialization failed (%d)\n", ret);
		graphics_free(&core_global->graphics);
		exit(ret);
	}

	/* Set up OpenGL. */
	ret = graphics_opengl_init(&core_global->graphics);
	
	if (ret != GRAPHICS_OK) {
		core_error("opengl initialization failed (%d)\n", ret);
		exit(ret);
	}
}
Exemplo n.º 8
0
/** Allocator function for a rdp context.
 *  The function will allocate a rdpRdp structure using rdp_new(), then copy
 *  its contents to the appropriate fields in the rdp_freerdp structure given in parameters.
 *  It will also initialize the 'context' field in the rdp_freerdp structure as needed.
 *  If the caller has set the ContextNew callback in the 'instance' parameter, it will be called at the end of the function.
 *
 *  @param instance - Pointer to the rdp_freerdp structure that will be initialized with the new context.
 */
BOOL freerdp_context_new(freerdp* instance)
{
	rdpRdp* rdp;
	rdpContext* context;
	BOOL ret = TRUE;

	instance->context = (rdpContext*) calloc(1, instance->ContextSize);
	if (!instance->context)
		return FALSE;

	context = instance->context;
	context->instance = instance;

	context->ServerMode = FALSE;
	context->settings = instance->settings;

	context->pubSub = PubSub_New(TRUE);
	if(!context->pubSub)
		goto out_error_pubsub;
	PubSub_AddEventTypes(context->pubSub, FreeRDP_Events, sizeof(FreeRDP_Events) / sizeof(wEventType));

	context->metrics = metrics_new(context);
	if (!context->metrics)
		goto out_error_metrics_new;

	rdp = rdp_new(context);
	if (!rdp)
		goto out_error_rdp_new;

	instance->input = rdp->input;
	instance->update = rdp->update;
	instance->settings = rdp->settings;
	instance->autodetect = rdp->autodetect;

	context->graphics = graphics_new(context);
	if(!context->graphics)
		goto out_error_graphics_new;

	context->rdp = rdp;

	context->input = instance->input;
	context->update = instance->update;
	context->settings = instance->settings;
	context->autodetect = instance->autodetect;

	instance->update->context = instance->context;
	instance->update->pointer->context = instance->context;
	instance->update->primary->context = instance->context;
	instance->update->secondary->context = instance->context;
	instance->update->altsec->context = instance->context;

	instance->input->context = context;

	instance->autodetect->context = context;

	if (!(context->errorDescription = calloc(1, 500)))
	{
		WLog_ERR(TAG, "calloc failed!");
		goto out_error_description;
	}

	if (!(context->channelErrorEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
	{
		WLog_ERR(TAG, "CreateEvent failed!");
		goto out_error_create_event;
	}

	update_register_client_callbacks(rdp->update);

	instance->context->abortEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
	if (!instance->context->abortEvent)
		goto out_error_abort_event;

	IFCALLRET(instance->ContextNew, ret, instance, instance->context);

	if (ret)
		return TRUE;

	CloseHandle(context->abortEvent);
out_error_abort_event:
	CloseHandle(context->channelErrorEvent);
out_error_create_event:
	free(context->errorDescription);
out_error_description:
	graphics_free(context->graphics);
out_error_graphics_new:
	rdp_free(rdp);
out_error_rdp_new:
	metrics_free(context->metrics);
out_error_metrics_new:
	PubSub_Free(context->pubSub);
out_error_pubsub:
	free(instance->context);
	return FALSE;
}
application_t *application_init(struct config *cfg)
{
    DEBUG("application_init()");
    assert(cfg != 0);

    application_t *app = calloc(1, sizeof(struct _application));
    assert(app != 0);

    // Initialize graphics
    if(!(app->graphics = graphics_init(cfg->app_window_id)))
    {
        ERROR("Cannot initialize graphics");
        goto error;
    }

    // Create atlases
    if(!(app->atlas1 = graphics_atlas_create(cfg->graphics_font_file, cfg->graphics_font_size_1)) ||
       !(app->atlas2 = graphics_atlas_create(cfg->graphics_font_file, cfg->graphics_font_size_2)))
    {
        ERROR("Cannot create atlas");
        goto error;
    }

    // Create image
    if(!(app->image = graphics_image_create(app->graphics, cfg->video_width, cfg->video_height, cfg->video_format, ANCHOR_CENTER)))
    {
        ERROR("Cannot create image");
        goto error;
    }

    // Create HUD
    if(!(app->hud = graphics_hud_create(app->graphics, app->atlas1, cfg->graphics_font_color_1, cfg->graphics_font_size_1, cfg->video_hfov, cfg->video_vfov)))
    {
        ERROR("Cannot create HUD");
        goto error;
    }

    // Initialize GPS
    memcpy(&app->gps_config, &cfg->gps_conf, sizeof(struct gps_config));
    app->gps_config.userdata = app;
    app->gps_config.create_label = create_label_handler;
    app->gps_config.delete_label = delete_label_handler;
    if(!(app->gps = gps_init(cfg->gps_device, &app->gps_config)))
    {
        ERROR("Cannot initialize GPS");
        goto error;
    }

    // Initialize IMU
    memcpy(&app->imu_config, &cfg->imu_conf, sizeof(struct imu_config));
    if(!(app->imu = imu_init(cfg->imu_device, &app->imu_config)))
    {
        ERROR("Cannot initialize IMU");
        goto error;
    }

    // Open video
    if(!(app->video = video_open(cfg->video_device, cfg->video_width, cfg->video_height, cfg->video_format, cfg->video_interlace)))
    {
        ERROR("Cannot open video device");
        goto error;
    }

    // Copy arguments
    app->video_width = cfg->video_width;
    app->video_height = cfg->video_height;
    app->window_width = cfg->window_width;
    app->window_height = cfg->window_height;
    app->video_hfov = cfg->video_hfov;
    app->video_vfov = cfg->video_vfov;
    app->visible_distance = cfg->app_landmark_vis_dist;
    memcpy(app->label_color, cfg->graphics_font_color_2, 4);

    return app;

error:
    if(app->video) video_close(app->video);
    if(app->gps) gps_free(app->gps);
    if(app->imu) imu_free(app->imu);
    if(app->image) graphics_drawable_free(app->image);
    if(app->hud) graphics_hud_free(app->hud);
    if(app->atlas1) graphics_atlas_free(app->atlas1);
    if(app->atlas2) graphics_atlas_free(app->atlas2);
    if(app->graphics) graphics_free(app->graphics);

    free(app);
    return NULL;
}