- More implementations and dependencies for Linux Wayland support
This commit is contained in:
@@ -29,6 +29,7 @@ set(CMAKE_C_STANDARD 23)
|
|||||||
set(FENNEC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
set(FENNEC_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
|
||||||
# include scripts
|
# include scripts
|
||||||
|
include("${FENNEC_SOURCE_DIR}/cmake/version.cmake")
|
||||||
include("${FENNEC_SOURCE_DIR}/cmake/platform.cmake")
|
include("${FENNEC_SOURCE_DIR}/cmake/platform.cmake")
|
||||||
include("${FENNEC_SOURCE_DIR}/cmake/build.cmake")
|
include("${FENNEC_SOURCE_DIR}/cmake/build.cmake")
|
||||||
include("${FENNEC_SOURCE_DIR}/cmake/compiler.cmake")
|
include("${FENNEC_SOURCE_DIR}/cmake/compiler.cmake")
|
||||||
@@ -60,10 +61,14 @@ add_library(fennec STATIC
|
|||||||
# CONTAINERS ===========================================================================================================
|
# CONTAINERS ===========================================================================================================
|
||||||
include/fennec/containers/array.h
|
include/fennec/containers/array.h
|
||||||
include/fennec/containers/dynarray.h
|
include/fennec/containers/dynarray.h
|
||||||
|
include/fennec/containers/list.h
|
||||||
include/fennec/containers/map.h
|
include/fennec/containers/map.h
|
||||||
include/fennec/containers/optional.h
|
include/fennec/containers/optional.h
|
||||||
include/fennec/containers/pair.h
|
include/fennec/containers/pair.h
|
||||||
include/fennec/containers/set.h
|
include/fennec/containers/set.h
|
||||||
|
include/fennec/containers/tuple.h
|
||||||
|
|
||||||
|
include/fennec/containers/detail/__tuple.h
|
||||||
|
|
||||||
|
|
||||||
# LANG =================================================================================================================
|
# LANG =================================================================================================================
|
||||||
@@ -79,9 +84,11 @@ add_library(fennec STATIC
|
|||||||
include/fennec/lang/numeric_transforms.h
|
include/fennec/lang/numeric_transforms.h
|
||||||
include/fennec/lang/sequences.h
|
include/fennec/lang/sequences.h
|
||||||
include/fennec/lang/type_identity.h
|
include/fennec/lang/type_identity.h
|
||||||
|
include/fennec/lang/type_operators.h
|
||||||
include/fennec/lang/type_sequences.h
|
include/fennec/lang/type_sequences.h
|
||||||
include/fennec/lang/type_traits.h
|
include/fennec/lang/type_traits.h
|
||||||
include/fennec/lang/type_transforms.h
|
include/fennec/lang/type_transforms.h
|
||||||
|
include/fennec/lang/typeuuid.h
|
||||||
include/fennec/lang/types.h
|
include/fennec/lang/types.h
|
||||||
include/fennec/lang/utility.h
|
include/fennec/lang/utility.h
|
||||||
include/fennec/lang/integer.h
|
include/fennec/lang/integer.h
|
||||||
@@ -93,6 +100,7 @@ add_library(fennec STATIC
|
|||||||
include/fennec/lang/detail/__type_traits.h
|
include/fennec/lang/detail/__type_traits.h
|
||||||
include/fennec/lang/detail/__type_transforms.h
|
include/fennec/lang/detail/__type_transforms.h
|
||||||
include/fennec/lang/detail/__type_sequences.h
|
include/fennec/lang/detail/__type_sequences.h
|
||||||
|
include/fennec/lang/detail/__typeuuid.h
|
||||||
|
|
||||||
include/fennec/lang/assert.h source/lang/assert.cpp
|
include/fennec/lang/assert.h source/lang/assert.cpp
|
||||||
|
|
||||||
@@ -165,17 +173,19 @@ add_library(fennec STATIC
|
|||||||
include/fennec/platform/interface/fwd.h
|
include/fennec/platform/interface/fwd.h
|
||||||
|
|
||||||
include/fennec/platform/interface/dialog.h
|
include/fennec/platform/interface/dialog.h
|
||||||
include/fennec/platform/interface/display.h
|
include/fennec/platform/interface/displaydev.h source/platform/interface/displaydev.cpp
|
||||||
include/fennec/platform/interface/window.h source/platform/interface/window.cpp
|
include/fennec/platform/interface/gfxcontext.h source/platform/interface/gfxcontext.cpp
|
||||||
include/fennec/platform/interface/platform.h source/platform/interface/platform.cpp
|
include/fennec/platform/interface/gfxsurface.h source/platform/interface/gfxsurface.cpp
|
||||||
|
include/fennec/platform/interface/platform.h source/platform/interface/platform.cpp
|
||||||
|
include/fennec/platform/interface/window.h source/platform/interface/window.cpp
|
||||||
|
|
||||||
${FENNEC_EXTRA_SOURCES}
|
${FENNEC_EXTRA_SOURCES}
|
||||||
include/fennec/lang/type_operators.h
|
include/fennec/platform/interface/inputdevice.h
|
||||||
include/fennec/containers/tuple.h
|
include/fennec/core/event.h
|
||||||
include/fennec/containers/detail/__tuple.h
|
source/core/event.cpp
|
||||||
include/fennec/platform/linux/wayland/window.h
|
include/fennec/concurrency/thread.h
|
||||||
include/fennec/containers/list.h
|
include/fennec/concurrency/mutex.h
|
||||||
|
include/fennec/concurrency/atomic.h
|
||||||
)
|
)
|
||||||
|
|
||||||
add_dependencies(fennec metaprogramming)
|
add_dependencies(fennec metaprogramming)
|
||||||
|
|||||||
@@ -162,7 +162,6 @@ management would be used.
|
|||||||
Platform support will be implemented in the following order:
|
Platform support will be implemented in the following order:
|
||||||
- Linux/BSD
|
- Linux/BSD
|
||||||
- Wayland
|
- Wayland
|
||||||
- XKB
|
|
||||||
- OpenGL (EGL)
|
- OpenGL (EGL)
|
||||||
- PulseAudio
|
- PulseAudio
|
||||||
- Vulkan
|
- Vulkan
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
# ======================================================================================================================
|
# ======================================================================================================================
|
||||||
|
|
||||||
|
# this script handles functionality related to the build process and its info
|
||||||
|
|
||||||
string(TOLOWER ${CMAKE_BUILD_TYPE} FENNEC_BUILD_NAME)
|
string(TOLOWER ${CMAKE_BUILD_TYPE} FENNEC_BUILD_NAME)
|
||||||
message(STATUS "Build: ${FENNEC_BUILD_NAME}")
|
message(STATUS "Build: ${FENNEC_BUILD_NAME}")
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
# ======================================================================================================================
|
# ======================================================================================================================
|
||||||
|
|
||||||
|
# this script finds the compiler being used
|
||||||
|
|
||||||
if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
|
if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
|
||||||
set(FENNEC_COMPILER "GCC")
|
set(FENNEC_COMPILER "GCC")
|
||||||
include("${FENNEC_SOURCE_DIR}/cmake/gcc.cmake")
|
include("${FENNEC_SOURCE_DIR}/cmake/gcc.cmake")
|
||||||
|
|||||||
35
cmake/default_user.cmake
Normal file
35
cmake/default_user.cmake
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
# ======================================================================================================================
|
||||||
|
# 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/>.
|
||||||
|
# ======================================================================================================================
|
||||||
|
|
||||||
|
# sets up cmake variables for client vs server
|
||||||
|
if(FENNEC_USER_CLIENT)
|
||||||
|
set(FENNEC_USER_CLIENT 1)
|
||||||
|
set(FENNEC_USER_SERVER 0)
|
||||||
|
|
||||||
|
list(APPEND FENNEC_COMPILE_DEFINITIONS FENNEC_USER_CLIENT=1)
|
||||||
|
elseif(FENNEC_USER_SERVER)
|
||||||
|
set(FENNEC_USER_CLIENT 0)
|
||||||
|
set(FENNEC_USER_SERVER 1)
|
||||||
|
|
||||||
|
list(APPEND FENNEC_COMPILE_DEFINITIONS FENNEC_USER_SERVER=1)
|
||||||
|
else()
|
||||||
|
set(FENNEC_USER_CLIENT 1)
|
||||||
|
set(FENNEC_USER_SERVER 0)
|
||||||
|
|
||||||
|
list(APPEND FENNEC_COMPILE_DEFINITIONS FENNEC_USER_CLIENT=1)
|
||||||
|
endif()
|
||||||
@@ -16,8 +16,10 @@
|
|||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
# ======================================================================================================================
|
# ======================================================================================================================
|
||||||
|
|
||||||
|
# this script sets flags and variables for gnu and gnu-like compilers
|
||||||
|
|
||||||
add_compile_options("-mxsave" "-Wall" "-Wextra" "-pedantic" "-Werror")
|
add_compile_options("-mxsave" "-Wall" "-Wextra" "-pedantic" "-Werror")
|
||||||
|
|
||||||
set(FENNEC_PRIVATE_LINK_OPTIONS "-nostdlib" "-fno-exceptions" "-fno-rtti" "-fdiagnostics-all-candidates")
|
set(FENNEC_PRIVATE_LINK_OPTIONS "-nostdlib" "-fno-exceptions" "-fno-rtti" "-fdiagnostics-all-candidates")
|
||||||
|
|
||||||
list(APPEND FENNEC_COMPILE_DEFINITIONS FENNEC_COMPILER_GCC=1)
|
list(APPEND FENNEC_COMPILE_DEFINITIONS FENNEC_COMPILER_GCC=1 FENNEC_NO_INLINE=[[gnu::noinline]])
|
||||||
@@ -16,6 +16,7 @@
|
|||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
# ======================================================================================================================
|
# ======================================================================================================================
|
||||||
|
|
||||||
|
# this script finds and loads libraries related to the Linux operating system. It also sets platform specific variables.
|
||||||
|
|
||||||
macro(fennec_check_platform)
|
macro(fennec_check_platform)
|
||||||
# unix
|
# unix
|
||||||
@@ -32,9 +33,10 @@ macro(fennec_check_platform)
|
|||||||
include/fennec/platform/linux/platform.h source/platform/linux/platform.cpp
|
include/fennec/platform/linux/platform.h source/platform/linux/platform.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# includes
|
if(FENNEC_USER_CLIENT)
|
||||||
include("${FENNEC_SOURCE_DIR}/cmake/wayland.cmake")
|
include("${FENNEC_SOURCE_DIR}/cmake/wayland.cmake")
|
||||||
|
|
||||||
|
fennec_check_wayland()
|
||||||
|
endif()
|
||||||
|
|
||||||
# tests
|
|
||||||
fennec_check_wayland()
|
|
||||||
endmacro()
|
endmacro()
|
||||||
48
cmake/opengl.cmake
Normal file
48
cmake/opengl.cmake
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
# ======================================================================================================================
|
||||||
|
# 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/>.
|
||||||
|
# ======================================================================================================================
|
||||||
|
|
||||||
|
find_package(OpenGL)
|
||||||
|
|
||||||
|
if(TARGET OpenGL::GL) # Core OpenGL Desktop Profile
|
||||||
|
list(APPEND FENNEC_LINK_LIBRARIES OpenGL::OpenGL)
|
||||||
|
list(APPEND FENNEC_COMPILE_DEFINITIONS FENNEC_GRAPHICS_OPENGL=1)
|
||||||
|
|
||||||
|
elseif(TARGET OpenGL::GLES3) # OpenGL for Embedded Systems 3
|
||||||
|
list(APPEND FENNEC_LINK_LIBRARIES OpenGL::GLES3)
|
||||||
|
list(APPEND FENNEC_COMPILE_DEFINITIONS FENNEC_GRAPHICS_GLES3=1)
|
||||||
|
|
||||||
|
elseif (TARGET OpenGL::GLES2) # OpenGL for Embedded Systems 2
|
||||||
|
list(APPEND FENNEC_LINK_LIBRARIES OpenGL::GLES2)
|
||||||
|
list(APPEND FENNEC_COMPILE_DEFINITIONS FENNEC_GRAPHICS_GLES2=1)
|
||||||
|
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "No Suitable OpenGL implementation found.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(FENNEC_GRAPHICS_WANT_EGL)
|
||||||
|
if(NOT TARGET OpenGL::EGL)
|
||||||
|
message(FATAL_ERROR "EGL Library not found.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
list(APPEND FENNEC_LINK_LIBRARIES OpenGL::EGL)
|
||||||
|
list(APPEND FENNEC_COMPILE_DEFINITIONS FENNEC_GRAPHICS_EGL=1)
|
||||||
|
list(APPEND FENNEC_EXTRA_SOURCES
|
||||||
|
include/fennec/platform/opengl/egl/context.h
|
||||||
|
include/fennec/platform/opengl/egl/surface.h
|
||||||
|
)
|
||||||
|
endif()
|
||||||
@@ -16,10 +16,19 @@
|
|||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
# ======================================================================================================================
|
# ======================================================================================================================
|
||||||
|
|
||||||
|
# this script finds the operating system of the build environment
|
||||||
|
|
||||||
message(STATUS "OS: ${CMAKE_SYSTEM_NAME}")
|
message(STATUS "OS: ${CMAKE_SYSTEM_NAME}")
|
||||||
|
|
||||||
|
include("${FENNEC_SOURCE_DIR}/cmake/default_user.cmake")
|
||||||
|
|
||||||
# Check for Linux
|
# Check for Linux
|
||||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||||
set(FENNEC_PLATFORM "Linux")
|
set(FENNEC_PLATFORM "Linux")
|
||||||
include("${FENNEC_SOURCE_DIR}/cmake/linux.cmake")
|
include("${FENNEC_SOURCE_DIR}/cmake/linux.cmake")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
# Graphics APIs
|
||||||
|
if(FENNEC_USER_CLIENT)
|
||||||
|
include("${FENNEC_SOURCE_DIR}/cmake/opengl.cmake")
|
||||||
|
endif()
|
||||||
@@ -16,6 +16,8 @@
|
|||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
# ======================================================================================================================
|
# ======================================================================================================================
|
||||||
|
|
||||||
|
# generic unix functionality
|
||||||
|
|
||||||
# compile definitions
|
# compile definitions
|
||||||
list(APPEND FENNEC_COMPILE_DEFINITIONS
|
list(APPEND FENNEC_COMPILE_DEFINITIONS
|
||||||
FENNEC_PLATFORM_UNIX=1
|
FENNEC_PLATFORM_UNIX=1
|
||||||
|
|||||||
33
cmake/version.cmake
Normal file
33
cmake/version.cmake
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# ======================================================================================================================
|
||||||
|
# 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/>.
|
||||||
|
# ======================================================================================================================
|
||||||
|
|
||||||
|
# this script contains the main version
|
||||||
|
|
||||||
|
set(FENNEC_VERSION_MAJOR 0)
|
||||||
|
set(FENNEC_VERSION_MINOR 1)
|
||||||
|
set(FENNEC_VERSION_PATCH 0)
|
||||||
|
set(FENNEC_VERSION_STRING "${FENNEC_VERSION_MAJOR}.${FENNEC_VERSION_MINOR}.${FENNEC_VERSION_PATCH}")
|
||||||
|
math(EXPR FENNEC_VERSION_NUM "(${FENNEC_VERSION_MAJOR} << 16) | (${FENNEC_VERSION_MINOR} << 8) | ${FENNEC_VERSION_PATCH}")
|
||||||
|
|
||||||
|
list(APPEND FENNEC_COMPILE_DEFINITIONS
|
||||||
|
FENNEC_VERSION_MAJOR=${FENNEC_VERSION_MAJOR}
|
||||||
|
FENNEC_VERSION_MINOR=${FENNEC_VERSION_MINOR}
|
||||||
|
FENNEC_VERSION_PATCH=${FENNEC_VERSION_PATCH}
|
||||||
|
FENNEC_VERSION_STRING=${FENNEC_VERSION_STRING}
|
||||||
|
FENNEC_VERSION_NUM=${FENNEC_VERSION_NUM}
|
||||||
|
)
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
# ======================================================================================================================
|
# ======================================================================================================================
|
||||||
|
|
||||||
# https://gist.github.com/mariobadr/acc3c8adf4b4e722705be38c3deac59a
|
# https://gist.github.com/mariobadr/acc3c8adf4b4e722705be38c3deac59a
|
||||||
|
# this script finds libwayland and dependencies
|
||||||
|
|
||||||
macro(fennec_check_wayland)
|
macro(fennec_check_wayland)
|
||||||
set(WAYLAND_CLIENT_FOUND 0)
|
set(WAYLAND_CLIENT_FOUND 0)
|
||||||
@@ -25,39 +26,55 @@ macro(fennec_check_wayland)
|
|||||||
WAYLAND_CLIENT_INCLUDE_DIR
|
WAYLAND_CLIENT_INCLUDE_DIR
|
||||||
NAMES wayland-client.h
|
NAMES wayland-client.h
|
||||||
)
|
)
|
||||||
|
|
||||||
find_library(
|
find_library(
|
||||||
WAYLAND_CLIENT_LIBRARY
|
WAYLAND_CLIENT_LIBRARY
|
||||||
NAMES wayland-client libwayland-client
|
NAMES wayland-client libwayland-client
|
||||||
)
|
)
|
||||||
get_filename_component(
|
|
||||||
WAYLAND_CLIENT_LIBRARY
|
# EGL is required
|
||||||
${WAYLAND_CLIENT_LIBRARY}
|
find_path(
|
||||||
NAME
|
WAYLAND_EGL_INCLUDE_DIR
|
||||||
|
NAMES wayland-egl.h
|
||||||
|
)
|
||||||
|
find_library(
|
||||||
|
WAYLAND_EGL_LIBRARY
|
||||||
|
NAMES wayland-egl libwayland-egl
|
||||||
)
|
)
|
||||||
|
|
||||||
if(WAYLAND_CLIENT_INCLUDE_DIR AND WAYLAND_CLIENT_LIBRARY)
|
if( (WAYLAND_CLIENT_INCLUDE_DIR AND WAYLAND_CLIENT_LIBRARY)
|
||||||
set(WAYLAND_CLIENT_FOUND 1)
|
AND (WAYLAND_EGL_INCLUDE_DIR AND WAYLAND_EGL_LIBRARY))
|
||||||
add_library(wayland::client UNKNOWN IMPORTED)
|
get_filename_component(
|
||||||
|
WAYLAND_CLIENT_LIBRARY
|
||||||
set_target_properties(
|
${WAYLAND_CLIENT_LIBRARY}
|
||||||
wayland::client PROPERTIES
|
NAME
|
||||||
INTERFACE_INCLUDE_DIRECTORIES "${WAYLAND_CLIENT_INCLUDE_DIR}"
|
|
||||||
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
|
|
||||||
IMPORTED_LOCATION "${WAYLAND_CLIENT_LIBRARY}"
|
|
||||||
)
|
)
|
||||||
|
get_filename_component(
|
||||||
|
WAYLAND_EGL_LIBRARY
|
||||||
|
${WAYLAND_EGL_LIBRARY}
|
||||||
|
NAME
|
||||||
|
)
|
||||||
|
|
||||||
|
set(WAYLAND_CLIENT_FOUND 1)
|
||||||
|
set(WAYLAND_EGL_FOUND 1)
|
||||||
|
set(FENNEC_GRAPHICS_WANT_EGL 1)
|
||||||
|
|
||||||
list(APPEND FENNEC_EXTRA_SOURCES
|
list(APPEND FENNEC_EXTRA_SOURCES
|
||||||
# Dynamic Library Files
|
# Dynamic Library Files
|
||||||
include/fennec/platform/linux/wayland/lib/fwd.h
|
include/fennec/platform/linux/wayland/lib/fwd.h
|
||||||
include/fennec/platform/linux/wayland/lib/sym.h
|
include/fennec/platform/linux/wayland/lib/sym.h
|
||||||
include/fennec/platform/linux/wayland/lib/sym_def.h
|
include/fennec/platform/linux/wayland/lib/wayland-client.h
|
||||||
|
include/fennec/platform/linux/wayland/lib/wayland-util.h
|
||||||
include/fennec/platform/linux/wayland/lib/dyn.h source/platform/linux/wayland/lib/dyn.cpp
|
include/fennec/platform/linux/wayland/lib/dyn.h source/platform/linux/wayland/lib/dyn.cpp
|
||||||
|
|
||||||
# Fennec Files
|
# Fennec Files
|
||||||
include/fennec/platform/linux/wayland/display.h source/platform/linux/wayland/display.cpp
|
include/fennec/platform/linux/wayland/displaydev.h source/platform/linux/wayland/displaydev.cpp
|
||||||
|
include/fennec/platform/linux/wayland/window.h source/platform/linux/wayland/window.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
list(APPEND FENNEC_COMPILE_DEFINITIONS FENNEC_LIB_WAYLAND="${WAYLAND_CLIENT_LIBRARY}")
|
list(APPEND FENNEC_COMPILE_DEFINITIONS
|
||||||
|
FENNEC_HAS_WAYLAND=1
|
||||||
|
FENNEC_LIB_WAYLAND="${WAYLAND_CLIENT_LIBRARY}"
|
||||||
|
FENNEC_LIB_WAYLAND_EGL="${WAYLAND_EGL_LIBRARY}"
|
||||||
|
)
|
||||||
endif()
|
endif()
|
||||||
endmacro()
|
endmacro()
|
||||||
@@ -48,7 +48,7 @@ PROJECT_NAME = fennec
|
|||||||
# could be handy for archiving the generated documentation or if some version
|
# could be handy for archiving the generated documentation or if some version
|
||||||
# control system is used.
|
# control system is used.
|
||||||
|
|
||||||
PROJECT_NUMBER = 1.0.2
|
PROJECT_NUMBER =
|
||||||
|
|
||||||
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
# Using the PROJECT_BRIEF tag one can provide an optional one line description
|
||||||
# for a project that appears at the top of each page and should give viewer a
|
# for a project that appears at the top of each page and should give viewer a
|
||||||
|
|||||||
22
include/fennec/concurrency/atomic.h
Normal file
22
include/fennec/concurrency/atomic.h
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
// =====================================================================================================================
|
||||||
|
// 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/>.
|
||||||
|
// =====================================================================================================================
|
||||||
|
|
||||||
|
#ifndef FENNEC_CONCURRENCY_ATOMIC_H
|
||||||
|
#define FENNEC_CONCURRENCY_ATOMIC_H
|
||||||
|
|
||||||
|
#endif // FENNEC_CONCURRENCY_ATOMIC_H
|
||||||
22
include/fennec/concurrency/mutex.h
Normal file
22
include/fennec/concurrency/mutex.h
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
// =====================================================================================================================
|
||||||
|
// 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/>.
|
||||||
|
// =====================================================================================================================
|
||||||
|
|
||||||
|
#ifndef FENNEC_CONCURRENCY_MUTEX_H
|
||||||
|
#define FENNEC_CONCURRENCY_MUTEX_H
|
||||||
|
|
||||||
|
#endif // FENNEC_CONCURRENCY_MUTEX_H
|
||||||
22
include/fennec/concurrency/thread.h
Normal file
22
include/fennec/concurrency/thread.h
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
// =====================================================================================================================
|
||||||
|
// 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/>.
|
||||||
|
// =====================================================================================================================
|
||||||
|
|
||||||
|
#ifndef FENNEC_CONCURRENCY_THREAD_H
|
||||||
|
#define FENNEC_CONCURRENCY_THREAD_H
|
||||||
|
|
||||||
|
#endif // FENNEC_CONCURRENCY_THREAD_H
|
||||||
@@ -42,7 +42,9 @@ namespace fennec
|
|||||||
///
|
///
|
||||||
/// \brief wrapper for fixed size arrays
|
/// \brief wrapper for fixed size arrays
|
||||||
///
|
///
|
||||||
/// \details
|
/// \details | | |
|
||||||
|
/// |-|-|
|
||||||
|
/// | | |
|
||||||
/// \tparam ValueT value type
|
/// \tparam ValueT value type
|
||||||
/// \tparam ElemV number of elements
|
/// \tparam ElemV number of elements
|
||||||
template<typename ValueT, size_t ElemV>
|
template<typename ValueT, size_t ElemV>
|
||||||
@@ -78,6 +80,12 @@ struct array
|
|||||||
return elements[i];
|
return elements[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr ValueT* begin() { return elements; }
|
||||||
|
constexpr ValueT* end() { return elements + ElemV; }
|
||||||
|
|
||||||
|
constexpr const ValueT* begin() const { return elements; }
|
||||||
|
constexpr const ValueT* end() const { return elements + ElemV; }
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -39,8 +39,7 @@ namespace fennec
|
|||||||
{
|
{
|
||||||
|
|
||||||
template<class TypeT, class Alloc = allocator<TypeT>>
|
template<class TypeT, class Alloc = allocator<TypeT>>
|
||||||
class dynarray
|
class dynarray {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
using element_t = TypeT;
|
using element_t = TypeT;
|
||||||
using alloc_t = Alloc;
|
using alloc_t = Alloc;
|
||||||
@@ -95,6 +94,8 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr dynarray(size_t n, TypeT&&) = delete;
|
||||||
|
|
||||||
template<typename...ArgsT>
|
template<typename...ArgsT>
|
||||||
constexpr dynarray(size_t n, ArgsT&&...args) {
|
constexpr dynarray(size_t n, ArgsT&&...args) {
|
||||||
element_t* addr = _alloc.data();
|
element_t* addr = _alloc.data();
|
||||||
@@ -130,6 +131,12 @@ public:
|
|||||||
assertd(i < _size, "Array Out of Bounds"); return _alloc.data()[i];
|
assertd(i < _size, "Array Out of Bounds"); return _alloc.data()[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr TypeT* begin() { return _alloc.data(); }
|
||||||
|
constexpr TypeT* end() { return begin() + _size; }
|
||||||
|
|
||||||
|
constexpr const TypeT* begin() const { return _alloc; }
|
||||||
|
constexpr const TypeT* end() const { return begin() + _size; }
|
||||||
|
|
||||||
constexpr TypeT& back() {
|
constexpr TypeT& back() {
|
||||||
return this->operator[](size() - 1);
|
return this->operator[](size() - 1);
|
||||||
}
|
}
|
||||||
@@ -138,26 +145,6 @@ public:
|
|||||||
return this->operator[](size() - 1);
|
return this->operator[](size() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr void insert(size_t i, const TypeT& val) {
|
|
||||||
|
|
||||||
// Grow if the size has reached the capacity of the allocation
|
|
||||||
if(_size == capacity()) {
|
|
||||||
_grow();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move the data if we are not inserting at the end of the array
|
|
||||||
if((i = min(i, _size)) < _size) {
|
|
||||||
fennec::memmove(
|
|
||||||
_alloc.data() + i
|
|
||||||
, _alloc.data() + i + 1
|
|
||||||
, (_size - i) * sizeof(TypeT));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Insert the element
|
|
||||||
fennec::construct(_alloc.data() + i, val);
|
|
||||||
++_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr void insert(size_t i, TypeT&& val) {
|
constexpr void insert(size_t i, TypeT&& val) {
|
||||||
|
|
||||||
// Grow if the size has reached the capacity of the allocation
|
// Grow if the size has reached the capacity of the allocation
|
||||||
@@ -168,8 +155,8 @@ public:
|
|||||||
// Move the data if we are not inserting at the end of the array
|
// Move the data if we are not inserting at the end of the array
|
||||||
if((i = min(i, _size)) < _size) {
|
if((i = min(i, _size)) < _size) {
|
||||||
fennec::memmove(
|
fennec::memmove(
|
||||||
_alloc.data() + i + 1
|
(void*)(_alloc.data() + i + 1)
|
||||||
, _alloc.data() + i
|
, (void*)(_alloc.data() + i)
|
||||||
, (_size - i) * sizeof(TypeT));
|
, (_size - i) * sizeof(TypeT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,6 +165,26 @@ public:
|
|||||||
++_size;
|
++_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr void insert(size_t i, const TypeT& val) {
|
||||||
|
|
||||||
|
// Grow if the size has reached the capacity of the allocation
|
||||||
|
if(_size == capacity()) {
|
||||||
|
_grow();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move the data if we are not inserting at the end of the array
|
||||||
|
if((i = min(i, _size)) < _size) {
|
||||||
|
fennec::memmove(
|
||||||
|
(void*)(_alloc.data() + i)
|
||||||
|
, (void*)(_alloc.data() + i + 1)
|
||||||
|
, (_size - i) * sizeof(TypeT));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert the element
|
||||||
|
fennec::construct(_alloc.data() + i, val);
|
||||||
|
++_size;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename...ArgsT>
|
template<typename...ArgsT>
|
||||||
constexpr void emplace(size_t i, ArgsT&&...args) {
|
constexpr void emplace(size_t i, ArgsT&&...args) {
|
||||||
|
|
||||||
@@ -189,8 +196,8 @@ public:
|
|||||||
// Move the data if we are not inserting at the end of the array
|
// Move the data if we are not inserting at the end of the array
|
||||||
if((i = min(i, _size)) < _size) {
|
if((i = min(i, _size)) < _size) {
|
||||||
fennec::memmove(
|
fennec::memmove(
|
||||||
_alloc.data() + i
|
(void*)(_alloc.data() + i)
|
||||||
, _alloc.data() + i + 1
|
, (void*)(_alloc.data() + i + 1)
|
||||||
, (_size - i) * sizeof(TypeT));
|
, (_size - i) * sizeof(TypeT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,7 +215,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
constexpr void pop_back() {
|
constexpr void pop_back() {
|
||||||
_alloc[_size--].~TypeT();
|
fennec::destruct(&_alloc[_size--]);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename...ArgsT>
|
template<typename...ArgsT>
|
||||||
@@ -218,6 +225,15 @@ public:
|
|||||||
|
|
||||||
constexpr void resize(size_t n) {
|
constexpr void resize(size_t n) {
|
||||||
_alloc.reallocate(n);
|
_alloc.reallocate(n);
|
||||||
|
|
||||||
|
if (_size < n) {
|
||||||
|
_size = n;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (_size < n) {
|
||||||
|
emplace_back();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -20,9 +20,14 @@
|
|||||||
#define FENNEC_CONTAINERS_LIST_H
|
#define FENNEC_CONTAINERS_LIST_H
|
||||||
|
|
||||||
#include <fennec/containers/dynarray.h>
|
#include <fennec/containers/dynarray.h>
|
||||||
|
#include <fennec/containers/list.h>
|
||||||
#include <fennec/containers/optional.h>
|
#include <fennec/containers/optional.h>
|
||||||
#include <fennec/memory/allocator.h>
|
#include <fennec/memory/allocator.h>
|
||||||
|
|
||||||
|
#include <fennec/math/common.h>
|
||||||
|
|
||||||
|
#include <fennec/platform/interface/window.h>
|
||||||
|
|
||||||
namespace fennec
|
namespace fennec
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -33,6 +38,8 @@ public:
|
|||||||
using value_t = TypeT;
|
using value_t = TypeT;
|
||||||
static constexpr size_t npos = -1;
|
static constexpr size_t npos = -1;
|
||||||
|
|
||||||
|
class iterator;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct node {
|
struct node {
|
||||||
optional<value_t> data;
|
optional<value_t> data;
|
||||||
@@ -82,20 +89,21 @@ private:
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t _next_free(size_t i) {
|
size_t _next_free() {
|
||||||
if (not _freed.empty()) {
|
if (not _freed.empty()) {
|
||||||
size_t n = _freed.back();
|
size_t n = _freed.back();
|
||||||
_freed.pop_back();
|
_freed.pop_back();
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
_table[_size];
|
_table[_size];
|
||||||
|
return _size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using elem_t = node;
|
using elem_t = node;
|
||||||
|
|
||||||
constexpr list()
|
constexpr list()
|
||||||
: _table(), _root(npos), _last(npos), _freed(), _size(0) {
|
: _table(), _freed(), _root(npos), _last(npos), _size(0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr ~list() = default;
|
constexpr ~list() = default;
|
||||||
@@ -108,14 +116,14 @@ public:
|
|||||||
assertd(i >= 0, "Index out of Bounds");
|
assertd(i >= 0, "Index out of Bounds");
|
||||||
size_t n = _walk(i);
|
size_t n = _walk(i);
|
||||||
assertd(n != npos, "Index out of Bounds");
|
assertd(n != npos, "Index out of Bounds");
|
||||||
return _table[n].data;
|
return *_table[n].data;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr const value_t& operator[](int i) const {
|
constexpr const value_t& operator[](int i) const {
|
||||||
assertd(i >= 0, "Index out of Bounds");
|
assertd(i >= 0, "Index out of Bounds");
|
||||||
size_t n = _walk(i);
|
size_t n = _walk(i);
|
||||||
assertd(n != npos, "Index out of Bounds");
|
assertd(n != npos, "Index out of Bounds");
|
||||||
return _table[n].data;
|
return *_table[n].data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void insert(size_t i, value_t&& x) {
|
void insert(size_t i, value_t&& x) {
|
||||||
@@ -123,20 +131,25 @@ public:
|
|||||||
if (size() == capacity()) {
|
if (size() == capacity()) {
|
||||||
_expand();
|
_expand();
|
||||||
}
|
}
|
||||||
size_t n = _walk(min(i, size() - 1));
|
size_t n = _walk(min(i, size_t(size() - 1)));
|
||||||
size_t p = _next_free(i);
|
size_t p = _next_free();
|
||||||
if (n == npos) {
|
if (n == npos) {
|
||||||
_root = p;
|
_root = p;
|
||||||
_table[p].data = fennec::forward<value_t>(x);
|
_table[p].data = fennec::forward<value_t>(x);
|
||||||
|
_table[p].next = npos;
|
||||||
|
_table[p].prev = npos;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_table[p].data = fennec::forward<value_t>(x);
|
_table[p].data = fennec::forward<value_t>(x);
|
||||||
_table[p].next = n;
|
if (i == size()) {
|
||||||
_table[p].prev = _prev(p);
|
_table[p].next = n;
|
||||||
_table[n].prev = p;
|
_table[p].prev = _prev(n);
|
||||||
|
_table[n].prev = p;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_table[p].prev = n;
|
||||||
|
}
|
||||||
++_size;
|
++_size;
|
||||||
|
|
||||||
_last = (n == npos) ? p : _last;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void insert(size_t i, const value_t& x) {
|
void insert(size_t i, const value_t& x) {
|
||||||
@@ -175,8 +188,9 @@ public:
|
|||||||
|
|
||||||
// Fix prev and next nodes
|
// Fix prev and next nodes
|
||||||
if (p != npos) _table[p].next = n;
|
if (p != npos) _table[p].next = n;
|
||||||
|
else _root = n;
|
||||||
if (n != npos) _table[n].prev = p;
|
if (n != npos) _table[n].prev = p;
|
||||||
else _last = j;
|
else _last = p;
|
||||||
|
|
||||||
// Mark node as freed
|
// Mark node as freed
|
||||||
_freed.push_back(j);
|
_freed.push_back(j);
|
||||||
@@ -190,11 +204,75 @@ public:
|
|||||||
erase(_size - 1);
|
erase(_size - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr value_t& back() {
|
||||||
|
return this->operator[](size() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr const value_t& back() const {
|
||||||
|
return this->operator[](size() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ITERATOR ============================================================================================================
|
||||||
|
|
||||||
|
class iterator {
|
||||||
|
public:
|
||||||
|
~iterator() {
|
||||||
|
_list = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// prefix operator
|
||||||
|
constexpr friend iterator& operator++(iterator& rhs) {
|
||||||
|
if (rhs._list->_next(rhs._n) < rhs._list->capacity()) {
|
||||||
|
return rhs;
|
||||||
|
}
|
||||||
|
rhs._n = npos;
|
||||||
|
return rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr friend iterator operator++(iterator& lhs, int) {
|
||||||
|
iterator prev = lhs;
|
||||||
|
++lhs;
|
||||||
|
return prev;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr value_t& operator*() {
|
||||||
|
return *(_list->_table[_n].data);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr bool operator==(const iterator& it) {
|
||||||
|
return _list == it._list and _n == it._n;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr bool operator!=(const iterator& it) {
|
||||||
|
return _list != it._list or _n != it._n;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
list* _list;
|
||||||
|
size_t _n;
|
||||||
|
friend list;
|
||||||
|
|
||||||
|
iterator(list* ls, size_t n)
|
||||||
|
: _list(ls)
|
||||||
|
, _n(n) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr iterator begin() {
|
||||||
|
return iterator(this, _root);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr iterator end() {
|
||||||
|
return iterator(this, npos);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
allocation<elem_t, alloc_t> _table;
|
allocation<elem_t, alloc_t> _table;
|
||||||
dynarray<size_t> _freed;
|
dynarray<size_t> _freed;
|
||||||
size_t _root, _last, _size;
|
size_t _root, _last, _size;
|
||||||
|
|
||||||
|
friend class iterator;
|
||||||
|
|
||||||
constexpr void _expand() {
|
constexpr void _expand() {
|
||||||
_table.reallocate(_table.capacity() * 2);
|
_table.reallocate(_table.capacity() * 2);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public:
|
|||||||
pair<KeyT, ValueT> val;
|
pair<KeyT, ValueT> val;
|
||||||
|
|
||||||
~U() {
|
~U() {
|
||||||
root.~pair<KeyT, char[sizeof(ValueT)]>();
|
fennec::destruct(&root);
|
||||||
}
|
}
|
||||||
} trick = { .root = { key, 0 } };
|
} trick = { .root = { key, 0 } };
|
||||||
auto it = _set.find(trick.val);
|
auto it = _set.find(trick.val);
|
||||||
@@ -93,7 +93,7 @@ public:
|
|||||||
pair<KeyT, ValueT> val;
|
pair<KeyT, ValueT> val;
|
||||||
|
|
||||||
~U() {
|
~U() {
|
||||||
root.~pair<KeyT, char[sizeof(ValueT)]>();
|
fennec::destruct(&root);
|
||||||
}
|
}
|
||||||
} trick = { .root = { key, 0 } }; // Only initialize root
|
} trick = { .root = { key, 0 } }; // Only initialize root
|
||||||
auto it = _set.find(trick.val);
|
auto it = _set.find(trick.val);
|
||||||
@@ -110,7 +110,7 @@ public:
|
|||||||
pair<KeyT, ValueT> val;
|
pair<KeyT, ValueT> val;
|
||||||
|
|
||||||
~U() {
|
~U() {
|
||||||
root.~pair<KeyT, char[sizeof(ValueT)]>();
|
fennec::destruct(&root);
|
||||||
}
|
}
|
||||||
} trick = { .root = { key_t(fennec::forward<ArgsT>(args)...), 0 } }; // Only initialize root
|
} trick = { .root = { key_t(fennec::forward<ArgsT>(args)...), 0 } }; // Only initialize root
|
||||||
auto it = _set.find(trick.val);
|
auto it = _set.find(trick.val);
|
||||||
@@ -127,7 +127,7 @@ public:
|
|||||||
pair<KeyT, ValueT> val;
|
pair<KeyT, ValueT> val;
|
||||||
|
|
||||||
~U() {
|
~U() {
|
||||||
root.~pair<KeyT, char[sizeof(ValueT)]>();
|
fennec::destruct(&root);
|
||||||
}
|
}
|
||||||
} trick = { .root = { key_t(fennec::forward<ArgsT>(args)...), 0 } }; // Only initialize root
|
} trick = { .root = { key_t(fennec::forward<ArgsT>(args)...), 0 } }; // Only initialize root
|
||||||
auto it = _set.find(trick.val);
|
auto it = _set.find(trick.val);
|
||||||
@@ -157,7 +157,7 @@ public:
|
|||||||
pair<KeyT, ValueT> val;
|
pair<KeyT, ValueT> val;
|
||||||
|
|
||||||
~U() {
|
~U() {
|
||||||
root.~pair<KeyT, char[sizeof(ValueT)]>();
|
fennec::destruct(&root);
|
||||||
}
|
}
|
||||||
} trick = { .root = { fennec::forward<KeyT>(key), 0 } };
|
} trick = { .root = { fennec::forward<KeyT>(key), 0 } };
|
||||||
_set.erase(trick.val);
|
_set.erase(trick.val);
|
||||||
@@ -175,7 +175,7 @@ public:
|
|||||||
pair<KeyT, ValueT> val;
|
pair<KeyT, ValueT> val;
|
||||||
|
|
||||||
~U() {
|
~U() {
|
||||||
root.~pair<KeyT, char[sizeof(ValueT)]>();
|
fennec::destruct(&root);
|
||||||
}
|
}
|
||||||
} trick = { .root = { KeyT(fennec::forward<ArgsT>(args)...), 0 } };
|
} trick = { .root = { KeyT(fennec::forward<ArgsT>(args)...), 0 } };
|
||||||
_set.erase(trick.val);
|
_set.erase(trick.val);
|
||||||
|
|||||||
@@ -40,9 +40,9 @@ struct optional {
|
|||||||
public:
|
public:
|
||||||
// Constructors ========================================================================================================
|
// Constructors ========================================================================================================
|
||||||
using reference_t = T&;
|
using reference_t = T&;
|
||||||
using pointer_t = add_pointer_t<remove_reference_t<T>>;
|
using pointer_t = T*;
|
||||||
using const_reference_t = const T&;
|
using const_reference_t = T&;
|
||||||
using const_pointer_t = const add_pointer_t<remove_reference_t<T>>;
|
using const_pointer_t = const T*;
|
||||||
|
|
||||||
///
|
///
|
||||||
/// \brief Default Constructor
|
/// \brief Default Constructor
|
||||||
@@ -61,7 +61,7 @@ public:
|
|||||||
///
|
///
|
||||||
/// \brief Fundamental Type Constructor
|
/// \brief Fundamental Type Constructor
|
||||||
/// \param val the value to initialize the underlying object with
|
/// \param val the value to initialize the underlying object with
|
||||||
constexpr optional(T val) requires is_fundamental_v<T>
|
constexpr optional(T val) requires(is_fundamental_v<T> or is_pointer_v<T>)
|
||||||
: _val(val)
|
: _val(val)
|
||||||
, _set(true) {
|
, _set(true) {
|
||||||
}
|
}
|
||||||
@@ -102,7 +102,7 @@ public:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_set) {
|
if (_set) {
|
||||||
_val.~T();
|
fennec::destruct(&_val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ public:
|
|||||||
constexpr optional& operator=(nullopt_t) {
|
constexpr optional& operator=(nullopt_t) {
|
||||||
if constexpr(not is_fundamental_v<T>) {
|
if constexpr(not is_fundamental_v<T>) {
|
||||||
if (_set) {
|
if (_set) {
|
||||||
_val.~T();
|
fennec::destruct(&_val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_root = '\0';
|
_root = '\0';
|
||||||
@@ -158,7 +158,7 @@ public:
|
|||||||
if (_set) { // Construct
|
if (_set) { // Construct
|
||||||
fennec::construct(&_val, opt._val);
|
fennec::construct(&_val, opt._val);
|
||||||
} else { // Destruct
|
} else { // Destruct
|
||||||
_val.~T();
|
fennec::destruct(&_val);
|
||||||
_root = 0;
|
_root = 0;
|
||||||
}
|
}
|
||||||
} else if (_set) { // Copy Assignment
|
} else if (_set) { // Copy Assignment
|
||||||
@@ -176,7 +176,7 @@ public:
|
|||||||
if (_set) { // Construct
|
if (_set) { // Construct
|
||||||
fennec::construct(&_val, fennec::move(opt._val));
|
fennec::construct(&_val, fennec::move(opt._val));
|
||||||
} else { // Destruct
|
} else { // Destruct
|
||||||
_val.~T();
|
fennec::destruct(&_val);
|
||||||
_root = 0;
|
_root = 0;
|
||||||
}
|
}
|
||||||
} else if (_set) { // Copy Assignment
|
} else if (_set) { // Copy Assignment
|
||||||
@@ -211,7 +211,7 @@ public:
|
|||||||
return _set ? &_val : nullptr;
|
return _set ? &_val : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr const pointer_t operator->() const noexcept {
|
constexpr const_pointer_t operator->() const noexcept {
|
||||||
return _set ? &_val : nullptr;
|
return _set ? &_val : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -238,19 +238,14 @@ public:
|
|||||||
|
|
||||||
class iterator {
|
class iterator {
|
||||||
public:
|
public:
|
||||||
constexpr iterator(const set* set, size_t i)
|
|
||||||
: _set(set)
|
|
||||||
, _i(i) {
|
|
||||||
}
|
|
||||||
|
|
||||||
constexpr ~iterator() {
|
constexpr ~iterator() {
|
||||||
_set = nullptr;
|
_set = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// prefix operator
|
// prefix operator
|
||||||
constexpr friend iterator& operator++(iterator& rhs) {
|
constexpr friend iterator& operator++(iterator& rhs) {
|
||||||
while (++rhs._i < capacity()) {
|
while (++rhs._i < rhs._set->capacity()) {
|
||||||
if (rhs._set->_alloc[rhs._i]) {
|
if (rhs._set->_alloc[rhs._i].value) {
|
||||||
return rhs;
|
return rhs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -280,6 +275,11 @@ public:
|
|||||||
const set* _set;
|
const set* _set;
|
||||||
size_t _i;
|
size_t _i;
|
||||||
friend set;
|
friend set;
|
||||||
|
|
||||||
|
constexpr iterator(const set* set, size_t i)
|
||||||
|
: _set(set)
|
||||||
|
, _i(i) {
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr iterator begin() const {
|
constexpr iterator begin() const {
|
||||||
|
|||||||
@@ -51,8 +51,9 @@
|
|||||||
///
|
///
|
||||||
/// | Library | Brief |
|
/// | Library | Brief |
|
||||||
/// | :------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
/// | :------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||||
/// | \subpage fennec_lang | Implementation for functions and classes related to the C++ Language, including base types, common utility functions, and metaprogramming templates |
|
/// | \subpage fennec_lang | Implementation for functions and classes related to the C++ Language, including base types, common utility functions, and metaprogramming templates |
|
||||||
/// | \subpage fennec_math | Implementation of math functions according to the [OpenGL 4.6 Shading Language Specification](https://registry.khronos.org/OpenGL/specs/gl/GLSLangSpec.4.60.pdf). Additional extensions are provided for other common math functions. |
|
/// | \subpage fennec_math | Implementation of math functions according to the [OpenGL 4.6 Shading Language Specification](https://registry.khronos.org/OpenGL/specs/gl/GLSLangSpec.4.60.pdf). Additional extensions are provided for other common math functions. |
|
||||||
|
/// | \subpage fennec_memory | Implementation of functions related to memory management. |
|
||||||
|
|
||||||
#ifndef FENNEC_CORE_ENGINE_H
|
#ifndef FENNEC_CORE_ENGINE_H
|
||||||
#define FENNEC_CORE_ENGINE_H
|
#define FENNEC_CORE_ENGINE_H
|
||||||
|
|||||||
61
include/fennec/core/event.h
Normal file
61
include/fennec/core/event.h
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
// =====================================================================================================================
|
||||||
|
// 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/>.
|
||||||
|
// =====================================================================================================================
|
||||||
|
|
||||||
|
#ifndef FENNEC_CORE_EVENT_H
|
||||||
|
#define FENNEC_CORE_EVENT_H
|
||||||
|
|
||||||
|
#include <fennec/lang/types.h>
|
||||||
|
#include <fennec/lang/typeuuid.h>
|
||||||
|
|
||||||
|
namespace fennec
|
||||||
|
{
|
||||||
|
|
||||||
|
struct event;
|
||||||
|
|
||||||
|
class event_listener {
|
||||||
|
public:
|
||||||
|
virtual ~event_listener() = default;
|
||||||
|
virtual void handle_event(event* event) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct event {
|
||||||
|
const uint64_t type;
|
||||||
|
|
||||||
|
event() = delete;
|
||||||
|
|
||||||
|
template<typename EventT>
|
||||||
|
event() : type(typeuuid<EventT>()) { }
|
||||||
|
|
||||||
|
template<typename EventT>
|
||||||
|
static void add_listener(event_listener* listener) {
|
||||||
|
event::add_listener(listener, typeuuid<EventT, event>());
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename EventT>
|
||||||
|
static void dispatch(EventT* event) {
|
||||||
|
dispatch(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void add_listener(event_listener* listener, uint64_t type);
|
||||||
|
static void remove_listener(event_listener* listener);
|
||||||
|
static void dispatch(event* event);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // FENNEC_CORE_EVENT_H
|
||||||
@@ -149,7 +149,7 @@ public:
|
|||||||
bool empty() {
|
bool empty() {
|
||||||
size_t size = _str.size();
|
size_t size = _str.size();
|
||||||
if (size == 0) return true;
|
if (size == 0) return true;
|
||||||
#ifdef _WIN32
|
#if FENNEC_PLATFORM_WINDOWS
|
||||||
return (_str[1] == ':' && size == 3);
|
return (_str[1] == ':' && size == 3);
|
||||||
#else
|
#else
|
||||||
return (_str[0] == '/' && size == 1);
|
return (_str[0] == '/' && size == 1);
|
||||||
@@ -157,7 +157,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
path parent() const {
|
path parent() const {
|
||||||
#ifdef _WIN32
|
#ifdef FENNEC_PLATFORM_WINDOWS
|
||||||
size_t start = _str.size() - 1;
|
size_t start = _str.size() - 1;
|
||||||
start = _str[start] == '/' || _str[start] == '\\' ? start - 1 : start;
|
start = _str[start] == '/' || _str[start] == '\\' ? start - 1 : start;
|
||||||
|
|
||||||
@@ -185,7 +185,7 @@ public:
|
|||||||
path working; working._str.resize(0);
|
path working; working._str.resize(0);
|
||||||
|
|
||||||
// Check if this is a rooted path;
|
// Check if this is a rooted path;
|
||||||
#ifdef _WIN32
|
#ifdef FENNEC_PLATFORM_WINDOWS
|
||||||
if (_str[1] != ':') {
|
if (_str[1] != ':') {
|
||||||
#else
|
#else
|
||||||
if (_str[0] != '/') {
|
if (_str[0] != '/') {
|
||||||
|
|||||||
@@ -67,6 +67,12 @@ public:
|
|||||||
: _str(nullptr), _size(0), _const(true) {
|
: _str(nullptr), _size(0), _const(true) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// \brief Default Constructor, initializes with nullptr
|
||||||
|
constexpr cstring(nullptr_t)
|
||||||
|
: _str(nullptr), _size(0), _const(true) {
|
||||||
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// \brief Buffer Constructor, wraps the provided C-Style string
|
/// \brief Buffer Constructor, wraps the provided C-Style string
|
||||||
/// \param str the buffer to wrap
|
/// \param str the buffer to wrap
|
||||||
@@ -129,11 +135,16 @@ public:
|
|||||||
constexpr cstring(const cstring&) = delete;
|
constexpr cstring(const cstring&) = delete;
|
||||||
constexpr ~cstring() = default;
|
constexpr ~cstring() = default;
|
||||||
|
|
||||||
|
constexpr cstring& operator=(nullptr_t) {
|
||||||
|
_str = nullptr, _size = 0, _const = true;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Document
|
// TODO: Document
|
||||||
template<size_t n>
|
template<size_t n>
|
||||||
constexpr cstring& operator=(char(&str)[n]) {
|
constexpr cstring& operator=(char(&str)[n]) {
|
||||||
assert(_str[n - 1] == '\0', "Invalid NTBS.");
|
assert(_str[n - 1] == '\0', "Invalid NTBS.");
|
||||||
_str = str; _size = n - 1; _const = false;
|
_str = str, _size = n - 1, _const = false;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,6 +171,10 @@ public:
|
|||||||
/// \returns the size of the string excluding its null terminator, i.e. `(*str)[size()] == '\0'`
|
/// \returns the size of the string excluding its null terminator, i.e. `(*str)[size()] == '\0'`
|
||||||
constexpr size_t size() const { return _size; }
|
constexpr size_t size() const { return _size; }
|
||||||
|
|
||||||
|
constexpr bool empty() const {
|
||||||
|
return _cstr == nullptr || _size == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Access ==============================================================================================================
|
// Access ==============================================================================================================
|
||||||
|
|
||||||
@@ -220,6 +235,15 @@ public:
|
|||||||
return ::strncmp(_cstr + i, str, n);
|
return ::strncmp(_cstr + i, str, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// \brief String Equality
|
||||||
|
/// \param str the string to compare against
|
||||||
|
/// \returns True if all characters are equal, false otherwise
|
||||||
|
template<size_t n>
|
||||||
|
constexpr bool operator==(const char (&str)[n]) const {
|
||||||
|
return compare(cstring(str)) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// \brief String Equality
|
/// \brief String Equality
|
||||||
/// \param str the string to compare against
|
/// \param str the string to compare against
|
||||||
|
|||||||
@@ -78,18 +78,6 @@ public:
|
|||||||
fennec::memset(_str.data(), c, n);
|
fennec::memset(_str.data(), c, n);
|
||||||
_str[n] = '\0';
|
_str[n] = '\0';
|
||||||
}
|
}
|
||||||
///
|
|
||||||
/// \brief Buffer Copy Constructor
|
|
||||||
/// \param str the buffer to copy
|
|
||||||
/// \tparam n number of characters in the buffer
|
|
||||||
///
|
|
||||||
/// \details adds additional character for null termination. Ignores whether str is null-terminated.
|
|
||||||
/// This constructor makes the assumption that `len` is the intended number of characters.
|
|
||||||
template<size_t n>
|
|
||||||
constexpr _string(const char str[n])
|
|
||||||
: _str(str, n + 1) {
|
|
||||||
_str[n] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// \brief Buffer Copy Constructor
|
/// \brief Buffer Copy Constructor
|
||||||
@@ -327,6 +315,10 @@ public:
|
|||||||
/// \param str the string to copy
|
/// \param str the string to copy
|
||||||
/// \returns a reference to `this`
|
/// \returns a reference to `this`
|
||||||
constexpr _string& operator=(const cstring& str) {
|
constexpr _string& operator=(const cstring& str) {
|
||||||
|
if (str.empty()) {
|
||||||
|
_str.deallocate();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
resize(str.size());
|
resize(str.size());
|
||||||
fennec::memcpy(_str.data(), str, str.size());
|
fennec::memcpy(_str.data(), str, str.size());
|
||||||
_str[str.size()] = '\0';
|
_str[str.size()] = '\0';
|
||||||
|
|||||||
@@ -71,6 +71,12 @@ public:
|
|||||||
, _const(true) {
|
, _const(true) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// \brief Default Constructor, initializes with nullptr
|
||||||
|
constexpr wcstring(nullptr_t)
|
||||||
|
: _str(nullptr), _size(0), _const(true) {
|
||||||
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// \brief Buffer Constructor, wraps the provided C-Style string
|
/// \brief Buffer Constructor, wraps the provided C-Style string
|
||||||
/// \param str the buffer to wrap
|
/// \param str the buffer to wrap
|
||||||
@@ -133,6 +139,11 @@ public:
|
|||||||
constexpr wcstring(const wcstring&) = delete;
|
constexpr wcstring(const wcstring&) = delete;
|
||||||
constexpr ~wcstring() = default;
|
constexpr ~wcstring() = default;
|
||||||
|
|
||||||
|
constexpr wcstring& operator=(nullptr_t) {
|
||||||
|
_str = nullptr, _size = 0, _const = true;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Document
|
// TODO: Document
|
||||||
template<size_t n>
|
template<size_t n>
|
||||||
constexpr wcstring& operator=(wchar_t(&str)[n]) {
|
constexpr wcstring& operator=(wchar_t(&str)[n]) {
|
||||||
@@ -164,6 +175,10 @@ public:
|
|||||||
/// \returns the size of the string excluding its null terminator, i.e. `(*str)[size()] == '\0'`
|
/// \returns the size of the string excluding its null terminator, i.e. `(*str)[size()] == '\0'`
|
||||||
constexpr size_t size() const { return _size; }
|
constexpr size_t size() const { return _size; }
|
||||||
|
|
||||||
|
constexpr bool empty() const {
|
||||||
|
return _cstr == nullptr || _size == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Access ==============================================================================================================
|
// Access ==============================================================================================================
|
||||||
|
|
||||||
|
|||||||
@@ -59,45 +59,32 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// \brief Sized Constructor, initializes a null-terminated string of size `n` with null wchar_tacters
|
/// \brief Sized Constructor, initializes a null-terminated string of size `n` with null characters
|
||||||
/// \param n the number of wchar_tacters
|
/// \param n the number of characters
|
||||||
///
|
///
|
||||||
/// \details adds additional wchar_tacter for null termination.
|
/// \details adds additional character for null termination.
|
||||||
constexpr _wstring(size_t n)
|
constexpr _wstring(size_t n)
|
||||||
: _wstring('\0', n) {
|
: _wstring('\0', n) {
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// \brief Sized Constructor, initializes a null-terminated string of size `n` filled with the wchar_tacter `c`
|
/// \brief Sized Constructor, initializes a null-terminated string of size `n` filled with the character `c`
|
||||||
/// \param c the wchar_tacter to fill with
|
/// \param c the characters to fill with
|
||||||
/// \param n the number of wchar_tacters
|
/// \param n the number of characters
|
||||||
///
|
///
|
||||||
/// \details adds additional wchar_tacter for null termination.
|
/// \details adds additional character for null termination.
|
||||||
constexpr _wstring(wchar_t c, size_t n)
|
constexpr _wstring(wchar_t c, size_t n)
|
||||||
: _str(n + 1) {
|
: _str(n + 1) {
|
||||||
fennec::wmemset(_str.data(), c, n); _str[n] = '\0';
|
fennec::wmemset(_str.data(), c, n); _str[n] = '\0';
|
||||||
}
|
}
|
||||||
///
|
|
||||||
/// \brief Buffer Copy Constructor
|
|
||||||
/// \param str the buffer to copy
|
|
||||||
/// \param len number of wchar_tacters in the buffer
|
|
||||||
///
|
|
||||||
/// \details adds additional wchar_tacter for null termination. Ignores whether str is null-terminated.
|
|
||||||
/// This constructor makes the assumption that `len` is the intended number of wchar_tacters.
|
|
||||||
template<size_t n>
|
|
||||||
constexpr _wstring(const wchar_t str[n])
|
|
||||||
: _str(str, n + 1) {
|
|
||||||
::wcsncpy(_str.data(), str, n);
|
|
||||||
_str[n] = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// \brief Buffer Copy Constructor
|
/// \brief Buffer Copy Constructor
|
||||||
/// \param str the buffer to copy
|
/// \param str the buffer to copy
|
||||||
/// \param len number of wchar_tacters in the buffer
|
/// \param len number of characters in the buffer
|
||||||
///
|
///
|
||||||
/// \details adds additional wchar_tacter for null termination. Ignores whether str is null-terminated.
|
/// \details adds additional character for null termination. Ignores whether str is null-terminated.
|
||||||
/// This constructor makes the assumption that `len` is the intended number of wchar_tacters.
|
/// This constructor makes the assumption that `len` is the intended number of characters.
|
||||||
constexpr _wstring(const wchar_t* str, size_t n)
|
constexpr _wstring(const wchar_t* str, size_t n)
|
||||||
: _str(str, n + 1) {
|
: _str(str, n + 1) {
|
||||||
::wcsncpy(_str.data(), str, n);
|
::wcsncpy(_str.data(), str, n);
|
||||||
@@ -107,10 +94,10 @@ public:
|
|||||||
///
|
///
|
||||||
/// \brief Buffer Copy Constructor
|
/// \brief Buffer Copy Constructor
|
||||||
/// \param str the buffer to copy
|
/// \param str the buffer to copy
|
||||||
/// \param len number of wchar_tacters in the buffer
|
/// \param len number of characters in the buffer
|
||||||
///
|
///
|
||||||
/// \details adds additional wchar_tacter for null termination. Ignores whether str is null-terminated.
|
/// \details adds additional character for null termination. Ignores whether str is null-terminated.
|
||||||
/// This constructor makes the assumption that `len` is the intended number of wchar_tacters.
|
/// This constructor makes the assumption that `len` is the intended number of characters.
|
||||||
constexpr _wstring(const wcstring& str)
|
constexpr _wstring(const wcstring& str)
|
||||||
: _str(str, str.size() + 1) {
|
: _str(str, str.size() + 1) {
|
||||||
_str[str.size()] = '\0';
|
_str[str.size()] = '\0';
|
||||||
@@ -149,7 +136,7 @@ public:
|
|||||||
///
|
///
|
||||||
/// \brief Array Access Operator
|
/// \brief Array Access Operator
|
||||||
/// \param i the index to access
|
/// \param i the index to access
|
||||||
/// \returns a reference to the wchar_tacter
|
/// \returns a reference to the character
|
||||||
constexpr wchar_t& operator[](int i) {
|
constexpr wchar_t& operator[](int i) {
|
||||||
return _str[i];
|
return _str[i];
|
||||||
}
|
}
|
||||||
@@ -157,7 +144,7 @@ public:
|
|||||||
///
|
///
|
||||||
/// \brief Const-Array Access Operator
|
/// \brief Const-Array Access Operator
|
||||||
/// \param i the index to access
|
/// \param i the index to access
|
||||||
/// \returns a copy of the wchar_tacter
|
/// \returns a copy of the character
|
||||||
constexpr wchar_t operator[](int i) const {
|
constexpr wchar_t operator[](int i) const {
|
||||||
assertd(i >= 0 && i < size(), "Array Out of Bounds");
|
assertd(i >= 0 && i < size(), "Array Out of Bounds");
|
||||||
return _str[i];
|
return _str[i];
|
||||||
@@ -219,7 +206,7 @@ public:
|
|||||||
|
|
||||||
///
|
///
|
||||||
/// \brief Finds the index of the first occurrence of `c` in the string
|
/// \brief Finds the index of the first occurrence of `c` in the string
|
||||||
/// \param c the wchar_tacter to find
|
/// \param c the character to find
|
||||||
/// \returns The index of `c` if it occurs in the string, otherwise returns `size()`
|
/// \returns The index of `c` if it occurs in the string, otherwise returns `size()`
|
||||||
constexpr size_t find(wchar_t c, size_t i = 0) const {
|
constexpr size_t find(wchar_t c, size_t i = 0) const {
|
||||||
if (i >= size()) { // bounds check
|
if (i >= size()) { // bounds check
|
||||||
@@ -332,6 +319,10 @@ public:
|
|||||||
/// \param str the string to copy
|
/// \param str the string to copy
|
||||||
/// \returns a reference to `this`
|
/// \returns a reference to `this`
|
||||||
constexpr wstring& operator=(const wcstring& str) {
|
constexpr wstring& operator=(const wcstring& str) {
|
||||||
|
if (str.empty()) {
|
||||||
|
_str.deallocate();
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
if (str.size() > size()) resize(str.size());
|
if (str.size() > size()) resize(str.size());
|
||||||
fennec::wmemcpy(_str.data(), str, str.size());
|
fennec::wmemcpy(_str.data(), str, str.size());
|
||||||
_str[str.size()] = L'\0';
|
_str[str.size()] = L'\0';
|
||||||
@@ -361,7 +352,7 @@ public:
|
|||||||
///
|
///
|
||||||
/// \brief Retrieve a substring of a string
|
/// \brief Retrieve a substring of a string
|
||||||
/// \param i the start index
|
/// \param i the start index
|
||||||
/// \param n the number of wchar_tacters
|
/// \param n the number of characters
|
||||||
/// \return
|
/// \return
|
||||||
constexpr wstring substring(size_t i, size_t n = npos) const {
|
constexpr wstring substring(size_t i, size_t n = npos) const {
|
||||||
if (i >= size()) {
|
if (i >= size()) {
|
||||||
@@ -378,7 +369,7 @@ public:
|
|||||||
constexpr wstring operator+(wchar_t c) const {
|
constexpr wstring operator+(wchar_t c) const {
|
||||||
// Copy contents with one additional byte.
|
// Copy contents with one additional byte.
|
||||||
wstring res(_str, _str.size());
|
wstring res(_str, _str.size());
|
||||||
res[size()] = c; // Set the last wchar_tacter to c
|
res[size()] = c; // Set the last character to c
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@
|
|||||||
///
|
///
|
||||||
///
|
///
|
||||||
|
|
||||||
#if _MSC_VER
|
#if FENNEC_COMPILER_MSVC
|
||||||
#define __PRETTY_FUNCTION__ __FUNCSIG__
|
#define __PRETTY_FUNCTION__ __FUNCSIG__
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,8 @@
|
|||||||
#ifndef FENNEC_LANG_CONSTANTS_H
|
#ifndef FENNEC_LANG_CONSTANTS_H
|
||||||
#define FENNEC_LANG_CONSTANTS_H
|
#define FENNEC_LANG_CONSTANTS_H
|
||||||
|
|
||||||
|
#include <fennec/lang/types.h>
|
||||||
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
/// \page fennec_lang_constants Constants
|
/// \page fennec_lang_constants Constants
|
||||||
@@ -61,8 +63,6 @@
|
|||||||
/// </table>
|
/// </table>
|
||||||
///
|
///
|
||||||
|
|
||||||
#include <fennec/lang/types.h>
|
|
||||||
|
|
||||||
namespace fennec
|
namespace fennec
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
#ifndef FENNEC_LANG_DETAIL_INT_H
|
#ifndef FENNEC_LANG_DETAIL_INT_H
|
||||||
#define FENNEC_LANG_DETAIL_INT_H
|
#define FENNEC_LANG_DETAIL_INT_H
|
||||||
|
|
||||||
#if _MSC_VER
|
#if FENNEC_COMPILER_MSVC
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable:4117)
|
#pragma warning(disable:4117)
|
||||||
|
|
||||||
|
|||||||
@@ -16,12 +16,20 @@
|
|||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
// =====================================================================================================================
|
// =====================================================================================================================
|
||||||
|
|
||||||
#ifndef FENNEC_PLATFORM_LINUX_WAYLAND_SYM_DEF_H
|
#ifndef FENNEC_LANG_DETAIL_TYPEUUID_H
|
||||||
#define FENNEC_PLATFORM_LINUX_WAYLAND_SYM_DEF_H
|
#define FENNEC_LANG_DETAIL_TYPEUUID_H
|
||||||
|
|
||||||
#define FENNEC_LIB(name) inline bool FENNEC_HAS_LIB_##name = false;
|
#include <fennec/lang/types.h>
|
||||||
#define FENNEC_SYMBOL(ret, fn, ...) using sym_##fn = ret(*)(__VA_ARGS__); \
|
|
||||||
inline sym_##fn fn = nullptr;
|
|
||||||
#include <fennec/platform/linux/wayland/lib/sym.h>
|
|
||||||
|
|
||||||
#endif // FENNEC_PLATFORM_LINUX_WAYLAND_SYM_DEF_H
|
namespace fennec::detail
|
||||||
|
{
|
||||||
|
|
||||||
|
template<typename RootT>
|
||||||
|
FENNEC_NO_INLINE uint64_t __typeuuid() {
|
||||||
|
static uint64_t i = 0;
|
||||||
|
return ++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // FENNEC_LANG_DETAIL_TYPEUUID_H
|
||||||
@@ -54,8 +54,10 @@ struct hash<IntT> : hash<uint64_t> {
|
|||||||
|
|
||||||
// Wrapper for pointers
|
// Wrapper for pointers
|
||||||
template<typename PtrT>
|
template<typename PtrT>
|
||||||
requires is_pointer_v<PtrT>
|
struct hash<PtrT*> : hash<uintptr_t> {
|
||||||
struct hash<PtrT> : hash<uintptr_t> {
|
constexpr size_t operator()(PtrT* ptr) const {
|
||||||
|
return hash<uintptr_t>::operator()((uintptr_t)(const void*)ptr);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Float
|
// Float
|
||||||
|
|||||||
@@ -251,7 +251,7 @@
|
|||||||
|
|
||||||
// TODO: More compiler support
|
// TODO: More compiler support
|
||||||
|
|
||||||
#if _MSC_VER
|
#if FENNEC_COMPILER_MSVC
|
||||||
|
|
||||||
# define FENNEC_HAS_BUILTIN_ADDRESS_OF 1
|
# define FENNEC_HAS_BUILTIN_ADDRESS_OF 1
|
||||||
# define FENNEC_BUILTIN_ADDRESS_OF(arg) __builtin_addressof(arg)
|
# define FENNEC_BUILTIN_ADDRESS_OF(arg) __builtin_addressof(arg)
|
||||||
|
|||||||
@@ -119,6 +119,14 @@ template<typename T> auto declval() noexcept -> decltype(detail::__declval<T>(0)
|
|||||||
return detail::__declval<T>(0);
|
return detail::__declval<T>(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr inline bool is_constant_evaluated() noexcept {
|
||||||
|
if consteval {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// fennec::is_void =====================================================================================================
|
// fennec::is_void =====================================================================================================
|
||||||
|
|
||||||
|
|||||||
@@ -263,15 +263,15 @@ namespace fennec
|
|||||||
/// \name Sized Integer Types
|
/// \name Sized Integer Types
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
using int8_t = schar_t; ///< \brief Signed 8-bit integer
|
using int8_t = ::int8_t; ///< \brief Signed 8-bit integer
|
||||||
using int16_t = short_t; ///< \brief Signed 16-bit integer
|
using int16_t = ::int16_t; ///< \brief Signed 16-bit integer
|
||||||
using int32_t = conditional_t<sizeof(int_t) == 4, int_t, long_t>; ///< \brief Signed 32-bit integer
|
using int32_t = ::int32_t; ///< \brief Signed 32-bit integer
|
||||||
using int64_t = conditional_t<sizeof(long_t) == 8, long_t, llong_t>; ///< \brief Signed 64-bit integer
|
using int64_t = ::int64_t; ///< \brief Signed 64-bit integer
|
||||||
|
|
||||||
using uint8_t = uchar_t; ///< \brief Unsigned 8-bit integer
|
using uint8_t = ::uint8_t; ///< \brief Unsigned 8-bit integer
|
||||||
using uint16_t = ushort_t; ///< \brief Unsigned 16-bit integer
|
using uint16_t = ::uint16_t; ///< \brief Unsigned 16-bit integer
|
||||||
using uint32_t = conditional_t<sizeof(uint_t) == 4, uint_t, ulong_t>; ///< \brief Unsigned 32-bit integer
|
using uint32_t = ::uint32_t; ///< \brief Unsigned 32-bit integer
|
||||||
using uint64_t = conditional_t<sizeof(ulong_t) == 8, ulong_t, ullong_t>; ///< \brief Unsigned 64-bit integer
|
using uint64_t = ::uint64_t; ///< \brief Unsigned 64-bit integer
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
|
|||||||
47
include/fennec/lang/typeuuid.h
Normal file
47
include/fennec/lang/typeuuid.h
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
// =====================================================================================================================
|
||||||
|
// 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/>.
|
||||||
|
// =====================================================================================================================
|
||||||
|
|
||||||
|
#ifndef FENNEC_LANG_TYPEUUID_H
|
||||||
|
#define FENNEC_LANG_TYPEUUID_H
|
||||||
|
|
||||||
|
#include <fennec/lang/assert.h>
|
||||||
|
#include <fennec/lang/types.h>
|
||||||
|
#include <fennec/lang/type_traits.h>
|
||||||
|
|
||||||
|
#include <fennec/lang/detail/__typeuuid.h>
|
||||||
|
|
||||||
|
namespace fennec
|
||||||
|
{
|
||||||
|
|
||||||
|
constexpr uint64_t nullid = 0;
|
||||||
|
|
||||||
|
template<typename TypeT, typename RootT = void>
|
||||||
|
FENNEC_NO_INLINE uint64_t typeuuid() {
|
||||||
|
assertf(not is_constant_evaluated(), "Type UUIDs Cannot Be Obtained at Compile Time");
|
||||||
|
|
||||||
|
static bool init = false;
|
||||||
|
static uint64_t id = nullid;
|
||||||
|
|
||||||
|
if (init) return id;
|
||||||
|
init = true;
|
||||||
|
return id = detail::__typeuuid<RootT>();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // FENNEC_LANG_TYPEUUID_H
|
||||||
@@ -275,7 +275,7 @@
|
|||||||
|
|
||||||
#include <fennec/math/vector.h>
|
#include <fennec/math/vector.h>
|
||||||
|
|
||||||
#if _MSC_VER
|
#if FENNEC_COMPILER_MSVC
|
||||||
#define isnanf(x) isnan(x)
|
#define isnanf(x) isnan(x)
|
||||||
#define isinff(x) isinf(x)
|
#define isinff(x) isinf(x)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -531,7 +531,7 @@
|
|||||||
///
|
///
|
||||||
///
|
///
|
||||||
|
|
||||||
#if _MSC_VER
|
#if FENNEC_COMPILER_MSVC
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable:4305)
|
#pragma warning(disable:4305)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
#pragma GCC diagnostic ignored "-Wpedantic"
|
#pragma GCC diagnostic ignored "-Wpedantic"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if _MSC_VER
|
#if FENNEC_COMPILER_MSVC
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable:4201)
|
#pragma warning(disable:4201)
|
||||||
#endif
|
#endif
|
||||||
@@ -606,7 +606,7 @@ namespace fennec::detail
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef FENNEC_COMPILER_GCC
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@
|
|||||||
#include <fennec/math/common.h>
|
#include <fennec/math/common.h>
|
||||||
|
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef FENNEC_COMPILER_GCC
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#pragma GCC diagnostic ignored "-Wchanges-meaning"
|
#pragma GCC diagnostic ignored "-Wchanges-meaning"
|
||||||
#endif
|
#endif
|
||||||
@@ -302,20 +302,20 @@ public:
|
|||||||
///
|
///
|
||||||
/// \brief Default Constructor, initializes internal data to `null` and the capacity to `0`
|
/// \brief Default Constructor, initializes internal data to `null` and the capacity to `0`
|
||||||
constexpr allocation() noexcept
|
constexpr allocation() noexcept
|
||||||
: _data(nullptr), _capacity(0) {
|
: _data(nullptr), _capacity(0), _alignment(zero<align_t>()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// \brief Sized Constructor, initializes the allocation with a block of size `n * sizeof(T)` bytes
|
/// \brief Sized Constructor, initializes the allocation with a block of size `n * sizeof(T)` bytes
|
||||||
/// \param n The number of elements of type `T` to allocate for
|
/// \param n The number of elements of type `T` to allocate for
|
||||||
constexpr allocation(size_t n) noexcept
|
explicit constexpr allocation(size_t n) noexcept
|
||||||
: _data(nullptr), _capacity(0) {
|
: _data(nullptr), _capacity(0), _alignment(zero<align_t>()) {
|
||||||
allocate(n);
|
allocate(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// \brief Buffer Copy Constructor, initializes the allocation with a block of size `n * sizeof(T)` bytes.
|
/// \brief Buffer Copy Constructor, initializes the allocation with a block of size `n * sizeof(T)` bytes.
|
||||||
/// Then, the contents of data are copied into the allocation.
|
/// Then, the contents of data are byte copied into the allocation.
|
||||||
/// \param data the buffer to copy
|
/// \param data the buffer to copy
|
||||||
/// \param n the number of elements
|
/// \param n the number of elements
|
||||||
constexpr allocation(const T* data, size_t n)
|
constexpr allocation(const T* data, size_t n)
|
||||||
@@ -330,13 +330,13 @@ public:
|
|||||||
constexpr allocation(size_t n, align_t align) noexcept
|
constexpr allocation(size_t n, align_t align) noexcept
|
||||||
: _data(nullptr)
|
: _data(nullptr)
|
||||||
, _capacity(0)
|
, _capacity(0)
|
||||||
, _alignment(zero<align_t>()) {
|
, _alignment(align) {
|
||||||
allocate(n, align);
|
allocate(n, align);
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
/// \brief Buffer Copy Constructor, initializes the allocation with a block of size `n * sizeof(T)` bytes.
|
/// \brief Buffer Copy Constructor, initializes the allocation with a block of size `n * sizeof(T)` bytes.
|
||||||
/// Then, the contents of data are copied into the allocation.
|
/// Then, the contents of data are byte copied into the allocation.
|
||||||
/// \param data the buffer to copy
|
/// \param data the buffer to copy
|
||||||
/// \param n the number of elements
|
/// \param n the number of elements
|
||||||
/// \param align The alignment of the allocation
|
/// \param align The alignment of the allocation
|
||||||
@@ -350,10 +350,11 @@ public:
|
|||||||
/// \param alloc The allocation object to copy.
|
/// \param alloc The allocation object to copy.
|
||||||
///
|
///
|
||||||
/// \details This constructor should be used when the type `AllocT` needs internal data.
|
/// \details This constructor should be used when the type `AllocT` needs internal data.
|
||||||
constexpr allocation(const alloc_t& alloc) noexcept
|
explicit constexpr allocation(const alloc_t& alloc) noexcept
|
||||||
: _alloc(alloc)
|
: _alloc(alloc)
|
||||||
, _data(nullptr)
|
, _data(nullptr)
|
||||||
, _capacity(0) {
|
, _capacity(0)
|
||||||
|
, _alignment(zero<align_t>()){
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
@@ -417,7 +418,8 @@ public:
|
|||||||
constexpr allocation(const allocation& alloc) noexcept
|
constexpr allocation(const allocation& alloc) noexcept
|
||||||
: _alloc(alloc._alloc)
|
: _alloc(alloc._alloc)
|
||||||
, _data(_alloc.allocate(alloc._capacity))
|
, _data(_alloc.allocate(alloc._capacity))
|
||||||
, _capacity(alloc._capacity) {
|
, _capacity(alloc._capacity)
|
||||||
|
, _alignment(alloc._alignment) {
|
||||||
fennec::memcpy(_data, alloc._data, alloc._capacity * sizeof(T));
|
fennec::memcpy(_data, alloc._data, alloc._capacity * sizeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,7 +430,8 @@ public:
|
|||||||
constexpr allocation(allocation&& alloc) noexcept
|
constexpr allocation(allocation&& alloc) noexcept
|
||||||
: _alloc(alloc._alloc)
|
: _alloc(alloc._alloc)
|
||||||
, _data(alloc._data)
|
, _data(alloc._data)
|
||||||
, _capacity(alloc._capacity) {
|
, _capacity(alloc._capacity)
|
||||||
|
, _alignment(alloc._alignment) {
|
||||||
alloc._data = nullptr; alloc._capacity = 0;
|
alloc._data = nullptr; alloc._capacity = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -524,7 +527,7 @@ public:
|
|||||||
|
|
||||||
value_t* old = _data;
|
value_t* old = _data;
|
||||||
_data = _alloc.allocate(n);
|
_data = _alloc.allocate(n);
|
||||||
fennec::memcpy(_data, old, min(_capacity, n) * sizeof(T));
|
fennec::memcpy(static_cast<void*>(_data), old, min(_capacity, n) * sizeof(T));
|
||||||
_alloc.deallocate(old);
|
_alloc.deallocate(old);
|
||||||
_capacity = n;
|
_capacity = n;
|
||||||
}
|
}
|
||||||
@@ -591,7 +594,7 @@ private:
|
|||||||
align_t _alignment; // Alignment information
|
align_t _alignment; // Alignment information
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __GNUC__
|
#ifdef FENNEC_COMPILER_GCC
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ public:
|
|||||||
/// \param arr the buffer to wrap
|
/// \param arr the buffer to wrap
|
||||||
/// \tparam n the size of the buffer in elements
|
/// \tparam n the size of the buffer in elements
|
||||||
template<typename T, size_t n>
|
template<typename T, size_t n>
|
||||||
constexpr byte_array(T arr[n])
|
constexpr byte_array(T (&arr)[n])
|
||||||
: byte_array(arr, n * sizeof(T)) {
|
: byte_array(arr, n * sizeof(T)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ public:
|
|||||||
/// \param arr the buffer to wrap
|
/// \param arr the buffer to wrap
|
||||||
/// \tparam n the size of the buffer in elements
|
/// \tparam n the size of the buffer in elements
|
||||||
template<typename T, size_t n>
|
template<typename T, size_t n>
|
||||||
constexpr byte_array(const T arr[n])
|
constexpr byte_array(const T (&arr)[n])
|
||||||
: byte_array(arr, n * sizeof(T)) {
|
: byte_array(arr, n * sizeof(T)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,14 +23,14 @@
|
|||||||
// see https://git.mslockbo.org/mslockbo/fennec/src/commit/0eeb7ae3cff9d78e98dc5d9fc09bcb98b10986b9 for previous
|
// see https://git.mslockbo.org/mslockbo/fennec/src/commit/0eeb7ae3cff9d78e98dc5d9fc09bcb98b10986b9 for previous
|
||||||
// implementation
|
// implementation
|
||||||
|
|
||||||
#if __GNUC__
|
#if FENNEC_COMPILER_GCC
|
||||||
#define __OPTIMIZE__
|
#define __OPTIMIZE__
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
|
|
||||||
#if __GNUC__
|
#if FENNEC_COMPILER_GCC
|
||||||
#undef __OPTIMIZE__
|
#undef __OPTIMIZE__
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -101,5 +101,8 @@ void operator delete[](void* ptr, fennec::size_t, fennec::align_t) noexcept;
|
|||||||
void operator delete (void* ptr, fennec::align_t, const fennec::nothrow_t&) noexcept;
|
void operator delete (void* ptr, fennec::align_t, const fennec::nothrow_t&) noexcept;
|
||||||
void operator delete[](void* ptr, fennec::align_t, const fennec::nothrow_t&) noexcept;
|
void operator delete[](void* ptr, fennec::align_t, const fennec::nothrow_t&) noexcept;
|
||||||
|
|
||||||
|
template<typename TypeT> constexpr void* operator new (fennec::size_t, TypeT* ptr) { return ptr; }
|
||||||
|
template<typename TypeT> constexpr void* operator new[](fennec::size_t, TypeT* ptr) { return ptr; }
|
||||||
|
|
||||||
|
|
||||||
#endif // FENNEC_MEMORY_NEW_H
|
#endif // FENNEC_MEMORY_NEW_H
|
||||||
|
|||||||
71
include/fennec/platform/interface/displaydev.h
Normal file
71
include/fennec/platform/interface/displaydev.h
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
// =====================================================================================================================
|
||||||
|
// 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/>.
|
||||||
|
// =====================================================================================================================
|
||||||
|
|
||||||
|
#ifndef FENNEC_PLATFORM_INTERFACE_DISPLAYDEV_H
|
||||||
|
#define FENNEC_PLATFORM_INTERFACE_DISPLAYDEV_H
|
||||||
|
|
||||||
|
#include <fennec/platform/interface/fwd.h>
|
||||||
|
#include <fennec/platform/interface/window.h>
|
||||||
|
|
||||||
|
namespace fennec
|
||||||
|
{
|
||||||
|
|
||||||
|
///
|
||||||
|
/// \brief Interface for display management
|
||||||
|
class displaydev
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
struct pixel_format {
|
||||||
|
uint8_t depth;
|
||||||
|
uint8_t r, g, b;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct config {
|
||||||
|
pixel_format format;
|
||||||
|
};
|
||||||
|
|
||||||
|
virtual bool connected() const = 0;
|
||||||
|
virtual ~displaydev() = default;
|
||||||
|
|
||||||
|
virtual window* create_window() = 0;
|
||||||
|
|
||||||
|
const pixel_format& get_color_format() const {
|
||||||
|
return _config.format;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ContextT>
|
||||||
|
ContextT* get_context() {
|
||||||
|
return static_cast<ContextT*>(_context);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename PlatformT>
|
||||||
|
PlatformT* get_platform() {
|
||||||
|
return static_cast<PlatformT*>(_platform);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
platform* _platform;
|
||||||
|
gfxcontext* _context;
|
||||||
|
config _config;
|
||||||
|
|
||||||
|
displaydev(platform* platform);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // FENNEC_PLATFORM_INTERFACE_DISPLAYDEV_H
|
||||||
@@ -22,8 +22,11 @@
|
|||||||
namespace fennec
|
namespace fennec
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class platform;
|
||||||
class window;
|
class window;
|
||||||
class display;
|
class displaydev;
|
||||||
|
class gfxcontext;
|
||||||
|
class gfxsurface;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,30 +16,28 @@
|
|||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
// =====================================================================================================================
|
// =====================================================================================================================
|
||||||
|
|
||||||
#ifndef FENNEC_PLATFORM_INTERFACE_DISPLAY_H
|
#ifndef FENNEC_PLATFORM_INTERFACE_GFXCONTEXT_H
|
||||||
#define FENNEC_PLATFORM_INTERFACE_DISPLAY_H
|
#define FENNEC_PLATFORM_INTERFACE_GFXCONTEXT_H
|
||||||
|
|
||||||
#include <fennec/platform/interface/fwd.h>
|
#include <fennec/platform/interface/fwd.h>
|
||||||
|
|
||||||
namespace fennec
|
namespace fennec
|
||||||
{
|
{
|
||||||
|
|
||||||
///
|
class gfxcontext {
|
||||||
/// \brief Interface for display management
|
|
||||||
class display
|
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
struct config {
|
template<typename TypeT>
|
||||||
|
TypeT* get_device() {
|
||||||
|
return static_cast<TypeT*>(_device);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
protected:
|
||||||
|
gfxcontext(displaydev* device);
|
||||||
virtual bool connected() const = 0;
|
|
||||||
virtual ~display() = default;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
config _config;
|
displaydev* _device;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // FENNEC_PLATFORM_INTERFACE_DISPLAY_H
|
#endif // FENNEC_PLATFORM_INTERFACE_GFXCONTEXT_H
|
||||||
48
include/fennec/platform/interface/gfxsurface.h
Normal file
48
include/fennec/platform/interface/gfxsurface.h
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
// =====================================================================================================================
|
||||||
|
// 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/>.
|
||||||
|
// =====================================================================================================================
|
||||||
|
|
||||||
|
#ifndef FENNEC_PLATFORM_INTERFACE_GFXSURFACE_H
|
||||||
|
#define FENNEC_PLATFORM_INTERFACE_GFXSURFACE_H
|
||||||
|
|
||||||
|
#include <fennec/platform/interface/fwd.h>
|
||||||
|
|
||||||
|
namespace fennec
|
||||||
|
{
|
||||||
|
|
||||||
|
class gfxsurface {
|
||||||
|
template<typename ContextT>
|
||||||
|
ContextT* get_context() {
|
||||||
|
return static_cast<ContextT*>(_context);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename WindowT>
|
||||||
|
WindowT* get_window() {
|
||||||
|
return static_cast<WindowT*>(_window);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
gfxsurface(window* window, gfxcontext* context);
|
||||||
|
|
||||||
|
private:
|
||||||
|
window* _window;
|
||||||
|
gfxcontext* _context;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // FENNEC_PLATFORM_INTERFACE_GFXSURFACE_H
|
||||||
@@ -16,31 +16,21 @@
|
|||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
// =====================================================================================================================
|
// =====================================================================================================================
|
||||||
|
|
||||||
#ifndef FENNEC_PLATFORM_LINUX_WAYLAND_DISPLAY_H
|
#ifndef FENNEC_PLATFORM_INTERFACE_INPUTDEVICE_H
|
||||||
#define FENNEC_PLATFORM_LINUX_WAYLAND_DISPLAY_H
|
#define FENNEC_PLATFORM_INTERFACE_INPUTDEVICE_H
|
||||||
|
|
||||||
#include <fennec/fproc/strings/cstring.h>
|
|
||||||
#include <fennec/platform/interface/display.h>
|
|
||||||
|
|
||||||
#include <fennec/platform/linux/platform.h>
|
|
||||||
#include <fennec/platform/linux/wayland/lib/fwd.h>
|
|
||||||
|
|
||||||
namespace fennec
|
namespace fennec
|
||||||
{
|
{
|
||||||
|
|
||||||
class wayland_display : public display {
|
class inputdevice {
|
||||||
public:
|
public:
|
||||||
wayland_display(linux_platform* platform);
|
virtual bool has_keyboard() = 0;
|
||||||
wayland_display(linux_platform* platform, const cstring& drv);
|
virtual bool has_mouse() = 0;
|
||||||
~wayland_display() override;
|
virtual bool has_touch() = 0;
|
||||||
|
|
||||||
bool connected() const override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct wl_display* _handle;
|
|
||||||
linux_platform* _platform;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // FENNEC_PLATFORM_LINUX_WAYLAND_DISPLAY_H
|
#endif // FENNEC_PLATFORM_INTERFACE_INPUTDEVICE_H
|
||||||
@@ -29,19 +29,14 @@ class platform {
|
|||||||
public:
|
public:
|
||||||
using shared_object = struct shared_object;
|
using shared_object = struct shared_object;
|
||||||
using function_pointer = void (*)(void);
|
using function_pointer = void (*)(void);
|
||||||
|
using global = void*;
|
||||||
|
|
||||||
struct shared_lib {
|
struct shared_lib {
|
||||||
shared_object* _lib;
|
shared_object* _lib;
|
||||||
const cstring _name;
|
const cstring _name;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class user {
|
|
||||||
client,
|
|
||||||
server
|
|
||||||
};
|
|
||||||
|
|
||||||
struct config {
|
struct config {
|
||||||
user type;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Functions with default implementations
|
// Functions with default implementations
|
||||||
@@ -52,17 +47,18 @@ public:
|
|||||||
|
|
||||||
// Pure Virtual Functions
|
// Pure Virtual Functions
|
||||||
|
|
||||||
virtual display* get_display() = 0;
|
virtual displaydev* get_display() = 0;
|
||||||
|
|
||||||
virtual shared_object* load_object(const cstring& file) = 0;
|
virtual shared_object* load_object(const cstring& file) = 0;
|
||||||
virtual void unload_object(shared_object* obj) = 0;
|
virtual void unload_object(shared_object* obj) = 0;
|
||||||
|
|
||||||
virtual function_pointer find_symbol(shared_object* hndl, const cstring& name) = 0;
|
virtual function_pointer find_symbol(shared_object* hndl, const cstring& name) = 0;
|
||||||
|
virtual global find_global(shared_object* hndl, const cstring& name) = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
platform(user t);
|
platform();
|
||||||
virtual ~platform() = default;
|
virtual ~platform() = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -19,8 +19,10 @@
|
|||||||
#ifndef FENNEC_PLATFORM_INTERFACE_WINDOW_H
|
#ifndef FENNEC_PLATFORM_INTERFACE_WINDOW_H
|
||||||
#define FENNEC_PLATFORM_INTERFACE_WINDOW_H
|
#define FENNEC_PLATFORM_INTERFACE_WINDOW_H
|
||||||
|
|
||||||
|
#include <fennec/containers/optional.h>
|
||||||
#include <fennec/fproc/strings/string.h>
|
#include <fennec/fproc/strings/string.h>
|
||||||
#include <fennec/platform/interface/fwd.h>
|
#include <fennec/platform/interface/fwd.h>
|
||||||
|
#include <fennec/platform/interface/gfxsurface.h>
|
||||||
|
|
||||||
namespace fennec
|
namespace fennec
|
||||||
{
|
{
|
||||||
@@ -45,19 +47,18 @@ public:
|
|||||||
flags_block_screensaver = 0x1 << 4,
|
flags_block_screensaver = 0x1 << 4,
|
||||||
};
|
};
|
||||||
|
|
||||||
union bits {
|
|
||||||
uint32_t depth;
|
|
||||||
uint8_t r, g, b, a;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct config {
|
struct config {
|
||||||
string title;
|
string title;
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
size_t width, height;
|
size_t width, height;
|
||||||
fullscreen_mode fullscreen;
|
fullscreen_mode fullscreen;
|
||||||
bits bit_depth;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
virtual bool running() = 0;
|
||||||
|
virtual void configure(const config& config) = 0;
|
||||||
|
virtual bool initialize(bool modal) = 0;
|
||||||
|
virtual bool shutdown() = 0;
|
||||||
|
|
||||||
virtual bool set_title(const cstring& title) = 0;
|
virtual bool set_title(const cstring& title) = 0;
|
||||||
virtual bool set_title(const string& title) = 0;
|
virtual bool set_title(const string& title) = 0;
|
||||||
|
|
||||||
@@ -74,60 +75,76 @@ public:
|
|||||||
virtual bool block_screensaver(bool e) = 0;
|
virtual bool block_screensaver(bool e) = 0;
|
||||||
|
|
||||||
bool is_child() const {
|
bool is_child() const {
|
||||||
return _config.flags & flags_child;
|
if (not _config) return false;
|
||||||
|
return _config->flags & flags_child;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_modal() const {
|
bool is_modal() const {
|
||||||
return _config.flags & flags_modal;
|
if (not _config) return false;
|
||||||
|
return _config->flags & flags_modal;
|
||||||
}
|
}
|
||||||
|
|
||||||
display* get_display() {
|
displaydev* get_display() {
|
||||||
return _display;
|
return _display;
|
||||||
}
|
}
|
||||||
|
|
||||||
const display* get_display() const {
|
const displaydev* get_display() const {
|
||||||
return _display;
|
return _display;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const string& get_title() const {
|
const string& get_title() const {
|
||||||
return _config.title;
|
static const string _null = { "null" };
|
||||||
|
if (not _config) return _null;
|
||||||
|
return _config->title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t get_width() const {
|
size_t get_width() const {
|
||||||
return _config.width;
|
if (not _config) return false;
|
||||||
|
return _config->width;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t get_height() const {
|
size_t get_height() const {
|
||||||
return _config.height;
|
if (not _config) return false;
|
||||||
|
return _config->height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fullscreen_mode get_fullscreen_mode() const {
|
fullscreen_mode get_fullscreen_mode() const {
|
||||||
return _config.fullscreen;
|
if (not _config) return fullscreen_mode::windowed;
|
||||||
|
return _config->fullscreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool is_keyboard_grabbed() const {
|
bool is_keyboard_grabbed() const {
|
||||||
return _config.flags & flags_grab_keyboard;
|
if (not _config) return false;
|
||||||
|
return _config->flags & flags_grab_keyboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_mouse_grabbed() const {
|
bool is_mouse_grabbed() const {
|
||||||
return _config.flags & flags_grab_mouse;
|
if (not _config) return false;
|
||||||
|
return _config->flags & flags_grab_mouse;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_screensaver_blocked() const {
|
bool is_screensaver_blocked() const {
|
||||||
return _config.flags & flags_block_screensaver;
|
if (not _config) return false;
|
||||||
|
return _config->flags & flags_block_screensaver;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class DisplayT>
|
||||||
|
DisplayT* get_display() {
|
||||||
|
return static_cast<DisplayT*>(_display);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ~window() = default;
|
virtual ~window() = default;
|
||||||
window(display* display, window* parent, bool modal);
|
window(displaydev* display, window* parent);
|
||||||
|
|
||||||
display* _display;
|
displaydev* _display;
|
||||||
window* _parent;
|
window* _parent;
|
||||||
config _config;
|
optional<config> _config;
|
||||||
|
gfxsurface* _context;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
#define FENNEC_PLATFORM_LINUX_PLATFORM_H
|
#define FENNEC_PLATFORM_LINUX_PLATFORM_H
|
||||||
|
|
||||||
#include <fennec/containers/set.h>
|
#include <fennec/containers/set.h>
|
||||||
#include <fennec/platform/interface/display.h>
|
#include <fennec/platform/interface/displaydev.h>
|
||||||
#include <fennec/platform/interface/platform.h>
|
#include <fennec/platform/interface/platform.h>
|
||||||
|
|
||||||
namespace fennec
|
namespace fennec
|
||||||
@@ -34,18 +34,20 @@ public:
|
|||||||
display_wayland,
|
display_wayland,
|
||||||
};
|
};
|
||||||
|
|
||||||
linux_platform(user type);
|
linux_platform();
|
||||||
~linux_platform() override;
|
~linux_platform() override;
|
||||||
|
|
||||||
shared_object* load_object(const cstring& file) override;
|
shared_object* load_object(const cstring& file) override;
|
||||||
void unload_object(shared_object* obj) override;
|
void unload_object(shared_object* obj) override;
|
||||||
function_pointer find_symbol(shared_object* hndl, const cstring& name) override;
|
|
||||||
|
|
||||||
display* get_display() override;
|
function_pointer find_symbol(shared_object* hndl, const cstring& name) override;
|
||||||
|
global find_global(shared_object* hndl, const cstring& name) override;
|
||||||
|
|
||||||
|
displaydev* get_display() override;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
display* _display;
|
displaydev* _display;
|
||||||
int_t _display_driver;
|
int_t _display_driver;
|
||||||
|
|
||||||
void _runtime_client_checks();
|
void _runtime_client_checks();
|
||||||
|
|||||||
71
include/fennec/platform/linux/wayland/displaydev.h
Normal file
71
include/fennec/platform/linux/wayland/displaydev.h
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
// =====================================================================================================================
|
||||||
|
// 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/>.
|
||||||
|
// =====================================================================================================================
|
||||||
|
|
||||||
|
#ifndef FENNEC_PLATFORM_LINUX_WAYLAND_DISPLAY_H
|
||||||
|
#define FENNEC_PLATFORM_LINUX_WAYLAND_DISPLAY_H
|
||||||
|
|
||||||
|
#include <fennec/containers/list.h>
|
||||||
|
#include <fennec/fproc/strings/cstring.h>
|
||||||
|
|
||||||
|
#include <fennec/platform/interface/displaydev.h>
|
||||||
|
|
||||||
|
#include <fennec/platform/linux/platform.h>
|
||||||
|
#include <fennec/platform/linux/wayland/fwd.h>
|
||||||
|
#include <fennec/platform/linux/wayland/lib/wayland-client.h>
|
||||||
|
|
||||||
|
namespace fennec
|
||||||
|
{
|
||||||
|
|
||||||
|
class wayland_display : public displaydev {
|
||||||
|
public:
|
||||||
|
wayland_display(linux_platform* platform);
|
||||||
|
wayland_display(linux_platform* platform, const cstring& drv);
|
||||||
|
~wayland_display() override;
|
||||||
|
|
||||||
|
bool connected() const override;
|
||||||
|
|
||||||
|
window* create_window() override;
|
||||||
|
|
||||||
|
inline wl_display* get_handle() { return _handle; }
|
||||||
|
inline wl_registry* get_registry() { return _registry; }
|
||||||
|
inline wl_compositor* get_compositor() { return _compositor; }
|
||||||
|
inline wl_shell* get_shell() { return _shell; }
|
||||||
|
inline wl_seat* get_seat() { return _seat; }
|
||||||
|
inline wl_pointer* get_pointer() { return _pointer; }
|
||||||
|
inline wl_keyboard* get_keyboard() { return _keyboard; }
|
||||||
|
inline wl_shm* get_shm() { return _shm; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
wl_display* _handle;
|
||||||
|
wl_registry* _registry;
|
||||||
|
wl_compositor* _compositor;
|
||||||
|
wl_shell* _shell;
|
||||||
|
wl_seat* _seat;
|
||||||
|
wl_pointer* _pointer;
|
||||||
|
wl_keyboard* _keyboard;
|
||||||
|
wl_shm* _shm;
|
||||||
|
list<wayland_window*> _windows;
|
||||||
|
|
||||||
|
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(void*, wl_seat*, uint32_t);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // FENNEC_PLATFORM_LINUX_WAYLAND_DISPLAY_H
|
||||||
30
include/fennec/platform/linux/wayland/fwd.h
Normal file
30
include/fennec/platform/linux/wayland/fwd.h
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
// =====================================================================================================================
|
||||||
|
// 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/>.
|
||||||
|
// =====================================================================================================================
|
||||||
|
|
||||||
|
#ifndef FENNEC_PLATFORM_LINUX_WAYLAND_FWD_H
|
||||||
|
#define FENNEC_PLATFORM_LINUX_WAYLAND_FWD_H
|
||||||
|
|
||||||
|
namespace fennec
|
||||||
|
{
|
||||||
|
|
||||||
|
class wayland_display;
|
||||||
|
class wayland_window;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // FENNEC_PLATFORM_LINUX_WAYLAND_FWD_H
|
||||||
@@ -16,9 +16,46 @@
|
|||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
// =====================================================================================================================
|
// =====================================================================================================================
|
||||||
|
|
||||||
#ifndef FENNEC_PLATFORM_LINUX_WAYLAND_FWD_H
|
#ifndef FENNEC_PLATFORM_LINUX_WAYLAND_LIB_FWD_H
|
||||||
#define FENNEC_PLATFORM_LINUX_WAYLAND_FWD_H
|
#define FENNEC_PLATFORM_LINUX_WAYLAND_LIB_FWD_H
|
||||||
|
|
||||||
|
#include <fennec/lang/types.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
struct wl_object;
|
||||||
|
struct wl_proxy;
|
||||||
struct wl_display;
|
struct wl_display;
|
||||||
|
struct wl_event_queue;
|
||||||
|
struct wl_buffer;
|
||||||
|
struct wl_callback;
|
||||||
|
struct wl_compositor;
|
||||||
|
struct wl_data_device;
|
||||||
|
struct wl_data_device_manager;
|
||||||
|
struct wl_data_offer;
|
||||||
|
struct wl_data_source;
|
||||||
|
struct wl_keyboard;
|
||||||
|
struct wl_output;
|
||||||
|
struct wl_pointer;
|
||||||
|
struct wl_region;
|
||||||
|
struct wl_registry;
|
||||||
|
struct wl_seat;
|
||||||
|
struct wl_shell;
|
||||||
|
struct wl_shell_surface;
|
||||||
|
struct wl_shm;
|
||||||
|
struct wl_shm_pool;
|
||||||
|
struct wl_subcompositor;
|
||||||
|
struct wl_subsurface;
|
||||||
|
struct wl_surface;
|
||||||
|
struct wl_touch;
|
||||||
|
|
||||||
#endif // FENNEC_PLATFORM_LINUX_WAYLAND_FWD_H
|
struct wl_egl_window;
|
||||||
|
struct wl_surface;
|
||||||
|
|
||||||
|
typedef int32_t wl_fixed_t;
|
||||||
|
|
||||||
|
#define WL_PRINTF(x, y) __attribute__((__format__(__printf__, x, y)))
|
||||||
|
typedef void (*wl_log_func_t)(const char *fmt, va_list args) WL_PRINTF(1, 0);
|
||||||
|
|
||||||
|
#define WL_MARSHAL_FLAG_DESTROY (1 << 0)
|
||||||
|
|
||||||
|
#endif // FENNEC_PLATFORM_LINUX_WAYLAND_LIB_FWD_H
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
// =====================================================================================================================
|
// =====================================================================================================================
|
||||||
|
|
||||||
|
#include <fennec/lang/types.h>
|
||||||
#include <fennec/platform/linux/wayland/lib/fwd.h>
|
#include <fennec/platform/linux/wayland/lib/fwd.h>
|
||||||
|
|
||||||
#ifndef FENNEC_LIB
|
#ifndef FENNEC_LIB
|
||||||
@@ -26,12 +27,87 @@
|
|||||||
#define FENNEC_SYMBOL(...)
|
#define FENNEC_SYMBOL(...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef FENNEC_GLOBAL
|
||||||
|
#define FENNEC_GLOBAL(...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
FENNEC_LIB(WAYLAND);
|
FENNEC_LIB(WAYLAND);
|
||||||
|
|
||||||
FENNEC_SYMBOL(struct wl_display*, wl_display_connect, const char* name);
|
FENNEC_SYMBOL(void, wl_proxy_marshal, struct wl_proxy*, uint32_t, ...);
|
||||||
FENNEC_SYMBOL(void, wl_display_disconnect, wl_display* name);
|
FENNEC_SYMBOL(struct wl_proxy*, wl_proxy_marshal_flags, struct wl_proxy *proxy, uint32_t opcode, const struct wl_interface *interface, uint32_t version, uint32_t flags, ...);
|
||||||
|
FENNEC_SYMBOL(struct wl_proxy*, wl_proxy_create, struct wl_proxy*, const struct wl_interface*);
|
||||||
|
FENNEC_SYMBOL(void, wl_proxy_destroy, struct wl_proxy*);
|
||||||
|
FENNEC_SYMBOL(int, wl_proxy_add_listener, struct wl_proxy*, void (**)(void), void*);
|
||||||
|
FENNEC_SYMBOL(void, wl_proxy_set_user_data, struct wl_proxy*, void*);
|
||||||
|
FENNEC_SYMBOL(void*, wl_proxy_get_user_data, struct wl_proxy*);
|
||||||
|
FENNEC_SYMBOL(uint32_t, wl_proxy_get_version, struct wl_proxy*);
|
||||||
|
FENNEC_SYMBOL(uint32_t, wl_proxy_get_id, struct wl_proxy*);
|
||||||
|
FENNEC_SYMBOL(const char*, wl_proxy_get_class, struct wl_proxy*);
|
||||||
|
FENNEC_SYMBOL(void, wl_proxy_set_queue, struct wl_proxy*, struct wl_event_queue*);
|
||||||
|
FENNEC_SYMBOL(void*, wl_proxy_create_wrapper, void*);
|
||||||
|
FENNEC_SYMBOL(void, wl_proxy_wrapper_destroy, void*);
|
||||||
|
FENNEC_SYMBOL(struct wl_display*, wl_display_connect, const char*);
|
||||||
|
FENNEC_SYMBOL(struct wl_display*, wl_display_connect_to_fd, int);
|
||||||
|
FENNEC_SYMBOL(void, wl_display_disconnect, struct wl_display*);
|
||||||
|
FENNEC_SYMBOL(int, wl_display_get_fd, struct wl_display*);
|
||||||
|
FENNEC_SYMBOL(int, wl_display_dispatch, struct wl_display*);
|
||||||
|
FENNEC_SYMBOL(int, wl_display_dispatch_queue, struct wl_display*, struct wl_event_queue*);
|
||||||
|
FENNEC_SYMBOL(int, wl_display_dispatch_queue_pending, struct wl_display*, struct wl_event_queue*);
|
||||||
|
FENNEC_SYMBOL(int, wl_display_dispatch_pending, struct wl_display*);
|
||||||
|
FENNEC_SYMBOL(int, wl_display_prepare_read, struct wl_display*);
|
||||||
|
FENNEC_SYMBOL(int, wl_display_prepare_read_queue, struct wl_display*, struct wl_event_queue*);
|
||||||
|
FENNEC_SYMBOL(int, wl_display_read_events, struct wl_display*);
|
||||||
|
FENNEC_SYMBOL(void, wl_display_cancel_read, struct wl_display*);
|
||||||
|
FENNEC_SYMBOL(int, wl_display_get_error, struct wl_display*);
|
||||||
|
FENNEC_SYMBOL(int, wl_display_flush, struct wl_display*);
|
||||||
|
FENNEC_SYMBOL(int, wl_display_roundtrip, struct wl_display*);
|
||||||
|
FENNEC_SYMBOL(struct wl_event_queue*, wl_display_create_queue, struct wl_display*);
|
||||||
|
FENNEC_SYMBOL(void, wl_event_queue_destroy, struct wl_event_queue*);
|
||||||
|
FENNEC_SYMBOL(void, wl_log_set_handler_client, wl_log_func_t);
|
||||||
|
FENNEC_SYMBOL(void, wl_list_init, struct wl_list*);
|
||||||
|
FENNEC_SYMBOL(void, wl_list_insert, struct wl_list*, struct wl_list*) ;
|
||||||
|
FENNEC_SYMBOL(void, wl_list_remove, struct wl_list*);
|
||||||
|
FENNEC_SYMBOL(int, wl_list_length, const struct wl_list*);
|
||||||
|
FENNEC_SYMBOL(int, wl_list_empty, const struct wl_list*);
|
||||||
|
FENNEC_SYMBOL(void, wl_list_insert_list, struct wl_list*, struct wl_list*);
|
||||||
|
FENNEC_SYMBOL(struct wl_proxy*, wl_proxy_marshal_constructor, struct wl_proxy*, uint32_t opcode, const struct wl_interface*interface, ...);
|
||||||
|
FENNEC_SYMBOL(struct wl_proxy*, wl_proxy_marshal_constructor_versioned, struct wl_proxy*proxy, uint32_t opcode, const struct wl_interface*interface, uint32_t version, ...);
|
||||||
|
FENNEC_SYMBOL(void, wl_proxy_set_tag, struct wl_proxy*, const char* const*);
|
||||||
|
FENNEC_SYMBOL(const char* const*, wl_proxy_get_tag, struct wl_proxy*);
|
||||||
|
|
||||||
|
FENNEC_GLOBAL(const struct wl_interface, wl_display_interface);
|
||||||
|
FENNEC_GLOBAL(const struct wl_interface, wl_registry_interface);
|
||||||
|
FENNEC_GLOBAL(const struct wl_interface, wl_callback_interface);
|
||||||
|
FENNEC_GLOBAL(const struct wl_interface, wl_compositor_interface);
|
||||||
|
FENNEC_GLOBAL(const struct wl_interface, wl_shm_pool_interface);
|
||||||
|
FENNEC_GLOBAL(const struct wl_interface, wl_shm_interface);
|
||||||
|
FENNEC_GLOBAL(const struct wl_interface, wl_buffer_interface);
|
||||||
|
FENNEC_GLOBAL(const struct wl_interface, wl_data_offer_interface);
|
||||||
|
FENNEC_GLOBAL(const struct wl_interface, wl_data_source_interface);
|
||||||
|
FENNEC_GLOBAL(const struct wl_interface, wl_data_device_interface);
|
||||||
|
FENNEC_GLOBAL(const struct wl_interface, wl_data_device_manager_interface);
|
||||||
|
FENNEC_GLOBAL(const struct wl_interface, wl_shell_interface);
|
||||||
|
FENNEC_GLOBAL(const struct wl_interface, wl_shell_surface_interface);
|
||||||
|
FENNEC_GLOBAL(const struct wl_interface, wl_surface_interface);
|
||||||
|
FENNEC_GLOBAL(const struct wl_interface, wl_seat_interface);
|
||||||
|
FENNEC_GLOBAL(const struct wl_interface, wl_pointer_interface);
|
||||||
|
FENNEC_GLOBAL(const struct wl_interface, wl_keyboard_interface);
|
||||||
|
FENNEC_GLOBAL(const struct wl_interface, wl_touch_interface);
|
||||||
|
FENNEC_GLOBAL(const struct wl_interface, wl_output_interface);
|
||||||
|
FENNEC_GLOBAL(const struct wl_interface, wl_region_interface);
|
||||||
|
FENNEC_GLOBAL(const struct wl_interface, wl_subcompositor_interface);
|
||||||
|
FENNEC_GLOBAL(const struct wl_interface, wl_subsurface_interface);
|
||||||
|
|
||||||
|
FENNEC_LIB(WAYLAND_EGL);
|
||||||
|
|
||||||
|
FENNEC_SYMBOL(struct wl_egl_window*, wl_egl_window_create, struct wl_surface *surface, int width, int height);
|
||||||
|
FENNEC_SYMBOL(void, wl_egl_window_destroy, struct wl_egl_window *egl_window);
|
||||||
|
FENNEC_SYMBOL(void, wl_egl_window_resize, struct wl_egl_window *egl_window, int width, int height, int dx, int dy);
|
||||||
|
FENNEC_SYMBOL(void, wl_egl_window_get_attached_size, struct wl_egl_window *egl_window, int *width, int *height);
|
||||||
|
|
||||||
#undef FENNEC_LIB
|
#undef FENNEC_LIB
|
||||||
#undef FENNEC_SYMBOL
|
#undef FENNEC_SYMBOL
|
||||||
|
#undef FENNEC_GLOBAL
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
2004
include/fennec/platform/linux/wayland/lib/wayland-client.h
Normal file
2004
include/fennec/platform/linux/wayland/lib/wayland-client.h
Normal file
File diff suppressed because it is too large
Load Diff
198
include/fennec/platform/linux/wayland/lib/wayland-util.h
Normal file
198
include/fennec/platform/linux/wayland/lib/wayland-util.h
Normal file
@@ -0,0 +1,198 @@
|
|||||||
|
// =====================================================================================================================
|
||||||
|
// 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/>.
|
||||||
|
// =====================================================================================================================
|
||||||
|
|
||||||
|
#ifndef FENNEC_PLATFORM_LINUX_WAYLAND_LIB_WAYLAND_UTIL_H
|
||||||
|
#define FENNEC_PLATFORM_LINUX_WAYLAND_LIB_WAYLAND_UTIL_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright © 2008 Kristian Høgsberg
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice (including the
|
||||||
|
* next paragraph) shall be included in all copies or substantial
|
||||||
|
* portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||||
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#if defined(__GNUC__) && __GNUC__ >= 4
|
||||||
|
#define WL_EXPORT __attribute__ ((visibility("default")))
|
||||||
|
#else
|
||||||
|
#define WL_EXPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __STDC_VERSION__ >= 202311L
|
||||||
|
#define WL_DEPRECATED [[deprecated]]
|
||||||
|
#elif defined(__GNUC__) && __GNUC__ >= 4
|
||||||
|
#define WL_DEPRECATED __attribute__ ((deprecated))
|
||||||
|
#else
|
||||||
|
#define WL_DEPRECATED
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__GNUC__) && __GNUC__ >= 4
|
||||||
|
#define WL_PRINTF(x, y) __attribute__((__format__(__printf__, x, y)))
|
||||||
|
#else
|
||||||
|
#define WL_PRINTF(x, y)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __STDC_VERSION__ >= 202311L
|
||||||
|
#define WL_TYPEOF(expr) typeof(expr)
|
||||||
|
#else
|
||||||
|
#define WL_TYPEOF(expr) __typeof__(expr)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct wl_message {
|
||||||
|
const char *name;
|
||||||
|
const char *signature;
|
||||||
|
const struct wl_interface **types;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct wl_interface {
|
||||||
|
const char *name;
|
||||||
|
int version;
|
||||||
|
int method_count;
|
||||||
|
const struct wl_message *methods;
|
||||||
|
int event_count;
|
||||||
|
const struct wl_message *events;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct wl_list {
|
||||||
|
struct wl_list *prev;
|
||||||
|
struct wl_list *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define wl_container_of(ptr, sample, member) \
|
||||||
|
(WL_TYPEOF(sample))((char *)(ptr) - \
|
||||||
|
offsetof(WL_TYPEOF(*sample), member))
|
||||||
|
|
||||||
|
#define wl_list_for_each(pos, head, member) \
|
||||||
|
for (pos = wl_container_of((head)->next, pos, member); \
|
||||||
|
&pos->member != (head); \
|
||||||
|
pos = wl_container_of(pos->member.next, pos, member))
|
||||||
|
|
||||||
|
#define wl_list_for_each_safe(pos, tmp, head, member) \
|
||||||
|
for (pos = wl_container_of((head)->next, pos, member), \
|
||||||
|
tmp = wl_container_of((pos)->member.next, tmp, member); \
|
||||||
|
&pos->member != (head); \
|
||||||
|
pos = tmp, \
|
||||||
|
tmp = wl_container_of(pos->member.next, tmp, member))
|
||||||
|
|
||||||
|
#define wl_list_for_each_reverse(pos, head, member) \
|
||||||
|
for (pos = wl_container_of((head)->prev, pos, member); \
|
||||||
|
&pos->member != (head); \
|
||||||
|
pos = wl_container_of(pos->member.prev, pos, member))
|
||||||
|
|
||||||
|
#define wl_list_for_each_reverse_safe(pos, tmp, head, member) \
|
||||||
|
for (pos = wl_container_of((head)->prev, pos, member), \
|
||||||
|
tmp = wl_container_of((pos)->member.prev, tmp, member); \
|
||||||
|
&pos->member != (head); \
|
||||||
|
pos = tmp, \
|
||||||
|
tmp = wl_container_of(pos->member.prev, tmp, member))
|
||||||
|
|
||||||
|
struct wl_array {
|
||||||
|
size_t size;
|
||||||
|
size_t alloc;
|
||||||
|
void *data;
|
||||||
|
};
|
||||||
|
|
||||||
|
void
|
||||||
|
wl_array_init(struct wl_array *array);
|
||||||
|
|
||||||
|
void
|
||||||
|
wl_array_release(struct wl_array *array);
|
||||||
|
|
||||||
|
void *
|
||||||
|
wl_array_add(struct wl_array *array, size_t size);
|
||||||
|
|
||||||
|
int
|
||||||
|
wl_array_copy(struct wl_array *array, struct wl_array *source);
|
||||||
|
|
||||||
|
#define wl_array_for_each(pos, array) \
|
||||||
|
for (pos = (array)->data; \
|
||||||
|
(array)->size != 0 && \
|
||||||
|
(const char *) pos < ((const char *) (array)->data + (array)->size); \
|
||||||
|
(pos)++)
|
||||||
|
|
||||||
|
typedef int32_t wl_fixed_t;
|
||||||
|
|
||||||
|
static inline double
|
||||||
|
wl_fixed_to_double(wl_fixed_t f)
|
||||||
|
{
|
||||||
|
return f / 256.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline wl_fixed_t
|
||||||
|
wl_fixed_from_double(double d)
|
||||||
|
{
|
||||||
|
return (wl_fixed_t) (d * 256.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
wl_fixed_to_int(wl_fixed_t f)
|
||||||
|
{
|
||||||
|
return f / 256;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline wl_fixed_t
|
||||||
|
wl_fixed_from_int(int i)
|
||||||
|
{
|
||||||
|
return i * 256;
|
||||||
|
}
|
||||||
|
|
||||||
|
union wl_argument {
|
||||||
|
int32_t i;
|
||||||
|
uint32_t u;
|
||||||
|
wl_fixed_t f;
|
||||||
|
const char *s;
|
||||||
|
struct wl_object *o;
|
||||||
|
uint32_t n;
|
||||||
|
struct wl_array *a;
|
||||||
|
int32_t h;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef int (*wl_dispatcher_func_t)(const void *user_data, void *target,
|
||||||
|
uint32_t opcode, const struct wl_message *msg,
|
||||||
|
union wl_argument *args);
|
||||||
|
|
||||||
|
typedef void (*wl_log_func_t)(const char *fmt, va_list args) WL_PRINTF(1, 0);
|
||||||
|
|
||||||
|
enum wl_iterator_result {
|
||||||
|
WL_ITERATOR_STOP,
|
||||||
|
WL_ITERATOR_CONTINUE
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // FENNEC_PLATFORM_LINUX_WAYLAND_LIB_WAYLAND_UTIL_H
|
||||||
@@ -19,13 +19,40 @@
|
|||||||
#ifndef FENNEC_PLATFORM_LINUX_WAYLAND_WINDOW_H
|
#ifndef FENNEC_PLATFORM_LINUX_WAYLAND_WINDOW_H
|
||||||
#define FENNEC_PLATFORM_LINUX_WAYLAND_WINDOW_H
|
#define FENNEC_PLATFORM_LINUX_WAYLAND_WINDOW_H
|
||||||
|
|
||||||
|
#include <fennec/platform/interface/window.h>
|
||||||
|
|
||||||
|
#include <fennec/platform/linux/wayland/fwd.h>
|
||||||
|
#include <fennec/platform/linux/wayland/lib/fwd.h>
|
||||||
|
|
||||||
namespace fennec
|
namespace fennec
|
||||||
{
|
{
|
||||||
|
|
||||||
class wayland_window {
|
class wayland_window : window {
|
||||||
public:
|
public:
|
||||||
|
bool running() override;
|
||||||
|
void configure(const config& config) override;
|
||||||
|
bool initialize(bool modal) override;
|
||||||
|
bool shutdown() override;
|
||||||
|
|
||||||
|
bool set_title(const cstring& title) override;
|
||||||
|
bool set_title(const string& title) override;
|
||||||
|
bool set_width(size_t w) override;
|
||||||
|
bool set_height(size_t h) override;
|
||||||
|
bool set_size(size_t w, size_t h) override;
|
||||||
|
bool set_fullscreen_mode(fullscreen_mode mode) override;
|
||||||
|
bool set_resizable(bool e) override;
|
||||||
|
bool grab_keyboard(bool e) override;
|
||||||
|
bool grab_mouse(bool e) override;
|
||||||
|
bool block_screensaver(bool e) override;
|
||||||
|
|
||||||
|
wayland_window(wayland_display* display, wayland_window* parent);
|
||||||
|
~wayland_window() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
wl_surface* _surface;
|
||||||
|
wl_shell_surface* _shell;
|
||||||
|
wl_callback* _callback;
|
||||||
|
gfxcontext* _context;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
44
include/fennec/platform/opengl/egl/context.h
Normal file
44
include/fennec/platform/opengl/egl/context.h
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
// =====================================================================================================================
|
||||||
|
// 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/>.
|
||||||
|
// =====================================================================================================================
|
||||||
|
|
||||||
|
#ifndef FENNEC_PLATFORM_EGL_CONTEXT_H
|
||||||
|
#define FENNEC_PLATFORM_EGL_CONTEXT_H
|
||||||
|
|
||||||
|
#include <EGL/egl.h>
|
||||||
|
#include <fennec/platform/interface/displaydev.h>
|
||||||
|
#include <fennec/platform/interface/gfxcontext.h>
|
||||||
|
|
||||||
|
#if FENNEC_HAS_WAYLAND
|
||||||
|
#include <fennec/platform/linux/wayland/fwd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace fennec
|
||||||
|
{
|
||||||
|
|
||||||
|
class eglcontext : gfxcontext {
|
||||||
|
public:
|
||||||
|
eglcontext(displaydev* device);
|
||||||
|
|
||||||
|
EGLDisplay display;
|
||||||
|
EGLContext context;
|
||||||
|
EGLConfig config;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // FENNEC_PLATFORM_EGL_CONTEXT_H
|
||||||
43
include/fennec/platform/opengl/egl/surface.h
Normal file
43
include/fennec/platform/opengl/egl/surface.h
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
// =====================================================================================================================
|
||||||
|
// 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/>.
|
||||||
|
// =====================================================================================================================
|
||||||
|
|
||||||
|
#ifndef FENNEC_PLATFORM_OPENGL_EGL_SURFACE_H
|
||||||
|
#define FENNEC_PLATFORM_OPENGL_EGL_SURFACE_H
|
||||||
|
|
||||||
|
#include <EGL/egl.h>
|
||||||
|
|
||||||
|
#include <fennec/platform/interface/gfxsurface.h>
|
||||||
|
#include <fennec/platform/opengl/egl/context.h>
|
||||||
|
|
||||||
|
#if FENNEC_HAS_WAYLAND
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace fennec
|
||||||
|
{
|
||||||
|
|
||||||
|
class eglsurface : gfxsurface {
|
||||||
|
public:
|
||||||
|
eglsurface(eglcontext* context);
|
||||||
|
|
||||||
|
EGLSurface surface;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // FENNEC_PLATFORM_OPENGL_EGL_SURFACE_H
|
||||||
@@ -16,38 +16,32 @@
|
|||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
// =====================================================================================================================
|
// =====================================================================================================================
|
||||||
|
|
||||||
#include <fennec/platform/linux/wayland/display.h>
|
#include <fennec/containers/dynarray.h>
|
||||||
#include <fennec/platform/linux/wayland/lib/sym_def.h>
|
#include <fennec/containers/set.h>
|
||||||
#include <fennec/platform/linux/wayland/lib/dyn.h>
|
#include <fennec/core/event.h>
|
||||||
|
|
||||||
namespace fennec
|
namespace fennec
|
||||||
{
|
{
|
||||||
|
|
||||||
wayland_display::wayland_display(linux_platform* platform)
|
static dynarray<set<event_listener*>> listeners;
|
||||||
: display()
|
|
||||||
, _handle()
|
void event::add_listener(event_listener* listener, uint64_t type) {
|
||||||
, _platform(platform) {
|
if (listeners.size() <= type) {
|
||||||
libwayland::load_symbols(_platform);
|
listeners.resize(type + 1);
|
||||||
_handle = wl_display_connect(nullptr);
|
}
|
||||||
|
listeners[type].insert(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
wayland_display::wayland_display(linux_platform* platform, const cstring& drv)
|
void event::remove_listener(event_listener* listener) {
|
||||||
: display()
|
for (auto& it : listeners) {
|
||||||
, _handle()
|
it.erase(listener);
|
||||||
, _platform(platform) {
|
}
|
||||||
libwayland::load_symbols(_platform);
|
|
||||||
_handle = wl_display_connect(drv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wayland_display::~wayland_display() {
|
void event::dispatch(event* event) {
|
||||||
wl_display_disconnect(_handle);
|
for (auto& it : listeners[event->type]) {
|
||||||
libwayland::unload_symbols(_platform);
|
it->handle_event(event);
|
||||||
_handle = nullptr;
|
}
|
||||||
_platform = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wayland_display::connected() const {
|
|
||||||
return _handle != nullptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
#include <fennec/fproc/filesystem/path.h>
|
#include <fennec/fproc/filesystem/path.h>
|
||||||
|
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef FENNEC_COMPILER_MSVC
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
namespace fennec
|
namespace fennec
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef FENNEC_COMPILER_MSVC
|
||||||
|
|
||||||
path path::current() {
|
path path::current() {
|
||||||
char cstr[MAX_PATH];
|
char cstr[MAX_PATH];
|
||||||
|
|||||||
@@ -29,7 +29,7 @@
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
// Windows does not define ISO C aligned allocation functions
|
// Windows does not define ISO C aligned allocation functions
|
||||||
#ifdef _MSC_VER
|
#ifdef FENNEC_COMPILER_MSVC
|
||||||
void operator delete (void* ptr) noexcept { _aligned_free(ptr); }
|
void operator delete (void* ptr) noexcept { _aligned_free(ptr); }
|
||||||
void operator delete[](void* ptr) noexcept { _aligned_free(ptr); }
|
void operator delete[](void* ptr) noexcept { _aligned_free(ptr); }
|
||||||
void operator delete (void* ptr, fennec::align_t) noexcept { ::_aligned_free(ptr); }
|
void operator delete (void* ptr, fennec::align_t) noexcept { ::_aligned_free(ptr); }
|
||||||
|
|||||||
37
source/platform/interface/displaydev.cpp
Normal file
37
source/platform/interface/displaydev.cpp
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
// =====================================================================================================================
|
||||||
|
// 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/displaydev.h>
|
||||||
|
|
||||||
|
namespace fennec
|
||||||
|
{
|
||||||
|
|
||||||
|
displaydev::displaydev(platform* platform)
|
||||||
|
: _platform(platform)
|
||||||
|
, _context(nullptr)
|
||||||
|
, _config {
|
||||||
|
.format = {
|
||||||
|
.depth = 24,
|
||||||
|
.r = 8,
|
||||||
|
.g = 8,
|
||||||
|
.b = 8
|
||||||
|
}
|
||||||
|
} {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
30
source/platform/interface/gfxcontext.cpp
Normal file
30
source/platform/interface/gfxcontext.cpp
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
// =====================================================================================================================
|
||||||
|
// 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/gfxcontext.h>
|
||||||
|
|
||||||
|
namespace fennec
|
||||||
|
{
|
||||||
|
|
||||||
|
gfxcontext::gfxcontext(displaydev* device)
|
||||||
|
: _device(device) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
28
source/platform/interface/gfxsurface.cpp
Normal file
28
source/platform/interface/gfxsurface.cpp
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
// =====================================================================================================================
|
||||||
|
// 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/gfxsurface.h>
|
||||||
|
|
||||||
|
namespace fennec
|
||||||
|
{
|
||||||
|
|
||||||
|
gfxsurface::gfxsurface(window* window, gfxcontext* context)
|
||||||
|
: _window(window), _context(context) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -27,8 +27,7 @@ string platform::get_environment_variable(const cstring& var) {
|
|||||||
return string(val, strlen(val));
|
return string(val, strlen(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
platform::platform(user t) {
|
platform::platform() {
|
||||||
_config.type = t;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,15 +21,10 @@
|
|||||||
namespace fennec
|
namespace fennec
|
||||||
{
|
{
|
||||||
|
|
||||||
window::window(display* display, window* parent, bool modal)
|
window::window(displaydev* display, window* parent)
|
||||||
: _display(display)
|
: _display(display)
|
||||||
, _parent(parent)
|
, _parent(parent)
|
||||||
, _config() {
|
, _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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,24 +22,20 @@
|
|||||||
|
|
||||||
#ifdef FENNEC_LIB_WAYLAND
|
#ifdef FENNEC_LIB_WAYLAND
|
||||||
#include <fennec/platform/linux/wayland/lib/dyn.h>
|
#include <fennec/platform/linux/wayland/lib/dyn.h>
|
||||||
#include <fennec/platform/linux/wayland/display.h>
|
#include <fennec/platform/linux/wayland/displaydev.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace fennec
|
namespace fennec
|
||||||
{
|
{
|
||||||
|
|
||||||
linux_platform::linux_platform(user _type)
|
linux_platform::linux_platform()
|
||||||
: platform(_type)
|
: platform()
|
||||||
, _display_driver(display_none) {
|
, _display_driver(display_none) {
|
||||||
switch (_type) {
|
#if FENNEC_BUILD_SERVER
|
||||||
case user::client: {
|
_runtime_server_checks();
|
||||||
_runtime_client_checks();
|
#else
|
||||||
return;
|
_runtime_client_checks();
|
||||||
}
|
#endif
|
||||||
case user::server: {
|
|
||||||
_runtime_server_checks();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
linux_platform::~linux_platform() {
|
linux_platform::~linux_platform() {
|
||||||
@@ -72,7 +68,17 @@ platform::function_pointer linux_platform::find_symbol(shared_object* hndl, cons
|
|||||||
return (function_pointer)symbol;
|
return (function_pointer)symbol;
|
||||||
}
|
}
|
||||||
|
|
||||||
display* linux_platform::get_display() {
|
platform::global linux_platform::find_global(shared_object* hndl, const cstring& name) {
|
||||||
|
string _name = name;
|
||||||
|
void* symbol = dlsym(hndl, _name);
|
||||||
|
if (symbol == nullptr) {
|
||||||
|
_name = '_' + _name;
|
||||||
|
symbol = dlsym(hndl, _name);
|
||||||
|
}
|
||||||
|
return symbol;
|
||||||
|
}
|
||||||
|
|
||||||
|
displaydev* linux_platform::get_display() {
|
||||||
return _display;
|
return _display;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +88,7 @@ void linux_platform::_runtime_client_checks() {
|
|||||||
_display_driver = display_wayland;
|
_display_driver = display_wayland;
|
||||||
_display = new wayland_display(this);
|
_display = new wayland_display(this);
|
||||||
libwayland::unload_symbols(this); // Doesn't actually unload symbols, just resets ref counter to only consider
|
libwayland::unload_symbols(this); // Doesn't actually unload symbols, just resets ref counter to only consider
|
||||||
// the created display
|
// the created display
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
assertf(_display != nullptr, "failed to find suitable display driver");
|
assertf(_display != nullptr, "failed to find suitable display driver");
|
||||||
|
|||||||
98
source/platform/linux/wayland/displaydev.cpp
Normal file
98
source/platform/linux/wayland/displaydev.cpp
Normal 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/wayland/displaydev.h>
|
||||||
|
#include <fennec/platform/linux/wayland/window.h>
|
||||||
|
|
||||||
|
#include <fennec/platform/linux/wayland/lib/dyn.h>
|
||||||
|
#include <fennec/platform/linux/wayland/lib/wayland-client.h>
|
||||||
|
|
||||||
|
namespace fennec
|
||||||
|
{
|
||||||
|
|
||||||
|
wayland_display::wayland_display(linux_platform* platform)
|
||||||
|
: wayland_display(platform, nullptr) {
|
||||||
|
}
|
||||||
|
|
||||||
|
wayland_display::wayland_display(linux_platform* platform, const cstring& drv)
|
||||||
|
: displaydev(platform)
|
||||||
|
, _handle(nullptr)
|
||||||
|
, _registry(nullptr)
|
||||||
|
, _compositor(nullptr) {
|
||||||
|
|
||||||
|
static constexpr wl_registry_listener listener = {
|
||||||
|
listen_global, listen_global_remove
|
||||||
|
};
|
||||||
|
|
||||||
|
// Load libwayland.so
|
||||||
|
libwayland::load_symbols(get_platform<linux_platform>());
|
||||||
|
|
||||||
|
// Get handles
|
||||||
|
_handle = wl_display_connect(drv);
|
||||||
|
_registry = wl_display_get_registry(_handle);
|
||||||
|
wl_registry_add_listener(_registry, &listener, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
wayland_display::~wayland_display() {
|
||||||
|
wl_registry_destroy(_registry);
|
||||||
|
wl_display_flush(_handle);
|
||||||
|
wl_display_disconnect(_handle);
|
||||||
|
libwayland::unload_symbols(get_platform<linux_platform>());
|
||||||
|
_handle = nullptr;
|
||||||
|
_platform = nullptr;
|
||||||
|
for (const auto it : _windows) {
|
||||||
|
delete it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wayland_display::connected() const {
|
||||||
|
return _handle != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
window* wayland_display::create_window() {
|
||||||
|
_windows.push_back(new wayland_window(this, nullptr));
|
||||||
|
return (window*)(_windows.back());
|
||||||
|
}
|
||||||
|
|
||||||
|
void wayland_display::listen_global(void* data, wl_registry* registry, uint32_t name, const char* itfc, uint32_t version) {
|
||||||
|
static constexpr wl_seat_listener seat_listener = {
|
||||||
|
listen_seat, nullptr
|
||||||
|
};
|
||||||
|
|
||||||
|
wayland_display* device = static_cast<wayland_display*>(data);
|
||||||
|
const cstring interface = cstring(itfc, strlen(itfc) + 1);
|
||||||
|
|
||||||
|
if (interface == "wl_compositor") {
|
||||||
|
device->_compositor = static_cast<wl_compositor*>(wl_registry_bind(registry, name, wl_compositor_interface, version));
|
||||||
|
} else if (interface == "wl_shell") {
|
||||||
|
device->_shell = static_cast<wl_shell*>(wl_registry_bind(registry, name, wl_shell_interface, version));
|
||||||
|
} else if (interface == "wl_seat") {
|
||||||
|
device->_seat = static_cast<wl_seat*>(wl_registry_bind(registry, name, wl_seat_interface, version));
|
||||||
|
wl_seat_add_listener(device->_seat, &seat_listener, device);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void wayland_display::listen_global_remove(void*, wl_registry*, uint32_t) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void wayland_display::listen_seat(void*, wl_seat*, uint32_t) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// 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/wayland-client.h>
|
||||||
#include <fennec/platform/linux/wayland/lib/dyn.h>
|
#include <fennec/platform/linux/wayland/lib/dyn.h>
|
||||||
|
|
||||||
namespace fennec
|
namespace fennec
|
||||||
@@ -31,7 +31,6 @@ static int _load_count = 0;
|
|||||||
|
|
||||||
// Create private variables
|
// Create private variables
|
||||||
#define FENNEC_LIB(lib) static shared_lib _FENNEC_LIB_##lib = { nullptr, FENNEC_LIB_##lib };
|
#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>
|
#include <fennec/platform/linux/wayland/lib/sym.h>
|
||||||
|
|
||||||
bool load_symbols(linux_platform* platform) {
|
bool load_symbols(linux_platform* platform) {
|
||||||
@@ -39,14 +38,20 @@ bool load_symbols(linux_platform* platform) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shared_lib* current_lib = nullptr;
|
||||||
#define FENNEC_LIB(lib) _FENNEC_LIB_##lib._lib = platform->load_object(_FENNEC_LIB_##lib._name); \
|
#define FENNEC_LIB(lib) _FENNEC_LIB_##lib._lib = platform->load_object(_FENNEC_LIB_##lib._name); \
|
||||||
FENNEC_HAS_LIB_##lib = _FENNEC_LIB_##lib._lib != nullptr; \
|
FENNEC_HAS_LIB_##lib = _FENNEC_LIB_##lib._lib != nullptr; \
|
||||||
if(not FENNEC_HAS_LIB_##lib) { \
|
if(not FENNEC_HAS_LIB_##lib) { \
|
||||||
unload_symbols(platform); \
|
unload_symbols(platform); \
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
shared_lib& current_lib = _FENNEC_LIB_##lib;
|
current_lib = &_FENNEC_LIB_##lib;
|
||||||
#define FENNEC_SYMBOL(ret, fn, ...) fn = (sym_##fn)(platform->find_symbol(current_lib._lib, #fn));
|
#define FENNEC_SYMBOL(ret, fn, ...) fn = (sym_##fn)(platform->find_symbol(current_lib->_lib, #fn)); \
|
||||||
|
assertf(fn != nullptr, "Failed to find symbol: " #fn);
|
||||||
|
#define FENNEC_GLOBAL(type, name) name = (type*)(platform->find_symbol(current_lib->_lib, #name)); \
|
||||||
|
assertf(name != nullptr, "Failed to find global: " #name);
|
||||||
|
|
||||||
|
|
||||||
#include <fennec/platform/linux/wayland/lib/sym.h>
|
#include <fennec/platform/linux/wayland/lib/sym.h>
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -60,6 +65,7 @@ void unload_symbols(linux_platform* platform) {
|
|||||||
#define FENNEC_LIB(lib) platform->unload_object(_FENNEC_LIB_##lib._lib); \
|
#define FENNEC_LIB(lib) platform->unload_object(_FENNEC_LIB_##lib._lib); \
|
||||||
_FENNEC_LIB_##lib._lib = nullptr;
|
_FENNEC_LIB_##lib._lib = nullptr;
|
||||||
#define FENNEC_SYMBOL(ret, fn, ...) fn = nullptr;
|
#define FENNEC_SYMBOL(ret, fn, ...) fn = nullptr;
|
||||||
|
#define FENNEC_GLOBAL(type, name) name = nullptr;
|
||||||
#include <fennec/platform/linux/wayland/lib/sym.h>
|
#include <fennec/platform/linux/wayland/lib/sym.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
86
source/platform/linux/wayland/window.cpp
Normal file
86
source/platform/linux/wayland/window.cpp
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
// =====================================================================================================================
|
||||||
|
// 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/displaydev.h>
|
||||||
|
#include <fennec/platform/linux/wayland/window.h>
|
||||||
|
|
||||||
|
#include <EGL/egl.h>
|
||||||
|
|
||||||
|
namespace fennec
|
||||||
|
{
|
||||||
|
bool wayland_window::running() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wayland_window::configure(const config& config) {
|
||||||
|
assertf(running() == false, "Attempted to Configure Running Window.");
|
||||||
|
|
||||||
|
_config = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wayland_window::initialize(bool modal) {
|
||||||
|
assertf(_config, "Attempted to Initialize a Window Without Configuration");
|
||||||
|
if (not _config) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
_config->flags &= ~flags_modal & ~flags_child;
|
||||||
|
if (_parent != nullptr) {
|
||||||
|
_config->flags |= flags_child;
|
||||||
|
if (modal) {
|
||||||
|
_config->flags |= flags_modal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_surface = wl_compositor_create_surface(get_display<wayland_display>()->get_compositor());
|
||||||
|
_shell = wl_shell_get_shell_surface(get_display<wayland_display>()->get_shell(), _surface);
|
||||||
|
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wayland_window::shutdown() {
|
||||||
|
wl_shell_surface_destroy(_shell);
|
||||||
|
wl_surface_destroy(_surface);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool wayland_window::set_title(const cstring&) { return true; }
|
||||||
|
bool wayland_window::set_title(const string&) { return true; }
|
||||||
|
bool wayland_window::set_width(size_t) { return true; }
|
||||||
|
bool wayland_window::set_height(size_t) { return true; }
|
||||||
|
bool wayland_window::set_size(size_t, size_t) { return true; }
|
||||||
|
bool wayland_window::set_fullscreen_mode(fullscreen_mode) { return true; }
|
||||||
|
bool wayland_window::set_resizable(bool) { return true; }
|
||||||
|
bool wayland_window::grab_keyboard(bool) { return true; }
|
||||||
|
bool wayland_window::grab_mouse(bool) { return true; }
|
||||||
|
bool wayland_window::block_screensaver(bool) { return true; }
|
||||||
|
|
||||||
|
wayland_window::wayland_window(wayland_display* display, wayland_window* parent)
|
||||||
|
: window(display, parent)
|
||||||
|
, _surface(nullptr)
|
||||||
|
, _shell(nullptr)
|
||||||
|
, _callback(nullptr) {
|
||||||
|
}
|
||||||
|
|
||||||
|
wayland_window::~wayland_window() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -32,7 +32,6 @@ namespace fennec::test
|
|||||||
dynarray<int> test2;
|
dynarray<int> test2;
|
||||||
|
|
||||||
int n = 10000;
|
int n = 10000;
|
||||||
test1.resize(n); test2.resize(n);
|
|
||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
test1.push_back(i);
|
test1.push_back(i);
|
||||||
test2.push_back(n - i - 1);
|
test2.push_back(n - i - 1);
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
#define FENNEC_TEST_PLATFORM_LINUX_WAYLAND_H
|
#define FENNEC_TEST_PLATFORM_LINUX_WAYLAND_H
|
||||||
|
|
||||||
#include "../../../test.h"
|
#include "../../../test.h"
|
||||||
#include <fennec/platform/linux/wayland/display.h>
|
#include <fennec/platform/linux/wayland/displaydev.h>
|
||||||
|
|
||||||
namespace fennec::test
|
namespace fennec::test
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ namespace fennec::test
|
|||||||
|
|
||||||
inline void fennec_test_platform_linux() {
|
inline void fennec_test_platform_linux() {
|
||||||
|
|
||||||
linux_platform platform(platform::user::client);
|
linux_platform platform;
|
||||||
|
|
||||||
#ifdef FENNEC_LIB_WAYLAND
|
#ifdef FENNEC_LIB_WAYLAND
|
||||||
fennec_test_section("wayland tests");
|
fennec_test_section("wayland tests");
|
||||||
|
|||||||
Reference in New Issue
Block a user