I'm having trouble coming up with a good design for a project I'm doing. The below works, but I feel it's messy at best to have a member class take the 'this' pointer from it's owner. Any tips on structure would be great. What I'm trying to...
I'm having trouble coming up with a good design for a project I'm doing. The below works, but I feel it's messy at best to have a member class take the 'this' pointer from it's owner. Any tips on structure would be great.
What I'm trying to do:
In essence, it's an automata system. Each entity is in a state and that state determines how it updates. Entities call a different update function that changes during runtime.
How I've implemented it:
Code:
class entity
{
public:
Update() { state->update(this); }
int getDataForUpdate();
private
State* state;
//other stuff
};
class State
{
public:
Update(entity& toUpdate) { return DoStuffForUpdate( toUpdate->getDataForUpdate())}
// other stuff
};