In my game, the properties of all characters on screen are stored in separate arrays. Something like this:
Code: Select all
byte ChrsType[CharCount];
byte ChrsX[CharCount];
byte ChrsY[CharCount];
byte ChrsEnergy[CharCount];
/* ... */
Code: Select all
LDX CharIndex
LDA ChrsType, X
STA CharType
LDA ChrsX, X
STA CharX
LDA ChrsY, X
STA CharX
LDA ChrsEnergy, X
STA CharEnergy
However, while the variables for the player character, for weapons and items are relatively few, each opponent has 35 variables.
This means, in each frame for each opponent, I have 140 LDAs and STAs just for preparation stuff. And most of the stuff gets used only once or not at all during this specific frame.
But simply omitting the rarely-used variables and accessing them directly in the array wouldn't be a solution either, since each read or write of those variables would have yet another LDX CharIndex.
So, is there any way to improve this stuff in a meaningful way? How can I reduce the huge overhead of copying 35 variables from arrays to single variables and then back to the arrays again?
(Unfortunately, I'm not aware of any banking method for RAM, where I would store the variables for each character in the same memory location of different banks and then activate the bank of the currently-processed character.)
By the way, in case you're interested, these are the variables of an opponent. Apart from shortening the access, I would also welcome ways to reduce the number of variables in general:
Code: Select all
BaseType
Type
MetaSpriteIndex
CurrentMetaSpriteIndexForStanding
FacingDirection
X
Y
UntouchableStatus
FlickerDuringUntouchable
PaletteCycleCounter
HorizontalDirection
VerticalDirection
Energy
WalkingPixelsPerFramesIndex
WalkingSpeedId
WalkingCounter
PatternIndex
SubPatternType
SubPatternCounter
UnattackableSoundCounter
PatternIsAdditional
CooldownCounter
CooldownType
StunnedOrThrownAwayCounter
HorizontalDirectionBeforeThrownAway
VerticalDirectionBeforeThrownAway
LoadAfterAttackedPatternNext
DyingStatus
DyingCounter
PreDyingType
IsBoss
LastHorizontalFacingDirection
SubPatternParameter1
SubPatternParameter2
Pattern