diff options
Diffstat (limited to 'test/03Thread/main.cpp')
-rw-r--r-- | test/03Thread/main.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/test/03Thread/main.cpp b/test/03Thread/main.cpp new file mode 100644 index 0000000..a792e53 --- /dev/null +++ b/test/03Thread/main.cpp @@ -0,0 +1,83 @@ +#include <iostream> +#include <functional> +#include "jin.h" + +using namespace std; +using namespace jin::core; +using namespace jin::graphics; +using namespace jin::input; +using namespace jin::audio; +using namespace jin::time; +using namespace jin::thread; + +Timers timers; + +void onEvent(jin::input::Event* e) +{ + static Game* game = Game::get(); + if (e->type == EventType::QUIT) + game->stop(); +} + +void onUpdate(int ms) +{ + timers.update(ms); +} + +void onDraw() +{ + +} + +void thread2Runner(Thread* t) +{ + int i = 0; + while (true) + { + if (i++ == 1000000000) + { + i = 0; + cout << (char*)(t->demand(1).pointer); + } + } +} + +void sendFunc(void* p) +{ + Thread* t = (Thread*)p; + t->send(1, "hello_"); +} + +int main(int argc, char* argv[]) +{ + Game* game = Game::get(); + Game::Setting setting; + setting.eventHandler = onEvent; + setting.updater = onUpdate; + setting.drawer = onDraw; + setting.loader = nullptr; + game->init(&setting); + + Window* wnd = Window::get(); + Window::Setting wndSetting; + wndSetting.width = 600; + wndSetting.height = 512; + wndSetting.title = "test"; + wndSetting.fps = 60; + wndSetting.vsync = false; + wndSetting.fullscreen = false; + wndSetting.resizable = false; + wnd->init(&wndSetting); + + Thread t("Count", thread2Runner); + + t.start(); + timers.after(2000, sendFunc, &t); + + game->run(); + + game->quit(); + wnd->quit(); + + return 0; +}
\ No newline at end of file |