Exploiter what do you think about my manager class, I'd not mind some input.
Although your PointerPack class is missing and I can give you some feedback on the provided code.
From the technical point it seems to be working good, i.e. I didn't see any mistakes, but I didn't test it.
From a code design perspective one can still change a few things.
The interface of the state manager is not very nice imho, personally I'd use something more like this:
void run();//main function that runs top state
void push(State::Ptr state);//no need to play with raw ptr here either
void pop(int amount=1);//=1 for convenience of removing 1 state
void leave(int amount=0);//=0 for convenience of closing up
std::size_t count()const;
PointerPack& pack()
You're missing const correctness in your state manager as well (
const std::size_t,
const int amount, ...).
Then for the state's destructor (
virtual ~State()=0{};), I'm not even sure if you can define a function as pure virtual and then give it a body anyways.
m_Stack.push_back(std::move(state));//i liked no std::move version more i think..
Don't be afraid of the use of
std::move, it might seem a bit unintuitive in the beginning, but it's the right way to go.
for(int i=0;i<amount;++i)
Always use
unsigned int if your index can't get negative.
Also don't be afraid to use spaces every now and then, it will make your code much easier to read.
As I said, I don't know how you've implemented the PointerPack, but
m_PointerPack.m_Manager=this; shows, that you've got a public member variable, which in nearly all cases is a bad thing and on top of that it's a pointer. A probably better way, would be to pass the deferenced this pointer to the constructor of the pointer pack, which internally holds a reference on the manager. Then you can provide access to the manager, with any kind of function.
Or wait, does pointer pack actually mean, a struct of raw pointers?
Well that'd be a lazy way around designing a nice engine.
I mean you can do it in such a way (if you can't think of any nicer way), but use a proper class with the right safety mechanisms around it.
As for your InitLock, I've no idea what it's used for, but it seems highly like a hack and the fact that you rely on init and uninit functions doesn't sound good at all. Every class has its constructor and destructor, there's no need to define pseudo c-/d-tors and then use an InitLock to simulate the otherwise normal behavior. Besides the illogical handling, it'd guess that you could prevent quite a few compiler optimizations and make it easier for a user to wrongly use your classes. Just use the constructor and destructor of your classes instead.