diff options
Diffstat (limited to 'test/03Thread/threadtest.cpp')
-rw-r--r-- | test/03Thread/threadtest.cpp | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/test/03Thread/threadtest.cpp b/test/03Thread/threadtest.cpp new file mode 100644 index 0000000..d5d75e4 --- /dev/null +++ b/test/03Thread/threadtest.cpp @@ -0,0 +1,86 @@ +#include <iostream> +#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() +{ + +} + +int thread2Runner(void* p) +{ + char* s = (char*)p; + int i = 0; + while (true) + { + if (i++ == 1000000000) + { + i = 0; + cout << s; + } + } + return 0; +} + +int thread3Runner(void* p) +{ + +} + +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); + + timers.every(1000, [](void* p)-> void{ + cout << 1; + }, nullptr); + + Thread t("Thread 2", thread2Runner); + char* str = "_OK"; + t.start(str); + + game->run(); + + game->quit(); + wnd->quit(); + + return 0; +}
\ No newline at end of file |