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
|
|
5329
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
35
|
|
7
|
1
|
|
|
1
|
|
8
|
use SDL; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
509
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = 2.548; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
13
|
0
|
|
|
|
|
|
my $self = bless {@_}, $class; |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
|
$self->{started_ticks} = 0; |
16
|
0
|
|
|
|
|
|
$self->{paused_ticks} = 0; |
17
|
0
|
|
|
|
|
|
$self->{started} = 0; |
18
|
0
|
|
|
|
|
|
$self->{paused} = 0; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
return $self; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub start { |
24
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
25
|
0
|
|
|
|
|
|
$self->{started} = 1; |
26
|
0
|
|
|
|
|
|
$self->{started_ticks} = SDL::get_ticks(); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub stop { |
30
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
$self->{started} = 0; |
33
|
0
|
|
|
|
|
|
$self->{paused} = 0; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub pause { |
37
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
38
|
0
|
0
|
0
|
|
|
|
if ( $self->{started} && !$self->{paused} ) { |
39
|
0
|
|
|
|
|
|
$self->{paused} = 1; |
40
|
0
|
|
|
|
|
|
$self->{paused_ticks} = SDL::get_ticks() - $self->{started_ticks}; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub unpause { |
45
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
46
|
0
|
0
|
|
|
|
|
if ( $self->{paused} ) { |
47
|
0
|
|
|
|
|
|
$self->{paused} = 0; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
$self->{started_ticks} = SDL::get_ticks() - $self->{started_ticks}; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
$self->{paused_ticks} = 0; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub get_ticks { |
56
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
57
|
0
|
0
|
|
|
|
|
if ( $self->{started} ) { |
58
|
0
|
0
|
|
|
|
|
if ( $self->{paused} ) { |
59
|
0
|
|
|
|
|
|
return $self->{paused_ticks}; |
60
|
|
|
|
|
|
|
} else { |
61
|
0
|
|
|
|
|
|
my $update = SDL::get_ticks(); |
62
|
0
|
|
|
|
|
|
my $diff = $update - $self->{started_ticks}; |
63
|
0
|
|
|
|
|
|
return $diff; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
0
|
|
|
|
|
|
return 0; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub is_started { |
70
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
71
|
0
|
|
|
|
|
|
return $self->{started}; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub is_paused { |
75
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
76
|
0
|
|
|
|
|
|
return $self->{paused}; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |