1 2 3 4 5 6 7 8 9 10 11 | 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:
1 2 3 4 5 6 7 8 9 | 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?