src/system/system_math.c
Random numbers, angles and square roots. More…
Included by system.c.
Macros
| Name | Description | |
|---|---|---|
#define | ATAN_ENTRIES 256 | The entries of MathTanTable in a quarter turn, which syAtan searches, the angle between neighbouring entries, and the tangent of the last one searched, in 8.8, beyond which syAtan gives a quarter turn. |
#define | ATAN_ENTRY_ANGLE (DEGtoANG(90) / ATAN_ENTRIES) | |
#define | ATAN_RATIO_MAX 64362 | |
#define | ROOT_BITS 16 | The bits of a 32-bit value's square root. |
Functions
| Name | Description | |
|---|---|---|
Uint32 | syRandom (void) | Advances the game's random number generator (the C library's classic linear congruential one), stores the new seed and returns its bits 8 to 23, 0 to 65535. |
void | syVectorAddPolarOffset (FIXED radius, ANGLE angle, POINT pos) | Moves the point pos by radius in direction angle on the ground plane: x by the cosine, z by the sine. |
ANGLE | syAtan (FIXED x, FIXED y) | Returns the angle of the vector (x, y), from 0 to TRIG_TURN - 1, measured from the y axis: 0 along +y, a quarter turn along +x; (0, 0) gives 0. |
Sint32 | sySquart (Sint32 value) | Returns the integer square root of value, rounded down, a bit at a time; a negative value gives 0. |
FIXED | sySquartFX (FIXED value) | Square root of a 16.16 fixed-point value, in 16.16. |
Sint32 | syPaletteGetBasicSpriteColors (void) | Returns the basic sprite palettes (SystemBasicColorPalette). |
Description
Random numbers, angles and square roots. Part of system.c.
Macros in detail
ATAN_ENTRIES
#define ATAN_ENTRIES 256
The entries of MathTanTable in a quarter turn, which syAtan searches, the
angle between neighbouring entries, and the tangent of the last one searched,
in 8.8, beyond which syAtan gives a quarter turn.
Referenced by syAtan().
Definition at line 32 of file system_math.c.
ATAN_ENTRY_ANGLE
#define ATAN_ENTRY_ANGLE (DEGtoANG(90) / ATAN_ENTRIES)
Referenced by syAtan().
Definition at line 33 of file system_math.c.
ATAN_RATIO_MAX
#define ATAN_RATIO_MAX 64362
Referenced by syAtan().
Definition at line 34 of file system_math.c.
ROOT_BITS
#define ROOT_BITS 16
The bits of a 32-bit value's square root.
Referenced by sySquart().
Definition at line 151 of file system_math.c.
Functions in detail
syRandom
Uint32 syRandom(void)
Advances the game's random number generator (the C library's classic linear congruential one), stores the new seed and returns its bits 8 to 23, 0 to 65535. Called throughout the game.
References RandWork.
Referenced by btAbilityReplaceDefeated(), btAutoBattleBuildActions(), btAutoBattleRunApproachAttack(), btAutoBattleRunPsynergy(), btBuildEnemyActions(), btCameraApplyVerticalShake(), btCameraShake(), btEffectConvertBackgroundToBlueRamp(), btEffectDrawStreaks(), btEffectRunAnnihilation(), btEffectRunAtalanta(), btEffectRunAttackSlash(), btEffectRunAzul(), btEffectRunBackstab(), btEffectRunBallLightning(), btEffectRunBladeRain(), btEffectRunBolt(), btEffectRunBoreas(), btEffectRunBreak(), btEffectRunBreaths(), btEffectRunBubbleColumn(), btEffectRunBurstShower(), btEffectRunCanvasBurst(), btEffectRunCards(), btEffectRunCastingImpact(), btEffectRunCatastrophe(), btEffectRunCharon(), btEffectRunCoatlicue(), btEffectRunCool(), btEffectRunCriticalHit(), btEffectRunCruelRuin(), btEffectRunCrystal(), btEffectRunCurse(), btEffectRunCybele(), btEffectRunDaedalus(), btEffectRunDaedalusStrike(), btEffectRunDeathPlunge(), btEffectRunDiamondBerg(), btEffectRunDjinnBeams(), btEffectRunDjinnHeal(), btEffectRunDjinniCharge(), btEffectRunDjinniEntrance(), btEffectRunDjinniSign(), btEffectRunDouse(), btEffectRunDragonCloud(), btEffectRunDragonFire(), btEffectRunDrainMotes(), btEffectRunEclipse(), btEffectRunElementBurst(), btEffectRunElementCards() and 309 more.
Definition at line 6 of file system_math.c.
syVectorAddPolarOffset
void syVectorAddPolarOffset(FIXED radius, ANGLE angle, POINT pos)
Moves the point pos by radius in direction angle on the ground plane: x
by the cosine, z by the sine.
References sySin().
Referenced by fdActorAppearInSparks(), fdActorCrossRope(), fdActorCrossTightrope(), fdActorDescendInWhirlwind(), fdActorFallOverById(), fdActorFallOverWithAnimationById(), fdActorFlyOnWorldMap(), fdActorGetCueMetatileAheadOfCurrent(), fdActorMoveAsSand(), fdActorMoveAsSandOnWorldMap(), fdActorMoveByKeys(), fdActorMoveOnWorldMap(), fdActorSailOnMap(), fdActorSailOnWorldMap(), fdActorScriptWanderNearHome(), fdActorSetTargetPosFromMagnitudeAngle(), fdActorUpdateHoverControl(), fdActorUpdatePlayerControl(), fdActorUpdateWalkingControl(), fdActorWander(), fdBlazeUpdateSpray(), fdCycloneCarryLeader(), fdCycloneLiftLeader(), fdEffectRunAngledApproachPhases(), fdEffectRunSparkEmitter(), fdEffectSpawnBurstParticleField(), fdEffectSpawnFallingParticles(), fdEffectUpdateDescendingOrbitActor(), fdEffectUpdateHaltParticle(), fdEffectUpdateMarsSpark(), fdEffectUpdateMoveHand(), fdEffectUpdateOrbitingParticleLeft(), fdEffectUpdateOrbitingParticleRight(), fdEffectUpdateOutAndBack(), fdEffectUpdateRadialBurst(), fdEffectUpdateRadialSpread(), fdEffectUpdateRandomTargetParticle(), fdEffectUpdateShrinkingOrbitActor(), fdGetCollisionAheadOfLeader(), fdItemDisplayShowItemInFront(), fdLeaderCanPushObjectAhead(), fdLeaderFindActorAhead(), fdLeaderPushObjectAhead(), fdLeaderStepOffRope(), fdLeaderStepOffTightrope(), fdMapScreenUpdateMarkers(), fdParticleBurstStart(), fdParticleBurstUpdate(), fdPsynergyArrow(), fdPsynergyCatch() and 40 more.
Definition at line 22 of file system_math.c.
syAtan
ANGLE syAtan(FIXED x, FIXED y)
Returns the angle of the vector (x, y), from 0 to TRIG_TURN - 1, measured
from the y axis: 0 along +y, a quarter turn along +x; (0, 0) gives 0. It
binary-searches the tangent table to ATAN_ENTRY_ANGLE.
References MathTanTable, result, Sint32 and syIntegerDivideUnsigned().
Referenced by btEffectRunProcne(), btMotionReturnToSpot(), btObjectMake(), btObjectReset(), btStagingRunAttack(), btStagingRunPsynergyCast(), fdActorFaceActorById(), fdActorFindNearestFacingTarget(), fdActorSailOnMap(), fdActorScriptFaceWatched(), fdActorScriptWanderNearHome(), fdActorSystemProjectSprites(), fdActorTurnPairToFaceEachOther(), fdActorTurnTowardWatchedActor(), fdActorUpdateAllMotion(), fdActorUpdateAllOnField(), fdActorUpdatePlayerControl(), fdActorUpdateWalkingControl(), fdEffectUpdateMoveHand(), fdFindNearbyTalkTarget(), fdHangingVineDraw(), fdLeaderSlideOnIce(), fdMapScreenUpdateMarkers(), fdMeasurePsynergyReach(), fdMotionStepTowardTarget(), fdParticleBurstStart(), fdParticleUpdateMotion(), fdPsynergyUpdateMindReadWave(), fdRopeDraw(), fdRopeLayCoil(), fdRopeLayTied(), fdRopeRecoil(), fdRopeThrow(), fdTightropeLay(), fdTightropeLayCoil(), fdTightropeRecoil(), fdTightropeThrow(), fdTreasureSpotMoveLeaderAway(), scActorIsFacingNear(), scAnemosInnerSanctumSendSpark(), scGabombaStatueSawEnergyFlow(), scLeaderSlideOnIceFromEdge(), scProxChaseTarget(), scTrialRoadMoveRival() and scYallamStopIfFacingNear().
Definition at line 39 of file system_math.c.
sySquart
Sint32 sySquart(Sint32 value)
Returns the integer square root of value, rounded down, a bit at a time; a
negative value gives 0. Reached through the stub table.
Definition at line 155 of file system_math.c.
sySquartFX
FIXED sySquartFX(FIXED value)
Square root of a 16.16 fixed-point value, in 16.16. The square root of the raw value is the result in 8.8, so the low eight bits are always 0.
References sySquartIWRAM().
Referenced by btElementGlowUpdateStarField(), fdActorFlyOnWorldMap(), fdActorMoveAsSand(), fdActorMoveAsSandOnWorldMap(), fdActorMoveOnWorldMap(), fdActorSailOnMap(), fdActorSailOnWorldMap(), fdActorSetMoveTarget(), fdActorUpdateAllOnField(), fdActorUpdatePlayerControl(), fdCameraFollowLeaderInBounds(), fdCameraFollowWatchedInBounds(), fdMapScreenUpdateMarkers(), fdMapScreenUpdateScroll(), fdParticleUpdateMotion() and syMatrixBuildLookAt().
Definition at line 179 of file system_math.c.
syPaletteGetBasicSpriteColors
Sint32 syPaletteGetBasicSpriteColors(void)
Returns the basic sprite palettes (SystemBasicColorPalette).
References Sint32 and SystemBasicColorPalette.
Referenced by mnOpenBackdropScreen() and mnPartyStatusDrawBars().
Definition at line 190 of file system_math.c.