Alchemy
Loading...
Searching...
No Matches

arcs.c

Go to the documentation of this file.
1/// @file
2/// The swelling arcs over the caster.
3/// Part of psynergy_effects.c, compiled only through it.
4
6
7/// Per-frame update of arc A: over 32 frames it swells and shrinks again
8/// (scale sin(frame / 64 turn)) while it rises a pixel a frame on the object
9/// it follows, 9 pixels in front of it and up to 5 pixels further while
10/// small.
12 // A shared inline kernel with a constant inversion argument changes both
13 // arc updates from 0x58 to 0x5c bytes in the forced native English build.
14 struct FieldActor *arc = (struct FieldActor *)fieldObject;
15 struct FieldActor *anchor;
16 s32 frame;
17 s32 scale;
18
19 anchor = arc->linkedObject;
20 frame = ++arc->timer;
21 if (frame > 31) {
24 return;
25 }
26 scale = Trig_Sin(frame << 10);
27 arc->scaleX = scale;
28 arc->scaleY = scale;
29 arc->x.fixed = anchor->x.fixed;
30 arc->y.fixed += 0x10000;
31 arc->z.fixed = anchor->z.fixed + (0x10000 - scale) * 5 + 0x90000;
32}
33
34/// Per-frame update of arc B: arc A upside down, 16 pixels in front of the
35/// object and up to 5 pixels nearer while small.
37 struct FieldActor *arc = (struct FieldActor *)fieldObject;
38 struct FieldActor *anchor;
39 s32 frame;
40 s32 scale;
41
42 anchor = arc->linkedObject;
43 frame = ++arc->timer;
44 if (frame > 31) {
47 return;
48 }
49 scale = Trig_Sin(frame << 10);
50 arc->scaleX = scale;
51 arc->scaleY = -scale;
52 arc->x.fixed = anchor->x.fixed;
53 arc->y.fixed += 0x10000;
54 arc->z.fixed = anchor->z.fixed - (0x10000 - scale) * 5 + 0x100000;
55}
56
57/// A sprite as the arcs set it up: its three OAM attributes and its
58/// bookkeeping.
59struct ArcSprite {
61 u16 y : 8;
64 u16 mode : 2;
66 u16 color : 1; ///< 1 = 256 colours
68 u16 x : 9;
72 u16 size : 2;
73 u16 tile : 10;
76 u8 pad0a[18];
77 u8 slot; ///< VRAM block
84};
85
86/// Spawns the two swelling arcs (object 26) on an object, A and B (B upside
87/// down); they follow it for 32 frames.
89 struct BattleFxScene *scene = gEffectWork;
90 struct FieldActor *source = scene->mainObject;
91 struct FieldActor *arcs[2];
92 struct FieldActor *arc;
93 struct ArcSprite *sprite;
94 s32 arcIndex;
95
96 for (arcIndex = 0; arcIndex <= 1; arcIndex++) {
97 arc = (struct FieldActor *)Object_CreateFar(
98 26, linked->x.fixed, linked->y.fixed, linked->z.fixed);
99 arcs[arcIndex] = arc;
100 if (arc == 0)
101 continue;
102 arc->terrainHeight = linked->terrainHeight;
103 sprite = (struct ArcSprite *)arc->sprite;
104 arc->motionFlags = 0;
105 arc->timer = 0;
106 arc->linkedObject = linked;
107 arc->scaleX = arc->scaleY = 0x1999; // 0.1
108 if (sprite == 0)
109 continue;
110 // A wide 16-colour sprite drawn from the effect's tiles.
112 sprite->flags = 0;
113 Resource_ResetEntry(sprite->slot);
114 sprite->slot = scene->tileSlot;
115 sprite->active = 1;
116 sprite->tile = (gVramBlockCache[sprite->slot].offset >> 5) & 0x3ff;
117 sprite->color = 0;
118 sprite->shape = 1;
119 sprite->size = 2;
120 sprite->child->frame = 0;
121 }
122 // Arc B in front of everything, arc A at the caster's priority.
123 // BUG: allocation failures above leave a missing arc or sprite here.
124 // The original does not define a partial-pair recovery path.
126 arcs[0]->sprite->image.priority = 0;
128 arcs[1]->sprite->image.priority = source->sprite->image.priority;
129 arcs[1]->priorityFlags = 2;
130}
131
132/// Per-frame update: flashes an object between sprite param 7 and 0 every 2
133/// frames and spawns the swelling arcs on it every 16.
135 struct FieldActor *actor = (struct FieldActor *)fieldObject;
136 if ((gFrameCount & 2) != 0) {
138 } else {
140 }
141 if ((gFrameCount & 15) == 0) {
143 }
144}
145
146/// Per-frame update: cycles an object through sprite params 0 to 5, one step
147/// every 2 frames, and spawns the swelling arcs on it every 16.
149 struct FieldActor *actor = (struct FieldActor *)fieldObject;
150 if ((gFrameCount & 1) != 0) {
151 s32 colorIndex = (gFrameCount >> 1) % 6;
152
153 Animation_ApplyChildValuesFar((struct DispatchObject *)actor, colorIndex);
154 }
155 if ((gFrameCount & 15) == 0) {
157 }
158}
void BattleFx_FlickerObjectAndTick(union FieldObject *fieldObject)
Per-frame update: flashes an object between sprite param 7 and 0 every 2 frames and spawns the swelli...
Definition arcs.c:134
void FieldFx_CycleObjectValueByCounter(union FieldObject *fieldObject)
Per-frame update: cycles an object through sprite params 0 to 5, one step every 2 frames,...
Definition arcs.c:148
void FieldFx_UpdateScaledArcObjectA(union FieldObject *fieldObject)
Per-frame update of arc A: over 32 frames it swells and shrinks again (scale sin(frame / 64 turn)) wh...
Definition arcs.c:11
void BattleFx_SpawnScaledArcObjects(struct FieldActor *linked)
Spawns the two swelling arcs (object 26) on an object, A and B (B upside down); they follow it for 32...
Definition arcs.c:88
void FieldFx_UpdateScaledArcObjectB(union FieldObject *fieldObject)
Per-frame update of arc B: arc A upside down, 16 pixels in front of the object and up to 5 pixels nea...
Definition arcs.c:36
struct ObjectRuntime * Object_CreateFar(s32 id, s32 x, s32 y, s32 z)
Far call to FieldObject_Create.
s32 AnimationObjects_SelectAnimationFar(struct AnimationObject *state, s32 flags)
void ObjectDispatch_InitializeFar(struct DispatchObject *obj, const s32 *script)
void Animation_ApplyChildValuesFar(struct DispatchObject *obj, u32 val)
s32 Trig_Sin(s32 angle)
volatile u32 gFrameCount
Frames WaitFrames has finished.
const s32 gBattleFx_CommonParticleScript[]
[0] only frees the actor, +1 waits for it to arrive and frees it; +3 is gBattleFx_SourceHoldScript,...
Definition fxdata.c:444
void * gEffectWork
Slot 56: points to a scene-specific structure.
What every part of psynergy_effects.c shares: its includes and the macros and types more than one par...
One animation layer of a sprite: its animation id, frames, running script and timer.
Definition animspr.h:37
An animated sprite: its image and shadow, scale, rotation, size and up to four animation layers.
Definition animspr.h:108
u8 flags
bits: 1 outlined in ObjectSystemWork's edge and fill colours | 0 shadow drawn (set when created)
Definition animspr.h:128
u8 slot
VRAM cache entry holding its tiles.
Definition animspr.h:112
A sprite as the arcs set it up: its three OAM attributes and its bookkeeping.
Definition arcs.c:59
u8 pad00[4]
Definition arcs.c:60
u16 x
Definition arcs.c:68
u8 active
Definition arcs.c:78
u8 flags
Definition arcs.c:81
u16 priority
Definition arcs.c:74
u16 unused
Definition arcs.c:69
u8 displayFlags
Definition arcs.c:79
u16 tile
Definition arcs.c:73
u8 pad1e[8]
Definition arcs.c:80
u8 pad0a[18]
Definition arcs.c:76
u8 slot
VRAM block.
Definition arcs.c:77
u16 palette
Definition arcs.c:75
u16 hflip
Definition arcs.c:70
u16 y
Definition arcs.c:61
u16 mosaic
Definition arcs.c:65
u16 size
Definition arcs.c:72
struct AnimationEntry * child
Definition arcs.c:83
u16 vflip
Definition arcs.c:71
u16 affine
Definition arcs.c:62
u16 color
1 = 256 colours
Definition arcs.c:66
u16 shape
Definition arcs.c:67
u16 doubleSize
Definition arcs.c:63
u16 mode
Definition arcs.c:64
u8 pad27
Definition arcs.c:82
The work of a Psynergy effect scene: its caster and target, where it takes place, the map state it re...
Definition fx_scene.h:31
u16 tileSlot
resource entry holding the spark tiles
Definition fx_scene.h:64
void * mainObject
the caster's object
Definition fx_scene.h:36
A field object as the object dispatcher's far calls take it.
A field actor: a person or thing on the field with a position, motion toward a target,...
Definition field_obj.h:30
s16 timer
The parameter its action script reads (a follow distance or an angle to face), the player's frames to...
Definition field_obj.h:109
struct FieldActor * linkedObject
The object its action script follows or faces.
Definition field_obj.h:114
u8 motionFlags
ActorMotionFlag bits; zero is free flight in 3D, and 3 is set on creation.
Definition field_obj.h:83
union FieldCoordinate x
16.16 fixed-point pixels
Definition field_obj.h:35
union FieldCoordinate y
16.16 fixed-point pixels
Definition field_obj.h:36
u8 priorityFlags
ActorPriorityFlag bits, read by the scrolling camera.
Definition field_obj.h:51
s32 terrainHeight
16.16 fixed-point pixels
Definition field_obj.h:38
union FieldCoordinate z
16.16 fixed-point pixels
Definition field_obj.h:37
s32 scaleX
16.16 fixed point, 0x10000 full size
Definition field_obj.h:39
s32 scaleY
16.16 fixed point, 0x10000 full size
Definition field_obj.h:40
void(*) update(union FieldObject *object)
Called each frame before the object's script, while the object is live.
Definition field_obj.h:116
u16 offset
bytes from the start of OBJ VRAM
Definition vram_tab.h:25
signed int s32
Definition types.h:14
unsigned short u16
Definition types.h:13
unsigned char u8
Definition types.h:11
s32 fixed
16.16 fixed-point pixels
An object on the field, read as an actor or as an effect.
s32 Resource_ResetEntry(u32 no)
Frees cache entry no: its blocks go back and the entry is marked free (offset 0xffff).
Definition vram_cache.c:106
struct VramBlockCacheEntry gVramBlockCache[]