aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-08-07 12:56:28 +0800
committerchai <chaifix@163.com>2018-08-07 12:56:28 +0800
commit35d0affb2b19a38ae43ac991021dd3c888dc3aa6 (patch)
tree378e1a6bf6fec56568dcec6aac15c4426f1f9375 /test
parentdf24addf48a6de2c4ef4e1723ae7d9c1d261dabe (diff)
*update
Diffstat (limited to 'test')
-rw-r--r--test/02Audio/main.cpp (renamed from test/02Audio/audiotest.cpp)0
-rw-r--r--test/03Thread/main.cpp (renamed from test/03Thread/threadtest.cpp)0
-rw-r--r--test/04Network/main.cpp83
3 files changed, 83 insertions, 0 deletions
diff --git a/test/02Audio/audiotest.cpp b/test/02Audio/main.cpp
index 4576cfa..4576cfa 100644
--- a/test/02Audio/audiotest.cpp
+++ b/test/02Audio/main.cpp
diff --git a/test/03Thread/threadtest.cpp b/test/03Thread/main.cpp
index a792e53..a792e53 100644
--- a/test/03Thread/threadtest.cpp
+++ b/test/03Thread/main.cpp
diff --git a/test/04Network/main.cpp b/test/04Network/main.cpp
new file mode 100644
index 0000000..a792e53
--- /dev/null
+++ b/test/04Network/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