Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use so_default_state as a parent state for an another state #13

Open
zamazan4ik opened this issue Jun 6, 2020 · 3 comments
Open

Use so_default_state as a parent state for an another state #13

zamazan4ik opened this issue Jun 6, 2020 · 3 comments

Comments

@zamazan4ik
Copy link
Contributor

Hi!

Is it possible with SObjectizer to use default agent state (which is returned with so_default_state) as a parent state for another state? I am trying to do something like this:

state_t NotStarted{initial_substate_of(so_default_state()), "NotStarted"};

Unfortunately initial_substate_of takes a non-const reference but so_default_state returns const reference, so it doesn't compile.

Is there any workaround (except introducing own "default" state and making it as a parent for another events)? Is it a limitation by design?

Thank you.

@eao197
Copy link
Member

eao197 commented Jun 6, 2020

Good question! :)

I think it's some heritage from ancient times. I don't think there are some reasons that prevent making agent_t::st_default non-const member of agent_t. I'll try to look deeper tomorrow (or Monday) and if there is no any other issues I'll change the st_default and add a new overload for so_default_state.

@eao197
Copy link
Member

eao197 commented Jun 7, 2020

There is a hidden underwater rock: a call to on_enter handlers for child states. For example:

class demo final : public so_5::agent_t {
   state_t st_parent{this, "parent"};
   state_t st_child_1{initial_substate_of{st_parent}, "child_1"};
   state_t st_child_2{substate_of{st_parent}, "child_2"};
   ...
   void so_define_agent() override {
      st_child.on_enter([]{ std::cout << "Hello, World!" << std::endl; });
      ...
      this >>= st_parent;
   }
};

In that case "Hello, World" would be printed at the start of demo agent.

But in that case:

class demo final : public so_5::agent_t {
   state_t st_child_1{initial_substate_of{so_default_state()}, "child_1"};
   state_t st_child_2{substate_of{so_default_state()}, "child_2"};
   ...
   void so_define_agent() override {
      st_child.on_enter([]{ std::cout << "Hello, World!" << std::endl; });
      ...
   }
};

The enter handler for st_child won't be called at the start of demo agent. It's because st_default is already the current state for the agent and SObjectizer doesn't know about changes that should be taken into the account.

@zamazan4ik
Copy link
Contributor Author

Hm... interesting case. In my opinion that's just "nice to know" thing, which shall be documented, if you want to allow so_default_state as a parent state in SObjectizer. In my case the example above doesn't matter at all.

For now locally I just created my own default state :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants