예제 #1
0
RectRawf *Rectf_United(Rectf const *rect, Rectf const *other, RectRawf *united)
{
    RectRawf normA, normB;

    if(!united) return NULL;

    if(!other)
    {
        united->origin.x = Point2f_X(rect->origin);
        united->origin.y = Point2f_Y(rect->origin);
        united->size.width  = Size2f_Width(rect->size);
        united->size.height = Size2f_Height(rect->size);
        return united;
    }

    Rectf_Normalized(rect, &normA);
    Rectf_Normalized(other, &normB);

    united->origin.x = MIN_OF(normA.origin.x, normB.origin.x);
    united->origin.y = MIN_OF(normA.origin.y, normB.origin.y);

    united->size.width  = MAX_OF(normA.origin.x + normA.size.width,
                                 normB.origin.x + normB.size.width)  - united->origin.x;
    united->size.height = MAX_OF(normA.origin.y + normA.size.height,
                                 normB.origin.y + normB.size.height) - united->origin.y;

    return united;
}
예제 #2
0
static void timeDeltaStatistics(int deltaMs)
{
    timeDeltas[timeDeltasIndex++] = deltaMs;
    if(timeDeltasIndex == NUM_FRAMETIME_DELTAS)
    {
        timeDeltasIndex = 0;

        if(devShowFrameTimeDeltas)
        {
            int maxDelta = timeDeltas[0], minDelta = timeDeltas[0];
            float average = 0, variance = 0;
            int lateCount = 0;
            int i;
            for(i = 0; i < NUM_FRAMETIME_DELTAS; ++i)
            {
                maxDelta = MAX_OF(timeDeltas[i], maxDelta);
                minDelta = MIN_OF(timeDeltas[i], minDelta);
                average += timeDeltas[i];
                variance += timeDeltas[i] * timeDeltas[i];
                if(timeDeltas[i] > 0) lateCount++;
            }
            average /= NUM_FRAMETIME_DELTAS;
            variance /= NUM_FRAMETIME_DELTAS;
            Con_Message("Time deltas [%i frames]: min=%-6i max=%-6i avg=%-11.7f late=%5.1f%% var=%12.10f",
                        NUM_FRAMETIME_DELTAS, minDelta, maxDelta, average,
                        lateCount/(float)NUM_FRAMETIME_DELTAS*100,
                        variance);
        }
    }
}
예제 #3
0
void SetMachineParameters( void )
{
  double dval;
  DB_MSG(("-->SetMachineParameters\n"));

  
  if( ParxRelsParHasValue("ACQ_word_size") == No )
  {
    ACQ_word_size = _32_BIT;
  }
  
  dval = PVM_GradDelayTime + PVM_2dPhaseGradientTime - 0.01;
  dval = MAX_OF(PVM_DigEndDelOpt,dval);

  DEOSC = (PVM_AcquisitionTime  + dval)*1000.0;
  ACQ_scan_shift = -1;
  ParxRelsParRelations("ACQ_scan_shift",Yes);
  
  DE = DE < 6.0 ? 6.0: DE;
  
  
  PAPS = QP;
  
  ACQ_BF_enable = Yes;
  
  DB_MSG(("<--SetMachineParameters\n"));
}
예제 #4
0
static int textFragmentHeight(const char* fragment)
{
    assert(NULL != fragment);
    {
    const char* ch;
    unsigned char c;
    int height = 0;
    size_t len;
    uint i;

    if(fr.fontNum == 0)
    {
        Con_Error("textFragmentHeight: Cannot determine height without a current font.");
        exit(1);
    }

    // Find the greatest height.
    i = 0;
    height = 0;
    len = strlen(fragment);
    ch = fragment;
    while(i++ < len && (c = *ch++) != 0 && c != '\n')
    {
        height = MAX_OF(height, FR_CharHeight(c));
    }

    return topToAscent(Fonts_ToFont(fr.fontNum)) + height;
    }
}
예제 #5
0
/**
 * Subtract the appropriate amount of ammo from the player for firing
 * the current ready weapon.
 *
 * @param player        The player doing the firing.
 */
