Giter Club home page Giter Club logo

hsm's People

Contributors

amaiorano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hsm's Issues

whats wrong with my code which uses hsm?

hi,
i'm writing a game (my menu state), but i have this problem which i couldn't fix:
when i select the item, it is selected, but the next menu doesnt do well
here is my code:
states.cpp
``C++
#include "hsm.h"
#include "vars.h"
#include "functions.h"
#include "states.h"

void ExitState::OnEnter()
{
Tolk_Speak(L"thanks for playing", true);
s.fadeGlobalVolume(0.0, 2.0);
SDL_Delay(2000);
quit=true;
}

hsm::Transition ExitState::GetTransition()
{
return hsm::NoTransition();
}

void MainMenuState::OnEnter()
{
//initialize the main menu
mainmenu.load_menumove_from_memory((unsigned char*)cfl->getFile("menumove.ogg"), cfl->getFileSize("menumove.ogg"));
mainmenu.load_menuedge_from_memory((unsigned char*)cfl->getFile("menuedge.ogg"), cfl->getFileSize("menuedge.ogg"));
mainmenu.load_menuselect_from_memory((unsigned char*)cfl->getFile("menuselect.ogg"), cfl->getFileSize("menuselect.ogg"));
//play the mainmenu music
menumusic_handle=s.play(mainmusic);
//add things to menu
mainmenu.add(L"start game");
mainmenu.add(L"test speakers");
mainmenu.add(L"exit");
should_change=false;
item=mainmenu.run(L"use up and down arrow keys to navigate and press enter to activate the menu");
}

void MainMenuState::Update()
{
should_change=!mainmenu.is_running();
if(!should_change)
{
item=mainmenu.run(L"use up and down arrow keys to navigate and press enter to activate the menu");
}
}

hsm::Transition MainMenuState::GetTransition()
{
if(should_change)
{
if(mainmenu.get_item(item)==L"start game")
{
return hsm::SiblingTransition();
}
else if(mainmenu.get_item(item)==L"exit"||item<0)
{
return hsm::SiblingTransition();
}
else if(mainmenu.get_item(item)==L"test speakers")
{
s.stopAll();
return hsm::SiblingTransition();
}

}
else
{
return hsm::NoTransition();
}
return hsm::NoTransition();
}

void TestSpeakerState::OnEnter()
{
speakertesthandle=s.play(speakertest);
}

hsm::Transition TestSpeakerState::GetTransition()
{
if(s.isValidVoiceHandle(speakertesthandle))
{
SDL_Delay(2000);
return hsm::SiblingTransition();
}
return hsm::NoTransition();
}

void startgameState::OnEnter()
{
m.add(L"start a new game");
m.add(L"load a saved game");
m.add(L"delete a saved game");
m.add(L"go back to main menu");
should_change=false;
item=m.run(L"choose an option");
}

void startgameState::Update()
{
should_change=!m.is_running();
if(!should_change)
{
item=m.run(L"choose an option");
}
}

hsm::Transition startgameState::GetTransition()
{
if(should_change)
{
if(m.get_item(item)==L"go back to main menu")
{
return hsm::SiblingTransition();
}
}
else
{
return hsm::NoTransition();
}
return hsm::NoTransition();
}

`
states.h
``C++
#pragma once
#ifndef states_h
#define states_h

#include "hsm.h"
#include "menu.h"

//the menu state
class MainMenuState: public hsm::State
{
int item;
int menumusic_handle;
menu mainmenu;
bool should_change;
public:
hsm::Transition GetTransition();
void OnEnter();
void Update();
};

//test speaker state
class TestSpeakerState: public hsm::State
{
int speakertesthandle;
public:
void OnEnter();
hsm::Transition GetTransition();
};

//the exit state
class ExitState: public hsm::State
{
public:
hsm::Transition GetTransition();
void OnEnter();
};

class startgameState: public hsm::State
{
int item;
menu m;
bool should_change;
public:
void OnEnter();
void Update();
hsm::Transition GetTransition();
};

#endif //states_h
`
please tell me whats wrong with this state (without state, i could use my menu class correctly. but now i cant)
it can switch states, but the next state doesn't work
the exitState works as expected, just the start game state has problem which i couldnt fix

Why is the state stack processed from outermost to innermost?

Consider this case:

  1. outer state A handles an event E
  2. A has several inner states: B, C, D
  3. B and C ignore event E
  4. D handles E differently from A.

According to https://github.com/amaiorano/hsm/wiki/Chapter-3.-The-H-in-HSM#algorithm and based on my understanding, state stack is processed from the outermost state, e.g. state A. If A::GetTransition() returns SiblingTransition() or InnerTransition() and the current state is D, then D is popped from stack and has no chance to handle the event.

Pls correct me if I was wrong.

plotHsm.py hangs

Not really sure what is going on here. Figured I'd bring it to your attention.

Traceback (most recent call last):
  File "plotHsm.py", line 46, in <module>
    sys.exit(main())
  File "plotHsm.py", line 36, in main
    ExecCommand(os.path.join(GetScriptPath(), 'hsmToDot.py') + ' ' + filespec + ' > ' + dotFile)
  File "plotHsm.py", line 22, in ExecCommand
    raise Exception("Command failed!")
Exception: Command failed!

However I can successfully generate the png if I do the steps manually

python hsmToDot.py ../samples/hsm_book_samples/source/ch4/state_args.cpp > myfile.dot
dot myfile.dot -Tpng -o myfile.png

myfile

ue4 integration

