Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

bg_lib.c File Reference

#include "q_shared.h"

Include dependency graph for bg_lib.c:

Include dependency graph

Go to the source code of this file.

Defines

#define min(a, b)   (a) < (b) ? a : b
#define swap(a, b)
#define swapcode(TYPE, parmi, parmj, n)
#define SWAPINIT(a, es)
#define vecswap(a, b, n)   if ((n) > 0) swapfunc(a, b, n, swaptype)

Typedefs

typedef int cmp_t (const void *, const void *)

Functions

double _atof (const char **stringPtr)
double atof (const char *string)
char * med3 (char *, char *, char *, cmp_t *)
void * memmove (void *dest, const void *src, size_t count)
void qsort (void *a, size_t n, size_t es, cmp_t *cmp)
int rand (void)
void srand (unsigned seed)
void swapfunc (char *, char *, int, int)

Variables

int randSeed = 0


Define Documentation

#define min a,
 )     (a) < (b) ? a : b
 

Definition at line 57 of file bg_lib.c.

Referenced by addd(), addi(), AddNewItem(), canonrect(), CG_DrawOldTourneyScoreboard(), Characteristic_BFloat(), Characteristic_BInteger(), divi(), G_LogPrintf(), GetUniqueTargetId(), Item_ListBox_ThumbDrawPosition(), muld(), muli(), PlaceMenuMRUItem(), qsort(), SetNbLruShow(), subd(), subi(), trap_Characteristic_BFloat(), and trap_Characteristic_BInteger().

#define swap a,
 ) 
 

Value:

if (swaptype == 0) {                \
        long t = *(long *)(a);          \
        *(long *)(a) = *(long *)(b);        \
        *(long *)(b) = t;           \
    } else                      \
        swapfunc(a, b, es, swaptype)

Definition at line 88 of file bg_lib.c.

Referenced by Hunk_SwapBanks(), increment(), mk_real(), and qsort().

#define swapcode TYPE,
parmi,
parmj,
n   ) 
 

Value:

{       \
    long i = (n) / sizeof (TYPE);           \
    register TYPE *pi = (TYPE *) (parmi);       \
    register TYPE *pj = (TYPE *) (parmj);       \
    do {                        \
        register TYPE   t = *pi;        \
        *pi++ = *pj;                \
        *pj++ = t;              \
        } while (--i > 0);              \
}

Definition at line 63 of file bg_lib.c.

Referenced by swapfunc().

#define SWAPINIT a,
es   ) 
 

Value:

swaptype = ((char *)a - (char *)0) % sizeof(long) || \
    es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1;

Definition at line 74 of file bg_lib.c.

Referenced by qsort().

#define vecswap a,
b,
n   )     if ((n) > 0) swapfunc(a, b, n, swaptype)
 

Definition at line 96 of file bg_lib.c.

Referenced by qsort().


Typedef Documentation

typedef int cmp_t(const void *, const void *)
 

Definition at line 50 of file bg_lib.c.


Function Documentation

double _atof const char **  stringPtr  ) 
 

Definition at line 848 of file bg_lib.c.

References c, sign, string(), and value.

00848                                        {
00849     const char  *string;
00850     float sign;
00851     float value;
00852     int     c = '0'; // bk001211 - uninitialized use possible
00853 
00854     string = *stringPtr;
00855 
00856     // skip whitespace
00857     while ( *string <= ' ' ) {
00858         if ( !*string ) {
00859             *stringPtr = string;
00860             return 0;
00861         }
00862         string++;
00863     }
00864 
00865     // check sign
00866     switch ( *string ) {
00867     case '+':
00868         string++;
00869         sign = 1;
00870         break;
00871     case '-':
00872         string++;
00873         sign = -1;
00874         break;
00875     default:
00876         sign = 1;
00877         break;
00878     }
00879 
00880     // read digits
00881     value = 0;
00882     if ( string[0] != '.' ) {
00883         do {
00884             c = *string++;
00885             if ( c < '0' || c > '9' ) {
00886                 break;
00887             }
00888             c -= '0';
00889             value = value * 10 + c;
00890         } while ( 1 );
00891     }
00892 
00893     // check for decimal point
00894     if ( c == '.' ) {
00895         double fraction;
00896 
00897         fraction = 0.1;
00898         do {
00899             c = *string++;
00900             if ( c < '0' || c > '9' ) {
00901                 break;
00902             }
00903             c -= '0';
00904             value += c * fraction;
00905             fraction *= 0.1;
00906         } while ( 1 );
00907 
00908     }
00909 
00910     // not handling 10e10 notation...
00911     *stringPtr = string;
00912 
00913     return value * sign;
00914 }

Here is the call graph for this function:

double atof const char *  string  ) 
 

