- Separated Platform and Compiler Dependent Behaviour into CMake scripts

- Implemented Basic Platform Interfaces
 - Implemented partial Linux platform and Wayland Display.
 - Implemented Dependencies for the above
   - map
     - set
       - optional
     - pair

TODO: threading
This commit is contained in:
2025-07-22 00:59:41 -04:00
parent ab1c7d94be
commit 73333b4c67
86 changed files with 3257 additions and 203 deletions

View File

@@ -0,0 +1,34 @@
// =====================================================================================================================
// 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/>.
// =====================================================================================================================
#include <cstdlib>
#include <fennec/platform/interface/platform.h>
namespace fennec
{
string platform::get_environment_variable(const cstring& var) {
const char* val = getenv(var);
return string(val, strlen(val));
}
platform::platform(user t) {
_config.type = t;
}
}

View File

@@ -0,0 +1,36 @@
// =====================================================================================================================
// 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/>.
// =====================================================================================================================
#include <fennec/platform/interface/window.h>
namespace fennec
{
window::window(display* display, window* parent, bool modal)
: _display(display)
, _parent(parent)
, _config() {
bool child = parent != nullptr;
assert(!modal || child, "Attempted to create non-child modal window.");
_config.flags |= child ? flags_child : flags_none;
_config.flags |= modal ? flags_modal : flags_none;
}
}

View File

@@ -0,0 +1,98 @@
// =====================================================================================================================
// 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/>.
// =====================================================================================================================
#include <fennec/platform/linux/platform.h>
#include <dlfcn.h>
#ifdef FENNEC_LIB_WAYLAND
#include <fennec/platform/linux/wayland/lib/dyn.h>
#include <fennec/platform/linux/wayland/display.h>
#endif
namespace fennec
{
using namespace wayland;
linux_platform::linux_platform(user _type)
: platform(_type)
, _display_driver(display_none) {
switch (_type) {
case user::client: {
_runtime_client_checks();
return;
}
case user::server: {
_runtime_server_checks();
}
}
}
linux_platform::~linux_platform() {
}
shared_object* linux_platform::load_object(const cstring& file) {
void* handle = dlopen(file, RTLD_NOW | RTLD_LOCAL);
const char* load_error = dlerror();
assert(handle != nullptr, load_error);
return static_cast<shared_object*>(handle);
}
void linux_platform::unload_object(shared_object* obj) {
if (obj) {
dlclose(obj);
}
}
platform::function_pointer linux_platform::find_symbol(shared_object* hndl, const cstring& name) {
string _name = name;
void* symbol = dlsym(hndl, _name);
if (symbol == nullptr) {
_name = '_' + _name;
symbol = dlsym(hndl, _name);
}
return (function_pointer)symbol;
}
display* linux_platform::get_display() {
return _display;
}
void linux_platform::_runtime_client_checks() {
#ifdef FENNEC_LIB_WAYLAND
if (wayland::load_symbols(this)) {
_display_driver = display_wayland;
_display = new wayland_display(this);
wayland::unload_symbols(this); // Doesn't actually unload symbols, just resets ref counter to only consider
// the created display
}
#endif
assertf(_display != nullptr, "failed to find suitable display driver");
}
void linux_platform::_find_display_driver() {
}
void linux_platform::_runtime_server_checks() {
}
}

View File

@@ -0,0 +1,58 @@
// =====================================================================================================================
// 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/>.
// =====================================================================================================================
#include <fennec/platform/linux/wayland/display.h>
#include <fennec/platform/linux/wayland/lib/sym_def.h>
#include <fennec/platform/linux/wayland/lib/dyn.h>
namespace fennec
{
namespace wayland
{
wayland_display::wayland_display(linux_platform* platform)
: display()
, _handle()
, _platform(platform) {
load_symbols(_platform);
_handle = wl_display_connect(nullptr);
}
wayland_display::wayland_display(linux_platform* platform, const cstring& drv)
: display()
, _handle()
, _platform(platform) {
load_symbols(_platform);
_handle = wl_display_connect(nullptr);
}
wayland_display::~wayland_display() {
wl_display_disconnect(_handle);
unload_symbols(_platform);
_handle = nullptr;
_platform = nullptr;
}
bool wayland_display::connected() const {
return _handle != nullptr;
}
}
}

View File

@@ -0,0 +1,69 @@
// =====================================================================================================================
// 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/>.
// =====================================================================================================================
#include <fennec/platform/linux/wayland/lib/sym_def.h>
#include <fennec/platform/linux/wayland/lib/dyn.h>
namespace fennec
{
namespace wayland
{
using shared_lib = platform::shared_lib;
static int _load_count = 0;
// Create private variables
#define FENNEC_LIB(lib) static shared_lib _FENNEC_LIB_##lib = { nullptr, FENNEC_LIB_##lib };
#define FENNEC_SYMBOL(...)
#include <fennec/platform/linux/wayland/lib/sym.h>
bool load_symbols(linux_platform* platform) {
if (_load_count++ != 0) {
return true;
}
#define FENNEC_LIB(lib) _FENNEC_LIB_##lib._lib = platform->load_object(_FENNEC_LIB_##lib._name); \
FENNEC_HAS_LIB_##lib = _FENNEC_LIB_##lib._lib != nullptr; \
if(not FENNEC_HAS_LIB_##lib) { \
unload_symbols(platform); \
return false; \
} \
shared_lib& current_lib = _FENNEC_LIB_##lib;
#define FENNEC_SYMBOL(ret, fn, ...) fn = (sym_##fn)(platform->find_symbol(current_lib._lib, #fn));
#include <fennec/platform/linux/wayland/lib/sym.h>
return true;
}
void unload_symbols(linux_platform* platform) {
if (--_load_count != 0) {
return;
}
#define FENNEC_LIB(lib) platform->unload_object(_FENNEC_LIB_##lib._lib); \
_FENNEC_LIB_##lib._lib = nullptr;
#define FENNEC_SYMBOL(ret, fn, ...) fn = nullptr;
#include <fennec/platform/linux/wayland/lib/sym.h>
}
}
}