I'm trying to use the HSM with ue4, however enabling RTTI in ue4 makes packagingimpossible, but when I don't enable it I can't seem to get it to work because of the RTTI.
image

Transition from innerstate to sibling of parent state not executing parent OnExit()

Is it possible to return a SiblingTransition from an inner state to a sibling of the parent state?
I have tried this, and it seems that the OnExit of the parent state is not executed

             Moving    ----   Idling
            /      \
    Opening         Closing

So when returning SiblingTransition<Idling> from state Opening, the OnExit() of Opening is executed, but the OnExit() from Moving is not. Also when enabling TraceLevel::Diagnostic you only see a Pop: Opening and a Sibling: Idling , missing the Pop:Moving

Is this a bug or I i'm doing something wrong? How can I solve this?

Question About State Inheritance

How can I use this in a more object oriented fashion. Your book examples reference all the code concurrently in a single CPP avoiding having to forward declare a class. If I were to organize my states into .h and .cpp files respectively and try to forward declare a class it fails the static assertion checks. Example being
`
//in State_Idle.h
class State_Ready;
class State_Idle : public AbstractState{
}
//where AbstractState inherits hsm::State

//in State_Idle.cpp
//constructors, destructors, etc

#include State_Ready.h

//in State_Ready.h
class State_Ready: public AbstractState{
}
`

Thanks for your help.

How best to parameterize a "return" transition of a state

Example: A leveling system, which has a LEVELING state.
This LEVELING state can be started by a external LEVEL command. This will start actuators based on an MPU until the platform is level and state will return to IDLING

But the system also has an EXTEND_LEVEL command, which will raise the platform level as far a possible.

The EXTENDING_LEVEL state raises the platform by starting all actuators, but when its not level anymore, it will transition to state LEVELING. When its LEVEL again, it will continue raising the platform until MAX_LIMIT is reached.

So the LEVELING state can be started from IDLING state and from EXTENDING_LEVEL state and has to return to that state when the platform is level.

What is the best way to tell the LEVELING state to which state it has to transition when the platform is LEVEL?

Publish current state via owner

I want to be able to access the current state of the statemachine through the owner, preferably with an enum value.

I could set this value in the OnEnter() method of every state, but I was wondering if there isn't an easier way to do this

C++11/14

Currently the library supports C++03, which is good for compatibility. But C++11/14 would allow for simplifying certain features (e.g. StateArgs), and remove some code that is now part of the standard (e.g. type traits). Maybe it's time to cut the cord on old compilers as most modern compilers (clang, gcc, msvc) implement most of C++11/14 today.

Add deprecation macro

#ifdef __GNUC__
#define HSM_DEPRECATED(MESSAGE) __attribute__((deprecated("DEPRECATED: " MESSAGE)))
#elif defined(_MSC_VER)
#define HSM_DEPRECATED(MESSAGE) __declspec(deprecated("DEPRECATED: " MESSAGE))
#else
#pragma message("Implement HSM_DEPRECATED for this compiler")
#define HSM_DEPRECATED
#endif

Single header file for entire library

Currently HSM consists of 5 headers and a single cpp file; the latter is a pain because client code has to build it. Also, the directory structure separating the cpp and headers isn't great either.

If the entire library were just a single header file, hsm.h, it would be simpler to use.

error: 'GetStaticStateType' is not a member of 'MyStates::STATENAME'

When trying to use this library I get the error:
error: 'GetStaticStateType' is not a member of 'MyStates::STATENAME' for my specific implementation.

Any ideas what could be causing this? I am running c++11
image

Heres the example code from the wiki I am trying to use
(https://github.com/amaiorano/hsm/blob/master/samples/hsm_book_samples/source/ch3/inner_transition.cpp)

#include "../lib/hsm/include/hsm.h"

using namespace hsm;

class MyOwner
{
public:
    MyOwner();
    void UpdateStateMachine();

    void Die() { mDead = true; }
    void SetMove(bool enable) { mMove = enable; }

private:
    bool IsDead() const { return mDead; }
    bool PressedMove() const { return mMove; }

    bool mDead;
    bool mMove;

    friend struct MyStates;
    StateMachine mStateMachine;
};

struct MyStates
{
    struct BaseState : StateWithOwner<MyOwner>
    {
    };

    struct Alive : BaseState
    {
        virtual Transition GetTransition()
        {
            if (Owner().IsDead())
                return SiblingTransition<Dead>();

            return InnerEntryTransition<Locomotion>();
        }
    };

    struct Dead : BaseState
    {
        virtual Transition GetTransition()
        {
            return NoTransition();
        }
    };

    struct Locomotion : BaseState
    {
        virtual Transition GetTransition()
        {
            if (Owner().PressedMove())
                return InnerTransition<Move>();
            else
                return InnerTransition<Stand>();
        }
    };

    struct Stand : BaseState
    {
    };

    struct Move : BaseState
    {
    };
};

MyOwner::MyOwner()
    : mDead(false), mMove(false)
{
    mStateMachine.Initialize<MyStates::Alive>(this);
    mStateMachine.SetDebugInfo("TestHsm", TraceLevel::Basic);
}

void MyOwner::UpdateStateMachine()
{
    mStateMachine.ProcessStateTransitions();
    mStateMachine.UpdateStates();
}

int main()
{
    MyOwner myOwner;
    myOwner.UpdateStateMachine();

    printf("Set Move = true\n");
    myOwner.SetMove(true);
    myOwner.UpdateStateMachine();

    printf("Set Move = false\n");
    myOwner.SetMove(false);
    myOwner.UpdateStateMachine();
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.