blib/lib/Game/Asset/GVG/OpenGL.pm

filter: Statementstmt 86.6% 13 / 15 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 90.0% 18 / 20 CC 1 SCAR 0.6
CC
1
Cov
87%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1 # Copyright (c) 2016 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::Asset::GVG::OpenGL;
25 $Game::Asset::GVG::OpenGL::VERSION = '0.1';
26 # ABSTRACT: Load GVG files from a Game::Asset archive and convert to OpenGL
27 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 ▶use Graphics::GVG;
Subroutine BEGIN: called CC=1 SCAR=2.6
32 use Graphics::GVG::OpenGLRenderer;
33  
34  
35 use constant type => 'opengl';
36  
37 with 'Game::Asset::Type';
38  
39  
40 has 'opengl' => (
41 is => 'ro',
42 writer => '_set_opengl',
43 );
44  
45 sub _process_content
46 {
47 my ($self, $content) = @_;
48 my $gvg = Graphics::GVG->new; # TODO include paths
49 my $ast = $gvg->parse( $content );
50  
51 my $renderer = Graphics::GVG::OpenGLRenderer->new;
52 my $obj = $renderer->make_drawer_obj( $ast );
53 $self->_set_opengl( $obj );
54  
55 return;
56 }
57  
58  
59 no Moose;
60 __PACKAGE__->meta->make_immutable;
61 1;
62 __END__
63  
64  
65 =head1 NAME
66  
67 Game::Asset::GVG::OpenGL - Load GVG files from a Game::Asset archive and convert to OpenGL
68  
69 =head1 SYNOPSIS
70  
71 my $asset = Game::Asset->new({
72 file => 't_data/test.zip',
73 });
74 my $opengl = $asset->get_by_name( 'test' );
75
76 my $opengl_obj = $opengl->opengl;
77 # Setup an OpenGL context, then do:
78 $opengl_obj->draw;
79  
80  
81 # In your index.yml for the Game::Asset archive, add:
82 gvg: Game::Asset::GVG::OpenGL
83  
84 =head1 DESCRIPTION
85  
86 L<Game::Asset> loads files and gives them to you as Perl objects.
87 L<Graphics::GVG::OpenGLRenderer> takes GVG files and turns them into a Perl
88 class that can be used to render the vectors in OpenGL. This module glues the
89 two together.
90  
91 =head1 ATTRIBUTES
92  
93 =head2 opengl
94  
95 Returns the object which can be used to draw the data in the GVG file using
96 OpenGL. Once an OpenGL context is set, you can call C<draw()> on this
97 object to draw the GVG.
98  
99 =head1 LICENSE
100  
101 Copyright (c) 2016 Timm Murray
102 All rights reserved.
103  
104 Redistribution and use in source and binary forms, with or without
105 modification, are permitted provided that the following conditions are met:
106  
107 * Redistributions of source code must retain the above copyright notice,
108 this list of conditions and the following disclaimer.
109 * Redistributions in binary form must reproduce the above copyright
110 notice, this list of conditions and the following disclaimer in the
111 documentation and/or other materials provided with the distribution.
112  
113 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
114 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
115 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
116 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
117 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
118 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
119 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
120 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
121 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
122 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
123 POSSIBILITY OF SUCH DAMAGE.
124  
125 =cut
↑ Summary