box2d-ruby 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +21 -0
  3. data/README.md +336 -0
  4. data/examples/contact_events.rb +22 -0
  5. data/examples/debug_draw.rb +15 -0
  6. data/examples/falling_ball.rb +19 -0
  7. data/examples/rugl_debug_draw.rb +68 -0
  8. data/examples/stagecraft_debug_draw.rb +64 -0
  9. data/examples/support/box2d_debug_lines.rb +125 -0
  10. data/ext/box2d/CMakeLists.txt +35 -0
  11. data/ext/box2d/extconf.rb +42 -0
  12. data/ext/box2d/native.c +9 -0
  13. data/ext/box2d/vendor/box2d/LICENSE +21 -0
  14. data/ext/box2d/vendor/box2d/VERSION +1 -0
  15. data/ext/box2d/vendor/box2d/include/box2d/base.h +131 -0
  16. data/ext/box2d/vendor/box2d/include/box2d/box2d.h +1222 -0
  17. data/ext/box2d/vendor/box2d/include/box2d/collision.h +830 -0
  18. data/ext/box2d/vendor/box2d/include/box2d/id.h +144 -0
  19. data/ext/box2d/vendor/box2d/include/box2d/math_functions.h +761 -0
  20. data/ext/box2d/vendor/box2d/include/box2d/types.h +1457 -0
  21. data/ext/box2d/vendor/box2d/src/CMakeLists.txt +223 -0
  22. data/ext/box2d/vendor/box2d/src/aabb.c +132 -0
  23. data/ext/box2d/vendor/box2d/src/aabb.h +56 -0
  24. data/ext/box2d/vendor/box2d/src/arena_allocator.c +112 -0
  25. data/ext/box2d/vendor/box2d/src/arena_allocator.h +48 -0
  26. data/ext/box2d/vendor/box2d/src/array.c +8 -0
  27. data/ext/box2d/vendor/box2d/src/array.h +179 -0
  28. data/ext/box2d/vendor/box2d/src/atomic.h +79 -0
  29. data/ext/box2d/vendor/box2d/src/bitset.c +67 -0
  30. data/ext/box2d/vendor/box2d/src/bitset.h +65 -0
  31. data/ext/box2d/vendor/box2d/src/body.c +1884 -0
  32. data/ext/box2d/vendor/box2d/src/body.h +194 -0
  33. data/ext/box2d/vendor/box2d/src/box2d.natvis +41 -0
  34. data/ext/box2d/vendor/box2d/src/broad_phase.c +524 -0
  35. data/ext/box2d/vendor/box2d/src/broad_phase.h +83 -0
  36. data/ext/box2d/vendor/box2d/src/constants.h +54 -0
  37. data/ext/box2d/vendor/box2d/src/constraint_graph.c +322 -0
  38. data/ext/box2d/vendor/box2d/src/constraint_graph.h +58 -0
  39. data/ext/box2d/vendor/box2d/src/contact.c +650 -0
  40. data/ext/box2d/vendor/box2d/src/contact.h +148 -0
  41. data/ext/box2d/vendor/box2d/src/contact_solver.c +2120 -0
  42. data/ext/box2d/vendor/box2d/src/contact_solver.h +54 -0
  43. data/ext/box2d/vendor/box2d/src/core.c +178 -0
  44. data/ext/box2d/vendor/box2d/src/core.h +149 -0
  45. data/ext/box2d/vendor/box2d/src/ctz.h +112 -0
  46. data/ext/box2d/vendor/box2d/src/distance.c +1415 -0
  47. data/ext/box2d/vendor/box2d/src/distance_joint.c +556 -0
  48. data/ext/box2d/vendor/box2d/src/dynamic_tree.c +1989 -0
  49. data/ext/box2d/vendor/box2d/src/geometry.c +1028 -0
  50. data/ext/box2d/vendor/box2d/src/hull.c +328 -0
  51. data/ext/box2d/vendor/box2d/src/id_pool.c +79 -0
  52. data/ext/box2d/vendor/box2d/src/id_pool.h +35 -0
  53. data/ext/box2d/vendor/box2d/src/island.c +977 -0
  54. data/ext/box2d/vendor/box2d/src/island.h +89 -0
  55. data/ext/box2d/vendor/box2d/src/joint.c +1272 -0
  56. data/ext/box2d/vendor/box2d/src/joint.h +335 -0
  57. data/ext/box2d/vendor/box2d/src/manifold.c +1726 -0
  58. data/ext/box2d/vendor/box2d/src/math_functions.c +159 -0
  59. data/ext/box2d/vendor/box2d/src/motor_joint.c +283 -0
  60. data/ext/box2d/vendor/box2d/src/mouse_joint.c +214 -0
  61. data/ext/box2d/vendor/box2d/src/mover.c +73 -0
  62. data/ext/box2d/vendor/box2d/src/prismatic_joint.c +656 -0
  63. data/ext/box2d/vendor/box2d/src/revolute_joint.c +534 -0
  64. data/ext/box2d/vendor/box2d/src/sensor.c +389 -0
  65. data/ext/box2d/vendor/box2d/src/sensor.h +36 -0
  66. data/ext/box2d/vendor/box2d/src/shape.c +1714 -0
  67. data/ext/box2d/vendor/box2d/src/shape.h +123 -0
  68. data/ext/box2d/vendor/box2d/src/solver.c +2038 -0
  69. data/ext/box2d/vendor/box2d/src/solver.h +155 -0
  70. data/ext/box2d/vendor/box2d/src/solver_set.c +613 -0
  71. data/ext/box2d/vendor/box2d/src/solver_set.h +57 -0
  72. data/ext/box2d/vendor/box2d/src/table.c +238 -0
  73. data/ext/box2d/vendor/box2d/src/table.h +37 -0
  74. data/ext/box2d/vendor/box2d/src/timer.c +185 -0
  75. data/ext/box2d/vendor/box2d/src/types.c +151 -0
  76. data/ext/box2d/vendor/box2d/src/weld_joint.c +310 -0
  77. data/ext/box2d/vendor/box2d/src/wheel_joint.c +551 -0
  78. data/ext/box2d/vendor/box2d/src/world.c +3301 -0
  79. data/ext/box2d/vendor/box2d/src/world.h +192 -0
  80. data/generator/generate.rb +316 -0
  81. data/generator/layout_probe.c +507 -0
  82. data/generator/verify_layouts.rb +32 -0
  83. data/lib/box2d/body.rb +172 -0
  84. data/lib/box2d/body_definition.rb +38 -0
  85. data/lib/box2d/body_shapes.rb +135 -0
  86. data/lib/box2d/chain.rb +61 -0
  87. data/lib/box2d/debug_draw.rb +118 -0
  88. data/lib/box2d/events.rb +103 -0
  89. data/lib/box2d/fixed_stepper.rb +39 -0
  90. data/lib/box2d/handle.rb +46 -0
  91. data/lib/box2d/hit.rb +5 -0
  92. data/lib/box2d/joint.rb +197 -0
  93. data/lib/box2d/native.rb +1462 -0
  94. data/lib/box2d/native_loader.rb +45 -0
  95. data/lib/box2d/pixel_scale.rb +29 -0
  96. data/lib/box2d/shape.rb +109 -0
  97. data/lib/box2d/shape_definition.rb +44 -0
  98. data/lib/box2d/value_conversion.rb +80 -0
  99. data/lib/box2d/version.rb +7 -0
  100. data/lib/box2d/world.rb +135 -0
  101. data/lib/box2d/world_joints.rb +156 -0
  102. data/lib/box2d/world_queries.rb +122 -0
  103. data/lib/box2d/world_registry.rb +95 -0
  104. data/lib/box2d.rb +31 -0
  105. data/script/build_platform_gem.rb +24 -0
  106. data/script/deterministic_scene.rb +56 -0
  107. data/script/update_deterministic_snapshot.rb +11 -0
  108. data/script/verify_platform_gem.rb +24 -0
  109. metadata +164 -0
