I remember reading somewhere that using an array of structures is not a good idea but don't remember why it was such a case. Is it really that bad?
For example, let say that I want to keep in a structure all the information about a specific animation. I could be something like this (code may contain mistakes since it is written in the post without testing):
This way I could retrieve a pointer to this group of information like this:
Then once the state change, I would retrieve from that struct the pointers for the animList, value from frameCount at proper index and save them to avoid accessing that structure many time:
So I do not access the array of structure on every frame change but just when the state change. And I keep a reference to the current frame to avoid accessing the other list in anim on every frame to reduce access to arrays of arrays.
I'm aware that right now that structure is maybe complicated. Since I'm experimenting on how I can write code (and enjoying it) the final result may be quite different based on the hurdle I will encounter when using it. Still, any new nes code I write is time I was able to spent on it and learn it so I'm more than happy with that. This is how I was able to make my makeFile that automatically takes any files in any folder in your target without the need to define them one by one and automatically set the include path on all the files so you don't need to write the relative path on every include, which is quite useful. I learned a lot from it.
For example, let say that I want to keep in a structure all the information about a specific animation. I could be something like this (code may contain mistakes since it is written in the post without testing):
Code:
typedef struct {
const unsigned char someAttribute1; // example of extra data
const unsgined char someAttribute2;
const unsigned char frameCount[]; // list for how long are each frame, 0 is end of list
const unsigned char* const frameList[]; // list of frames
} animInfo_t;
...
animInfo_t heroAnimList[] = { .. some list here ... };
const unsigned char someAttribute1; // example of extra data
const unsgined char someAttribute2;
const unsigned char frameCount[]; // list for how long are each frame, 0 is end of list
const unsigned char* const frameList[]; // list of frames
} animInfo_t;
...
animInfo_t heroAnimList[] = { .. some list here ... };
This way I could retrieve a pointer to this group of information like this:
Code:
if ( state == STANDING) {
hero.anim = &heroAnimList[STANDING];
... // will continue next "code" tag
hero.anim = &heroAnimList[STANDING];
... // will continue next "code" tag
Then once the state change, I would retrieve from that struct the pointers for the animList, value from frameCount at proper index and save them to avoid accessing that structure many time:
Code:
// retrieve first frame
hero.frame.maxCount = hero.anim->frameCount[0];
hero.frame.current = hero.anim->frameList[0];
}
hero.frame.maxCount = hero.anim->frameCount[0];
hero.frame.current = hero.anim->frameList[0];
}
So I do not access the array of structure on every frame change but just when the state change. And I keep a reference to the current frame to avoid accessing the other list in anim on every frame to reduce access to arrays of arrays.
I'm aware that right now that structure is maybe complicated. Since I'm experimenting on how I can write code (and enjoying it) the final result may be quite different based on the hurdle I will encounter when using it. Still, any new nes code I write is time I was able to spent on it and learn it so I'm more than happy with that. This is how I was able to make my makeFile that automatically takes any files in any folder in your target without the need to define them one by one and automatically set the include path on all the files so you don't need to write the relative path on every include, which is quite useful. I learned a lot from it.