aboutsummaryrefslogtreecommitdiff
path: root/examples/state_machine/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/state_machine/main.cpp')
-rw-r--r--examples/state_machine/main.cpp124
1 files changed, 0 insertions, 124 deletions
diff --git a/examples/state_machine/main.cpp b/examples/state_machine/main.cpp
deleted file mode 100644
index c061a81..0000000
--- a/examples/state_machine/main.cpp
+++ /dev/null
@@ -1,124 +0,0 @@
-#include <iostream>
-
-#include "libjin/jin.h"
-
-using namespace std;
-using namespace JinEngine::AI;
-using namespace JinEngine::Game;
-using namespace JinEngine::Input;
-using namespace JinEngine::Graphics;
-using namespace JinEngine::Graphics::Particles;
-using namespace JinEngine::Filesystem;
-using namespace JinEngine::Time;
-
-ParticleSystem* p;
-StateMachine sm;
-Timer timer;
-enum
-{
- STATE_EMPTY = 0,
- STATE_RUN,
- STATE_IDLE,
- STATE_SLEEP,
- STATE_JUMP
-};
-
-enum
-{
- PARAM_RUN = 1,
- PARAM_IDLE = 2,
- PARAM_IDLE2 = 3,
- PARAM_RUN = 4
-};
-
-void onLoad()
-{
- sm.addState(STATE_RUN);
- sm.addState(STATE_IDLE);
- sm.addState(STATE_SLEEP);
- sm.addState(STATE_JUMP);
- sm.addParametert(PARAM_RUN);
- sm.addParameterb(PARAM_IDLE);
- sm.addParameterb(PARAM_IDLE2);
- sm.addTransition(STATE_EMPTY, STATE_IDLE, StateMachine::Conditions().andt(PARAM_RUN));
- sm.addTransition("Idle", "Run", StateMachine::Conditions().andb("idle", StateMachine::BOOL_IS, true).andb("idle2", StateMachine::BOOL_IS, true));
- sm.setEnterListener([](const string& state, void* p) {
- cout << "Enter: " << state << endl;
- });
- sm.addEnterListener("Run", [](void* p) {
- cout << "A Run state enter callback" << endl;
- });
- sm.addTranslateListener("Idle", "Run", [](void* p) {
- cout << "From Idle to Run" << endl;
- });
- sm.addUpdateListener("Run", [](void* p) {
- cout << "run" << endl;
- });
- Window::get()->show();
- Timer::Handler* hnd = timer.every(500, [](void*) {
- cout << sm.getCurrentState() << endl;
- }, NULL);
- timer.after(2500, [](void*) {
- //sm.setParameterb("run", true);
- sm.setParametert("run");
- }, NULL);
- timer.after(5000, [=](void*) {
- sm.setParameterb("idle", true);
- sm.setParametert("run");
- timer.cancel(hnd);
- //sm.setParameterb("run", false);
- }, NULL);
- timer.after(8000, [](void*) {
- sm.setParameterb("idle2", true);
- //sm.setParameterb("run", false);
- }, NULL);
-}
-
-void onEvent(Event* e)
-{
- static Application* Application = Application::get();
- if (e->type == EventType::QUIT)
- Application->stop();
-}
-
-void onUpdate(int ms)
-{
- timer.update(ms);
- sm.update();
-}
-
-void onDraw()
-{
-}
-
-int main(int argc, char* argv[])
-{
- Application* Application = Application::get();
- Application::Setting setting;
- setting.loader = onLoad;
- setting.eventHandler = onEvent;
- setting.updater = onUpdate;
- setting.drawer = onDraw;
- Application->init(&setting);
-
- AssetDatabase::get()->mount(".");
-
- Window* wnd = Window::get();
- Window::Setting wndSetting;
- wndSetting.width = 600;
- wndSetting.height = 512;
- wndSetting.title = "Jin v0.1.1";
- wndSetting.fps = 60;
- wndSetting.vsync = false;
- wndSetting.fullscreen = false;
- wndSetting.resizable = false;
- wndSetting.icon = ".";
- wnd->init(&wndSetting);
-
- Application->run();
-
- Application->quit();
- wnd->quit();
-
- return 0;
-} \ No newline at end of file