@@ -0,0 +1,35 @@
1
+ cmake_minimum_required(VERSION 3.16)
2
+
3
+ project(box2d_ruby_vendor LANGUAGES C)
4
+
5
+ file(GLOB BOX2D_VENDOR_SOURCES CONFIGURE_DEPENDS
6
+ "${CMAKE_CURRENT_SOURCE_DIR}/vendor/box2d/src/*.c"
7
+ )
8
+
9
+ add_library(box2d_vendor STATIC ${BOX2D_VENDOR_SOURCES})
10
+
11
+ target_include_directories(box2d_vendor
12
+ PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/vendor/box2d/include"
13
+ PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/vendor/box2d/src"
14
+ )
15
+ target_compile_definitions(box2d_vendor PRIVATE B2_ENABLE_ASSERT box2d_EXPORTS)
16
+
17
+ set_target_properties(box2d_vendor PROPERTIES
18
+ ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
19
+ C_STANDARD 17
20
+ C_STANDARD_REQUIRED YES
21
+ C_EXTENSIONS YES
22
+ POSITION_INDEPENDENT_CODE ON
23
+ )
24
+
25
+ foreach(configuration DEBUG RELEASE RELWITHDEBINFO MINSIZEREL)
26
+ set_target_properties(box2d_vendor PROPERTIES
27
+ "ARCHIVE_OUTPUT_DIRECTORY_${configuration}" "${CMAKE_BINARY_DIR}/lib"
28
+ )
29
+ endforeach()
30
+
31
+ if(MSVC)
32
+ target_compile_options(box2d_vendor PRIVATE /fp:strict)
33
+ else()
34
+ target_compile_options(box2d_vendor PRIVATE -ffp-contract=off)
35
+ endif()
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+ require "shellwords"
5
+
6
+ cmake = find_executable("cmake")
7
+ abort "CMake 3.16 or newer is required to build box2d-ruby from source" unless cmake
8
+
9
+ build_directory = File.expand_path("cmake-build", __dir__)
10
+ host_os = RbConfig::CONFIG.fetch("host_os")
11
+ configure = [
12
+ cmake,
13
+ "-S", __dir__,
14
+ "-B", build_directory,
15
+ "-DCMAKE_BUILD_TYPE=Release"
16
+ ]
17
+ if host_os.match?(/mingw/) && !ENV["CMAKE_GENERATOR"]
18
+ configure.concat(["-G", "MinGW Makefiles", "-DCMAKE_C_COMPILER=#{RbConfig::CONFIG.fetch("CC")}"])
19
+ end
20
+ build = [cmake, "--build", build_directory, "--config", "Release", "--target", "box2d_vendor"]
21
+
22
+ abort "CMake configuration failed for vendored Box2D" unless system(*configure)
23
+ abort "CMake build failed for vendored Box2D" unless system(*build)
24
+
25
+ archive = Dir[File.join(build_directory, "lib", "*box2d_vendor*.{a,lib}")].first
26
+ abort "CMake did not produce the vendored Box2D static library" unless archive
27
+
28
+ $srcs = ["native.c"]
29
+ $LIBRUBYARG_SHARED = ""
30
+ $LIBRUBYARG_STATIC = ""
31
+
32
+ escaped_archive = Shellwords.escape(archive)
33
+ case host_os
34
+ when /darwin/
35
+ $LDFLAGS << " -Wl,-force_load,#{escaped_archive}"
36
+ when /mswin/
37
+ $LOCAL_LIBS << " /WHOLEARCHIVE:#{escaped_archive}"
38
+ else
39
+ $LOCAL_LIBS << " -Wl,--whole-archive #{escaped_archive} -Wl,--no-whole-archive"
40
+ end
41
+
42
+ create_makefile("box2d/native")
@@ -0,0 +1,9 @@
1
+ #if defined(_WIN32)
2
+ #define BOX2D_RUBY_EXPORT __declspec(dllexport)
3
+ #else
4
+ #define BOX2D_RUBY_EXPORT __attribute__((visibility("default")))
5
+ #endif
6
+
7
+ BOX2D_RUBY_EXPORT void Init_native(void)
8
+ {
9
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Erin Catto
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ 3.1.0
@@ -0,0 +1,131 @@
1
+ // SPDX-FileCopyrightText: 2023 Erin Catto
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ #pragma once
5
+
6
+ #include <stdint.h>
7
+
8
+ // clang-format off
9
+ //
10
+ // Shared library macros
11
+ #if defined( _MSC_VER ) && defined( box2d_EXPORTS )
12
+ // build the Windows DLL
13
+ #define BOX2D_EXPORT __declspec( dllexport )
14
+ #elif defined( _MSC_VER ) && defined( BOX2D_DLL )
15
+ // using the Windows DLL
16
+ #define BOX2D_EXPORT __declspec( dllimport )
17
+ #elif defined( box2d_EXPORTS )
18
+ // building or using the shared library
19
+ #define BOX2D_EXPORT __attribute__( ( visibility( "default" ) ) )
20
+ #else
21
+ // static library
22
+ #define BOX2D_EXPORT
23
+ #endif
24
+
25
+ // C++ macros
26
+ #ifdef __cplusplus
27
+ #define B2_API extern "C" BOX2D_EXPORT
28
+ #define B2_INLINE inline
29
+ #define B2_LITERAL(T) T
30
+ #define B2_ZERO_INIT {}
31
+ #else
32
+ #define B2_API BOX2D_EXPORT
33
+ #define B2_INLINE static inline
34
+ /// Used for C literals like (b2Vec2){1.0f, 2.0f} where C++ requires b2Vec2{1.0f, 2.0f}
35
+ #define B2_LITERAL(T) (T)
36
+ #define B2_ZERO_INIT {0}
37
+ #endif
38
+ // clang-format on
39
+
40
+ /**
41
+ * @defgroup base Base
42
+ * Base functionality
43
+ * @{
44
+ */
45
+
46
+ /// Prototype for user allocation function
47
+ /// @param size the allocation size in bytes
48
+ /// @param alignment the required alignment, guaranteed to be a power of 2
49
+ typedef void* b2AllocFcn( unsigned int size, int alignment );
50
+
51
+ /// Prototype for user free function
52
+ /// @param mem the memory previously allocated through `b2AllocFcn`
53
+ typedef void b2FreeFcn( void* mem );
54
+
55
+ /// Prototype for the user assert callback. Return 0 to skip the debugger break.
56
+ typedef int b2AssertFcn( const char* condition, const char* fileName, int lineNumber );
57
+
58
+ /// This allows the user to override the allocation functions. These should be
59
+ /// set during application startup.
60
+ B2_API void b2SetAllocator( b2AllocFcn* allocFcn, b2FreeFcn* freeFcn );
61
+
62
+ /// @return the total bytes allocated by Box2D
63
+ B2_API int b2GetByteCount( void );
64
+
65
+ /// Override the default assert callback
66
+ /// @param assertFcn a non-null assert callback
67
+ B2_API void b2SetAssertFcn( b2AssertFcn* assertFcn );
68
+
69
+ /// Version numbering scheme.
70
+ /// See https://semver.org/
71
+ typedef struct b2Version
72
+ {
73
+ /// Significant changes
74
+ int major;
75
+
76
+ /// Incremental changes
77
+ int minor;
78
+
79
+ /// Bug fixes
80
+ int revision;
81
+ } b2Version;
82
+
83
+ /// Get the current version of Box2D
84
+ B2_API b2Version b2GetVersion( void );
85
+
86
+ /**@}*/
87
+
88
+ //! @cond
89
+
90
+ // see https://github.com/scottt/debugbreak
91
+ #if defined( _MSC_VER )
92
+ #define B2_BREAKPOINT __debugbreak()
93
+ #elif defined( __GNUC__ ) || defined( __clang__ )
94
+ #define B2_BREAKPOINT __builtin_trap()
95
+ #else
96
+ // Unknown compiler
97
+ #include <assert.h>
98
+ #define B2_BREAKPOINT assert( 0 )
99
+ #endif
100
+
101
+ #if !defined( NDEBUG ) || defined( B2_ENABLE_ASSERT )
102
+ B2_API int b2InternalAssertFcn( const char* condition, const char* fileName, int lineNumber );
103
+ #define B2_ASSERT( condition ) \
104
+ do \
105
+ { \
106
+ if ( !( condition ) && b2InternalAssertFcn( #condition, __FILE__, (int)__LINE__ ) ) \
107
+ B2_BREAKPOINT; \
108
+ } \
109
+ while ( 0 )
110
+ #else
111
+ #define B2_ASSERT( ... ) ( (void)0 )
112
+ #endif
113
+
114
+ /// Get the absolute number of system ticks. The value is platform specific.
115
+ B2_API uint64_t b2GetTicks( void );
116
+
117
+ /// Get the milliseconds passed from an initial tick value.
118
+ B2_API float b2GetMilliseconds( uint64_t ticks );
119
+
120
+ /// Get the milliseconds passed from an initial tick value. Resets the passed in
121
+ /// value to the current tick value.
122
+ B2_API float b2GetMillisecondsAndReset( uint64_t* ticks );
123
+
124
+ /// Yield to be used in a busy loop.
125
+ B2_API void b2Yield( void );
126
+
127
+ /// Simple djb2 hash function for determinism testing
128
+ #define B2_HASH_INIT 5381
129
+ B2_API uint32_t b2Hash( uint32_t hash, const uint8_t* data, int count );
130
+
131
+ //! @endcond