Example #1
0
/**
 * map_control -- draw a cursor on the screen and accept control from FSM
 * @ch: the input word from the FSM
 */
int map_control(int ch)
{
        bool dozoom = false;
        struct map_t *tmp;

        if (!nav_win)
                map_cursor_init();

        top_panel(nav_pan);

        switch (ch) 
        {
        case MODE_STARTED:
                map_controls_active = true;
                cursor->Show(cursor);
                show_panel(nav_pan);
                break;
                
        /* Scroll the map in a direction */
        case 'w': case 'a': case 's': case 'd':
        case 'W': case 'A': case 'S': case 'D':
                map_scroll(MAPBOOK->active, ch);
                break;

        /* Move the zoom frame in a direction */
        case 'h': case 'j': case 'k': case 'l':
        case 'H': case 'J': case 'K': case 'L':
                cursor->Move(cursor, ch);
                break;

        /* Select the current zoom frame */
        case '\n':
                dozoom = true;
                break;

        case KEY_ESC:
        case 'm':
                map_controls_active = false;
                show_dock();
                cursor->Hide(cursor);
                hide_panel(nav_pan);
                return MODE_RELEASE;
        }

        /* Adjust for changing y0 or x0 of the map pad */
        y_map = pos_y(cursor->pos) + pos_y(ACTIVE->pos);
        x_map = pos_x(cursor->pos) + pos_x(ACTIVE->pos);
        zoomlevel = MAPBOOK->page;

        print_map_control(y_map, x_map);
        draw_zoom_box(ACTIVE, y_map, x_map);

        if (dozoom)
                set_zoom(MAPBOOK, y_map, x_map);

        return MODE_PERSIST;
}
Example #2
0
void UIContext::set_beacon_position(const Point2i& pos)
{
  if( this->valid() ) {

    Rocket::Core::ElementDocument* target =
      this->context()->GetDocument("rkt-debug-log-beacon");

    NOM_ASSERT( target != nullptr );
    if( target ) {
      // NOM_DUMP( target->GetSourceURL().CString() );

      Rocket::Core::Element* body_tag =
        target->GetParentNode();

      NOM_ASSERT( body_tag != nullptr );
      if( body_tag ) {

        Rocket::Core::Element* debug_info =
          body_tag->GetElementById("rkt-debug-log-beacon");

        NOM_ASSERT( debug_info != nullptr );
        if( debug_info ) {

          Rocket::Core::Property pos_x( pos.x, Rocket::Core::Property::PX);
          Rocket::Core::Property pos_y( pos.y, Rocket::Core::Property::PX);

          debug_info->SetProperty("left", pos_x);
          debug_info->SetProperty("top", pos_y);

        } // end if debug_info
      } // end if body_tag
    } // end if target
  } // end if valid context
}
Example #3
0
void chk_walls(unsigned int c_pos, unsigned char m_dir)
{
	unsigned int i;
	unsigned char cnt_L0,cnt_R0,cnt_L45,cnt_R45;

	// Initiate.
	cnt_L0 = cnt_R0 = cnt_L45 = cnt_R45 = 0;

	// Count.
	for(i=0;i<SS_HISTORY_SIZE;i++)	{
		if (ss_history[SS_L45][i] > threshold_L45 ) cnt_L45++;
		if (ss_history[SS_R45][i] > threshold_R45 ) cnt_R45++;
		if (ss_history[SS_L0 ][i] > threshold_L0  ) cnt_L0++;
		if (ss_history[SS_R0 ][i] > threshold_R0  ) cnt_R0++;
	}

	// Decide the existance of walls.
	if ( cnt_L45 > 2 ) 				 maze[c_pos] |= wall_bit(get_absolute_dir(L,m_dir));
	if ( cnt_R45 > 2 )  			 maze[c_pos] |= wall_bit(get_absolute_dir(R,m_dir));
	//if ( cnt_L0  > 2 && cnt_R0 > 2 ) maze[c_pos] |= wall_bit(get_absolute_dir(F,m_dir));
	if ( cnt_L0  > 1 && cnt_R0 > 1 ) maze[c_pos] |= wall_bit(get_absolute_dir(F,m_dir));

	// Process walls of blocks around.
	unsigned char x,y;
	x = pos_x( c_pos ); y = pos_y( c_pos );
	if ( (maze[c_pos] & NORTH) && y < 15 )  maze[ c_pos + dxy[N] ] |= SOUTH;
	if ( (maze[c_pos] & EAST ) && x < 15 )  maze[ c_pos + dxy[E] ] |= WEST;
	if ( (maze[c_pos] & SOUTH) && y >  0 )  maze[ c_pos + dxy[S] ] |= NORTH;
	if ( (maze[c_pos] & WEST ) && x >  0 )  maze[ c_pos + dxy[W] ] |= EAST;

	// Check the block read.
	maze_info[ c_pos ] |= VALID_BLK;
}
Example #4
0
void print_map_control(int y, int x)
{
        werase(nav_win);
        mvwpumpw(nav_win, 0, 2,  L"y:%03d, x:%03d", pos_y(ACTIVE->pos), pos_x(ACTIVE->pos));
        mvwpumpw(nav_win, 0, 16, L"▏ ymax:%d xmax:%d", ACTIVE->pos->ymax, ACTIVE->pos->xmax);
        mvwpumpw(nav_win, 0, COLS-17, L"▕  %s", page[zoomlevel]);
}
Example #5
0
File: sort_3.c Project: mdambrev/42
void				tri_basic(t_content *axx)
{
	TMP_A(4) = LIST_A(3);
	LIST_I(NB_LIST + 4, 0);
	norm(axx);
	while (check_list(axx, 0) != 0)
	{
		TMP_A(3) = LIST_A(0);
		LIST_I(NB_LIST + 3, 1);
		TMP_A(8) = LIST_A(0);
		LIST_I(NB_LIST + 8, 0);
		LIST_I(NB_LIST + 8, 0);
		if (VALUE_IN(0, 0) < VALUE_IN(0, 1))
		{
			op(axx, 5);
		}
		else if (TMP_IN(3, 1) < VALUE_IN(0, 1))
		{
			op(axx, 0);
		}
		else
		{
			push_b(axx, pos_x(axx, TMP_I(4, 0)));
			LIST_I(NB_LIST + 4, 0);
		}
	}
}
Example #6
0
File: algo.c Project: shizkr/dsy_mm
/* wall bits are filled by absolute direction.
 * index : current mouse location to save the wall information.
 */
