So I'm currently designing and implementing my animation system for my game and I've come across some thoughts that I wanted to get some advice on. So far I've completed my first pass of the animation system api using a compression oriented approach to basically get things working. I don't have all the aspects worked out but enough so that I want to tighten up the API a bit before moving on. After mocking out an easily readable API my class's would now look something like:
| struct Skeleton
{
//some other members
Dynamic_Array<Bone> bones;
}
struct Animation
{
//some other members
Dynamic_Array<Bone*> bones;
}
|
The animation struct would have bone pointers which point to the Skeleton's bones. With this current setup I have function which setups the skeleton for the given animation and that would look something like this:
| void SetupPose(Anim* anim)
{
//Other code
for(i32 boneIndex{}; boneIndex < anim.bones->size; ++boneIndex)
{
anim.bones->at(boneIndex).rotation = newRotation;
}
}
|
After observing this function I didn't like the fact that passing in an animation will actually effect the skeleton's bone positions without it being immediately apparent to the caller. With this setup I could forsee many functions that could be effecting a skeleton's bone properties without ever having to pass in the actual skeleton to the function, again possibly making things ambiguous as to where my skeleton gets modified in the code base.
After some more thought though I realize that this kind of thing is probably happening in a lot of places around my code base, given my sort of cavalier attitude towards pointers. For whatever reason this particular instance caught my attention when other situations didn't.
My questions are is this sort of situation something I should be trying to avoid or not really a big deal? Is this what people talk about when suggesting to avoid pointers whenever possible as they can make things less understandable? How should one generally go about managing pointers when making API decisions?