From 789b2dea3f0e8911020f0054b213bb84cc06e715 Mon Sep 17 00:00:00 2001 From: Peter Schaefer Date: Tue, 7 Jun 2016 08:26:30 +0200 Subject: [PATCH] Event (FKey) Messages, FPS&ObjectCount im WindowTitle (Frustum sieht man jetzt) --- Weave/Events.cpp | 14 +++++++++++++- Weave/Game.cpp | 7 +++++-- Weave/Graphix/Graphix.cpp | 19 +++++++++++++++++++ Weave/Graphix/Graphix.h | 6 ++++++ Weave/Scene/Scene.cpp | 8 +++++++- 5 files changed, 50 insertions(+), 4 deletions(-) diff --git a/Weave/Events.cpp b/Weave/Events.cpp index 4851b6a..7c9eee3 100644 --- a/Weave/Events.cpp +++ b/Weave/Events.cpp @@ -5,13 +5,14 @@ #include "Game.h" #include "GLM.h" +#include "Message.h" #include using std::cout; using std::endl; - +void message(std::string title, bool onoff); void Events::processEvents() { @@ -112,9 +113,11 @@ void Events::KeyDown(int _key) break; case SDLK_F2: //FPS + message("FPS", !key_toggle[SDLK_F2]); break; case SDLK_F3: //WIREFRAME + message("WireFrame", !key_toggle[SDLK_F3]); break; case SDLK_F4: //TEXTURE SAMPLING QUALITY @@ -124,6 +127,7 @@ void Events::KeyDown(int _key) break; case SDLK_F6: //??? BoundingBox + message("BoundingMeshes", !key_toggle[SDLK_F6]); break; case SDLK_F7: //??? @@ -134,6 +138,7 @@ void Events::KeyDown(int _key) Graphix::disableEffects(EF_FRUSTUM_CULLING); else Graphix::enableEffects(EF_FRUSTUM_CULLING); + message("FrustumCulling", !key_toggle[SDLK_F9]); break; case SDLK_F9: //TRANSPARENCY @@ -141,6 +146,7 @@ void Events::KeyDown(int _key) Graphix::disableEffects(EF_TRANSPARENCY); else Graphix::enableEffects(EF_TRANSPARENCY); + message("Transparency", key_toggle[SDLK_F9]); break; case SDLK_F10: //??? FullScreen @@ -148,6 +154,7 @@ void Events::KeyDown(int _key) Graphix::FullScreen(true,true); else Graphix::FullScreen(false,true); + message("FullScreen", !key_toggle[SDLK_F10]); break; case SDLK_SPACE: jump++; @@ -291,6 +298,11 @@ int Events::returnSet(int& value, int action2) return tmp; } +void message(std::string title, bool onoff) +{ + Message::info(title + ": " + ((onoff)? "on" : "off")); +} + map Events::key_held; map Events::mouse_held; map Events::pad_held; diff --git a/Weave/Game.cpp b/Weave/Game.cpp index b167f42..5b60c14 100644 --- a/Weave/Game.cpp +++ b/Weave/Game.cpp @@ -112,14 +112,17 @@ void Game::play() { ++framecount; message_time += fps.getDelta(); - if (message_time >= 1.5) + if (message_time >= 0.5) { - Message::info((string)"Fps: " + std::to_string((float)framecount/message_time)); + Graphix::updateFPS((float)framecount / message_time); + //Message::info((string)"Fps: " + std::to_string((float)framecount/message_time)); message_time = 0; framecount = 0; } } + else + Graphix::updateFPS(-1); diff --git a/Weave/Graphix/Graphix.cpp b/Weave/Graphix/Graphix.cpp index ed3d421..4595275 100644 --- a/Weave/Graphix/Graphix.cpp +++ b/Weave/Graphix/Graphix.cpp @@ -218,7 +218,13 @@ void Graphix::clear() glClear(GL_ACCUM_BUFFER_BIT); } + string out = windowTitle; + if (fps > 0) + out += "(FPS:" + std::to_string(fps) + ")"; + if (obj >= 0) + out += "(NumObj:" + std::to_string(obj) + ")"; + SDL_SetWindowTitle(sdl_window, out.c_str()); } @@ -270,6 +276,16 @@ unsigned int Graphix::getGlError() return error; } +void Graphix::updateFPS(float _fps) +{ + fps = _fps; +} + +void Graphix::updateNumObjects(int _obj) +{ + obj = _obj; +} + unsigned int Graphix::width = 1024; unsigned int Graphix::height = 768; @@ -289,3 +305,6 @@ SDL_Window* Graphix::sdl_window; SDL_GLContext Graphix::sdl_glcontext; short Graphix::effects = EF_TRANSPARENCY | EF_BLOOM | EF_FRUSTUM_CULLING; + +int Graphix::obj = -1; +float Graphix::fps = -1; diff --git a/Weave/Graphix/Graphix.h b/Weave/Graphix/Graphix.h index ea7a0ea..a004d98 100644 --- a/Weave/Graphix/Graphix.h +++ b/Weave/Graphix/Graphix.h @@ -23,6 +23,9 @@ public: static unsigned int getWindowHeight(); static unsigned int getWindowWidth(); + static void updateFPS(float fps); + static void updateNumObjects(int obj); + static void FullScreen(bool enable, bool keepDesktopResolution = true); static void catchMouse(); @@ -59,5 +62,8 @@ private: static short effects; + static int obj; + static float fps; + }; diff --git a/Weave/Scene/Scene.cpp b/Weave/Scene/Scene.cpp index a168b5c..8c709f6 100644 --- a/Weave/Scene/Scene.cpp +++ b/Weave/Scene/Scene.cpp @@ -343,7 +343,7 @@ void Scene::draw() const void Scene::drawSceneObjects(drawTarget _target, bool _culling) const { /*TODO: Z-Order (Back2Front)*/ - + int count = 0; for (auto i = SceneObjects.cbegin(); i != SceneObjects.cend(); ++i) { if (Graphix::testEffect(EF_FRUSTUM_CULLING)&&_culling) @@ -353,7 +353,13 @@ void Scene::drawSceneObjects(drawTarget _target, bool _culling) const continue; } (*i)->draw(_target); + count++; } + + if (Events::isKToggleActive(SDLK_F2)) + Graphix::updateNumObjects(count); + else + Graphix::updateNumObjects(-1); } void Scene::addObject(SceneObject* _add) -- 2.47.3