TheOpenSpaceProgram / osp-magnum

A spaceship game
https://www.openspaceprogram.org/
MIT License
216 stars 32 forks source link

Refactor IdRegistryStl `for` loops #283

Closed Capital-Asterisk closed 5 months ago

Capital-Asterisk commented 6 months ago

Something to do. This doesn't require too much knowledge of how everything works. Depends on #281, this issue is mostly copied from it.

IdRegistryStl now has iterators. Iterating all possible IDs previously looks something like this:

for (std::size_t const drawEntInt : rScene.m_scnRdr.m_drawIds.bitview().zeros())
{
    auto const drawEnt = DrawEnt(drawEntInt);
    // do something with drawEnt
}

This works because IdRegistryStl is internally just a bit view / bitvector; ones bits are used for free IDs, and zeros bits are used for existing ones. There are countless instances of this in the code (search for "bitview().zeros()"), which can now be replaced with:

for (DrawEnt const drawEnt : rScene.m_scnRdr.m_drawIds)
{
    // do something with drawEnt
}

Task:

Search the entire codebase for ".bitview().zeros()". Then refactor like above.

Capital-Asterisk commented 5 months ago

Fixed in #286. Thanks, Lamakaio!