File Coverage

blib/lib/Game/Asset/GVG/OpenGL.pm
Criterion Covered Total %
statement 24 31 77.4
branch n/a
condition n/a
subroutine 8 9 88.8
pod n/a
total 32 40 80.0


line stmt bran cond sub pod time code
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     1   1071 use strict;
  1         3  
  1         37  
28 1     1   6 use warnings;
  1         1  
  1         36  
29 1     1   784 use Moose;
  1         293676  
  1         18  
30 1     1   4925 use namespace::autoclean;
  1         5471  
  1         2  
31 1     1   482 use Graphics::GVG;
  1         576916  
  1         39  
32 1     1   670 use Graphics::GVG::OpenGLRenderer;
  1         105506  
  1         39  
33              
34              
35 1     1   7 use constant type => 'opengl';
  1         1  
  1         139  
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 0     0     my ($self, $content) = @_;
48 0           my $gvg = Graphics::GVG->new; # TODO include paths
49 0           my $ast = $gvg->parse( $content );
50              
51 0           my $renderer = Graphics::GVG::OpenGLRenderer->new;
52 0           my $obj = $renderer->make_drawer_obj( $ast );
53 0           $self->_set_opengl( $obj );
54              
55 0           return;
56             }
57              
58              
59 1     1   4 no Moose;
  1         1  
  1         6  
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