line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SDLx::Widget::Controller::Timer; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Implementation of lesson 13 and 14 from http://lazyfoo.net/SDL_tutorials/index.php |
4
|
|
|
|
|
|
|
# |
5
|
1
|
|
|
1
|
|
8
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
6
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
7
|
1
|
|
|
1
|
|
6
|
use SDL; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
546
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
12
|
0
|
|
|
|
|
|
my $self = bless {@_}, $class; |
13
|
|
|
|
|
|
|
|
14
|
0
|
|
|
|
|
|
$self->{started_ticks} = 0; |
15
|
0
|
|
|
|
|
|
$self->{paused_ticks} = 0; |
16
|
0
|
|
|
|
|
|
$self->{started} = 0; |
17
|
0
|
|
|
|
|
|
$self->{paused} = 0; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
return $self; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub start |
26
|
|
|
|
|
|
|
{ |
27
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
28
|
0
|
|
|
|
|
|
$self->{started} = 1; |
29
|
0
|
|
|
|
|
|
$self->{started_ticks} = SDL::get_ticks(); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub stop |
33
|
|
|
|
|
|
|
{ |
34
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
$self->{started} = 0; |
37
|
0
|
|
|
|
|
|
$self->{paused} = 0; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub pause |
41
|
|
|
|
|
|
|
{ |
42
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
43
|
0
|
0
|
0
|
|
|
|
if ( $self->{started} && !$self->{paused} ) |
44
|
|
|
|
|
|
|
{ |
45
|
0
|
|
|
|
|
|
$self->{paused} = 1; |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
$self->{paused_ticks} = SDL::get_ticks() - $self->{started_ticks}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub unpause |
52
|
|
|
|
|
|
|
{ |
53
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
54
|
0
|
0
|
|
|
|
|
if ( $self->{paused} ) |
55
|
|
|
|
|
|
|
{ |
56
|
0
|
|
|
|
|
|
$self->{paused} = 0; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
$self->{started_ticks} = SDL::get_ticks() - $self->{started_ticks}; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
$self->{paused_ticks} = 0; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub get_ticks |
67
|
|
|
|
|
|
|
{ |
68
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
69
|
0
|
0
|
|
|
|
|
if ( $self->{started} ) |
70
|
|
|
|
|
|
|
{ |
71
|
0
|
0
|
|
|
|
|
if ( $self->{paused} ) |
72
|
|
|
|
|
|
|
{ |
73
|
0
|
|
|
|
|
|
return $self->{paused_ticks}; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
else |
76
|
|
|
|
|
|
|
{ |
77
|
0
|
|
|
|
|
|
my $update = SDL::get_ticks(); |
78
|
0
|
|
|
|
|
|
my $diff = $update - $self->{started_ticks}; |
79
|
0
|
|
|
|
|
|
$self->{started_ticks} = $update; |
80
|
0
|
|
|
|
|
|
return $diff; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
return 0; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub is_started |
89
|
|
|
|
|
|
|
{ |
90
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
91
|
0
|
|
|
|
|
|
return $self->{started} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub is_paused |
97
|
|
|
|
|
|
|
{ |
98
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
99
|
0
|
|
|
|
|
|
return $self->{paused} |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |