~ubuntu-branches/ubuntu/trusty/plee-the-bear/trusty-proposed

« back to all changes in this revision

Viewing changes to bear-engine/lib/src/generic_items/code/path_trace.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Julien Jorge, Julien Jorge
  • Date: 2010-11-17 20:13:34 UTC
  • mfrom: (6.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20101117201334-o4dp7uq437to7oxb
Tags: 0.5.1-1
[ Julien Jorge ]
* New upstream release (Closes: #565062, #546514).
* Add armhf architecture (Closes: #604689).
* Remove patches integrated upstream: rpath-editors.diff, rpath-game.diff,
  editors-menu-section.diff.
* Bump the Standard-Version, no changes.
* Update my email address.
* Set build dependency of libclaw to 1.6.0.
* Add the missing ${misc:Depends} in debian/control.
* List gettext translations in bear-factory.install and plee-the-bear.install.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Bear Engine
 
3
 
 
4
  Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
 
5
 
 
6
  This program is free software; you can redistribute it and/or modify it
 
7
  under the terms of the GNU General Public License as published by the
 
8
  Free Software Foundation; either version 2 of the License, or (at your
 
9
  option) any later version.
 
10
 
 
11
  This program is distributed in the hope that it will be useful, but WITHOUT
 
12
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
13
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 
14
  more details.
 
15
 
 
16
  You should have received a copy of the GNU General Public License along
 
17
  with this program; if not, write to the Free Software Foundation, Inc.,
 
18
  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 
 
20
  contact: plee-the-bear@gamned.org
 
21
 
 
22
  Please add the tag [Bear] in the subject of your mails.
 
23
*/
 
24
/**
 
25
 * \file code/path_trace.cpp
 
26
 * \brief Implementation of the bear::path_trace class.
 
27
 * \author Julien Jorge
 
28
 */
 
29
#include "generic_items/path_trace.hpp"
 
30
 
 
31
#include "visual/scene_polygon.hpp"
 
32
 
 
33
BASE_ITEM_EXPORT(path_trace, bear)
 
34
 
 
35
/*----------------------------------------------------------------------------*/
 
36
/**
 
37
 * \brief Constructor.
 
38
 */
 
39
bear::path_trace::path_trace()
 
40
  : m_progress(&path_trace::progress_void),
 
41
    m_fill_color(claw::graphic::black_pixel), m_opacity(1), m_fade_out_speed(1)
 
42
{
 
43
  set_artificial(true);
 
44
  set_phantom(true);
 
45
  set_can_move_items(false);
 
46
} // path_trace::path_trace()
 
47
 
 
48
/*----------------------------------------------------------------------------*/
 
49
/**
 
50
 * \brief Constructor.
 
51
 * \param ref The item to trace.
 
52
 */
 
53
bear::path_trace::path_trace( const base_item& ref )
 
54
  : m_progress(&path_trace::progress_alive), m_item(ref),
 
55
    m_fill_color(claw::graphic::black_pixel), m_opacity(1), m_fade_out_speed(1)
 
56
{
 
57
  set_artificial(true);
 
58
  set_phantom(true);
 
59
  set_can_move_items(false);
 
60
 
 
61
  set_z_position(ref.get_z_position() - 1);
 
62
  set_bounding_box( ref.get_bounding_box() );
 
63
} // path_trace::path_trace()
 
64
 
 
65
/*----------------------------------------------------------------------------*/
 
66
/**
 
67
 * \brief Set the color of the trace.
 
68
 * \param c The new color.
 
69
 */
 
70
void bear::path_trace::set_fill_color( const visual::color_type& c )
 
71
{
 
72
  m_fill_color = c;
 
73
} // path_trace::set_fill_color()
 
74
 
 
75
/*----------------------------------------------------------------------------*/
 
76
/**
 
77
 * \brief Set the item to trace.
 
78
 * \param ref The item to trace.
 
79
 */
 
80
void bear::path_trace::set_item( const base_item& ref )
 
81
{
 
82
  set_z_position(ref.get_z_position() - 1);
 
83
  set_bounding_box( ref.get_bounding_box() );
 
84
 
 
85
  m_previous_top.clear();
 
86
  m_previous_bottom.clear();
 
87
  m_item=ref;
 
88
  m_progress = &path_trace::progress_alive;
 
89
 
 
90
  m_previous_top.push_back( ref.get_top_middle() );
 
91
  m_previous_bottom.push_back( ref.get_bottom_middle() );
 
92
} // path_trace::set_item()
 
93
 
 
94
/*----------------------------------------------------------------------------*/
 
95
/**
 
96
 * \brief Set the speed of the fade out of the trace when the traced item is
 
97
 *        dead.
 
98
 * \param s Units of opacity lost per second.
 
99
 */
 
100
void bear::path_trace::set_fade_out_speed( double s )
 
101
{
 
102
  m_fade_out_speed = (s > 0) ? s : 0;
 
103
} // path_trace::set_fade_out_speed()
 
104
 
 
105
/*----------------------------------------------------------------------------*/
 
106
/**
 
107
 * \brief Do one step in the progression of the item.
 
108
 * \param elapsed_time Elapsed time since the last call.
 
109
 */
 
110
void bear::path_trace::progress( universe::time_type elapsed_time )
 
111
{
 
112
  super::progress(elapsed_time);
 
113
 
 
114
  (this->*m_progress)( elapsed_time );
 
115
} // path_trace::progress()
 
116
 
 
117
/*----------------------------------------------------------------------------*/
 
118
/**
 
119
 * \brief Get the visuals of this item.
 
120
 * \param visuals (out) The visuals.
 
121
 */
 
122
void
 
123
bear::path_trace::get_visual( std::list<engine::scene_visual>& visuals ) const
 
124
{
 
125
  CLAW_PRECOND( m_previous_bottom.size() == m_previous_top.size() );
 
126
 
 
127
  if ( m_previous_top.empty() )
 
128
    return;
 
129
 
 
130
  std::vector<visual::position_type> p(4);
 
131
 
 
132
  position_list::const_iterator bottom_it = m_previous_bottom.begin();
 
133
  position_list::const_iterator top_it = m_previous_top.begin();
 
134
 
 
135
  position_list::const_iterator next_top(top_it);
 
136
  ++next_top;
 
137
 
 
138
  while ( next_top != m_previous_top.end() )
 
139
    {
 
140
      p[0] = *bottom_it;
 
141
      ++bottom_it;
 
142
      p[1] = *bottom_it;
 
143
 
 
144
      p[3] = *top_it;
 
145
      ++top_it;
 
146
      p[2] = *top_it;
 
147
 
 
148
      next_top = top_it;
 
149
      ++next_top;
 
150
 
 
151
      if ( !p.empty() )
 
152
        {
 
153
          visual::scene_polygon e(0, 0, m_fill_color, p);
 
154
          e.get_rendering_attributes().set_opacity(m_opacity);
 
155
          visuals.push_back( engine::scene_visual(e) );
 
156
        }
 
157
    }
 
158
} // path_trace::get_visual()
 
159
 
 
160
/*----------------------------------------------------------------------------*/
 
161
/**
 
162
 * \brief Do one step in the progression of this item, when there is no traced
 
163
 *        item.
 
164
 * \param elapsed_time Elapsed time since the last call.
 
165
 */
 
166
void bear::path_trace::progress_void( universe::time_type elapsed_time )
 
167
{
 
168
  // nothing to do
 
169
} // path_trace::progress_void()
 
170
 
 
171
/*----------------------------------------------------------------------------*/
 
172
/**
 
173
 * \brief Do one step in the progression of this item, while the traced item is
 
174
 *        alive.
 
175
 * \param elapsed_time Elapsed time since the last call.
 
176
 */
 
177
void bear::path_trace::progress_alive( universe::time_type elapsed_time )
 
178
{
 
179
  if ( m_item == NULL )
 
180
    {
 
181
      m_progress = &path_trace::progress_dead;
 
182
      return;
 
183
    }
 
184
 
 
185
  m_previous_top.push_back( m_item->get_top_middle() );
 
186
  m_previous_bottom.push_back( m_item->get_bottom_middle() );
 
187
 
 
188
  set_bounding_box( get_bounding_box().join(m_item->get_bounding_box()) );
 
189
} // path_trace::progress_alive()
 
190
 
 
191
/*----------------------------------------------------------------------------*/
 
192
/**
 
193
 * \brief Do one step in the progression of this item, once the traced item is
 
194
 *        dead.
 
195
 * \param elapsed_time Elapsed time since the last call.
 
196
 */
 
197
void bear::path_trace::progress_dead( universe::time_type elapsed_time )
 
198
{
 
199
  m_opacity -= m_fade_out_speed * elapsed_time;
 
200
 
 
201
  if (m_opacity < 0)
 
202
    kill();
 
203
} // path_trace::progress_dead()