Filename | /home/tmurray/proj/Game-Collisions/lib/Game/Collisions/AABB.pm |
Statements | Executed 2748344 statements in 2.37s |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
26436 | 3 | 1 | 566ms | 659ms | _calculate_bounding_box_for_nodes | Game::Collisions::AABB::
239960 | 1 | 1 | 354ms | 354ms | does_collide | Game::Collisions::AABB::
194280 | 1 | 1 | 105ms | 105ms | is_branch_node | Game::Collisions::AABB::
183200 | 1 | 1 | 59.4ms | 59.4ms | right_node | Game::Collisions::AABB::
184198 | 2 | 1 | 58.7ms | 58.7ms | left_node | Game::Collisions::AABB::
999 | 1 | 1 | 49.9ms | 315ms | resize_all_parents | Game::Collisions::AABB::
999 | 1 | 1 | 43.8ms | 469ms | find_best_sibling_node | Game::Collisions::AABB::
9478 | 1 | 1 | 27.1ms | 260ms | _resize_to_fit_children | Game::Collisions::AABB::
107742 | 3 | 2 | 26.6ms | 26.6ms | x | Game::Collisions::AABB::
107742 | 3 | 2 | 24.8ms | 24.8ms | y | Game::Collisions::AABB::
52872 | 1 | 1 | 12.1ms | 12.1ms | length | Game::Collisions::AABB::
52872 | 1 | 1 | 11.6ms | 11.6ms | height | Game::Collisions::AABB::
2996 | 2 | 1 | 9.76ms | 12.9ms | _set_node | Game::Collisions::AABB::
18956 | 2 | 2 | 5.35ms | 5.35ms | parent | Game::Collisions::AABB::
1541 | 2 | 1 | 3.76ms | 11.6ms | set_left_node | Game::Collisions::AABB::
1455 | 2 | 1 | 3.72ms | 8.76ms | set_right_node | Game::Collisions::AABB::
1999 | 2 | 1 | 3.32ms | 3.32ms | new | Game::Collisions::AABB::
2996 | 1 | 1 | 2.07ms | 2.07ms | set_parent | Game::Collisions::AABB::
1 | 1 | 1 | 1.57ms | 1.84ms | BEGIN@32 | Game::Collisions::AABB::
1 | 1 | 1 | 494µs | 533µs | BEGIN@30 | Game::Collisions::AABB::
1 | 1 | 1 | 250µs | 253µs | BEGIN@26 | Game::Collisions::AABB::
1 | 1 | 1 | 10µs | 10µs | BEGIN@27 | Game::Collisions::AABB::
1 | 1 | 1 | 8µs | 14µs | BEGIN@28 | Game::Collisions::AABB::
1 | 1 | 1 | 8µs | 35µs | BEGIN@33 | Game::Collisions::AABB::
1 | 1 | 1 | 5µs | 38µs | BEGIN@34 | Game::Collisions::AABB::
1 | 1 | 1 | 5µs | 27µs | BEGIN@35 | Game::Collisions::AABB::
1 | 1 | 1 | 5µs | 26µs | BEGIN@39 | Game::Collisions::AABB::
1 | 1 | 1 | 5µs | 28µs | BEGIN@36 | Game::Collisions::AABB::
1 | 1 | 1 | 5µs | 24µs | BEGIN@40 | Game::Collisions::AABB::
1 | 1 | 1 | 4µs | 25µs | BEGIN@38 | Game::Collisions::AABB::
1 | 1 | 1 | 4µs | 24µs | BEGIN@37 | Game::Collisions::AABB::
1 | 1 | 1 | 3µs | 3µs | BEGIN@29 | Game::Collisions::AABB::
0 | 0 | 0 | 0s | 0s | dump_tree | Game::Collisions::AABB::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # Copyright (c) 2018 Timm Murray | ||||
2 | # All rights reserved. | ||||
3 | # | ||||
4 | # Redistribution and use in source and binary forms, with or without | ||||
5 | # modification, are permitted provided that the following conditions are met: | ||||
6 | # | ||||
7 | # * Redistributions of source code must retain the above copyright notice, | ||||
8 | # this list of conditions and the following disclaimer. | ||||
9 | # * Redistributions in binary form must reproduce the above copyright | ||||
10 | # notice, this list of conditions and the following disclaimer in the | ||||
11 | # documentation and/or other materials provided with the distribution. | ||||
12 | # | ||||
13 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||||
14 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||||
15 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||||
16 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||||
17 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||||
18 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||||
19 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||||
20 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||||
21 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||||
22 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||||
23 | # POSSIBILITY OF SUCH DAMAGE. | ||||
24 | package Game::Collisions::AABB; | ||||
25 | |||||
26 | 2 | 253µs | 2 | 256µs | # spent 253µs (250+3) within Game::Collisions::AABB::BEGIN@26 which was called:
# once (250µs+3µs) by Game::Collisions::BEGIN@30 at line 26 # spent 253µs making 1 call to Game::Collisions::AABB::BEGIN@26
# spent 3µs making 1 call to utf8::import |
27 | 2 | 45µs | 1 | 10µs | # spent 10µs within Game::Collisions::AABB::BEGIN@27 which was called:
# once (10µs+0s) by Game::Collisions::BEGIN@30 at line 27 # spent 10µs making 1 call to Game::Collisions::AABB::BEGIN@27 |
28 | 2 | 23µs | 2 | 21µs | # spent 14µs (8+6) within Game::Collisions::AABB::BEGIN@28 which was called:
# once (8µs+6µs) by Game::Collisions::BEGIN@30 at line 28 # spent 14µs making 1 call to Game::Collisions::AABB::BEGIN@28
# spent 6µs making 1 call to warnings::import |
29 | 2 | 20µs | 1 | 3µs | # spent 3µs within Game::Collisions::AABB::BEGIN@29 which was called:
# once (3µs+0s) by Game::Collisions::BEGIN@30 at line 29 # spent 3µs making 1 call to Game::Collisions::AABB::BEGIN@29 |
30 | 2 | 122µs | 1 | 533µs | # spent 533µs (494+38) within Game::Collisions::AABB::BEGIN@30 which was called:
# once (494µs+38µs) by Game::Collisions::BEGIN@30 at line 30 # spent 533µs making 1 call to Game::Collisions::AABB::BEGIN@30 |
31 | |||||
32 | 2 | 129µs | 2 | 1.89ms | # spent 1.84ms (1.57+275µs) within Game::Collisions::AABB::BEGIN@32 which was called:
# once (1.57ms+275µs) by Game::Collisions::BEGIN@30 at line 32 # spent 1.84ms making 1 call to Game::Collisions::AABB::BEGIN@32
# spent 42µs making 1 call to constant::import |
33 | 2 | 26µs | 2 | 63µs | # spent 35µs (8+27) within Game::Collisions::AABB::BEGIN@33 which was called:
# once (8µs+27µs) by Game::Collisions::BEGIN@30 at line 33 # spent 35µs making 1 call to Game::Collisions::AABB::BEGIN@33
# spent 27µs making 1 call to constant::import |
34 | 2 | 25µs | 2 | 70µs | # spent 38µs (5+32) within Game::Collisions::AABB::BEGIN@34 which was called:
# once (5µs+32µs) by Game::Collisions::BEGIN@30 at line 34 # spent 38µs making 1 call to Game::Collisions::AABB::BEGIN@34
# spent 32µs making 1 call to constant::import |
35 | 2 | 21µs | 2 | 48µs | # spent 27µs (5+22) within Game::Collisions::AABB::BEGIN@35 which was called:
# once (5µs+22µs) by Game::Collisions::BEGIN@30 at line 35 # spent 27µs making 1 call to Game::Collisions::AABB::BEGIN@35
# spent 22µs making 1 call to constant::import |
36 | 2 | 21µs | 2 | 52µs | # spent 28µs (5+24) within Game::Collisions::AABB::BEGIN@36 which was called:
# once (5µs+24µs) by Game::Collisions::BEGIN@30 at line 36 # spent 28µs making 1 call to Game::Collisions::AABB::BEGIN@36
# spent 24µs making 1 call to constant::import |
37 | 2 | 20µs | 2 | 44µs | # spent 24µs (4+20) within Game::Collisions::AABB::BEGIN@37 which was called:
# once (4µs+20µs) by Game::Collisions::BEGIN@30 at line 37 # spent 24µs making 1 call to Game::Collisions::AABB::BEGIN@37
# spent 20µs making 1 call to constant::import |
38 | 2 | 21µs | 2 | 46µs | # spent 25µs (4+21) within Game::Collisions::AABB::BEGIN@38 which was called:
# once (4µs+21µs) by Game::Collisions::BEGIN@30 at line 38 # spent 25µs making 1 call to Game::Collisions::AABB::BEGIN@38
# spent 21µs making 1 call to constant::import |
39 | 2 | 22µs | 2 | 46µs | # spent 26µs (5+20) within Game::Collisions::AABB::BEGIN@39 which was called:
# once (5µs+20µs) by Game::Collisions::BEGIN@30 at line 39 # spent 26µs making 1 call to Game::Collisions::AABB::BEGIN@39
# spent 20µs making 1 call to constant::import |
40 | 2 | 902µs | 2 | 42µs | # spent 24µs (5+19) within Game::Collisions::AABB::BEGIN@40 which was called:
# once (5µs+19µs) by Game::Collisions::BEGIN@30 at line 40 # spent 24µs making 1 call to Game::Collisions::AABB::BEGIN@40
# spent 19µs making 1 call to constant::import |
41 | |||||
42 | |||||
43 | sub new | ||||
44 | # spent 3.32ms within Game::Collisions::AABB::new which was called 1999 times, avg 2µs/call:
# 1000 times (1.61ms+0s) by Game::Collisions::make_aabb at line 52 of /home/tmurray/proj/Game-Collisions/lib/Game/Collisions.pm, avg 2µs/call
# 999 times (1.71ms+0s) by Game::Collisions::_new_meta_aabb at line 147 of /home/tmurray/proj/Game-Collisions/lib/Game/Collisions.pm, avg 2µs/call | ||||
45 | 1999 | 376µs | my ($class, $args) = @_; | ||
46 | my $self = [ | ||||
47 | $args->{x}, | ||||
48 | $args->{y}, | ||||
49 | $args->{length}, | ||||
50 | $args->{height}, | ||||
51 | $args->{x} + $args->{length}, | ||||
52 | $args->{y} + $args->{height}, | ||||
53 | undef, # parent node | ||||
54 | undef, # left node | ||||
55 | undef, # right node | ||||
56 | 1999 | 1.94ms | ]; | ||
57 | |||||
58 | 1999 | 1.93ms | bless $self => $class; | ||
59 | } | ||||
60 | |||||
61 | |||||
62 | 107742 | 129ms | # spent 26.6ms within Game::Collisions::AABB::x which was called 107742 times, avg 247ns/call:
# 52872 times (13.9ms+0s) by Game::Collisions::AABB::_calculate_bounding_box_for_nodes at line 210, avg 263ns/call
# 52872 times (12.1ms+0s) by Game::Collisions::AABB::_calculate_bounding_box_for_nodes at line 212, avg 229ns/call
# 1998 times (561µs+0s) by Game::Collisions::_add_aabb at line 113 of /home/tmurray/proj/Game-Collisions/lib/Game/Collisions.pm, avg 281ns/call | ||
63 | 107742 | 136ms | # spent 24.8ms within Game::Collisions::AABB::y which was called 107742 times, avg 231ns/call:
# 52872 times (12.3ms+0s) by Game::Collisions::AABB::_calculate_bounding_box_for_nodes at line 211, avg 233ns/call
# 52872 times (12.0ms+0s) by Game::Collisions::AABB::_calculate_bounding_box_for_nodes at line 216, avg 228ns/call
# 1998 times (499µs+0s) by Game::Collisions::_add_aabb at line 114 of /home/tmurray/proj/Game-Collisions/lib/Game/Collisions.pm, avg 250ns/call | ||
64 | 52872 | 53.2ms | # spent 12.1ms within Game::Collisions::AABB::length which was called 52872 times, avg 229ns/call:
# 52872 times (12.1ms+0s) by Game::Collisions::AABB::_calculate_bounding_box_for_nodes at line 212, avg 229ns/call | ||
65 | 52872 | 60.5ms | # spent 11.6ms within Game::Collisions::AABB::height which was called 52872 times, avg 220ns/call:
# 52872 times (11.6ms+0s) by Game::Collisions::AABB::_calculate_bounding_box_for_nodes at line 216, avg 220ns/call | ||
66 | 184198 | 264ms | # spent 58.7ms within Game::Collisions::AABB::left_node which was called 184198 times, avg 319ns/call:
# 183200 times (58.4ms+0s) by Game::Collisions::get_collisions_for_aabb at line 81 of /home/tmurray/proj/Game-Collisions/lib/Game/Collisions.pm, avg 319ns/call
# 998 times (336µs+0s) by Game::Collisions::_add_aabb at line 133 of /home/tmurray/proj/Game-Collisions/lib/Game/Collisions.pm, avg 337ns/call | ||
67 | 183200 | 279ms | # spent 59.4ms within Game::Collisions::AABB::right_node which was called 183200 times, avg 324ns/call:
# 183200 times (59.4ms+0s) by Game::Collisions::get_collisions_for_aabb at line 82 of /home/tmurray/proj/Game-Collisions/lib/Game/Collisions.pm, avg 324ns/call | ||
68 | 18956 | 20.4ms | # spent 5.35ms within Game::Collisions::AABB::parent which was called 18956 times, avg 282ns/call:
# 17957 times (5.00ms+0s) by Game::Collisions::AABB::resize_all_parents at line 98, avg 278ns/call
# 999 times (351µs+0s) by Game::Collisions::_add_aabb at line 123 of /home/tmurray/proj/Game-Collisions/lib/Game/Collisions.pm, avg 352ns/call | ||
69 | |||||
70 | |||||
71 | sub set_left_node | ||||
72 | # spent 11.6ms (3.76+7.89) within Game::Collisions::AABB::set_left_node which was called 1541 times, avg 8µs/call:
# 999 times (3.13ms+5.60ms) by Game::Collisions::_add_aabb at line 124 of /home/tmurray/proj/Game-Collisions/lib/Game/Collisions.pm, avg 9µs/call
# 542 times (629µs+2.29ms) by Game::Collisions::_add_aabb at line 136 of /home/tmurray/proj/Game-Collisions/lib/Game/Collisions.pm, avg 5µs/call | ||||
73 | 1541 | 192µs | my ($self, $node) = @_; | ||
74 | 1541 | 3.53ms | 1541 | 7.89ms | return $self->_set_node( $node, _LEFT_NODE ); # spent 7.89ms making 1541 calls to Game::Collisions::AABB::_set_node, avg 5µs/call |
75 | } | ||||
76 | |||||
77 | sub set_right_node | ||||
78 | # spent 8.76ms (3.72+5.04) within Game::Collisions::AABB::set_right_node which was called 1455 times, avg 6µs/call:
# 999 times (3.19ms+3.17ms) by Game::Collisions::_add_aabb at line 125 of /home/tmurray/proj/Game-Collisions/lib/Game/Collisions.pm, avg 6µs/call
# 456 times (538µs+1.87ms) by Game::Collisions::_add_aabb at line 136 of /home/tmurray/proj/Game-Collisions/lib/Game/Collisions.pm, avg 5µs/call | ||||
79 | 1455 | 211µs | my ($self, $node) = @_; | ||
80 | 1455 | 1.47ms | 1455 | 5.04ms | return $self->_set_node( $node, _RIGHT_NODE ); # spent 5.04ms making 1455 calls to Game::Collisions::AABB::_set_node, avg 3µs/call |
81 | } | ||||
82 | |||||
83 | sub set_parent | ||||
84 | # spent 2.07ms within Game::Collisions::AABB::set_parent which was called 2996 times, avg 692ns/call:
# 2996 times (2.07ms+0s) by Game::Collisions::AABB::_set_node at line 185, avg 692ns/call | ||||
85 | 2996 | 382µs | my ($self, $parent) = @_; | ||
86 | 2996 | 425µs | my $current_parent = $self->[_PARENT_NODE]; | ||
87 | 2996 | 399µs | $self->[_PARENT_NODE] = $parent; | ||
88 | 2996 | 2.10ms | return $current_parent; | ||
89 | } | ||||
90 | |||||
91 | sub resize_all_parents | ||||
92 | # spent 315ms (49.9+265) within Game::Collisions::AABB::resize_all_parents which was called 999 times, avg 316µs/call:
# 999 times (49.9ms+265ms) by Game::Collisions::_add_aabb at line 139 of /home/tmurray/proj/Game-Collisions/lib/Game/Collisions.pm, avg 316µs/call | ||||
93 | 999 | 142µs | my ($self) = @_; | ||
94 | |||||
95 | 999 | 223µs | my @nodes_to_resize = ($self); | ||
96 | 999 | 227µs | while( @nodes_to_resize ) { | ||
97 | 9478 | 1.08ms | my $next_node = shift @nodes_to_resize; | ||
98 | 9478 | 9.98ms | 17957 | 5.00ms | push @nodes_to_resize, $next_node->parent # spent 5.00ms making 17957 calls to Game::Collisions::AABB::parent, avg 278ns/call |
99 | if defined $next_node->parent; | ||||
100 | 9478 | 5.64ms | 9478 | 260ms | $next_node->_resize_to_fit_children; # spent 260ms making 9478 calls to Game::Collisions::AABB::_resize_to_fit_children, avg 27µs/call |
101 | } | ||||
102 | |||||
103 | 999 | 726µs | return; | ||
104 | } | ||||
105 | |||||
106 | sub does_collide | ||||
107 | # spent 354ms within Game::Collisions::AABB::does_collide which was called 239960 times, avg 1µs/call:
# 239960 times (354ms+0s) by Game::Collisions::get_collisions_for_aabb at line 84 of /home/tmurray/proj/Game-Collisions/lib/Game/Collisions.pm, avg 1µs/call | ||||
108 | 239960 | 30.2ms | my ($self, $other_object) = @_; | ||
109 | 239960 | 46.1ms | return 0 if $self == $other_object; # Does not collide with itself | ||
110 | 239260 | 94.7ms | my ($minx1, $miny1, $length1, $height1, $maxx1, $maxy1) = @$self; | ||
111 | 239260 | 70.0ms | my ($minx2, $miny2, $length2, $height2, $maxx2, $maxy2) = @$other_object; | ||
112 | |||||
113 | 239260 | 403ms | return $maxx1 >= $minx2 | ||
114 | && $minx1 <= $maxx2 | ||||
115 | && $maxy1 >= $miny1 | ||||
116 | && $miny1 <= $maxy2; | ||||
117 | } | ||||
118 | |||||
119 | sub find_best_sibling_node | ||||
120 | # spent 469ms (43.8+425) within Game::Collisions::AABB::find_best_sibling_node which was called 999 times, avg 470µs/call:
# 999 times (43.8ms+425ms) by Game::Collisions::_add_aabb at line 111 of /home/tmurray/proj/Game-Collisions/lib/Game/Collisions.pm, avg 470µs/call | ||||
121 | 999 | 151µs | my ($self, $new_node) = @_; | ||
122 | |||||
123 | 999 | 267µs | my @nodes_to_check = ($self); | ||
124 | 999 | 157µs | while( @nodes_to_check ) { | ||
125 | 9478 | 1.12ms | my $check_node = shift @nodes_to_check; | ||
126 | 9478 | 1.45ms | my $left_node = $check_node->[_LEFT_NODE]; | ||
127 | 9478 | 1.24ms | my $right_node = $check_node->[_RIGHT_NODE]; | ||
128 | 9478 | 2.08ms | return $check_node | ||
129 | if (! defined $left_node) || (! defined $right_node); | ||||
130 | |||||
131 | 8479 | 4.95ms | 8479 | 207ms | my (undef, undef, $left_length, $left_height) # spent 207ms making 8479 calls to Game::Collisions::AABB::_calculate_bounding_box_for_nodes, avg 24µs/call |
132 | = $self->_calculate_bounding_box_for_nodes( $left_node, $new_node ); | ||||
133 | 8479 | 4.65ms | 8479 | 218ms | my (undef, undef, $right_length, $right_height) # spent 218ms making 8479 calls to Game::Collisions::AABB::_calculate_bounding_box_for_nodes, avg 26µs/call |
134 | = $self->_calculate_bounding_box_for_nodes( $right_node, $new_node); | ||||
135 | |||||
136 | 8479 | 980µs | my $left_surface = $left_length * $left_height; | ||
137 | 8479 | 750µs | my $right_surface = $right_length * $right_height; | ||
138 | 8479 | 4.14ms | push @nodes_to_check, | ||
139 | ($left_surface > $right_surface) ? $right_node : $left_node; | ||||
140 | } | ||||
141 | |||||
142 | # How did we get here? It should have descended the tree until it | ||||
143 | # came to the leaf and returned that. Just in case, return ourselves. | ||||
144 | return $self; | ||||
145 | } | ||||
146 | |||||
147 | sub is_branch_node | ||||
148 | # spent 105ms within Game::Collisions::AABB::is_branch_node which was called 194280 times, avg 539ns/call:
# 194280 times (105ms+0s) by Game::Collisions::get_collisions_for_aabb at line 80 of /home/tmurray/proj/Game-Collisions/lib/Game/Collisions.pm, avg 539ns/call | ||||
149 | 194280 | 21.3ms | my ($self) = @_; | ||
150 | 194280 | 337ms | return (defined $self->[_LEFT_NODE]) || (defined $self->[_RIGHT_NODE]); | ||
151 | } | ||||
152 | |||||
153 | sub dump_tree | ||||
154 | { | ||||
155 | my ($self, $spacing) = @_; | ||||
156 | $spacing //= ''; | ||||
157 | |||||
158 | my $draw_chars = $self->is_branch_node | ||||
159 | ? '├┐' | ||||
160 | : '│├'; | ||||
161 | my $str = "$spacing├┤ " . join( ', ', | ||||
162 | "$self", | ||||
163 | $self->x, | ||||
164 | $self->y, | ||||
165 | $self->length, | ||||
166 | $self->height, | ||||
167 | ); | ||||
168 | $str .= "\n"; | ||||
169 | $str .= $self->left_node->dump_tree( $spacing . '┼' ) | ||||
170 | if defined $self->left_node; | ||||
171 | $str .= $self->right_node->dump_tree( $spacing . '┼' ) | ||||
172 | if defined $self->right_node; | ||||
173 | |||||
174 | return $str; | ||||
175 | } | ||||
176 | |||||
177 | |||||
178 | sub _set_node | ||||
179 | # spent 12.9ms (9.76+3.17) within Game::Collisions::AABB::_set_node which was called 2996 times, avg 4µs/call:
# 1541 times (6.14ms+1.74ms) by Game::Collisions::AABB::set_left_node at line 74, avg 5µs/call
# 1455 times (3.62ms+1.42ms) by Game::Collisions::AABB::set_right_node at line 80, avg 3µs/call | ||||
180 | 2996 | 445µs | my ($self, $node, $index) = @_; | ||
181 | 2996 | 1.45ms | 998 | 246µs | Scalar::Util::unweaken( $self->[$index] ) # spent 246µs making 998 calls to Scalar::Util::unweaken, avg 246ns/call |
182 | if defined $self->[$index]; | ||||
183 | 2996 | 380µs | $self->[$index] = $node; | ||
184 | 2996 | 4.91ms | 2996 | 847µs | Scalar::Util::weaken( $self->[$index] ); # spent 847µs making 2996 calls to Scalar::Util::weaken, avg 283ns/call |
185 | 2996 | 1.35ms | 2996 | 2.07ms | my $former_parent = $node->set_parent( $self ); # spent 2.07ms making 2996 calls to Game::Collisions::AABB::set_parent, avg 692ns/call |
186 | 2996 | 6.10ms | return $former_parent; | ||
187 | } | ||||
188 | |||||
189 | sub _resize_to_fit_children | ||||
190 | # spent 260ms (27.1+233) within Game::Collisions::AABB::_resize_to_fit_children which was called 9478 times, avg 27µs/call:
# 9478 times (27.1ms+233ms) by Game::Collisions::AABB::resize_all_parents at line 100, avg 27µs/call | ||||
191 | 9478 | 1.09ms | my ($self) = @_; | ||
192 | 9478 | 5.96ms | 9478 | 233ms | my ($x, $y, $length, $height) = $self->_calculate_bounding_box_for_nodes( # spent 233ms making 9478 calls to Game::Collisions::AABB::_calculate_bounding_box_for_nodes, avg 25µs/call |
193 | $self->[_LEFT_NODE], | ||||
194 | $self->[_RIGHT_NODE], | ||||
195 | ); | ||||
196 | |||||
197 | 9478 | 1.17ms | $self->[_X] = $x; | ||
198 | 9478 | 971µs | $self->[_Y] = $y; | ||
199 | 9478 | 933µs | $self->[_LENGTH] = $length; | ||
200 | 9478 | 883µs | $self->[_HEIGHT] = $height; | ||
201 | 9478 | 1.16ms | $self->[_MAX_X] = $x + $length; | ||
202 | 9478 | 946µs | $self->[_MAX_Y] = $y + $height; | ||
203 | |||||
204 | 9478 | 20.1ms | return; | ||
205 | } | ||||
206 | |||||
207 | sub _calculate_bounding_box_for_nodes | ||||
208 | # spent 659ms (566+92.1) within Game::Collisions::AABB::_calculate_bounding_box_for_nodes which was called 26436 times, avg 25µs/call:
# 9478 times (201ms+32.6ms) by Game::Collisions::AABB::_resize_to_fit_children at line 192, avg 25µs/call
# 8479 times (188ms+29.4ms) by Game::Collisions::AABB::find_best_sibling_node at line 133, avg 26µs/call
# 8479 times (177ms+30.1ms) by Game::Collisions::AABB::find_best_sibling_node at line 131, avg 24µs/call | ||||
209 | 26436 | 3.28ms | my ($self, $node1, $node2) = @_; | ||
210 | 26436 | 61.6ms | 79308 | 18.1ms | my $min_x = List::Util::min( $node1->x, $node2->x ); # spent 13.9ms making 52872 calls to Game::Collisions::AABB::x, avg 263ns/call
# spent 4.21ms making 26436 calls to List::Util::min, avg 159ns/call |
211 | 26436 | 58.2ms | 79308 | 15.2ms | my $min_y = List::Util::min( $node1->y, $node2->y ); # spent 12.3ms making 52872 calls to Game::Collisions::AABB::y, avg 233ns/call
# spent 2.94ms making 26436 calls to List::Util::min, avg 111ns/call |
212 | 26436 | 72.9ms | 132180 | 29.7ms | my $max_x = List::Util::max( # spent 12.1ms making 52872 calls to Game::Collisions::AABB::x, avg 229ns/call
# spent 12.1ms making 52872 calls to Game::Collisions::AABB::length, avg 229ns/call
# spent 5.48ms making 26436 calls to List::Util::max, avg 207ns/call |
213 | $node1->length + $node1->x, | ||||
214 | $node2->length + $node2->x, | ||||
215 | ); | ||||
216 | 26436 | 66.0ms | 132180 | 29.0ms | my $max_y = List::Util::max( # spent 12.0ms making 52872 calls to Game::Collisions::AABB::y, avg 228ns/call
# spent 11.6ms making 52872 calls to Game::Collisions::AABB::height, avg 220ns/call
# spent 5.38ms making 26436 calls to List::Util::max, avg 203ns/call |
217 | $node1->height + $node1->y, | ||||
218 | $node2->height + $node2->y, | ||||
219 | ); | ||||
220 | |||||
221 | 26436 | 2.66ms | my $length = $max_x - $min_x; | ||
222 | 26436 | 2.35ms | my $height = $max_y - $min_y; | ||
223 | 26436 | 51.5ms | return ($min_x, $min_y, $length, $height); | ||
224 | } | ||||
225 | |||||
226 | |||||
227 | 1 | 3µs | 1; | ||
228 | __END__ |