This commit is contained in:
herbglitch 2025-02-14 03:27:04 -07:00
commit fc5bf78919
36 changed files with 1193 additions and 525 deletions

View file

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.25)
set(ARCHEUS_STD_VERSION 0.0.0)
project(archeus_std LANGUAGES C VERSION ${ARCHEUS_STD_VERSION} DESCRIPTION "libarcheus_std standard archeus c library")
set(ARCHEUS_VERSION 0.0.0)
project(archeus LANGUAGES C VERSION ${ARCHEUS_VERSION} DESCRIPTION "libarcheus c library")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
@ -13,7 +13,7 @@ endfunction()
#TODO: Might want to remove this
if(NOT CMAKE_BUILD_TYPE)
message("[Archeus C STD] Build Type not set, defaulting to Debug")
message("[Archeus] Build Type not set, defaulting to Debug")
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Default to Debug" FORCE)
endif()
@ -24,39 +24,44 @@ add_compile_options(
)
# ~ OPTIONS ~ #
option(ARCHEUS_STD_DEFAULT_CONFIG "Build with default config keys" ON)
option(ARCHEUS_STD_TESTS "Build with tests" OFF)
option(ARCHEUS_DEFAULT_CONFIG "Build with default config keys" ON)
option(ARCHEUS_TESTS "Build with tests" OFF)
set(ARCHEUS_STD_CONSOLE_BACKEND "NONE" CACHE STRING "Console Backend to build with")
set_property(CACHE ARCHEUS_STD_CONSOLE_BACKEND PROPERTY STRINGS NONE NCURSES)
set(ARCHEUS_WINDOW_BACKEND "NONE" CACHE STRING "Window Backend to build with")
set_property(CACHE ARCHEUS_WINDOW_BACKEND PROPERTY STRINGS NONE SDL2 GLFW)
set(ARCHEUS_STD_WINDOW_BACKEND "NONE" CACHE STRING "Window Backend to build with")
set_property(CACHE ARCHEUS_STD_WINDOW_BACKEND PROPERTY STRINGS NONE SDL2 GLFW)
set(ARCHEUS_INPUT_BACKEND "NONE" CACHE STRING "Input Backend to build with, most likely should match Window Backend")
set_property(CACHE ARCHEUS_INPUT_BACKEND PROPERTY STRINGS NONE SDL2 GLFW)
set(ARCHEUS_STD_INPUT_BACKEND "NONE" CACHE STRING "Input Backend to build with, most likely should match Window Backend")
set_property(CACHE ARCHEUS_STD_INPUT_BACKEND PROPERTY STRINGS NONE SDL2 GLFW)
set(ARCHEUS_GRAPHICS_BACKEND "NONE" CACHE STRING "Graphics Backend to build with")
set_property(CACHE ARCHEUS_GRAPHICS_BACKEND PROPERTY STRINGS NONE SDL2 OPENGL)
set(ARCHEUS_STD_GRAPHICS_BACKEND "NONE" CACHE STRING "Graphics Backend to build with")
set_property(CACHE ARCHEUS_STD_GRAPHICS_BACKEND PROPERTY STRINGS NONE SDL2 OPENGL)
if(UNIX)
set(ARCHEUS_CONSOLE_BACKEND "NONE" CACHE STRING "Console Backend to build with")
set_property(CACHE ARCHEUS_CONSOLE_BACKEND PROPERTY STRINGS NONE NCURSES)
set(ARCHEUS_STD_SSH_BACKEND "NONE" CACHE STRING "SSH Backend to build with")
set_property(CACHE ARCHEUS_STD_GRAPHICS_BACKEND PROPERTY STRINGS NONE LIBSSH)
set(ARCHEUS_SSH_BACKEND "NONE" CACHE STRING "SSH Backend to build with")
set_property(CACHE ARCHEUS_SSH_BACKEND PROPERTY STRINGS NONE LIBSSH)
set(ARCHEUS_DBUS_BACKEND "NONE" CACHE STRING "DBus Backend to build with")
set_property(CACHE ARCHEUS_DBUS_BACKEND PROPERTY STRINGS NONE LIBDBUS)
endif()
# ~ INIT VARIABLES ~ #
set(ARCHEUS_STD_FLAGS "")
set(ARCHEUS_STD_LIBRARIES "")
set(ARCHEUS_FLAGS "")
set(ARCHEUS_LIBRARIES "")
set(ARCHEUS_STD_INCLUDE_DIRECTORIES
set(ARCHEUS_INCLUDE_DIRECTORIES
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
set(ARCHEUS_STD_LINK_LIBRARIES
set(ARCHEUS_LINK_LIBRARIES
PUBLIC m
)
# ~ ARCHEUS_SOURCES ~ #
set(ARCHEUS_STD_SOURCES
set(ARCHEUS_SOURCES
src/std/chemical.c
src/std/errno.c
src/std/handler.c
@ -83,46 +88,43 @@ set(ARCHEUS_STD_SOURCES
src/engine/state.c
)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
string(APPEND ARCHEUS_STD_FLAGS "-Wall -Werror -g -ggdb -DARC_DEBUG ")
endif()
# TODO: replace this with a better system
if(ARCHEUS_STD_DEFAULT_CONFIG)
string(APPEND ARCHEUS_STD_FLAGS "-DARC_DEFAULT_CONFIG ")
endif()
# ~ NONE ~ #
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/archeus_none.cmake)
none_check_and_init_needed(ARCHEUS_STD_FLAGS ARCHEUS_STD_SOURCES ${ARCHEUS_STD_WINDOW_BACKEND} ${ARCHEUS_STD_INPUT_BACKEND} ${ARCHEUS_STD_GRAPHICS_BACKEND})
# ~ NCURSES ~ #
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/archeus_ncurses.cmake)
ncurses_check_and_init_needed(ARCHEUS_STD_FLAGS ARCHEUS_STD_SOURCES ${ARCHEUS_STD_CONSOLE_BACKEND})
none_check_and_init_needed(ARCHEUS_FLAGS ARCHEUS_SOURCES ${ARCHEUS_WINDOW_BACKEND} ${ARCHEUS_INPUT_BACKEND} ${ARCHEUS_GRAPHICS_BACKEND})
# ~ SDL2 ~ #
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/archeus_sdl2.cmake)
sdl2_check_and_init_needed(ARCHEUS_STD_SOURCES ARCHEUS_STD_INCLUDE_DIRECTORIES ARCHEUS_STD_LINK_LIBRARIES ${ARCHEUS_STD_WINDOW_BACKEND} ${ARCHEUS_STD_INPUT_BACKEND} ${ARCHEUS_STD_GRAPHICS_BACKEND})
sdl2_check_and_init_needed(ARCHEUS_SOURCES ARCHEUS_INCLUDE_DIRECTORIES ARCHEUS_LINK_LIBRARIES ${ARCHEUS_WINDOW_BACKEND} ${ARCHEUS_INPUT_BACKEND} ${ARCHEUS_GRAPHICS_BACKEND})
# ~ OPENGL ~ #
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/archeus_opengl.cmake)
opengl_check_and_init_needed(ARCHEUS_STD_FLAGS ARCHEUS_STD_SOURCES ${ARCHEUS_STD_GRAPHICS_BACKEND})
opengl_check_and_init_needed(ARCHEUS_FLAGS ARCHEUS_SOURCES ${ARCHEUS_GRAPHICS_BACKEND})
# ~ GLFW ~ #
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/archeus_glfw.cmake)
glfw_check_and_init_needed(ARCHEUS_STD_FLAGS ARCHEUS_STD_SOURCES ${ARCHEUS_STD_WINDOW_BACKEND} ${ARCHEUS_STD_INPUT_BACKEND})
glfw_check_and_init_needed(ARCHEUS_FLAGS ARCHEUS_SOURCES ${ARCHEUS_WINDOW_BACKEND} ${ARCHEUS_INPUT_BACKEND})
# ~ LIBSSH ~ #
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/archeus_libssh.cmake)
libssh_check_and_init_needed(ARCHEUS_STD_FLAGS ARCHEUS_STD_SOURCES ${ARCHEUS_STD_SSH_BACKEND})
if(UNIX)
# ~ NCURSES ~ #
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/archeus_ncurses.cmake)
ncurses_check_and_init_needed(ARCHEUS_FLAGS ARCHEUS_SOURCES ${ARCHEUS_CONSOLE_BACKEND})
#if(ARCHEUS_STD_GLEW)
# string(APPEND ARCHEUS_STD_FLAGS "-DARC_GLEW ")
# ~ LIBSSH ~ #
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/archeus_libssh.cmake)
libssh_check_and_init_needed(ARCHEUS_FLAGS ARCHEUS_SOURCES ${ARCHEUS_SSH_BACKEND})
# ~ LIBDBUS ~ #
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/archeus_libdbus.cmake)
libdbus_check_and_init_needed(ARCHEUS_SOURCES ARCHEUS_INCLUDE_DIRECTORIES ARCHEUS_LINK_LIBRARIES ${ARCHEUS_DBUS_BACKEND})
endif()
#if(ARCHEUS_GLEW)
# string(APPEND ARCHEUS_FLAGS "-DARC_GLEW ")
#endif()
set(CMAKE_C_FLAGS ${ARCHEUS_STD_FLAGS})
set(CMAKE_C_FLAGS ${ARCHEUS_FLAGS})
if(ARCHEUS_STD_TESTS)
if(ARCHEUS_TESTS)
add_executable(tests
tests/test.c
@ -134,32 +136,32 @@ if(ARCHEUS_STD_TESTS)
#tests/std/parser/parserlang.c
#tests/std/vector.c
${ARCHEUS_STD_SOURCES}
${ARCHEUS_SOURCES}
)
target_compile_options(tests PUBLIC "-DARC_DEBUG_LOG_STREAM_OVERRIDE")
target_include_directories(tests ${ARCHEUS_STD_INCLUDE_DIRECTORIES})
target_link_libraries(tests ${ARCHEUS_STD_LINK_LIBRARIES})
target_include_directories(tests ${ARCHEUS_INCLUDE_DIRECTORIES})
target_link_libraries(tests ${ARCHEUS_LINK_LIBRARIES})
endif()
if(WIN32 AND NOT MSVC)
add_library(archeus_std STATIC ${ARCHEUS_STD_SOURCES})
add_library(archeus STATIC ${ARCHEU_SOURCES})
else()
add_library(archeus_std SHARED ${ARCHEUS_STD_SOURCES})
add_library(archeus SHARED ${ARCHEUS_SOURCES})
endif()
target_include_directories(archeus_std ${ARCHEUS_STD_INCLUDE_DIRECTORIES})
target_include_directories(archeus ${ARCHEUS_INCLUDE_DIRECTORIES})
target_link_libraries(archeus_std ${ARCHEUS_STD_LINK_LIBRARIES})
target_link_libraries(archeus ${ARCHEUS_LINK_LIBRARIES})
install(TARGETS archeus_std EXPORT archeus_std_Exports
install(TARGETS archeus EXPORT archeus_Exports
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(EXPORT archeus_std_Exports
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/archeus_std-${PROJECT_VERSION}
install(EXPORT archeus_Exports
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/archeus-${PROJECT_VERSION}
)
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/
@ -173,22 +175,22 @@ set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR})
set(LIBRARY_INSTALL_BIN ${CMAKE_INSTALL_LIBDIR})
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/archeus_std-config.cmake.in"
"${PROJECT_BINARY_DIR}/archeus_std-config.cmake"
"${PROJECT_SOURCE_DIR}/cmake/archeus-config.cmake.in"
"${PROJECT_BINARY_DIR}/archeus-config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/archeus_std-${PROJECT_VERSION}
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/archeus-${PROJECT_VERSION}
PATH_VARS INCLUDE_INSTALL_DIR LIBRARY_INSTALL_BIN
)
write_basic_package_version_file(
"archeus_std-ConfigVersion.cmake"
"archeus-ConfigVersion.cmake"
VERSION {PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/archeus_std-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/archeus_std-ConfigVersion.cmake
${CMAKE_CURRENT_BINARY_DIR}/archeus-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/archeus-ConfigVersion.cmake
DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/archeus_std-${PROJECT_VERSION}
${CMAKE_INSTALL_LIBDIR}/cmake/archeus-${PROJECT_VERSION}
)

View file

@ -0,0 +1,9 @@
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@_Exports.cmake")
set_and_check(ARCHEUS_INCLUDE_DIRS "@PACKAGE_INCLUDE_INSTALL_DIR@")
set_and_check(ARCHEUS_LINK_DIRS "@PACKAGE_LIBRARY_INSTALL_BIN@")
set(ARCHEUS_LIBRARIES "@PROJECT_NAME@")
check_required_components("@PROJECT_NAME@")

View file

@ -1,26 +1,26 @@
set(ARCHEUS_STD_GLFW_WINDOW_SOURCES
set(ARCHEUS_GLFW_WINDOW_SOURCES
src/graphics/glfw/config.c
src/graphics/glfw/renderer.c
src/graphics/glfw/window.c
)
set(ARCHEUS_STD_GLFW_INPUT_SOURCES
set(ARCHEUS_GLFW_INPUT_SOURCES
src/input/glfw/keyboard.c
src/input/glfw/mouse.c
)
function(glfw_check_and_init_needed _ARCHEUS_STD_FLAGS _ARCHEUS_STD_SOURCES ARCHEUS_STD_WINDOW_BACKEND ARCHEUS_STD_INPUT_BACKEND)
function(glfw_check_and_init_needed _ARCHEUS_FLAGS _ARCHEUS_SOURCES ARCHEUS_WINDOW_BACKEND ARCHEUS_INPUT_BACKEND)
#add matching files for the selected backends
if(${ARCHEUS_STD_WINDOW_BACKEND} STREQUAL "GLFW")
string(APPEND ${_ARCHEUS_STD_FLAGS} "-lglfw -DARC_GLFW_WINDOW ")
list(APPEND ${_ARCHEUS_STD_SOURCES} ${ARCHEUS_STD_GLFW_WINDOW_SOURCES})
if(${ARCHEUS_WINDOW_BACKEND} STREQUAL "GLFW")
string(APPEND ${_ARCHEUS_FLAGS} "-lglfw -DARC_GLFW_WINDOW ")
list(APPEND ${_ARCHEUS_SOURCES} ${ARCHEUS_GLFW_WINDOW_SOURCES})
endif()
if(${ARCHEUS_STD_INPUT_BACKEND} STREQUAL "GLFW")
string(APPEND ${_ARCHEUS_STD_FLAGS} "-lglfw -lGLEW -DARC_GLFW_INPUT ")
list(APPEND ${_ARCHEUS_STD_SOURCES} ${ARCHEUS_STD_GLFW_INPUT_SOURCES})
if(${ARCHEUS_INPUT_BACKEND} STREQUAL "GLFW")
string(APPEND ${_ARCHEUS_FLAGS} "-lglfw -lGLEW -DARC_GLFW_INPUT ")
list(APPEND ${_ARCHEUS_SOURCES} ${ARCHEUS_GLFW_INPUT_SOURCES})
endif()
set(${_ARCHEUS_STD_FLAGS} ${${_ARCHEUS_STD_FLAGS}} PARENT_SCOPE)
set(${_ARCHEUS_STD_SOURCES} ${${_ARCHEUS_STD_SOURCES}} PARENT_SCOPE)
endfunction()
set(${_ARCHEUS_FLAGS} ${${_ARCHEUS_FLAGS}} PARENT_SCOPE)
set(${_ARCHEUS_SOURCES} ${${_ARCHEUS_SOURCES}} PARENT_SCOPE)
endfunction()

View file

@ -0,0 +1,27 @@
set(ARCHEUS_LIBDBUS_DBUS_SOURCES
packages/linux/dbus/libdbus/dbus.c
packages/linux/dbus/libdbus/helpers.c
)
function(libdbus_check_and_init_needed _ARCHEUS_SOURCES _ARCHEUS_INCLUDE_DIRECTORIES _ARCHEUS_LINK_LIBRARIES ARCHEUS_DBUS_BACKEND)
#add matching files for the selected backends
if(${ARCHEUS_DBUS_BACKEND} STREQUAL "LIBDBUS")
find_package(PkgConfig REQUIRED)
pkg_check_modules(DBUS REQUIRED dbus-1)
list(APPEND ${_ARCHEUS_SOURCES} ${ARCHEUS_LIBDBUS_DBUS_SOURCES})
#add to include directories
list(APPEND ${_ARCHEUS_INCLUDE_DIRECTORIES}
PUBLIC ${DBUS_INCLUDE_DIRS}
)
list(APPEND ${_ARCHEUS_LINK_LIBRARIES}
PUBLIC ${DBUS_LIBRARIES}
)
endif()
set(${_ARCHEUS_SOURCES} ${${_ARCHEUS_SOURCES}} PARENT_SCOPE)
set(${_ARCHEUS_INCLUDE_DIRECTORIES} ${${_ARCHEUS_INCLUDE_DIRECTORIES}} PARENT_SCOPE)
set(${_ARCHEUS_LINK_LIBRARIES} ${${_ARCHEUS_LINK_LIBRARIES}} PARENT_SCOPE)
endfunction()

View file

@ -1,14 +1,14 @@
set(ARCHEUS_STD_LIBSSH_SSH_SOURCES
packages/networking/libssh/ssh.c
set(ARCHEUS_LIBSSH_SSH_SOURCES
packages/linux/ssh/libssh/ssh.c
)
function(libssh_check_and_init_needed _ARCHEUS_STD_FLAGS _ARCHEUS_STD_SOURCES ARCHEUS_STD_SSH_BACKEND)
function(libssh_check_and_init_needed _ARCHEUS_FLAGS _ARCHEUS_SOURCES ARCHEUS_SSH_BACKEND)
#add matching files for the selected backends
if(${ARCHEUS_STD_SSH_BACKEND} STREQUAL "LIBSSH")
string(APPEND ${_ARCHEUS_STD_FLAGS} "-lssh ")
list(APPEND ${_ARCHEUS_STD_SOURCES} ${ARCHEUS_STD_LIBSSH_SSH_SOURCES})
if(${ARCHEUS_SSH_BACKEND} STREQUAL "LIBSSH")
string(APPEND ${_ARCHEUS_FLAGS} "-lssh ")
list(APPEND ${_ARCHEUS_SOURCES} ${ARCHEUS_LIBSSH_SSH_SOURCES})
endif()
set(${_ARCHEUS_STD_FLAGS} ${${_ARCHEUS_STD_FLAGS}} PARENT_SCOPE)
set(${_ARCHEUS_STD_SOURCES} ${${_ARCHEUS_STD_SOURCES}} PARENT_SCOPE)
set(${_ARCHEUS_FLAGS} ${${_ARCHEUS_FLAGS}} PARENT_SCOPE)
set(${_ARCHEUS_SOURCES} ${${_ARCHEUS_SOURCES}} PARENT_SCOPE)
endfunction()

View file

@ -1,19 +1,19 @@
set(ARCHEUS_STD_NCURSES_CONSOLE_SOURCES
packages/console/ncurses/element.c
packages/console/ncurses/key.c
packages/console/ncurses/view.c
set(ARCHEUS_NCURSES_CONSOLE_SOURCES
packages/linux/console/ncurses/element.c
packages/linux/console/ncurses/key.c
packages/linux/console/ncurses/view.c
packages/console/ncurses/shell.c
packages/console/ncurses/buffer.c
packages/linux/console/ncurses/shell.c
packages/linux/console/ncurses/buffer.c
)
function(ncurses_check_and_init_needed _ARCHEUS_STD_FLAGS _ARCHEUS_STD_SOURCES ARCHEUS_STD_CONSOLE_BACKEND)
function(ncurses_check_and_init_needed _ARCHEUS_FLAGS _ARCHEUS_SOURCES ARCHEUS_CONSOLE_BACKEND)
#add matching files for the selected backends
if(${ARCHEUS_STD_CONSOLE_BACKEND} STREQUAL "NCURSES")
string(APPEND ${_ARCHEUS_STD_FLAGS} "-lncurses ")
list(APPEND ${_ARCHEUS_STD_SOURCES} ${ARCHEUS_STD_NCURSES_CONSOLE_SOURCES})
if(${ARCHEUS_CONSOLE_BACKEND} STREQUAL "NCURSES")
string(APPEND ${_ARCHEUS_FLAGS} "-lncurses ")
list(APPEND ${_ARCHEUS_SOURCES} ${ARCHEUS_NCURSES_CONSOLE_SOURCES})
endif()
set(${_ARCHEUS_STD_FLAGS} ${${_ARCHEUS_STD_FLAGS}} PARENT_SCOPE)
set(${_ARCHEUS_STD_SOURCES} ${${_ARCHEUS_STD_SOURCES}} PARENT_SCOPE)
set(${_ARCHEUS_FLAGS} ${${_ARCHEUS_FLAGS}} PARENT_SCOPE)
set(${_ARCHEUS_SOURCES} ${${_ARCHEUS_SOURCES}} PARENT_SCOPE)
endfunction()

View file

@ -1,14 +1,14 @@
set(ARCHEUS_STD_NONE_WINDOW_SOURCES
set(ARCHEUS_NONE_WINDOW_SOURCES
src/graphics/window.c
)
set(ARCHEUS_STD_NONE_INPUT_SOURCES
set(ARCHEUS_NONE_INPUT_SOURCES
src/input/input.c
src/input/keyboard.c
src/input/mouse.c
)
set(ARCHEUS_STD_NONE_GRAPHICS_SOURCES
set(ARCHEUS_NONE_GRAPHICS_SOURCES
src/graphics/circle.c
src/graphics/config.c
src/graphics/line.c
@ -20,23 +20,23 @@ set(ARCHEUS_STD_NONE_GRAPHICS_SOURCES
src/graphics/text.c
)
function(none_check_and_init_needed _ARCHEUS_STD_FLAGS _ARCHEUS_STD_SOURCES ARCHEUS_STD_WINDOW_BACKEND ARCHEUS_STD_INPUT_BACKEND ARCHEUS_STD_GRAPHICS_BACKEND)
function(none_check_and_init_needed _ARCHEUS_FLAGS _ARCHEUS_SOURCES ARCHEUS_WINDOW_BACKEND ARCHEUS_INPUT_BACKEND ARCHEUS_GRAPHICS_BACKEND)
#add matching files for the selected backends
if(${ARCHEUS_STD_WINDOW_BACKEND} STREQUAL "NONE")
string(APPEND ${_ARCHEUS_STD_FLAGS} "-DARC_NONE_WINDOW ")
list(APPEND ${_ARCHEUS_STD_SOURCES} ${ARCHEUS_STD_NONE_WINDOW_SOURCES})
if(${ARCHEUS_WINDOW_BACKEND} STREQUAL "NONE")
string(APPEND ${_ARCHEUS_FLAGS} "-DARC_NONE_WINDOW ")
list(APPEND ${_ARCHEUS_SOURCES} ${ARCHEUS_NONE_WINDOW_SOURCES})
endif()
if(${ARCHEUS_STD_INPUT_BACKEND} STREQUAL "NONE")
string(APPEND ${_ARCHEUS_STD_FLAGS} "-DARC_NONE_INPUT ")
list(APPEND ${_ARCHEUS_STD_SOURCES} ${ARCHEUS_STD_NONE_INPUT_SOURCES})
if(${ARCHEUS_INPUT_BACKEND} STREQUAL "NONE")
string(APPEND ${_ARCHEUS_FLAGS} "-DARC_NONE_INPUT ")
list(APPEND ${_ARCHEUS_SOURCES} ${ARCHEUS_NONE_INPUT_SOURCES})
endif()
if(${ARCHEUS_STD_GRAPHICS_BACKEND} STREQUAL "NONE")
string(APPEND ${_ARCHEUS_STD_FLAGS} "-DARC_NONE_GRAPHICS ")
list(APPEND ${_ARCHEUS_STD_SOURCES} ${ARCHEUS_STD_NONE_GRAPHICS_SOURCES})
if(${ARCHEUS_GRAPHICS_BACKEND} STREQUAL "NONE")
string(APPEND ${_ARCHEUS_FLAGS} "-DARC_NONE_GRAPHICS ")
list(APPEND ${_ARCHEUS_SOURCES} ${ARCHEUS_NONE_GRAPHICS_SOURCES})
endif()
set(${_ARCHEUS_STD_FLAGS} ${${_ARCHEUS_STD_FLAGS}} PARENT_SCOPE)
set(${_ARCHEUS_STD_SOURCES} ${${_ARCHEUS_STD_SOURCES}} PARENT_SCOPE)
endfunction()
set(${_ARCHEUS_FLAGS} ${${_ARCHEUS_FLAGS}} PARENT_SCOPE)
set(${_ARCHEUS_SOURCES} ${${_ARCHEUS_SOURCES}} PARENT_SCOPE)
endfunction()

View file

@ -1,4 +1,4 @@
set(ARCHEUS_STD_OPENGL_GRAPHICS_SOURCES
set(ARCHEUS_OPENGL_GRAPHICS_SOURCES
packages/graphics/opengl/circle.c
packages/graphics/opengl/line.c
packages/graphics/opengl/obround.c
@ -8,13 +8,13 @@ set(ARCHEUS_STD_OPENGL_GRAPHICS_SOURCES
packages/graphics/opengl/text.c
)
function(opengl_check_and_init_needed _ARCHEUS_STD_FLAGS _ARCHEUS_STD_SOURCES ARCHEUS_STD_GRAPHICS_BACKEND)
function(opengl_check_and_init_needed _ARCHEUS_FLAGS _ARCHEUS_SOURCES ARCHEUS_GRAPHICS_BACKEND)
#add matching files for the selected backends
if(${ARCHEUS_STD_GRAPHICS_BACKEND} STREQUAL "OPENGL")
string(APPEND ${_ARCHEUS_STD_FLAGS} "-lGL -DARC_OPENGL_GRAPHICS ")
list(APPEND ${_ARCHEUS_STD_SOURCES} ${ARCHEUS_STD_OPENGL_GRAPHICS_SOURCES})
if(${ARCHEUS_GRAPHICS_BACKEND} STREQUAL "OPENGL")
string(APPEND ${_ARCHEUS_FLAGS} "-lGL -DARC_OPENGL_GRAPHICS ")
list(APPEND ${_ARCHEUS_SOURCES} ${ARCHEUS_OPENGL_GRAPHICS_SOURCES})
endif()
set(${_ARCHEUS_STD_FLAGS} ${${_ARCHEUS_STD_FLAGS}} PARENT_SCOPE)
set(${_ARCHEUS_STD_SOURCES} ${${_ARCHEUS_STD_SOURCES}} PARENT_SCOPE)
endfunction()
set(${_ARCHEUS_FLAGS} ${${_ARCHEUS_FLAGS}} PARENT_SCOPE)
set(${_ARCHEUS_SOURCES} ${${_ARCHEUS_SOURCES}} PARENT_SCOPE)
endfunction()

View file

@ -1,9 +1,9 @@
set(ARCHEUS_STD_SDL2_WINDOW_SOURCES
set(ARCHEUS_SDL2_WINDOW_SOURCES
packages/graphics/sdl/window.c
packages/graphics/sdl/renderer.c
)
set(ARCHEUS_STD_SDL2_INPUT_SOURCES
set(ARCHEUS_SDL2_INPUT_SOURCES
packages/input/sdl/input.c
packages/input/sdl/keyboard.c
packages/input/sdl/mouse.c
@ -12,7 +12,7 @@ set(ARCHEUS_STD_SDL2_INPUT_SOURCES
packages/audio/sdl/config.c
)
set(ARCHEUS_STD_SDL2_GRAPHICS_SOURCES
set(ARCHEUS_SDL2_GRAPHICS_SOURCES
packages/graphics/sdl/circle.c
packages/graphics/sdl/config.c
packages/graphics/sdl/line.c
@ -23,9 +23,9 @@ set(ARCHEUS_STD_SDL2_GRAPHICS_SOURCES
packages/graphics/sdl/text.c
)
function(sdl2_check_and_init_needed _ARCHEUS_STD_SOURCES _ARCHEUS_STD_INCLUDE_DIRECTORIES _ARCHEUS_STD_LINK_LIBRARIES ARCHEUS_STD_WINDOW_BACKEND ARCHEUS_STD_INPUT_BACKEND ARCHEUS_STD_GRAPHICS_BACKEND)
function(sdl2_check_and_init_needed _ARCHEUS_SOURCES _ARCHEUS_INCLUDE_DIRECTORIES _ARCHEUS_LINK_LIBRARIES ARCHEUS_WINDOW_BACKEND ARCHEUS_INPUT_BACKEND ARCHEUS_GRAPHICS_BACKEND)
#if no backend uses sdl return
if(NOT ${ARCHEUS_STD_WINDOW_BACKEND} STREQUAL "SDL2" AND NOT ${ARCHEUS_STD_INPUT_BACKEND} STREQUAL "SDL2" AND NOT ${ARCHEUS_STD_GRAPHICS_BACKEND} STREQUAL "SDL2")
if(NOT ${ARCHEUS_WINDOW_BACKEND} STREQUAL "SDL2" AND NOT ${ARCHEUS_INPUT_BACKEND} STREQUAL "SDL2" AND NOT ${ARCHEUS_GRAPHICS_BACKEND} STREQUAL "SDL2")
return()
endif()
@ -33,51 +33,56 @@ function(sdl2_check_and_init_needed _ARCHEUS_STD_SOURCES _ARCHEUS_STD_INCLUDE_DI
find_package(SDL2 REQUIRED)
#add to include directories
list(APPEND ${_ARCHEUS_STD_INCLUDE_DIRECTORIES}
list(APPEND ${_ARCHEUS_INCLUDE_DIRECTORIES}
PRIVATE ${SDL2_INCLUDE_DIRS}
)
#add to link libraries
list(APPEND ${_ARCHEUS_STD_LINK_LIBRARIES}
list(APPEND ${_ARCHEUS_LINK_LIBRARIES}
PUBLIC ${SDL2_LIBRARIES}
)
#add matching files for the selected backends
if(${ARCHEUS_STD_WINDOW_BACKEND} STREQUAL "SDL2")
list(APPEND ${_ARCHEUS_STD_SOURCES} ${ARCHEUS_STD_SDL2_WINDOW_SOURCES})
if(${ARCHEUS_WINDOW_BACKEND} STREQUAL "SDL2")
list(APPEND ${_ARCHEUS_SOURCES} ${ARCHEUS_SDL2_WINDOW_SOURCES})
endif()
if(${ARCHEUS_STD_INPUT_BACKEND} STREQUAL "SDL2")
if(${ARCHEUS_INPUT_BACKEND} STREQUAL "SDL2")
#TODO: remove this
find_package(SDL2_mixer REQUIRED)
list(APPEND ${_ARCHEUS_STD_SOURCES} ${ARCHEUS_STD_SDL2_INPUT_SOURCES})
list(APPEND ${_ARCHEUS_SOURCES} ${ARCHEUS_SDL2_INPUT_SOURCES})
#TODO: remove this
list(APPEND ${_ARCHEUS_STD_LINK_LIBRARIES}
list(APPEND ${_ARCHEUS_LINK_LIBRARIES}
PUBLIC SDL2_mixer::SDL2_mixer
)
endif()
if(${ARCHEUS_STD_GRAPHICS_BACKEND} STREQUAL "SDL2")
if(${ARCHEUS_GRAPHICS_BACKEND} STREQUAL "SDL2")
find_package(SDL2_image REQUIRED)
find_package(SDL2_ttf REQUIRED)
list(APPEND ${_ARCHEUS_STD_SOURCES} ${ARCHEUS_STD_SDL2_GRAPHICS_SOURCES})
find_package(PkgConfig REQUIRED)
pkg_check_modules(SDL2_GFX REQUIRED SDL2_gfx)
list(APPEND ${_ARCHEUS_SOURCES} ${ARCHEUS_SDL2_GRAPHICS_SOURCES})
#add to include directories
list(APPEND ${_ARCHEUS_STD_INCLUDE_DIRECTORIES}
list(APPEND ${_ARCHEUS_INCLUDE_DIRECTORIES}
PRIVATE ${SDL2IMAGE_INCLUDE_DIRS}
PRIVATE ${SDL2_GFX_INCLUDE_DIRS}
)
#add to link libraries
list(APPEND ${_ARCHEUS_STD_LINK_LIBRARIES}
list(APPEND ${_ARCHEUS_LINK_LIBRARIES}
PUBLIC SDL2_image::SDL2_image
PUBLIC SDL2_ttf::SDL2_ttf
PUBLIC ${SDL2_GFX_LIBRARIES}
)
endif()
set(${_ARCHEUS_STD_SOURCES} ${${_ARCHEUS_STD_SOURCES}} PARENT_SCOPE)
set(${_ARCHEUS_STD_INCLUDE_DIRECTORIES} ${${_ARCHEUS_STD_INCLUDE_DIRECTORIES}} PARENT_SCOPE)
set(${_ARCHEUS_STD_LINK_LIBRARIES} ${${_ARCHEUS_STD_LINK_LIBRARIES}} PARENT_SCOPE)
set(${_ARCHEUS_SOURCES} ${${_ARCHEUS_SOURCES}} PARENT_SCOPE)
set(${_ARCHEUS_INCLUDE_DIRECTORIES} ${${_ARCHEUS_INCLUDE_DIRECTORIES}} PARENT_SCOPE)
set(${_ARCHEUS_LINK_LIBRARIES} ${${_ARCHEUS_LINK_LIBRARIES}} PARENT_SCOPE)
endfunction()

View file

@ -1,9 +0,0 @@
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@_Exports.cmake")
set_and_check(ARCHEUS_STD_INCLUDE_DIRS "@PACKAGE_INCLUDE_INSTALL_DIR@")
set_and_check(ARCHEUS_STD_LINK_DIRS "@PACKAGE_LIBRARY_INSTALL_BIN@")
set(ARCHEUS_STD_LIBRARIES "@PROJECT_NAME@")
check_required_components("@PROJECT_NAME@")

206
doc/style.md Normal file
View file

@ -0,0 +1,206 @@
# Introduction
This document outlines the style for any C code that is to be stored within this repository. This document will most likely be changed over time as the style becomes more set.
# The Basic Tenets of This Style
- Readability is the main goal of following this style
- Consistancy should never be compromised
- When creating memory, said memory should be freed within the same scope
- If the last tenet is broken there should be a function for freeing memory and a note is to be made in documentation that memory needs to be freed after the function call
- Doxygen documentation should be applied to every header with the express goal of explaining the headers contents
# Code Layout
## Indentation
Use 4 spaces for indentation, the only exception to this rule is for multi line comments
Closing braces over multiple lines should match up with the initial declaration like:
```c
DOC_Type example = {
value1,
value2
};
```
## Maximum Number of Indents
As of now there is no maximum number of indentation, though the suggestion is avoid indentation as much as possible because in herbglitch's opinion it makes the code way less readable
## Spacing
There is no space between text and open or closing parenthesis. The only time to add spaces to a curly brace is when on one line for spacing of contents to make it more readable. Example:
```c
//function declaration
void DOC_Type_ExampleFunction(){
uint8_t exampleCheck = 1;
if(exampleCheck == 1){
printf("Here\n");
}
//curly braces with space
DOC_Type example = { value1, value2 };
}
```
## Trailing Space
As of now trailing spaces are not allowed, please message herbglitch if you find a reason to use trailing spaces
## Maximum Line Length
As of now there is no maximum line length
## Blank Lines
As of now there should never be more than two blank lines next to each other
## Organizing lines
This is up to the programmer to decide what is most readable. The suggestion is to group lines together that relate to each other. Example:
```c
void DOC_Type_ExampleFunction(){
//the first grouping
printf("Hello World!");
printf("\n");
//the next grouping
printf("Goodbye World!");
printf("\n");
}
```
## Inline functions
Do not use inline functions, always indent functions even if they are short. Example:
```c
//do not do this
uint32_t *DOC_Type_ExampleFunction(DOC_Type *type){ return type->data; }
//do this
uint32_t *DOC_Type_ExampleFunction(DOC_Type *type){
return type->data;
}
```
## Inline if, for, while, etc... Statements
Same rule as the function, also if, for, while, etc.. statements always need to have the curly braces to avoid confusion. Example:
```c
//do not do this. this could cause confusions if the next statement is accidentally indented
if(exampleCheck == 1)
exampleData = 'c';
examplePath = "temp/path.txt";
//do not do this
if(exampleCheck == 1){ exampleData = 'c'; }
//do this
if(exampleCheck == 1){
exampleData = 'c';
}
```
## Includes
Every library used in a header or c file should be included in the respective file. The include should be alphabetical in order with local files (ordered by relation) on top and library files below. If in a c file, the matching header should be separate from the other headers. Example:
```c
#include "matchingHeader.h"
#include "../../veryFarBackHeader.h"
#include "../backHeader.h"
#include "closeHeader.h"
#include "otherHeader.h"
#include "folder/forwardHeader.h"
#include "folder/nextFolder/veryFarForwardHeader.h"
#include <stdio.h>
#include <stdlib.h>
```
## Alignment of Pointer Asterisks or Ampersand
Always align an Asterisk and Ampersand with the variable and not the type. Aligning with the type can lead to confusion if multiple variables were created on the same line. Example:
```c
//do not do this, only a is created as a pointer, but it looks like b and c are also pointers
uint32_t* a, b, c;
//this is more clear
uint32_t *a, b, c;
```
## When to Pass a Value as a Pointer
The only time to pass a value as a pointer is if:
- It cannot be copied
- It is being modified
# Header Layout
## Include Guards
Include guards should match the file name. It is also recommended to have your namespace and path as part of the include guard to avoid confliction. Example:
```c
// archeus/include/arc/std/vector.h
#ifndef ARC_STD_VECTOR_H_
#define ARC_STD_VECTOR_H_
// header contents here
#endif // !ARC_STD_VECTOR_H_
```
## Boilerplate
The recommendation is after the header guards to wrap the header content with a c++ check so that the code can be used in a c++ project as well. Example:
```c
//include guard
#ifdef __cplusplus
extern "C" {
#endif
// header contents here
#ifdef __cplusplus
}
#endif
//end include guard
```
# Comments
Document all headers with doxygen commenting, there probably shouldn't be any other comment in the header.
For the c file, the recommendation is to break up blocks with comments describing what a block does. It is up to the programmer though because there are times when adding a comment would only be redundant if the code describes what it does. herbglitch likes to think of comments in the c file as like markdown headers, basically easy ways to see what parts of the code do what, which makes it easier to jump back into the code
# Naming Conventions
Before getting into naming conventions it is important to note that this style uses namespaces in all caps separated by an underscore. The recommendation is to have the namespace be as short as possible so like:
```
DOC_
ARC_
TBYTE_
NAMESPACE_
```
## Types
Every type should be upper camel case with the namespace before the type name, like:
```c
typedef struct DOC_Type DOC_Type;
typedef struct DOC_LongerType DOC_LongerType;
```
## Defines and Constants
Defines and constants should be in all caps with a namespace and as descriptive as possible, like:
```c
#define DOC_MEMORY_BLOCK_SIZE 6
const uint8_t DOC_LOBY_MAX_ENTITIES 12;
```
## Functions
Every function should be in upper camel case and have the main type it is modifying (the first parameter) as part of the function name separated by an underscore, like:
```c
void DOC_Type_Example(){
//function contents
}
int32_t DOC_Type_GetValue(){
return 0;
}
```
## Callbacks
Callbacks are the same as functions but end with Fn, like:
```c
typedef void (* DOC_Type_CallbackFn)();
typedef DOC_Bool (* DOC_Type_PollDataFn)(void *userdata);
```
## Variables
Variables are lower camel case and should be as self documenting as possible, do not use acronyms (type out the full thing). Also using one letter is usually not recommended (x, y, and in for loops i can sometimes be ok). Remember readability is crucial.
# Herb's Suggestions
I'd suggest avoiding ternary operators, else, and else if statements as much as possible. Usually returning instead of else statements makes the code more readable in my opinion. Also ternary operators almost always can be made more readable if put into an if statement.

View file

@ -0,0 +1,38 @@
#ifndef ARC_DBUS_H_
#define ARC_DBUS_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <dbus/dbus.h>
#include <arc/std/vector.h>
/**
* @brief
*/
typedef struct ARC_DBus ARC_DBus;
void ARC_DBus_Create(ARC_DBus **dbus);
void ARC_DBus_Destroy(ARC_DBus *dbus);
//Docs: https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Request.html#org-freedesktop-portal-request-response
void ARC_DBus_RequestResponse();
//Docs: https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.GlobalShortcuts.html#org-freedesktop-portal-globalshortcuts-createsession
void ARC_DBus_InitSession(ARC_DBus *dbus);
//Docs: https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.GlobalShortcuts.html#org-freedesktop-portal-globalshortcuts-bindshortcuts
//NOTE: this is a vector of ARC_DBusShortcut
void ARC_DBus_BindShortcuts(ARC_DBus *dbus, ARC_Vector *dbusShortcutVector);
//NOTE: https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.GlobalShortcuts.html#org-freedesktop-portal-globalshortcuts-listshortcuts
void ARC_DBus_ListShortcuts(ARC_DBus *dbus);
#ifdef __cplusplus
}
#endif
#endif // !ARC_DBUS_H_

View file

@ -0,0 +1,55 @@
#ifndef ARC_DBUS_HELPER_H_
#define ARC_DBUS_HELPER_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <dbus/dbus.h>
/**
* @brief
*/
typedef struct ARC_DBus ARC_DBus;
/**
* @brief
*
* @param[in] dbus
* @param[in] interface
* @param[in] objectPath
*/
void ARC_DBusHelper_BusRequestName(ARC_DBus *dbus, const char *interface, const char *objectPath);
/**
* @brief
*
* @param[in] dbus
* @param[in] interface
* @param[in] objectPath
* @param[in] member
*/
void ARC_DBusHelper_BusAddMatch(ARC_DBus *dbus, const char *interface, const char *objectPath, const char *member);
/**
* @brief
*
* @param[in] message
*/
void ARC_DBusHelper_HandleSignal(DBusMessage *message);
/**
* @brief
*
* @param[in] dictonaryIter
* @param[in] stringKey
* @param[in] varientStringValue
*/
void ARC_DBusHelper_AddStringVarientStringToMessageIterDictionary(DBusMessageIter *dictonaryIter, const char *stringKey, const char *varientStringValue);
#ifdef __cplusplus
}
#endif
#endif // !ARC_DBUS_HELPER_H_

View file

@ -13,6 +13,18 @@ typedef struct ARC_Circle {
int32_t r;
} ARC_Circle;
typedef struct ARC_FCircle {
float x;
float y;
float r;
} ARC_FCircle;
typedef struct ARC_DCircle {
double x;
double y;
double r;
} ARC_DCircle;
#ifdef __cplusplus
}
#endif

View file

@ -9,15 +9,15 @@ extern "C" {
#include "arc/std/string.h"
typedef struct ARC_Config ARC_Config;
void ARC_MathConfig_Init(ARC_Config *config);
uint8_t ARC_Point_Read (ARC_Config *config, ARC_String *string, void **value);
uint8_t ARC_Rect_Read (ARC_Config *config, ARC_String *string, void **value);
uint8_t ARC_RectArray_Read(ARC_Config *config, ARC_String *string, void **value);
void ARC_Point_Delete (ARC_Config *config, ARC_String *string, void *value);
void ARC_Rect_Delete (ARC_Config *config, ARC_String *string, void *value);
void ARC_RectArray_Delete(ARC_Config *config, ARC_String *string, void *value);
//void ARC_MathConfig_Init(ARC_Config *config);
//
//uint8_t ARC_Point_Read (ARC_Config *config, ARC_String *string, void **value);
//uint8_t ARC_Rect_Read (ARC_Config *config, ARC_String *string, void **value);
//uint8_t ARC_RectArray_Read(ARC_Config *config, ARC_String *string, void **value);
//
//void ARC_Point_Delete (ARC_Config *config, ARC_String *string, void *value);
//void ARC_Rect_Delete (ARC_Config *config, ARC_String *string, void *value);
//void ARC_RectArray_Delete(ARC_Config *config, ARC_String *string, void *value);
#ifdef __cplusplus
}

View file

@ -22,6 +22,11 @@ typedef struct ARC_FPoint {
float y;
} ARC_FPoint;
typedef struct ARC_DPoint {
double x;
double y;
} ARC_DPoint;
ARC_FPoint ARC_FPoint_Lerp(ARC_FPoint *start, ARC_FPoint *end, float t);
#ifdef __cplusplus

View file

@ -61,7 +61,7 @@ void ARC_Config_AddKey(ARC_Config *config, ARC_String *type, ARC_ConfigKeyRead k
* @param keyRead function for reading/creating key from string
* @param keyDelete function for deleting stored key
*/
void ARC_Config_AddKeyCString(ARC_Config *config, const char *type, uint64_t length, ARC_ConfigKeyRead keyRead, ARC_ConfigKeyDelete keyDelete);
//void ARC_Config_AddKeyCString(ARC_Config *config, const char *type, uint64_t length, ARC_ConfigKeyRead keyRead, ARC_ConfigKeyDelete keyDelete);
/**
* @brief external callback to add keys to config
@ -99,7 +99,7 @@ void ARC_Config_SetGroup(ARC_Config *config, ARC_String *groupname);
* @param keyname name of key to get from config
* @param value data retrieved from config
*/
void ARC_Config_Get(ARC_Config *config, ARC_String *keyname, void **value);
//void ARC_Config_Get(ARC_Config *config, ARC_String *keyname, void **value);
/**
* @brief commands that can be used in ARC_Config_FileIO

View file

@ -8,36 +8,36 @@
// #define ARC_DEFAULT_CONFIG
#include "arc/std/defaults/config.h"
void ARC_AudioConfig_Init(ARC_Config *config){
ARC_Config_AddKeyCString(config, (char *)"ARC_Audio", 9, ARC_Audio_Read, ARC_Audio_Delete);
}
uint8_t ARC_Audio_Read(ARC_Config *config, ARC_String *string, void **value){
ARC_Config_Get(config, string, value);
if(*value){
return 1;
}
if(string->data[0] != '"' || string->data[string->length - 1] != '"'){
ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("in ARC_Point_Read(config, string, value); no matching quotes: %s", string->data);
arc_errno = ARC_ERRNO_DATA;
return 0;
}
ARC_Audio *audio = (ARC_Audio *)malloc(sizeof(ARC_Audio));
ARC_String *path;
ARC_String_CopySubstring(&path, string, 1, string->length - 2);
audio->chunk = Mix_LoadWAV(path->data);
//TODO: get error message if not loaded
*value = (void *)audio;
return 0;
}
void ARC_Audio_Delete(ARC_Config* config, ARC_String *string, void *value){
Mix_FreeChunk(((ARC_Audio *)value)->chunk);
free((ARC_Audio *)value);
}
//
//void ARC_AudioConfig_Init(ARC_Config *config){
// ARC_Config_AddKeyCString(config, (char *)"ARC_Audio", 9, ARC_Audio_Read, ARC_Audio_Delete);
//}
//
//uint8_t ARC_Audio_Read(ARC_Config *config, ARC_String *string, void **value){
// ARC_Config_Get(config, string, value);
// if(*value){
// return 1;
// }
//
// if(string->data[0] != '"' || string->data[string->length - 1] != '"'){
// ARC_DEBUG_LOG_ERROR_WITH_VARIABLES("in ARC_Point_Read(config, string, value); no matching quotes: %s", string->data);
// arc_errno = ARC_ERRNO_DATA;
// return 0;
// }
//
// ARC_Audio *audio = (ARC_Audio *)malloc(sizeof(ARC_Audio));
//
// ARC_String *path;
// ARC_String_CopySubstring(&path, string, 1, string->length - 2);
// audio->chunk = Mix_LoadWAV(path->data);
//
// //TODO: get error message if not loaded
//
// *value = (void *)audio;
// return 0;
//}
//
//void ARC_Audio_Delete(ARC_Config* config, ARC_String *string, void *value){
// Mix_FreeChunk(((ARC_Audio *)value)->chunk);
// free((ARC_Audio *)value);
//}

View file

@ -1,49 +1,12 @@
#include "arc/graphics/circle.h"
#include "renderer.h"
#include <stdlib.h>
#include <SDL2_gfxPrimitives.h>
//Modified from https://stackoverflow.com/questions/38334081/how-to-draw-circles-arcs-and-vector-graphics-in-sdl
void ARC_Circle_Render(ARC_Circle *circle, ARC_Renderer *renderer, ARC_Color *color){
SDL_SetRenderDrawColor((SDL_Renderer *)renderer, color->r, color->g, color->b, color->a);
int32_t diameter = (circle->r * 2);
int32_t x = (circle->r - 1);
int32_t y = 0;
int32_t tx = 1;
int32_t ty = 1;
int32_t error = (tx - diameter);
while(x >= y){
// Each of the following renders an octant of the circle
SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x + x, circle->y - y);
SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x + x, circle->y + y);
SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x - x, circle->y - y);
SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x - x, circle->y + y);
SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x + y, circle->y - x);
SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x + y, circle->y + x);
SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x - y, circle->y - x);
SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x - y, circle->y + x);
if(error <= 0){
++y;
error += ty;
ty += 2;
}
if(error > 0){
--x;
tx += 2;
error += (tx - diameter);
}
}
circleRGBA((SDL_Renderer *)renderer, (Sint16)circle->x, (Sint16)circle->y, (Sint16)circle->r, (Uint8)color->r, (Uint8)color->g, (Uint8)color->b, (Uint8)color->a);
}
//TODO: very temp
void ARC_Circle_RenderFill(ARC_Circle *circle, ARC_Renderer *renderer, ARC_Color *color){
ARC_Circle temp = *circle;
for(; temp.r; temp.r--){
ARC_Circle_Render(&temp, renderer, color);
}
}
filledCircleRGBA((SDL_Renderer *)renderer, (Sint16)circle->x, (Sint16)circle->y, (Sint16)circle->r, (Uint8)color->r, (Uint8)color->g, (Uint8)color->b, (Uint8)color->a);
}

View file

@ -17,295 +17,295 @@
// #define ARC_DEFAULT_CONFIG
#include "arc/std/defaults/config.h"
SDL_Renderer *global_renderer;
uint8_t ARC_SDL_Texture_Read(ARC_Config *config, ARC_String *string, void **value);
uint8_t ARC_Spritesheet_Read(ARC_Config *config, ARC_String *string, void **value);
uint8_t ARC_Sprite_Read (ARC_Config *config, ARC_String *string, void **value);
void ARC_SDL_Texture_Delete(ARC_Config *config, ARC_String *string, void *value);
void ARC_Spritesheet_Delete(ARC_Config *config, ARC_String *string, void *value);
void ARC_Sprite_Delete (ARC_Config *config, ARC_String *string, void *value);
void ARC_GraphicsConfig_Init(ARC_Config *config, ARC_Renderer *renderer){
global_renderer = (SDL_Renderer *)renderer;
ARC_Config_AddKeyCString(config, (char *)"SDL_Texture" , 11, ARC_SDL_Texture_Read, ARC_SDL_Texture_Delete);
ARC_Config_AddKeyCString(config, (char *)"ARC_Spritesheet", 15, ARC_Spritesheet_Read, ARC_Spritesheet_Delete);
ARC_Config_AddKeyCString(config, (char *)"ARC_Sprite" , 10, ARC_Sprite_Read , ARC_Sprite_Delete );
}
uint64_t ARC_GraphicsConfig_GetIndexAndErrorCheck(ARC_String *string, char *search, uint64_t searchLength){
uint64_t separator = ARC_String_FindCString(string, ",", 1);
if(separator == ~(uint64_t)0){
arc_errno = ARC_ERRNO_DATA;
}
return separator;
}
int32_t ARC_SDL_Texture_Load(const char *path, SDL_Texture **texture){
IMG_Init(IMG_INIT_PNG);
SDL_Surface *surface = IMG_Load(path);
if(!surface){
printf("Error: reading png '%s'\nSDL_Image Error: %s", path, IMG_GetError());
return 1; // GE_SDL_ERRNO_
}
SDL_BlendMode tempMode;
SDL_GetSurfaceBlendMode(surface, &tempMode);
*texture = SDL_CreateTextureFromSurface(global_renderer, surface);
SDL_GetTextureBlendMode(*texture, &tempMode);
SDL_FreeSurface(surface);
IMG_Quit();
return 0;
}
uint8_t ARC_SDL_Texture_Read(ARC_Config* config, ARC_String *string, void **value){
ARC_Config_Get(config, string, value);
if(*value){
return 1;
}
ARC_String *tempStr, *textureStr;
ARC_String_StripEndsWhitespace(&tempStr, string);
ARC_String_CopySubstring(&textureStr, tempStr, 1, tempStr->length - 2);
ARC_String_Destroy(tempStr);
ARC_SDL_Texture_Load(textureStr->data, (SDL_Texture **)value);
ARC_String_Destroy(textureStr);
return 0;
}
void ARC_Spritesheet_ReadTexture(ARC_Config *config, ARC_String *string, uint32_t *size, void **value){
SDL_Texture *texture;
ARC_String *tempStr, *textureStr;
ARC_String_StripEndsWhitespace(&tempStr, string);
//check for reference
ARC_Config_Get(config, tempStr, (void **)&texture);
if(!texture && (tempStr->data[0] != '"' || tempStr->data[string->length - 1] != '"')){
arc_errno = ARC_ERRNO_DATA;
}
ARC_String_CopySubstring(&textureStr, tempStr, 1, tempStr->length - 2);
ARC_String_Destroy(tempStr);
//try reading in the texture
if(!texture){
ARC_SDL_Texture_Read(config, string, (void **)&texture);
if(arc_errno){
*value = NULL;
}
}
ARC_String_Destroy(textureStr);
*value = malloc(sizeof(ARC_Spritesheet));
((ARC_Spritesheet *) *value)->texture = texture;
((ARC_Spritesheet *) *value)->size = size;
}
uint8_t ARC_Spritesheet_Read(ARC_Config* config, ARC_String *string, void **value){
if(string->data[0] != '{' || string->data[string->length - 1] != '}'){
ARC_Spritesheet_ReadTexture(config, string, NULL, value);
return 0;
}
uint64_t split = ARC_GraphicsConfig_GetIndexAndErrorCheck(string, ",", 1);
if(arc_errno){
return 0;
}
ARC_String *temp, *textureStr, *sizeStr;
ARC_String_CopySubstring(&temp, string, 1, split - 2);
ARC_String_StripEndsWhitespace(&textureStr, temp);
ARC_String_Destroy(temp);
ARC_String_CopySubstring(&temp, string, split + 1, string->length - (split + 2));
ARC_String_StripEndsWhitespace(&sizeStr, temp);
ARC_String_Destroy(temp);
uint32_t *size;
ARC_Config_Get(config, string, (void **)&size);
if(!size){
ARC_ConfigKey_Read_Uint32_t(config, sizeStr, (void **)&size);
if(arc_errno){
ARC_String_Destroy(sizeStr);
ARC_String_Destroy(textureStr);
return ARC_ERRNO_DATA;
}
}
ARC_Spritesheet_ReadTexture(config, textureStr, size, value);
ARC_String_Destroy(sizeStr);
ARC_String_Destroy(textureStr);
return 0;
}
uint8_t ARC_Sprite_Read(ARC_Config* config, ARC_String *string, void **value){
ARC_Config_Get(config, string, value);
if(*value){
return 1;
}
if(string->data[0] != '{' || string->data[string->length - 1] != '}'){
ARC_Spritesheet_ReadTexture(config, string, NULL, value);
return 0;
}
uint64_t split = ARC_GraphicsConfig_GetIndexAndErrorCheck(string, ",", 1);
if(arc_errno){
return 0;
}
ARC_String *temp, *spritesheetStr, *framesStr;
ARC_String_CopySubstring(&temp, string, 1, split - 2);
ARC_String_StripEndsWhitespace(&spritesheetStr, temp);
ARC_String_Destroy(temp);
ARC_String_CopySubstring(&temp, string, split + 1, string->length - (split + 2));
ARC_String_StripEndsWhitespace(&framesStr, temp);
ARC_String_Destroy(temp);
//spritesheet
ARC_Spritesheet *spritesheet;
ARC_Config_Get(config, spritesheetStr, (void **)&spritesheet);
if(!spritesheet){
ARC_Spritesheet_Read(config, spritesheetStr, (void **)&spritesheet);
if(arc_errno){
ARC_String_Destroy(spritesheetStr);
ARC_String_Destroy(framesStr );
return 0;
}
}
//bounds
ARC_Array *frames;
ARC_Config_Get(config, framesStr, (void **)&frames);
if(!frames){
ARC_RectArray_Read(config, framesStr, (void **)&frames);
if(arc_errno){
ARC_String_Destroy(spritesheetStr);
ARC_String_Destroy(framesStr );
return 0;
}
}
ARC_String_Destroy(spritesheetStr);
ARC_String_Destroy(framesStr );
// Scale frames to match spritesheet size
// TODO: possible bug for sheets that use same frames
if(spritesheet->size){
for(uint32_t i = 0; i < frames->size; i++){
((ARC_Rect *)frames->data)[i].x *= *spritesheet->size;
((ARC_Rect *)frames->data)[i].y *= *spritesheet->size;
((ARC_Rect *)frames->data)[i].w *= *spritesheet->size;
((ARC_Rect *)frames->data)[i].h *= *spritesheet->size;
}
}
//sprite
ARC_Sprite_Create((ARC_Sprite **)value, spritesheet, frames);
return 0;
}
void ARC_SDL_Texture_Delete(ARC_Config* config, ARC_String *string, void *value){
SDL_DestroyTexture((SDL_Texture *) value);
}
void ARC_Spritesheet_Delete(ARC_Config* config, ARC_String *string, void *value){
ARC_Spritesheet *sheetValue = (ARC_Spritesheet *)value;
//check if read in as a Textrue reference
void *temp;
ARC_Config_Get(config, string, &temp);
if(temp){
//TODO: test to see if this breaks references
free(sheetValue);
return;
}
uint64_t split = ARC_GraphicsConfig_GetIndexAndErrorCheck(string, ",", 1);
if(arc_errno){
//TODO: test to make sure no edge cases
// free(sheetValue);
ARC_SDL_Texture_Delete(config, string, value);
arc_errno = 0;
return;
}
if(split == ~0){
}
//check if texture and size are references
ARC_String *tempStr, *textureStr, *sizeStr;
ARC_String_CopySubstring(&tempStr, string, 1, split - 1);
ARC_String_StripEndsWhitespace(&textureStr, tempStr);
ARC_String_Destroy(tempStr);
ARC_String_CopySubstring(&tempStr, string, split + 1, string->length - (split + 1));
ARC_String_StripEndsWhitespace(&sizeStr, tempStr);
ARC_String_Destroy(tempStr);
ARC_Config_Get(config, sizeStr, (void **)&temp);
ARC_String_Destroy(sizeStr);
if(temp){
free(sheetValue->size);
}
ARC_Config_Get(config, textureStr, (void **)&temp);
ARC_String_Destroy(textureStr);
if(temp){
free(sheetValue->size);
}
free(sheetValue);
}
void ARC_Sprite_Delete(ARC_Config* config, ARC_String *string, void *value){
ARC_Sprite *spriteValue = (ARC_Sprite *)value;
//check if read in as a Textrue reference
void *temp;
uint64_t split = ARC_GraphicsConfig_GetIndexAndErrorCheck(string, ",", 1);
if(arc_errno){
free(spriteValue);
return;
}
//check if texture and size are references
ARC_String *tempStr, *spritesheetStr, *framesStr;
ARC_String_CopySubstring(&tempStr, string, 1, split - 1);
ARC_String_StripEndsWhitespace(&spritesheetStr, tempStr);
ARC_String_Destroy(tempStr);
ARC_String_CopySubstring(&tempStr, string, split + 1, string->length - (split + 1));
ARC_String_StripEndsWhitespace(&framesStr, tempStr);
ARC_String_Destroy(tempStr);
ARC_Config_Get(config, spritesheetStr, (void **)&temp);
ARC_String_Destroy(spritesheetStr);
if(temp){
free(spriteValue->spritesheet);
}
ARC_Config_Get(config, framesStr, (void **)&temp);
ARC_String_Destroy(framesStr);
if(temp){
free(spriteValue->frames);
}
free(spriteValue);
}
//SDL_Renderer *global_renderer;
//
//uint8_t ARC_SDL_Texture_Read(ARC_Config *config, ARC_String *string, void **value);
//uint8_t ARC_Spritesheet_Read(ARC_Config *config, ARC_String *string, void **value);
//uint8_t ARC_Sprite_Read (ARC_Config *config, ARC_String *string, void **value);
//
//void ARC_SDL_Texture_Delete(ARC_Config *config, ARC_String *string, void *value);
//void ARC_Spritesheet_Delete(ARC_Config *config, ARC_String *string, void *value);
//void ARC_Sprite_Delete (ARC_Config *config, ARC_String *string, void *value);
//
//void ARC_GraphicsConfig_Init(ARC_Config *config, ARC_Renderer *renderer){
// global_renderer = (SDL_Renderer *)renderer;
// ARC_Config_AddKeyCString(config, (char *)"SDL_Texture" , 11, ARC_SDL_Texture_Read, ARC_SDL_Texture_Delete);
// ARC_Config_AddKeyCString(config, (char *)"ARC_Spritesheet", 15, ARC_Spritesheet_Read, ARC_Spritesheet_Delete);
// ARC_Config_AddKeyCString(config, (char *)"ARC_Sprite" , 10, ARC_Sprite_Read , ARC_Sprite_Delete );
//}
//
//uint64_t ARC_GraphicsConfig_GetIndexAndErrorCheck(ARC_String *string, char *search, uint64_t searchLength){
// uint64_t separator = ARC_String_FindCString(string, ",", 1);
//
// if(separator == ~(uint64_t)0){
// arc_errno = ARC_ERRNO_DATA;
// }
//
// return separator;
//}
//
//int32_t ARC_SDL_Texture_Load(const char *path, SDL_Texture **texture){
// IMG_Init(IMG_INIT_PNG);
// SDL_Surface *surface = IMG_Load(path);
// if(!surface){
// printf("Error: reading png '%s'\nSDL_Image Error: %s", path, IMG_GetError());
// return 1; // GE_SDL_ERRNO_
// }
//
// SDL_BlendMode tempMode;
// SDL_GetSurfaceBlendMode(surface, &tempMode);
// *texture = SDL_CreateTextureFromSurface(global_renderer, surface);
// SDL_GetTextureBlendMode(*texture, &tempMode);
//
// SDL_FreeSurface(surface);
// IMG_Quit();
//
// return 0;
//}
//
//uint8_t ARC_SDL_Texture_Read(ARC_Config* config, ARC_String *string, void **value){
// ARC_Config_Get(config, string, value);
// if(*value){
// return 1;
// }
//
// ARC_String *tempStr, *textureStr;
// ARC_String_StripEndsWhitespace(&tempStr, string);
//
// ARC_String_CopySubstring(&textureStr, tempStr, 1, tempStr->length - 2);
// ARC_String_Destroy(tempStr);
//
// ARC_SDL_Texture_Load(textureStr->data, (SDL_Texture **)value);
//
// ARC_String_Destroy(textureStr);
// return 0;
//}
//
//void ARC_Spritesheet_ReadTexture(ARC_Config *config, ARC_String *string, uint32_t *size, void **value){
// SDL_Texture *texture;
//
// ARC_String *tempStr, *textureStr;
// ARC_String_StripEndsWhitespace(&tempStr, string);
//
// //check for reference
// ARC_Config_Get(config, tempStr, (void **)&texture);
// if(!texture && (tempStr->data[0] != '"' || tempStr->data[string->length - 1] != '"')){
// arc_errno = ARC_ERRNO_DATA;
// }
//
// ARC_String_CopySubstring(&textureStr, tempStr, 1, tempStr->length - 2);
// ARC_String_Destroy(tempStr);
//
// //try reading in the texture
// if(!texture){
// ARC_SDL_Texture_Read(config, string, (void **)&texture);
// if(arc_errno){
// *value = NULL;
// }
// }
//
// ARC_String_Destroy(textureStr);
//
// *value = malloc(sizeof(ARC_Spritesheet));
// ((ARC_Spritesheet *) *value)->texture = texture;
// ((ARC_Spritesheet *) *value)->size = size;
//}
//
//uint8_t ARC_Spritesheet_Read(ARC_Config* config, ARC_String *string, void **value){
// if(string->data[0] != '{' || string->data[string->length - 1] != '}'){
// ARC_Spritesheet_ReadTexture(config, string, NULL, value);
// return 0;
// }
//
// uint64_t split = ARC_GraphicsConfig_GetIndexAndErrorCheck(string, ",", 1);
// if(arc_errno){
// return 0;
// }
//
// ARC_String *temp, *textureStr, *sizeStr;
// ARC_String_CopySubstring(&temp, string, 1, split - 2);
// ARC_String_StripEndsWhitespace(&textureStr, temp);
// ARC_String_Destroy(temp);
//
// ARC_String_CopySubstring(&temp, string, split + 1, string->length - (split + 2));
// ARC_String_StripEndsWhitespace(&sizeStr, temp);
// ARC_String_Destroy(temp);
//
// uint32_t *size;
// ARC_Config_Get(config, string, (void **)&size);
// if(!size){
// ARC_ConfigKey_Read_Uint32_t(config, sizeStr, (void **)&size);
// if(arc_errno){
// ARC_String_Destroy(sizeStr);
// ARC_String_Destroy(textureStr);
// return ARC_ERRNO_DATA;
// }
// }
//
// ARC_Spritesheet_ReadTexture(config, textureStr, size, value);
//
// ARC_String_Destroy(sizeStr);
// ARC_String_Destroy(textureStr);
//
// return 0;
//}
//
//uint8_t ARC_Sprite_Read(ARC_Config* config, ARC_String *string, void **value){
// ARC_Config_Get(config, string, value);
// if(*value){
// return 1;
// }
//
// if(string->data[0] != '{' || string->data[string->length - 1] != '}'){
// ARC_Spritesheet_ReadTexture(config, string, NULL, value);
// return 0;
// }
//
// uint64_t split = ARC_GraphicsConfig_GetIndexAndErrorCheck(string, ",", 1);
// if(arc_errno){
// return 0;
// }
//
// ARC_String *temp, *spritesheetStr, *framesStr;
// ARC_String_CopySubstring(&temp, string, 1, split - 2);
// ARC_String_StripEndsWhitespace(&spritesheetStr, temp);
// ARC_String_Destroy(temp);
//
// ARC_String_CopySubstring(&temp, string, split + 1, string->length - (split + 2));
// ARC_String_StripEndsWhitespace(&framesStr, temp);
// ARC_String_Destroy(temp);
//
// //spritesheet
// ARC_Spritesheet *spritesheet;
// ARC_Config_Get(config, spritesheetStr, (void **)&spritesheet);
//
// if(!spritesheet){
// ARC_Spritesheet_Read(config, spritesheetStr, (void **)&spritesheet);
// if(arc_errno){
// ARC_String_Destroy(spritesheetStr);
// ARC_String_Destroy(framesStr );
// return 0;
// }
// }
//
// //bounds
// ARC_Array *frames;
// ARC_Config_Get(config, framesStr, (void **)&frames);
//
// if(!frames){
// ARC_RectArray_Read(config, framesStr, (void **)&frames);
// if(arc_errno){
// ARC_String_Destroy(spritesheetStr);
// ARC_String_Destroy(framesStr );
// return 0;
// }
// }
//
// ARC_String_Destroy(spritesheetStr);
// ARC_String_Destroy(framesStr );
//
// // Scale frames to match spritesheet size
// // TODO: possible bug for sheets that use same frames
// if(spritesheet->size){
// for(uint32_t i = 0; i < frames->size; i++){
// ((ARC_Rect *)frames->data)[i].x *= *spritesheet->size;
// ((ARC_Rect *)frames->data)[i].y *= *spritesheet->size;
// ((ARC_Rect *)frames->data)[i].w *= *spritesheet->size;
// ((ARC_Rect *)frames->data)[i].h *= *spritesheet->size;
// }
// }
// //sprite
// ARC_Sprite_Create((ARC_Sprite **)value, spritesheet, frames);
//
// return 0;
//}
//
//void ARC_SDL_Texture_Delete(ARC_Config* config, ARC_String *string, void *value){
// SDL_DestroyTexture((SDL_Texture *) value);
//}
//
//void ARC_Spritesheet_Delete(ARC_Config* config, ARC_String *string, void *value){
// ARC_Spritesheet *sheetValue = (ARC_Spritesheet *)value;
//
// //check if read in as a Textrue reference
// void *temp;
// ARC_Config_Get(config, string, &temp);
// if(temp){
// //TODO: test to see if this breaks references
// free(sheetValue);
// return;
// }
//
// uint64_t split = ARC_GraphicsConfig_GetIndexAndErrorCheck(string, ",", 1);
// if(arc_errno){
// //TODO: test to make sure no edge cases
// // free(sheetValue);
// ARC_SDL_Texture_Delete(config, string, value);
// arc_errno = 0;
// return;
// }
//
// if(split == ~0){
//
// }
//
// //check if texture and size are references
// ARC_String *tempStr, *textureStr, *sizeStr;
// ARC_String_CopySubstring(&tempStr, string, 1, split - 1);
// ARC_String_StripEndsWhitespace(&textureStr, tempStr);
// ARC_String_Destroy(tempStr);
//
// ARC_String_CopySubstring(&tempStr, string, split + 1, string->length - (split + 1));
// ARC_String_StripEndsWhitespace(&sizeStr, tempStr);
// ARC_String_Destroy(tempStr);
//
// ARC_Config_Get(config, sizeStr, (void **)&temp);
// ARC_String_Destroy(sizeStr);
// if(temp){
// free(sheetValue->size);
// }
//
// ARC_Config_Get(config, textureStr, (void **)&temp);
// ARC_String_Destroy(textureStr);
// if(temp){
// free(sheetValue->size);
// }
//
// free(sheetValue);
//}
//
//void ARC_Sprite_Delete(ARC_Config* config, ARC_String *string, void *value){
// ARC_Sprite *spriteValue = (ARC_Sprite *)value;
//
// //check if read in as a Textrue reference
// void *temp;
// uint64_t split = ARC_GraphicsConfig_GetIndexAndErrorCheck(string, ",", 1);
// if(arc_errno){
// free(spriteValue);
// return;
// }
//
// //check if texture and size are references
// ARC_String *tempStr, *spritesheetStr, *framesStr;
// ARC_String_CopySubstring(&tempStr, string, 1, split - 1);
// ARC_String_StripEndsWhitespace(&spritesheetStr, tempStr);
// ARC_String_Destroy(tempStr);
//
// ARC_String_CopySubstring(&tempStr, string, split + 1, string->length - (split + 1));
// ARC_String_StripEndsWhitespace(&framesStr, tempStr);
// ARC_String_Destroy(tempStr);
//
// ARC_Config_Get(config, spritesheetStr, (void **)&temp);
// ARC_String_Destroy(spritesheetStr);
// if(temp){
// free(spriteValue->spritesheet);
// }
//
// ARC_Config_Get(config, framesStr, (void **)&temp);
// ARC_String_Destroy(framesStr);
// if(temp){
// free(spriteValue->frames);
// }
//
// free(spriteValue);
//}

View file

@ -0,0 +1,292 @@
#include "arc/linux/dbus/dbus.h"
#include "arc/linux/dbus/helpers.h"
#include <stdlib.h>
#include <stdio.h>
static const char *handleCStr = "ARC_Controller";
static const char *sessionHandleCStr = "arc_controller";
static const char *busNameCStr = "org.freedesktop.portal.Desktop";
static const char *requestInterfaceCStr = "org.freedesktop.portal.Request";
static const char *shortcutInterfaceCStr = "org.freedesktop.portal.GlobalShortcuts";
static const char *objectPathCStr = "/org/freedesktop/portal/desktop";
typedef struct ARC_DBus {
DBusConnection *connection;
DBusError error;
const char *handle;
} ARC_DBus;
typedef struct ARC_DBusShortcut {
const char *id;
const char *description;
const char *preferredTrigger;
} ARC_DBusShortcut;
void ARC_DBus_Create(ARC_DBus **dbus){
*dbus = (ARC_DBus *)malloc(sizeof(ARC_DBus));
dbus_error_init(&((*dbus)->error));
(*dbus)->connection = dbus_bus_get(DBUS_BUS_SESSION, &((*dbus)->error));
if((*dbus)->connection == NULL){
printf("Connection to D-Bus failed %s\n", ((*dbus)->error).message);
dbus_error_free(&((*dbus)->error));
free(*dbus);
*dbus = NULL;
return;
}
}
void ARC_DBus_Destroy(ARC_DBus *dbus){
dbus_error_free(&(dbus->error));
dbus_connection_unref(dbus->connection);
free(dbus);
}
//Docs: https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Request.html#org-freedesktop-portal-request-response
void ARC_DBus_RequestResponse(){
//create the create session message
DBusMessage *message = dbus_message_new_method_call(busNameCStr, objectPathCStr, requestInterfaceCStr, "Response");
if(!message){
//TODO: arc errno stuff here
printf("Message creation failed\n");
return;
}
//initialize the message arguments
DBusMessageIter arguments;
dbus_message_iter_init_append(message, &arguments);
}
//Docs: https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.GlobalShortcuts.html#org-freedesktop-portal-globalshortcuts-createsession
void ARC_DBus_InitSession(ARC_DBus *dbus){
//create the create session message
DBusMessage *message = dbus_message_new_method_call(busNameCStr, objectPathCStr, shortcutInterfaceCStr, "CreateSession");
if(!message){
//TODO: arc errno stuff here
printf("Message creation failed\n");
return;
}
//initialize the message arguments
DBusMessageIter arguments;
dbus_message_iter_init_append(message, &arguments);
//create the dictionary to add the message arguments to and make sure it can open
DBusMessageIter dictonaryIter;
if(!dbus_message_iter_open_container(&arguments, DBUS_TYPE_ARRAY, "{sv}", &dictonaryIter)){
printf("Failed to append array to the message\n");
return;
}
//init variable container for handle and session handle
ARC_DBusHelper_AddStringVarientStringToMessageIterDictionary(&dictonaryIter, "handle_token" , handleCStr);
ARC_DBusHelper_AddStringVarientStringToMessageIterDictionary(&dictonaryIter, "session_handle_token", sessionHandleCStr);
//close to be able to send the message
dbus_message_iter_close_container(&arguments, &dictonaryIter);
//send the message and store the handle response in a reply message
DBusMessage *reply = dbus_connection_send_with_reply_and_block(dbus->connection, message, -1, &(dbus->error));
if(reply == NULL){
//TODO: arc errno stuff here
printf("ERROR: %s\n", dbus->error.message);
}
//wait until message queue is empty then clean up the message
dbus_connection_flush(dbus->connection);
dbus_message_unref(message);
//get the reply message iterator and make sure it stores an object (this will be a handle on success)
DBusMessageIter replyIter;
dbus_message_iter_init(reply, &replyIter);
if(dbus_message_iter_get_arg_type(&replyIter) != 'o'){
//TODO: arc errno stuff here
printf("object expected, but recieved something else, '%c'\n", (char)dbus_message_iter_get_arg_type(&replyIter));
return;
}
//store the handle from the iterator into the dbus type
//TODO: probably want to warn if dbus->handle already stores something
dbus_message_iter_get_basic(&replyIter, &(dbus->handle));
//request response shit?
// dbus_connection_read_write(dbus->connection, 0);
//
// DBusMessage *message = dbus_connection_pop_message(dbus->connection);
// if(message == NULL){
// continue;
// }
//cleanup
dbus_message_unref(reply);
}
//Docs: https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.GlobalShortcuts.html#org-freedesktop-portal-globalshortcuts-bindshortcuts
//NOTE: this is a vector of ARC_DBusShortcut
void ARC_DBus_BindShortcuts(ARC_DBus *dbus, ARC_Vector *dbusShortcutVector){
//create the create session message
DBusMessage *message = dbus_message_new_method_call(busNameCStr, objectPathCStr, shortcutInterfaceCStr, "BindShortcuts");
if(!message){
//TODO: arc errno stuff here
printf("Message creation failed\n");
return;
}
//initialize the message arguments
DBusMessageIter arguments;
dbus_message_iter_init_append(message, &arguments);
/* ~ session handle ~ */
dbus_message_iter_append_basic(&arguments, DBUS_TYPE_OBJECT_PATH, &(dbus->handle));
/* ~ shortcuts ~ */
//create the dictionary to add the message arguments to and make sure it can open
DBusMessageIter shortcutsIter;
if(!dbus_message_iter_open_container(&arguments, DBUS_TYPE_ARRAY, "(sa{sv})", &shortcutsIter)){
printf("Failed to append array to the message\n");
return;
}
//add all the shortcuts from the vector to the shortcuts
for(uint32_t index = 0; index < ARC_Vector_GetSize(dbusShortcutVector); index++){
DBusMessageIter shortcutStructIter;
if(!dbus_message_iter_open_container(&shortcutsIter, DBUS_TYPE_STRUCT, NULL, &shortcutStructIter)){
printf("Failed to append array to the message\n");
return;
}
ARC_DBusShortcut *shortcut = ARC_Vector_Get(dbusShortcutVector, index);
dbus_message_iter_append_basic(&shortcutStructIter, DBUS_TYPE_STRING, &shortcut->id);
DBusMessageIter shortcutItemIter;
if(!dbus_message_iter_open_container(&shortcutStructIter, DBUS_TYPE_ARRAY, "{sv}", &shortcutItemIter)){
printf("Failed to append array to the message\n");
return;
}
//add the shortcut to the dictionary
ARC_DBusHelper_AddStringVarientStringToMessageIterDictionary(&shortcutItemIter, shortcut->description, shortcut->preferredTrigger);
//close to be able to send the message
dbus_message_iter_close_container(&shortcutStructIter, &shortcutItemIter);
dbus_message_iter_close_container(&shortcutsIter, &shortcutStructIter);
}
//close to be able to send the message
dbus_message_iter_close_container(&arguments, &shortcutsIter);
/* ~ parent window ~ */
const char *parentWindow = "";
dbus_message_iter_append_basic(&arguments, DBUS_TYPE_STRING, &parentWindow);
/* ~ options ~ */
DBusMessageIter optionsIter;
if(!dbus_message_iter_open_container(&arguments, DBUS_TYPE_ARRAY, "{sv}", &optionsIter)){
printf("Failed to append array to the message\n");
return;
}
dbus_message_iter_close_container(&arguments, &optionsIter);
//send the message and store the handle response in a reply message
DBusMessage *reply = dbus_connection_send_with_reply_and_block(dbus->connection, message, -1, &(dbus->error));
if(reply == NULL){
//TODO: arc errno stuff here
printf("ERROR: %s\n", dbus->error.message);
}
//wait until message queue is empty then clean up the message
dbus_connection_flush(dbus->connection);
dbus_message_unref(message);
//get the reply message iterator and make sure it stores an object (this will be a handle on success)
DBusMessageIter replyIter;
dbus_message_iter_init(reply, &replyIter);
if(dbus_message_iter_get_arg_type(&replyIter) != 'o'){
//TODO: arc errno stuff here
printf("object expected, but recieved something else, '%c'\n", (char)dbus_message_iter_get_arg_type(&replyIter));
return;
}
//get the request handle. not sure what to do with this yet...
const char *requestHandle;
dbus_message_iter_get_basic(&replyIter, &requestHandle);
printf("Request Handle: %s\n", requestHandle);
//cleanup
dbus_message_unref(reply);
}
//NOTE: https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.GlobalShortcuts.html#org-freedesktop-portal-globalshortcuts-listshortcuts
void ARC_DBus_ListShortcuts(ARC_DBus *dbus){
//create the create session message
DBusMessage *message = dbus_message_new_method_call(busNameCStr, objectPathCStr, shortcutInterfaceCStr, "ListShortcuts");
if(!message){
//TODO: arc errno stuff here
printf("Message creation failed\n");
return;
}
//initialize the message arguments
DBusMessageIter arguments;
dbus_message_iter_init_append(message, &arguments);
/* ~ session handle ~ */
dbus_message_iter_append_basic(&arguments, DBUS_TYPE_OBJECT_PATH, &(dbus->handle));
/* ~ options ~ */
DBusMessageIter optionsIter;
if(!dbus_message_iter_open_container(&arguments, DBUS_TYPE_ARRAY, "{sv}", &optionsIter)){
printf("Failed to append array to the message\n");
return;
}
dbus_message_iter_close_container(&arguments, &optionsIter);
//send the message and store the handle response in a reply message
DBusMessage *reply = dbus_connection_send_with_reply_and_block(dbus->connection, message, -1, &(dbus->error));
if(reply == NULL){
//TODO: arc errno stuff here
printf("ERROR: %s\n", dbus->error.message);
}
//wait until message queue is empty then clean up the message
dbus_connection_flush(dbus->connection);
dbus_message_unref(message);
/*
//get the reply message iterator and make sure it stores an object (this will be a handle on success)
DBusMessageIter replyIter;
dbus_message_iter_init(reply, &replyIter);
if(dbus_message_iter_get_arg_type(&replyIter) != 'o'){
//TODO: arc errno stuff here
printf("object expected, but recieved something else, '%c'\n", (char)dbus_message_iter_get_arg_type(&replyIter));
return;
}
//get the request handle. not sure what to do with this yet...
const char *requestHandle;
dbus_message_iter_get_basic(&replyIter, &requestHandle);
printf("Request Handle: %s\n", requestHandle);
*/
//cleanup
dbus_message_unref(reply);
}
ARC_DBusShortcut *ARC_DBusShortcut_CreateAndReturn(const char *id, const char *description, const char *preferredTrigger){
ARC_DBusShortcut *shortcut = (ARC_DBusShortcut *)malloc(sizeof(ARC_DBusShortcut));
*shortcut = (ARC_DBusShortcut){
id,
description,
preferredTrigger
};
return shortcut;
}

View file

@ -0,0 +1,63 @@
#include "arc/linux/dbus/helpers.h"
#include "arc/linux/dbus/dbus.h"
#include <stdio.h>
#include <string.h>
typedef struct ARC_DBus {
DBusConnection *connection;
DBusError error;
const char *handle;
} ARC_DBus;
void ARC_DBusHelper_BusRequestName(ARC_DBus *dbus, const char *interface, const char *objectPath){
int32_t response = dbus_bus_request_name(dbus->connection, interface, DBUS_NAME_FLAG_REPLACE_EXISTING, &(dbus->error));
if(response == -1){
printf("Request name failed %s\n", (dbus->error).message);
dbus_error_free(&(dbus->error));
return;
}
}
void ARC_DBusHelper_BusAddMatch(ARC_DBus *dbus, const char *interface, const char *objectPath, const char *member){
//add response signal
const char *matchRuleCStr = "type='signal',interface='%s',path='%s',member='%s'";
uint32_t matchRuleLen = strlen(matchRuleCStr) + strlen(interface) + strlen(objectPath) + strlen(member);
char matchRule[matchRuleLen];
snprintf(matchRule, matchRuleLen, matchRuleCStr, interface, objectPath, member);
dbus_bus_add_match(dbus->connection, matchRule, &(dbus->error));
if(dbus_error_is_set(&(dbus->error))){
printf("failed to add match rule: %s\n", matchRuleCStr);
dbus_error_free(&(dbus->error));
}
}
void ARC_DBusHelper_HandleSignal(DBusMessage *message){
DBusError error;
dbus_error_init(&error);
uint32_t response;
DBusMessageIter argumentsIter;
dbus_message_iter_init(message, &argumentsIter);
dbus_message_iter_get_basic(&argumentsIter, &response);
printf("Response signal: %u\n", response);
dbus_error_free(&error);
}
void ARC_DBusHelper_AddStringVarientStringToMessageIterDictionary(DBusMessageIter *dictonaryIter, const char *stringKey, const char *varientStringValue){
//TODO: should add arc error checks here
DBusMessageIter keyIter;
dbus_message_iter_open_container(dictonaryIter, DBUS_TYPE_DICT_ENTRY, NULL, &keyIter);
dbus_message_iter_append_basic(&keyIter, DBUS_TYPE_STRING, &stringKey);
DBusMessageIter valueIter;
dbus_message_iter_open_container(&keyIter, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &valueIter);
dbus_message_iter_append_basic(&valueIter, DBUS_TYPE_STRING, &varientStringValue);
dbus_message_iter_close_container(&keyIter, &valueIter);
dbus_message_iter_close_container(dictonaryIter, &keyIter);
}

View file

@ -29,17 +29,17 @@ ARC_TEST(Hashtable_Init){
ARC_Hashtable_Destroy(hashtable);
}
ARC_TEST(Vector_Add){
ARC_TEST(Hashtable_Add){
ARC_Hashtable *hashtable;
ARC_Hashtable_KeyCompareFn keyCompareFn = TEST_Hashtable_KeyCompareDataFn;
ARC_Hashtable_DestroyKeyValueFn destroyKeyValueFn = TEST_Hashtable_DestroyKeyValueFn;
ARC_Hashtable_Create(&hashtable, NULL, &keyCompareFn, &destroyKeyValueFn);
char *key0 = (char *)"test";
char *key0 = (char *)"tests";
int32_t val0 = 2;
ARC_Hashtable_Add(hashtable, &key0, &val0);
ARC_CHECK(2 == *(int32_t *)ARC_Hashtable_Get(hashtable, (char *)"test"));
ARC_CHECK(2 == *(int32_t *)ARC_Hashtable_Get(hashtable, (char *)"tests"));
ARC_Hashtable_Destroy(hashtable);
}