Accessing 2 arrays using indices of one array [Problem]

Started by
13 comments, last by lipsryme 10 years, 10 months ago

AB=AAA...ABBB...B

if the entity is of type B:

IndexInAB = AmountOfA + AmountOfBEntitiesBeforeEntity + 1 //i think

if its A:

IndexInAB = AmountOfAEntitiesBeforeEntity + 1

This is assuming that you add the A/B in the AB container each time you add a new entity, always at the end of all As or Bs, and that the entity you add will be the highest ID and that there are no gaps in the entity ID's

But if you are going for something dynamic your system isnt really going to work. It might work for some serialization but for other things not so well.

o3o

Advertisement

No wait i might have misunderstood the question.

In the code you posted with vectors A,B,C

when going over B you should remove the amount of A from the index and it should work.

o3o

That's exactly the problem. Let's consider I instantiate 3 of type A first. So these will have sceneIDs of (0,1,2).

Accessing them using these indices - amount of B works of course because B is 0.

Now when I instantiate one of B it's going to crash because the amount of B is now 1. So when going through the array above for all the A's (0, 1, 2) the 0 is going to become -1 when subtracting the amount of B's from it.

So you have A0, A1, A2, B3

you can directly use the A indices.
But to use B index (3) you need to subtract amount of A, which gets you 0, the correct B index.

o3o

That's true but in return A would fail if you were to do the same for getting the A index, because then it would give you -1, 0, 1 as indices for 0, 1, 2 scene ID's.

I don't think my design will work at all. If there's a perfect and easy solution to calculate the exact Indices from the sceneID's then that would be great, but I'm probably going to have to change my design.

Update: Got it working. I redesigned it to store an std::pair<unsigned int, unsigned int> to always store the actual data ID in combination with the unique sceneID.

Was a few hours of work but this was the best solution.

This topic is closed to new replies.

Advertisement