Definition at line 781 of file bg_lib.c.

References c, sign, string(), and value.

Referenced by AAS_FloatForBSPEpairKey(), ASE_KeyMESH_TVERTLIST(), ASE_KeyMESH_VERTEX_LIST(), BG_AddPredictableEventToPlayerstate(), BotGetTime(), BotMatch_FormationSpace(), Brush_Parse(), BrushPrimit_Parse(), idCameraDef::buildCamera(), CG_NewParticleArea(), CG_ParseAnimationFile(), CG_TestModel_f(), Cmd_SetViewpos_f(), Com_Freeze_f(), Com_Parse1DMatrix(), Com_ParseFloat(), Com_ParseInt(), Cvar_Get(), Cvar_Set2(), Float_Parse(), FloatForKey(), G_BotConnect(), G_ParseField(), G_SpawnFloat(), GammaDlgProc(), CSurfaceDlg::GetTexMods(), CSurfaceDlg::GrabPatchMods(), LightMain(), CPrefsDlg::LoadPrefs(), LoadShader(), main(), MoveHold(), MoveSelected(), CRotateDlg::OnApply(), idSplineList::parse(), idCameraFOV::parse(), Parse1DMatrix(), ParseDeform(), ParseRawBrush(), ParseShader(), ParseShaderFile(), ParseSkyParms(), ParseSort(), ParseStage(), ParseTerrain(), ParseTexMod(), idCameraPosition::parseToken(), ParseVector(), ParseWaveForm(), Q2_ParseBrush(), R_RemapShader(), RotateDlgProc(), RotateHold(), RotateSelected(), Svcmd_AddBot_f(), Terrain_ParseFace(), TrackMD3Angles(), trap_Cvar_VariableValue(), UI_ParseAnimationFile(), VLightMain(), and VSoundMain().

00781                                   {
00782     float sign;
00783     float value;
00784     int     c;
00785 
00786 
00787     // skip whitespace
00788     while ( *string <= ' ' ) {
00789         if ( !*string ) {
00790             return 0;
00791         }
00792         string++;
00793     }
00794 
00795     // check sign
00796     switch ( *string ) {
00797     case '+':
00798         string++;
00799         sign = 1;
00800         break;
00801     case '-':
00802         string++;
00803         sign = -1;
00804         break;
00805     default:
00806         sign = 1;
00807         break;
00808     }
00809 
00810     // read digits
00811     value = 0;
00812     c = string[0];
00813     if ( c != '.' ) {
00814         do {
00815             c = *string++;
00816             if ( c < '0' || c > '9' ) {
00817                 break;
00818             }
00819             c -= '0';
00820             value = value * 10 + c;
00821         } while ( 1 );
00822     } else {
00823         string++;
00824     }
00825 
00826     // check for decimal point
00827     if ( c == '.' ) {
00828         double fraction;
00829 
00830         fraction = 0.1;
00831         do {
00832             c = *string++;
00833             if ( c < '0' || c > '9' ) {
00834                 break;
00835             }
00836             c -= '0';
00837             value += c * fraction;
00838             fraction *= 0.1;
00839         } while ( 1 );
00840 
00841     }
00842 
00843     // not handling 10e10 notation...
00844 
00845     return value * sign;
00846 }

Here is the call graph for this function:

char * med3 char *  ,
char *  ,
char *  ,
cmp_t
[static]
 

Definition at line 99 of file bg_lib.c.

References a, b, c, and cmp().

Referenced by qsort().

00102 {
00103     return cmp(a, b) < 0 ?
00104            (cmp(b, c) < 0 ? b : (cmp(a, c) < 0 ? c : a ))
00105               :(cmp(b, c) > 0 ? b : (cmp(a, c) < 0 ? a : c ));
00106 }

Here is the call graph for this function:

void* memmove void *  dest,
const void *  src,
size_t  count
 

Definition at line 294 of file bg_lib.c.

00294                                                            {
00295     int     i;
00296 
00297     if ( dest > src ) {
00298         for ( i = count-1 ; i >= 0 ; i-- ) {
00299             ((char *)dest)[i] = ((char *)src)[i];
00300         }
00301     } else {
00302         for ( i = 0 ; i < count ; i++ ) {
00303             ((char *)dest)[i] = ((char *)src)[i];
00304         }
00305     }
00306     return dest;
00307 }

void qsort void *  a,
size_t  n,
size_t  es,
cmp_t cmp
 

Definition at line 109 of file bg_lib.c.

