Permalink
Browse files

Adds the flag allowing to reset a mark animation with the action.

The engine reads the flag from the model file but the model files are not
produced with this flag yet.
  • Loading branch information...
Julien Jorge
Julien Jorge committed Sep 28, 2013
1 parent 9fdc37b commit c3999dbaae2c8a6c26359cf34da00a09d1f15c28
@@ -34,24 +34,25 @@
*/
bear::engine::model_loader::model_loader
( std::istream& f, level_globals& glob )
: m_file(f, true), m_level_globals(glob)
: m_file(f, true), m_level_globals(glob),
m_major_version(0),
m_minor_version(0),
m_release_version(0)
{
} // model_loader::model_loader()
/*----------------------------------------------------------------------------*/
/**
* \brief Build the model
* \brief Builds the model
*/
bear::engine::model_actor* bear::engine::model_loader::run()
{
unsigned int maj(0), min(0), rel(0);
m_file >> maj >> min >> rel;
m_file >> m_major_version >> m_minor_version >> m_release_version;
if ( !m_file )
throw claw::exception("Can't read the version of the model file.");
else if ( (maj != 0) || (min < 6) )
else if ( !model_version_greater_or_equal( 0, 6, 0 ) )
throw claw::exception("This version of the model file is not supported.");
else
{
@@ -64,6 +65,30 @@ bear::engine::model_actor* bear::engine::model_loader::run()
}
} // model_loader::run()
/*----------------------------------------------------------------------------*/
/**
* \brief Tells if the version of the model in process is greater or equal to
* a given version.
* \param major The major version number to compare to.
* \param minor The minor version number to compare to.
* \param release The realese version number to compare to.
* \return true if the version of the model is lexicographically greater or
* equal to the provided version.
*/
bool bear::engine::model_loader::model_version_greater_or_equal
( unsigned int major, unsigned int minor, unsigned int release ) const
{
if ( major == m_major_version )
{
if ( minor == m_minor_version )
return release <= m_release_version;
else
return minor <= m_minor_version;
}
else
return major <= m_major_version;
} // model_loader::model_version_greater_or_equal()
/*----------------------------------------------------------------------------*/
/**
* \brief Load all the actions of a model.
@@ -161,12 +186,19 @@ void bear::engine::model_loader::load_marks
if ( m_file >> label >> apply_angle >> pause_hidden >> anim_index )
{
bool reset_with_action( true );
if ( model_version_greater_or_equal( 0, 10, 0 ) )
m_file >> reset_with_action;
model_animation anim;
if ( anim_index < anim_map.size() )
anim = anim_map[anim_index];
a.get_mark(i) = model_mark( label, anim, apply_angle, pause_hidden );
a.get_mark(i) =
model_mark
( label, anim, apply_angle, pause_hidden, reset_with_action );
}
else
claw::logger << claw::log_error << "The mark is incomplete."
@@ -22,6 +22,7 @@
*/
bear::engine::model_mark::model_mark()
: m_apply_angle_to_animation(false), m_pause_when_hidden(false),
m_reset_animation_with_action(true),
m_box_item( new model_mark_item ), m_item_in_layer(false)
{
@@ -32,14 +33,19 @@ bear::engine::model_mark::model_mark()
* \brief Constructor.
* \param label The label of the mark.
* \param anim The animation displayed on the mark.
* \param apply_angle Tell if the angle of the mark is applied to the animation.
* \param pause_hidden Tell if the animation must be paused when hidden.
* \param apply_angle Tells if the angle of the mark is applied to the
* animation.
* \param pause_hidden Tells if the animation must be paused when hidden.
* \param reset_animation_with_action Tells if the animation must be reset when
* the action begins.
*/
bear::engine::model_mark::model_mark
( const std::string& label, const model_animation& anim, bool apply_angle,
bool pause_hidden )
bool pause_hidden, bool reset_animation_with_action )
: m_label(label), m_animation(anim), m_apply_angle_to_animation(apply_angle),
m_pause_when_hidden(pause_hidden), m_box_item( new model_mark_item ),
m_pause_when_hidden(pause_hidden),
m_reset_animation_with_action(reset_animation_with_action),
m_box_item( new model_mark_item ),
m_item_in_layer(false)
{
@@ -220,7 +226,8 @@ void bear::engine::model_mark::remove_substitute()
*/
bool bear::engine::model_mark::reset_animation_with_action() const
{
return has_animation()
return m_reset_animation_with_action
&& has_animation()
&& ( get_animation()->is_finite()
|| (get_animation()->get_first_index() != 0) );
} // model_mark::reset_animation_with_action()
@@ -35,7 +35,7 @@ namespace bear
model_mark();
model_mark
( const std::string& label, const model_animation& anim,
bool apply_angle, bool pause_hidden );
bool apply_angle, bool pause_hidden, bool reset_animation_with_action );
model_mark( const model_mark& that );
~model_mark();
@@ -80,6 +80,9 @@ namespace bear
/** \brief Tell if the animation must be paused when hidden. */
bool m_pause_when_hidden;
/** \brief Tells if the animation must be reset when an action begins. */
bool m_reset_animation_with_action;
/** \brief The item centered on this mark. */
model_mark_item* m_box_item;
@@ -45,6 +45,9 @@ namespace bear
model_actor* run();
private:
bool model_version_greater_or_equal
( unsigned int major, unsigned int minor, unsigned int release ) const;
void load_actions( model_actor& m, const anim_map_type& anim_map );
void load_action( model_actor& m, const anim_map_type& anim_map );
void load_sound( std::vector<std::string>& sound_name, bool& glob );
@@ -63,6 +66,15 @@ namespace bear
/** \brief The level_globals in which we load the resources. */
level_globals& m_level_globals;
/** \brief The major version number in the model file. */
unsigned int m_major_version;
/** \brief The minor version number in the model file. */
unsigned int m_minor_version;
/** \brief The release version number in the model file. */
unsigned int m_release_version;
}; // class model_loader
} // namespace engine
} // namespace bear

0 comments on commit c3999db

Please sign in to comment.