Jump to content

Actor: Difference between revisions

m
no edit summary
No edit summary
mNo edit summary
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 or type, from 0 to 13 (inclusive)
     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 type, uint size)</code>: malloc()s an actor and adds to g_ActorLists.
* <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_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).
Line 63: Line 63:
Each actor type will have a "constructor" function, which calls Actor_Create(), followed by Actor_SetCallbacks(), followed by an actor-specific initialization function.
Each actor type will have a "constructor" function, which calls Actor_Create(), followed by Actor_SetCallbacks(), followed by an actor-specific initialization function.


= Actor types =
= Actor priorities =


{| class="wikitable exportable"
{| class="wikitable exportable"
! Type || Description
! Priority || Description
|-
|-
| 0 || System / TODO
| 0 || System / TODO