Editing Wikifang:Network Translation Patchsite/SpriteManager

Jump to navigation Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
Bugsite's metasprite system is a scriptable SpriteManager which manages the movement of objects on a playfield. These objects need to be managed as a collection of hardware sprites (on systems which support them). In GB retroprogramming parlance these collections of sprites are called metasprites. SpriteManager is Bugsite's implementation of a metasprite system.
Bugsite's metasprite system is a scriptable SpriteManager which manages the movement of objects on a playfield. These objects need to be managed as a collection of hardware sprites (on systems which support them). In GB retroprogramming parlance these collections of sprites are called metasprites. SpriteManager is Bugsite's implementation of a metasprite system.
== Directions ==
Sprites can be said to be ''facing'' a certain direction; and these directions themselves are referred to either by enumerants or input bits. Here's which is which:
{| class="wikitable"
|+ Direction Key
|-
! Direction !! Enumerant !! Input bit
|-
| Right / East || 0 || Bit 4
|-
| Left / West || 1 || Bit 5
|-
| Up / North || 2 || Bit 6
|-
| Down / South || 3 || Bit 7
|}


== Metasprite Data Structure ==
== Metasprite Data Structure ==
Line 34: Line 16:
Bit 1: Metasprite is active, meaning the user is expected to be able to see it. Sprites are usually activated and deactivated by a per-frame clip test; however, sprites can also manually deactivate themselves. Deactivated sprites are processed normally, but they do not create visible hardware sprites on screen.
Bit 1: Metasprite is active, meaning the user is expected to be able to see it. Sprites are usually activated and deactivated by a per-frame clip test; however, sprites can also manually deactivate themselves. Deactivated sprites are processed normally, but they do not create visible hardware sprites on screen.


Bit 2: Metasprite is in motion. New animations won't be queued, and choreography scripts won't run, until the animation completes. Stationary animations do not set this flag and are always interruptible animations.
Bit 2: Metasprite is in motion. New animations won't be queued, and idle loop scripts won't run, until the animation completes. Stationary animations do not set this flag and are always interruptible animations.
 
Bit 3: Metasprite is frozen. Choreography scripts will not run and sprite will consistently repeat it's idle animation.


Bit 4: Metasprite is frozen. Choreography scripts will not run and sprite will consistently repeat it's idle animation.
Bit 3: Metasprite has been locked to it's stationary animation.


For some reason, there are two bits with the same effect of freezing the sprite. It is unknown if one bit has different semantics from the other.
Bit 4: Metasprite has been locked to it's stationary animation. For some reason, there are two bits with the same effect. It is unknown if one bit has different semantics from the other.
|-
|-
| SpriteY || +$01 || Y coordinate of sprite (16bit)
| SpriteY || +$01 || Y coordinate of sprite (16bit)
Line 50: Line 30:
| AnimAllowed || +$07 || Must be non-zero for animations to run on this sprite.
| AnimAllowed || +$07 || Must be non-zero for animations to run on this sprite.
|-
|-
| Direction || +$08 || Which direction the sprite is facing.
| FileIndex || +$08 || Offset from the base files for stationary and moving animations.


Acts as an offset from the base files for stationary and moving animations. Is not allowed to exceed 3; further values would be meaningless.
The file index appears to be restricted to the following common indices; BugVM instructions that directly set FileIndex will wrap any further values to zero.
 
{| class="wikitable"
|+ Common indices
|-
! Direction !! FileIndex
|-
| Right / East || 0
|-
| Left / West || 1
|-
| Up / North || 2
|-
| Down / South || 3
|}


''See "[[#Directions|Directions]]".''
|-
|-
| FileAnimStationary || +$09 || BugFS file ID containing an animation script to be used for the stationary animation.
| FileAnimStationary || +$09 || BugFS file ID containing an animation script to be used for the stationary animation.
Line 60: Line 53:
| FileAnimMoving || +$0B || BugFS file ID containing an animation script to be used for walk cycles and other sprite-moving animations.
| FileAnimMoving || +$0B || BugFS file ID containing an animation script to be used for walk cycles and other sprite-moving animations.
|-
|-
| ChoreoRepeat || +$0D || How many times to continue executing the current ChoreoInstr.
| IdleRepeat || +$0D || How many idle frames to continue executing the current IdleInstr.
|-
|-
| ChoreoInstr || +$0E || The current choreography instruction being executed.
| IdleInstr || +$0E || The current IdleInstr being executed.
 
''See "Idle Loop Instructions".''
''See "[[#Choreography_Instructions|Choreography Instructions]]".''
|-
|-
| ChoreoPC || +$0F || Pointer to the next choreography instruction to execute.
| IdlePC || +$0F || Pointer to the next idle loop instruction to execute.
|-
|-
| ChoreoScript || +$11 || Pointer to the start of the current choreography script.
| IdleScript || +$11 || Pointer to the start point of the current idle loop.
|-
|-
| || +$13 to +$1F || Presumed empty
| || +$13 to +$1F || Presumed empty
Line 80: Line 72:
! Field !! Offset !!  
! Field !! Offset !!  
|-
|-
| Playing || +$00 || Set non-zero when an animation is ready to play.
| || +$00 || Purpose unknown. Zeroed upon initialization.
|-
|-
| Delay || +$01 || Amount of frames to wait until next frame of animation.
| Delay || +$01 || Amount of frames to wait until next frame of animation.
Line 91: Line 83:
|-
|-
| AnimPC || +$07 || Pointer to the next animation instruction to execute.
| AnimPC || +$07 || Pointer to the next animation instruction to execute.
''See "[[#Animation_Script_Instructions|Animation Script Instructions]]".''
|-
|-
| SpriteIndex || +$09 || Index of the metasprite slot that this animation serves.
| SpriteIndex || +$09 || Index of the metasprite slot that this animation serves.
Line 108: Line 98:
Yes, Bugsite has ''two of them''.
Yes, Bugsite has ''two of them''.


