After trying a few SFM libraries I found they're just too much for what I need, so here's the start of a simple one I can use.

master
Zed A. Shaw 2 months ago
parent 356314406f
commit b9025be45b
  1. 62
      fsmtest.cpp
  2. 9
      meson.build

@ -0,0 +1,62 @@
#include <fmt/core.h>
using namespace fmt;
template<typename S, typename E>
class DeadSimpleFSM {
protected:
S _state = S::START;
public:
virtual void event(E event) = 0;
void state(S next_state) {
_state = next_state;
}
};
#define T(S, F) case S: F(); break
enum MyState {
START, RUNNING, END
};
enum MyEvent {
STARTED, PUSH, QUIT
};
class MyFSM : DeadSimpleFSM<MyState, MyEvent> {
public:
void event(MyEvent ev) override {
switch(ev) {
T(STARTED, start);
T(PUSH, push);
T(QUIT, stop);
}
}
void start() {
println("<<< START");
state(RUNNING);
}
void push() {
println("<<< RUN");
state(RUNNING);
}
void quit() {
println("<<< STOP");
state(END);
}
};
int main() {
MyFSM fsm;
fsm.event(STARTED);
fsm.event(PUSH);
fsm.event(PUSH);
fsm.event(PUSH);
fsm.event(QUIT);
}

@ -11,9 +11,9 @@ opts.add_cmake_defines({
'BUILD_TESTS': false,
})
libgit2_proj = cmake.subproject('libgit2', options: opts)
libgit2package_dep = libgit2_proj.dependency('libgit2package')
libgit2package = libgit2_proj.dependency('libgit2package')
efsw_dep = dependency('efsw')
efsw = dependency('efsw')
fmt = dependency('fmt')
catch2 = dependency('catch2-with-main')
sfml = dependency('sfml')
@ -21,7 +21,7 @@ json = dependency('nlohmann_json')
imgui = dependency('imgui-sfml')
dependencies = [
fmt, libgit2package_dep, efsw_dep,
fmt, libgit2package, efsw,
sfml, imgui, json
]
@ -46,6 +46,9 @@ executable('jsontest', 'jsontest.cpp',
executable('threadtest', 'threadtest.cpp',
dependencies: dependencies)
executable('fsmtest', 'fsmtest.cpp',
dependencies: dependencies)
executable('badref', 'badref.cpp',
dependencies: dependencies)

Loading…
Cancel
Save