static void bubble_preprocess (ELEMENT *ElementPtr) { BYTE thrust_wait, turn_wait; thrust_wait = HINIBBLE (ElementPtr->turn_wait); turn_wait = LONIBBLE (ElementPtr->turn_wait); if (thrust_wait > 0) --thrust_wait; else { ElementPtr->next.image.frame = IncFrameIndex (ElementPtr->current.image.frame); ElementPtr->state_flags |= CHANGING; thrust_wait = (BYTE)((COUNT)TFB_Random () & 3); } if (turn_wait > 0) --turn_wait; else { COUNT facing; SIZE delta_facing; facing = NORMALIZE_FACING (ANGLE_TO_FACING ( GetVelocityTravelAngle (&ElementPtr->velocity))); if ((delta_facing = TrackShip (ElementPtr, &facing)) == -1) facing = (COUNT)TFB_Random (); else if (delta_facing <= ANGLE_TO_FACING (HALF_CIRCLE)) facing += (COUNT)TFB_Random () & (ANGLE_TO_FACING (HALF_CIRCLE) - 1); else facing -= (COUNT)TFB_Random () & (ANGLE_TO_FACING (HALF_CIRCLE) - 1); SetVelocityVector (&ElementPtr->velocity, MISSILE_SPEED, facing); #define TRACK_WAIT 2 turn_wait = TRACK_WAIT; } ElementPtr->turn_wait = MAKE_BYTE (turn_wait, thrust_wait); }
static void blaster_preprocess (ELEMENT *ElementPtr) { BYTE wait; switch (ElementPtr->mass_points) { case BLASTER_DAMAGE * 1: if (GetFrameIndex (ElementPtr->current.image.frame) < 8) { ElementPtr->next.image.frame = IncFrameIndex (ElementPtr->current.image.frame); ElementPtr->state_flags |= CHANGING; } break; case BLASTER_DAMAGE * 3: if (GetFrameIndex (ElementPtr->current.image.frame) < 19) ElementPtr->next.image.frame = IncFrameIndex (ElementPtr->current.image.frame); else ElementPtr->next.image.frame = SetAbsFrameIndex (ElementPtr->current.image.frame, 16); ElementPtr->state_flags |= CHANGING; break; } if (LONIBBLE (ElementPtr->turn_wait)) --ElementPtr->turn_wait; else if ((wait = HINIBBLE (ElementPtr->turn_wait))) { COUNT facing; facing = NORMALIZE_FACING (ANGLE_TO_FACING ( GetVelocityTravelAngle (&ElementPtr->velocity))); if (TrackShip (ElementPtr, &facing) > 0) SetVelocityVector (&ElementPtr->velocity, BLASTER_SPEED, facing); ElementPtr->turn_wait = MAKE_BYTE (wait, wait); } }
/* * Given a buffer that holds a cookie (and therefore has an idea * of the current position within the cookie), parse the next * name / value pair out of it. * * A cookie will have the form: * * name1 = value1; name2=value2;name3 =value3;... * * As the example shows, there may be annoying whitespace embedded * within the name=value components. What we do here is to run a * state machine that keeps track of the following states: * * URI_STATE_START Start parsing * URI_STATE_NAME Parsing name component * URI_STATE_EQUALS Just saw the '=' between name and value * URI_STATE_VALUE Parsing the value component * URI_STATE_END End parsing * URI_STATE_ERROR Error while parsing * * In order to achieve the maximum performance, this state machine * is represented in a precomputed table called uri_state_tbl[c][s], * whose values depend on the current character and current state. * This table (as well as the other tables that ease the process * of URL encoding and decoding) was generated with a C program, * which can be found in tools/encode/encode. */ Buffer* cookie_get_pair(Buffer* cookie, Buffer* name, Buffer* value) { int ncur = name->pos; int vcur = value->pos; int vend = 0; int state = 0; int current = 0; /* State machine starts in URI_STATE_START state and * will loop until we enter any state that is * >= URI_STATE_TERMINATE */ for (state = URI_STATE_START; state < URI_STATE_TERMINATE; ) { /* Switch to next state based on last character read * and current state. */ current = cookie->data[cookie->pos]; state = uri_state_tbl[current][state]; switch (state) { /* If we are reading the name part, add the current * character (possibly URL-decoded) */ case URI_STATE_NAME: buffer_ensure_unused(name, 1); if (current == '%' && isxdigit(cookie->data[cookie->pos+1]) && isxdigit(cookie->data[cookie->pos+2])) { /* put a byte together from the next two hex digits */ name->data[name->pos++] = MAKE_BYTE(uri_decode_tbl[(int)cookie->data[cookie->pos+1]], uri_decode_tbl[(int)cookie->data[cookie->pos+2]]); cookie->pos += 3; } else { /* just copy current character */ name->data[name->pos++] = current; ++cookie->pos; } break; /* If we are reading the value part, add the current * character (possibly URL-decoded) */ case URI_STATE_VALUE: buffer_ensure_unused(value, 1); if (current == '%' && isxdigit(cookie->data[cookie->pos+1]) && isxdigit(cookie->data[cookie->pos+2])) { /* put a byte together from the next two hex digits */ value->data[value->pos++] = MAKE_BYTE(uri_decode_tbl[(int)cookie->data[cookie->pos+1]], uri_decode_tbl[(int)cookie->data[cookie->pos+2]]); cookie->pos += 3; vend = value->pos; } else { /* just copy current character */ value->data[value->pos++] = current; ++cookie->pos; if (!isspace(current)) { vend = value->pos; } } break; /* Any other state, just move to the next position. */ default: ++cookie->pos; break; } } /* If last character seen was EOS, we have already incremented * the buffer position once too many; correct that. */ if (current == '\0') { --cookie->pos; } /* If we didn't end in URI_STATE_END, reset buffers. */ if (state != URI_STATE_END) { name->pos = ncur; value->pos = vcur; } else { /* Maybe correct end position for value. */ if (vend) { value->pos = vend; } } /* Terminate both output buffers and return. */ buffer_terminate(name); buffer_terminate(value); return cookie; }