Alchemy
Loading...
Searching...
No Matches

scheduler.c File Reference

The task scheduler: per-frame and VBlank routines in order. More...

Go to the source code of this file.

Typedefs

typedef s32(*) KeyCallbackFn(void)

Functions

void Scheduler_ResetTaskTable (void)
 Empties the task table: every slot gets no routine, order 0xffff (sorted last) and no flags.
UNUSED void Scheduler_CopyWords (u32 *destination, u32 *source, u32 byteCount)
 Copies byteCount bytes a word at a time. Nothing in ☀️ calls it.
void Scheduler_SortTasks (void)
 Bubble-sorts the task table by order, highest first, so each pass runs its tasks from the highest order down; removed tasks (order 0x7fff) rise to the front.
UNUSED s32 Scheduler_FindCallback (SchedulerCallback callback)
 Returns the table index of the task running callback, or -1.
s32 Scheduler_AddOrUpdateCallback (SchedulerCallback callback, s32 order)
 Schedules callback with order, or gives a task already running it the new order, and re-sorts the table.
UNUSED void Scheduler_Idle (void)
 An empty routine; nothing in ☀️ calls it.
UNUSED void Scheduler_EmptyCallback (void)
 An empty routine; nothing in ☀️ calls it.
s32 Scheduler_RemoveCallback (SchedulerCallback callback)
 Unschedules the task running callback: clears its routine and gives it order 0x7fff, which no pass matches.
s32 Scheduler_SuspendTasks (SchedulerCallback callback)
 Suspends the task running callback, or every task when callback is null, by setting bit 0 of its order's high byte, which then matches neither pass key.
s32 Scheduler_SuspendOverlayTasks (void)
 Suspends every task whose routine is in an overlay (EWRAM, 0x02xxxxxx) unless its flag bit 0 asks to keep it running, as Scheduler_SuspendTasks does.
s32 Scheduler_SetTaskFlags (SchedulerCallback callback, u32 mask)
 Stores mask as the flags of the task running callback; bit 0 keeps it running while the overlay tasks are suspended.
s32 Scheduler_ResumeTasks (SchedulerCallback callback)
 Resumes the task running callback, or every task when callback is null, by clearing bit 0 of its order's high byte.
s32 Scheduler_ResumeOverlayTasks (void)
 Resumes every task whose routine is in an overlay, flagged or not.
void Scheduler_RunPass (s32 key)
 Runs one pass of the scheduler: every task whose order's high byte matches key's (SCHEDULER_KEY_MAIN_LOOP or SCHEDULER_KEY_VBLANK), in table order.

Detailed Description

The task scheduler: per-frame and VBlank routines in order.

Part of runtime.c, the runtime object, compiled only through it.

Definition in file scheduler.c.

Typedef Documentation

◆ KeyCallbackFn

typedef s32(*) KeyCallbackFn(void)

Definition at line 8 of file scheduler.c.

Function Documentation

◆ Scheduler_ResetTaskTable()

void Scheduler_ResetTaskTable ( void )

Empties the task table: every slot gets no routine, order 0xffff (sorted last) and no flags.

Clears gSchedulerReady while it works and sets it at the end, so neither pass runs a half-cleared table. Called by System_Initialize and by the battle, Lucky Dice and other modes that start from a clean table.

Definition at line 19 of file scheduler.c.

Referenced by Battle_RunEncounter(), DebugBattle_RunMenu(), DisplayScroll_RunSlideshow(), Field_RunScene(), Game_ResetForNewGame(), LuckyDice_Run(), ReelGame_Run(), Scheduler_ResetTaskTable(), System_GetLanguage(), System_Initialize(), Title_ShowAnimatedSplash(), Title_ShowIntro(), Title_ShowSplashScreen(), and Ui_RunIconMonitor().

◆ Scheduler_CopyWords()

UNUSED void Scheduler_CopyWords ( u32 * destination,
u32 * source,
u32 byteCount )

Copies byteCount bytes a word at a time. Nothing in ☀️ calls it.

Definition at line 37 of file scheduler.c.

Referenced by Scheduler_CopyWords(), and System_GetLanguage().

◆ Scheduler_SortTasks()

void Scheduler_SortTasks ( void )

Bubble-sorts the task table by order, highest first, so each pass runs its tasks from the highest order down; removed tasks (order 0x7fff) rise to the front.

Called by Scheduler_AddOrUpdateCallback with interrupts disabled.

Definition at line 47 of file scheduler.c.

Referenced by Scheduler_AddOrUpdateCallback(), Scheduler_SortTasks(), and System_GetLanguage().

◆ Scheduler_FindCallback()

UNUSED s32 Scheduler_FindCallback ( SchedulerCallback callback)

Returns the table index of the task running callback, or -1.

