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) set(ARCHEUS_STD_VERSION 0.0.0)
project(archeus_std LANGUAGES C VERSION ${ARCHEUS_STD_VERSION} DESCRIPTION "libarcheus_std standard archeus c library") 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}}") message("${var} = ${${var}}")
endfunction() 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_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_FLAGS "")
set(ARCHEUS_STD_LIBRARIES "")
if(ARCHEUS_STD_DEBUG) # ~ ARCHEUS_SOURCES ~ #
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})
set(ARCHEUS_STD_SOURCES set(ARCHEUS_STD_SOURCES
src/std/config.c src/std/config.c
src/std/errno.c
src/std/handler.c src/std/handler.c
src/std/hashtable.c src/std/hashtable.c
src/std/io.c src/std/io.c
@ -74,21 +54,37 @@ set(ARCHEUS_STD_SOURCES
src/engine/state.c src/engine/state.c
) )
set(ARCHEUS_STD_SDL_SOURCES if(CMAKE_BUILD_TYPE STREQUAL "Debug")
src/input/sdl/keyboard.c string(APPEND ARCHEUS_STD_FLAGS "-Wall -Werror -g -ggdb -DARC_DEBUG ")
src/input/sdl/mouse.c endif()
src/graphics/sdl/circle.c # TODO: replace this with a better system
src/graphics/sdl/config.c if(ARCHEUS_STD_DEFAULT_CONFIG)
src/graphics/sdl/line.c string(APPEND ARCHEUS_STD_FLAGS "-DARC_DEFAULT_CONFIG ")
src/graphics/sdl/obround.c endif()
src/graphics/sdl/rectangle.c
src/graphics/sdl/renderer.c # ~ NONE ~ #
src/graphics/sdl/sprite.c include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/archeus_none.cmake)
src/graphics/sdl/spritesheet.c none_check_and_init_needed(ARCHEUS_STD_FLAGS ARCHEUS_STD_SOURCES ${ARCHEUS_STD_WINDOW_BACKEND} ${ARCHEUS_STD_INPUT_BACKEND} ${ARCHEUS_STD_GRAPHICS_BACKEND})
src/graphics/sdl/text.c
src/graphics/sdl/window.c # ~ 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 set(ARCHEUS_STD_OPENGL_SOURCES
src/graphics/opengl/config.c src/graphics/opengl/config.c
@ -105,10 +101,6 @@ set(ARCHEUS_STD_GLFW_SOURCES
src/input/glfw/mouse.c src/input/glfw/mouse.c
) )
if(ARCHEUS_STD_SDL)
list(APPEND ARCHEUS_STD_SOURCES ${ARCHEUS_STD_SDL_SOURCES})
endif()
if(ARCHEUS_STD_OPENGL) if(ARCHEUS_STD_OPENGL)
list(APPEND ARCHEUS_STD_SOURCES ${ARCHEUS_STD_OPENGL_SOURCES}) list(APPEND ARCHEUS_STD_SOURCES ${ARCHEUS_STD_OPENGL_SOURCES})
endif() endif()
@ -123,21 +115,13 @@ else()
add_library(archeus_std SHARED ${ARCHEUS_STD_SOURCES}) add_library(archeus_std SHARED ${ARCHEUS_STD_SOURCES})
endif() endif()
if(ARCHEUS_STD_SDL) target_include_directories(archeus_std
target_include_directories(archeus_std
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> 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) target_link_libraries(archeus_std
endif() PUBLIC m
)
if(ARCHEUS_STD_OPENGL)
target_include_directories(archeus_std PRIVATE
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)
endif()
install(TARGETS archeus_std EXPORT archeus_std_Exports install(TARGETS archeus_std EXPORT archeus_std_Exports
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}

View file

@ -10,16 +10,12 @@
#define ARC_ERRNO_OVERFLOW -0x05 #define ARC_ERRNO_OVERFLOW -0x05
#define ARC_ERRNO_INIT -0x06 #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 #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
extern int32_t arc_errno;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
@ -27,7 +23,7 @@ extern "C" {
#ifdef ARC_DEBUG #ifdef ARC_DEBUG
# include <stdio.h> # include <stdio.h>
# define ARC_DEBUG_LOG(ERR, STR, ...) printf("[ERROR %d] " STR "\n", ERR, __VA_ARGS__) # define ARC_DEBUG_LOG(ERR, STR, ...) printf("[ERROR %d] " STR "\n", ERR, __VA_ARGS__)
# define ARC_DEBUG_ERR(STR) printf("[ERROR %d]" STR "\n", arc_errno) # define ARC_DEBUG_ERR(STR) printf("[ERROR %d] " STR "\n", arc_errno)
#else #else
# define ARC_DEBUG_LOG(ERR, STR, ...) # define ARC_DEBUG_LOG(ERR, STR, ...)
# define ARC_DEBUG_ERR(STR) # define ARC_DEBUG_ERR(STR)

View file

@ -9,6 +9,11 @@
#include "arc/std/handler.h" #include "arc/std/handler.h"
//NOTE: some of this file is temporary, mostly to get smthn running so I can test out different ideas //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 #ifdef ARC_SDL
#include "arc/graphics/sdl/window.h" #include "arc/graphics/sdl/window.h"
#include "arc/graphics/sdl/renderer.h" #include "arc/graphics/sdl/renderer.h"

View file

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