Mercurial > projects > chipmunkd
annotate trunk/chipmunkd/constraints/cpConstraint.d @ 28:4541ca17975b
use __gshared as chipmunk heavily relies on globals and D would otherwise make them TLS
author | Extrawurst |
---|---|
date | Mon, 13 Dec 2010 21:40:56 +0100 |
parents | df4ebc8add66 |
children |
rev | line source |
---|---|
4 | 1 |
2 // written in the D programming language | |
3 | |
4 module chipmunkd.constraints.cpConstraint; | |
5 | |
6 import chipmunkd.chipmunk; | |
7 | |
8 alias void function(cpConstraint *constraint, cpFloat dt, cpFloat dt_inv) cpConstraintPreStepFunction; | |
9 alias void function(cpConstraint *constraint) cpConstraintApplyImpulseFunction; | |
10 alias cpFloat function(cpConstraint *constraint) cpConstraintGetImpulseFunction; | |
11 | |
12 struct cpConstraintClass { | |
13 cpConstraintPreStepFunction preStep; | |
14 cpConstraintApplyImpulseFunction applyImpulse; | |
15 cpConstraintGetImpulseFunction getImpulse; | |
16 } | |
17 | |
18 | |
19 | |
20 struct cpConstraint { | |
21 cpConstraintClass *klass; | |
22 | |
23 cpBody *a; | |
24 cpBody *b; | |
25 cpFloat maxForce; | |
26 cpFloat biasCoef; | |
27 cpFloat maxBias; | |
28 | |
29 cpDataPointer data; | |
30 } | |
31 | |
32 //#ifdef CP_USE_DEPRECATED_API_4 | |
33 //typedef cpConstraint cpJoint; | |
34 //#endif | |
35 | |
36 //void cpConstraintDestroy(cpConstraint *constraint); | |
37 //void cpConstraintFree(cpConstraint *constraint); | |
38 | |
39 static void | |
40 cpConstraintActivateBodies(cpConstraint *constraint) | |
41 { | |
42 cpBody *a = constraint.a; if(a) cpBodyActivate(a); | |
43 cpBody *b = constraint.b; if(b) cpBodyActivate(b); | |
44 } | |
45 | |
46 static cpFloat | |
47 cpConstraintGetImpulse(cpConstraint *constraint) | |
48 { | |
49 return constraint.klass.getImpulse(constraint); | |
50 } | |
51 | |
52 template cpConstraintCheckCast(string constraint, string _struct) | |
53 { | |
54 enum cpConstraintCheckCast = | |
55 "assert("~constraint~".klass == "~_struct~"GetClass(), \"Constraint is not a "~_struct~"\");"; | |
56 } | |
57 | |
58 template CP_DefineConstraintGetter(string _struct,string type,string member,string name) | |
59 { | |
60 enum CP_DefineConstraintGetter = | |
61 "static "~type~" "~_struct~"Get"~name~"(cpConstraint *constraint){"~ | |
62 cpConstraintCheckCast!("constraint",_struct)~ | |
63 "cpConstraintActivateBodies(constraint);"~ | |
64 "return (cast("~_struct~"*)constraint)."~member~";"~ | |
65 "}"; | |
66 } | |
67 | |
68 template CP_DefineConstraintSetter(string _struct,string type,string member,string name) | |
69 { | |
70 enum CP_DefineConstraintSetter = | |
71 "static void "~_struct~"Set"~name~"(cpConstraint *constraint,"~type~" value){"~ | |
72 cpConstraintCheckCast!("constraint",_struct)~ | |
73 "cpConstraintActivateBodies(constraint);"~ | |
74 "(cast("~_struct~"*)constraint)."~member~" = value;"~ | |
75 "}"; | |
76 } | |
77 | |
78 template CP_DefineConstraintProperty(string _struct,string type,string member,string name) | |
79 { | |
80 enum CP_DefineConstraintProperty = | |
81 CP_DefineConstraintGetter!(_struct,type,member,name)~CP_DefineConstraintSetter!(_struct,type,member,name); | |
82 | |
83 } | |
84 | |
85 //// Built in Joint types | |
86 public import chipmunkd.constraints.cpPinJoint; | |
6 | 87 public import chipmunkd.constraints.cpSlideJoint; |
4 | 88 public import chipmunkd.constraints.cpPivotJoint; |
6 | 89 public import chipmunkd.constraints.cpGrooveJoint; |
4 | 90 public import chipmunkd.constraints.cpDampedSpring; |
6 | 91 public import chipmunkd.constraints.cpDampedRotarySpring; |
92 public import chipmunkd.constraints.cpRotaryLimitJoint; | |
93 public import chipmunkd.constraints.cpRatchetJoint; | |
94 public import chipmunkd.constraints.cpGearJoint; | |
95 public import chipmunkd.constraints.cpSimpleMotor; | |
4 | 96 |
97 | |
28
4541ca17975b
use __gshared as chipmunk heavily relies on globals and D would otherwise make them TLS
Extrawurst
parents:
15
diff
changeset
|
98 __gshared cpFloat cp_constraint_bias_coef = 0.1f; |
4 | 99 |
100 void cpConstraintDestroy(cpConstraint *constraint){} | |
101 | |
102 void | |
103 cpConstraintFree(cpConstraint *constraint) | |
104 { | |
105 if(constraint){ | |
106 cpConstraintDestroy(constraint); | |
107 cpfree(constraint); | |
108 } | |
109 } | |
110 | |
111 void | |
112 cpConstraintInit(cpConstraint *constraint, /+const+/ cpConstraintClass *klass, cpBody *a, cpBody *b) | |
113 { | |
114 constraint.klass = klass; | |
115 constraint.a = a; | |
116 constraint.b = b; | |
117 | |
118 constraint.maxForce = cast(cpFloat)INFINITY; | |
119 constraint.biasCoef = cp_constraint_bias_coef; | |
120 constraint.maxBias = cast(cpFloat)INFINITY; | |
121 } |