void save_wallinfo_to_maze(unsigned char index, unsigned char wall)
{
    int x, y;

    print_dbg(DEBUG_SEARCH, "%02X, %02X\n", index, wall&0xf);
    /* trying to save know wall to maze_search? */
    if ((maze_search[index]&0xF0) == 0xF0)
        print_exit("%s: %d,%d is already known block!\n",
                   __func__, pos_x(index), pos_y(index));

    /* save wall info to current index */
    maze_search[index] |= (wall&0xf);
    maze_search[index] |= 0xF0;

    /* save wall information the wall of other blocks */
    x = pos_x(index);
    y = pos_y(index);

    /* north (it's south wall of next block) */
    if (y+1 < MAX_Y) {
        maze_search[get_index(x, y+1)] |= KNOWN_SOUTH;
        if (wall & NORTH)
            maze_search[get_index(x, y+1)] |= SOUTH;
    }
    /* east (it's west wall of next block) */
    if (x+1 < MAX_X) {
        maze_search[get_index(x+1, y)] |= KNOWN_WEST;
        if (wall & EAST)
            maze_search[get_index(x+1, y)] |= WEST;
    }
    /* south (it's north wall of next block) */
    if (y > 0) {
        maze_search[get_index(x, y-1)] |= KNOWN_NORTH;
        if (wall & SOUTH)
            maze_search[get_index(x, y-1)] |= NORTH;
    }
    /* west (it's east wall of next block) */
    if (x > 0) {
        maze_search[get_index(x-1, y)] |= KNOWN_EAST;
        if (wall & WEST)
            maze_search[get_index(x-1, y)] |= EAST;
    }
    print_dbg(DEBUG_SEARCH, "%s: index:%02X maze_search[index]=%02X\n",
              __func__, index, (unsigned char)maze_search[index]);
}
Example #7
0
File: algo.c Project: shizkr/dsy_mm
/* Find fastest path from known maze information
 * and return the FRBL turn array to the caller.
 * if first turn is one of RBL, it means that the
 * mouse has to make back turn or smooth L/R turn.
 * In that case, no diagonal turns.
 *
 * fast_path_type: 0 find all possible pathes
 *                 1 find from only known blocks
 */