void P_ShotAmmo(player_t *player)
{
    ammotype_t          i;
    int                 fireMode;
    weaponinfo_t*       wInfo =
        &weaponInfo[player->readyWeapon][player->class_];

    if(IS_CLIENT) return; // Server keeps track of this.

#if __JHERETIC__
    if(deathmatch)
        fireMode = 0; // In deathmatch always use mode zero.
    else
        fireMode = (player->powers[PT_WEAPONLEVEL2]? 1 : 0);
#else
    fireMode = 0;
#endif

    for(i = 0; i < NUM_AMMO_TYPES; ++i)
    {
        if(!wInfo->mode[fireMode].ammoType[i])
            continue; // Weapon does not take this ammo.

        // Don't let it fall below zero.
        player->ammo[i].owned = MAX_OF(0,
            player->ammo[i].owned - wInfo->mode[fireMode].perShot[i]);
    }
    player->update |= PSF_AMMO;
}
예제 #6
0
/// @pre  This and @a other have been normalized.
static Rectf *Rectf_UniteRaw2(Rectf *r, RectRawf const *other)
{
    Point2Rawf oldOrigin;
    DENG_ASSERT(r && other);

    Point2f_Raw(r->origin, &oldOrigin);

    Rectf_SetXY(r, MIN_OF(Point2f_X(r->origin), other->origin.x),
                   MIN_OF(Point2f_Y(r->origin), other->origin.y));

    Rectf_SetWidthHeight(r, MAX_OF(oldOrigin.x + Size2f_Width(r->size),
                                   other->origin.x + other->size.width)  - Point2f_X(r->origin),
                            MAX_OF(oldOrigin.y + Size2f_Height(r->size),
                                   other->origin.y + other->size.height) - Point2f_Y(r->origin));

    return r;
}
예제 #7
0
void UIChat_UpdateGeometry(uiwidget_t* obj)
{
    const char* text = UIChat_Text(obj);
    assert(obj->type == GUI_CHAT);

    Rect_SetWidthHeight(obj->geometry, 0, 0);

    if(!UIChat_IsActive(obj)) return;

    FR_SetFont(obj->font);
    Rect_SetWidthHeight(obj->geometry, cfg.msgScale * (FR_TextWidth(text) + FR_CharWidth('_')),
                                       cfg.msgScale * (MAX_OF(FR_TextHeight(text), FR_CharHeight('_'))));
}
예제 #8
0
static void animateBackground(void)
{
    wianimdef_t const *def;
    wianimstate_t *state;
    int i;

    if(gameModeBits & GM_ANY_DOOM2) return;
    if(wbs->episode > 2) return;

    for(i = 0; i < animCounts[wbs->episode]; ++i)
    {
        def = &animDefs[wbs->episode][i];
        state = &animStates[i];

        // Is the animation active for the current map?
        if(def->mapNum && wbs->nextMap != def->mapNum) continue;

        // Has the animation begun yet
        if(state->frame < 0) continue;

        // Time to progress the animation?
        if(backgroundAnimCounter != state->nextTic) continue;

        ++state->frame;
        if(state->frame >= def->numFrames)
        {
            if(def->mapNum)
            {
                // Loop.
                state->frame = def->numFrames - 1;
            }
            else
            {
                // Restart.
                state->frame = 0;
            }
        }

        state->nextTic = backgroundAnimCounter + MAX_OF(def->tics, 1);
    }
}
예제 #9
0
void chose_best_plane( Fplane &p, const Fvector &v, Fplane &p0, Fplane &p1, Fplane &p2   )
{
	MAX_OF( p0.n.dotproduct(v), p = p0, p1.n.dotproduct(v), p = p1, p2.n.dotproduct(v), p = p2 );
}
예제 #10
0
void SetPpgParameters( void )
{
  DB_MSG(("-->SetPpgParameters\n"));
  
  if( ParxRelsParHasValue("ACQ_trigger_enable") == No )
  {
    ACQ_trigger_enable = No;
  }
  
  if( ParxRelsParHasValue("ACQ_trigger_reference") == No )
  {
    ACQ_trigger_reference[0] = '\0';
  }
  
  if( ParxRelsParHasValue("ACQ_trigger_delay") == No )
  {
    ACQ_trigger_delay = 0;
  }
  
  ParxRelsParRelations("ACQ_trigger_reference",Yes);
  
  
  ACQ_vd_list_size=1;
  PARX_change_dims("ACQ_vd_list",1);
  ACQ_vd_list[0] = 1e-6;
  ParxRelsParRelations("ACQ_vd_list",Yes);
  
  ACQ_vp_list_size=1;
  PARX_change_dims("ACQ_vp_list",1);
  ACQ_vp_list[0] = 1e-6;
  ParxRelsParRelations("ACQ_vp_list",Yes);
    
  ATB_SetPulprog("T1rho_MSME.ppg");

   if(PVM_SelIrOnOff)
  {
    D[0] = PVM_InterGradientWaitTime / 1000.0;
    D[10] = SliceSegEndDelay/1000.0;
  }
  else
  {
    D[0]  = ((PVM_RepetitionTime - PVM_MinRepetitionTime)/NSLICES
       + PVM_InterGradientWaitTime) / 1000.0;
    D[10] = 0.00001;
  }
 
  D[1]  = ((PVM_EchoTime - minTE1)/2.0 + PVM_InterGradientWaitTime) / 1000.0;
  D[2]  = ((PVM_EchoTime - minTE2)/2.0 + 0.04) / 1000.0; /* 0.04 is duration of ADC_END_4ch */
  D[3]  = PVM_GradDelayTime / 1000.0;
  D[3]  = MAX_OF(D[3], 1e-5);  /* min d3 in case PVM_GradDelayTime==0  */
  D[4]  = PVM_RampTime / 1000.0;
  D[5]  = (SliceSpoilerDuration - 2*PVM_RampTime)/1000.0;
  D[6]  = (PVM_2dPhaseGradientTime - 2*PVM_RampTime)/1000.0;
  D[11] = (PVM_ReadDephaseTime - 2.0*PVM_RampTime) / 1000.0;
  D[8] = CFG_AmplifierEnable()/1000.0; 
 
  /* set shaped pulses     */
  sprintf(TPQQ[0].name,ExcPulse.Filename);
  sprintf(TPQQ[1].name,RefPulse.Filename);
  if(PVM_DeriveGains == Yes)  {
    TPQQ[0].power  = ExcPulse.Attenuation;
    TPQQ[1].power  = RefPulse.Attenuation;
  }
  TPQQ[0].offset = 0.0;
  TPQQ[1].offset = 0.0;
  
  ParxRelsParRelations("TPQQ",Yes);
  
  /* set duration of pulse, in this method P[0] is used          */
  P[0] = ExcPulse.Length * 1000;
  P[1] = RefPulse.Length * 1000;
  ParxRelsParRelations("P",Yes);
  
  
  DB_MSG(("<--SetPpgParameters\n"));
}
예제 #11
0
bool H_RenderHalo(coord_t x, coord_t y, coord_t z, float size,
    DGLuint tex, float const color[3], coord_t distanceToViewer,
    float occlusionFactor, float brightnessFactor, float viewXOffset,
    bool primary, bool viewRelativeRotate)
{
    int i, k;
    float viewToCenter[3], mirror[3], normalViewToCenter[3];
    float leftOff[3], rightOff[3], center[3], radius;
    float haloPos[3];
    float rgba[4], radX, radY, scale, turnAngle = 0;
    float fadeFactor = 1, secBold, secDimFactor;
    float colorAverage, f, distanceDim;
    flare_t *fl;
    viewdata_t const *viewData = R_ViewData(viewPlayer - ddPlayers);

    // In realistic mode we don't render secondary halos.
    if(!primary && haloRealistic)
        return false;

    if(distanceToViewer <= 0 || occlusionFactor == 0 ||
       (haloFadeMax && distanceToViewer > haloFadeMax))
        return false;

    occlusionFactor = (1 + occlusionFactor) / 2;

    if(haloFadeMax && haloFadeMax != haloFadeMin &&
       distanceToViewer < haloFadeMax && distanceToViewer >= haloFadeMin)
    {
        fadeFactor = (distanceToViewer - haloFadeMin) / (haloFadeMax - haloFadeMin);
    }

    // viewSideVec is to the left.
    for(i = 0; i < 3; ++i)
    {
        leftOff[i] = viewData->upVec[i] + viewData->sideVec[i];
        rightOff[i] = viewData->upVec[i] - viewData->sideVec[i];
    }

    rgba[CR] = color[CR];
    rgba[CG] = color[CG];
    rgba[CB] = color[CB];
    rgba[CA] = 1; // Real alpha is set later.

    center[VX] = x;
    center[VZ] = y;
    center[VY] = z;

    // Apply the flare's X offset. (Positive is to the right.)
    for(i = 0; i < 3; i++)
        center[i] -= viewXOffset * viewData->sideVec[i];

    // Calculate the mirrored position.
    // Project viewtocenter vector onto viewSideVec.
    for(i = 0; i < 3; ++i)
    {
        normalViewToCenter[i] = viewToCenter[i] = center[i] - (float)(vOrigin[i]);
    }
    V3f_Normalize(normalViewToCenter);

    // Calculate the dimming factor for secondary flares.
    secDimFactor = V3f_DotProduct(normalViewToCenter, viewData->frontVec);

    scale = V3f_DotProduct(viewToCenter, viewData->frontVec) / V3f_DotProduct(viewData->frontVec, viewData->frontVec);

    for(i = 0; i < 3; ++i)
        haloPos[i] = mirror[i] = (viewData->frontVec[i] * scale - viewToCenter[i]) * 2;
    // Now adding 'mirror' to a position will mirror it.

    // Calculate texture turn angle.
    if(V3f_Normalize(haloPos))
    {
        // Now halopos is a normalized version of the mirror vector.
        // Both vectors are on the view plane.
        if(viewRelativeRotate)
        {
            turnAngle = V3f_DotProduct(haloPos, viewData->upVec);
            if(turnAngle > 1)
                turnAngle = 1;
            else if(turnAngle < -1)
                turnAngle = -1;

            if(turnAngle >= 1)
                turnAngle = 0;
            else if(turnAngle <= -1)
                turnAngle = float(de::PI);
            else
                turnAngle = acos(turnAngle);

            // On which side of the up vector (left or right)?
            if(V3f_DotProduct(haloPos, viewData->sideVec) < 0)
                turnAngle = -turnAngle;
        }
        else
        {
            turnAngle = 0;
        }
    }

    // The overall brightness of the flare.
    colorAverage = (rgba[CR] + rgba[CG] + rgba[CB] + 1) / 4;

    // Small flares have stronger dimming.
    f = distanceToViewer / size;
    if(haloDimStart && haloDimStart < haloDimEnd && f > haloDimStart)
        distanceDim = 1 - (f - haloDimStart) / (haloDimEnd - haloDimStart);
    else
        distanceDim = 1;

    // Setup GL state.
    if(primary)
        H_SetupState(true);

    DENG_ASSERT_IN_MAIN_THREAD();
    DENG_ASSERT_GL_CONTEXT_ACTIVE();

    // Prepare the texture rotation matrix.
    glMatrixMode(GL_TEXTURE);
    glPushMatrix();
    glLoadIdentity();
    // Rotate around the center of the texture.
    glTranslatef(0.5f, 0.5f, 0);
    glRotatef(turnAngle / float(de::PI) * 180, 0, 0, 1);
    glTranslatef(-0.5f, -0.5f, 0);

    for(i = 0, fl = flares; i < haloMode && i < NUM_FLARES; ++i, fl++)
    {
        if(primary && i)
            break;
        if(!primary && !i)
            continue;

        // Calculate the dimming factor.
        if(i > 0)
            // Secondary flares receive additional dimming.
            f = MAX_OF(minHaloSize * size / distanceToViewer, 1);
        else
            f = 1;
        f *= distanceDim * brightnessFactor;

        // The rgba & alpha of the flare.
        rgba[CA] = f * (fl->alpha * occlusionFactor * fadeFactor + colorAverage * colorAverage / 5);

        radius = size * (1 - colorAverage / 3) + distanceToViewer / haloZMagDiv;
        if(radius < haloMinRadius)
            radius = haloMinRadius;
        radius *= occlusionFactor;

        secBold = colorAverage - 8 * (1 - secDimFactor);

        rgba[CA] *= .8f * haloBright / 100.0f;
        if(i)
        {
            rgba[CA] *= secBold; // Secondary flare boldness.
        }

        if(rgba[CA] <= 0)
            break; // Not visible.

        // In the realistic mode, halos are slightly dimmer.
        if(haloRealistic)
        {
            rgba[CA] *= .6f;
        }

        if(haloRealistic)
        {
            // The 'realistic' halos just use the blurry round
            // texture unless custom.
            if(!tex)
                tex = GL_PrepareSysFlaremap(FXT_ROUND);
        }
        else
        {
            if(!(primary && tex))
            {
                if(size > 45 || (colorAverage > .90 && size > 20))
                {
                    // The "Very Bright" condition.
                    radius *= .65f;
                    if(!i)
                        tex = GL_PrepareSysFlaremap(FXT_BIGFLARE);
                    else
                        tex = GL_PrepareSysFlaremap(flaretexid_t(fl->texture));
                }
                else
                {
                    if(!i)
                        tex = GL_PrepareSysFlaremap(FXT_ROUND);
                    else
                        tex = GL_PrepareSysFlaremap(flaretexid_t(fl->texture));
                }
            }
        }

        // In the realistic mode, halos are slightly smaller.
        if(haloRealistic)
        {
            radius *= 0.8f;
        }

        // The final radius.
        radX = radius * fl->size;
        radY = radX / 1.2f;

        // Determine the final position of the halo.
        haloPos[VX] = center[VX];
        haloPos[VY] = center[VY];
        haloPos[VZ] = center[VZ];
        if(i)
        {   // Secondary halos.
            // Mirror it according to the flare table.
            for(k = 0; k < 3; ++k)
                haloPos[k] += mirror[k] * fl->offset;
        }

        GL_BindTextureUnmanaged(renderTextures? tex : 0, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
        glEnable(GL_TEXTURE_2D);

        glColor4fv(rgba);

        glBegin(GL_QUADS);
            glTexCoord2f(0, 0);
            glVertex3f(haloPos[VX] + radX * leftOff[VX],
                       haloPos[VY] + radY * leftOff[VY],
                       haloPos[VZ] + radX * leftOff[VZ]);
            glTexCoord2f(1, 0);
            glVertex3f(haloPos[VX] + radX * rightOff[VX],
                       haloPos[VY] + radY * rightOff[VY],
                       haloPos[VZ] + radX * rightOff[VZ]);
            glTexCoord2f(1, 1);
            glVertex3f(haloPos[VX] - radX * leftOff[VX],
                       haloPos[VY] - radY * leftOff[VY],
                       haloPos[VZ] - radX * leftOff[VZ]);
            glTexCoord2f(0, 1);
            glVertex3f(haloPos[VX] - radX * rightOff[VX],
                       haloPos[VY] - radY * rightOff[VY],
                       haloPos[VZ] - radX * rightOff[VZ]);
        glEnd();

        glDisable(GL_TEXTURE_2D);
    }

    glMatrixMode(GL_TEXTURE);
    glPopMatrix();

    // Restore previous GL state.
    if(primary)
        H_SetupState(false);

    return true;
}