chipmunk 5.3.4.0-x86-mingw32 → 5.3.4.2-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/README +33 -13
  2. data/Rakefile +20 -7
  3. data/ext/chipmunk/extconf.rb +55 -12
  4. data/ext/chipmunk/rb_chipmunk.c +92 -98
  5. data/ext/chipmunk/rb_chipmunk.h +44 -34
  6. data/ext/chipmunk/rb_cpArbiter.c +135 -98
  7. data/ext/chipmunk/rb_cpBB.c +84 -101
  8. data/ext/chipmunk/rb_cpBody.c +219 -241
  9. data/ext/chipmunk/rb_cpConstraint.c +173 -185
  10. data/ext/chipmunk/rb_cpShape.c +347 -251
  11. data/ext/chipmunk/rb_cpSpace.c +376 -408
  12. data/ext/chipmunk/rb_cpVect.c +132 -170
  13. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/chipmunk.h +163 -0
  14. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/chipmunk_ffi.h +59 -0
  15. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/chipmunk_private.h +49 -0
  16. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/chipmunk_types.h +151 -0
  17. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/chipmunk_unsafe.h +54 -0
  18. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpConstraint.h +105 -0
  19. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpDampedRotarySpring.h +46 -0
  20. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpDampedSpring.h +53 -0
  21. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpGearJoint.h +41 -0
  22. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpGrooveJoint.h +48 -0
  23. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpPinJoint.h +43 -0
  24. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpPivotJoint.h +42 -0
  25. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpRatchetJoint.h +40 -0
  26. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpRotaryLimitJoint.h +39 -0
  27. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpSimpleMotor.h +37 -0
  28. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpSlideJoint.h +44 -0
  29. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/util.h +134 -0
  30. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpArbiter.h +188 -0
  31. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpArray.h +49 -0
  32. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpBB.h +74 -0
  33. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpBody.h +219 -0
  34. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpCollision.h +28 -0
  35. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpHashSet.h +82 -0
  36. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpPolyShape.h +103 -0
  37. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpShape.h +177 -0
  38. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpSpace.h +206 -0
  39. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpSpaceHash.h +110 -0
  40. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpVect.h +207 -0
  41. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/chipmunk.c +151 -0
  42. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpConstraint.c +54 -0
  43. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpDampedRotarySpring.c +105 -0
  44. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpDampedSpring.c +115 -0
  45. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpGearJoint.c +113 -0
  46. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpGrooveJoint.c +161 -0
  47. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpPinJoint.c +116 -0
  48. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpPivotJoint.c +114 -0
  49. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpRatchetJoint.c +126 -0
  50. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpRotaryLimitJoint.c +120 -0
  51. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpSimpleMotor.c +97 -0
  52. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpSlideJoint.c +129 -0
  53. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpArbiter.c +280 -0
  54. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpArray.c +143 -0
  55. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpBB.c +47 -0
  56. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpBody.c +192 -0
  57. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpCollision.c +411 -0
  58. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpHashSet.c +253 -0
  59. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpPolyShape.c +240 -0
  60. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpShape.c +405 -0
  61. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpSpace.c +499 -0
  62. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpSpaceComponent.c +279 -0
  63. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpSpaceHash.c +534 -0
  64. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpSpaceQuery.c +246 -0
  65. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpSpaceStep.c +398 -0
  66. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpVect.c +71 -0
  67. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/prime.h +68 -0
  68. data/lib/1.9/chipmunk.so +0 -0
  69. data/lib/chipmunk.rb +19 -8
  70. metadata +84 -42
  71. data/lib/1.8/chipmunk.so +0 -0
data/README CHANGED
@@ -3,7 +3,8 @@ Ruby Bindings to Chipmunk Physics Version 5.3.4
3
3
  (C) Scott Lembcke, Beoran and John Mair (banisterfiend)
4
4
 
5
5
  IMPORTANT NOTICE:
6
- These are bindings for MRI Ruby 1.8.x and 1.9.x to Chipmunk version 5.3.4
6
+ These is version 5.3.4.2 of the bindings for MRI Ruby 1.8.x and 1.9.x to
7
+ Chipmunk version 5.3.4.
7
8
 
