Sdk/Application: Add Console and FPSCounter overlays

This allows any Nazara-powered application to enable a ready-to-use
console or a working FPS counter


Former-commit-id: 2b1c7ae5a7c72ea1c102734841f4e25742c2b42b [formerly f1fece5295a0a43147396752b3c61d84e0d7fc74] [formerly 40eff1e79a68fb5e0b7e1d4d6528fec318fed74c [formerly b17ee1558babcd4ed89525e447fb9c4e58b67033]]
Former-commit-id: 1e1297789e402d25e7b5324dceebbbe8021a2217 [formerly 1c62735c3ff7f53efbef3e45c2284739fc22ec32]
Former-commit-id: 3d331aae0e7db884e36d07b095a9d25a1dbe7926
This commit is contained in:
Lynix
2016-08-28 18:10:09 +02:00
parent 62cfdd6ade
commit 07fe2f560e
5 changed files with 423 additions and 120 deletions

View File

@@ -8,18 +8,34 @@
#define NDK_APPLICATION_HPP
#include <NDK/Prerequesites.hpp>
#include <NDK/EntityOwner.hpp>
#include <NDK/World.hpp>
#include <Nazara/Core/Clock.hpp>
#include <Nazara/Utility/Window.hpp>
#include <list>
#include <set>
#include <vector>
#ifndef NDK_SERVER
#include <NDK/Console.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Lua/LuaInstance.hpp>
#include <Nazara/Graphics/TextSprite.hpp>
#include <Nazara/Renderer/RenderTarget.hpp>
#include <Nazara/Utility/Window.hpp>
#endif
namespace Ndk
{
class NDK_API Application
{
public:
#ifndef NDK_SERVER
struct ConsoleOverlay;
struct FPSCounterOverlay;
#endif
inline Application();
inline Application(int argc, const char* argv[]);
Application(const Application&) = delete;
Application(Application&&) = delete;
inline ~Application();
@@ -29,8 +45,21 @@ namespace Ndk
#endif
template<typename... Args> World& AddWorld(Args&&... args);
#ifndef NDK_SERVER
inline void EnableConsole(bool enable);
inline void EnableFPSCounter(bool enable);
inline ConsoleOverlay& GetConsoleOverlay(std::size_t windowIndex = 0U);
inline FPSCounterOverlay& GetFPSCounterOverlay(std::size_t windowIndex = 0U);
#endif
inline float GetUpdateTime() const;
#ifndef NDK_SERVER
inline bool IsConsoleEnabled() const;
inline bool IsFPSCounterEnabled() const;
#endif
bool Run();
#ifndef NDK_SERVER
@@ -44,13 +73,56 @@ namespace Ndk
inline static Application* Instance();
#ifndef NDK_SERVER
struct ConsoleOverlay
{
std::unique_ptr<Console> console;
Nz::LuaInstance lua;
NazaraSlot(Nz::EventHandler, OnEvent, eventSlot);
NazaraSlot(Nz::EventHandler, OnKeyPressed, keyPressedSlot);
NazaraSlot(Nz::EventHandler, OnResized, resizedSlot);
NazaraSlot(Nz::Log, OnLogWrite, logSlot);
};
struct FPSCounterOverlay
{
Nz::TextSpriteRef sprite;
EntityOwner entity;
float elapsedTime = 0.f;
unsigned int frameCount = 0;
};
#endif
private:
#ifndef NDK_SERVER
std::vector<std::unique_ptr<Nz::Window>> m_windows;
enum OverlayFlags
{
OverlayFlags_Console = 0x1,
OverlayFlags_FPSCounter = 0x2
};
struct WindowInfo
{
inline WindowInfo(std::unique_ptr<Nz::Window>&& window);
Nz::RenderTarget* renderTarget;
std::unique_ptr<Nz::Window> window;
std::unique_ptr<ConsoleOverlay> console;
std::unique_ptr<FPSCounterOverlay> fpsCounter;
std::unique_ptr<World> overlayWorld;
};
void SetupConsole(WindowInfo& info);
void SetupFPSCounter(WindowInfo& info);
void SetupOverlay(WindowInfo& info);
std::vector<WindowInfo> m_windows;
#endif
std::list<World> m_worlds;
Nz::Clock m_updateClock;
#ifndef NDK_SERVER
Nz::UInt32 m_overlayFlags;
bool m_exitOnClosedWindows;
#endif
bool m_shouldQuit;