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: 274b276313b530ff8c99f3e0fb43c8b78689d787 [formerly 36e3a7e9d0d050af4b217311bde4496597e37c37] [formerly 69146c2fc6887f86b9c39d0265a95a4ba003f41e [formerly 72a66d7a31ceb87197b800813c90d43f73fc26b4]] Former-commit-id: 3fda987313648101b8a423e5e3aa8b0cd67a1c72 [formerly 5f9d42cdc5ed5443846531bad26059f66670df63] Former-commit-id: 2ef1496fb4a379e14f9c11c788da306eff465719
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