8
9
  (1) 1/10/09 Cross-Platform Gem built by John Mair (banisterfiend)
9
10
  * Just go: gem install chipmunk
@@ -20,7 +21,7 @@ ABOUT CHIPMUNK:
20
21
  written in C by Slembcke. It's licensed under the unrestrictive, OSI approved
21
22
  MIT license.
22
23
 
23
- ABOUT THESE RUBY BINDINGS:
24
+ ABOUT THESE RUBY BINDINGS:
24
25
  Although chipmunk comes with ruby bindings, they are not always up to date
25
26
  with regards to the functionality of the C library, and historically, they
26
27
  have been incompatible with recent versions of Ruby.
@@ -30,17 +31,35 @@ ABOUT THESE RUBY BINDINGS:
30
31
  intended to be an alternative to the chipmunk-ffi bindings when performance
31
32
  is of the utmost importance, as it may be for games.
32
33
 
33
- The intent is for these bindings to be mostly source code compatible with both
34
- Slembcke's and ffi's bindings. Main exceptions are where I dislike either API.
35
- In that case, I made an API that is pleasing to myself, and similar in naming
36
- to the C API adjusted to ruby conventions. If you have any problems with these bindings, please contact the maintainer at beoran@rubyforge.org.
34
+ The intent is for these bindings to be mostly source code compatible with the
35
+ FFI bindings. Main exceptions are when it did not support the functionality I
36
+ added yet. All this is documented by specs and by the html documentation.
37
37
 
38
+ If you have any problems with these bindings, please contact the maintainer at
39
+ beoran@rubyforge.org, or report the issue on the issue tracker:
40
+ https://github.com/beoran/chipmunk/issues
41
+
42
+ INSTALLATION
43
+ These bindings vendor Chipmunk 5.3.4 with a few extra patches, so a gem
44
+ install chipmunk should do the trick. Optionally, the C chipmunk library
45
+ may be installed separately. To compile without vendoring, go to the
46
+ ext/chipmunk directory and compile with ruby extconf.rb --disable-vendor ;
47
+ make ; make install.
48
+
38
49
  DOCUMENTATION:
50
+ Full handcrafted documentation based on the C documentation is available at:
39
51
  http://beoran.github.com/chipmunk/
40
52
 
41
- INCOMPATIBILITIES:
42
- There are no bindings to SpaceHash since I fail to see the use of it, but
43
- if someone is using them, I'll probably implement them.
53
+ CHANGES:
54
+ * Since 5.3.4.1: Vendored chipmunk again, cleanly. Several bugfixes.
55
+ * Since 5.1.0 : Much more of Chipmunk's functionality is wrapped. Unvendored
56
+ chipmunk. More specs and documentation.
57
+
58
+ KNOWN BUGS:
59
+ * There are no bindings to SpaceHash since I think they are not so useful
60
+ anymore since Chipmunk supports BB queries.
61
+ * Some methods may crash with a segentation violation in case they are not
62
+ used correctly, according to the underlying requirements of the C library.
44
63
 
45
64
  CONTRACTING:
46
65
  Howling Moon Software (Slembke's company) is available for contracting if you
@@ -48,10 +67,11 @@ CONTRACTING:
48
67
  them through their webpage: http://howlingmoonsoftware.com/contracting.php
49
68
 
50
69
  TODO:
51
- * More functionality.
52
- * Specs for the new functionality I've wrapped and will wrap.
53
- * Better documentation, perhaps based on C API documentation.
54
-
70
+ * Allow several constructors to be more flexible and take nil as a default
71
+ argument.
72
+ * Try to prevent segfauts on incorrect use of certain methods, if possible.
73
+ * Get ready for chipmunk 5.3.5 and 6.x when they come out.
74
+ * Some more specs.
55
75
 
56
76
  INFO FOR MAINTAINERS:
57
77
 
data/Rakefile CHANGED
@@ -1,7 +1,13 @@
1
1
  # Rakefile added by John Mair (banisterfiend)
2
2
 
3
- require 'rake/gempackagetask'
3
+ # require 'rake/gempackagetask'
4
+ require 'psych'
5
+ require 'rake'
4
6
  require 'rake/clean'
7
+ require 'rubygems'
8
+ require 'rubygems/package_task'
9
+
10
+
5
11
 
6
12
  begin
7
13
  require 'rake/extensiontask'
@@ -12,7 +18,13 @@ rescue LoadError
12
18
  # puts "...done!"
13
19
  end
14
20
 
15
- CHIPMUNK_VERSION = "5.3.4.0"
21
+ CHIPMUNK_VERSION = "5.3.4.2"
22
+ VENDORED_CHIPMUNK = 'chipmunk-5.3.4'
23
+ VENDORED_SRC_DIR = File.join('vendor', VENDORED_CHIPMUNK, 'src')
24
+ VENDORED_SRC_DIR2 = File.join('vendor', VENDORED_CHIPMUNK, 'src', 'constraints')
25
+ VENDORED_INCLUDE_DIR = File.join('vendor', VENDORED_CHIPMUNK, 'include', 'chipmunk')
26
+
27
+
16
28
 
17
29
  dlext = Config::CONFIG['DLEXT']
18
30
 
@@ -42,22 +54,23 @@ if RUBY_PLATFORM =~ /darwin/
42
54
  spec = Gem::Specification.new do |s|
43
55
  apply_spec_defaults(s)
44
56
  s.platform = Gem::Platform::CURRENT
45
- s.files = ["Rakefile", "README", "LICENSE", "lib/chipmunk.rb", "lib/1.8/chipmunk.#{dlext}", "lib/1.9/chipmunk.#{dlext}"]
57
+ s.files = ["Rakefile", "README", "LICENSE", "lib/chipmunk.rb", "lib/1.8/chipmunk.#{dlext}", "lib/1.9/chipmunk.#{dlext}"] +
58
+ FileList["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c"].to_a
46
59
  end
47
60
 
48
61
  Rake::ExtensionTask.new('chipmunk') do |ext|
49
62
  ext.ext_dir = "ext"
50
63
  ext.lib_dir = "lib/#{RUBY_VERSION[0..2]}"
51
64
  ext.config_script = 'extconf.rb'
52
- ext.config_options << 'macosx'
65
+ ext.config_options << '--enable-macosx'
53
66
  end
54
67
 
55
68
  task :compile_multi => :clean do
56
- `/bin/bash -l -c "rvm 1.8.6,1.9.1 rake compile"`
69
+ `/bin/bash -l -c "rvm 1.8.6,1.9.2 rake compile"`
57
70
  end
58
71
 
59
72
  task :gem => :compile_multi
60
- Rake::GemPackageTask.new(spec) do |pkg|
73
+ Gem::PackageTask.new(spec) do |pkg|
61
74
  pkg.need_zip = false
62
75
  pkg.need_tar = false
63
76
  end
@@ -79,7 +92,7 @@ else
79
92
  # ext.cross_platform = 'i386-mswin32'
80
93
  end
81
94
 
82
- Rake::GemPackageTask.new(spec) do |pkg|
95
+ Gem::PackageTask.new(spec) do |pkg|
83
96
  pkg.need_zip = false
84
97
  pkg.need_tar = false
85
98
  end
@@ -2,41 +2,84 @@ require 'mkmf'
2
2
 
3
3
  RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
4
4
 
5
+ if ARGV.member?('--help') || ARGV.member?('-?')
6
+ puts "ruby extconf.rb:"
7
+ puts "Options for the Ruby bindings to Chipmunk: "
8
+ puts "--disable-vendor Disables vendoring Chipmunk."
9
+ puts "--enable-vendor Enables vendoring Chipmunk."
10
+ puts "--enable-macosx Enables compiling for OS-X."
11
+ puts "--enable-64 Enables compiling to 64 bits targets."
12
+ puts
13
+ exit
14
+ end
15
+
16
+ p "pwd", Dir.pwd
17
+
5
18
  dir_config('chipmunk')
6
19
 
20
+ VENDORED_CHIPMUNK = 'chipmunk-5.3.4'
21
+ VENDORED_SRC_DIR = File.join($srcdir, 'vendor', VENDORED_CHIPMUNK, 'src')
22
+ VENDORED_SRC_DIR2 = File.join($srcdir, 'vendor', VENDORED_CHIPMUNK, 'src',
23
+ 'constraints')
24
+ VENDORED_INCLUDE_DIR = File.join($srcdir, 'vendor', VENDORED_CHIPMUNK, 'include',
25
+ 'chipmunk')
26
+
27
+
7
28
  MINGW = '/usr/i586-mingw32msvc'
8
29
  CHIPMUNK_HEADER = 'chipmunk.h'
9
30
  CHIPMUNK_NAME = 'chipmunk'
10
31
  CHIPMUNK_FUNCTION = 'cpMomentForPoly'
11
- CHIPMUNK_INCLUDE = ['/usr/include',
32
+ CHIPMUNK_INCLUDE = [ '/usr/include',
12
33
  File.join(MINGW, 'include'),
13
34
  File.join(MINGW, 'include', 'chipmunk'),
14
35
  '/usr/local/include',
15
36
  '/usr/include/chipmunk',
16
37
  '/usr/local/include/chipmunk'
17
38
  ]
18
- CHIPMUNK_LIBDIR = ['/usr/lib',
19
- File.join(MINGW, 'lib'),
20
- '/usr/local/lib']
39
+ CHIPMUNK_LIBDIR = ['/usr/lib', File.join(MINGW, 'lib'), '/usr/local/lib']
21
40
 
22
- unless find_header(CHIPMUNK_HEADER, *CHIPMUNK_INCLUDE)
23
- raise "Could not find Chipmunk headers!"
24
- end
41
+ # This is a bit of a trick to cleanly vendor the chipmunk C library.
42
+ sources = Dir.glob(File.join($srcdir, 'rb_*.c')).to_a
43
+ # normally, we need the rb_xxx files...
25
44
 
26
45
 
27
- unless find_library(CHIPMUNK_NAME, CHIPMUNK_FUNCTION, *CHIPMUNK_LIBDIR)
28
- raise "Could not link to Chipmunk library!"
46
+ if enable_config("vendor", true)
47
+ unless find_header(CHIPMUNK_HEADER, VENDORED_INCLUDE_DIR)
48
+ raise "Vendored chipmunk #{VENDORED_INCLUDE_DIR} not found!"
49
+ end
50
+ CHIPMUNK_INCLUDE .unshift(VENDORED_INCLUDE_DIR)
51
+ sources += Dir.glob(File.join(VENDORED_SRC_DIR, '*.c'))
52
+ sources += Dir.glob(File.join(VENDORED_SRC_DIR2, '*.c'))
53
+ # when vendoring, also include the needed c files files...
54
+
55
+
56
+ else
57
+ unless find_header(CHIPMUNK_HEADER, *CHIPMUNK_INCLUDE)
58
+ raise "Could not find Chipmunk headers!"
59
+ end
60
+
61
+ unless find_library(CHIPMUNK_NAME, CHIPMUNK_FUNCTION, *CHIPMUNK_LIBDIR)
62
+ raise "Could not link to Chipmunk library!"
63
+ end
29
64
  end
30
65
 
66
+ # this is the core of the trick, it overrides create_makefile's looking for
67
+ # based on the c files
68
+ $objs = sources.map { |s| s.gsub(/.c\Z/,'.o') }
69
+
70
+
31
71
  =begin
32
72
  have_header('chipmunk.h', include_dirs)
33
73
  =end
34
-
35
- if ARGV[0] == "macosx"
74
+ if enable_config("macosx", false)
36
75
  $CFLAGS += ' -arch ppc -arch i386 -arch x86_64'
37
76
  $LDFLAGS += ' -arch x86_64 -arch i386 -arch ppc'
38
77
  end
78
+
79
+ if enable_config("64", false)
80
+ $CFLAGS += ' -m64'
81
+ end
39
82
 
40
- $CFLAGS += ' -std=gnu99 -ffast-math'
83
+ $CFLAGS += ' -std=gnu99 -ffast-math -DNDEBUG '
41
84
  create_makefile('chipmunk')
42
85
 
@@ -1,15 +1,15 @@
1
1
  /* Copyright (c) 2007 Scott Lembcke
2
- *
2
+ *
3
3
  * Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  * of this software and associated documentation files (the "Software"), to deal
5
5
  * in the Software without restriction, including without limitation the rights
6
6
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
7
  * copies of the Software, and to permit persons to whom the Software is
8
8
  * furnished to do so, subject to the following conditions:
9
- *
9
+ *
10
10
  * The above copyright notice and this permission notice shall be included in
11
11
  * all copies or substantial portions of the Software.
12
- *
12
+ *
13
13
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
14
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
15
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -32,65 +32,62 @@ ID id_parent;
32
32
 
33
33
  static VALUE
34
34
  rb_get_cp_bias_coef(VALUE self) {
35
- return rb_float_new(cp_bias_coef);
35
+ return rb_float_new(cp_bias_coef);
36
36
  }
37
37
 
38
38
  static VALUE
39
39
  rb_set_cp_bias_coef(VALUE self, VALUE num) {
40
- cp_bias_coef = NUM2DBL(num);
41
- return num;
40
+ cp_bias_coef = NUM2DBL(num);
41
+ return num;
42
42
  }
43
43
 
44
44
  static VALUE
45
45
  rb_get_cp_collision_slop(VALUE self) {
46
- return rb_float_new(cp_collision_slop);
46
+ return rb_float_new(cp_collision_slop);
47
47
  }
48
48
 
49
49
  static VALUE
50
50
  rb_set_cp_collision_slop(VALUE self, VALUE num) {
51
- cp_collision_slop = NUM2DBL(num);
52
- return num;
51
+ cp_collision_slop = NUM2DBL(num);
52
+ return num;
53
53
  }
54
54
 
55
55
  static VALUE
56
56
  rb_set_cp_contact_persistence(VALUE self, VALUE num) {
57
- cp_contact_persistence = NUM2DBL(num);
57
+ cp_contact_persistence = NUM2UINT(num);
58
58
  return num;
59
59
  }
60
60
 
61
61
  static VALUE
62
- rb_get_cp_contact_persistence(VALUE self) {
63
- return rb_float_new(cp_contact_persistence);
62
+ rb_get_cp_contact_persistence(VALUE self) {
63
+ return UINT2NUM(cp_contact_persistence);
64
64
  }
65
65
 
66
66
 
67
67
  static VALUE
68
- rb_cpMomentForCircle(VALUE self, VALUE m, VALUE r1, VALUE r2, VALUE offset)
69
- {
70
- cpFloat i = cpMomentForCircle(NUM2DBL(m), NUM2DBL(r1), NUM2DBL(r2), *VGET(offset));
71
- return rb_float_new(i);
68
+ rb_cpMomentForCircle(VALUE self, VALUE m, VALUE r1, VALUE r2, VALUE offset) {
69
+ cpFloat i = cpMomentForCircle(NUM2DBL(m), NUM2DBL(r1), NUM2DBL(r2), *VGET(offset));
70
+ return rb_float_new(i);
72
71
  }
73
72
 
74
73
  static VALUE
75
- rb_cpMomentForSegment(VALUE self, VALUE m, VALUE v1, VALUE v2)
76
- {
74
+ rb_cpMomentForSegment(VALUE self, VALUE m, VALUE v1, VALUE v2) {
77
75
  cpFloat i = cpMomentForSegment(NUM2DBL(m), *VGET(v1), *VGET(v2));
78
76
  return rb_float_new(i);
79
77
  }
80
78
 
81
79
  static VALUE
82
- rb_cpMomentForPoly(VALUE self, VALUE m, VALUE arr, VALUE offset)
83
- {
84
- Check_Type(arr, T_ARRAY);
85
- int numVerts = RARRAY_LEN(arr);
86
- VALUE *ary_ptr = RARRAY_PTR(arr);
87
- cpVect verts[numVerts];
88
-
89
- for(int i=0; i<numVerts; i++)
90
- verts[i] = *VGET(ary_ptr[i]);
91
-
92
- cpFloat inertia = cpMomentForPoly(NUM2DBL(m), numVerts, verts, *VGET(offset));
93
- return rb_float_new(inertia);
80
+ rb_cpMomentForPoly(VALUE self, VALUE m, VALUE arr, VALUE offset) {
81
+ Check_Type(arr, T_ARRAY);
82
+ long numVerts = RARRAY_LEN(arr);
83
+ VALUE *ary_ptr = RARRAY_PTR(arr);
84
+ cpVect verts[numVerts];
85
+
86
+ for(long i = 0; i < numVerts; i++)
87
+ verts[i] = *VGET(ary_ptr[i]);
88
+
89
+ cpFloat inertia = cpMomentForPoly(NUM2DBL(m), numVerts, verts, *VGET(offset));
90
+ return rb_float_new(inertia);
94
91
  }
95
92
 
96
93
  static VALUE
@@ -100,31 +97,28 @@ rb_cpMomentForBox(VALUE self, VALUE m, VALUE w, VALUE h) {
100
97
  }
101
98
 
102
99
  static VALUE
103
- rb_cpAreaForCircle(VALUE self, VALUE r1, VALUE r2)
104
- {
100
+ rb_cpAreaForCircle(VALUE self, VALUE r1, VALUE r2) {
105
101
  cpFloat i = cpAreaForCircle(NUM2DBL(r1), NUM2DBL(r2));
106
102
  return rb_float_new(i);
107
103
  }
108
104
 
109
105
  static VALUE
110
- rb_cpAreaForSegment(VALUE self, VALUE v1, VALUE v2, VALUE r)
111
- {
106
+ rb_cpAreaForSegment(VALUE self, VALUE v1, VALUE v2, VALUE r) {
112
107
  cpFloat i = cpAreaForSegment(*VGET(v1), *VGET(v2), NUM2DBL(r));
113
108
  return rb_float_new(i);
114
109
  }
115
110
 
116
111
  static VALUE
117
- rb_cpAreaForPoly(VALUE self, VALUE arr)
118
- {
112
+ rb_cpAreaForPoly(VALUE self, VALUE arr) {
119
113
  Check_Type(arr, T_ARRAY);
120
- int numVerts = RARRAY_LEN(arr);
114
+ long numVerts = RARRAY_LEN(arr);
121
115
  VALUE *ary_ptr = RARRAY_PTR(arr);
122
116
  cpVect verts[numVerts];
123
-
124
- for(int i=0; i<numVerts; i++)
117
+
118
+ for(long i = 0; i < numVerts; i++)
125
119
  verts[i] = *VGET(ary_ptr[i]);
126
-
127
- cpFloat area = cpAreaForPoly(numVerts, verts);
120
+
121
+ cpFloat area = cpAreaForPoly(numVerts, verts);
128
122
  return rb_float_new(area);
129
123
  }
130
124
 
@@ -135,49 +129,50 @@ rb_cpAreaForBox(VALUE self, VALUE w, VALUE h) {
135
129
  }
136
130
 
137
131
 
138
- static VALUE rb_cpfclamp(VALUE self, VALUE f, VALUE min, VALUE max) {
132
+ static VALUE
133
+ rb_cpfclamp(VALUE self, VALUE f, VALUE min, VALUE max) {
139
134
  cpFloat result = cpfclamp(NUM2DBL(f), NUM2DBL(min), NUM2DBL(max));
140
135
  return rb_float_new(result);
141
- }
136
+ }
142
137
 
143
- static VALUE rb_cpflerp(VALUE self, VALUE f1, VALUE f2, VALUE t) {
138
+ static VALUE
139
+ rb_cpflerp(VALUE self, VALUE f1, VALUE f2, VALUE t) {
144
140
  cpFloat result = cpflerp(NUM2DBL(f1), NUM2DBL(f2), NUM2DBL(t));
145
141
  return rb_float_new(result);
146
- }
142
+ }
147
143
 
148
- static VALUE rb_cpflerpconst(VALUE self, VALUE f1, VALUE f2, VALUE d) {
144
+ static VALUE
145
+ rb_cpflerpconst(VALUE self, VALUE f1, VALUE f2, VALUE d) {
149
146
  cpFloat result = cpflerpconst(NUM2DBL(f1), NUM2DBL(f2), NUM2DBL(d));
150
147
  return rb_float_new(result);
151
- }
148
+ }
152
149
 
153
150
  static VALUE
154
- rb_cpCentroidForPoly(VALUE self, VALUE arr)
155
- {
151
+ rb_cpCentroidForPoly(VALUE self, VALUE arr) {
156
152
  Check_Type(arr, T_ARRAY);
157
- int numVerts = RARRAY_LEN(arr);
153
+ long numVerts = RARRAY_LEN(arr);
158
154
  VALUE *ary_ptr = RARRAY_PTR(arr);
159
155
  cpVect verts[numVerts];
160
-
161
- for(int i=0; i<numVerts; i++)
156
+
157
+ for(long i = 0; i < numVerts; i++)
162
158
  verts[i] = *VGET(ary_ptr[i]);
163
-
159
+
164
160
  return VNEW(cpCentroidForPoly(numVerts, verts));
165
161
  }
166
162
 
167
163
  static VALUE
168
- rb_cpRecenterPoly(VALUE self, VALUE arr)
169
- {
164
+ rb_cpRecenterPoly(VALUE self, VALUE arr) {
170
165
  Check_Type(arr, T_ARRAY);
171
- int numVerts = RARRAY_LEN(arr);
166
+ long numVerts = RARRAY_LEN(arr);
172
167
  VALUE *ary_ptr = RARRAY_PTR(arr);
173
168
  cpVect verts[numVerts];
174
-
175
- for(int i=0; i<numVerts; i++)
169
+
170
+ for(long i = 0; i < numVerts; i++)
176
171
  verts[i] = *VGET(ary_ptr[i]);
177
-
172
+
178
173
  cpRecenterPoly(numVerts, verts);
179
-
180
- for(int i=0; i<numVerts; i++)
174
+
175
+ for(long i = 0; i < numVerts; i++)
181
176
  ary_ptr[i] = VNEW(verts[i]);
182
177
  return arr;
183
178
  }
@@ -186,65 +181,64 @@ rb_cpRecenterPoly(VALUE self, VALUE arr)
186
181
 
187
182
 
188
183
  void
189
- Init_chipmunk(void)
190
- {
191
- id_parent = rb_intern("parent");
192
-
193
- cpInitChipmunk();
194
-
195
-
196
-
197
- m_Chipmunk = rb_define_module("CP");
198
- rb_define_module_function(m_Chipmunk, "bias_coef", rb_get_cp_bias_coef, 0);
199
- rb_define_module_function(m_Chipmunk, "bias_coef=", rb_set_cp_bias_coef, 1);
200
- rb_define_module_function(m_Chipmunk, "collision_slop", rb_get_cp_collision_slop, 0);
201
- rb_define_module_function(m_Chipmunk, "collision_slop=", rb_set_cp_collision_slop, 1);
184
+ Init_chipmunk(void) {
185
+ id_parent = rb_intern("parent");
186
+
187
+ cpInitChipmunk();
188
+
189
+
190
+
191
+ m_Chipmunk = rb_define_module("CP");
192
+ rb_define_module_function(m_Chipmunk, "bias_coef", rb_get_cp_bias_coef, 0);
193
+ rb_define_module_function(m_Chipmunk, "bias_coef=", rb_set_cp_bias_coef, 1);
194
+ rb_define_module_function(m_Chipmunk, "collision_slop", rb_get_cp_collision_slop, 0);
195
+ rb_define_module_function(m_Chipmunk, "collision_slop=", rb_set_cp_collision_slop, 1);
202
196
  rb_define_module_function(m_Chipmunk, "contact_persistence", rb_get_cp_contact_persistence, 0);
203
197
  rb_define_module_function(m_Chipmunk, "contact_persistence=", rb_set_cp_contact_persistence, 1);
204
-
205
-
206
-
198
+
199
+
200
+
207
201
  rb_define_module_function(m_Chipmunk, "clamp", rb_cpfclamp, 3);
208
202
  rb_define_module_function(m_Chipmunk, "flerp", rb_cpflerp, 3);
209
203
  rb_define_module_function(m_Chipmunk, "flerpconst", rb_cpflerpconst, 3);
210
-
211
- rb_define_module_function(m_Chipmunk, "moment_for_circle", rb_cpMomentForCircle, 4);
212
- rb_define_module_function(m_Chipmunk, "moment_for_poly", rb_cpMomentForPoly, 3);
204
+
205
+ rb_define_module_function(m_Chipmunk, "moment_for_circle", rb_cpMomentForCircle, 4);
206
+ rb_define_module_function(m_Chipmunk, "moment_for_poly", rb_cpMomentForPoly, 3);
213
207
  rb_define_module_function(m_Chipmunk, "moment_for_segment", rb_cpMomentForSegment, 3);
214
208
  rb_define_module_function(m_Chipmunk, "moment_for_box", rb_cpMomentForBox, 3);
215
-
209
+
216
210
  rb_define_module_function(m_Chipmunk, "circle_moment", rb_cpMomentForCircle, 4);
217
211
  rb_define_module_function(m_Chipmunk, "poly_moment", rb_cpMomentForPoly, 3);
218
212
  rb_define_module_function(m_Chipmunk, "segment_moment", rb_cpMomentForSegment, 3);
219
213
  rb_define_module_function(m_Chipmunk, "box_moment", rb_cpMomentForBox, 3);
220
-
221
-
214
+
215
+
222
216
  rb_define_module_function(m_Chipmunk, "area_for_circle", rb_cpAreaForCircle, 2);
223
217
  rb_define_module_function(m_Chipmunk, "area_for_poly", rb_cpAreaForPoly, 1);
224
218
  rb_define_module_function(m_Chipmunk, "centroid_for_poly",
225
- rb_cpCentroidForPoly, 1);
219
+ rb_cpCentroidForPoly, 1);
226
220
  rb_define_module_function(m_Chipmunk, "recenter_poly",
227
- rb_cpRecenterPoly, 1);
228
-
221
+ rb_cpRecenterPoly, 1);
222
+
229
223
  rb_define_module_function(m_Chipmunk, "area_for_segment", rb_cpAreaForSegment, 3);
230
224
  rb_define_module_function(m_Chipmunk, "area_for_box", rb_cpAreaForBox, 2);
231
-
225
+
232
226
  rb_define_module_function(m_Chipmunk, "circle_area", rb_cpAreaForCircle, 2);
233
227
  rb_define_module_function(m_Chipmunk, "poly_area", rb_cpAreaForPoly, 1);
234
228
  rb_define_module_function(m_Chipmunk, "segment_area", rb_cpAreaForSegment, 3);
235
229
  rb_define_module_function(m_Chipmunk, "box_area", rb_cpAreaForBox, 2);
236
-
230
+
237
231
  rb_define_const(m_Chipmunk, "ALL_LAYERS", UINT2NUM((unsigned int)CP_ALL_LAYERS));
238
- rb_define_const(m_Chipmunk, "NO_GROUP" , UINT2NUM(CP_NO_GROUP));
232
+ rb_define_const(m_Chipmunk, "NO_GROUP", UINT2NUM(CP_NO_GROUP));
239
233
 
240
234
  rb_eval_string("Float::INFINITY = 1.0/0.0 unless Float.const_defined? :INFINITY");
241
- rb_eval_string("CP::INFINITY = 1.0/0.0 unless CP.const_defined? :INFINITY");
242
-
243
- Init_cpVect();
244
- Init_cpBB();
245
- Init_cpBody();
246
- Init_cpShape();
247
- Init_cpConstraint();
248
- Init_cpSpace();
249
- Init_cpArbiter();
235
+ rb_eval_string("CP::INFINITY = 1.0/0.0 unless CP.const_defined? :INFINITY");
236
+
237
+ Init_cpVect();
238
+ Init_cpBB();
239
+ Init_cpBody();
240
+ Init_cpShape();
241
+ Init_cpConstraint();
242
+ Init_cpSpace();
243
+ Init_cpArbiter();
250
244
  }