Example #1
0
static void menu_on_item(GtkMenuItem *item, struct screen_info *screen_info)
{
    xcb_randr_rotation_t old_config, option, rotation, reflection;

    option = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(item), "rotation"));

    if (option & xcb_rotations_mask &&
            !gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(item))) {
        /* let the activated item take care of the event */
        return;
    }

    old_config = normalize_rotation(screen_info->rotation);
    rotation = old_config & xcb_rotations_mask;
    reflection = old_config & xcb_reflections_mask;

    if (option & xcb_rotations_mask) {
            rotation = option;
    } else if (option & xcb_reflections_mask) {
            reflection ^= option;
    }

    xcb_randr_set_screen_config_unchecked(conn, screen_info->root,
            XCB_CURRENT_TIME, screen_info->config_timestamp,
            screen_info->sizeID,
            normalize_rotation(rotation | reflection),
            screen_info->rate);

    xcb_flush(conn);
}
Example #2
0
Real normalize_rotation(Real rotation){
  if (rotation > PI)
    return normalize_rotation(rotation - 2 * PI);
  else if (rotation <= -PI)
    return normalize_rotation(rotation + 2 * PI);
  else
    return rotation;
}
	bool better_to_kick() {
		if(!enemy || !enemy->known() || !ball || !ball->known() || !us || !us->known())
			return false;
		float enemy_to_ball = euclidean_distance(enemy->x, enemy->y, ball->x, ball->y);
		if(enemy_to_ball > scale(50))
			return false;
		if(euclidean_distance(us->x, us->y, ball->x, ball->y) > scale(20))
			return false;

		float error = 0.03f;
		float dir = 0;
		if(old_us) {
			double difference = normalize_rotation(us->rotation - old_us->rotation);
			difference = std::min(difference, 2 * pi - difference);
			error += difference / 2;
			dir = us->rotation - old_us->rotation;
		}

		int good = 0;
		float a = us->rotation - error + dir;
		float b = us->rotation + error + dir;
		init_enemy_segments();
		for(int i = 0; i < 50; ++i) {
			float f = a + (b - a) * i / 49;
			if(f < 0.2 || f > pi - 0.2)
				continue;
			if((us->rotation > 0.2 && us->rotation < pi - 0.2) && (enemy_to_ball <= scale(30) || !enemy_in_the_way(f)))
				++good;
		}

		if(good >= 2)
			return true;
		return false;
	}
	void plan() {
		if(!us || !ball || ball_in_goal() || !us->known() || forced_state == WAIT) {
			return;
		} else if(!ball->known()) {
			if(had_ball)
				kick();
			had_ball = false;
			return;
		} else {
			had_ball = true;
		}
		//cout << "ball: " << *ball << endl;

		float error = 0.03f;
		float dir = 0;
		if(old_us) {
			double difference = normalize_rotation(us->rotation - old_us->rotation);
			difference = std::min(difference, 2 * pi - difference);
			error += difference / 2;
			dir = us->rotation - old_us->rotation;
		}

		int good = 0;
		float a = us->rotation - error + dir;
		float b = us->rotation + error + dir;
		init_enemy_segments();
		for(int i = 0; i < 50; ++i) {
			float f = a + (b - a) * i / 49;
			if(ball_in_kicker_area(f) && possible_goal(f) && !enemy_in_the_way(f))
				++good;
		}

		if(good > 1)
			cout << "/planner/info/kicker_prob " << good / 50.0 << endl;
		if(good >= 30)
			kick();
		else if(better_to_kick()) {
			cout << "/planner/info/better_to_kick" << endl;
			kick();
		}
	}
