So great to hear! I also have a Morse Code Arduino project video here on TH-cam that has source code that uses a state pattern as well! Please feel free to tinker!
Thank you for viewing! I believe I made about four or five of these videos. My "C++ Game Programming" video series has the design pattern videos as a subset for now. I'm not sure if I will be able to do many more in the near future.
My understanding is that template member functions must be defined in the same file as the header. I think you get pretty nasty linker errors that seem unsolvable, or at least I know I had that experience in the past. Does it work for you if you move the function to the implementation file?
A small enhancement. I think owner should have nextState, curState pointers. And in changeState, we should only update nextState (i.e. not delete curState). Later, after the step function, we should call owner->updateState(); which should do void updateState(); { if( !nextState ) return; delete curState; curState=nextState; nextState=nullptr; }
The state update is performed in Step() when CountDown hits 0, no need to call it yourself in main(). Also, how will you pass type info for nextState into your updateState() function? Why even use nextState when you can just pass in the new state type as a template parameter?
Thanks, very thoughtful presentation. I'm working on C++ IoT state machines. The game perspective is illuminating!
Thanks this helped me with my arduino project.
So great to hear! I also have a Morse Code Arduino project video here on TH-cam that has source code that uses a state pattern as well! Please feel free to tinker!
Awesome video. Can you please create a playlist that has all the design pattern videos in 1 place?
Thank you for viewing! I believe I made about four or five of these videos. My "C++ Game Programming" video series has the design pattern videos as a subset for now. I'm not sure if I will be able to do many more in the near future.
In state design patten, is it always the case the main state will hold a pointer to state class and state class will hold a pointer to Main class?
Hi Bradley, thanks once again for the great quality videos. May I ask does the state design pattern also go by the name memento design pattern?
Is there any specific reason that you put ChangeCurrentState() in header file not cpp file?
My understanding is that template member functions must be defined in the same file as the header. I think you get pretty nasty linker errors that seem unsolvable, or at least I know I had that experience in the past. Does it work for you if you move the function to the implementation file?
@@bradleysward I was taught to make the class templated if the member function is templated, but apparently your way works and seems easier!
HI Bradley, can you please share the source code of this design pattern? or else please share me the link from where i can download the source code
Hi, I just wonder why the example did not use smart pointer to represent ownership?
Un capo ud
A small enhancement. I think owner should have nextState, curState pointers. And in changeState, we should only update nextState (i.e. not delete curState). Later, after the step function, we should call owner->updateState(); which should do
void updateState();
{
if( !nextState ) return;
delete curState;
curState=nextState;
nextState=nullptr;
}
The state update is performed in Step() when CountDown hits 0, no need to call it yourself in main(). Also, how will you pass type info for nextState into your updateState() function? Why even use nextState when you can just pass in the new state type as a template parameter?