Nothing in ☀️ calls it.

Definition at line 77 of file scheduler.c.

Referenced by Scheduler_FindCallback(), and System_GetLanguage().

◆ Scheduler_AddOrUpdateCallback()

s32 Scheduler_AddOrUpdateCallback ( SchedulerCallback callback,
s32 order )

Schedules callback with order, or gives a task already running it the new order, and re-sorts the table.

Writes the task's routine, order and flags (cleared for a new task) with interrupts disabled. Returns the task's index, or -1 when all 20 slots are taken. Called throughout the game to start per-frame and VBlank work; order is SCHEDULER_KEY_MAIN_LOOP or SCHEDULER_KEY_VBLANK's high byte with a priority in the low byte.

Definition at line 102 of file scheduler.c.

Referenced by AffineEffect_InitializeWork(), Battle_CollectPartyCommands(), Battle_RunEncounter(), BattleBackground_Load(), BattleEffect_InitializeBuffers(), BattleEventRuntime_SchedulePhase(), BattleFx_BeginCanvasLayer(), BattleFx_InitializeSlots(), BattleFx_InitializeStarField(), BattleFx_LoadActionEffectResources(), BattleFx_OpenCanvasLayer(), BattleFx_RunAnnihilation(), BattleFx_RunAstralBlast(), BattleFx_RunAtalanta(), BattleFx_RunBoreas(), BattleFx_RunBurstShower(), BattleFx_RunCastingImpact(), BattleFx_RunCondemn(), BattleFx_RunCurse(), BattleFx_RunDeathPlunge(), BattleFx_RunDouse(), BattleFx_RunFire(), BattleFx_RunFlare(), BattleFx_RunFroth(), BattleFx_RunGatheringLights(), BattleFx_RunHaunt(), BattleFx_RunHealingMotes(), BattleFx_RunIce(), BattleFx_RunJudgment(), BattleFx_RunKirin(), BattleFx_RunNeptune(), BattleFx_RunOrbitingSkulls(), BattleFx_RunOrbitingSpirals(), BattleFx_RunParticleStreams(), BattleFx_RunProjectileVolley(), BattleFx_RunRamses(), BattleFx_RunRingAndSparkScene(), BattleFx_RunShiningStar(), BattleFx_RunStatBoost(), BattleFx_RunTargetMotes(), BattleFx_RunThor(), BattleFx_RunThorn(), BattleFx_RunTorch(), BattleFx_ScheduleRatioTransition(), BattleFx_StartBufferBlend(), BattleFx_StartElementStreaks(), BattleFx_StartFadeOverlay(), BattleFx_SteerLiftedTarget(), BattlePres_RunAttack(), BattlePres_RunEntryTransition(), BattlePres_RunItem(), BattlePres_RunPsynergyCast(), BattlePres_SetActorModes(), BattlePresentation_ConfigurePaletteFade(), BattlePresentation_RunUnitTransition(), CharacterMenu_SelectCommand(), DebugMenu_ScheduleSceneSelector(), DisplayBlend_StartScript(), DisplayScroll_InitObjectTable(), DisplayScroll_RunSlideshow(), DisplayTransition_Finish(), DisplayTransition_InitializeBattleEffectState(), DisplayTransition_InitializeState(), DisplayTransition_Start(), DjinnMenu_ShowHelp(), DjinnMenu_ShowOwnerStatus(), FieldEffect_InitSparkles(), FieldEvent_Begin(), FieldFx_ResumeCloakCheck(), FieldFx_RunAvoid(), FieldFx_RunReveal(), FieldFx_StartCloak(), FieldFx_StartGroundParticles(), FieldFx_StartLightning(), FieldMotes_Start(), FieldScheduler_AddCallback(), FourObjectMotion_InitializeBottomRow(), FourObjectMotion_InitializeTopRow(), ItemMenu_ChooseCommand(), ItemMenu_SelectItem(), ItemMenu_SelectTarget(), Map_InitializePerspectiveScene(), Map_LoadLayeredScene(), Map_ShowWorldMap(), MapAnimation_StartChannels(), Menu_CancelSoundReset(), Menu_RunCommandRow(), Menu_SelectQuantity(), Menu_SelectResourceLayout(), ObjectSystem_Initialize(), OptionMenu_InitializeWork(), OwnerAction_RunCompareLoop(), PaletteFade_Init(), PaletteGlow_Start(), PaletteQueue_Start(), PsynergyMenu_InitializeEntryObjects(), PsynergyMenu_SelectAction(), ReelGame_Run(), Resource_ScheduleOwnerResetDelayed(), RunSceneTransitionEffect(), SaveMenu_ShowDjinnSprites(), SaveMenu_ShowPartySprites(), Scheduler_AddOrUpdateCallback(), Shop_InitializeCursorWork(), Shop_RunPartyMemberIconBurst(), System_GetLanguage(), SystemMenu_Initialize(), Title_ShowIntro(), Ui_FillBank15PaletteGrey(), Ui_RunIconMonitor(), UiTimedNotice_Create(), UiWork_InitCountersAndScheduleRefresh(), UiWork_InitCountersWithResourceAndScheduleRefresh(), UiWork_Initialize(), and UiWork_InitializeWithResourceCounters().

