int main() { ITEMTYPE removed; Dlist *dl = create_dlist(); add_last_dlist(dl,10); add_last_dlist(dl,20); add_last_dlist(dl,30); add_last_dlist(dl,40); add_dlist(dl,70,1); add_dlist(dl,80,0); remove_dlist(dl,5,&removed); remove_dlist(dl,2,&removed); remove_dlist(dl,0,&removed); set_dlist(dl,0,35); remove_element_dlist(dl,20); remove_dlist(dl,0,&removed); print_dlist(dl); int n; get_dlist(dl,0,&n); printf("testando get_dlist(dl,0,&n) = %d\n",n); return 0; }
static void generate_system (ModeInfo * mi) { pipesstruct *pp = &pipes[MI_SCREEN(mi)]; Bool wire = MI_IS_WIREFRAME(mi); int newdir; int OPX, OPY, OPZ; Bool reset_p = False; pp->system_index = 0; pp->system_size = 0; pinit (mi, 1); while (1) { glNewList (get_dlist (mi, pp->system_size++), GL_COMPILE); mi->polygon_count = 0; glPushMatrix(); FindNeighbors(mi); if (wire) glColor4fv (pp->system_color); else glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color); /* If it's the begining of a system, draw a sphere */ if (pp->olddir == dirNone) { glPushMatrix(); glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0); mySphere(0.6, wire); glPopMatrix(); } /* Check for stop conditions */ if (pp->ndirections == 0 || pp->counter > pp->system_length) { glPushMatrix(); glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0); /* Finish the system with another sphere */ mySphere(0.6, wire); glPopMatrix(); /* If the maximum number of system was drawn, restart (clearing the screen), */ /* else start a new system. */ if (++pp->system_number > pp->number_of_systems) { reset_p = True; } else { pinit(mi, 0); } goto NEXT; } pp->counter++; pp->turncounter++; /* Do will the direction change? if so, determine the new one */ newdir = pp->nowdir; if (!pp->directions[newdir]) { /* cannot proceed in the current direction */ newdir = SelectNeighbor(mi); } else { if (tightturns) { /* random change (20% chance) */ if ((pp->counter > 1) && (NRAND(100) < 20)) { newdir = SelectNeighbor(mi); } } else { /* Chance to turn increases after each length of pipe drawn */ if ((pp->counter > 1) && NRAND(50) < NRAND(pp->turncounter + 1)) { newdir = SelectNeighbor(mi); pp->turncounter = 0; } } } /* Has the direction changed? */ if (newdir == pp->nowdir) { /* If not, draw the cell's center pipe */ glPushMatrix(); glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0); /* Chance of factory shape here, if enabled. */ if ((pp->counter > 1) && (NRAND(100) < factory)) { MakeShape(mi, newdir); } else { MakeTube(mi, newdir); } glPopMatrix(); } else { /* If so, draw the cell's center elbow/sphere */ int sysT = pp->system_type; if (sysT == NofSysTypes + 1) { sysT = ((pp->system_number - 1) % NofSysTypes) + 1; } glPushMatrix(); switch (sysT) { case 1: glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0); mySphere(elbowradius, wire); break; case 2: case 3: switch (pp->nowdir) { case dirUP: switch (newdir) { case dirLEFT: glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0); glRotatef(180.0, 1.0, 0.0, 0.0); break; case dirRIGHT: glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0); glRotatef(180.0, 1.0, 0.0, 0.0); glRotatef(180.0, 0.0, 1.0, 0.0); break; case dirFAR: glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0 - (one_third)); glRotatef(90.0, 0.0, 1.0, 0.0); glRotatef(180.0, 0.0, 0.0, 1.0); break; case dirNEAR: glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0 + (one_third)); glRotatef(90.0, 0.0, 1.0, 0.0); glRotatef(180.0, 1.0, 0.0, 0.0); break; } break; case dirDOWN: switch (newdir) { case dirLEFT: glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0); break; case dirRIGHT: glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0); glRotatef(180.0, 0.0, 1.0, 0.0); break; case dirFAR: glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0 - (one_third)); glRotatef(270.0, 0.0, 1.0, 0.0); break; case dirNEAR: glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0 + (one_third)); glRotatef(90.0, 0.0, 1.0, 0.0); break; } break; case dirLEFT: switch (newdir) { case dirUP: glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0); glRotatef(180.0, 0.0, 1.0, 0.0); break; case dirDOWN: glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0); glRotatef(180.0, 1.0, 0.0, 0.0); glRotatef(180.0, 0.0, 1.0, 0.0); break; case dirFAR: glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 - (one_third)); glRotatef(270.0, 1.0, 0.0, 0.0); glRotatef(180.0, 0.0, 1.0, 0.0); break; case dirNEAR: glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 + (one_third)); glRotatef(270.0, 1.0, 0.0, 0.0); glRotatef(180.0, 0.0, 0.0, 1.0); break; } break; case dirRIGHT: switch (newdir) { case dirUP: glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0); break; case dirDOWN: glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0); glRotatef(180.0, 1.0, 0.0, 0.0); break; case dirFAR: glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 - (one_third)); glRotatef(270.0, 1.0, 0.0, 0.0); break; case dirNEAR: glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 + (one_third)); glRotatef(90.0, 1.0, 0.0, 0.0); break; } break; case dirNEAR: switch (newdir) { case dirLEFT: glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 - (one_third)); glRotatef(270.0, 1.0, 0.0, 0.0); break; case dirRIGHT: glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 - (one_third)); glRotatef(270.0, 1.0, 0.0, 0.0); glRotatef(180.0, 0.0, 1.0, 0.0); break; case dirUP: glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0 - (one_third)); glRotatef(270.0, 0.0, 1.0, 0.0); break; case dirDOWN: glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0 - (one_third)); glRotatef(90.0, 0.0, 1.0, 0.0); glRotatef(180.0, 0.0, 0.0, 1.0); break; } break; case dirFAR: switch (newdir) { case dirUP: glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0 + (one_third)); glRotatef(90.0, 0.0, 1.0, 0.0); break; case dirDOWN: glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0 + (one_third)); glRotatef(90.0, 0.0, 1.0, 0.0); glRotatef(180.0, 1.0, 0.0, 0.0); break; case dirLEFT: glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 + (one_third)); glRotatef(90.0, 1.0, 0.0, 0.0); break; case dirRIGHT: glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 + (one_third)); glRotatef(270.0, 1.0, 0.0, 0.0); glRotatef(180.0, 0.0, 0.0, 1.0); break; } break; } myElbow(mi, (sysT == 2)); break; } glPopMatrix(); } OPX = pp->PX; OPY = pp->PY; OPZ = pp->PZ; pp->olddir = pp->nowdir; pp->nowdir = newdir; switch (pp->nowdir) { case dirUP: pp->PY++; break; case dirDOWN: pp->PY--; break; case dirLEFT: pp->PX--; break; case dirRIGHT: pp->PX++; break; case dirNEAR: pp->PZ++; break; case dirFAR: pp->PZ--; break; } pp->Cells[pp->PX][pp->PY][pp->PZ] = 1; /* Cells'face pipe */ glTranslatef(((pp->PX + OPX) / 2.0 - 16) / 3.0 * 4.0, ((pp->PY + OPY) / 2.0 - 12) / 3.0 * 4.0, ((pp->PZ + OPZ) / 2.0 - 16) / 3.0 * 4.0); MakeTube(mi, newdir); NEXT: glPopMatrix(); glEndList(); pp->poly_counts [pp->system_size-1] = mi->polygon_count; if (reset_p) break; } }