Actor: Difference between revisions
Appearance
Created page with "The Boktai games use an actor system to keep track of all "objects" currently existing in the game. Every actor has a callback that will be called every frame. Examples of actors are: Django, the camera, enemies... = Structure = Actors are defined using a pattern similar to object-oriented programming. There is a "base class", <code>Actor</code>, and "subclasses", like <code>DjangoActor</code> for example. Each subclass contains data specific to that actor type (for ex..." |
No edit summary |
||
(5 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
= Structure = | = Structure = | ||
Actors are defined using a pattern similar to object-oriented programming. There is a "base class", <code>Actor</code>, and "subclasses", like <code>DjangoActor</code> for example. Each subclass contains data specific to that actor type (for example, Django's actor would store his position, his stats, his sprite, etc., while the camera would store the camera position). In practice, this looks like this: | Actors are defined using a pattern similar to object-oriented programming. There is a "base class", <code>Actor</code>, and "subclasses", like <code>DjangoActor</code> for example. Each subclass contains data specific to that actor type (for example, Django's actor would store his position, his stats, his sprite, etc., while the camera actor would store the camera position). In practice, this looks like this: | ||
<syntaxhighlight lang="c"> | <syntaxhighlight lang="c"> | ||
Line 20: | Line 20: | ||
u16 unknown_0x10; | u16 unknown_0x10; | ||
u16 flags; // Set to 1 to schedule this actor for deletion in the next frame | u16 flags; // Set to 1 to schedule this actor for deletion in the next frame | ||
u8 priority; // Priority | u8 priority; // Priority, from 0 to 13 (inclusive) | ||
}; | }; | ||
Line 55: | Line 55: | ||
Each game has these functions to deal with actors in general, see each game's ROM map page for their locations: | Each game has these functions to deal with actors in general, see each game's ROM map page for their locations: | ||
* <code>void Actor_RunAll()</code>: Called by main() every frame. Calls onFrame/onDestroy callbacks, and free()s destroyed actors. | * <code>void Actor_RunAll()</code>: Called by main() every frame. Calls onFrame/onDestroy callbacks (starting with priority 0), and free()s destroyed actors. | ||
* <code>Actor* Actor_Create(u8 | * <code>Actor* Actor_Create(u8 priority, uint size)</code>: malloc()s an actor and adds to g_ActorLists. | ||
* <code>void Actor_SetCallbacks(Actor* actor, FrameCallback onFrame, DestroyCallback onDestroy)</code>: Just sets the onFrame/onDestroy fields | * <code>void Actor_SetCallbacks(Actor* actor, FrameCallback onFrame, DestroyCallback onDestroy)</code>: Just sets the onFrame/onDestroy fields | ||
* <code>void Actor_Destroy(Actor* actor)</code>: Schedules an actor for deletion during the next frame (sets actor->flags |= 1). The next Actor_RunAll() will call the onDestroy callback, and then call Actor_Uninstall() followed by free(). | |||
* <code>void Actor_Install(Actor* actor)</code>: Adds an actor to g_ActorLists (automatically called by Actor_Create). | * <code>void Actor_Install(Actor* actor)</code>: Adds an actor to g_ActorLists (automatically called by Actor_Create). | ||
* <code>void Actor_Uninstall(Actor* actor)</code>: Removes an actor from g_ActorLists (automatically called by Actor_RunAll). | * <code>void Actor_Uninstall(Actor* actor)</code>: Removes an actor from g_ActorLists (automatically called by Actor_RunAll). | ||
Each actor type will have a "constructor" function, which calls Actor_Create(), followed by | Each actor type will have a "constructor" function, which calls Actor_Create(), followed by Actor_SetCallbacks(), followed by an actor-specific initialization function. | ||
= Actor | = Actor priorities = | ||
{| class="wikitable exportable" | {| class="wikitable exportable" | ||
! | ! Priority || Description | ||
|- | |- | ||
| 0 || System / TODO | | 0 || System / TODO | ||
Line 78: | Line 79: | ||
| 4 || | | 4 || | ||
|- | |- | ||
| 5 || | | 5 || Timers | ||
|- | |- | ||
| 6 || Protagonist | | 6 || Protagonist | ||
Line 96: | Line 97: | ||
| 13 || | | 13 || | ||
|} | |} | ||
= See also = | |||
* [[Actors (Boktai 1)]] | |||
* [[Actors (Boktai 2)]] | |||
* [[Actors (Boktai 3)]] | |||
[[Category:Documentation]] | [[Category:Documentation]] | ||
[[Category:Boktai 1]] [[Category:Boktai 2]] [[Category:Boktai 3]] | [[Category:Boktai 1]] [[Category:Boktai 2]] [[Category:Boktai 3]] |