- Some underlying features for RTTI
- Macro for automatically generating this_t - Semantics with static_constructor.h, now FENNEC_PRIVATE_STATIC_CONSTRUCTOR for .cpp files and FENNEC_CLASS_STATIC_CONSTRUCTOR for a class in any source file type.
This commit is contained in:
114
include/fennec/platform/interface/display_server.h
Normal file
114
include/fennec/platform/interface/display_server.h
Normal file
@@ -0,0 +1,114 @@
|
||||
// =====================================================================================================================
|
||||
// fennec, a free and open source game engine
|
||||
// Copyright © 2025 Medusa Slockbower
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
///
|
||||
/// \file display_server.h
|
||||
/// \brief
|
||||
///
|
||||
///
|
||||
/// \details
|
||||
/// \author Medusa Slockbower
|
||||
///
|
||||
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
|
||||
///
|
||||
///
|
||||
|
||||
#ifndef FENNEC_PLATFORM_INTERFACE_DISPLAY_SERVER_H
|
||||
#define FENNEC_PLATFORM_INTERFACE_DISPLAY_SERVER_H
|
||||
|
||||
#include <fennec/containers/bitfield.h>
|
||||
#include <fennec/platform/interface/fwd.h>
|
||||
#include <fennec/platform/interface/window.h>
|
||||
#include <fennec/rtti/enable.h>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
class display_server {
|
||||
// Typedefs/Constants/Enums ============================================================================================
|
||||
public:
|
||||
|
||||
enum feature_ : uint32_t {
|
||||
feature_subwindows = 0,
|
||||
feature_icon,
|
||||
|
||||
feature_window_drag,
|
||||
|
||||
feature_mouse,
|
||||
feature_cursors,
|
||||
feature_custom_cursors,
|
||||
|
||||
feature_clipboard,
|
||||
feature_clipboard_primary,
|
||||
feature_virtual_keyboard,
|
||||
|
||||
feature_status_indicators,
|
||||
feature_dialogues,
|
||||
feature_input_dialogues,
|
||||
feature_file_dialogues,
|
||||
feature_filtered_file_dialogues,
|
||||
|
||||
feature_orientation,
|
||||
feature_hidpi,
|
||||
feature_hdr,
|
||||
feature_swap_buffers,
|
||||
feature_window_transparency,
|
||||
|
||||
feature_screen_reader,
|
||||
feature_text_to_speech,
|
||||
feature_touchscreen,
|
||||
feature_system_theme,
|
||||
|
||||
feature_count,
|
||||
};
|
||||
|
||||
using featureset_t = bitfield<feature_count>;
|
||||
|
||||
struct config {
|
||||
};
|
||||
|
||||
|
||||
// Public Members ======================================================================================================
|
||||
platform* const platform;
|
||||
|
||||
explicit display_server(fennec::platform* p)
|
||||
: platform(p) {
|
||||
}
|
||||
|
||||
virtual ~display_server() = default;
|
||||
|
||||
|
||||
bool has_feature(uint32_t feature) const {
|
||||
return _features.test(feature);
|
||||
}
|
||||
|
||||
|
||||
virtual window* create_window(const window::config& conf) = 0;
|
||||
|
||||
|
||||
private:
|
||||
featureset_t _features;
|
||||
|
||||
FENNEC_RTTI_CLASS_ENABLE() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // FENNEC_PLATFORM_INTERFACE_DISPLAY_SERVER_H
|
||||
@@ -22,7 +22,10 @@
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
class window; // Handles window surfaces of the display protocol
|
||||
class platform;
|
||||
|
||||
class display_server; // The display server used by the OS, e.g. WDM, Wayland, X11, etc.
|
||||
class window; // Handles window surfaces of the display protocol
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
#include <fennec/lang/strings/string.h>
|
||||
#include <fennec/platform/interface/fwd.h>
|
||||
#include <fennec/platform/interface/window.h>
|
||||
#include <fennec/rtti/enable.h>
|
||||
#include <fennec/rtti/detail/_this_t.h>
|
||||
|
||||
/*
|
||||
* This class should resemble the target platform as a whole. By itself, it will represent the OS, i.e. Linux, Windows,
|
||||
@@ -65,50 +67,7 @@ public:
|
||||
using shared_object = struct shared_object;
|
||||
using symbol = void*;
|
||||
|
||||
template<typename ctor>
|
||||
struct driver {
|
||||
int priority;
|
||||
ctor constructor;
|
||||
|
||||
driver()
|
||||
: priority(0)
|
||||
, constructor(nullptr) {
|
||||
}
|
||||
|
||||
driver(int priority, ctor constructor)
|
||||
: priority(priority)
|
||||
, constructor(constructor) {
|
||||
}
|
||||
|
||||
driver(const driver& d)
|
||||
: priority(d.priority)
|
||||
, constructor(d.constructor) {
|
||||
}
|
||||
|
||||
driver(driver&& d) noexcept
|
||||
: priority(d.priority)
|
||||
, constructor(d.constructor) {
|
||||
}
|
||||
|
||||
driver& operator=(const driver& d) {
|
||||
priority = d.priority;
|
||||
constructor = d.constructor;
|
||||
return *this;
|
||||
}
|
||||
|
||||
driver& operator=(driver&& d) noexcept {
|
||||
priority = fennec::move(d.priority);
|
||||
constructor = fennec::move(d.constructor);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator<(const driver& d) const {
|
||||
return priority > d.priority;
|
||||
}
|
||||
};
|
||||
|
||||
const string name;
|
||||
|
||||
platform() = default;
|
||||
virtual ~platform() = default;
|
||||
platform(const platform&) = delete;
|
||||
|
||||
@@ -120,39 +79,9 @@ public:
|
||||
virtual void initialize(); // Initialize Drivers and Contexts
|
||||
virtual void shutdown(); // Close Drivers and Contexts
|
||||
|
||||
// Platform level functions for retrieving driver and protocol contexts ================================================
|
||||
FENNEC_RTTI_CLASS_ENABLE() {
|
||||
|
||||
// Window Management
|
||||
using window_ctor = window* (*)(platform*, const window::config&);
|
||||
using window_driver = driver<window_ctor>;
|
||||
window* create_window(const window::config& config);
|
||||
static void register_window_driver(window_driver&& driver);
|
||||
|
||||
protected:
|
||||
template<typename PlatformT>
|
||||
explicit platform(const cstring& name, PlatformT*)
|
||||
: name(name) {
|
||||
assertf(globals.singleton == nullptr, "Conflicting platform implementations!");
|
||||
globals.singleton = this;
|
||||
}
|
||||
|
||||
// Static Stuff ========================================================================================================
|
||||
|
||||
public:
|
||||
static platform* instance() {
|
||||
return globals.singleton;
|
||||
}
|
||||
|
||||
private:
|
||||
inline static struct global {
|
||||
platform* singleton;
|
||||
sequence<window_driver> windows;
|
||||
|
||||
global()
|
||||
: singleton(nullptr)
|
||||
, windows() {
|
||||
}
|
||||
} globals = global();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -33,120 +33,46 @@
|
||||
|
||||
#include <fennec/langcpp/types.h>
|
||||
#include <fennec/lang/strings/string.h>
|
||||
#include <fennec/containers/bitfield.h>
|
||||
#include <fennec/renderers/interface/gfxcontext.h>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
class window {
|
||||
// Structures & Typedefs ===============================================================================================
|
||||
public:
|
||||
virtual ~window() = default;
|
||||
enum flag_ {
|
||||
flag_always_on_top = 0, // Window always appears on top level
|
||||
flag_borderless, // Window has no border decorations
|
||||
flag_child, // Window is a child window, and closes when the parent does
|
||||
flag_decorations, // Window has a titlebar with basic functions
|
||||
flag_modal, // Window always appears above parent and blocks input going to parent
|
||||
flag_pass_mouse, // Mouse interaction passes to next underlying window in the application
|
||||
flag_popup, // Window does not show in taskbar and closes when loses focus
|
||||
flag_resizable, // Window can be resized through functions defined by Desktop Environment
|
||||
flag_transparent, // Window has an alpha value
|
||||
flag_visible, // Window is visible
|
||||
flag_no_focus, // Window can be focused
|
||||
|
||||
enum flags : uint8_t {
|
||||
fullscreen = 0x1 << 0,
|
||||
borderless = 0x1 << 1,
|
||||
resizeable = 0x1 << 2,
|
||||
modal = 0x1 << 3, // Treat as modal, blocks interaction with parent windows
|
||||
popup = 0x1 << 4, // Treat as a popup menu
|
||||
tooltip = 0x1 << 5, // Treat as a tooltip, does not receive mouse or keyboard focus
|
||||
utility = 0x1 << 6, // Treat as utility, does not show in taskbar
|
||||
flag_count
|
||||
};
|
||||
|
||||
enum vsync {
|
||||
vsync_off = 0,
|
||||
vsync_on = 1,
|
||||
adaptive_sync = -1,
|
||||
};
|
||||
using flags_t = bitfield<flag_count>;
|
||||
|
||||
struct pixel_format {
|
||||
uint8_t r, g, b, a;
|
||||
bool floating_point;
|
||||
};
|
||||
|
||||
struct display_mode {
|
||||
pixel_format format;
|
||||
float rate;
|
||||
float density;
|
||||
struct accessibility {
|
||||
string name, description;
|
||||
};
|
||||
|
||||
struct config {
|
||||
uint8_t flags;
|
||||
display_mode mode;
|
||||
string title;
|
||||
int8_t vsync;
|
||||
string title;
|
||||
flags_t flags;
|
||||
|
||||
ivec2 size;
|
||||
|
||||
accessibility accessibility;
|
||||
};
|
||||
|
||||
// Properties ==========================================================================================================
|
||||
|
||||
virtual bool running() = 0;
|
||||
|
||||
bool is_fullscreen() const {
|
||||
return _config.flags & fullscreen;
|
||||
}
|
||||
|
||||
bool is_borderless() const {
|
||||
return _config.flags & borderless;
|
||||
}
|
||||
|
||||
bool is_modal() const {
|
||||
return _config.flags & modal;
|
||||
}
|
||||
|
||||
bool is_resizeable() const {
|
||||
return _config.flags & resizeable;
|
||||
}
|
||||
|
||||
const display_mode& get_mode() const {
|
||||
return _config.mode;
|
||||
}
|
||||
|
||||
const pixel_format& get_format() const {
|
||||
return _config.mode.format;
|
||||
}
|
||||
|
||||
bool is_hdr() const {
|
||||
static constexpr size_t sdr = 255ull * 255ull * 255ull;
|
||||
const pixel_format& fmt = _config.mode.format;
|
||||
return fmt.r * fmt.g * fmt.b > sdr;
|
||||
}
|
||||
|
||||
const config& get_config() const {
|
||||
return _config;
|
||||
}
|
||||
|
||||
// Modifiers ===========================================================================================================
|
||||
|
||||
virtual void resize(size_t, size_t) = 0;
|
||||
virtual void position(size_t, size_t) = 0;
|
||||
|
||||
virtual void set_fullscreen(bool) = 0;
|
||||
virtual void set_borderless(bool) = 0;
|
||||
|
||||
virtual void grab_mouse(bool) = 0;
|
||||
virtual void grab_keyboard(bool) = 0;
|
||||
|
||||
virtual void set_title(const cstring&) = 0;
|
||||
virtual void set_title(const string&) = 0;
|
||||
virtual void set_progress(bool, float) = 0;
|
||||
|
||||
virtual void vsync(int8_t) = 0;
|
||||
|
||||
// Graphics ============================================================================================================
|
||||
|
||||
virtual void begin_frame() = 0;
|
||||
virtual void end_frame() = 0;
|
||||
|
||||
protected:
|
||||
window* _parent;
|
||||
gfxcontext* _context;
|
||||
config _config;
|
||||
|
||||
window(window* parent, const config& cfg)
|
||||
: _parent(parent)
|
||||
, _config(cfg) {
|
||||
}
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace fennec
|
||||
class linux_platform : public unix_platform {
|
||||
public:
|
||||
linux_platform()
|
||||
: unix_platform("linux", this) {
|
||||
: unix_platform() {
|
||||
}
|
||||
|
||||
void initialize() override;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
// =====================================================================================================================
|
||||
|
||||
///
|
||||
/// \file sdlwindow.h
|
||||
/// \file display_server.h
|
||||
/// \brief
|
||||
///
|
||||
///
|
||||
@@ -28,40 +28,25 @@
|
||||
///
|
||||
///
|
||||
|
||||
#ifndef FENNEC_PLATFORM_SDL_SDLWINDOW_H
|
||||
#define FENNEC_PLATFORM_SDL_SDLWINDOW_H
|
||||
|
||||
#include <fennec/platform/interface/window.h>
|
||||
#ifndef FENNEC_PLATFORM_LINUX_WAYLAND_DISPLAY_SERVER_H
|
||||
#define FENNEC_PLATFORM_LINUX_WAYLAND_DISPLAY_SERVER_H
|
||||
#include <fennec/platform/interface/display_server.h>
|
||||
|
||||
namespace fennec
|
||||
{
|
||||
|
||||
class sdlwindow : public window {
|
||||
class wayland_server : display_server {
|
||||
public:
|
||||
sdlwindow(window* parent, const config& cfg);
|
||||
|
||||
bool running() override;
|
||||
|
||||
void set_fullscreen(bool) override;
|
||||
void set_borderless(bool) override;
|
||||
|
||||
void grab_mouse(bool) override;
|
||||
void grab_keyboard(bool) override;
|
||||
|
||||
void set_title(const cstring&) override;
|
||||
void set_title(const string&) override;
|
||||
void set_progress(bool, float) override;
|
||||
|
||||
void vsync(int8_t) override;
|
||||
|
||||
|
||||
void begin_frame() override;
|
||||
void end_frame() override;
|
||||
explicit wayland_server(fennec::platform* p)
|
||||
: display_server(p) {
|
||||
}
|
||||
|
||||
private:
|
||||
FENNEC_RTTI_CLASS_ENABLE(display_server) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // FENNEC_PLATFORM_SDL_SDLWINDOW_H
|
||||
#endif // FENNEC_PLATFORM_LINUX_WAYLAND_DISPLAY_SERVER_H
|
||||
@@ -26,9 +26,8 @@ namespace fennec
|
||||
|
||||
class unix_platform : public platform {
|
||||
public:
|
||||
template<typename PlatformT>
|
||||
explicit unix_platform(const cstring& name, PlatformT* type)
|
||||
: platform(name, type) {
|
||||
explicit unix_platform()
|
||||
: platform() {
|
||||
}
|
||||
|
||||
shared_object* load_object(const cstring& file) override;
|
||||
|
||||
Reference in New Issue
Block a user