| 1 | |||||||||||||||||||||||||||||
| 2 | # Thingy - a base class for virtual and physical 3D objects | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | package Games::3D::Thingy; | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | # (C) by Tels <http://bloodgate.com/> | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 6 | require Exporter; | |||||||||||||||||||||||||||
| 11 | 6 | ▶ | use vars qw/@ISA $VERSION $AUTOLOAD/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 6 | @ISA = qw/Exporter/; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 6 | ▶ | use Games::3D::Signal qw/ | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | STATE_OFF STATE_FLIP STATE_ON STATE_0 | ||||||||||||||||||||||||||||
| 16 | SIG_FLIP SIG_ACTIVATE SIG_DEACTIVATE | ||||||||||||||||||||||||||||
| 17 | SIG_DIE SIG_NOW_0 SIG_KILLED | ||||||||||||||||||||||||||||
| 18 | state_from_signal | ||||||||||||||||||||||||||||
| 19 | signal_from_state signal_name | ||||||||||||||||||||||||||||
| 20 | 6 | /; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | sub DEBUG () { 0; } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 6 | $VERSION = '0.04'; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | ############################################################################## | ||||||||||||||||||||||||||||
| 27 | # protected vars | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | # each Thingy will get a unique ID, however, upon adding it to the world/level | ||||||||||||||||||||||||||||
| 30 | # it will get a new ID, local and unique to that world. We could do away with | ||||||||||||||||||||||||||||
| 31 | # this function here... | ||||||||||||||||||||||||||||
| 32 | { | ||||||||||||||||||||||||||||
| 33 | 6 | my $id = 1; | |||||||||||||||||||||||||||
| 34 | 18 | ▶ | sub ID { return $id++;} | ||||||||||||||||||||||||||
|
Subroutine
ID: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | ############################################################################## | ||||||||||||||||||||||||||||
| 38 | # methods | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | sub new | ||||||||||||||||||||||||||||
| 41 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | # create a new instance of a thingy | ||||||||||||||||||||||||||||
| 43 | 18 | my $class = shift; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 18 | my $template; | |||||||||||||||||||||||||||
| 46 | 18 | ▶ | $template = shift if ref($_[0]) =~ /::Template/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 18 | my $self = { id => ID() }; | |||||||||||||||||||||||||||
| 49 | 18 | bless $self, $class; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 18 | $self->{active} = 1; | |||||||||||||||||||||||||||
| 52 | 18 | $self->{_world} = undef; # not contained in anything yet | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 18 | $self->{outputs} = {}; | |||||||||||||||||||||||||||
| 55 | 18 | $self->{inputs} = {}; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 18 | $self->{name} = $class; | |||||||||||||||||||||||||||
| 58 | 18 | $self->{name} =~ s/.*:://; | |||||||||||||||||||||||||||
| 59 | 18 | $self->{name} = ucfirst($self->{name}); | |||||||||||||||||||||||||||
| 60 | 18 | $self->{name} .= ' #' . $self->{id}; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 18 | $self->{state} = 0; # current state | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | # time when state change has to end. endtime is starttime + time_for_change, | ||||||||||||||||||||||||||||
| 65 | # as defined in field 0 of 'states' below: | ||||||||||||||||||||||||||||
| 66 | 18 | $self->{state_endtime} = 0; # disable change | |||||||||||||||||||||||||||
| 67 | 18 | $self->{state_target} = 0; # target state (from current) | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | # example: | ||||||||||||||||||||||||||||
| 70 | $self->{state_0} = [ | ||||||||||||||||||||||||||||
| 71 | 18 | 1, # ms to change to this state | |||||||||||||||||||||||||||
| 72 | # example: | ||||||||||||||||||||||||||||
| 73 | # 'light_r' => 0, # light off | ||||||||||||||||||||||||||||
| 74 | # 'light_g' => 0, # light off | ||||||||||||||||||||||||||||
| 75 | # 'light_b' => 0, # light off | ||||||||||||||||||||||||||||
| 76 | # 'light_a' => 0, # light off | ||||||||||||||||||||||||||||
| 77 | ]; | ||||||||||||||||||||||||||||
| 78 | $self->{state_1} = [ | ||||||||||||||||||||||||||||
| 79 | 18 | 1, | |||||||||||||||||||||||||||
| 80 | # example: | ||||||||||||||||||||||||||||
| 81 | # 'light_r' => 1.0, # light on | ||||||||||||||||||||||||||||
| 82 | # 'light_g' => 1.0, # light on | ||||||||||||||||||||||||||||
| 83 | # 'light_b' => 0, # light on | ||||||||||||||||||||||||||||
| 84 | # 'light_a' => 1.0, # light on | ||||||||||||||||||||||||||||
| 85 | ]; | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 18 | $self->{visible} = 0; # invisible | |||||||||||||||||||||||||||
| 88 | 18 | $self->{think_time} = 0; # never think | |||||||||||||||||||||||||||
| 89 | 18 | $self->{next_think} = 0; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 18 | ▶ | $template->init_thing($self) if $template; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 18 | $self->_init(@_); | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | sub kill | ||||||||||||||||||||||||||||
| 97 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
kill: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 98 | 1 | my ($self,$src) = @_; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 1 | $self->event($src,'kill'); | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | # send SIG_KILLED to all our links to announce our death | ||||||||||||||||||||||||||||
| 103 | 1 | $self->output($self, SIG_KILLED); | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | # remove all links from and to ourself | ||||||||||||||||||||||||||||
| 106 | 1 | $self->unlink(); | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | # remove ourself from parent if necc. | ||||||||||||||||||||||||||||
| 109 | 1 | ▶ | $self->{_world}->unregister($self) if $self->{_world}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 1 | undef; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | sub event | ||||||||||||||||||||||||||||
| 115 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
event: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||
| 116 | # when an event (frob, use, kill etc) occurs, this routine handles it | ||||||||||||||||||||||||||||
| 117 | 1 | my ($self,$src,$event) = @_; | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | &{$self->{"_event_$event"}}($self,$src) if $self->{"_event_$event"}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | sub AUTOLOAD | ||||||||||||||||||||||||||||
| 123 | 12 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 124 | # when you do $self->name(), the AUTOLOAD steps in, checks that the | ||||||||||||||||||||||||||||
| 125 | # attribute "name" exists, and constructs a little accessor method for it. | ||||||||||||||||||||||||||||
| 126 | # This is then put into place and the next time round it will be called | ||||||||||||||||||||||||||||
| 127 | # directly. | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 12 | my $func = $AUTOLOAD; | |||||||||||||||||||||||||||
| 130 | 12 | my $class = $func; | |||||||||||||||||||||||||||
| 131 | 12 | $func =~ s/.*:://; # remove package | |||||||||||||||||||||||||||
| 132 | 12 | $class =~ s/::[^:]+$//; # keep package | |||||||||||||||||||||||||||
| 133 | 12 | ▶ | return if $func eq 'DESTROY'; # we have DESTROY, so not necc. here | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | # print "autoload for $class $func\n"; | ||||||||||||||||||||||||||||
| 136 | 6 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 137 | # if (!$self->attr_exists($func)) | ||||||||||||||||||||||||||||
| 138 | # { | ||||||||||||||||||||||||||||
| 139 | # require Carp; Carp::croak ("Attribute '$func' does not exist in $class"); | ||||||||||||||||||||||||||||
| 140 | # } | ||||||||||||||||||||||||||||
| 141 | 3 | *{$class."::$func"} = | |||||||||||||||||||||||||||
| 142 | 2 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 143 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 144 | 2 | ▶ | if (@_ > 0) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | { | ||||||||||||||||||||||||||||
| 146 | # more than one argument, need to modify | ||||||||||||||||||||||||||||
| 147 | 1 | $self->{$func} = $_[0]; | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | 2 | $self->{$func}; | |||||||||||||||||||||||||||
| 150 | 3 | }; | |||||||||||||||||||||||||||
| 151 | 3 | &$func; # call constructed accessor method using @_ | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | sub id | ||||||||||||||||||||||||||||
| 155 | 5 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 156 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 5 | $self->{id}; | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | sub as_string | ||||||||||||||||||||||||||||
| 162 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=14 SCAR=29.0
Pod
documented
| |||||||||||||||||||||||||||||
| 163 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 1 | my $txt = ref($self) . " {\n"; | |||||||||||||||||||||||||||
| 166 | 1 | foreach my $k (sort keys %$self) | |||||||||||||||||||||||||||
| 167 | { | ||||||||||||||||||||||||||||
| 168 | 15 | ▶ | next if $k =~ /^_/; # skip internal keys | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | 14 | my $v = $self->{$k}; # get key | |||||||||||||||||||||||||||
| 170 | 14 | ▶ | next if !defined $v; # skip empty | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 13 | ▶ | if (ref($v) eq 'HASH') | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 172 | { | ||||||||||||||||||||||||||||
| 173 | 2 | ▶ | next if scalar keys %$v == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | 0 | $v = "{\n"; | |||||||||||||||||||||||||||
| 175 | 0 | foreach my $key (sort keys %{$self->{$k}}) | |||||||||||||||||||||||||||
| 176 | { | ||||||||||||||||||||||||||||
| 177 | 0 | my $vi = $self->{$k}->{$key}; | |||||||||||||||||||||||||||
| 178 | 0 | ▶ | $vi = $vi->as_string() if ref($v); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | 0 | $v .= " $key = $vi\n"; | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | 0 | $v .= " }"; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | elsif (ref($v) eq 'ARRAY') | ||||||||||||||||||||||||||||
| 184 | { | ||||||||||||||||||||||||||||
| 185 | 2 | ▶ | next if scalar @$v == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | 2 | $v = "[ "; | |||||||||||||||||||||||||||
| 187 | 2 | foreach my $vi (@{$self->{$k}}) | |||||||||||||||||||||||||||
| 188 | { | ||||||||||||||||||||||||||||
| 189 | 2 | ▶ | $vi = $vi->as_string() if ref($v); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | 2 | $v .= "$vi, "; | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | 2 | $v =~ /,\s$/; # remove last , | |||||||||||||||||||||||||||
| 193 | 2 | $v .= "]"; | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | else | ||||||||||||||||||||||||||||
| 196 | { | ||||||||||||||||||||||||||||
| 197 | 9 | ▶ | $v = '"'.$v.'"' if $v =~ /[^a-z0-9_\.,='"+-]/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | 9 | ▶ | next if $v eq ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | 11 | $txt .= " $k = $v\n"; | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | 1 | $txt .= "}\n"; | |||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | sub new_flag | ||||||||||||||||||||||||||||
| 206 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new_flag: not called CC=3 SCAR=21.9
Pod
documented
| |||||||||||||||||||||||||||||
| 207 | 0 | my ($self,$name,$value) = @_; | |||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 0 | $name =~ s/^-//; # -name => name | |||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | # set the initial value | ||||||||||||||||||||||||||||
| 212 | 0 | ▶ | $self->{$name} = $value ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 0 | my $class = ref($self); | |||||||||||||||||||||||||||
| 215 | 0 | ▶ | return if defined *{$class."::is_$name"}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | # create an accessor method | ||||||||||||||||||||||||||||
| 218 | 6 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 219 | 0 | *{$class."::is_$name"} = | |||||||||||||||||||||||||||
| 220 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 221 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 222 | 0 | ▶ | if (@_ > 0) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 223 | { | ||||||||||||||||||||||||||||
| 224 | # more than one argument, need to modify | ||||||||||||||||||||||||||||
| 225 | 0 | ▶ | $self->{$name} = $_[0] ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | 0 | $self->{$name}; | |||||||||||||||||||||||||||
| 228 | 0 | }; | |||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | 6 | ▶ | BEGIN { no warnings 'redefine'; } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | sub _init | ||||||||||||||||||||||||||||
| 234 | 15 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_init: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 235 | 15 | my $self = shift; | |||||||||||||||||||||||||||
| 236 | 15 | $self; | |||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | sub container | ||||||||||||||||||||||||||||
| 240 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
container: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 241 | # return the container this thing is inside or undef for none | ||||||||||||||||||||||||||||
| 242 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | 0 | $self->{parent}; | |||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | sub insert | ||||||||||||||||||||||||||||
| 248 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
insert: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 249 | # insert thingy into a container | ||||||||||||||||||||||||||||
| 250 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 251 | 0 | my $thingy = shift; | |||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 0 | $self->{contains}->{$thingy->{id}} = $thingy; | |||||||||||||||||||||||||||
| 254 | 0 | $self->_update_space(); | |||||||||||||||||||||||||||
| 255 | 0 | $self; | |||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | sub _update_space | ||||||||||||||||||||||||||||
| 259 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_update_space: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | sub remove | ||||||||||||||||||||||||||||
| 263 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
remove: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 264 | # remove thing from ourself | ||||||||||||||||||||||||||||
| 265 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 266 | 0 | my $thing = shift; | |||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 0 | ▶ | if (ref $thing) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | { | ||||||||||||||||||||||||||||
| 270 | 0 | my $c = $self->{contains}; | |||||||||||||||||||||||||||
| 271 | 0 | ▶ | if (exists $c->{$thing->{id}}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 272 | { | ||||||||||||||||||||||||||||
| 273 | 0 | delete $c->{$thing->{id}}; | |||||||||||||||||||||||||||
| 274 | 0 | $self->_update_space(); | |||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||
| 277 | else | ||||||||||||||||||||||||||||
| 278 | { | ||||||||||||||||||||||||||||
| 279 | # try to remove us from our container | ||||||||||||||||||||||||||||
| 280 | 0 | ▶ | $self->{parent}->remove($self) if (defined $self->{parent}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | sub name | ||||||||||||||||||||||||||||
| 285 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
name: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 286 | # (set and) return the name of this thingy | ||||||||||||||||||||||||||||
| 287 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 288 | 6 | ▶ | if (defined $_[0]) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 289 | { | ||||||||||||||||||||||||||||
| 290 | 0 | $self->{name} = shift; | |||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||
| 292 | 6 | $self->{name}; | |||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | sub activate | ||||||||||||||||||||||||||||
| 296 | 5 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
activate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 297 | 5 | my ($self) = shift; | |||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | 5 | $self->{active} = 1; | |||||||||||||||||||||||||||
| 300 | 5 | 1; | |||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | sub deactivate | ||||||||||||||||||||||||||||
| 304 | 5 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
deactivate: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 305 | 5 | my ($self) = shift; | |||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | 5 | $self->{active} = 0; | |||||||||||||||||||||||||||
| 308 | 5 | 0; | |||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | sub is_active | ||||||||||||||||||||||||||||
| 312 | 7 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
is_active: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 313 | 7 | my ($self) = shift; | |||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | 7 | $self->{active}; | |||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | sub state | ||||||||||||||||||||||||||||
| 319 | 34 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
state: called CC=8 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||
| 320 | 34 | my $self = shift; | |||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | # if given a state change and we are active | ||||||||||||||||||||||||||||
| 323 | 34 | ▶ | if (defined $_[0] && $self->{active} == 1) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $_[0] and $self->{"active"} == 1
MC/DC50%1/2
defined $_[0] and $self->{"active"} == 1
defined $_[0]
$self->{"active"} == 1
Truth table66%2/3
A and B
A= defined $_[0]B= $self->{"active"} == 1
| |||||||||||||||||||||||||||||
| 324 | { | ||||||||||||||||||||||||||||
| 325 | 15 | my $old_state = $self->{state}; | |||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | # initiate state change: | ||||||||||||||||||||||||||||
| 328 | 15 | my $newstate; | |||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | 15 | ▶ | if ($_[0] == STATE_FLIP) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 331 | { | ||||||||||||||||||||||||||||
| 332 | 2 | ▶ | if ($self->{state} <= STATE_ON) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 333 | { | ||||||||||||||||||||||||||||
| 334 | 2 | $newstate = STATE_ON - $self->{state}; | |||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||
| 336 | else | ||||||||||||||||||||||||||||
| 337 | { | ||||||||||||||||||||||||||||
| 338 | # XXX TODO: on thingy with more than 2 states, flip is undefined | ||||||||||||||||||||||||||||
| 339 | 0 | $newstate = STATE_0; | |||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||
| 342 | else | ||||||||||||||||||||||||||||
| 343 | { | ||||||||||||||||||||||||||||
| 344 | 13 | $newstate = $_[0]; | |||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | 15 | ▶ | if ($self->{state} != $newstate) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 348 | { | ||||||||||||||||||||||||||||
| 349 | 12 | print '# ', $self->name(), | |||||||||||||||||||||||||||
| 350 | " changes state from $self->{state} to $newstate\n" if DEBUG; | ||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | # set the endtime for when the state change should be complete | ||||||||||||||||||||||||||||
| 353 | 12 | my $now = 0; | |||||||||||||||||||||||||||
| 354 | 12 | ▶ | $now = $self->{_world}->time() if $self->{_world}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 355 | $self->{state_endtime} = $now + | ||||||||||||||||||||||||||||
| 356 | 12 | ▶ | ($self->{"state_$newstate"}->[0] || 1); # avoid state changes | ||||||||||||||||||||||||||
|
Condition100%2/2
$$self{"state_$newstate"}[0] || 1
MC/DC100%1/1
$$self{"state_$newstate"}[0] || 1
$$self{"state_$newstate"}[0]
Truth table100%2/2
A
A= $$self{"state_$newstate"}[0]
| |||||||||||||||||||||||||||||
| 357 | # that take no time | ||||||||||||||||||||||||||||
| 358 | 12 | $self->{state_target} = $newstate; | |||||||||||||||||||||||||||
| 359 | # notifing our listeners will be done when the state change is complete | ||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||
| 362 | 34 | $self->{state}; | |||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | sub signal | ||||||||||||||||||||||||||||
| 366 | 11 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
signal: called CC=6 SCAR=20.4
Pod
documented
| |||||||||||||||||||||||||||||
| 367 | # receive signal $sig from input $input, where $input is the sender's ID (not | ||||||||||||||||||||||||||||
| 368 | # the link(s) relaying the signal). We ignore here the input. Links relay | ||||||||||||||||||||||||||||
| 369 | # their input to their outputs (maybe, delayed , inverted etc), while other | ||||||||||||||||||||||||||||
| 370 | # objects receive input, change state (or not) and then maybe output | ||||||||||||||||||||||||||||
| 371 | # something. | ||||||||||||||||||||||||||||
| 372 | 11 | my ($self,$input,$sig) = @_; | |||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | 11 | ▶ | my $id = $input; $id = $input->{id} if ref($id); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 375 | 11 | print "# ",$self->name()," received signal ",signal_name($sig), | |||||||||||||||||||||||||||
| 376 | " from $id\n" if DEBUG; | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | # if asked to die, do so now | ||||||||||||||||||||||||||||
| 379 | 11 | ▶ | if ($sig == SIG_DIE) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 380 | { | ||||||||||||||||||||||||||||
| 381 | 0 | $self->kill(); | |||||||||||||||||||||||||||
| 382 | 0 | return; | |||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||
| 384 | # if asked to deactivate, do so now | ||||||||||||||||||||||||||||
| 385 | 11 | ▶ | if ($sig == SIG_ACTIVATE) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 386 | { | ||||||||||||||||||||||||||||
| 387 | 0 | $self->{active} = 1; | |||||||||||||||||||||||||||
| 388 | 0 | return; | |||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||
| 390 | 11 | ▶ | if ($sig == SIG_DEACTIVATE) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 391 | { | ||||||||||||||||||||||||||||
| 392 | 0 | $self->{active} = 0; | |||||||||||||||||||||||||||
| 393 | 0 | return; | |||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||
| 395 | # set ourself to the new state, unless SIG_NOW_x (these are ignored) | ||||||||||||||||||||||||||||
| 396 | 11 | ▶ | $self->state(state_from_signal($sig)) if $sig <= SIG_NOW_0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 397 | # relay incoming signals to outputs if neccessary | ||||||||||||||||||||||||||||
| 398 | 11 | $self->output($input,$sig); | |||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||
| 401 | sub inputs | ||||||||||||||||||||||||||||
| 402 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
inputs: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 403 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | 2 | keys %{$self->{inputs}}; | |||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | sub outputs | ||||||||||||||||||||||||||||
| 409 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
outputs: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 410 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | 0 | keys %{$self->{outputs}}; | |||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||
| 415 | sub add_input | ||||||||||||||||||||||||||||
| 416 | 7 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
add_input: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 417 | 7 | my ($self,$src) = @_; | |||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | 7 | $self->{inputs}->{$src->{id}} = $src; | |||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | sub add_output | ||||||||||||||||||||||||||||
| 423 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
add_output: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 424 | 6 | my ($self,$dst) = @_; | |||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | 6 | $self->{outputs}->{$dst->{id}} = $dst; | |||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | sub del_input | ||||||||||||||||||||||||||||
| 430 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
del_input: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 431 | 2 | my ($self,$src) = @_; | |||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||
| 433 | 2 | delete $self->{inputs}->{$src->{id}}; | |||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | sub del_output | ||||||||||||||||||||||||||||
| 437 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
del_output: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 438 | 1 | my ($self,$dst) = @_; | |||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||
| 440 | 1 | delete $self->{outputs}->{$dst->{id}}; | |||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | sub unlink | ||||||||||||||||||||||||||||
| 444 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
unlink: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||
| 445 | # unlink all inputs and outputs from ourself | ||||||||||||||||||||||||||||
| 446 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | 2 | foreach my $out (keys %{$self->{outputs}}) | |||||||||||||||||||||||||||
| 449 | { | ||||||||||||||||||||||||||||
| 450 | $self->{outputs}->{$out}->del_input($self) | ||||||||||||||||||||||||||||
| 451 | 2 | ▶ | if ref($self->{outputs}->{$out}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||
| 453 | 2 | foreach my $in (keys %{$self->{inputs}}) | |||||||||||||||||||||||||||
| 454 | { | ||||||||||||||||||||||||||||
| 455 | $self->{inputs}->{$in}->del_output($self) | ||||||||||||||||||||||||||||
| 456 | 1 | ▶ | if ref($self->{inputs}->{$in}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||
| 458 | 2 | $self->{inputs} = {}; | |||||||||||||||||||||||||||
| 459 | 2 | $self->{outputs} = {}; | |||||||||||||||||||||||||||
| 460 | 2 | $self; | |||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | sub output | ||||||||||||||||||||||||||||
| 464 | 32 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
output: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 465 | # send a signal to all the outputs | ||||||||||||||||||||||||||||
| 466 | 32 | my ($self,$source,$sig) = @_; | |||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||
| 468 | 32 | ▶ | $source = $source->{id} if ref($source); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 469 | 32 | my $out = $self->{outputs}; | |||||||||||||||||||||||||||
| 470 | 32 | foreach my $id (keys %{$self->{outputs}}) | |||||||||||||||||||||||||||
| 471 | { | ||||||||||||||||||||||||||||
| 472 | 16 | $out->{$id}->signal($source,$sig); # sender id, signal | |||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||
| 476 | sub link | ||||||||||||||||||||||||||||
| 477 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
link: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 478 | # link us to another one by creating intermidiate link object and return | ||||||||||||||||||||||||||||
| 479 | # link object | ||||||||||||||||||||||||||||
| 480 | 1 | my ($self,$dst,$link) = @_; | |||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||
| 482 | 1 | $self->{outputs}->{$link->{id}} = $link; | |||||||||||||||||||||||||||
| 483 | 1 | $link->add_output($dst); # from link to $dst | |||||||||||||||||||||||||||
| 484 | 1 | $dst->add_input($link); | |||||||||||||||||||||||||||
| 485 | 1 | $link->add_input($self); # from us to link | |||||||||||||||||||||||||||
| 486 | 1 | $link; | |||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||
| 489 | sub update | ||||||||||||||||||||||||||||
| 490 | 10 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
update: called CC=6 SCAR=21.9
Pod
documented
| |||||||||||||||||||||||||||||
| 491 | # if thing is going from state A to state B, interpolate values based upon | ||||||||||||||||||||||||||||
| 492 | # current time tick. If reached state B, disable interpolation, and send a | ||||||||||||||||||||||||||||
| 493 | # signal. Return 1 if while still in transit, 0 if target state reached | ||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||
| 495 | 10 | my ($self, $tick) = @_; | |||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||
| 497 | # if the thingy is in between two state changes, interpolate between them | ||||||||||||||||||||||||||||
| 498 | 10 | ▶ | return if $self->{state_endtime} == 0; # no change neccessary | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||
| 500 | # for all fields in the target state, interpolate them | ||||||||||||||||||||||||||||
| 501 | 10 | my $s = "state_$self->{state_target}"; | |||||||||||||||||||||||||||
| 502 | 10 | ▶ | if (!exists $self->{$s}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 503 | { | ||||||||||||||||||||||||||||
| 504 | 0 | $self->{$s} = [1]; | |||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||
| 506 | 10 | my @states = @{$self->{$s}}; | |||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||
| 508 | 10 | ▶ | if ($tick >= $self->{state_endtime}) # overdue | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 509 | { | ||||||||||||||||||||||||||||
| 510 | # simple set the fields, and disable the state change | ||||||||||||||||||||||||||||
| 511 | 10 | print "# update($tick) caused change ",$self->name(), | |||||||||||||||||||||||||||
| 512 | " $self->{state} => $self->{state_target}\n" if DEBUG; | ||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||
| 514 | 10 | $self->{state_endtime} = 0; # no further change | |||||||||||||||||||||||||||
| 515 | 10 | $self->{state} = $self->{state_target}; # reached target state | |||||||||||||||||||||||||||
| 516 | # send signal that state change is complete | ||||||||||||||||||||||||||||
| 517 | 10 | print "# Sending signal ", signal_name(signal_from_state($self->{state})), | |||||||||||||||||||||||||||
| 518 | "\n" if DEBUG; | ||||||||||||||||||||||||||||
| 519 | 10 | $self->output($self, signal_from_state($self->{state})); | |||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||
| 521 | 10 | ▶ | while (@states > 0) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 522 | { | ||||||||||||||||||||||||||||
| 523 | # set a => 1 (f.i.) | ||||||||||||||||||||||||||||
| 524 | 10 | $self->{$states[0]} = $states[1]; | |||||||||||||||||||||||||||
| 525 | 10 | splice @states,0,2; # throw away first two entries | |||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||
| 527 | 10 | return 0; # no more changes | |||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||
| 530 | 0 | my $time = shift @states; # field 0 is the time it takes | |||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||
| 532 | # get the values from the current state | ||||||||||||||||||||||||||||
| 533 | 0 | my @cur_states = @{$self->{"states_$self->{state}"}}; | |||||||||||||||||||||||||||
| 534 | 0 | shift @cur_states; # dont need field 0 | |||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||
| 536 | # factor: endtime - time = starttime # 200 - 100 = 100 | ||||||||||||||||||||||||||||
| 537 | # tick - starttime = elapsedtime # 180 - 100 = 80 | ||||||||||||||||||||||||||||
| 538 | # time / elapsedtime = factor # 100 / 80 = 0.8 (80%) | ||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||
| 540 | 0 | my $factor = $time / ($tick - ($self->{state_endtime} - $time)); | |||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||
| 542 | # interpolate linaer to the target values | ||||||||||||||||||||||||||||
| 543 | 0 | ▶ | while (@states > 0) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 544 | { | ||||||||||||||||||||||||||||
| 545 | # 20 .. 80 => 60 * 0.8 (factor, 80%) = 48 + 20 => 68 as current value | ||||||||||||||||||||||||||||
| 546 | 0 | $self->{$states[0]} = | |||||||||||||||||||||||||||
| 547 | ($states[1] - $cur_states[1]) * $factor + $cur_states[1]; | ||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||
| 549 | 0 | splice @states,0,2; # throw away first two entries | |||||||||||||||||||||||||||
| 550 | 0 | splice @cur_states,0,2; # throw away first two entries | |||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||
| 552 | 0 | 1; # more changes to do | |||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||
| 555 | ############################################################################## | ||||||||||||||||||||||||||||
| 556 | # field access | ||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||
| 558 | sub is | ||||||||||||||||||||||||||||
| 559 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
is: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 560 | 0 | my ($self,$flag) = @_; | |||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||
| 562 | 0 | ▶ | if (!exists $self->{$flag}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 563 | { | ||||||||||||||||||||||||||||
| 564 | 0 | require Carp; | |||||||||||||||||||||||||||
| 565 | 0 | Carp::croak ("Flag '$flag' does not exist at $self"); | |||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||
| 567 | 0 | $self->{$flag}; | |||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||
| 570 | sub make | ||||||||||||||||||||||||||||
| 571 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
make: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 572 | 0 | my ($self,$flag) = @_; | |||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||
| 574 | 0 | ▶ | if (!exists $self->{$flag}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 575 | { | ||||||||||||||||||||||||||||
| 576 | 0 | require Carp; | |||||||||||||||||||||||||||
| 577 | 0 | Carp::croak ("Flag '$flag' does not exist at $self"); | |||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||
| 579 | 0 | $self->{$flag} = 1; | |||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||
| 582 | sub get | ||||||||||||||||||||||||||||
| 583 | 7 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=2 SCAR=8.4
Pod
documented
| |||||||||||||||||||||||||||||
| 584 | 7 | my ($self,$field) = @_; | |||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||
| 586 | 7 | ▶ | if (!exists $self->{$field}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 587 | { | ||||||||||||||||||||||||||||
| 588 | 0 | require Carp; | |||||||||||||||||||||||||||
| 589 | 0 | Carp::croak ("Field '$field' does not exist at " . $self->name()); | |||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||
| 591 | 7 | $self->{$field}; | |||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||
| 594 | 6 | 1; | |||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||
| 596 | __END__ | ||||||||||||||||||||||||||||