From d41e44b28183d0825bdf008fa512a97a030f8b40 Mon Sep 17 00:00:00 2001 From: turanszkij Date: Sat, 19 Sep 2015 01:49:30 +0200 Subject: [PATCH] added basic engine info display to main component --- WickedEngine/MainComponent.cpp | 23 +++++++++ WickedEngine/MainComponent.h | 19 +++++++ WickedEngine/MainComponent_BindLua.cpp | 68 ++++++++++++++++++++++++++ WickedEngine/MainComponent_BindLua.h | 4 ++ 4 files changed, 114 insertions(+) diff --git a/WickedEngine/MainComponent.cpp b/WickedEngine/MainComponent.cpp index 88f438adb..79af94495 100644 --- a/WickedEngine/MainComponent.cpp +++ b/WickedEngine/MainComponent.cpp @@ -7,6 +7,7 @@ #include "wiInputManager.h" #include "wiBackLog.h" #include "MainComponent_BindLua.h" +#include "WickedEngine.h" MainComponent::MainComponent() { @@ -19,6 +20,8 @@ MainComponent::MainComponent() setFrameSkip(true); setTargetFrameRate(60); setApplicationControlLostThreshold(10); + + infoDisplay = InfoDisplayer(); } @@ -102,6 +105,26 @@ void MainComponent::Compose() { getActiveComponent()->Compose(); + + if (infoDisplay.active) + { + stringstream ss(""); + if (infoDisplay.watermark) + { + ss << string("Wicked Engine ") + string(WICKED_ENGINE_VERSION) << endl; + } + if (infoDisplay.fpsinfo) + { + ss.precision(2); + ss << fixed << wiFrameRate::FPS() << " FPS" << endl; + } + if (infoDisplay.cpuinfo) + { + ss << "CPU: " << wiCpuInfo::GetCpuPercentage() << "%" << endl; + } + wiFont(ss.str(), wiFontProps(0, 0, infoDisplay.size, WIFALIGN_LEFT, WIFALIGN_TOP, infoDisplay.size)).Draw(); + } + wiBackLog::Draw(); } diff --git a/WickedEngine/MainComponent.h b/WickedEngine/MainComponent.h index b6049603c..ae1fbbea0 100644 --- a/WickedEngine/MainComponent.h +++ b/WickedEngine/MainComponent.h @@ -49,5 +49,24 @@ public: bool setWindow(Windows::UI::Core::CoreWindow^ window); #endif + + struct InfoDisplayer + { + // activate the whole display + bool active; + // display engine version number + bool watermark; + // display framerate + bool fpsinfo; + // display cpu utilization + bool cpuinfo; + // text size + float size; + + InfoDisplayer() :active(false), watermark(true), fpsinfo(true), cpuinfo(true), size(-7.f) + {} + }; + // display all-time engine information text + InfoDisplayer infoDisplay; }; diff --git a/WickedEngine/MainComponent_BindLua.cpp b/WickedEngine/MainComponent_BindLua.cpp index 3b38a6127..cf106e9c3 100644 --- a/WickedEngine/MainComponent_BindLua.cpp +++ b/WickedEngine/MainComponent_BindLua.cpp @@ -14,6 +14,10 @@ Luna::FunctionType MainComponent_BindLua::methods[] = { lunamethod(MainComponent_BindLua, GetActiveComponent), lunamethod(MainComponent_BindLua, SetActiveComponent), lunamethod(MainComponent_BindLua, SetFrameSkip), + lunamethod(MainComponent_BindLua, SetInfoDisplay), + lunamethod(MainComponent_BindLua, SetWatermarkDisplay), + lunamethod(MainComponent_BindLua, SetFPSDisplay), + lunamethod(MainComponent_BindLua, SetCPUDisplay), { NULL, NULL } }; Luna::PropertyType MainComponent_BindLua::properties[] = { @@ -179,6 +183,70 @@ int MainComponent_BindLua::SetFrameSkip(lua_State *L) wiLua::SError(L, "SetFrameSkip(bool enabled) not enought arguments!"); return 0; } +int MainComponent_BindLua::SetInfoDisplay(lua_State *L) +{ + if (component == nullptr) + { + wiLua::SError(L, "SetInfoDisplay() component is empty!"); + return 0; + } + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + component->infoDisplay.active = wiLua::SGetBool(L, 1); + } + else + wiLua::SError(L, "SetInfoDisplay(bool active) not enough arguments!"); + return 0; +} +int MainComponent_BindLua::SetWatermarkDisplay(lua_State *L) +{ + if (component == nullptr) + { + wiLua::SError(L, "SetWatermarkDisplay() component is empty!"); + return 0; + } + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + component->infoDisplay.watermark = wiLua::SGetBool(L, 1); + } + else + wiLua::SError(L, "SetWatermarkDisplay(bool active) not enough arguments!"); + return 0; +} +int MainComponent_BindLua::SetFPSDisplay(lua_State *L) +{ + if (component == nullptr) + { + wiLua::SError(L, "SetFPSDisplay() component is empty!"); + return 0; + } + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + component->infoDisplay.fpsinfo = wiLua::SGetBool(L, 1); + } + else + wiLua::SError(L, "SetFPSDisplay(bool active) not enough arguments!"); + return 0; +} +int MainComponent_BindLua::SetCPUDisplay(lua_State *L) +{ + if (component == nullptr) + { + wiLua::SError(L, "SetCPUDisplay() component is empty!"); + return 0; + } + int argc = wiLua::SGetArgCount(L); + if (argc > 0) + { + component->infoDisplay.cpuinfo = wiLua::SGetBool(L, 1); + } + else + wiLua::SError(L, "SetCPUDisplay(bool active) not enough arguments!"); + return 0; +} void MainComponent_BindLua::Bind() { diff --git a/WickedEngine/MainComponent_BindLua.h b/WickedEngine/MainComponent_BindLua.h index 339d1209e..fe50439ce 100644 --- a/WickedEngine/MainComponent_BindLua.h +++ b/WickedEngine/MainComponent_BindLua.h @@ -20,6 +20,10 @@ public: int GetActiveComponent(lua_State *L); int SetActiveComponent(lua_State *L); int SetFrameSkip(lua_State *L); + int SetInfoDisplay(lua_State *L); + int SetWatermarkDisplay(lua_State *L); + int SetFPSDisplay(lua_State *L); + int SetCPUDisplay(lua_State *L); static void Bind(); };