From 35d0affb2b19a38ae43ac991021dd3c888dc3aa6 Mon Sep 17 00:00:00 2001 From: chai Date: Tue, 7 Aug 2018 12:56:28 +0800 Subject: *update --- build/.vs/libjin/v14/.suo | Bin 121856 -> 135168 bytes build/02Audio/02Audio.vcxproj | 2 +- build/02Audio/02Audio.vcxproj.filters | 2 +- build/03Thread/03Thread.vcxproj | 3 +- build/03Thread/03Thread.vcxproj.filters | 5 +- build/03Thread/main.cpp | 154 ------------------------------ build/04Network/04Network.vcxproj | 133 ++++++++++++++++++++++++++ build/04Network/04Network.vcxproj.filters | 22 +++++ build/libjin.sln | 10 ++ test/02Audio/audiotest.cpp | 70 -------------- test/02Audio/main.cpp | 70 ++++++++++++++ test/03Thread/main.cpp | 83 ++++++++++++++++ test/03Thread/threadtest.cpp | 83 ---------------- test/04Network/main.cpp | 83 ++++++++++++++++ 14 files changed, 405 insertions(+), 315 deletions(-) delete mode 100644 build/03Thread/main.cpp create mode 100644 build/04Network/04Network.vcxproj create mode 100644 build/04Network/04Network.vcxproj.filters delete mode 100644 test/02Audio/audiotest.cpp create mode 100644 test/02Audio/main.cpp create mode 100644 test/03Thread/main.cpp delete mode 100644 test/03Thread/threadtest.cpp create mode 100644 test/04Network/main.cpp diff --git a/build/.vs/libjin/v14/.suo b/build/.vs/libjin/v14/.suo index cf42b3a..4ee2374 100644 Binary files a/build/.vs/libjin/v14/.suo and b/build/.vs/libjin/v14/.suo differ diff --git a/build/02Audio/02Audio.vcxproj b/build/02Audio/02Audio.vcxproj index a06df79..5aa3542 100644 --- a/build/02Audio/02Audio.vcxproj +++ b/build/02Audio/02Audio.vcxproj @@ -120,7 +120,7 @@ - + diff --git a/build/02Audio/02Audio.vcxproj.filters b/build/02Audio/02Audio.vcxproj.filters index 30ce2ab..29e09e3 100644 --- a/build/02Audio/02Audio.vcxproj.filters +++ b/build/02Audio/02Audio.vcxproj.filters @@ -15,7 +15,7 @@ - + 源文件 diff --git a/build/03Thread/03Thread.vcxproj b/build/03Thread/03Thread.vcxproj index ddd8193..6cad582 100644 --- a/build/03Thread/03Thread.vcxproj +++ b/build/03Thread/03Thread.vcxproj @@ -125,8 +125,7 @@ - - + diff --git a/build/03Thread/03Thread.vcxproj.filters b/build/03Thread/03Thread.vcxproj.filters index d0d38cf..a9c0e02 100644 --- a/build/03Thread/03Thread.vcxproj.filters +++ b/build/03Thread/03Thread.vcxproj.filters @@ -15,10 +15,7 @@ - - 源文件 - - + 源文件 diff --git a/build/03Thread/main.cpp b/build/03Thread/main.cpp deleted file mode 100644 index ed12172..0000000 --- a/build/03Thread/main.cpp +++ /dev/null @@ -1,154 +0,0 @@ -//#include -//#include -//#include -//#include -//#include -// -//class SdlMutex -//{ -//public: -// SdlMutex() -// { -// mutex = SDL_CreateMutex(); -// if (!mutex) throw std::runtime_error("SDL_CreateMutex == NULL"); -// } -// -// ~SdlMutex() -// { -// SDL_DestroyMutex(mutex); -// } -// -// void lock() -// { -// if (SDL_mutexP(mutex) == -1) throw std::runtime_error("SDL_mutexP == -1"); -// // Note: -// // -1 does not mean it was already locked - it means there was an error in locking - -// // if it was locked it will just block - see SDL_mutexP(3) -// } -// -// void unlock() -// { -// if (SDL_mutexV(mutex) == -1) throw std::runtime_error("SDL_mutexV == -1"); -// } -// -// SDL_mutex* underlying() -// { -// return mutex; -// } -//private: -// SDL_mutex* mutex; -//}; -// -//class SdlScopedLock -//{ -//public: -// SdlScopedLock(SdlMutex& mutex) -// : -// mutex(mutex) -// { -// mutex.lock(); -// } -// ~SdlScopedLock() -// { -// try -// { -// this->unlock(); -// } -// catch (const std::exception& e) -// { -// // Destructors should never throw ... -// std::cerr << "SdlScopedLock::~SdlScopedLock - caught : " << e.what() << std::endl; -// } -// } -// void unlock() -// { -// mutex.unlock(); -// } -//private: -// SdlMutex& mutex; -//}; -// -//class ThreadData -//{ -//public: -// ThreadData() -// : -// dataReady(false), -// done(false) -// { -// condition = SDL_CreateCond(); -// } -// -// ~ThreadData() -// { -// SDL_DestroyCond(condition); -// } -// -// // Using stringstream so I can just shift on integers... -// std::stringstream data; -// bool dataReady; -// bool done; -// SdlMutex mutex; -// SDL_cond* condition; -//}; -// -//int threadFunction(void* data) -//{ -// try -// { -// ThreadData* threadData = static_cast< ThreadData* >(data); -// -// for (size_t i = 0; i < 100; i++) -// { -// { -// SdlScopedLock lock(threadData->mutex); -// // Everything in this scope is now syncronized with the mutex -// if (i != 0) threadData->data << ", "; -// threadData->data << i; -// threadData->dataReady = true; -// } // threadData->mutex is automatically unlocked here -// // Its important to note that condition should be signaled after mutex is unlocked -// if (SDL_CondSignal(threadData->condition) == -1) throw std::runtime_error("Failed to signal"); -// } -// { -// SdlScopedLock lock(threadData->mutex); -// threadData->done = true; -// } -// if (SDL_CondSignal(threadData->condition) == -1) throw std::runtime_error("Failed to signal"); -// return 0; -// } -// catch (const std::exception& e) -// { -// std::cerr << "Caught : " << e.what() << std::endl; -// return 1; -// } -//} -// -//int main(int argc, char* argv[]) -//{ -// ThreadData threadData; -// SDL_Thread* thread = SDL_CreateThread(threadFunction, "", &threadData); -// -// while (true) -// { -// SdlScopedLock lock(threadData.mutex); -// while (threadData.dataReady == false && threadData.done == false) -// { -// // NOTE: must call condition wait with mutex already locked -// if (SDL_CondWait(threadData.condition, threadData.mutex.underlying()) == -1) throw std::runtime_error("Failed to wait"); -// } -// // once dataReady == true or threadData.done == true we get here -// std::cout << "Got data = " << threadData.data.str() << std::endl; -// threadData.data.str(""); -// threadData.dataReady = false; -// if (threadData.done) -// { -// std::cout << "child done - ending" << std::endl; -// break; -// } -// } -// -// int status = 99; -// SDL_WaitThread(thread, &status); -// std::cerr << "Thread completed with : " << status << std::endl; -//} \ No newline at end of file diff --git a/build/04Network/04Network.vcxproj b/build/04Network/04Network.vcxproj new file mode 100644 index 0000000..b992a7a --- /dev/null +++ b/build/04Network/04Network.vcxproj @@ -0,0 +1,133 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {85071432-24B6-46D4-98D8-DAA63183093C} + My04Network + 8.1 + + + + Application + true + v140 + MultiByte + + + Application + false + v140 + true + MultiByte + + + Application + true + v140 + MultiByte + + + Application + false + v140 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + Level3 + Disabled + true + $(SolutionDir)..\libjin\;$(SolutionDir)\lib\SDL2-2.0.5\include\ + + + $(SolutionDir)\lib\SDL2-2.0.5\lib\x86\ + SDL2main.lib;SDL2.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies) + Console + + + + + Level3 + Disabled + true + + + + + Level3 + MaxSpeed + true + true + true + $(SolutionDir)..\libjin\;$(SolutionDir)\lib\SDL2-2.0.5\include\ + + + true + true + $(SolutionDir)\lib\SDL2-2.0.5\lib\x86\ + SDL2main.lib;SDL2.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies) + Console + + + + + Level3 + MaxSpeed + true + true + true + + + true + true + + + + + + + + {407e9199-d39c-4460-b218-0c29ab42483b} + + + + + + \ No newline at end of file diff --git a/build/04Network/04Network.vcxproj.filters b/build/04Network/04Network.vcxproj.filters new file mode 100644 index 0000000..01aea0c --- /dev/null +++ b/build/04Network/04Network.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + \ No newline at end of file diff --git a/build/libjin.sln b/build/libjin.sln index eb11a5f..7bdc3c3 100644 --- a/build/libjin.sln +++ b/build/libjin.sln @@ -11,6 +11,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "02Audio", "02Audio\02Audio. EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "03Thread", "03Thread\03Thread.vcxproj", "{0E49D105-2032-4825-9FA1-54B1B94E3655}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "04Network", "04Network\04Network.vcxproj", "{85071432-24B6-46D4-98D8-DAA63183093C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -51,6 +53,14 @@ Global {0E49D105-2032-4825-9FA1-54B1B94E3655}.Release|x64.Build.0 = Release|x64 {0E49D105-2032-4825-9FA1-54B1B94E3655}.Release|x86.ActiveCfg = Release|Win32 {0E49D105-2032-4825-9FA1-54B1B94E3655}.Release|x86.Build.0 = Release|Win32 + {85071432-24B6-46D4-98D8-DAA63183093C}.Debug|x64.ActiveCfg = Debug|x64 + {85071432-24B6-46D4-98D8-DAA63183093C}.Debug|x64.Build.0 = Debug|x64 + {85071432-24B6-46D4-98D8-DAA63183093C}.Debug|x86.ActiveCfg = Debug|Win32 + {85071432-24B6-46D4-98D8-DAA63183093C}.Debug|x86.Build.0 = Debug|Win32 + {85071432-24B6-46D4-98D8-DAA63183093C}.Release|x64.ActiveCfg = Release|x64 + {85071432-24B6-46D4-98D8-DAA63183093C}.Release|x64.Build.0 = Release|x64 + {85071432-24B6-46D4-98D8-DAA63183093C}.Release|x86.ActiveCfg = Release|Win32 + {85071432-24B6-46D4-98D8-DAA63183093C}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/test/02Audio/audiotest.cpp b/test/02Audio/audiotest.cpp deleted file mode 100644 index 4576cfa..0000000 --- a/test/02Audio/audiotest.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include -#include "jin.h" - -using namespace jin::core; -using namespace jin::graphics; -using namespace jin::input; -using namespace jin::audio; - -void onEvent(jin::input::Event* e) -{ - static Game* game = Game::get(); - if (e->type == EventType::QUIT) - game->stop(); -} - -void onUpdate(int ms) -{ - -} - -void onDraw() -{ - -} - -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); - - SDLAudio* audio = SDLAudio::get(); - SDLAudio::Setting audioSetting; - audioSetting.samplerate = 44100; - audioSetting.samples = 44100; - audio->init(&audioSetting); - - SDLSource* src = SDLSource::createSource("a.ogg"); - src->play(); - src->setLoop(false); - - SDLSource* src2 = SDLSource::createSource("a.wav"); - src2->setLoop(true); - src2->play(); - - audio->setVolume(0.7); - - game->run(); - - game->quit(); - audio->quit(); - wnd->quit(); - - return 0; -} \ No newline at end of file diff --git a/test/02Audio/main.cpp b/test/02Audio/main.cpp new file mode 100644 index 0000000..4576cfa --- /dev/null +++ b/test/02Audio/main.cpp @@ -0,0 +1,70 @@ +#include +#include "jin.h" + +using namespace jin::core; +using namespace jin::graphics; +using namespace jin::input; +using namespace jin::audio; + +void onEvent(jin::input::Event* e) +{ + static Game* game = Game::get(); + if (e->type == EventType::QUIT) + game->stop(); +} + +void onUpdate(int ms) +{ + +} + +void onDraw() +{ + +} + +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); + + SDLAudio* audio = SDLAudio::get(); + SDLAudio::Setting audioSetting; + audioSetting.samplerate = 44100; + audioSetting.samples = 44100; + audio->init(&audioSetting); + + SDLSource* src = SDLSource::createSource("a.ogg"); + src->play(); + src->setLoop(false); + + SDLSource* src2 = SDLSource::createSource("a.wav"); + src2->setLoop(true); + src2->play(); + + audio->setVolume(0.7); + + game->run(); + + game->quit(); + audio->quit(); + wnd->quit(); + + return 0; +} \ No newline at end of file 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 diff --git a/test/03Thread/threadtest.cpp b/test/03Thread/threadtest.cpp deleted file mode 100644 index a792e53..0000000 --- a/test/03Thread/threadtest.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#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 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 +#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