Browse Source

Set up GitHub Actions correctly on my first try

Lucien Greathouse 1 year ago
parent
commit
cdcf8ecba2
5 changed files with 148 additions and 8 deletions
  1. 51 0
      .github/workflows/ci.yml
  2. 19 0
      CMakeLists.txt
  3. 1 1
      HelloWorld/main.cpp
  4. 61 7
      JoltC/Functions.h
  5. 16 0
      test-all-flags.sh

+ 51 - 0
.github/workflows/ci.yml

@@ -0,0 +1,51 @@
+name: Test Suite
+
+on:
+  push:
+    branches:
+      - main
+
+  pull_request:
+    branches:
+      - main
+
+jobs:
+  test-suite:
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [ubuntu-latest, windows-latest]
+        build_type: [Debug, Release]
+        build_flags: ['', '-DDOUBLE_PRECISION=ON', '-DOBJECT_LAYER_BITS=32']
+
+    runs-on: ${{ matrix.os }}
+    name: Tests - ${{ matrix.os }} ${{ matrix.build_type }} ${{ matrix.build_flags }}
+
+    steps:
+    - uses: actions/checkout@v4
+      with:
+        submodules: true
+
+    - name: Setup C++ Tooling
+      uses: aminya/setup-cpp@v1
+      with:
+        compiler: ${{ contains(matrix.os, 'windows') && 'msvc' || 'clang' }}
+        cmake: true
+
+    - name: Configure CMake
+      run: cmake -B build ${{ matrix.build_flags }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
+
+    - name: Build
+      run: cmake --build build --config=${{ matrix.build_type }}
+
+    - name: Run Hello World
+      shell: bash
+      run: |
+        ./build/${{ matrix.build_type }}/HelloWorld
+      if: ${{ contains(matrix.os, 'windows') }}
+
+    - name: Run Hello World
+      shell: bash
+      run: |
+        ./build/HelloWorld
+      if: ${{ !contains(matrix.os, 'windows') }}

+ 19 - 0
CMakeLists.txt

@@ -6,6 +6,17 @@ project(JoltC VERSION 0.1
     DESCRIPTION "C Wrapper for Jolt Physics"
     LANGUAGES C CXX)
 
+# When turning this option on, the library will be compiled using doubles for positions. This allows for much bigger worlds.
+option(DOUBLE_PRECISION "Use double precision math" OFF)
+
+# Number of bits to use in ObjectLayer. Can be 16 or 32.
+option(OBJECT_LAYER_BITS "Number of bits in ObjectLayer" 16)
+
+# Only do this when we're at the top level, see: https://gitlab.kitware.com/cmake/cmake/-/issues/24181
+if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
+    set(CMAKE_CONFIGURATION_TYPES "Debug;Release")
+endif()
+
 add_library(joltc STATIC
     JoltC/JoltC.h
     JoltC/JoltC.cpp
@@ -27,6 +38,14 @@ else()
   target_compile_options(joltc PRIVATE -Wall -Wextra -Wpedantic)
 endif()
 
+if (DOUBLE_PRECISION)
+    target_compile_definitions(joltc PUBLIC JPC_DOUBLE_PRECISION)
+endif()
+
+if (OBJECT_LAYER_BITS)
+    target_compile_definitions(joltc PUBLIC JPC_OBJECT_LAYER_BITS=${OBJECT_LAYER_BITS})
+endif()
+
 add_executable(HelloWorld
     HelloWorld/main.cpp
 )

+ 1 - 1
HelloWorld/main.cpp

@@ -123,7 +123,7 @@ int main() {
 	// TODO: register contact listener
 
 	const JPC_BodyInterface* body_interface = JPC_PhysicsSystem_GetBodyInterface(physics_system);
-	// TODO: body interface
+
 	// TODO: creating bodies
 	// TODO: PhysicsSystem::OptimizeBroadPhase
 

+ 61 - 7
JoltC/Functions.h

@@ -2,8 +2,13 @@
 
 #include <stdint.h>
 #include <stdbool.h>
+#include <stdalign.h>
 
-#define JPC_API extern __declspec(dllexport)
+#ifdef _MSC_VER
+	#define JPC_API extern __declspec(dllexport)
+#else
+	#define JPC_API
+#endif
 
 // C-compatible typedefs that match Jolt's internal primitive typedefs.
 #define uint unsigned int
@@ -18,6 +23,61 @@ JPC_API void JPC_FactoryDelete();
 JPC_API void JPC_RegisterTypes();
 JPC_API void JPC_UnregisterTypes();
 
+////////////////////////////////////////////////////////////////////////////////
+// Primitive types
+
+typedef struct JPC_Vec3 {
+	alignas(16) float x;
+	float y;
+	float z;
+	float _w;
+} JPC_Vec3;
+
+ENSURE_SIZE_ALIGN(JPC_Vec3, JPH::Vec3);
+
+typedef struct JPC_DVec3 {
+	alignas(32) double x;
+	double y;
+	double z;
+	double _w;
+} JPC_DVec3;
+
+ENSURE_SIZE_ALIGN(JPC_DVec3, JPH::DVec3);
+
+typedef struct JPC_Quat {
+	alignas(16) float x;
+	float y;
+	float z;
+	float w;
+} JPC_Quat;
+
+ENSURE_SIZE_ALIGN(JPC_Quat, JPH::Quat);
+
+#ifdef JPC_DOUBLE_PRECISION
+	typedef JPC_DVec3 JPC_RVec3;
+#else
+	typedef JPC_Vec3 JPC_RVec3;
+#endif
+
+ENSURE_SIZE_ALIGN(JPC_RVec3, JPH::RVec3);
+
+typedef uint8_t JPC_BroadPhaseLayer;
+ENSURE_SIZE_ALIGN(JPC_BroadPhaseLayer, JPH::BroadPhaseLayer)
+
+#ifndef JPC_OBJECT_LAYER_BITS
+	#define JPC_OBJECT_LAYER_BITS 16
+#endif
+
+#if JPC_OBJECT_LAYER_BITS == 16
+	typedef uint16_t JPC_ObjectLayer;
+#elif JPC_OBJECT_LAYER_BITS == 32
+	typedef uint32_t JPC_ObjectLayer;
+#else
+	#error "JPC_OBJECT_LAYER_BITS must be 16 or 32"
+#endif
+
+ENSURE_SIZE_ALIGN(JPC_ObjectLayer, JPH::ObjectLayer)
+
 ////////////////////////////////////////////////////////////////////////////////
 // TempAllocatorImpl
 
@@ -44,12 +104,6 @@ JPC_API void JPC_JobSystemThreadPool_delete(JPC_JobSystemThreadPool* object);
 ////////////////////////////////////////////////////////////////////////////////
 // BroadPhaseLayerInterface
 
-typedef uint8_t JPC_BroadPhaseLayer;
-ENSURE_SIZE_ALIGN(JPC_BroadPhaseLayer, JPH::BroadPhaseLayer)
-
-typedef uint16_t JPC_ObjectLayer; // FIXME: Branch on JPH_OBJECT_LAYER_BITS?
-ENSURE_SIZE_ALIGN(JPC_ObjectLayer, JPH::ObjectLayer)
-
 typedef struct JPC_BroadPhaseLayerInterfaceFns {
 	uint (*GetNumBroadPhaseLayers)(const void *self);
 	JPC_BroadPhaseLayer (*GetBroadPhaseLayer)(const void *self, JPC_ObjectLayer inLayer);

+ 16 - 0
test-all-flags.sh

@@ -0,0 +1,16 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+run_tests() {
+	echo "Building with flags $1"
+
+	cmake $1 -B build
+	cmake --build build
+
+	./build/Debug/HelloWorld
+}
+
+run_tests ""
+run_tests "-DDOUBLE_PRECISION=ON"
+run_tests "-DOBJECT_LAYER_BITS=32"