Example #5
0
static void on_screen_change(xcb_randr_screen_change_notify_event_t *ev)
{
    struct screen_info *screen_info = get_screen_info(ev->root);
    xcb_randr_rotation_t rotation = normalize_rotation(ev->rotation);

    if (!screen_info) {
        g_warning("Unable to find screen\n");
        return;
    }

    /* Update menu items with new rotation setting */
    screen_info->config_timestamp = ev->config_timestamp;
    screen_info->rotation = rotation;

    check_rotation_menu_item(screen_info,
            rotation & xcb_rotations_mask, TRUE);
    check_rotation_menu_item(screen_info, XCB_RANDR_ROTATION_REFLECT_X,
            rotation & XCB_RANDR_ROTATION_REFLECT_X);
    check_rotation_menu_item(screen_info, XCB_RANDR_ROTATION_REFLECT_Y,
            rotation & XCB_RANDR_ROTATION_REFLECT_Y);
}
Example #6
0
Real angle_separation(Real x, Real y){
  Real x_y, y_x;
  x_y = x - y;
  y_x = y - x;
  return MIN(fabs(normalize_rotation(x_y)), fabs(normalize_rotation(y_x)));
}
Example #7
0
static void add_screen(xcb_randr_get_screen_info_reply_t *reply)
{
    const gchar *title = "Display";
    GtkWidget *item = gtk_menu_item_new_with_label(title);
    GtkMenuShell *menu = GTK_MENU_SHELL(app_menu);
    struct screen_info *info = g_malloc(sizeof *info);
    xcb_randr_rotation_t rotation = normalize_rotation(reply->rotation);
    xcb_randr_rotation_t rotations = reply->rotations;

    info->label_menu_item = item;
    info->rotation_menu_group = NULL;
    info->rotation = rotation;
    info->config_timestamp = reply->config_timestamp;
    info->root = reply->root;
    info->sizeID = reply->sizeID;
    info->rate = reply->rate;
    screens_info = g_slist_append(screens_info, info);

    gtk_widget_set_sensitive(item, FALSE);
    gtk_menu_shell_append(menu, item);

#define R(rot, title) \
    if (rotations & XCB_RANDR_ROTATION_##rot) \
        add_screen_rotation(info, XCB_RANDR_ROTATION_##rot, title, \
                XCB_RANDR_ROTATION_##rot & rotation)
    R(ROTATE_0, "Landscape");
    R(ROTATE_90, "Portrait");
    R(ROTATE_180, "Landscape Flipped");
    R(ROTATE_270, "Portrait Flipped");

    if (rotations & xcb_rotations_mask && rotations & xcb_reflections_mask)
        gtk_menu_shell_append(menu, gtk_separator_menu_item_new());

    R(REFLECT_X, "Reflected X");
    R(REFLECT_Y, "Reflected Y");
#undef R

    gtk_menu_shell_append(menu, gtk_separator_menu_item_new());
    gtk_widget_show_all(app_menu);

    /* Get screen resources */
    xcb_randr_get_screen_resources_current_cookie_t resources_cookie;
    xcb_randr_get_screen_resources_current_reply_t *resources_reply;
    xcb_generic_error_t *err = NULL;

    resources_cookie = xcb_randr_get_screen_resources_current(conn,
            info->root);
    resources_reply = xcb_randr_get_screen_resources_current_reply(conn,
            resources_cookie, &err);
    if (err) {
        g_warning("Get Screen Resources returned error %u\n", err->error_code);
        return;
    }

    /* Get screen outputs */
    xcb_randr_output_t *outputs;
    guint i;
    gchar *output_name;

    outputs = xcb_randr_get_screen_resources_current_outputs(resources_reply);
    for (i = 0; i < resources_reply->num_outputs; i++) {
        xcb_randr_get_output_info_reply_t *output_info_reply;
        xcb_randr_get_output_info_cookie_t output_info_cookie =
            xcb_randr_get_output_info_unchecked(conn, outputs[i],
                    resources_reply->config_timestamp);
        output_info_reply =
            xcb_randr_get_output_info_reply(conn, output_info_cookie, NULL);
        /* Show only if connected */
        switch (output_info_reply->connection) {
            case XCB_RANDR_CONNECTION_DISCONNECTED:
            case XCB_RANDR_CONNECTION_UNKNOWN:
                continue;
            case XCB_RANDR_CONNECTION_CONNECTED:
                break;
        }
        output_name = get_output_name(output_info_reply);
        /* Put output names on the menu */
        gtk_menu_item_set_label(GTK_MENU_ITEM(item), output_name);
        g_free(output_name);
        /* TODO: concatenate multiple names or pick them intelligently */
    }
}