diff --git a/.gitattributes b/.gitattributes index d1eab11..af058c0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,6 @@ * text=auto eol=lf *.a binary +*.bat text eol=crlf *.cj text *.dll binary *.gif binary diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..2b9d1ab --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,118 @@ +name: build + +on: [push, pull_request] + +env: + VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite" + +jobs: + build: + name: ${{ matrix.preset }} + runs-on: ${{ matrix.os }} + + strategy: + # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. + # Consider changing this to true when your workflow is stable. + fail-fast: false + + # Set up a matrix to run the following configurations: + matrix: + preset: + - linux-release + - windows-release + os: + - ubuntu-latest + - windows-latest + include: + - preset: linux-release + os: ubuntu-latest + triplet: x64-linux + toolchain: /usr/local/share/vcpkg/scripts/buildsystems/vcpkg.cmake + - preset: windows-release + os: windows-latest + triplet: x64-mingw-dynamic + toolchain: C:/vcpkg/scripts/buildsystems/vcpkg.cmake + exclude: + - os: ubuntu-latest + preset: windows-release + - os: windows-latest + preset: linux-release + + steps: + - uses: actions/checkout@v3 + + - name: Install CMake + uses: lukka/get-cmake@latest + with: + cmakeVersion: "3.31.5" + + - name: Enable GitHub Actions cache + uses: actions/github-script@v6 + with: + script: | + core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); + core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); + + - name: Install CSFML dependencies + if: runner.os == 'Linux' + uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: libx11-dev libxrandr-dev libxcursor-dev libxi-dev libudev-dev libgl1-mesa-dev nasm + version: 1.0 + execute_install_scripts: true + + - name: Setup w64devkit + if: runner.os == 'Windows' + run: | + Invoke-WebRequest -Uri "https://github.com/skeeto/w64devkit/releases/download/v2.1.0/w64devkit-x64-2.1.0.exe" -OutFile "w64devkit-x64-2.1.0.exe" + Start-Process -FilePath "w64devkit-x64-2.1.0.exe" -ArgumentList "-oC:\", "-y" -Wait + echo "C:\w64devkit\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + + - name: Verify w64devkit installation + if: runner.os == 'Windows' + run: | + gcc --version + g++ --version + + - name: Setup Ninja + uses: turtlesec-no/get-ninja@main + + - name: Setup Cangjie + if: runner.os == 'Linux' + run: | + curl -L -o Cangjie-0.53.18-linux_x64.tar.gz https://github.com/causerp/cangjie/releases/download/v0.53.18/Cangjie-0.53.18-linux_x64.tar.gz + tar -xzf Cangjie-0.53.18-linux_x64.tar.gz -C . + + - name: Setup Cangjie + if: runner.os == 'Windows' + run: | + Invoke-WebRequest -Uri "https://github.com/causerp/cangjie/releases/download/v0.53.18/Cangjie-0.53.18-windows_x64.zip" -OutFile "Cangjie-0.53.18-windows_x64.zip" + Expand-Archive -Path "Cangjie-0.53.18-windows_x64.zip" -DestinationPath "." + + - name: Download CSFML + shell: bash + run: ./download_csfml.sh + + - name: Install vcpkg dependencies + run: | + vcpkg install sfml --triplet=${{ matrix.triplet }} + + - name: Build CSFML + run: | + cd csfml + cmake --preset ${{ matrix.preset }} -DCMAKE_TOOLCHAIN_FILE=${{ matrix.toolchain }} + cmake --build --preset ${{ matrix.preset }} --target install + + - name: Build and test cjsfml + if: runner.os == 'Linux' + shell: bash + run: | + source ./cangjie/envsetup.sh + cjpm build + cjpm test + + - name: Build cjsfml + if: runner.os == 'Windows' + run: | + .\cangjie\envsetup.ps1 + cjpm build diff --git a/.gitignore b/.gitignore index c64cec8..bc1b6c1 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ .svn .vs .vscode +csfml target diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..3df15c5 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,96 @@ +{ + "version": 3, + "configurePresets": [ + { + "name": "linux-base", + "hidden": true, + "generator": "Ninja", + "binaryDir": "${sourceDir}/build", + "installDir": "${sourceDir}/install", + "cacheVariables": { + "BUILD_SHARED_LIBS": true + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Linux" + } + }, + { + "name": "linux-debug", + "displayName": "Debug", + "inherits": "linux-base", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "linux-release", + "displayName": "Release", + "inherits": "linux-debug", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + }, + { + "name": "windows-base", + "hidden": true, + "generator": "Ninja", + "binaryDir": "${sourceDir}/build", + "installDir": "${sourceDir}/install", + "cacheVariables": { + "BUILD_SHARED_LIBS": true, + "CMAKE_C_COMPILER": "gcc", + "CMAKE_CXX_COMPILER": "g++", + "CMAKE_TOOLCHAIN_FILE": { + "value": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", + "type": "FILEPATH" + }, + "VCPKG_TARGET_TRIPLET": "x64-mingw-dynamic" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + }, + { + "name": "windows-debug", + "displayName": "Debug", + "inherits": "windows-base", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "windows-release", + "displayName": "Release", + "inherits": "windows-debug", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + } + ], + "buildPresets": [ + { + "name": "linux-debug", + "configurePreset": "linux-debug", + "displayName": "Debug" + }, + { + "name": "linux-release", + "configurePreset": "linux-release", + "displayName": "Release" + }, + { + "name": "windows-debug", + "configurePreset": "windows-debug", + "displayName": "Debug" + }, + { + "name": "windows-release", + "configurePreset": "windows-release", + "displayName": "Release" + } + ] +} \ No newline at end of file diff --git a/cjpm.toml b/cjpm.toml index 6153c9d..b26bf85 100644 --- a/cjpm.toml +++ b/cjpm.toml @@ -16,8 +16,8 @@ endian = { git = "https://github.com/causerp/endian.git", tag = "v1.0.0"} [ffi.c] - csfml-audio = { path = "./csfml" } - csfml-graphics = { path = "./csfml" } - csfml-network = { path = "./csfml" } - csfml-system = { path = "./csfml" } - csfml-window = { path = "./csfml" } + csfml-audio = { path = "./csfml/install/lib" } + csfml-graphics = { path = "./csfml/install/lib" } + csfml-network = { path = "./csfml/install/lib" } + csfml-system = { path = "./csfml/install/lib" } + csfml-window = { path = "./csfml/install/lib" } diff --git a/csfml/README.md b/csfml/README.md deleted file mode 100644 index 0b532cb..0000000 --- a/csfml/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# CSFML - -Binaries for 64 bit Windows from the CSFML release. -For other OSes, delete these and place library files here. - -## License - -zlib diff --git a/csfml/csfml-audio-2.dll b/csfml/csfml-audio-2.dll deleted file mode 100644 index b65bbc3..0000000 Binary files a/csfml/csfml-audio-2.dll and /dev/null differ diff --git a/csfml/csfml-graphics-2.dll b/csfml/csfml-graphics-2.dll deleted file mode 100644 index d471763..0000000 Binary files a/csfml/csfml-graphics-2.dll and /dev/null differ diff --git a/csfml/csfml-network-2.dll b/csfml/csfml-network-2.dll deleted file mode 100644 index 4bf3969..0000000 Binary files a/csfml/csfml-network-2.dll and /dev/null differ diff --git a/csfml/csfml-system-2.dll b/csfml/csfml-system-2.dll deleted file mode 100644 index 9881a2f..0000000 Binary files a/csfml/csfml-system-2.dll and /dev/null differ diff --git a/csfml/csfml-window-2.dll b/csfml/csfml-window-2.dll deleted file mode 100644 index 059fcf5..0000000 Binary files a/csfml/csfml-window-2.dll and /dev/null differ diff --git a/csfml/libcsfml-audio.a b/csfml/libcsfml-audio.a deleted file mode 100644 index e1696f3..0000000 Binary files a/csfml/libcsfml-audio.a and /dev/null differ diff --git a/csfml/libcsfml-graphics.a b/csfml/libcsfml-graphics.a deleted file mode 100644 index 4049ad0..0000000 Binary files a/csfml/libcsfml-graphics.a and /dev/null differ diff --git a/csfml/libcsfml-network.a b/csfml/libcsfml-network.a deleted file mode 100644 index fd09054..0000000 Binary files a/csfml/libcsfml-network.a and /dev/null differ diff --git a/csfml/libcsfml-system.a b/csfml/libcsfml-system.a deleted file mode 100644 index 1e2ed49..0000000 Binary files a/csfml/libcsfml-system.a and /dev/null differ diff --git a/csfml/libcsfml-window.a b/csfml/libcsfml-window.a deleted file mode 100644 index b55bb52..0000000 Binary files a/csfml/libcsfml-window.a and /dev/null differ diff --git a/csfml/license.md b/csfml/license.md deleted file mode 100644 index 5a61815..0000000 --- a/csfml/license.md +++ /dev/null @@ -1,15 +0,0 @@ -# CSFML - -CSFML - Copyright (C) 2007-2024 Laurent Gomila - laurent@sfml-dev.org - -This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - -## External libraries used by CSFML - - * _SFML_ is under the zlib/png license diff --git a/csfml/openal32.dll b/csfml/openal32.dll deleted file mode 100644 index 7760c05..0000000 Binary files a/csfml/openal32.dll and /dev/null differ diff --git a/download_csfml.sh b/download_csfml.sh new file mode 100755 index 0000000..76b06d0 --- /dev/null +++ b/download_csfml.sh @@ -0,0 +1,2 @@ +git clone --branch 2.6.1 https://github.com/SFML/CSFML.git csfml +cp -f CMakePresets.json ./csfml/CMakePresets.json diff --git a/src/system/Buffer.cj b/src/system/Buffer.cj new file mode 100644 index 0000000..afb7566 --- /dev/null +++ b/src/system/Buffer.cj @@ -0,0 +1,65 @@ +package cjsfml.system + +foreign { + func sfBuffer_create(): CPointer + + func sfBuffer_destroy(handle: CPointer): Unit + + @FastNative + func sfBuffer_getSize(handle: CPointer): UIntNative + + @FastNative + func sfBuffer_getData(handle: CPointer): CPointer +} + +protected class Buffer <: ResourceHandle { + private var m_handle: CPointer = CPointer() + + public init() { + m_handle = unsafe { sfBuffer_create() } + if (m_handle.isNull()) { + throw SFMLNullHandleException() + } + } + + ~init() { + if (m_handle.isNotNull()) { + unsafe { sfBuffer_destroy(m_handle) } + m_handle = CPointer() + } + } + + // ResourceHandle + + public func isClosed(): Bool { + m_handle.isNull() + } + + public func close(): Unit { + if (isClosed()) { + return + } + unsafe { sfBuffer_destroy(m_handle) } + m_handle = CPointer() + } + + public prop handle: CPointer { + get() { + m_handle + } + } + + // buffer + + public prop size: Int64 { + get() { + unsafe { Int64(sfBuffer_getSize(m_handle)) } + } + } + + public prop data: CPointer { + get() { + unsafe { sfBuffer_getData(m_handle) } + } + } +}