Skip to content

Commit

Permalink
2.4.0
Browse files Browse the repository at this point in the history
* Added `destroy<>()`
* switched msbuild workflow to the premake solution
  • Loading branch information
andrew-gresyk committed Dec 26, 2023
1 parent d993031 commit c7ccd25
Show file tree
Hide file tree
Showing 80 changed files with 2,106 additions and 5,593 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/msbuild.yml
Expand Up @@ -7,7 +7,7 @@ on:
branches: [ master ]

env:
SOLUTION_FILE_PATH: projects\visual-studio\hfsm2-vs.sln
SOLUTION_FILE_PATH: projects\premake\hfsm2-vs.sln

jobs:
build:
Expand All @@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
BUILD_CONFIG: [ Release, Debug ]
BUILD_PLATFORM: [ x86, x64 ]
BUILD_PLATFORM: [ 32, 64 ]

steps:
- uses: actions/checkout@v4
Expand All @@ -31,4 +31,4 @@ jobs:

- name: Test
working-directory: ${{env.GITHUB_WORKSPACE}}
run: binaries-${{matrix.BUILD_PLATFORM}}\test-17-${{matrix.BUILD_CONFIG}}-${{matrix.BUILD_PLATFORM}}.exe
run: "binaries/test-17-${{matrix.BUILD_CONFIG}}-${{matrix.BUILD_PLATFORM}}.exe"
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -18,3 +18,5 @@ cmake-*
/projects/code-lite/test/test.mk
/projects/visual-studio/.opencppcov
/projects/visual-studio/*.log
/pull.cmd
/push.cmd
16 changes: 8 additions & 8 deletions development/hfsm2/detail/features/logger_interface.hpp
Expand Up @@ -35,7 +35,7 @@ struct LoggerInterfaceT {
void
recordMethod(const Context& HFSM2_UNUSED(context),
const StateID HFSM2_UNUSED(origin),
const Method HFSM2_UNUSED(method)) noexcept
const Method HFSM2_UNUSED(method))
{}

HFSM2_CONSTEXPR(NO)
Expand All @@ -44,7 +44,7 @@ struct LoggerInterfaceT {
recordTransition(const Context& HFSM2_UNUSED(context),
const StateID HFSM2_UNUSED(origin),
const TransitionType HFSM2_UNUSED(transitionType),
const StateID HFSM2_UNUSED(target)) noexcept
const StateID HFSM2_UNUSED(target))
{}

#if HFSM2_PLANS_AVAILABLE()
Expand All @@ -55,15 +55,15 @@ struct LoggerInterfaceT {
recordTaskStatus(const Context& HFSM2_UNUSED(context),
const RegionID HFSM2_UNUSED(region),
const StateID HFSM2_UNUSED(origin),
const StatusEvent HFSM2_UNUSED(event)) noexcept
const StatusEvent HFSM2_UNUSED(event))
{}

HFSM2_CONSTEXPR(NO)
virtual
void
recordPlanStatus(const Context& HFSM2_UNUSED(context),
const RegionID HFSM2_UNUSED(region),
const StatusEvent HFSM2_UNUSED(event)) noexcept
const StatusEvent HFSM2_UNUSED(event))
{}

#endif
Expand All @@ -72,15 +72,15 @@ struct LoggerInterfaceT {
virtual
void
recordCancelledPending(const Context& HFSM2_UNUSED(context),
const StateID HFSM2_UNUSED(origin)) noexcept
const StateID HFSM2_UNUSED(origin))
{}

HFSM2_CONSTEXPR(NO)
virtual
void
recordSelectResolution(const Context& HFSM2_UNUSED(context),
const StateID HFSM2_UNUSED(head),
const Prong HFSM2_UNUSED(prong)) noexcept
const Prong HFSM2_UNUSED(prong))
{}

#if HFSM2_UTILITY_THEORY_AVAILABLE()
Expand All @@ -91,7 +91,7 @@ struct LoggerInterfaceT {
recordUtilityResolution(const Context& HFSM2_UNUSED(context),
const StateID HFSM2_UNUSED(head),
const Prong HFSM2_UNUSED(prong),
const Utilty HFSM2_UNUSED(utilty)) noexcept
const Utilty HFSM2_UNUSED(utilty))
{}

HFSM2_CONSTEXPR(NO)
Expand All @@ -100,7 +100,7 @@ struct LoggerInterfaceT {
recordRandomResolution(const Context& HFSM2_UNUSED(context),
const StateID HFSM2_UNUSED(head),
const Prong HFSM2_UNUSED(prong),
const Utilty HFSM2_UNUSED(utilty)) noexcept
const Utilty HFSM2_UNUSED(utilty))
{}

#endif
Expand Down
41 changes: 28 additions & 13 deletions development/hfsm2/detail/shared/utility.hpp
Expand Up @@ -108,12 +108,12 @@ using Undecorate = RemoveConst<RemoveReference<T>>;

template <typename T>
struct IsValueReferenceT final {
static constexpr bool VALUE = false;
static const bool VALUE = false;
};

template <typename T>
struct IsValueReferenceT<T&> final {
static constexpr bool VALUE = true;
static const bool VALUE = true;
};

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -187,8 +187,10 @@ move(T&& t) noexcept {

////////////////////////////////////////////////////////////////////////////////

template <typename T0,
typename T1>
template <
typename T0
, typename T1
>
HFSM2_CONSTEXPR(11)
T0
min(const T0 t0,
Expand All @@ -200,8 +202,10 @@ min(const T0 t0,

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

template <typename T0,
typename T1>
template <
typename T0
, typename T1
>
HFSM2_CONSTEXPR(11)
T0
max(const T0 t0,
Expand All @@ -213,9 +217,11 @@ max(const T0 t0,

//------------------------------------------------------------------------------

template <typename TIndex,
typename TElement,
TIndex NCount>
template <
typename TIndex
, typename TElement
, TIndex NCount
>
HFSM2_CONSTEXPR(11)
TIndex
count(const TElement (&)[NCount]) noexcept {
Expand All @@ -224,8 +230,10 @@ count(const TElement (&)[NCount]) noexcept {

//------------------------------------------------------------------------------

template <typename T,
typename TT>
template <
typename T
, typename TT
>
HFSM2_CONSTEXPR(11)
T
contain(const T x,
Expand All @@ -238,8 +246,7 @@ contain(const T x,

HFSM2_CONSTEXPR(11)
uint64_t
widen(const uint32_t x, const uint32_t y) noexcept
{
widen(const uint32_t x, const uint32_t y) noexcept {
return static_cast<uint64_t>(x) << 32 | y;
}

Expand Down Expand Up @@ -297,6 +304,14 @@ reinterpret(const TI& in) noexcept {
return out;
}

//------------------------------------------------------------------------------

template<class T>
HFSM2_CONSTEXPR(14)
void destroy(T& t) noexcept {
t.~T();
}

////////////////////////////////////////////////////////////////////////////////

template <int>
Expand Down
6 changes: 3 additions & 3 deletions development/hfsm2/machine_dev.hpp
@@ -1,5 +1,5 @@
// HFSM2 (hierarchical state machine for games and interactive applications)
// 2.3.3 (2023-12-21)
// 2.4.0 (2023-12-25)
//
// Created by Andrew Gresyk
//
Expand Down Expand Up @@ -32,8 +32,8 @@
#pragma once

#define HFSM2_VERSION_MAJOR 2
#define HFSM2_VERSION_MINOR 3
#define HFSM2_VERSION_PATCH 3
#define HFSM2_VERSION_MINOR 4
#define HFSM2_VERSION_PATCH 0

#define HFSM2_VERSION (10000 * HFSM2_VERSION_MAJOR + 100 * HFSM2_VERSION_MINOR + HFSM2_VERSION_PATCH)

Expand Down
17 changes: 8 additions & 9 deletions examples/advanced_event_handling/main.cpp
Expand Up @@ -94,7 +94,7 @@ struct Reactive
: FSM::State
{
// handle a single event type - TransitionEvent
void react(const TransitionEvent&, FullControl& control) noexcept {
void react(const TransitionEvent&, FullControl& control) {
std::cout << " Reactive: reacting to TransitionEvent\n";

control.changeTo<Target>();
Expand All @@ -118,12 +118,12 @@ struct ConcreteHandler
: FSM::State
{
// handle two event types - PrimaryEvent
void react(const PrimaryEvent&, FullControl&) noexcept {
void react(const PrimaryEvent&, FullControl&) {
std::cout << " ConcreteHandler: reacting to PrimaryEvent\n";
}

// and SecondaryEvent
void react(const SecondaryEvent&, FullControl&) noexcept {
void react(const SecondaryEvent&, FullControl&) {
std::cout << " ConcreteHandler: reacting to SecondaryEvent\n";
}

Expand All @@ -138,7 +138,7 @@ struct TemplateHandler
{
// handle all possible event types
template <typename TEvent>
void react(const TEvent&, FullControl&) noexcept {
void react(const TEvent&, FullControl&) {
std::cout << " TemplateHandler: reacting to TEvent\n";
}
};
Expand All @@ -151,14 +151,14 @@ struct EnableIfHandler
// use std::enable_if to build more complex conditional event handling
template <typename TEvent>
typename std::enable_if<std::is_class<TEvent>::value>::type
react(const TEvent&, FullControl&) noexcept {
react(const TEvent&, FullControl&) {
std::cout << " EnableIfHandler: reacting to a <class event>\n";
}

// but remember to cover all the remaining cases
template <typename TEvent>
typename std::enable_if<!std::is_class<TEvent>::value>::type
react(const TEvent&, FullControl&) noexcept {
react(const TEvent&, FullControl&) {
std::cout << " EnableIfHandler: reacting to a <non-class event>\n";
}
};
Expand All @@ -168,15 +168,14 @@ struct EnableIfHandler
struct Target
: FSM::State
{
void enter(Control&) noexcept {
void enter(Control&) {
std::cout << " changed to Target\n";
}
};

////////////////////////////////////////////////////////////////////////////////

int
main() noexcept {
int main() {
FSM::Instance machine;

std::cout << "sending PrimaryEvent:\n";
Expand Down
23 changes: 11 additions & 12 deletions examples/basic_audio_player/main.cpp
Expand Up @@ -4,11 +4,11 @@
// An HFSM2 port of https://gist.github.com/martinmoene/797b1923f9c6c1ae355bb2d6870be25e
// by Martin Moene (see https://twitter.com/MartinMoene/status/1118453128834232320)

#include <assert.h>

#include <iostream>
#include <string>

#include <assert.h>

#define HFSM2_ENABLE_LOG_INTERFACE
#define HFSM2_ENABLE_STRUCTURE_REPORT
#include <hfsm2/machine.hpp>
Expand Down Expand Up @@ -64,7 +64,7 @@ static_assert(FSM::stateId<Paused>() == 3, "");
struct Logger
: M::LoggerInterface
{
static const char* stateName(const StateID stateId) noexcept {
static const char* stateName(const StateID stateId) {
switch (stateId) {
case 1:
return "Idle";
Expand All @@ -81,7 +81,7 @@ struct Logger
void recordTransition(const Context& /*context*/,
const StateID origin,
const TransitionType /*transition*/,
const StateID target) noexcept override
const StateID target) override
{
std::cout << stateName(origin) << " -> " << stateName(target) << "\n";
}
Expand All @@ -94,7 +94,7 @@ struct Base
: FSM::State
{
template <typename Event>
void react(const Event&, FullControl&) noexcept {
void react(const Event&, FullControl&) {
std::cout << "[unsupported transition]\n";
}
};
Expand All @@ -105,7 +105,7 @@ struct Idle
{
using Base::react;

void react(const Play& event, FullControl& control) noexcept {
void react(const Play& event, FullControl& control) {
control.context() = event.title;
control.changeTo<Playing>();
}
Expand All @@ -116,11 +116,11 @@ struct Playing
{
using Base::react;

void react(const Pause&, FullControl& control) noexcept {
void react(const Pause&, FullControl& control) {
control.changeTo<Paused>();
}

void react(const Stop&, FullControl& control) noexcept {
void react(const Stop&, FullControl& control) {
control.changeTo<Idle>();
}
};
Expand All @@ -130,19 +130,18 @@ struct Paused
{
using Base::react;

void react(const Resume&, FullControl& control) noexcept {
void react(const Resume&, FullControl& control) {
control.changeTo<Playing>();
}

void react(const Stop&, FullControl& control) noexcept {
void react(const Stop&, FullControl& control) {
control.changeTo<Idle>();
}
};

//------------------------------------------------------------------------------

int
main() noexcept {
int main() {
// construct everything
Context title;
Logger logger;
Expand Down

0 comments on commit c7ccd25

Please sign in to comment.