amaiorano / hsm

C++ framework library to simplify state-driven code
MIT License
107 stars 38 forks source link

ue4 integration #13

Open Adv4nc3d123 opened 4 years ago

Adv4nc3d123 commented 4 years ago

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

amaiorano commented 4 years ago

Hi there,

If you disable RTTI, you'll need to add the DEFINE_HSM_STATE() macros in each of your states to inject the custom RTTI info needed by hsm. Check out the info in the documentation: https://github.com/amaiorano/hsm/wiki/Chapter-1.-Getting-Started#rtti

If you haven't already, I highly recommend reading the doc. Let me know if that works for you! I've shipped UE4 multiple games that use HSM, so it should work out just fine.

Adv4nc3d123 commented 4 years ago

Hi, this is what I am doing right now (just leaving 1 state in there) and the baseState in there in case I happen to be using the wrong syntax;

struct MyStates { struct BaseState : hsm::StateWithOwner { DEFINE_HSM_STATE(BaseState); }; struct Grabbed : BaseState { DEFINE_HSM_STATE(Grabbed);

    virtual hsm::Transition GetTransition()
    {
        if (!Owner().m_pBlackboard->GetValueAsBool(ISGRABBED))
            return hsm::SiblingTransition<FallLoop>();

        return hsm::NoTransition();
    }
    virtual void OnEnter()
    {
        Owner().m_bShouldProcess = true;
        Owner().m_Animstate = EAnimEnum::Grabbed;
    }
};

};

this throws me all of these erors: Severity Code Description Project File Line Suppression State Error (active) E0135 namespace "hsm" has no member "StateTypeIdStorage" FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 33
Error (active) E0135 namespace "hsm" has no member "StateTypeIdStorage" FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 38
Error (active) E0135 namespace "hsm" has no member "StateTypeIdStorage" FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 69
Error (active) E0135 namespace "hsm" has no member "StateTypeIdStorage" FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 108 Error (active) E0135 namespace "hsm" has no member "StateTypeIdStorage" FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 140 Error (active) E0135 namespace "hsm" has no member "StateTypeIdStorage" FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 164 Error (active) E0135 namespace "hsm" has no member "StateTypeIdStorage" FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 196 Error (active) E0135 namespace "hsm" has no member "StateTypeIdStorage" FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 217 Error (active) E0135 namespace "hsm" has no member "StateTypeIdStorage" FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 234 Error (active) E0135 namespace "hsm" has no member "StateTypeIdStorage" FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 250 Error (active) E0135 namespace "hsm" has no member "StateTypeIdStorage" FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 266 Error C2039 'StateTypeIdStorage': is not a member of 'hsm' FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 33
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 33
Error C2146 syntax error: missing ';' before identifier 'sStateTypeId' FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 33
Error C3861 'sStateTypeId': identifier not found FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 33
Error C2065 'sStateTypeId': undeclared identifier FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 33
Error C2039 'StateTypeIdStorage': is not a member of 'hsm' FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 38
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 38
Error C2146 syntax error: missing ';' before identifier 'sStateTypeId' FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 38
Error C3861 'sStateTypeId': identifier not found FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 38
Error C2065 'sStateTypeId': undeclared identifier FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 38
Error C2039 'StateTypeIdStorage': is not a member of 'hsm' FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 69
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 69
Error C2146 syntax error: missing ';' before identifier 'sStateTypeId' FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 69
Error C3861 'sStateTypeId': identifier not found FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 69
Error C2065 'sStateTypeId': undeclared identifier FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 69
Error C2039 'StateTypeIdStorage': is not a member of 'hsm' FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 108 Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 108 Error C2146 syntax error: missing ';' before identifier 'sStateTypeId' FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 108 Error C3861 'sStateTypeId': identifier not found FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 108 Error C2065 'sStateTypeId': undeclared identifier FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 108 Error C2039 'StateTypeIdStorage': is not a member of 'hsm' FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 140 Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 140 Error C2146 syntax error: missing ';' before identifier 'sStateTypeId' FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 140 Error C3861 'sStateTypeId': identifier not found FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 140 Error C2065 'sStateTypeId': undeclared identifier FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 140 Error C2039 'StateTypeIdStorage': is not a member of 'hsm' FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 164 Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 164 Error C2146 syntax error: missing ';' before identifier 'sStateTypeId' FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 164 Error C3861 'sStateTypeId': identifier not found FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 164 Error C2065 'sStateTypeId': undeclared identifier FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 164 Error C2039 'StateTypeIdStorage': is not a member of 'hsm' FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 196 Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 196 Error C2146 syntax error: missing ';' before identifier 'sStateTypeId' FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 196 Error C3861 'sStateTypeId': identifier not found FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 196 Error C2065 'sStateTypeId': undeclared identifier FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 196 Error C2039 'StateTypeIdStorage': is not a member of 'hsm' FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 217 Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 217 Error C2146 syntax error: missing ';' before identifier 'sStateTypeId' FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 217 Error C3861 'sStateTypeId': identifier not found FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 217 Error C2065 'sStateTypeId': undeclared identifier FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 217 Error C2039 'StateTypeIdStorage': is not a member of 'hsm' FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 234 Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 234 Error C2146 syntax error: missing ';' before identifier 'sStateTypeId' FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 234 Error C3861 'sStateTypeId': identifier not found FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 234 Error C2065 'sStateTypeId': undeclared identifier FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 234 Error C2039 'StateTypeIdStorage': is not a member of 'hsm' FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 250 Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 250 Error C2146 syntax error: missing ';' before identifier 'sStateTypeId' FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 250 Error C3861 'sStateTypeId': identifier not found FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 250 Error C2065 'sStateTypeId': undeclared identifier FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 250 Error C2039 'StateTypeIdStorage': is not a member of 'hsm' FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 266 Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 266 Error C2146 syntax error: missing ';' before identifier 'sStateTypeId' FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 266 Error C3861 'sStateTypeId': identifier not found FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 266 Error C2065 'sStateTypeId': undeclared identifier FluffyFactory C:\perf\Grp_Fluffy\Dev\FluffyFactory\Source\FluffyFactory\FluffyCharacter.cpp 266

which are basically the same for every state I Define I am currently using the latest Release Build I could find on here.

Adv4nc3d123 commented 4 years ago

So I downloaded the second latest release (1.5) and had to comment the line //static_assert(std::is_convertible<TargetState, State>::value, "TargetState must derive from hsm::State");

and add this define at the start to make it build

define HSM_CPP_RTTI 0

Seems to me there must be something missing in the latest release or the syntax of something has changed which I am not aware off.

amaiorano commented 4 years ago

So I downloaded the second latest release (1.5) and had to comment the line //static_assert(std::is_convertible<TargetState, State>::value, "TargetState must derive from hsm::State");

This assert is important, you should not remove it. If you're triggering it, it means you've probably added a DEFINE_HSM_STATE somewhere you shouldn't. This macro should only really be added to the actual states you transition to, not to base classes for your states. I noticed in the code you pasted above that you had added this macro to your BaseState, which you shouldn't be doing (see this example: https://github.com/amaiorano/hsm/blob/master/samples/hsm_book_samples/source/ch3/drawing_hsms.cpp).

and add this define at the start to make it build

define HSM_CPP_RTTI 0

This is correct. You are supposed to define this to 0 to disable C++ RTTI, and make use of the custom RTTI. I assume you had already done this even before downgrading.

Seems to me there must be something missing in the latest release or the syntax of something has changed which I am not aware off.

I think you found a bug in the latest version related to custom RTTI. When I get the chance, I'll take a look and see what's up. For now, using 1.5 should be perfectly fine.