Jump to content
  • Advertisement
Sign in to follow this  
Artificial_Idiot

finite state machine class explosion

This topic is 916 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am using state machine with one class for state I have a ground cat and flying cat enemy they both have patrol ,attack , and run away. now I realised that I cant reuse their class and I have to write for each one and I cant use heirarchy because they dont have member viriables cause all they do is call public functions from the cat and flying cat controller. if I have to do this then I have to create the same states for different entities.

Share this post


Link to post
Share on other sites
Advertisement
I am using state machine with one class for state I have a ground cat and flying cat enemy they both have patrol ,attack , and run away. now I realised that I cant reuse their class

Could you elaborate on this? This sentence doesn't suggest re-use is impossible, on the contrary, they seem to have all kinds of behaviour in common.

 

If re-use isn't possible, maybe you didn't abstract at the right level?  What if you consider flying to be "ground at high altitude"? (or driving as "flying at 0 altitude"?)

 

 

 

I cant use heirarchy because they dont have member viriables

Huh? Class hierarchy can exist even if you don't have data. I don't understand your problem sufficiently to say whether inheritance is the right solution, but lack of member variables shouldn't be the problem (if they were, just add a few dummy ones, and you would be done, right?)

 

 

 

cause all they do is call public functions from the cat and flying cat controller

This sounds to me like you actually want composition. Can you split common parts off, and make it a sub-object?

 

Nobody says an object cannot consist of several sub-objects internally.

Edited by Alberth

Share this post


Link to post
Share on other sites
So All of my states have a common interface called IState which has enter,exit,execute,fixedexecute virtual functions. all of this has a parameter to the cat or flying-cat or any other entity. thats why I cant reuse them because their are concrete. I need to make a common interface for the parameter haha thanks.

Share this post


Link to post
Share on other sites

I am not sure if this is relevant to you, but, as of late i have been learning about finite state machines and their use in Python. I came across this example which together with my tutor we determined that it seems to be dynamically able to add and execute functions on the fly for use within the machine (we think...i am still new to this so i do apologise if that is wrong). It might be an example that is unrelated to game design but it might be able to help you in figuring out a more dynamic way to handle your issue?

 

http://www.python-course.eu/finite_state_machine.php

Share this post


Link to post
Share on other sites

If your problem is that the ground cat and the flying cat cannot share the same state classes (i.e. you don't have a patrol state, but a flying patrol state and a ground patrol state) you are probably making the states depend on excessively concrete details of the cats (for example, the controllers explicitly flap wings and walk legs instead of asking an abstract cat interface to go somewhere).

Find a suitable interface for your cats (and presumably for other enemy types) with the operations your controllers need, and your controllers would be able to do their best with any creature (for example, the flying cat is likely to patrol faster and see ground enemies further, but it can patrol by going through a cyclical sequence of waypoints exactly like the ground cat).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!