static SHIP_FRAGMENT * LockSupportShip (ROSTER_STATE *rosterState, HSHIPFRAG *phFrag) { const POINT *pship_pos; HSHIPFRAG hStarShip, hNextShip; // Lookup the current escort's location in the unsorted points list // to find the original escort index for (hStarShip = GetHeadLink (&GLOBAL (built_ship_q)), pship_pos = ship_pos; hStarShip; hStarShip = hNextShip, ++pship_pos) { SHIP_FRAGMENT *StarShipPtr; StarShipPtr = LockShipFrag (&GLOBAL (built_ship_q), hStarShip); if (pointsEqual (*pship_pos, rosterState->curShipPt)) { *phFrag = hStarShip; return StarShipPtr; } hNextShip = _GetSuccLink (StarShipPtr); UnlockShipFrag (&GLOBAL (built_ship_q), hStarShip); } return NULL; }
void pamd_line(tuple ** const tuples, int const cols, int const rows, int const depth, sample const maxval, pamd_point const p0, pamd_point const p1, pamd_drawproc drawProc, const void * const clientdata) { pamd_point c0, c1; bool noLine; /* There's no line left after clipping */ pamd_validateCoord(cols); pamd_validateCoord(rows); pamd_validatePoint(p0); pamd_validatePoint(p1); if (lineclip) { clipLine(p0, p1, cols, rows, &c0, &c1, &noLine); } else { c0 = p0; c1 = p1; noLine = FALSE; } if (noLine) { /* Nothing to draw */ } else if (pointsEqual(c0, c1)) { /* This line is just a point. Because there aren't two distinct endpoints, we have a special case. */ drawPoint(drawProc, clientdata, tuples, cols, rows, depth, maxval, c0); } else { /* Draw, using a simple DDA. */ if (abs(c1.x - c0.x) > abs(c1.y - c0.y)) drawShallowLine(drawProc, clientdata, tuples, cols, rows, depth, maxval, c0, c1); else drawSteepLine(drawProc, clientdata, tuples, cols, rows, depth, maxval, c0, c1); } }
void pamd_circle(tuple ** const tuples, unsigned int const cols, unsigned int const rows, unsigned int const depth, sample const maxval, pamd_point const center, unsigned int const radius, pamd_drawproc drawProc, const void * const clientData) { /*---------------------------------------------------------------------------- If lineclip mode is on, draw only points within the image. If lineclip is off, "draw" all points (by designated drawproc). Note that the drawproc can't actually draw a point outside the image, but it might maintain state that is affected by imaginary points outside the image. Initial point is 3 o'clock. -----------------------------------------------------------------------------*/ if (radius >= DDA_SCALE) pm_error("Error drawing circle. Radius %d is too large.", radius); pamd_validateCoord(center.x + radius); pamd_validateCoord(center.y + radius); pamd_validateCoord(center.x - radius); pamd_validateCoord(center.y - radius); if (radius > 0) { long const e = DDA_SCALE / radius; pamd_point const p0 = makePoint(radius, 0); /* 3 o'clock */ /* The starting point around the circle, assuming (0, 0) center */ pamd_point p; /* Current drawing position in the circle, assuming (0,0) center */ bool onFirstPoint; bool prevPointExists; pamd_point prevPoint; /* Previous drawing position, assuming (0, 0) center*/ long sx, sy; /* 'p', scaled by DDA_SCALE */ p = p0; sx = p.x * DDA_SCALE + DDA_SCALE / 2; sy = p.y * DDA_SCALE + DDA_SCALE / 2; onFirstPoint = TRUE; prevPointExists = FALSE; while (onFirstPoint || !pointsEqual(p, p0)) { if (prevPointExists && pointsEqual(p, prevPoint)) { /* We're on the same point we were on last time (we moved less than a point's worth). Just keep moving. */ } else { pamd_point const imagePoint = vectorSum(center,p); if (!lineclip || pointIsWithinBounds(imagePoint, cols, rows)) drawPoint(drawProc, clientData, tuples, cols, rows, depth, maxval, imagePoint); prevPoint = p; prevPointExists = TRUE; } if (!pointsEqual(p, p0)) onFirstPoint = FALSE; sx += e * sy / DDA_SCALE; sy -= e * sx / DDA_SCALE; p = makePoint(sx / DDA_SCALE, sy / DDA_SCALE); } } }