diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..ca2b787 Binary files /dev/null and b/.DS_Store differ diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml index d3e28e6..291ee9f 100644 --- a/.github/workflows/deploy-docs.yml +++ b/.github/workflows/deploy-docs.yml @@ -1,7 +1,7 @@ name: Deploy Docs on: - pull_request: + push: branches: [main] permissions: diff --git a/CMakeLists.txt b/CMakeLists.txt index d1555e7..0ea4512 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.24) -project (asw VERSION 1.0.0 LANGUAGES CXX) +project(asw VERSION 0.3.5 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -21,15 +21,19 @@ add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) target_compile_options(${PROJECT_NAME} PRIVATE -O2 -Wall -Wextra -pedantic) # Add include -target_include_directories(${PROJECT_NAME} PUBLIC - $ - $ - PRIVATE src) +target_include_directories( + ${PROJECT_NAME} PUBLIC + $ + $ + PRIVATE src +) # Versioning -set_target_properties(${PROJECT_NAME} PROPERTIES - VERSION ${PROJECT_VERSION} - SOVERSION 1) +set_target_properties( + ${PROJECT_NAME} PROPERTIES + VERSION ${PROJECT_VERSION} + SOVERSION 1 +) # Find libs if(NOT EMSCRIPTEN) @@ -47,27 +51,27 @@ if(EMSCRIPTEN) set(CMAKE_EXECUTABLE_SUFFIX ".html") target_compile_options( ${PROJECT_NAME} - PRIVATE - -sUSE_SDL=2 - -sUSE_SDL_IMAGE=2 - -sUSE_SDL_TTF=2 - -sUSE_SDL_MIXER=2 + PRIVATE + -sUSE_SDL=2 + -sUSE_SDL_IMAGE=2 + -sUSE_SDL_TTF=2 + -sUSE_SDL_MIXER=2 -sSDL2_IMAGE_FORMATS=["png"] ) target_link_libraries( - ${PROJECT_NAME} - -sWASM=1 - -sUSE_SDL=2 - -sUSE_SDL_IMAGE=2 - -sUSE_SDL_TTF=2 - -sUSE_SDL_MIXER=2 - -sSDL2_IMAGE_FORMATS=["png"] + ${PROJECT_NAME} + -sWASM=1 + -sUSE_SDL=2 + -sUSE_SDL_IMAGE=2 + -sUSE_SDL_TTF=2 + -sUSE_SDL_MIXER=2 + -sSDL2_IMAGE_FORMATS=["png"] -sDEMANGLE_SUPPORT=1 -sTOTAL_MEMORY=512MB ) set_target_properties( - ${PROJECT_NAME} - PROPERTIES + ${PROJECT_NAME} + PROPERTIES LINK_FLAGS "--preload-file ${CMAKE_CURRENT_LIST_DIR}/assets@/assets --use-preload-plugins" ) @@ -77,14 +81,15 @@ else(EMSCRIPTEN) if(MINGW) target_link_libraries(${PROJECT_NAME} -lmingw32) endif(MINGW) + target_link_libraries( - ${PROJECT_NAME} - -lm - ${SDL_MAIN_LIBRARY} - ${SDL_LIBRARY} - ${SDL_MIXER_LIBRARY} - ${SDL_IMAGE_LIBRARY} - ${SDL_TTF_LIBRARY} + ${PROJECT_NAME} + -lm + ${SDL_MAIN_LIBRARY} + ${SDL_LIBRARY} + ${SDL_MIXER_LIBRARY} + ${SDL_IMAGE_LIBRARY} + ${SDL_TTF_LIBRARY} ) endif(EMSCRIPTEN) @@ -98,12 +103,12 @@ configure_package_config_file( ) write_basic_package_version_file( - ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake - VERSION ${PROJECT_VERSION} - COMPATIBILITY AnyNewerVersion + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake + VERSION ${PROJECT_VERSION} + COMPATIBILITY AnyNewerVersion ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake - ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} + ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ) diff --git a/include/asw/modules/input.h b/include/asw/modules/input.h index 1a46d36..f1ee4b3 100644 --- a/include/asw/modules/input.h +++ b/include/asw/modules/input.h @@ -21,42 +21,8 @@ namespace asw::input { /** * @brief Mouse state stores the current state of the mouse. It is updated by * the core. - * */ using MouseState = struct MouseState { - /** - * @brief Check if a button is down. - * - * @param button The button to check. - * @return true - If the button is down. - * @return false - If the button is not down. - */ - bool isButtonDown(asw::input::MouseButton button) { - return down[static_cast(button)]; - } - - /** - * @brief Check if a button was pressed since the last update. - * - * @param button The button to check. - * @return true - If the button was pressed. - * @return false - If the button was not pressed. - */ - bool wasButtonPressed(asw::input::MouseButton button) { - return pressed[static_cast(button)]; - } - - /** - * @brief Check if a button was released since the last update. - * - * @param button The button to check. - * @return true - If the button was released. - * @return false - If the button was not released. - */ - bool wasButtonReleased(asw::input::MouseButton button) { - return released[static_cast(button)]; - } - bool anyPressed{false}; int lastPressed{-1}; @@ -72,40 +38,43 @@ namespace asw::input { std::array down{false}; }; + /** + * @brief Global mouse state. + */ extern MouseState mouse; - using KeyState = struct KeyState { - /** - * @brief Check if a key is down. - * - * @param key The key to check. - * @return true - If the key is down. - * @return false - If the key is not down. - */ - bool isKeyDown(asw::input::Key key) { return down[static_cast(key)]; } - - /** - * @brief Check if a key was pressed since the last update. - * - * @param key The key to check. - * @return true - If the key was pressed. - * @return false - If the key was not pressed. - */ - bool wasKeyPressed(asw::input::Key key) { - return pressed[static_cast(key)]; - } - - /** - * @brief Check if a key was released since the last update. - * - * @param key The key to check. - * @return true - If the key was released. - * @return false - If the key was not released. - */ - bool wasKeyReleased(asw::input::Key key) { - return released[static_cast(key)]; - } + /** + * @brief Check if a button is down. + * + * @param button The button to check. + * @return true - If the button is down. + * @return false - If the button is not down. + */ + bool isButtonDown(asw::input::MouseButton button); + /** + * @brief Check if a button was pressed since the last update. + * + * @param button The button to check. + * @return true - If the button was pressed. + * @return false - If the button was not pressed. + */ + bool wasButtonPressed(asw::input::MouseButton button); + + /** + * @brief Check if a button was released since the last update. + * + * @param button The button to check. + * @return true - If the button was released. + * @return false - If the button was not released. + */ + bool wasButtonReleased(asw::input::MouseButton button); + + /** + * @brief Keyboard state stores the current state of the keyboard. It is + * updated by the core. + */ + using KeyState = struct KeyState { std::array pressed{false}; std::array released{false}; std::array down{false}; @@ -114,8 +83,38 @@ namespace asw::input { int lastPressed{-1}; }; + /** + * @brief Global keyboard state. + */ extern KeyState keyboard; + /** + * @brief Check if a key is down. + * + * @param key The key to check. + * @return true - If the key is down. + * @return false - If the key is not down. + */ + bool isKeyDown(asw::input::Key key); + + /** + * @brief Check if a key was pressed since the last update. + * + * @param key The key to check. + * @return true - If the key was pressed. + * @return false - If the key was not pressed. + */ + bool wasKeyPressed(asw::input::Key key); + + /** + * @brief Check if a key was released since the last update. + * + * @param key The key to check. + * @return true - If the key was released. + * @return false - If the key was not released. + */ + bool wasKeyReleased(asw::input::Key key); + void reset(); } // namespace asw::input diff --git a/src/modules/input.cpp b/src/modules/input.cpp index 90be8dd..1fc7ab4 100644 --- a/src/modules/input.cpp +++ b/src/modules/input.cpp @@ -33,4 +33,28 @@ void asw::input::reset() { for (auto& button : m_state.released) { button = false; } +} + +bool asw::input::isButtonDown(asw::input::MouseButton button) { + return mouse.down[static_cast(button)]; +} + +bool asw::input::wasButtonPressed(asw::input::MouseButton button) { + return mouse.pressed[static_cast(button)]; +} + +bool asw::input::wasButtonReleased(asw::input::MouseButton button) { + return mouse.released[static_cast(button)]; +} + +bool asw::input::isKeyDown(asw::input::Key key) { + return keyboard.down[static_cast(key)]; +} + +bool asw::input::wasKeyPressed(asw::input::Key key) { + return keyboard.pressed[static_cast(key)]; +} + +bool asw::input::wasKeyReleased(asw::input::Key key) { + return keyboard.released[static_cast(key)]; } \ No newline at end of file