@@ -91,7 +91,7 @@ public void Test_B2BoardPhases_b2UnBufferMove()
9191 {
9292 B2BroadPhase bp = null ;
9393 b2CreateBroadPhase ( ref bp ) ;
94-
94+
9595 int proxyKeyA = 42 ;
9696 int proxyKeyB = 99 ;
9797 int proxyKeyC = 88 ;
@@ -135,7 +135,84 @@ public void Test_B2BoardPhases_b2UnBufferMove()
135135 Assert . That ( b2ContainsKey ( ref bp . moveSet , ( ulong ) proxyKeyA + 1 ) , Is . False ) ;
136136 Assert . That ( b2ContainsKey ( ref bp . moveSet , ( ulong ) proxyKeyB + 1 ) , Is . False ) ;
137137 Assert . That ( b2ContainsKey ( ref bp . moveSet , ( ulong ) proxyKeyC + 1 ) , Is . False ) ;
138-
138+
139139 Assert . That ( bp . moveArray . count , Is . EqualTo ( 0 ) ) ;
140140 }
141+
142+ [ Test ]
143+ public void Test_B2BoardPhases_b2BroadPhase_CreateProxy ( )
144+ {
145+ B2BroadPhase bp = null ;
146+ b2CreateBroadPhase ( ref bp ) ;
147+
148+ var aabb = new B2AABB
149+ {
150+ lowerBound = new B2Vec2 ( 0 , 0 ) ,
151+ upperBound = new B2Vec2 ( 1 , 1 )
152+ } ;
153+ ulong categoryBits = 0x0001 ;
154+ int shapeIndex = 123 ;
155+
156+ // case 1: static body, forcePairCreation = false
157+ int proxyKeyA = b2BroadPhase_CreateProxy ( bp , B2BodyType . b2_staticBody , aabb , categoryBits , shapeIndex , false ) ;
158+
159+ Assert . That ( bp . moveSet . count , Is . EqualTo ( 0 ) , "Should not add to moveSet if static body and forcePairCreation == false" ) ;
160+ Assert . That ( bp . moveArray . count , Is . EqualTo ( 0 ) , "Should not add to moveArray if static body and forcePairCreation == false" ) ;
161+
162+ // case 2: static body, forcePairCreation = true
163+ int proxyKeyB = b2BroadPhase_CreateProxy ( bp , B2BodyType . b2_staticBody , aabb , categoryBits , shapeIndex + 1 , true ) ;
164+
165+ Assert . That ( bp . moveSet . count , Is . EqualTo ( 1 ) , "Should add to moveSet if static body but forcePairCreation == true" ) ;
166+ Assert . That ( bp . moveArray . count , Is . EqualTo ( 1 ) , "Should add to moveArray if static body but forcePairCreation == true" ) ;
167+ Assert . That ( bp . moveArray . data , Does . Contain ( proxyKeyB ) , "moveArray should contain proxyKeyB" ) ;
168+
169+ // case 3: dynamic body, forcePairCreation irrelevant
170+ int proxyKeyC = b2BroadPhase_CreateProxy ( bp , B2BodyType . b2_dynamicBody , aabb , categoryBits , shapeIndex + 2 , false ) ;
171+
172+ Assert . That ( bp . moveSet . count , Is . EqualTo ( 2 ) , "Should add to moveSet if body is dynamic" ) ;
173+ Assert . That ( bp . moveArray . count , Is . EqualTo ( 2 ) , "Should add to moveArray if body is dynamic" ) ;
174+ Assert . That ( bp . moveArray . data , Does . Contain ( proxyKeyC ) , "moveArray should contain proxyKeyC" ) ;
175+ }
176+
177+ [ Test ]
178+ public void Test_B2BoardPhases_b2BroadPhase_DestroyProxy ( )
179+ {
180+ B2BroadPhase bp = null ;
181+ b2CreateBroadPhase ( ref bp ) ;
182+
183+ var aabb = new B2AABB
184+ {
185+ lowerBound = new B2Vec2 ( 0 , 0 ) ,
186+ upperBound = new B2Vec2 ( 1 , 1 )
187+ } ;
188+ ulong categoryBits = 0x0001 ;
189+ int shapeIndex = 123 ;
190+
191+ // Create and buffer proxies
192+ int proxyKeyA = b2BroadPhase_CreateProxy ( bp , B2BodyType . b2_dynamicBody , aabb , categoryBits , shapeIndex , false ) ;
193+ int proxyKeyB = b2BroadPhase_CreateProxy ( bp , B2BodyType . b2_dynamicBody , aabb , categoryBits , shapeIndex + 1 , false ) ;
194+
195+ Assert . That ( bp . moveSet . count , Is . EqualTo ( 2 ) , "moveSet should have 2 items before destroying proxies" ) ;
196+ Assert . That ( bp . moveArray . count , Is . EqualTo ( 2 ) , "moveArray should have 2 items before destroying proxies" ) ;
197+ Assert . That ( bp . proxyCount , Is . EqualTo ( 0 ) ) ;
198+
199+ // Destroy proxy A
200+ b2BroadPhase_DestroyProxy ( bp , proxyKeyA ) ;
201+
202+ Assert . That ( bp . moveSet . count , Is . EqualTo ( 1 ) , "moveSet should have 1 item after destroying proxy A" ) ;
203+ Assert . That ( bp . moveArray . count , Is . EqualTo ( 1 ) , "moveArray should have 1 item after destroying proxy A" ) ;
204+ Assert . That ( bp . proxyCount , Is . EqualTo ( - 1 ) , "proxyCount should decrease after destroying a proxy" ) ;
205+
206+ // Destroy proxy B
207+ b2BroadPhase_DestroyProxy ( bp , proxyKeyB ) ;
208+
209+ Assert . That ( bp . moveSet . count , Is . EqualTo ( 0 ) , "moveSet should have 0 items after destroying proxy B" ) ;
210+ Assert . That ( bp . moveArray . count , Is . EqualTo ( 0 ) , "moveArray should have 0 items after destroying proxy B" ) ;
211+ Assert . That ( bp . proxyCount , Is . EqualTo ( - 2 ) , "proxyCount should decrease to 0 after destroying all proxies" ) ;
212+
213+ #if DEBUG
214+ // Case 3: Destroy a non-existent proxy
215+ Assert . Throws < InvalidOperationException > ( ( ) => b2BroadPhase_DestroyProxy ( bp , proxyKeyB ) , "Destroying a non-existent proxy should throw an exception" ) ;
216+ #endif
217+ }
141218}
0 commit comments