void draw_screen_game_running(SDL_Surface *screen, SDL_Surface *map, list_minion *minions, list_turret *turrets) { //Draw map SDL_Rect map_Rect = {0, 0, map->w, map->h}; SDL_BlitSurface(map, NULL, screen, &map_Rect); //Draw turrets list_turret *t = turrets; while (t && t->e) { turret *target = t->e; if(target->node) draw_node(screen, target->node, true); t = t->next; } //Draw minions list_minion *m = minions; while (m && m->e) { minion *target = m->e; if(target->node) draw_node(screen, target->node, false); list_projectile *p = m->e->targetted_projectils; //Draw projectiles while (p && p->e) { if(p->e->node)//Dont known why p->e != NULL and p->e->node == NULL. draw_node(screen, p->e->node, false); p = p->next; } m = m->next; } }
int Graf::save_svg(ostream &out) { if(currentLayout && n>0) { out << head_svg; int maxx = 0,maxy=0,v,cx,cy,cindex; for(cindex=0;cindex<n;cindex++) { Nod& cnode = getNode(cindex); if(maxx < cnode.x) maxx = cnode.x; if(maxy < cnode.y) maxy = cnode.y; } maxx += 40; maxy += 40; cx = (maxx / 100) + (maxx % 100 ? 1 : 0); cy = (maxy / 100) + (maxy % 100 ? 1 : 0); put_viewbox(out,cx,cy); for(v=0;v<capacitate;v++) if(lnod[v].alocat) { Muchie *cap; cx = lnod[v].x; cy = lnod[v].y; for(cap=lnod[v].first;cap;cap=cap->next) if(cap->v > v) draw_edge(out,cx,cy,lnod[cap->v].x,lnod[cap->v].y); } for(v=0;v<capacitate;v++) if(lnod[v].alocat) draw_node(out,v,lnod[v].x,lnod[v].y); out << svg_end; return 1; } else return 0; }
void display() { GLfloat m[4][4]; glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* get rotation matrix */ build_rot_matrix(m); //set_orthoview_pass(width, height); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(view_org[0], view_org[1], view_org[2], view_tgt[0], view_tgt[1], view_tgt[2], 0, 1, 0); /* Y up */ glMultMatrixf(&(m[0][0])); glScalef(1.0 / scenesize, 1.0 / scenesize, 1.0 / scenesize); draw_node(curr); glutSwapBuffers(); }
/* let the user input a list of path nodes */ void input_nodes(void) { clear_to_color(screen, makecol(255, 255, 255)); textout_centre_ex(screen, font, "Click the left mouse button to add path " "nodes", SCREEN_W/2, 8, palette_color[255], palette_color[0]); textout_centre_ex(screen, font, "Right mouse button or any key to finish", SCREEN_W/2, 24, palette_color[255], palette_color[0]); node_count = 1; show_mouse(screen); do { poll_mouse(); } while (mouse_b); clear_keybuf(); for (;;) { poll_mouse(); if (mouse_b & 1) { if (node_count < MAX_NODES-1) { nodes[node_count].x = mouse_x; nodes[node_count].y = mouse_y; show_mouse(NULL); draw_node(node_count); show_mouse(screen); node_count++; } do { poll_mouse(); } while (mouse_b & 1); } if ((mouse_b & 2) || (keypressed())) { if (node_count < 3) alert("You must enter at least two nodes", NULL, NULL, "OK", NULL, 13, 0); else break; } } show_mouse(NULL); do { poll_mouse(); } while (mouse_b); clear_keybuf(); }
int a_star_search(search_node * root, lifo ** path) { search_node * node = root; #if DEBUG god_mode_debug("Creating new priority queue\n"); #endif lifo closed_set; init_lifo_queue(&closed_set); priority_queue queue; init_priority_queue(&queue); #if DEBUG god_mode_debug("Adding first entry to priority queue\n"); #endif pq_add_entry(&queue, root, h(root)); while (queue.total_entries > 0) { #if DEBUG god_mode_debug("\n----------------\nNew iteration\n----------------\n"); print_lifo_queue(&closed_set); print_priority_queue(&queue); god_mode_debug("Expanding node\n"); #endif node = queue.head->node; #if DEBUG draw_node(node); #endif if (expand_node(&queue, &closed_set) == 1) { #if DEBUG god_mode_debug("Goal node found\n"); #endif *path = recover_path(node); if (*path == NULL) { #if DEBUG god_mode_debug("unable to recover path\n"); #endif return -1; } sprintf(str, "%d expanded_nodes\n%d nodes in closed set\n%d nodes in open set\n", closed_set.total_entries + 1, closed_set.total_entries, queue.total_entries); god_mode_debug(str); god_mode_debug("Returning solution\n"); //printf("%d expanded_nodes\n%d nodes in closed set\n%d nodes in open set\n", closed_set.total_entries + 1, closed_set.total_entries, queue.total_entries); return 0; } } // Solution not found return -2; }
void draw_node(avl_node_t *node, int height) { if(!node) return ; int l = 0; char *c = ch[height]; c += strlen(c); sprintf(c,"[k:%d,l:%d,r:%d,lb:%d,rb:%d] ", node->key, node->left ? node->left->key : -1, node->right ? node->right->key : -1, node->lbalance, node->rbalance); draw_node(node->left,height+1); draw_node(node->right,height+1); }
void Fl_Tree::draw(void) { // printf("Fl_Tree::draw %d %d\n",x(),y()); update_top(); int cy = parent()->y() + top_yoffset_; int ey = parent()->y() + parent()->h(); int depth = top_depth_; Fl_Node* node = top_; int drawing = 0; //printf("DAMAGE %d %d %d\n",damage(),FL_DAMAGE_ALL,FL_DAMAGE_CHILD); if (damage() == FL_DAMAGE_ALL) drawing = 1; if (damage() == FL_DAMAGE_CHILD && damaged_ == 0) drawing = 1; while (cy < ey && node) { if (damaged_ == node) { if (damage() == FL_DAMAGE_CHILD) { draw_node(depth, cy, node); return; } drawing = 1; } //printf("%s %d\n",(char*) node->data(),drawing); if (drawing) draw_node(depth, cy, node); cy += height(node); if (node->vsub_) { //printf("has sub\n"); node = node->vsub_; depth++; } else if (node->next_) { //printf("has no sub\n"); node = node->next_; } else { while (node && !node->next_) { node = node->up_; depth--; } if (node) node = node->next_; } } fl_color(parent()->color()); fl_rectf(x(), cy, w(), ey - cy); }
static void render(void) { mdarea_t *lv; draw_border(); for (lv = world.hvarea; lv; lv = lv->next) { draw_varea(lv); } for (lv = world.hvarea; lv; lv = lv->next) { mdnode_t *ln; for (ln = lv->hnode; ln; ln = ln->next) { draw_node(ln); } } }
void draw(avl_tree_t *tree) { int i; for (i=0; i<100; ++i) { ch[i][0] = '\0'; } draw_node(tree->root,0); for(i=0;i<10;i++){ printf ("%s\n",ch[i]); } }
static void draw_subtree_nodes (tsp_bbnode *bbnode, int depth, int maxdepth, double upbound) { draw_node (bbnode, depth); if (bbnode->child0 != (tsp_bbnode *) NULL && (maxdepth <= 0 || depth < maxdepth) && bbnode->child0->lowerbound <= upbound - 1.0) { draw_subtree_nodes (bbnode->child0, depth+1, maxdepth, upbound); } if (bbnode->child1 != (tsp_bbnode *) NULL && (maxdepth <= 0 || depth < maxdepth) && bbnode->child1->lowerbound <= upbound - 1.0) { draw_subtree_nodes (bbnode->child1, depth+1, maxdepth, upbound); } }
void print_lifo_queue(lifo * queue) { lifo_entry * entry = queue->head; god_mode_debug("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); sprintf(str, "Total entries in LIFO is %d\n\n",queue->total_entries); god_mode_debug(str); for (int i = 0; i < queue->total_entries; i++, entry = entry->next) { sprintf(str, "id = %llu\n", entry->node->key); god_mode_debug(str); sprintf(str, "moves = %d\n", entry->node->g); god_mode_debug(str); draw_node(entry->node); } god_mode_debug("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); }
void print_priority_queue(priority_queue * queue) { pq_entry * entry = queue->head; god_mode_debug("_____________________________________________\n"); sprintf(str, "Total entries in PQ is %d\n\n",queue->total_entries); god_mode_debug(str); for (int i = 0; i < queue->total_entries; i++, entry = entry->next) { sprintf(str, "id = %llu\n", entry->node->key); god_mode_debug(str); sprintf(str, "priority = %d\n", entry->priority); god_mode_debug(str); sprintf(str, "moves = %d\n", entry->node->g); god_mode_debug(str); sprintf(str, "manhattan = %d\n",entry->priority - entry->node->g); god_mode_debug(str); draw_node(entry->node); } god_mode_debug("_____________________________________________\n"); }
void update_debug_tree(void) { if (!debug.render_tree) { return; } int width = 640, height = 480; for (int i = 0; i < root->outputs->length; ++i) { struct sway_output *output = root->outputs->items[i]; if (output->width > width) { width = output->width; } if (output->height > height) { height = output->height; } } cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); cairo_t *cairo = cairo_create(surface); PangoContext *pango = pango_cairo_create_context(cairo); struct sway_seat *seat = input_manager_current_seat(); struct sway_node *focus = seat_get_focus(seat); cairo_set_source_u32(cairo, 0x000000FF); draw_node(cairo, &root->node, focus, 0, 0); cairo_surface_flush(surface); struct wlr_renderer *renderer = wlr_backend_get_renderer(server.backend); if (root->debug_tree) { wlr_texture_destroy(root->debug_tree); } unsigned char *data = cairo_image_surface_get_data(surface); int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width); struct wlr_texture *texture = wlr_texture_from_pixels(renderer, WL_SHM_FORMAT_ARGB8888, stride, width, height, data); root->debug_tree = texture; cairo_surface_destroy(surface); g_object_unref(pango); cairo_destroy(cairo); }
static void plot_node (BDDPTR v) { /* Draw the node v: */ if (!BDD_CONST_P (v)) { BDDPTR T = BDD_THEN (v); BDDPTR E = BDD_ELSE (v); /* Draw the non-terminal node: */ draw_node (plot_fp, POSITION_F (v), Y_POS (v), (*plot_name) (v)); /* Draw the outgoing edges: */ if (BDD_0_P (T)) draw_then_const (plot_fp, POSITION_F (v), Y_POS (v), 0); else if (BDD_1_P (T)) draw_then_const (plot_fp, POSITION_F (v), Y_POS (v), 1); else if (BDD_X_P (T)) draw_then_const (plot_fp, POSITION_F (v), Y_POS (v), 2); else draw_then_edge (plot_fp, POSITION_F (v), Y_POS (v), POSITION_F (T), Y_POS (T), BDD_NEG_P (T), BDD_I_INV_EDGE_P (T)); if (BDD_0_P (E)) draw_else_const (plot_fp, POSITION_F (v), Y_POS (v), 0); else if (BDD_1_P (E)) draw_else_const (plot_fp, POSITION_F (v), Y_POS (v), 1); else if (BDD_X_P (E)) draw_else_const (plot_fp, POSITION_F (v), Y_POS (v), 2); else draw_else_edge (plot_fp, POSITION_F (v), Y_POS (v), POSITION_F (E), Y_POS (E), BDD_NEG_P (E), BDD_I_INV_EDGE_P (E)); } }
static int draw_node(cairo_t *cairo, struct sway_node *node, struct sway_node *focus, int x, int y) { int text_width, text_height; char *buffer = get_string(node); get_text_size(cairo, "monospace", &text_width, &text_height, NULL, 1, false, buffer); cairo_save(cairo); cairo_rectangle(cairo, x + 2, y, text_width - 2, text_height); cairo_set_source_u32(cairo, 0xFFFFFFE0); cairo_fill(cairo); int height = text_height; list_t *children = get_children(node); if (children) { for (int i = 0; i < children->length; ++i) { // This is really dirty - the list contains specific structs but // we're casting them as nodes. This works because node is the first // item in each specific struct. This is acceptable because this is // debug code. struct sway_node *child = children->items[i]; if (node_get_parent(child) == node) { cairo_set_source_u32(cairo, 0x000000FF); } else { cairo_set_source_u32(cairo, 0xFF0000FF); } height += draw_node(cairo, child, focus, x + 10, y + height); } } cairo_set_source_u32(cairo, 0xFFFFFFE0); cairo_rectangle(cairo, x, y, 2, height); cairo_fill(cairo); cairo_restore(cairo); cairo_move_to(cairo, x, y); if (focus == node) { cairo_set_source_u32(cairo, 0x0000FFFF); } pango_printf(cairo, "monospace", 1, false, buffer); free(buffer); return height; }
/* draws the spline paths */ void draw_splines(void) { int i; acquire_screen(); clear_to_color(screen, makecol(255, 255, 255)); textout_centre_ex(screen, font, "Spline curve path", SCREEN_W/2, 8, palette_color[255], palette_color[0]); textprintf_centre_ex(screen, font, SCREEN_W/2, 32, palette_color[255], palette_color[0], "Curviness = %.2f", fixtof(curviness)); textout_centre_ex(screen, font, "Up/down keys to alter", SCREEN_W/2, 44, palette_color[255], palette_color[0]); textout_centre_ex(screen, font, "Space to walk", SCREEN_W/2, 68, palette_color[255], palette_color[0]); textout_centre_ex(screen, font, "C to display control points", SCREEN_W/2, 92, palette_color[255], palette_color[0]); textout_centre_ex(screen, font, "T to display tangents", SCREEN_W/2, 104, palette_color[255], palette_color[0]); for (i=1; i<node_count-2; i++) draw_spline(nodes[i], nodes[i+1]); for (i=1; i<node_count-1; i++) { draw_node(i); if (show_tangents) { line(screen, nodes[i].x - fixtoi(fixcos(nodes[i].tangent) * 24), nodes[i].y - fixtoi(fixsin(nodes[i].tangent) * 24), nodes[i].x + fixtoi(fixcos(nodes[i].tangent) * 24), nodes[i].y + fixtoi(fixsin(nodes[i].tangent) * 24), palette_color[1]); } } release_screen(); }
// draws the tree in OpenGL trying to spread the nodes over the screen void Node::draw_subtree(GLfloat parent_x, GLfloat parent_y, int number_children, GLfloat parent_space) { GLfloat separation = parent_space / (number_children); // std::cout << "depth: " << depth_ << " separation: " << separation // << " parent space: " << parent_space // << " number of children: " << number_children << std::endl; GLfloat x = (GLfloat)( parent_x + (((GLfloat)children_number_) - ((GLfloat)number_children - 1) / 2) * separation); GLfloat y = (GLfloat)(parent_y - SPACE_HEIGHT); draw_node(x, y, this->get_node_type()); draw_connector(parent_x, parent_y, x, y); draw_status(x, y, node_status_); draw_string(x - CURSOR_WIDTH, y + 2.1 * CURSOR_WIDTH, get_node_name().c_str()); if (this->get_node_type() == ACTION) draw_string(x - CURSOR_WIDTH, y + 2.2 * NODE_WIDTH, get_ros_node_name().c_str()); if (highlighted_) draw_cursor(x, y); if (number_children_ > 0) { first_child_->draw_subtree(x, y, number_children_, separation); } if (next_brother_ != NULL) { next_brother_->draw_subtree(parent_x, parent_y, number_children, parent_space); } }
static void print_content(void) { int required_lines = 0, disable_detailed = 0, disabled_graphical = 0; if (NULL == get_current_node()) return; if (c_list_in_list) { NEXT_ROW; putl(""); if (c_use_colors) attrset(COLOR_PAIR(LAYOUT_HEADER) | layout[LAYOUT_HEADER].attr); NEXT_ROW; putl(" # Tarjeta RX Tasa RX # " \ " TX Tasa TX #"); NEXT_ROW; hline(ACS_HLINE, cols); if (c_combined_node_list) foreach_node(draw_node, NULL); else draw_node(get_current_node(), NULL); } else { NEXT_ROW; hline(ACS_HLINE, cols); move(row, 24); addstr(" Press l to enable list view "); move(row, 0); } /* * calculate lines required for graphical and detailed stats unfolded */ if (c_graphical_in_list) required_lines += lines_required_for_graphical(); else required_lines++; if (c_detailed_in_list) required_lines += lines_required_for_detailed(); else required_lines++; if ((rows - row) <= (required_lines + 1)) { /* * not enough lines, start over with detailed stats disabled */ required_lines = 0; disable_detailed = 1; /* * 1 line for folded detailed stats display */ required_lines++; if (c_graphical_in_list) required_lines += lines_required_for_graphical(); else required_lines++; if ((rows - row) <= (required_lines + 1)) { /* * bad luck, not even enough space for graphical stats * reserve 2 lines for displaying folded detailed and * graphical stats */ required_lines = 2; disabled_graphical = 1; } } /* * Clear out spare space */ while (row < (rows - (required_lines + 2))) { NEXT_ROW; putl(""); } NEXT_ROW; hline(ACS_HLINE, cols); if (c_graphical_in_list) { if (disabled_graphical) { move(row, 15); addstr(" Increase screen size to see graphical statistics "); move(row, 0); } else draw_graphic(); } else { move(row, 20); addstr(" Press g to enable graphical statistics "); move(row, 0); } NEXT_ROW; hline(ACS_HLINE, cols); if (c_detailed_in_list) { if (disable_detailed) { move(row, 15); addstr(" Increase screen size to see detailed statistics "); move(row, 0); } else draw_detailed(); } else { move(row, 20); addstr(" Press d to enable detailed statistics "); move(row, 0); } }
static gboolean expose_event (GtkWidget *widget, GdkEventExpose *event) { widget_data_t *data = get_widget_data(widget); designer_node_t *hn = NULL; _hit_t hit; int hs = -1; cairo_t *cr = gdk_cairo_create( GTK_WIDGET (data->drawing_area)->window); cairo_set_source_rgb(cr, 0.9, 0.9, 0.9); cairo_paint(cr); _size_t delta = _ptos(data->visible_area.o); cairo_translate(cr, 0.5 - delta.w, 0.5 - delta.h); #if 0 cairo_set_line_width(cr, 3.0); cairo_set_source_rgba(cr, 0.3, 0.3, 0.3, 0.5); round_path(cr, data->used_area, round_s); cairo_stroke(cr); cairo_set_source_rgba(cr, 0.8, 0.6, 0.3, 0.5); round_path(cr, data->visible_area, round_s); cairo_stroke(cr); { char buf[32]; _point_t o = data->mouse; show_axis(cr, o, 0,0,0, 20, 20); set_title_font(cr); cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.8); cairo_move_to(cr, o.x + 5, o.y - 5); sprintf(buf, "(%.0f,%.0f)", o.x, o.y); cairo_show_text(cr, buf); cairo_stroke(cr); cairo_move_to(cr, o.x + 5, o.y + 13); sprintf(buf, "[%.0f,%.0f,%.0fx%.0f]", data->used_area.o.x, data->used_area.o.y, data->used_area.s.w, data->used_area.s.h); cairo_show_text(cr, buf); cairo_stroke(cr); cairo_move_to(cr, o.x + 5, o.y + 28); sprintf(buf, "[%.0f,%.0f,%.0fx%.0f]", data->visible_area.o.x, data->visible_area.o.y, data->visible_area.s.w, data->visible_area.s.h); cairo_show_text(cr, buf); cairo_stroke(cr); show_axis(cr, _zerop, 1,0,0, 10, 10); } #endif /* draw the slot conenctions */ for (GSList *list = data->design->nodes; list != NULL; list = list->next) { designer_node_t *dst = list->data; node_data_t *ndd = node_data(dst); calc_node_type(cr, dst->type); calc_node(cr, dst); for (GSList *slot_list = dst->input_slots; slot_list != NULL; slot_list = slot_list->next) { designer_slot_t *slot = slot_list->data; designer_node_t *src = slot->source; node_data_t *nsd = node_data(src); designer_slot_spec_t *src_spec = slot->output_slot_spec; designer_slot_spec_t *dst_spec = slot->input_slot_spec; slot_spec_data_t *ssd = slot_spec_data(src_spec); slot_spec_data_t *dsd = slot_spec_data(dst_spec); _point_t sp = _move(_move(nsd->or.o, _ptos(nsd->origin)), ssd->offset); _point_t dp = _move(_move(ndd->ir.o, _ptos(ndd->origin)), dsd->offset); draw_connect(cr, sp, dp, 0); } /* check for 'highest' node hit */ _hit_t nht = hit_node(dst, data->mouse); if (nht) { hn = dst; hit = nht; } } /* update target info */ switch (hit) { case HIT_INPUT: hs = hit_input_slot(hn, data->mouse); data->target = input_slot_origin(hn, hs); if (data->state == STATE_IDLE) /* show 'break' if already connected */ data->target_check = input_slot_check(hn, hs); else if (data->state == STATE_CONIN) data->target_check = DESIGNER_CONNECTION_UNCONNECTABLE; else if (data->state == STATE_CONOUT && ((hn != data->target_node) || (hs != data->target_slot_id))) data->target_check = connect_check( data->active_node, data->active_slot_id, hn, hs); break; case HIT_OUTPUT: hs = hit_output_slot(hn, data->mouse); data->target = output_slot_origin(hn, hs); if (data->state == STATE_IDLE) data->target_check = DESIGNER_CONNECTION_FREE; else if (data->state == STATE_CONOUT) data->target_check = DESIGNER_CONNECTION_UNCONNECTABLE; else if (data->state == STATE_CONIN && ((hn != data->target_node) || (hs != data->target_slot_id))) data->target_check = connect_check( hn, hs, data->active_node, data->active_slot_id); break; default: data->target_check = DESIGNER_CONNECTION_UNCONNECTABLE; hs = -1; break; } data->target_node = hn; data->target_slot_id = hs; /* draw the nodes */ for (GSList *list = data->design->nodes; list != NULL; list = list->next) { designer_node_t *node = list->data; int flags = (node == data->design->root) ? 0x1 : 0; draw_node(cr, node, flags); if (node == hn) { draw_highlight(cr, node, data->mouse, hit, data->target_check); } } if (data->state == STATE_CONIN) { draw_connect(cr, data->mouse, data->origin, 0); } if (data->state == STATE_CONOUT) { draw_connect(cr, data->origin, data->mouse, 0); } cairo_destroy(cr); return FALSE; }
static void draw_tree(cairo_t *cr, struct entry *e) { draw_node(cr, e, 0, 0, display_width, display_height); }
void ListNode::draw(const Cairo::RefPtr<Cairo::Context> & cr) { cr->set_source_rgb(1.0, 1.0, 1.0); draw_node(cr, x, y); cr->set_source_rgb(0.0, 0.0, 0.0); draw_text(cr, x, y); }
/* moves a sprite along the spline path */ void walk(void) { #define MAX_POINTS 256 int points[8]; int x[MAX_POINTS], y[MAX_POINTS]; int n, i; int npoints; int ox, oy; acquire_screen(); clear_to_color(screen, makecol(255, 255, 255)); for (i=1; i<node_count-1; i++) draw_node(i); release_screen(); do { poll_mouse(); } while (mouse_b); clear_keybuf(); ox = -16; oy = -16; xor_mode(TRUE); for (n=1; n < node_count-2; n++) { npoints = (fixtoi(node_dist(nodes[n], nodes[n+1]))+3) / 4; if (npoints < 1) npoints = 1; else if (npoints > MAX_POINTS) npoints = MAX_POINTS; get_control_points(nodes[n], nodes[n+1], points); calc_spline(points, npoints, x, y); for (i=1; i<npoints; i++) { vsync(); acquire_screen(); circlefill(screen, ox, oy, 6, palette_color[2]); circlefill(screen, x[i], y[i], 6, palette_color[2]); release_screen(); ox = x[i]; oy = y[i]; poll_mouse(); if ((keypressed()) || (mouse_b)) goto getout; } } getout: xor_mode(FALSE); do { poll_mouse(); } while (mouse_b); clear_keybuf(); }