From 97c96e1d127a7a0c21d6bcf8af97b90649971d1f Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 28 Jul 2018 13:33:11 +0800 Subject: *update --- build/01HelloWorld/01HelloWorld.vcxproj | 19 ++++++++-- build/lib/SDL2-2.0.5/lib/x86/SDL2test.lib | Bin 899966 -> 0 bytes build/libjin/libjin.vcxproj | 14 ++++---- build/libjin/libjin.vcxproj.filters | 12 +++---- libjin/3rdparty/smount/smount.c | 2 +- libjin/Audio/SDL/SDLAudio.h | 2 -- libjin/Common/Singleton.hpp | 3 +- libjin/Core/Game.cpp | 38 +++++++++++++++++--- libjin/Core/Game.h | 56 +++++++++++++----------------- libjin/Graphics/Window.cpp | 11 +++--- libjin/Graphics/Window.h | 2 -- test/01HelloWorld/main.cpp | 47 +++++++++++++++++++++++-- 12 files changed, 142 insertions(+), 64 deletions(-) delete mode 100644 build/lib/SDL2-2.0.5/lib/x86/SDL2test.lib diff --git a/build/01HelloWorld/01HelloWorld.vcxproj b/build/01HelloWorld/01HelloWorld.vcxproj index 8b42290..cab9535 100644 --- a/build/01HelloWorld/01HelloWorld.vcxproj +++ b/build/01HelloWorld/01HelloWorld.vcxproj @@ -74,8 +74,14 @@ Level3 Disabled true - $(SolutionDir)..\libjin\;%(AdditionalIncludeDirectories) + $(SolutionDir)..\libjin\;$(SolutionDir)\lib\SDL2-2.0.5\include\;%(AdditionalIncludeDirectories) + CompileAsCpp + + Console + $(SolutionDir)\lib\SDL2-2.0.5\lib\x86\;%(AdditionalLibraryDirectories) + SDL2.lib;SDL2main.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies) + @@ -91,11 +97,15 @@ true true true - $(SolutionDir)..\libjin\;%(AdditionalIncludeDirectories) + $(SolutionDir)..\libjin\;$(SolutionDir)\lib\SDL2-2.0.5\include\;%(AdditionalIncludeDirectories) + CompileAsCpp true true + Console + $(SolutionDir)\lib\SDL2-2.0.5\lib\x86\;%(AdditionalLibraryDirectories) + SDL2.lib;SDL2main.lib;opengl32.lib;glu32.lib;%(AdditionalDependencies) @@ -114,6 +124,11 @@ + + + {407e9199-d39c-4460-b218-0c29ab42483b} + + diff --git a/build/lib/SDL2-2.0.5/lib/x86/SDL2test.lib b/build/lib/SDL2-2.0.5/lib/x86/SDL2test.lib deleted file mode 100644 index c26c50f..0000000 Binary files a/build/lib/SDL2-2.0.5/lib/x86/SDL2test.lib and /dev/null differ diff --git a/build/libjin/libjin.vcxproj b/build/libjin/libjin.vcxproj index bd83f54..a1ba5df 100644 --- a/build/libjin/libjin.vcxproj +++ b/build/libjin/libjin.vcxproj @@ -68,8 +68,8 @@ - - + + @@ -121,13 +121,13 @@ - Application + StaticLibrary true v140 Unicode - Application + StaticLibrary false v140 true @@ -182,9 +182,10 @@ Level3 Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + WIN32;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true $(SolutionDir)\lib\SDL2-2.0.5\include;%(AdditionalIncludeDirectories) + CompileAsCpp Console @@ -215,9 +216,10 @@ MaxSpeed true true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + WIN32;_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true $(SolutionDir)\lib\SDL2-2.0.5\include;%(AdditionalIncludeDirectories) + CompileAsCpp Console diff --git a/build/libjin/libjin.vcxproj.filters b/build/libjin/libjin.vcxproj.filters index 83bc4be..0f3b2e4 100644 --- a/build/libjin/libjin.vcxproj.filters +++ b/build/libjin/libjin.vcxproj.filters @@ -221,12 +221,6 @@ Common - - Common - - - Common - Core @@ -340,6 +334,12 @@ Time + + Common + + + Common + diff --git a/libjin/3rdparty/smount/smount.c b/libjin/3rdparty/smount/smount.c index c4e2ef0..3006fa3 100644 --- a/libjin/3rdparty/smount/smount.c +++ b/libjin/3rdparty/smount/smount.c @@ -109,7 +109,7 @@ int smtexists(smtShared* S, const char *path) static struct stat smtgetstat(smtShared* S, const char*path) { char* r = concat(S->mount->path, "/", path, 0); - struct stat s = {}; + struct stat s = {0}; if (!r) return s; int res = stat(r, &s); free(r); diff --git a/libjin/Audio/SDL/SDLAudio.h b/libjin/Audio/SDL/SDLAudio.h index 4c9ab34..bac4544 100644 --- a/libjin/Audio/SDL/SDLAudio.h +++ b/libjin/Audio/SDL/SDLAudio.h @@ -59,8 +59,6 @@ namespace audio }; - typedef SDLAudio::Setting SDLAudioSetting; - } } diff --git a/libjin/Common/Singleton.hpp b/libjin/Common/Singleton.hpp index 2783927..c3ce467 100644 --- a/libjin/Common/Singleton.hpp +++ b/libjin/Common/Singleton.hpp @@ -21,11 +21,10 @@ namespace jin protected: Singleton() {}; virtual ~Singleton() {}; + static T* _instance; private: Singleton(const Singleton&); Singleton& operator = (const Singleton&); - - static T* _instance; }; template T* Singleton::_instance = nullptr; diff --git a/libjin/Core/Game.cpp b/libjin/Core/Game.cpp index 308bbec..f2223b2 100644 --- a/libjin/Core/Game.cpp +++ b/libjin/Core/Game.cpp @@ -1,16 +1,46 @@ #include "game.h" +#include "../Time/Timer.h" +#include "../input/Event.h" namespace jin { namespace core { - Game::Game() :_run(true) {}; + using namespace jin::input; + + Game::Game() :_running(true) {}; void Game::run() { + _running = true; + Event e; + while (_running) + { + while (jin::input::pollEvent(&e)) + { + if (_instance != nullptr && _onEvent) + _onEvent(&e); + } + if (!_running) + break; + } + } + bool Game::initSystem(const SettingBase* setting) + { + if (setting == nullptr) + return false; + Game::Setting* s = (Game::Setting*) setting; + _onEvent = s->eventHandler; + _onUpdate = s->updater; + _onDraw = s->drawer; + return true; } - -} -} \ No newline at end of file + + void Game::quitSystem() + { + } + +} // core +} // jin \ No newline at end of file diff --git a/libjin/Core/Game.h b/libjin/Core/Game.h index 3928943..7ae1855 100644 --- a/libjin/Core/Game.h +++ b/libjin/Core/Game.h @@ -3,38 +3,33 @@ #include "SDL2/SDL.h" -#include "../common/singleton.h" +#include "../Common/Subsystem.hpp" #include "../utils/macros.h" +#include "../Input/Event.h" namespace jin { namespace core { - class Game : public Singleton + + class Game : public Subsystem { public: - struct Setting - { + typedef void(*onEvent)(jin::input::Event* e); + typedef void(*onUpdate)(float dt); + typedef void(*onDraw)(); - }; - - inline void quit() + struct Setting : SettingBase { - CALLONCE(_quit()); - } - - inline bool running() - { - return run; - } - - inline void exit() - { - CALLONCE(_exit()); - } + onEvent eventHandler; + onUpdate updater; + onDraw drawer; + }; void run(); + inline void stop() { _running = false; }; + inline bool running() { return _running; }; private: @@ -43,19 +38,18 @@ namespace core SINGLETON(Game); - bool _run; + onEvent _onEvent; + onUpdate _onUpdate; + onDraw _onDraw; - inline void _exit() - { - SDL_Quit(); - } + bool _running; + + onlyonce bool initSystem(const SettingBase* setting); + onlyonce void quitSystem(); - inline void _quit() - { - _run = false; - } }; -} -} -#endif \ No newline at end of file +} // core +} // jin + +#endif // __JIN_CORE_GAME_H \ No newline at end of file diff --git a/libjin/Graphics/Window.cpp b/libjin/Graphics/Window.cpp index 2d0fa82..28e5b84 100644 --- a/libjin/Graphics/Window.cpp +++ b/libjin/Graphics/Window.cpp @@ -14,14 +14,14 @@ namespace jin namespace graphics { - onlyonce bool WindowSystem::initSystem(const SettingBase* s) + bool WindowSystem::initSystem(const SettingBase* s) { Loghelper::log(Loglevel::LV_INFO, "Init window system"); if (SDL_Init(SDL_INIT_VIDEO) < 0) return false; - const WindowSetting* setting = (WindowSetting*)s; + const Setting* setting = (Setting*)s; width = setting->width; height = setting->height; @@ -73,9 +73,10 @@ namespace graphics return true; } - onlyonce void WindowSystem::quitSystem() + void WindowSystem::quitSystem() { SDL_DestroyWindow(wnd); + SDL_Quit(); } inline void WindowSystem::swapBuffers() @@ -84,7 +85,7 @@ namespace graphics SDL_GL_SwapWindow(wnd); } -} -} +} // graphics +} // jin #endif // JIN_MODULES_RENDER \ No newline at end of file diff --git a/libjin/Graphics/Window.h b/libjin/Graphics/Window.h index 55492f6..6213cee 100644 --- a/libjin/Graphics/Window.h +++ b/libjin/Graphics/Window.h @@ -51,8 +51,6 @@ namespace graphics onlyonce void quitSystem() override; }; - typedef WindowSystem::Setting WindowSetting; - } // render } // jin diff --git a/test/01HelloWorld/main.cpp b/test/01HelloWorld/main.cpp index 701d53f..09a12d3 100644 --- a/test/01HelloWorld/main.cpp +++ b/test/01HelloWorld/main.cpp @@ -1,7 +1,48 @@ +#include #include "jin.h" -int main() +using namespace jin::core; +using namespace jin::graphics; +using namespace jin::input; + +void onEvent(jin::input::Event* e) +{ + static Game* game = Game::get(); + if (e->type == EventType::QUIT) + game->stop(); +} + +void onUpdate(float dt) +{ + +} + +void onDraw() { - jin::core::Game* game; - jin::graphics::WindowSystem; + +} + +int main(int argc, char* argv[]) +{ + Game* game = Game::get(); + Game::Setting setting; + setting.eventHandler = onEvent; + setting.updater = onUpdate; + setting.drawer = onDraw; + game->init(&setting); + + WindowSystem* wnd = WindowSystem::get(); + WindowSystem::Setting wndSetting; + wndSetting.width = 600; + wndSetting.height = 512; + wndSetting.title = "test"; + wndSetting.vsync = false; + wnd->init(&wndSetting); + + game->run(); + + game->quit(); + wnd->quit(); + + return 0; } \ No newline at end of file -- cgit v1.1-26-g67d0