00113 {
00114     char *pa, *pb, *pc, *pd, *pl, *pm, *pn;
00115     int d, r, swaptype, swap_cnt;
00116 
00117 loop:   SWAPINIT(a, es);
00118     swap_cnt = 0;
00119     if (n < 7) {
00120         for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es)
00121             for (pl = pm; pl > (char *)a && cmp(pl - es, pl) > 0;
00122                  pl -= es)
00123                 swap(pl, pl - es);
00124         return;
00125     }
00126     pm = (char *)a + (n / 2) * es;
00127     if (n > 7) {
00128         pl = a;
00129         pn = (char *)a + (n - 1) * es;
00130         if (n > 40) {
00131             d = (n / 8) * es;
00132             pl = med3(pl, pl + d, pl + 2 * d, cmp);
00133             pm = med3(pm - d, pm, pm + d, cmp);
00134             pn = med3(pn - 2 * d, pn - d, pn, cmp);
00135         }
00136         pm = med3(pl, pm, pn, cmp);
00137     }
00138     swap(a, pm);
00139     pa = pb = (char *)a + es;
00140 
00141     pc = pd = (char *)a + (n - 1) * es;
00142     for (;;) {
00143         while (pb <= pc && (r = cmp(pb, a)) <= 0) {
00144             if (r == 0) {
00145                 swap_cnt = 1;
00146                 swap(pa, pb);
00147                 pa += es;
00148             }
00149             pb += es;
00150         }
00151         while (pb <= pc && (r = cmp(pc, a)) >= 0) {
00152             if (r == 0) {
00153                 swap_cnt = 1;
00154                 swap(pc, pd);
00155                 pd -= es;
00156             }
00157             pc -= es;
00158         }
00159         if (pb > pc)
00160             break;
00161         swap(pb, pc);
00162         swap_cnt = 1;
00163         pb += es;
00164         pc -= es;
00165     }
00166     if (swap_cnt == 0) {  /* Switch to insertion sort */
00167         for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es)
00168             for (pl = pm; pl > (char *)a && cmp(pl - es, pl) > 0;
00169                  pl -= es)
00170                 swap(pl, pl - es);
00171         return;
00172     }
00173 
00174     pn = (char *)a + n * es;
00175     r = min(pa - (char *)a, pb - pa);
00176     vecswap(a, pb - r, r);
00177     r = min(pd - pc, pn - pd - es);
00178     vecswap(pb, pn - r, r);
00179     if ((r = pb - pa) > es)
00180         qsort(a, r / es, es, cmp);
00181     if ((r = pd - pc) > es) {
00182         /* Iterate rather than recurse to save stack space */
00183         a = pn - r;
00184         n = r / es;
00185         goto loop;
00186     }
00187 /*      qsort(pn - r, r / es, es, cmp);*/
00188 }

int rand void   ) 
 

Definition at line 776 of file bg_lib.c.

References randSeed.

Referenced by CG_AddPlayerWeapon(), CG_Bleed(), CG_BloodPool(), CG_BubbleTrail(), CG_EntityEvent(), CG_FireWeapon(), CG_FragmentBounceMark(), CG_FragmentBounceSound(), CG_GibPlayer(), CG_LightningBolt(), CG_MachineGunEjectBrass(), CG_MakeExplosion(), CG_MissileHitWall(), CG_Particle_Bleed(), CG_Particle_OilParticle(), CG_Particle_OilSlick(), CG_ParticleBloodCloud(), CG_ParticleDust(), CG_ParticleImpactSmokePuff(), CG_ParticleMisc(), CG_ParticleSnowFlurry(), CG_PlasmaTrail(), CG_PlayerPowerups(), CG_ShotgunEjectBrass(), CL_RequestMotd(), eval(), G_PickTarget(), ItemParse_asset_model(), P_WorldEffects(), R_NoiseInit(), RespawnItem(), SelectRandomDeathmatchSpawnPoint(), SelectRandomTeamSpawnPoint(), SV_GetChallenge(), SV_SpawnServer(), UI_DrawPlayer(), and weapon_supershotgun_fire().

00776                      {
00777     randSeed = (69069 * randSeed + 1);
00778     return randSeed & 0x7fff;
00779 }

void srand unsigned  seed  ) 
 

Definition at line 772 of file bg_lib.c.

References randSeed.

Referenced by G_InitGame(), R_NoiseInit(), and SV_SpawnServer().

00772                                {
00773     randSeed = seed;
00774 }

void swapfunc char *  ,
char *  ,
int  ,
int 
[static]
 

Definition at line 78 of file bg_lib.c.

References a, b, n, and swapcode.

00081 {
00082     if(swaptype <= 1)
00083         swapcode(long, a, b, n)
00084     else
00085         swapcode(char, a, b, n)
00086 }


Variable Documentation

int randSeed = 0 [static]
 

Definition at line 770 of file bg_lib.c.

Referenced by rand(), and srand().


Generated on Thu Aug 25 13:46:24 2005 for Quake III Arena by  doxygen 1.3.9.1