huge redesign

This commit is contained in:
herbglitch 2024-01-12 19:48:06 -07:00
parent 46e26e41e5
commit 85d0bad350
4 changed files with 66 additions and 81 deletions

View file

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.10)
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")
@ -9,52 +9,32 @@ function(print var)
message("${var} = ${${var}}")
endfunction()
option(ARCHEUS_STD_DEBUG "Build in debug mode" ON)
#TODO: Might want to remove this
if(NOT CMAKE_BUILD_TYPE)
message("[Archeus C STD] Build Type not set, defaulting to Debug")
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Default to Debug" FORCE)
endif()
# ~ OPTIONS ~ #
option(ARCHEUS_STD_DEFAULT_CONFIG "Build with default config keys" ON)
option(ARCHEUS_STD_SDL "Build with SDL" OFF)
option(ARCHEUS_STD_GLFW "Build with GLFW window" OFF)
option(ARCHEUS_STD_GLEW "Build with GLEW" OFF)
option(ARCHEUS_STD_OPENGL "Build with OpenGL" OFF)
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_STD_INPUT_BACKEND "NONE" CACHE STRING "Input Backend to build with, most likely should match Window API")
set_property(CACHE ARCHEUS_STD_INPUT_BACKEND PROPERTY STRINGS NONE SDL2 GLFW)
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)
# ~ INIT VARIABLES ~ #
set(ARCHEUS_STD_FLAGS "")
set(ARCHEUS_STD_LIBRARIES "")
if(ARCHEUS_STD_DEBUG)
string(APPEND ARCHEUS_STD_FLAGS "-Wall -Werror -g -ggdb -DARC_DEBUG ")
endif()
if(ARCHEUS_STD_DEFAULT_CONFIG)
string(APPEND ARCHEUS_STD_FLAGS "-DARC_DEFAULT_CONFIG ")
endif()
if(ARCHEUS_STD_SDL)
if(NOT PNG AND WIN32 AND NOT MSVC)
set(PNG_LIBRARY "C:/Program Files(x86)/libpng")
set(PNG_PNG_INCLUDE_DIR "C:/Program Files(x86)/libpng/include")
endif()
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
find_package(SDL2_ttf REQUIRED)
string(APPEND ARCHEUS_STD_FLAGS "-DARC_SDL ")
endif()
if(ARCHEUS_STD_GLFW)
string(APPEND ARCHEUS_STD_FLAGS "-DARC_GLFW ")
endif()
if(ARCHEUS_STD_GLEW)
string(APPEND ARCHEUS_STD_FLAGS "-DARC_GLEW ")
endif()
if(ARCHEUS_STD_OPENGL)
string(APPEND ARCHEUS_STD_FLAGS "-DARC_OPENGL")
endif()
set(CMAKE_C_FLAGS ${ARCHEUS_STD_FLAGS})
# ~ ARCHEUS_SOURCES ~ #
set(ARCHEUS_STD_SOURCES
src/std/config.c
src/std/errno.c
src/std/handler.c
src/std/hashtable.c
src/std/io.c
@ -74,21 +54,37 @@ set(ARCHEUS_STD_SOURCES
src/engine/state.c
)
set(ARCHEUS_STD_SDL_SOURCES
src/input/sdl/keyboard.c
src/input/sdl/mouse.c
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
string(APPEND ARCHEUS_STD_FLAGS "-Wall -Werror -g -ggdb -DARC_DEBUG ")
endif()
src/graphics/sdl/circle.c
src/graphics/sdl/config.c
src/graphics/sdl/line.c
src/graphics/sdl/obround.c
src/graphics/sdl/rectangle.c
src/graphics/sdl/renderer.c
src/graphics/sdl/sprite.c
src/graphics/sdl/spritesheet.c
src/graphics/sdl/text.c
src/graphics/sdl/window.c
)
# 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})
# ~ SDL2 ~ #
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/archeus_sdl2.cmake)
sdl2_check_and_init_needed(ARCHEUS_STD_FLAGS ARCHEUS_STD_SOURCES ${ARCHEUS_STD_WINDOW_BACKEND} ${ARCHEUS_STD_INPUT_BACKEND} ${ARCHEUS_STD_GRAPHICS_BACKEND})
# ~ OPENGL ~ #
if(ARCHEUS_STD_GRAPHICS_BACKEND STREQUAL OPENGL)
string(APPEND ARCHEUS_STD_FLAGS "-DARC_OPENGL ")
endif()
if(ARCHEUS_STD_GLFW)
string(APPEND ARCHEUS_STD_FLAGS "-DARC_GLFW ")
endif()
if(ARCHEUS_STD_GLEW)
string(APPEND ARCHEUS_STD_FLAGS "-DARC_GLEW ")
endif()
set(CMAKE_C_FLAGS ${ARCHEUS_STD_FLAGS})
set(ARCHEUS_STD_OPENGL_SOURCES
src/graphics/opengl/config.c
@ -105,10 +101,6 @@ set(ARCHEUS_STD_GLFW_SOURCES
src/input/glfw/mouse.c
)
if(ARCHEUS_STD_SDL)
list(APPEND ARCHEUS_STD_SOURCES ${ARCHEUS_STD_SDL_SOURCES})
endif()
if(ARCHEUS_STD_OPENGL)
list(APPEND ARCHEUS_STD_SOURCES ${ARCHEUS_STD_OPENGL_SOURCES})
endif()
@ -123,21 +115,13 @@ else()
add_library(archeus_std SHARED ${ARCHEUS_STD_SOURCES})
endif()
if(ARCHEUS_STD_SDL)
target_include_directories(archeus_std
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE ${SDL2_INCLUDE_DIRS}
PRIVATE ${SDL2IMAGE_INCLUDE_DIRS}
)
target_link_libraries(archeus_std PUBLIC ${SDL2_LIBRARIES} SDL2_image::SDL2_image SDL2_ttf::SDL2_ttf)
endif()
if(ARCHEUS_STD_OPENGL)
target_include_directories(archeus_std PRIVATE
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
target_link_libraries(archeus_std
PUBLIC m
)
endif()
install(TARGETS archeus_std EXPORT archeus_std_Exports
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}

View file

@ -10,16 +10,12 @@
#define ARC_ERRNO_OVERFLOW -0x05
#define ARC_ERRNO_INIT -0x06
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
static int32_t arc_errno = 0;
#pragma GCC diagnostic pop
#ifdef __cplusplus
extern "C" {
#endif
extern int32_t arc_errno;
#ifdef __cplusplus
}
#endif

View file

@ -9,6 +9,11 @@
#include "arc/std/handler.h"
//NOTE: some of this file is temporary, mostly to get smthn running so I can test out different ideas
#include "arc/graphics/none/window.h"
#include "arc/graphics/none/renderer.h"
#include "arc/input/none/mouse.h"
#include "arc/input/none/keyboard.h"
#ifdef ARC_SDL
#include "arc/graphics/sdl/window.h"
#include "arc/graphics/sdl/renderer.h"

View file

@ -8,8 +8,8 @@
void ARC_IO_FileToStr(ARC_String *path, ARC_String **data){
FILE *file = fopen(path->data, "rb");
if(!file){
return;
arc_errno = ARC_ERRNO_NULL;
return;
}
fseek(file, 0L, SEEK_END);