I'm creating a multiplayer video game for fun, I have a server and a client running. I would like to optimized as much as I can the process on the server. The server lag when we receive to much information from different clients at the same time.
I would like to check with you if what I have done could be optimized, I feel like it easily could.
There we go with the code :
We have a map :
std::vector< std::vector < caseMap > > _map;
A simple object caseMap :
struct caseMap
{
int areaId;
bomb *bombs;
Bonus *bonus;
int underEffect;
int effectOwnerId;
std::list< player* > players;
};
We access a lot of time to map case following this operation : ( example when a player die )
this->_map[pl->getPosY()][pl->getPosX()].players.erase(itp);
There is my question and solution : - We could have one vector only instead of two, and have a little formula to retrieve the actual case we are looking for.
But is it heavy to use it the way I do right now ? I thought accessing by [] was big O constant, so it should not be super heavy.
Can I use some const reference at some point ?
Should I use a different object such as std::map ?
I'm a bit confused if you guys can refresh my brain on c++ code. Thank you :)