From 3fa76830d3bde5cb3c76da0cc58dd613965b98e5 Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 28 Jul 2018 13:48:26 +0800 Subject: *update --- libjin/Core/Game.cpp | 8 +++++++- libjin/Graphics/Window.cpp | 1 + libjin/Graphics/Window.h | 17 ++++++----------- test/01HelloWorld/main.cpp | 1 + 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/libjin/Core/Game.cpp b/libjin/Core/Game.cpp index f2223b2..707a983 100644 --- a/libjin/Core/Game.cpp +++ b/libjin/Core/Game.cpp @@ -1,25 +1,31 @@ #include "game.h" #include "../Time/Timer.h" #include "../input/Event.h" +#include "../Graphics/Window.h" namespace jin { namespace core { + using namespace jin::graphics; using namespace jin::input; Game::Game() :_running(true) {}; void Game::run() { + WindowSystem* wnd = WindowSystem::get(); _running = true; Event e; + int fps = 60; + if (wnd != nullptr) + fps = wnd->getFPS(); while (_running) { while (jin::input::pollEvent(&e)) { - if (_instance != nullptr && _onEvent) + if (_onEvent != nullptr) _onEvent(&e); } if (!_running) diff --git a/libjin/Graphics/Window.cpp b/libjin/Graphics/Window.cpp index 28e5b84..8a7e8a2 100644 --- a/libjin/Graphics/Window.cpp +++ b/libjin/Graphics/Window.cpp @@ -25,6 +25,7 @@ namespace graphics width = setting->width; height = setting->height; + fps = setting->fps; bool vsync = setting->vsync; const char* title = setting->title; diff --git a/libjin/Graphics/Window.h b/libjin/Graphics/Window.h index 6213cee..66c34a5 100644 --- a/libjin/Graphics/Window.h +++ b/libjin/Graphics/Window.h @@ -19,21 +19,15 @@ namespace graphics struct Setting : SettingBase { public: + const char* title; // 标题 int width, height; // 窗口大小 bool vsync; // 垂直同步 - const char* title; // 标题 + int fps; // FPS }; - inline int getW() - { - return width; - } - - inline int getH() - { - return height; - } - + inline int getW(){ return width; } + inline int getH(){ return height; } + inline int getFPS() { return fps; } inline void swapBuffers(); private: @@ -46,6 +40,7 @@ namespace graphics SDL_Window* wnd; int width, height; + int fps; onlyonce bool initSystem(const SettingBase* setting) override; onlyonce void quitSystem() override; diff --git a/test/01HelloWorld/main.cpp b/test/01HelloWorld/main.cpp index 09a12d3..77d5096 100644 --- a/test/01HelloWorld/main.cpp +++ b/test/01HelloWorld/main.cpp @@ -36,6 +36,7 @@ int main(int argc, char* argv[]) wndSetting.width = 600; wndSetting.height = 512; wndSetting.title = "test"; + wndSetting.fps = 60; wndSetting.vsync = false; wnd->init(&wndSetting); -- cgit v1.1-26-g67d0