unsigned char *find_maze_fastest_path(
    unsigned char cur_mouse_pos, char cur_mouse_dir,
    unsigned int search_type, struct s_link *f_node,
    int fast_path_type)
{
    unsigned char *path;
    struct s_link *mouse_path;
    struct s_link *sl_fast_path;
#ifdef DEBUG
    int i;
#endif

    if (!f_node)
        print_exit("f_node NULL\n");
    print_dbg(DEBUG_SEARCH, "mouse pos:%d,%d mouse_dir:%d "
              "search_type:%d\n", pos_x(cur_mouse_pos),
              pos_y(cur_mouse_pos), cur_mouse_dir,
              search_type);
    /* draw contour map from the goal */
    draw_contour(maze_search, contour_map,
                 search_type, cur_mouse_pos);
    /* generate full binary tree with all pathes */
    mouse_path = gen_bin_tree(maze_search,
                              contour_map, cur_mouse_pos, cur_mouse_dir);
    /* find the fastest path and get the node */
    sl_fast_path = find_fastest_path(mouse_path, fast_path_type);

    if (sl_fast_path) {

        memcpy(f_node, sl_fast_path, sizeof(struct s_link));

        /* Free sl_nodes after searching the fastest path */
        sl_node_free(mouse_path);
    } else {
        sl_node_free(mouse_path);
        return NULL;
    }

    /* generate FRBL array for the fastest path */
    path = gen_frbl_from_node(f_node);

#ifdef DEBUG
    printf("%s\n", __func__);
    for (i = 0; path[i] != 0xff; i++)
        printf("%C",
               (path[i] == FD) ? 'F' : \
               ((path[i] == RD) ? 'R' : \
                ((path[i] == BD) ? 'B' : \
                 ((path[i] == LD) ? 'L' : 'X'))));
    printf("\n");
#endif

    return path;
}
Example #8
0
void drawmouse()
{
	int x,y,xx,yy;
	char temp[]="**";
	x=pos_x(mouse_pos);
	y=pos_y(mouse_pos);

	xx=x*28+2;
	yy=28*(15-y)+2;

//	showweight(); getch();

	setcolor(WHITE);
	outtextxy(xx+2,yy+10,temp);

}
Example #9
0
void UIContext::set_debugger_position(const Point2i& pos)
{
  if( this->valid() ) {

    Rocket::Core::ElementDocument* target =
      this->context()->GetDocument("rkt-debug-hook");

    NOM_ASSERT( target != nullptr );
    if( target ) {
      // NOM_DUMP( target->GetSourceURL().CString() );

      Rocket::Core::Element* body_tag =
        target->GetParentNode();

      NOM_ASSERT( body_tag != nullptr );
      if( body_tag ) {

        Rocket::Core::Element* debug_info =
          body_tag->GetElementById("rkt-debug-info");

        NOM_ASSERT( debug_info != nullptr );
        if( debug_info ) {

          Rocket::Core::Property pos_x( pos.x, Rocket::Core::Property::PX);
          Rocket::Core::Property pos_y( pos.y, Rocket::Core::Property::PX);

          debug_info->SetProperty("left", pos_x);
          debug_info->SetProperty("top", pos_y);

        } // end if debug_info
      } // end if body_tag
    } // end if target
  } // end if valid context

  // for( auto itr = tags.begin(); itr != tags.end(); ++itr ) {
  //   if( (*itr)->GetId() == "rkt-debug-info" ) {
  //     NOM_DUMP( (*itr)->GetTagName().CString() );
  //     NOM_DUMP( (*itr)->GetId().CString() );
  //   }
  // } // end for tags loop
}
Example #10
0
File: algo.c Project: shizkr/dsy_mm
static int gen_bin_tree_tail(unsigned char *maze, unsigned char *map,
                             struct s_link **head)
{
    struct btree_node *bt_new_node, *bt_node;
    struct s_link *sl_node;
    struct s_link *sl_new_node, *tail_new_list = NULL;
    unsigned char i, index, abs_dir;
    struct btree_node bt_node_backup;
    char dir, is_goal = 0, found_node;
#ifdef CONFIG_PATH_LIMIT
    int path_limit = 0;
#endif

    if (!maze || !map || !head || !*head) {
        print_error("NULL pointer error! %X %X %X %X\n",
                    (unsigned int)maze, (unsigned int)map,
                    (unsigned int)head, (unsigned int)*head);
    }

    print_dbg(DEBUG_S_LINK, "Check input linked list: %08X\n",
              (unsigned int)*head);
    debug_sl_node(*head);

