// ---------------------------------------------------------------------------- void draw_segment(segment *seg) { short *svp; int nv; g3s_codes cc; if (seg->segnum == -1) //this segment doesn't exitst return; med_get_vertex_list(seg,&nv,&svp); // set nv = number of vertices, svp = pointer to vertex indices cc=rotate_list(nv,svp); if (! cc.and) { //all off screen? int i; for (i=0;i<4;i++) draw_line(svp[i],svp[i+4]); for (i=0;i<3;i++) { draw_line(svp[i] ,svp[i+1]); draw_line(svp[i+4],svp[i+4+1]); } draw_line(svp[0],svp[3]); draw_line(svp[0+4],svp[3+4]); } }
static void jffs2_rotate_lists(struct jffs2_sb_info *c) { uint32_t x; x = count_list(&c->clean_list); if (x) rotate_list((&c->clean_list), pseudo_random % x); x = count_list(&c->dirty_list); if (x) rotate_list((&c->dirty_list), pseudo_random % x); if (c->nr_erasing_blocks) rotate_list((&c->erase_pending_list), pseudo_random % c->nr_erasing_blocks); if (c->nr_free_blocks) /* Not that it should ever be zero */ rotate_list((&c->free_list), pseudo_random % c->nr_free_blocks); }
void draw_side_edge(segment *seg,int side,int edge) { short *svp; int nv; g3s_codes cc; med_get_vertex_list(seg,&nv,&svp); // set nv = number of vertices, svp = pointer to vertex indices cc=rotate_list(nv,svp); if (! cc.and) //on screen? draw_line(svp[Side_to_verts[side][edge]],svp[Side_to_verts[side][(edge+1)%4]]); }
static void put_max_in_last_pos(t_opt *opt) { int nbr_elem; int max; int pos; nbr_elem = get_nbr_elem(opt->a_heap_save); max = get_max(opt->a_heap_save, &pos); while ((*opt->a_heap_save)->nbr != max) choose_rx_rrx(opt->a_heap_save, nbr_elem, opt, 'a'); rotate_list(opt->a_heap_save); print_ft("ra", opt); }
int main(int argc, char* argv[]){ if (argc < 2) K = 2; else K = atoi(argv[1]); struct node *list = (struct node*)malloc(sizeof(struct node)); int arr[] = {1, 2, 3, 4, 5, 6}; fill_list(list, arr, 6); PRINT_LIST(list); rotate_list(&list); PRINT_LIST(list); exit(0); }
/* * @brief Driver function */ int main(int argc, char *argv[]) { node *head = NULL; /* Populate the list */ for (int i = 0; i < LEN; i++) head = add_node(head, i + 1); /* Print the state of the list before rearrangement */ print_list(head); /* Perform rotation on the list by K places */ head = rotate_list(head, K); /* Print the state of the list afterwards */ print_list(head); return 0; }
void jffs2_rotate_lists(struct jffs2_sb_info *c) { uint32_t x; uint32_t rotateby; x = count_list(&c->clean_list); if (x) { rotateby = pseudo_random % x; D1(printk(KERN_DEBUG "Rotating clean_list by %d\n", rotateby)); rotate_list((&c->clean_list), rotateby); D1(printk(KERN_DEBUG "Erase block at front of clean_list is at %08x\n", list_entry(c->clean_list.next, struct jffs2_eraseblock, list)->offset)); } else {
// ---------------------------------------------------------------------------- void draw_trigger_side(segment *seg,int side) { short *svp; int nv; g3s_codes cc; med_get_vertex_list(seg,&nv,&svp); // set nv = number of vertices, svp = pointer to vertex indices cc=rotate_list(nv,svp); if (! cc.and) { //all off screen? // Draw diagonals draw_line(svp[Side_to_verts[side][0]],svp[Side_to_verts[side][2]]); //g3_draw_line(svp[Side_to_verts[side][1]],svp[Side_to_verts[side][3]]); } }
// ---------------------------------------------------------------------------- void draw_seg_side(segment *seg,int side) { short *svp; int nv; g3s_codes cc; med_get_vertex_list(seg,&nv,&svp); // set nv = number of vertices, svp = pointer to vertex indices cc=rotate_list(nv,svp); if (! cc.and) { //all off screen? int i; for (i=0;i<3;i++) draw_line(svp[Side_to_verts[side][i]],svp[Side_to_verts[side][i+1]]); draw_line(svp[Side_to_verts[side][i]],svp[Side_to_verts[side][0]]); } }
static void push_step_to_b(t_opt *opt, int nbr_elem_lst, int i) { int count; count = nbr_elem_lst - opt->step * (i - 1); while (count) { if ((*opt->a_heap_save)->nbr >= opt->split) { push_src_to_dst(opt->a_heap_save, opt->b_heap_save); print_ft("pb", opt); } else { rotate_list(opt->a_heap_save); print_ft("ra", opt); } --count; } }
static void sort_step(t_heap **a_heap, t_heap **b_heap, t_opt *opt) { int nbr_elem; int max; int n; while ((nbr_elem = get_nbr_elem(b_heap))) { opt->pos = choice_min_or_max(b_heap, nbr_elem, &n, &max); while ((*b_heap)->nbr != n) choose_rx_rrx(b_heap, nbr_elem, opt, 'b'); push_src_to_dst(b_heap, a_heap); print_ft("pa", opt); if (n != max) { rotate_list(a_heap); print_ft("ra", opt); } } }
void swap_two_first_elem(t_heap **list) { t_heap *tmp; if (*list && *list != (*list)->next) { if (*list == (*list)->next->next) rotate_list(list); else { tmp = *list; *list = (*list)->next; tmp->next = (*list)->next; tmp->next->prev = tmp; (*list)->next = tmp; (*list)->prev = tmp->prev; tmp->prev->next = *list; tmp->prev = *list; } } }
//for looking for segment under a mouse click void check_segment(segment *seg) { short *svp; int nv; g3s_codes cc; med_get_vertex_list(seg,&nv,&svp); // set nv = number of vertices, svp = pointer to vertex indices cc=rotate_list(nv,svp); if (! cc.and) { //all off screen? int fn; gr_setcolor(0); gr_pixel(Search_x,Search_y); //set our search pixel to color zero gr_setcolor(1); //and render in color one for (fn=0;fn<6;fn++) { g3s_point *vert_list[4]; vert_list[0] = &Segment_points[seg->verts[Side_to_verts[fn][0]]]; vert_list[1] = &Segment_points[seg->verts[Side_to_verts[fn][1]]]; vert_list[2] = &Segment_points[seg->verts[Side_to_verts[fn][2]]]; g3_check_and_draw_poly(3,vert_list,NULL,NULL); vert_list[1] = &Segment_points[seg->verts[Side_to_verts[fn][2]]]; vert_list[2] = &Segment_points[seg->verts[Side_to_verts[fn][3]]]; g3_check_and_draw_poly(3,vert_list,NULL,NULL); } if (gr_ugpixel(&grd_curcanv->cv_bitmap,Search_x,Search_y) == 1) { if (N_found_segs < MAX_FOUND_SEGS) Found_segs[N_found_segs++] = SEG_PTR_2_NUM(seg); else Warning("Found too many segs! (limit=%d)",MAX_FOUND_SEGS); } } }
void jffs2_rotate_lists(struct jffs2_sb_info *c) { uint32_t x; uint32_t rotateby; x = count_list(&c->clean_list); if (x) { rotateby = pseudo_random % x; rotate_list((&c->clean_list), rotateby); } x = count_list(&c->very_dirty_list); if (x) { rotateby = pseudo_random % x; rotate_list((&c->very_dirty_list), rotateby); } x = count_list(&c->dirty_list); if (x) { rotateby = pseudo_random % x; rotate_list((&c->dirty_list), rotateby); } x = count_list(&c->erasable_list); if (x) { rotateby = pseudo_random % x; rotate_list((&c->erasable_list), rotateby); } if (c->nr_erasing_blocks) { rotateby = pseudo_random % c->nr_erasing_blocks; rotate_list((&c->erase_pending_list), rotateby); } if (c->nr_free_blocks) { rotateby = pseudo_random % c->nr_free_blocks; rotate_list((&c->free_list), rotateby); } }
// ----------------------------------------------------------------------------- void draw_coordinate_axes(void) { int i; short Axes_verts[16]; vms_vector tvec,xvec,yvec,zvec; for (i=0; i<16; i++) Axes_verts[i] = alloc_vert(); create_coordinate_axes_from_segment(Cursegp,Axes_verts); vm_vec_sub(&xvec,&Vertices[Axes_verts[1]],&Vertices[Axes_verts[0]]); vm_vec_sub(&yvec,&Vertices[Axes_verts[2]],&Vertices[Axes_verts[0]]); vm_vec_sub(&zvec,&Vertices[Axes_verts[3]],&Vertices[Axes_verts[0]]); // Create the letter X tvec = xvec; vm_vec_add(&Vertices[Axes_verts[4]],&Vertices[Axes_verts[1]],vm_vec_scale(&tvec,F1_0/16)); tvec = yvec; vm_vec_add2(&Vertices[Axes_verts[4]],vm_vec_scale(&tvec,F1_0/8)); vm_vec_sub(&Vertices[Axes_verts[6]],&Vertices[Axes_verts[4]],vm_vec_scale(&tvec,F2_0)); tvec = xvec; vm_vec_scale(&tvec,F1_0/8); vm_vec_add(&Vertices[Axes_verts[7]],&Vertices[Axes_verts[4]],&tvec); vm_vec_add(&Vertices[Axes_verts[5]],&Vertices[Axes_verts[6]],&tvec); // Create the letter Y tvec = yvec; vm_vec_add(&Vertices[Axes_verts[11]],&Vertices[Axes_verts[2]],vm_vec_scale(&tvec,F1_0/16)); vm_vec_add(&Vertices[Axes_verts[8]],&Vertices[Axes_verts[11]],&tvec); vm_vec_add(&Vertices[Axes_verts[9]],&Vertices[Axes_verts[11]],vm_vec_scale(&tvec,F1_0*2)); vm_vec_add(&Vertices[Axes_verts[10]],&Vertices[Axes_verts[11]],&tvec); tvec = xvec; vm_vec_scale(&tvec,F1_0/16); vm_vec_sub2(&Vertices[Axes_verts[9]],&tvec); vm_vec_add2(&Vertices[Axes_verts[10]],&tvec); // Create the letter Z tvec = zvec; vm_vec_add(&Vertices[Axes_verts[12]],&Vertices[Axes_verts[3]],vm_vec_scale(&tvec,F1_0/16)); tvec = yvec; vm_vec_add2(&Vertices[Axes_verts[12]],vm_vec_scale(&tvec,F1_0/8)); vm_vec_sub(&Vertices[Axes_verts[14]],&Vertices[Axes_verts[12]],vm_vec_scale(&tvec,F2_0)); tvec = zvec; vm_vec_scale(&tvec,F1_0/8); vm_vec_add(&Vertices[Axes_verts[13]],&Vertices[Axes_verts[12]],&tvec); vm_vec_add(&Vertices[Axes_verts[15]],&Vertices[Axes_verts[14]],&tvec); rotate_list(16,Axes_verts); gr_setcolor(AXIS_COLOR); draw_line(Axes_verts[0],Axes_verts[1]); draw_line(Axes_verts[0],Axes_verts[2]); draw_line(Axes_verts[0],Axes_verts[3]); // draw the letter X draw_line(Axes_verts[4],Axes_verts[5]); draw_line(Axes_verts[6],Axes_verts[7]); // draw the letter Y draw_line(Axes_verts[8],Axes_verts[9]); draw_line(Axes_verts[8],Axes_verts[10]); draw_line(Axes_verts[8],Axes_verts[11]); // draw the letter Z draw_line(Axes_verts[12],Axes_verts[13]); draw_line(Axes_verts[13],Axes_verts[14]); draw_line(Axes_verts[14],Axes_verts[15]); for (i=0; i<16; i++) free_vert(Axes_verts[i]); }
//adds a segment's edges to the edge list void add_edges(segment *seg) { short *svp; int nv; g3s_codes cc; med_get_vertex_list(seg,&nv,&svp); // set nv = number of vertices, svp = pointer to vertex indices cc=rotate_list(nv,svp); if (! cc.and) { //all off screen? int i,sn,fn,vn; int flag; ubyte edge_flags[N_EDGES_PER_SEGMENT]; for (i=0;i<N_NORMAL_EDGES;i++) edge_flags[i]=ET_NOTUSED; for (;i<N_EDGES_PER_SEGMENT;i++) edge_flags[i]=ET_NOTEXTANT; for (sn=0;sn<MAX_SIDES_PER_SEGMENT;sn++) { side *sidep = &seg->sides[sn]; int num_faces, num_vertices; int vertex_list[6]; create_all_vertex_lists(&num_faces, vertex_list, seg-Segments, sn); if (num_faces == 1) num_vertices = 4; else num_vertices = 3; for (fn=0; fn<num_faces; fn++) { int en; int *v0; //Note: normal check appears to be the wrong way since the normals points in, but we're looking from the outside if (g3_check_normal_facing(&Vertices[seg->verts[vertex_list[fn*3]]],&sidep->normals[fn])) flag = ET_NOTFACING; else flag = ET_FACING; v0 = &vertex_list[fn*3]; for (vn=0; vn<num_vertices-1; vn++) { // en = find_edge_num(vertex_list[fn*3 + vn], vertex_list[fn*3 + (vn+1)%num_vertices]); en = find_edge_num(*v0, *(v0+1)); if (en!=-1) if (flag < edge_flags[en]) edge_flags[en] = flag; v0++; } en = find_edge_num(*v0, vertex_list[fn*3]); if (en!=-1) if (flag < edge_flags[en]) edge_flags[en] = flag; } } for (i=0; i<N_EDGES_PER_SEGMENT; i++) if (i<N_NORMAL_EDGES || (edge_flags[i]!=ET_NOTEXTANT && Show_triangulations)) add_edge(seg->verts[edges[i]/8],seg->verts[edges[i]&7],edge_flags[i]); } }
/*------------------------------------- * Node Parenting -------------------------------------*/ bool SceneGraph::reparent_node(const unsigned nodeIndex, const unsigned newParentId) noexcept { if (nodeIndex == scene_property_t::SCENE_GRAPH_ROOT_ID) { return false; } if (node_is_child(newParentId, nodeIndex)) { LS_LOG_MSG("Cannot make a node ", nodeIndex, " a parent of its ancestor ", newParentId, '.'); return false; } LS_DEBUG_ASSERT(nodeIndex < nodes.size()); const unsigned numChildren = get_num_total_children(nodeIndex); const unsigned displacement = 1 + numChildren; const unsigned numNewSiblings = get_num_total_children(newParentId); const unsigned newNodeIndex = 1 + newParentId + numNewSiblings; // Keep track of the range of elements which need to be updated. const unsigned effectStart = math::min(nodeIndex, newNodeIndex); const unsigned effectEnd = math::max(newNodeIndex, nodeIndex+displacement); // Sentinel to help determine not to modify the node at 'nodeIndex' const bool movingUp = nodeIndex < newParentId; /* LS_LOG_MSG( "Re-parenting node ", nodeIndex, " from ", currentTransforms[nodeIndex].parentId, " to ", newParentId, ".\nRotating ", displacement, " indices from ", nodeIndex, " to ", newNodeIndex, " and updating node indices between ", effectStart, '-', effectEnd ); */ rotate_list(nodes, nodeIndex, displacement, newNodeIndex); rotate_list(baseTransforms, nodeIndex, displacement, newNodeIndex); rotate_list(currentTransforms, nodeIndex, displacement, newNodeIndex); rotate_list(modelMatrices, nodeIndex, displacement, newNodeIndex); for (unsigned i = effectStart; i < effectEnd; ++i) { unsigned& rParentId = currentTransforms[i].parentId; const unsigned pId = rParentId; const unsigned nId = nodes[i].nodeId; nodes[i].nodeId = i; // Update the requested node's index if (nId == nodeIndex) { rParentId = movingUp ? (newParentId-displacement) : newParentId; currentTransforms[i].set_dirty(); continue; } // Determine if there's a node which even needs its parent ID updated. if (pId == scene_property_t::SCENE_GRAPH_ROOT_ID || pId < effectStart) { continue; } const unsigned parentDelta = nId - pId; //LS_LOG_MSG("\t\tMoving ", i, "'s (", nId, ") parent ID by ", parentDelta, " from ", pId, " to ", i-parentDelta); rParentId = i - parentDelta; currentTransforms[i].set_dirty(); } /* std::cout << "To this:"; std::cout << "\n\t"; print_list(nodes); std::cout << "\t"; print_list(currentTransforms); */ // Animations need love too static_assert(sizeof(unsigned) == sizeof(uint32_t), "Cannot update indices of differing types."); for (Animation& anim : animations) { for (uint32_t& oldId : anim.transformIds) { const uint32_t newId = nodes[oldId].nodeId; const uint32_t nodeDelta = math::max(oldId, newId) - math::min(oldId, newId); oldId = (newId >= oldId) ? (oldId+nodeDelta) : (oldId-nodeDelta); } } //LS_LOG_MSG("\tDone."); LS_DEBUG_ASSERT(newNodeIndex <= nodes.size()); return true; }
void draw_all_edges(automap *am) { g3s_codes cc; int i,j,nbright; ubyte nfacing,nnfacing; Edge_info *e; vms_vector *tv1; fix distance; fix min_distance = 0x7fffffff; g3s_point *p1, *p2; nbright=0; for (i=0; i<=am->highest_edge_index; i++ ) { //e = &am->edges[Edge_used_list[i]]; e = &am->edges[i]; if (!(e->flags & EF_USED)) continue; if ( e->flags & EF_TOO_FAR) continue; if (e->flags&EF_FRONTIER) { // A line that is between what we have seen and what we haven't if ( (!(e->flags&EF_SECRET))&&(e->color==am->wall_normal_color)) continue; // If a line isn't secret and is normal color, then don't draw it } cc=rotate_list(2,e->verts); distance = Segment_points[e->verts[1]].p3_z; if (min_distance>distance ) min_distance = distance; if (!cc.uand) { //all off screen? nfacing = nnfacing = 0; tv1 = &Vertices[e->verts[0]]; j = 0; while( j<e->num_faces && (nfacing==0 || nnfacing==0) ) { #ifdef COMPACT_SEGS vms_vector temp_v; get_side_normal(&Segments[e->segnum[j]], e->sides[j], 0, &temp_v ); if (!g3_check_normal_facing( tv1, &temp_v ) ) #else if (!g3_check_normal_facing( tv1, &Segments[e->segnum[j]].sides[e->sides[j]].normals[0] ) ) #endif nfacing++; else nnfacing++; j++; } if ( nfacing && nnfacing ) { // a contour line am->drawingListBright[nbright++] = e-am->edges; } else if ( e->flags&(EF_DEFINING|EF_GRATE) ) { if ( nfacing == 0 ) { if ( e->flags & EF_NO_FADE ) gr_setcolor( e->color ); else gr_setcolor( gr_fade_table[e->color+256*8] ); g3_draw_line( &Segment_points[e->verts[0]], &Segment_points[e->verts[1]] ); } else { am->drawingListBright[nbright++] = e-am->edges; } } } } if ( min_distance < 0 ) min_distance = 0; // Sort the bright ones using a shell sort { int t; int i, j, incr, v1, v2; incr = nbright / 2; while( incr > 0 ) { for (i=incr; i<nbright; i++ ) { j = i - incr; while (j>=0 ) { // compare element j and j+incr v1 = am->edges[am->drawingListBright[j]].verts[0]; v2 = am->edges[am->drawingListBright[j+incr]].verts[0]; if (Segment_points[v1].p3_z < Segment_points[v2].p3_z) { // If not in correct order, them swap 'em t=am->drawingListBright[j+incr]; am->drawingListBright[j+incr]=am->drawingListBright[j]; am->drawingListBright[j]=t; j -= incr; } else break; } } incr = incr / 2; } } // Draw the bright ones for (i=0; i<nbright; i++ ) { int color; fix dist; e = &am->edges[am->drawingListBright[i]]; p1 = &Segment_points[e->verts[0]]; p2 = &Segment_points[e->verts[1]]; dist = p1->p3_z - min_distance; // Make distance be 1.0 to 0.0, where 0.0 is 10 segments away; if ( dist < 0 ) dist=0; if ( dist >= am->farthest_dist ) continue; if ( e->flags & EF_NO_FADE ) { gr_setcolor( e->color ); } else { dist = F1_0 - fixdiv( dist, am->farthest_dist ); color = f2i( dist*31 ); gr_setcolor( gr_fade_table[e->color+color*256] ); } g3_draw_line( p1, p2 ); } }