=== Choreography Instructions ===
=== Idle Loop Instructions ===
Choreography scripts are small lists of instructions that dictate how a non-player-controlled sprite, such as an NPC, will move across the screen. Each instruction is preceded by a repeat count; each instruction will execute that many times before moving to the next instruction. A maximum of one choreography instruction will execute per frame, and choreography instructions wait for their triggered animations to finish before proceeding. Choreography opcodes do not have operands, and only one flow control instruction.
Idle loops are small lists of instructions that dictate how a non-player-controlled sprite, such as an NPC, will move across the screen. Each instruction is preceded by a repeat count; each instruction will execute that many times before moving to the next idle loop. A maximum of one idle instruction will execute per frame, and idle instructions wait for animations to finish before proceeding. Idle loop opcodes do not have operands, and only one flow control instruction.


Setting a repeat value of 0 causes the loop to stop executing instructions. The current instruction will still execute; however, the next time the sprite is processed, the stationary animation for it's current direction will play.
Setting a repeat value of 0 causes the loop to stop executing instructions. The current instruction will still execute.


{| class='wikitable'
{| class='wikitable'
Line 119: Line 109:
| ENOP $nn || $00-$4F || N/A || Treated as effective NOP by the script interpreter.
| ENOP $nn || $00-$4F || N/A || Treated as effective NOP by the script interpreter.
|-
|-
| CNOP $50 || $50 || $33F7 || NOP
| INOP $50 || $50 || $33F7 || NOP
|-
|-
| CNOP $51 || $51 || $33FA || NOP
| INOP $51 || $51 || $33FA || NOP
|-
|-
| CNOP $52 || $52 || $33FD || NOP
| INOP $52 || $52 || $33FD || NOP
|-
|-
| CDOWN || $53 || $341F || Run the sprite's move-down animation.
| IDOWN || $53 || $341F || Run the sprite's move-down animation.
|-
|-
| CUP || $54 || $3436 || Run the sprite's move-up animation.
| IUP || $54 || $3436 || Run the sprite's move-up animation.
|-
|-
| CLEFT || $55 || $344D || Run the sprite's move-left animation.
| ILEFT || $55 || $344D || Run the sprite's move-left animation.
|-
|-
| CRIGHT || $56 || $3464 || Run the sprite's move-right animation.
| IRIGHT || $56 || $3464 || Run the sprite's move-right animation.
|-
|-
| CNOP $57 || $57 || $347B || NOP
| INOP $57 || $57 || $347B || NOP
|-
|-
| CWAIT || $58 || $3400 || Run the stationary animation for the sprite's current direction a random number of times, from $0 to $20.
| IWAIT || $58 || $3400 || Run the stationary animation for the sprite's current direction a random number of times, from $0 to $20.


The repeat value of this instruction is ignored.
The repeat value of this instruction is ignored.
|-
|-
| CSTOP || $59 || $341C || Run the stationary animation for the sprite's current direction.
| ISTOP || $59 || $341C || Run the stationary animation for the sprite's current direction.
|-
|-
| EFGAME $nn || $60-$EF || N/A || Invalid opcodes, will likely crash game.
| EFGAME $nn || $60-$EF || N/A || Invalid opcodes, will likely crash game.
|-
|-
| CHALT || $F0 || $33C0 || Reset the choreography script back to ChoreoScript.
| IHALT || $F0 || $33C0 || Reset the idle loop back to IdleScript.


The repeat value of this instruction is always treated as 0 (e.g. halt).
The repeat value of this instruction is always treated as 0 (e.g. halt).
|-
|-
| CRESET || $F1 || $33E2 || Reset the choreography script back to ChoreoScript.
| IRESET || $F1 || $33E2 || Reset the idle loop back to IdleScript.
|-
|-
| EFGAME $nn || $F2-$FF || N/A || Invalid opcodes, will likely crash game.
| EFGAME $nn || $F2-$FF || N/A || Invalid opcodes, will likely crash game.
|}
|}


''Please keep in mind that directional commands such as CDOWN, CUP, CLEFT, and CRIGHT do not actually move the sprite.'' Instead, they queue the animation script associated with that direction. The animation script itself moves the sprite; it's only by convention that, e.g. CDOWN always executes a script that moves the sprite down two tiles. Furthermore, script execution is predicated upon the target tiles being free; if they are occupied, then the choreography script will halt until that slot becomes free. This has the following consequences:
''Please keep in mind that directional commands such as IDOWN, IUP, ILEFT, and IRIGHT do not actually move the sprite.'' Instead, they queue the animation script associated with that direction. The animation script itself moves the sprite; it's only by convention that, e.g. IDOWN always executes a script that moves the sprite down two tiles. Furthermore, script execution is predicated upon the target tiles being free; if they are occupied, then the idle script will halt until that slot becomes free. This has the following consequences:


* The movement path specified by the choreography script will be followed exactly.
* The movement path specified by the idle script will be followed exactly.
* Sprites can get 'stuck' on stationary walls, or even each other.
* Sprites can get 'stuck' on stationary walls, or even each other.
* NPCs will 'box in' players, never moving until the player moves out of their way, as the player is just another sprite.
* NPCs will 'box in' players, never moving until the player moves out of their way, as the player is just another sprite.
Eight choreography script slots exist in memory starting at $2:DC00. Each script storage slot is 128 bytes maximum.


=== Animation Script Instructions ===
=== Animation Script Instructions ===
Please note that all contributions to Wikifang are considered to be released under the Attribution-NonCommercial-ShareAlike 3.0 Unported (see Wikifang:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)