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