◆ Scheduler_Idle()

UNUSED void Scheduler_Idle ( void )

An empty routine; nothing in ☀️ calls it.

Definition at line 138 of file scheduler.c.

Referenced by Scheduler_Idle(), and System_GetLanguage().

◆ Scheduler_EmptyCallback()

UNUSED void Scheduler_EmptyCallback ( void )

An empty routine; nothing in ☀️ calls it.

Definition at line 141 of file scheduler.c.

Referenced by Scheduler_EmptyCallback(), and System_GetLanguage().

◆ Scheduler_RemoveCallback()

s32 Scheduler_RemoveCallback ( SchedulerCallback callback)

Unschedules the task running callback: clears its routine and gives it order 0x7fff, which no pass matches.

Returns its old index, or -1. Called throughout the game when the work a task did is finished.

Definition at line 146 of file scheduler.c.

Referenced by Battle_CollectPartyCommands(), Battle_RunEncounter(), BattleEffect_CleanupSceneObjects(), BattleEventRuntime_WaitForReady(), BattleFx_ClearActiveSlotsAndScheduleUpdates(), BattleFx_EndCanvasLayer(), BattleFx_EndElementStreaks(), BattleFx_FinishSceneAndReleaseHeapBlock(), BattleFx_RunAnnihilation(), BattleFx_RunAtalanta(), BattleFx_RunBeamSequence(), BattleFx_RunBind(), BattleFx_RunBoreas(), BattleFx_RunBurstScene(), BattleFx_RunCastingImpact(), BattleFx_RunCondemn(), BattleFx_RunCybele(), BattleFx_RunDjinnBeams(), BattleFx_RunDjinniEntrance(), BattleFx_RunDouse(), BattleFx_RunElementBurst(), BattleFx_RunElementPillar(), BattleFx_RunFire(), BattleFx_RunFlare(), BattleFx_RunFlashingStrike(), BattleFx_RunFrost(), BattleFx_RunFroth(), BattleFx_RunGaia(), BattleFx_RunGatheringLights(), BattleFx_RunHaunt(), BattleFx_RunIce(), BattleFx_RunImpactBurst(), BattleFx_RunNeptune(), BattleFx_RunNereid(), BattleFx_RunOrbitingSpirals(), BattleFx_RunPaletteParticles(), BattleFx_RunParticleStreams(), BattleFx_RunRingAndSparkScene(), BattleFx_RunShatteringOpening(), BattleFx_RunSpiderWeb(), BattleFx_RunStatBoost(), BattleFx_RunTargetMotes(), BattleFx_RunTargetStrike(), BattleFx_RunThor(), BattleFx_RunTorch(), BattleFx_RunTriangleStrike(), BattleFx_RunUndeadSword(), BattleFx_RunVolcano(), BattleFx_RunWhirlwind(), BattleFx_SteerLiftedTarget(), BattlePalette_StopBlendAndReleaseBuffer(), BattlePres_RunEntryTransition(), BattlePres_SetActorModes(), CastingImpact_EndPrelude(), CharacterMenu_SelectCommand(), CrossboneIslePlatformRooms_ReleaseSecondBlockPlatform(), DisplayScroll_DisarmHBlankDma(), DisplayTransition_Update(), DisplayTransition_UpdateFrame(), DisplayTransition_UpdateFromCentre(), DisplayTransition_UpdateScanlineTable(), EquipmentMenu_StartCompatibilityIndicators(), Event_ConfrontSaturosAndMenardi(), Event_DemonstrateLevitation(), Event_DemonstratePsynergy(), Event_DiscussSuspiciousGuests(), Event_EnterWaterfallGrotto(), Event_MendingTheRoof(), Event_ReadCorneredSuspectsMinds(), Event_RoofMended(), Event_WatchBoulderFall(), FieldEvent_End(), FieldFx_EndCloak(), FieldFx_RunAvoid(), FieldFx_StepRatioTransition(), Graphics_ResetVramBlockAndReleaseHeapBlocks(), ItemMenu_SelectItem(), Kalay_CatchTownNut(), Kalay_WatchTourGroupDeparture(), Map_ShowWorldMap(), Menu_CancelSoundTick(), Menu_EndResourceSelection(), Menu_EnsureCancelSound(), Menu_ReleaseEntryObjects(), Menu_RunCommandRow(), Menu_SelectQuantity(), Menu_SelectResourceLayout(), OptionMenu_Release(), PaletteFade_Release(), PaletteGlow_Stop(), PaletteQueue_Stop(), PsynergyMenu_SelectAction(), ReelGame_Run(), ResetSceneTransitionEffect(), Resource_ScheduleOwnerReset(), SaveMenu_HideDjinnSprites(), SaveMenu_HidePartySprites(), Scheduler_RemoveCallback(), Shop_ReleaseCursorWork(), Shop_RunPartyMemberIconBurst(), System_GetLanguage(), SystemMenu_Release(), Title_ShowIntro(), Ui_SetBank15PaletteAndClearRenderMode(), UiTimedNotice_CloseIfActive(), UiTimedNotice_Tick(), ValeStorm_GaretLeavesIsaac(), ValeStorm_ShowBoulderSweepingDownriver(), and VenusLighthouseAerie_EruptBeacon().

◆ Scheduler_SuspendTasks()

s32 Scheduler_SuspendTasks ( SchedulerCallback callback)

Suspends the task running callback, or every task when callback is null, by setting bit 0 of its order's high byte, which then matches neither pass key.

Returns the last index changed, or -1. Called by the map animation and battle code, through the far-call table, to pause tasks Scheduler_ResumeTasks restarts later.

Definition at line 172 of file scheduler.c.

Referenced by Battle_RunEncounter(), DisplayBlend_SuspendScript(), DisplayTransition_SuspendCallbacks(), FadeOverlay_Suspend(), MapAnimation_Suspend(), ObjectSystem_SuspendProjectionAndShowSprites(), Scheduler_SuspendTasks(), System_GetLanguage(), and WorldMap_BeginStillView().

◆ Scheduler_SuspendOverlayTasks()

s32 Scheduler_SuspendOverlayTasks ( void )

Suspends every task whose routine is in an overlay (EWRAM, 0x02xxxxxx) unless its flag bit 0 asks to keep it running, as Scheduler_SuspendTasks does.

Called by the menus' common code while a menu is open, and by the world map's visibility transition. Returns the last index changed, or -1.

Definition at line 197 of file scheduler.c.

Referenced by BattleFx_RunVisibilityTransition(), Menu_SuspendFieldTasks(), Scheduler_SuspendOverlayTasks(), and System_GetLanguage().

◆ Scheduler_SetTaskFlags()

s32 Scheduler_SetTaskFlags ( SchedulerCallback callback,
u32 mask )

Stores mask as the flags of the task running callback; bit 0 keeps it running while the overlay tasks are suspended.

Called by the link lobby and Colosso scenes for the tasks that must keep running under a menu. Returns its index, or -1.

Definition at line 220 of file scheduler.c.

Referenced by ColossoWall_Initialize(), LinkLobby_EnterBattle(), LinkLobby_RunRoundResult(), Scheduler_SetTaskFlags(), and System_GetLanguage().

◆ Scheduler_ResumeTasks()

s32 Scheduler_ResumeTasks ( SchedulerCallback callback)

Resumes the task running callback, or every task when callback is null, by clearing bit 0 of its order's high byte.

Called by the map animation and field object code. Returns the last index changed, or -1.

Definition at line 243 of file scheduler.c.

Referenced by DisplayBlend_ResumeScript(), FadeOverlay_Resume(), Map_LoadAreaGraphics(), Map_LoadDefaultCellsAndUpdateBlock(), MapAnimation_Resume(), ObjectSystem_ResumeProjectionAndHideLayers(), Scheduler_ResumeTasks(), and System_GetLanguage().

◆ Scheduler_ResumeOverlayTasks()

s32 Scheduler_ResumeOverlayTasks ( void )

Resumes every task whose routine is in an overlay, flagged or not.

Called by the menus' common code when a menu closes, and by the world map's visibility transition. Returns the last index changed, or -1.

Definition at line 265 of file scheduler.c.

Referenced by BattleFx_RunVisibilityTransition(), Menu_ResumeFieldTasks(), Scheduler_ResumeOverlayTasks(), and System_GetLanguage().

◆ Scheduler_RunPass()

void Scheduler_RunPass ( s32 key)

Runs one pass of the scheduler: every task whose order's high byte matches key's (SCHEDULER_KEY_MAIN_LOOP or SCHEDULER_KEY_VBLANK), in table order.

Called once a frame by WaitFrames and once a VBlank by System_VBlankHandler. Nothing runs until Scheduler_ResetTaskTable has set gSchedulerReady.

Definition at line 289 of file scheduler.c.

Referenced by Scheduler_RunPass(), System_GetLanguage(), System_VBlankHandler(), and WaitFrames().