- Setup wayland display and window. Window surface is created and appears in hotbar. Window is not visible.

This commit is contained in:
2025-12-14 15:47:11 -05:00
parent a1bdc077b1
commit 5dcb58f53c
25 changed files with 985 additions and 40 deletions

View File

@@ -34,6 +34,7 @@
#include <fennec/lang/types.h>
#include <fennec/lang/assert.h>
#include <fennec/lang/metasequences.h>
namespace fennec
{

View File

@@ -33,6 +33,7 @@
#include <fennec/containers/array.h>
#include <fennec/lang/types.h>
#include <fennec/lang/utility.h>
namespace fennec
{
@@ -49,7 +50,7 @@ public:
: _bytes() {
}
constexpr bitfield(const bool (&arr)[N])
explicit constexpr bitfield(const bool (&arr)[N])
: _bytes() {
for (size_t i = 0; i < arr; ++i) {
this->store(i, arr[i]);
@@ -57,7 +58,7 @@ public:
}
template<size_t I>
constexpr bitfield(const size_t (&arr)[I])
explicit constexpr bitfield(const size_t (&arr)[I])
: _bytes() {
for (size_t i : arr) {
this->set(i);

View File

@@ -0,0 +1,88 @@
// =====================================================================================================================
// 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 logger.h
/// \brief
///
///
/// \details
/// \author Medusa Slockbower
///
/// \copyright Copyright © 2025 Medusa Slockbower ([GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html))
///
///
#ifndef FENNEC_CORE_LOGGER_H
#define FENNEC_CORE_LOGGER_H
#include <fennec/filesystem/file.h>
#include <fennec/rtti/singleton.h>
#include <fennec/containers/tuple.h>
namespace fennec
{
class logger : public singleton<logger> {
public:
logger();
~logger();
static void log(const cstring& str,
uint32_t _line = FENNEC_BUILTIN_LINE(),
const char* const _file = FENNEC_BUILTIN_FILE()
) {
logger& inst = instance();
if (inst._logfile.is_open()) {
inst._logfile.print(cstring(_file, strlen(_file)));
inst._logfile.printf("({}): ", _line);
inst._logfile.println(str);
}
inst._cout->print(cstring(_file, strlen(_file)));
inst._cout->printf("({}): ", _line);
inst._cout->println(str);
}
static void log(const string& str,
uint32_t _line = FENNEC_BUILTIN_LINE(),
const char* const _file = FENNEC_BUILTIN_FILE()
) {
logger& inst = instance();
if (inst._logfile.is_open()) {
inst._logfile.print(cstring(_file, strlen(_file)));
inst._logfile.printf("({}): ", _line);
inst._logfile.println(str);
}
inst._cout->print(cstring(_file, strlen(_file)));
inst._cout->printf("({}): ", _line);
inst._cout->println(str);
}
private:
file _logfile;
file* _cout;
};
}
#endif // FENNEC_CORE_LOGGER_H

View File

@@ -20,6 +20,7 @@
#define FENNEC_FILESYSTEM_FILE_H
#include <fennec/filesystem/path.h>
#include <fennec/format/format.h>
#include <fennec/string/cstring.h>
#include <fennec/string/string.h>
@@ -108,6 +109,21 @@ public:
/// \brief default constructor, initializes an empty stream
file();
file(const cstring& path, uint8_t mode)
: file() {
open(path, mode);
}
file(const string& path, uint8_t mode)
: file() {
open(path, mode);
}
file(const path& path, uint8_t mode)
: file() {
open(path, mode);
}
///
/// \brief default destructor, cleans up an open stream
~file();
@@ -302,6 +318,18 @@ public:
// Printing Operations =================================================================================================
void print(const cstring& str);
void print(const string& str);
void println(const cstring& str);
void println(const string& str);
template<typename...ArgsT>
void printf(const cstring& str, ArgsT&&...args) {
string fmt = fennec::format(str, fennec::forward<ArgsT>(args)...);
this->print(cstring(fmt.cstr(), fmt.length()));
}

View File

@@ -80,6 +80,20 @@ struct _format_arg<T&> : _format_arg<T> {
}
};
// Polymorphic template specialization for x/r/xr value references
template<typename T>
struct _format_arg<const T> : _format_arg<T> {
_format_arg(const T& arg) : _format_arg<T>(arg) {
}
};
// Polymorphic template specialization for x/r/xr value references
template<typename T>
struct _format_arg<const T&> : _format_arg<T> {
_format_arg(const T& arg) : _format_arg<T>(arg) {
}
};
// Containing array for format args
template<size_t N>
struct _format_argarray {

View File

@@ -54,6 +54,13 @@ struct formatter {
// strings =============================================================================================================
template<size_t N>
struct formatter<char[N]> {
string operator()(const format_arg&, const char (&str)[N]) {
return string(str);
}
};
template<size_t N>
struct formatter<const char[N]> {
string operator()(const format_arg&, const char (&str)[N]) {

View File

@@ -102,6 +102,9 @@
// Most major compilers support __has_builtin, notably GCC, MINGW, and CLANG
#if defined(__has_builtin)
// UTILITIES ===========================================================================================================
// addressof is very difficult to implement without intrinsics.
#if __has_builtin(__builtin_addressof)
# define FENNEC_HAS_BUILTIN_ADDRESSOF 1
@@ -118,6 +121,37 @@
# define FENNEC_HAS_BUILTIN_BIT_CAST 0
#endif
#if __has_builtin(__builtin_LINE)
# define FENNEC_HAS_BUILTIN_LINE 1
# define FENNEC_BUILTIN_LINE() __builtin_LINE()
#else
# define FENNEC_HAS_BUILTIN_LINE 0
#endif
#if __has_builtin(__builtin_COLUMN)
# define FENNEC_HAS_BUILTIN_COLUMN 1
# define FENNEC_BUILTIN_COLUMN() __builtin_COLUMN()
#else
# define FENNEC_HAS_BUILTIN_COLUMN 0
#endif
#if __has_builtin(__builtin_FILE)
# define FENNEC_HAS_BUILTIN_FILE 1
# define FENNEC_BUILTIN_FILE() __builtin_FILE()
#else
# define FENNEC_HAS_BUILTIN_FILE 0
#endif
#if __has_builtin(__builtin_FUNCTION)
# define FENNEC_HAS_BUILTIN_FUNCTION 1
# define FENNEC_BUILTIN_FUNCTION() __builtin_FUNCTION()
#else
# define FENNEC_HAS_BUILTIN_FUNCTION 0
#endif
// PROPERTIES ==========================================================================================================
// Inconsistent without intrinsics
#if __has_builtin(__is_abstract)
# define FENNEC_HAS_BUILTIN_IS_ABSTRACT 1
@@ -142,6 +176,7 @@
# define FENNEC_HAS_BUILTIN_IS_CLASS
#endif
// CONSTRUCTORS ========================================================================================================
// Difficult and Inconsistent without intrinsics

View File

@@ -35,11 +35,12 @@
#include <fennec/platform/interface/fwd.h>
#include <fennec/platform/interface/window.h>
#include <fennec/rtti/enable.h>
#include <fennec/rtti/type_registry.h>
namespace fennec
{
class display_server {
class display_server : public type_registry<display_server, platform*> {
// Typedefs/Constants/Enums ============================================================================================
public:
@@ -90,19 +91,29 @@ enum feature_ : uint32_t {
: platform(p) {
}
virtual ~display_server() = default;
virtual ~display_server() {
}
bool has_feature(uint32_t feature) const {
return _features.test(feature);
return features.test(feature);
}
virtual window* create_window(const window::config& conf) = 0;
window* get_window(size_t id) {
return id == window::nullid ? nullptr : windows[id];
}
private:
featureset_t _features;
virtual void connect() = 0;
virtual void disconnect() = 0;
virtual bool connected() const = 0;
protected:
featureset_t features;
object_pool<window*> windows;
FENNEC_RTTI_CLASS_ENABLE() {

View File

@@ -19,12 +19,9 @@
#ifndef FENNEC_PLATFORM_INTERFACE_PLATFORM_H
#define FENNEC_PLATFORM_INTERFACE_PLATFORM_H
#include <fennec/containers/list.h>
#include <fennec/containers/sequence.h>
#include <fennec/platform/interface/display_server.h>
#include <fennec/string/cstring.h>
#include <fennec/string/string.h>
#include <fennec/platform/interface/fwd.h>
#include <fennec/platform/interface/window.h>
#include <fennec/rtti/enable.h>
#include <fennec/rtti/singleton.h>
#include <fennec/rtti/detail/_this_t.h>
@@ -63,7 +60,7 @@
namespace fennec
{
class platform : singleton<platform*> {
class platform : public singleton<platform*> {
public:
using shared_object = struct shared_object;
using symbol = void*;
@@ -78,10 +75,14 @@ public:
virtual symbol find_symbol(shared_object* obj, const cstring& name) = 0;
virtual void initialize(); // Initialize Drivers and Contexts
virtual void shutdown(); // Close Drivers and Contexts
virtual void shutdown(); // Close Drivers and Contexts
display_server* get_display_server() { return display.get(); }
protected:
unique_ptr<display_server> display;
FENNEC_RTTI_CLASS_ENABLE() {
}
};

View File

@@ -31,10 +31,10 @@
#ifndef FENNEC_PLATFORM_INTERFACE_WINDOW_H
#define FENNEC_PLATFORM_INTERFACE_WINDOW_H
#include <fennec/lang/types.h>
#include <fennec/platform/interface/fwd.h>
#include <fennec/math/vector.h>
#include <fennec/string/string.h>
#include <fennec/containers/bitfield.h>
#include <fennec/renderers/interface/gfxcontext.h>
namespace fennec
{
@@ -42,7 +42,23 @@ namespace fennec
class window {
// Structures & Typedefs ===============================================================================================
public:
enum flag_ {
static constexpr size_t nullid = -1;
enum mode_ : uint8_t {
mode_windowed = 0,
mode_minimized,
mode_maximized,
mode_fullscreen,
mode_exclusive_fullscreen,
};
enum vsync_ : uint8_t {
vsync_disabled = 0,
vsync_enabled,
vsync_adaptive
};
enum flag_ : uint8_t {
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
@@ -53,6 +69,7 @@ public:
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_running, // Window is running
flag_no_focus, // Window can be focused
flag_count
@@ -67,12 +84,64 @@ public:
struct config {
string title;
flags_t flags;
uint8_t mode;
size_t parent;
ivec2 size;
accessibility accessibility;
};
window(display_server* server, size_t id, const config& conf)
: server(server), id(id)
, cfg(conf), root(nullptr) {
cfg.flags.clear(flag_visible);
}
virtual ~window() = default;
size_t get_id() const { return id; }
size_t get_parent_id() const { return cfg.parent; }
window* get_parent() const;
bool get_flag(uint8_t flag) const { return cfg.flags.test(flag); }
bool is_always_on_top() const { return get_flag(flag_always_on_top); }
bool is_borderless() const { return get_flag(flag_borderless); }
bool is_child() const { return get_flag(flag_child); }
bool has_decorations() const { return get_flag(flag_decorations); }
bool is_modal() const { return get_flag(flag_modal); }
bool is_passing_mouse() const { return get_flag(flag_pass_mouse); }
bool is_popup() const { return get_flag(flag_popup); }
bool is_resizable() const { return get_flag(flag_resizable); }
bool is_transparent() const { return get_flag(flag_transparent); }
bool is_visible() const { return get_flag(flag_visible); }
bool is_running() const { return get_flag(flag_running); }
bool is_no_focus() const { return get_flag(flag_no_focus); }
virtual bool set_flag(uint8_t flag, bool val) = 0;
bool set_always_on_top(bool val) { return set_flag(flag_always_on_top, val); }
bool set_borderless(bool val) { return set_flag(flag_borderless, val); }
bool set_decorations(bool val) { return set_flag(flag_decorations, val); }
bool set_modal(bool val) { return set_flag(flag_modal, val); }
bool set_passing_mouse(bool val) { return set_flag(flag_pass_mouse, val); }
bool set_popup(bool val) { return set_flag(flag_popup, val); }
bool set_resizable(bool val) { return set_flag(flag_resizable, val); }
bool set_transparent(bool val) { return set_flag(flag_transparent, val); }
bool set_no_focus(bool val) { return set_flag(flag_no_focus, val); }
virtual void show() = 0;
virtual void hide() = 0;
virtual void dispatch() = 0;
protected:
display_server* const server;
const size_t id;
config cfg;
window* root;
};
}

View File

@@ -17,7 +17,7 @@
// =====================================================================================================================
///
/// \file display_server.h
/// \file wayland_server.h
/// \brief
///
///
@@ -28,25 +28,59 @@
///
///
#ifndef FENNEC_PLATFORM_LINUX_WAYLAND_DISPLAY_SERVER_H
#define FENNEC_PLATFORM_LINUX_WAYLAND_DISPLAY_SERVER_H
#ifndef FENNEC_PLATFORM_LINUX_WAYLAND_SERVER_H
#define FENNEC_PLATFORM_LINUX_WAYLAND_SERVER_H
#include <fennec/platform/interface/display_server.h>
// forward defs to avoid flooding global namespace
struct wl_display;
struct wl_shm;
struct wl_compositor;
struct wl_registry;
struct wl_seat;
struct wp_viewporter;
struct xdg_wm_base;
namespace fennec
{
class wayland_server : display_server {
class wayland_server : public display_server {
public:
explicit wayland_server(fennec::platform* p)
: display_server(p) {
}
explicit wayland_server(fennec::platform* p);
~wayland_server() override;
void connect() override;
void disconnect() override;
bool connected() const override;
window* create_window(const window::config& conf) override;
private:
FENNEC_RTTI_CLASS_ENABLE(display_server) {
wl_display* display;
wl_registry* registry;
wl_compositor* compositor;
xdg_wm_base* xdg;
wl_seat* seat;
bool fifo;
static void listen_global(void*, wl_registry*, uint32_t, const char*, uint32_t);
static void listen_global_remove(void*, wl_registry*, uint32_t);
static void listen_seat_capabilities(void*, wl_seat*, uint32_t);
static void listen_seat_name(void*, wl_seat*, const char*);
static void listen_xdg_ping(void*, xdg_wm_base*, uint32_t);
FENNEC_RTTI_CLASS_ENABLE(display_server) {
display_server::register_type<wayland_server>(1);
}
friend class wayland_window;
};
}
#endif // FENNEC_PLATFORM_LINUX_WAYLAND_DISPLAY_SERVER_H
#endif // FENNEC_PLATFORM_LINUX_WAYLAND_SERVER_H

View File

@@ -0,0 +1,82 @@
// =====================================================================================================================
// 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 wayland_window.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_LINUX_WAYLAND_WINDOW_H
#define FENNEC_PLATFORM_LINUX_WAYLAND_WINDOW_H
#include <fennec/platform/interface/window.h>
struct wl_array;
struct wl_callback;
struct wl_output;
struct wl_surface;
struct xdg_surface;
struct xdg_toplevel;
namespace fennec
{
class wayland_window : public window {
public:
wayland_window(display_server* server, uint32_t id, const config& cfg);
~wayland_window();
void show() override;
void hide() override;
void dispatch() override;
bool set_flag(uint8_t flag, bool val) override;
private:
wl_surface* surface;
xdg_surface* xdgsurface;
xdg_toplevel* xdgtoplevel;
wl_callback* frame_callback;
static void listen_enter(void*, wl_surface*, wl_output*);
static void listen_leave(void*, wl_surface*, wl_output*);
static void listen_preferred_buffer_scale(void*, wl_surface*, int32_t);
static void listen_preferred_buffer_transform(void*, wl_surface*, uint32_t);
static void listen_frame_callback(void*, wl_callback*, uint32_t);
static void listen_xdg_surface_configure(void*, xdg_surface*, uint32_t);
static void listen_xdg_toplevel_configure(void*, xdg_toplevel*, int32_t, int32_t, wl_array*);
static void listen_xdg_toplevel_configure_bounds(void*, xdg_toplevel*, int32_t, int32_t);
static void listen_xdg_toplevel_close(void*, xdg_toplevel*);
static void listen_xdg_toplevel_capabilities(void*, xdg_toplevel*, wl_array*);
};
}
#endif // FENNEC_PLATFORM_LINUX_WAYLAND_WINDOW_H

View File

@@ -118,7 +118,7 @@ struct type {
static type get_from_instance(TypeT* t) { return type(t); }
private:
const type_data* const _data;
const type_data* _data;
template<typename TypeT>
type(TypeT*) : _data(type_storage::get_data<TypeT>()) {
@@ -126,6 +126,12 @@ private:
public:
type(type_data* d) : _data(d) { }
type(const type& t) = default;
type(type&& t) noexcept = default;
type& operator=(const type&) = default;
type& operator=(type&&) noexcept = default;
};

View File

@@ -39,12 +39,46 @@ namespace fennec
template<typename BaseT, typename...ArgsT>
class type_registry {
public:
using ctor_t = BaseT (*)(ArgsT&&...);
using ctor_t = BaseT* (*)(ArgsT&&...);
struct entry {
size_t priority;
type type;
ctor_t ctor;
entry()
: priority(0)
, type(nullptr)
, ctor(nullptr) {
}
entry(const entry& e)
: priority(e.priority)
, type(e.type)
, ctor(e.ctor) {
}
entry(entry&& e) noexcept
: priority(e.priority)
, type(e.type)
, ctor(e.ctor) {
}
~entry() {
}
entry& operator=(const entry& e) {
priority = e.priority;
type = e.type;
ctor = e.ctor;
return *this;
}
entry& operator=(entry&&) noexcept = default;
entry(size_t p, fennec::type type, ctor_t ctor)
: priority(p), type(type), ctor(ctor) {
}
};
struct compare {
@@ -60,7 +94,7 @@ public:
_global_list().emplace(
priority,
type::get<T>(),
_constructor_helper<ArgsT...>
_constructor_helper<T>
);
}