    print_dbg(DEBUG_S_LINK, "Find next lower contour level\n");
    /* Find next lower contour cube arond current location */
    for (sl_node = *head; sl_node; sl_node = sl_node->node) {
        index = sl_node->bt_node->pos;
        abs_dir = sl_node->bt_node->abs_dir;
        bt_node = sl_node->bt_node;

        /* when it's set, found turn. on the unkonwn blocks,
         * there may be too many pathes to calculate.
         **/
        found_node = 0;
        bt_node_backup.time = 0; /* use to check FD detection */

        for (i = NI; i <= WI; i++) {
            if (!(maze[index] & wall_bit(i)) &&
                    (map[index] == map[index + maze_dxy[i]] + 1)) {

                dir = relative_direction(abs_dir, i);

                /* if block is unknown, then take turn prior
                 * to straight path. It's to save memory
                 * and calculation time.
                 */
                if (dir == FD && ((maze[index]&0xF0) != 0xF0)) {
                    bt_node_backup.pos = index+maze_dxy[i];
                    bt_node_backup.dir = dir;
                    bt_node_backup.abs_dir = i;
                    /* to mark block has meaningful data */
                    bt_node_backup.time = 1;
                    continue;
                }

                found_node = 1;
                /* create new bt_node and save next mouse index
                 * and absolute direction of mouse at next block
                 */
                bt_new_node =
                    bt_node_alloc(index+maze_dxy[i], i);

                /* Next bt_node->dir is to save how mouse made
                 * a turn to come the block.
                 */
                bt_new_node->dir = dir;

                /* there can be 3rd child, only take 2 child at
                 * a time
                 */
                if (!add_bt_node(bt_node, bt_new_node)) {
                    sl_new_node = s_link_alloc(bt_new_node);
                    add_sl_node(&tail_new_list, sl_new_node);
#ifdef CONFIG_PATH_LIMIT
                    path_limit++;
#endif
                } else {
                    bt_node_free(bt_new_node);
                }

                /*
                 * debug_sl_node(tail_new_list);
                 */
            }
        }

        /* if forward is the only one in known block,
         * then use it
         */
        if (!found_node && bt_node_backup.time) {
            bt_new_node =
                bt_node_alloc(bt_node_backup.pos,
                              bt_node_backup.abs_dir);
            bt_new_node->dir = bt_node_backup.dir;

            add_bt_node(bt_node, bt_new_node);

            sl_new_node = s_link_alloc(bt_new_node);
            add_sl_node(&tail_new_list, sl_new_node);
#ifdef CONFIG_PATH_LIMIT
            path_limit++;
#endif
        }

        if (map[index] == 1 && !is_goal)
            is_goal = 1;

        /* Remove bt_node if there is no child, it'll search
         * parent node and remove the node if it had no child
         */
        if (!is_goal)
            clean_bin_tree(bt_node, 80);

#ifdef CONFIG_PATH_LIMIT
        /* 10 pathes : max 20KB
         * 20 pathes : max 30 KB
         * 40 pathes : max 57 KB
         */
        if (path_limit >= 20)
            break;
#endif
    }
    if (tail_new_list)
        debug_sl_node(tail_new_list);

#ifdef DEBUG
    if (is_goal) {
        i = 0;
        print_dbg(DEBUG_BINTREE,
                  "Found maze goal!!!\n");
        print_dbg(DEBUG_BINTREE,
                  "tail_new_list for tail: 0x%08X\n",
                  (unsigned int)tail_new_list);
        print_dbg(DEBUG_BINTREE,
                  "*head pointer: %08X\n",
                  (unsigned int)*head);
        if (tail_new_list)
            print_error("tail_new_list must be NULL!\n");
        for (sl_node = *head; sl_node; sl_node = sl_node->node) {
            index = sl_node->bt_node->pos;
            bt_node = sl_node->bt_node;
            i++;
        }
        print_dbg(DEBUG_BINTREE, "Total path: %d\n", i);
    }
#endif

    /* critical error to find next contour maps */
    if (!is_goal && tail_new_list == NULL) {
        printf("contour map\n");
        print_full(map);
        printf("maze map\n");
        print_map(maze);
        for (sl_node = *head; sl_node; sl_node = sl_node->node) {
            index = sl_node->bt_node->pos;
            abs_dir = sl_node->bt_node->abs_dir;
            bt_node = sl_node->bt_node;
            printf("mouse:(%d,%d),abs_dir:%d\n", pos_x(index),
                   pos_y(index), abs_dir);
        }
    }

    /* free s_link nodes */
    if (!is_goal) {
        sl_node_free(*head);
        *head = tail_new_list;
    }

    return is_goal;
}