From 35d0affb2b19a38ae43ac991021dd3c888dc3aa6 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 7 Aug 2018 12:56:28 +0800 Subject: *update --- test/03Thread/main.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 test/03Thread/main.cpp (limited to 'test/03Thread/main.cpp') 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 +#include +#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 -- cgit v1.1-26-g67d0