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: 87845d0983bb2a72255845b5f83a447a2f7c7c2f [formerly 964c60603b8a6c54e0171b648b9a271fb5af993f] [formerly 3018a4286e2e27cd0ede008c1fe6ecde3441253d [formerly a6b82b63dbfb62d537b626bfd46f5cfe6c946b07]] Former-commit-id: 1d602cad3381dba43ddb236a991b7653e713ae68 [formerly 581b57b5a5f533415163302391612f88bc22fbf3] Former-commit-id: f1a7ef57cd4dd648a5da708133dba875821278e5
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user