Skip to content

Commit

Permalink
Added animation template classes and made particle system use them.
Browse files Browse the repository at this point in the history
  • Loading branch information
loonycyborg committed Sep 24, 2008
1 parent cd64ea0 commit 7c45499
Show file tree
Hide file tree
Showing 12 changed files with 196 additions and 63 deletions.
2 changes: 2 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ opts.AddOptions(
)

env = Environment(tools = ["zip", "config_checks"], toolpath = ["scons"], options = opts)
env.Decider("MD5-timestamp")
SetOption('implicit_cache', 1)
env["Build"] = env["Build"].lower()
if env["PLATFORM"] == "win32":
env.Tool("mingw")
Expand Down
22 changes: 10 additions & 12 deletions aclocal.m4
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,14 @@ fi])
# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES])
# ---------------------------------------------
m4_define([_PKG_CONFIG],
[if test -n "$PKG_CONFIG"; then
if test -n "$$1"; then
pkg_cv_[]$1="$$1"
else
PKG_CHECK_EXISTS([$3],
[pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`],
[pkg_failed=yes])
fi
else
pkg_failed=untried
[if test -n "$$1"; then
pkg_cv_[]$1="$$1"
elif test -n "$PKG_CONFIG"; then
PKG_CHECK_EXISTS([$3],
[pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`],
[pkg_failed=yes])
else
pkg_failed=untried
fi[]dnl
])# _PKG_CONFIG

Expand Down Expand Up @@ -137,9 +135,9 @@ See the pkg-config man page for more details.])
if test $pkg_failed = yes; then
_PKG_SHORT_ERRORS_SUPPORTED
if test $_pkg_short_errors_supported = yes; then
$1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "$2"`
$1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "$2" 2>&1`
else
$1[]_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "$2"`
$1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors "$2" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
Expand Down
32 changes: 14 additions & 18 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -7811,11 +7811,10 @@ pkg_failed=no
{ echo "$as_me:$LINENO: checking for PANGO" >&5
echo $ECHO_N "checking for PANGO... $ECHO_C" >&6; }
if test -n "$PKG_CONFIG"; then
if test -n "$PANGO_CFLAGS"; then
pkg_cv_PANGO_CFLAGS="$PANGO_CFLAGS"
else
if test -n "$PKG_CONFIG" && \
if test -n "$PANGO_CFLAGS"; then
pkg_cv_PANGO_CFLAGS="$PANGO_CFLAGS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
{ (echo "$as_me:$LINENO: \$PKG_CONFIG --exists --print-errors \"pangoft2\"") >&5
($PKG_CONFIG --exists --print-errors "pangoft2") 2>&5
ac_status=$?
Expand All @@ -7825,15 +7824,13 @@ if test -n "$PKG_CONFIG"; then
else
pkg_failed=yes
fi
fi
else
pkg_failed=untried
else
pkg_failed=untried
fi
if test -n "$PKG_CONFIG"; then
if test -n "$PANGO_LIBS"; then
pkg_cv_PANGO_LIBS="$PANGO_LIBS"
else
if test -n "$PKG_CONFIG" && \
if test -n "$PANGO_LIBS"; then
pkg_cv_PANGO_LIBS="$PANGO_LIBS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
{ (echo "$as_me:$LINENO: \$PKG_CONFIG --exists --print-errors \"pangoft2\"") >&5
($PKG_CONFIG --exists --print-errors "pangoft2") 2>&5
ac_status=$?
Expand All @@ -7843,9 +7840,8 @@ if test -n "$PKG_CONFIG"; then
else
pkg_failed=yes
fi
fi
else
pkg_failed=untried
else
pkg_failed=untried
fi
Expand All @@ -7858,9 +7854,9 @@ else
_pkg_short_errors_supported=no
fi
if test $_pkg_short_errors_supported = yes; then
PANGO_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "pangoft2"`
PANGO_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "pangoft2" 2>&1`
else
PANGO_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "pangoft2"`
PANGO_PKG_ERRORS=`$PKG_CONFIG --print-errors "pangoft2" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
echo "$PANGO_PKG_ERRORS" >&5
Expand Down
2 changes: 1 addition & 1 deletion data/test.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ sun_light="color_transition(hour*60+minute,0,rgb(0,0,0),
equipment="short_sword,shield_slot,armor_slot"
improvement_points="40"
level="1"
model="chr-heroine2.3d"
model="chr-heroine.3d"
portrait="portraits/callieh.png"
[attributes]
agility="8"
Expand Down
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ endif
SUBDIRS=. editor

libsilvertree_a_SOURCES=\
animation.hpp \
base_terrain_fwd.hpp \
base_terrain.hpp \
battle_character_fwd.hpp \
Expand Down Expand Up @@ -154,6 +155,7 @@ world.hpp \
tinyxml/tinyxml.h \
zoom_map_generator.hpp \
\
animation.cpp \
base_terrain.cpp \
battle_character.cpp \
battle_character_npc.cpp \
Expand Down
17 changes: 9 additions & 8 deletions src/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ AR = ar
ARFLAGS = cru
libsilvertree_a_AR = $(AR) $(ARFLAGS)
libsilvertree_a_LIBADD =
am__libsilvertree_a_SOURCES_DIST = base_terrain_fwd.hpp \
am__libsilvertree_a_SOURCES_DIST = animation.hpp base_terrain_fwd.hpp \
base_terrain.hpp battle_character_fwd.hpp battle_character.hpp \
battle_character_npc.hpp battle_character_pc.hpp battle.hpp \
battle_map_generator.hpp battle_menu_fwd.hpp battle_menu.hpp \
Expand Down Expand Up @@ -104,8 +104,8 @@ am__libsilvertree_a_SOURCES_DIST = base_terrain_fwd.hpp \
util.hpp variant.hpp widget.hpp wml_command_fwd.hpp \
wml_command.hpp wml_node_fwd.hpp wml_node.hpp wml_parser.hpp \
wml_utils.hpp wml_writer.hpp world_fwd.hpp world.hpp \
tinyxml/tinyxml.h zoom_map_generator.hpp base_terrain.cpp \
battle_character.cpp battle_character_npc.cpp \
tinyxml/tinyxml.h zoom_map_generator.hpp animation.cpp \
base_terrain.cpp battle_character.cpp battle_character_npc.cpp \
battle_character_pc.cpp battle.cpp battle_map_generator.cpp \
battle_menu.cpp battle_missile.cpp battle_modification.cpp \
battle_move.cpp button.cpp camera_controller.cpp camera.cpp \
Expand Down Expand Up @@ -136,7 +136,7 @@ am__libsilvertree_a_SOURCES_DIST = base_terrain_fwd.hpp \
tinyxml/tinyxmlerror.cpp tinyxml/tinyxmlparser.cpp \
zoom_map_generator.cpp pango_text.hpp pango_text.cpp
@HAVE_PANGO_TRUE@am__objects_1 = pango_text.$(OBJEXT)
am_libsilvertree_a_OBJECTS = titlescreen.$(OBJEXT) \
am_libsilvertree_a_OBJECTS = titlescreen.$(OBJEXT) animation.$(OBJEXT) \
base_terrain.$(OBJEXT) battle_character.$(OBJEXT) \
battle_character_npc.$(OBJEXT) battle_character_pc.$(OBJEXT) \
battle.$(OBJEXT) battle_map_generator.$(OBJEXT) \
Expand Down Expand Up @@ -355,8 +355,8 @@ silvertreerpg_LDADD = libsilvertree.a
AM_CPPFLAGS = -DDATADIR=\"$(pkgdatadir)\"
AM_CXXFLAGS = -Wall -Werror -Wno-sign-compare -Wno-switch -Wno-switch-enum
SUBDIRS = . editor
libsilvertree_a_SOURCES = base_terrain_fwd.hpp base_terrain.hpp \
battle_character_fwd.hpp battle_character.hpp \
libsilvertree_a_SOURCES = animation.hpp base_terrain_fwd.hpp \
base_terrain.hpp battle_character_fwd.hpp battle_character.hpp \
battle_character_npc.hpp battle_character_pc.hpp battle.hpp \
battle_map_generator.hpp battle_menu_fwd.hpp battle_menu.hpp \
battle_missile.hpp battle_modification.hpp battle_move_fwd.hpp \
Expand Down Expand Up @@ -394,8 +394,8 @@ libsilvertree_a_SOURCES = base_terrain_fwd.hpp base_terrain.hpp \
util.hpp variant.hpp widget.hpp wml_command_fwd.hpp \
wml_command.hpp wml_node_fwd.hpp wml_node.hpp wml_parser.hpp \
wml_utils.hpp wml_writer.hpp world_fwd.hpp world.hpp \
tinyxml/tinyxml.h zoom_map_generator.hpp base_terrain.cpp \
battle_character.cpp battle_character_npc.cpp \
tinyxml/tinyxml.h zoom_map_generator.hpp animation.cpp \
base_terrain.cpp battle_character.cpp battle_character_npc.cpp \
battle_character_pc.cpp battle.cpp battle_map_generator.cpp \
battle_menu.cpp battle_missile.cpp battle_modification.cpp \
battle_move.cpp button.cpp camera_controller.cpp camera.cpp \
Expand Down Expand Up @@ -498,6 +498,7 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c

@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/animation.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/audio.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/base_terrain.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/battle.Po@am__quote@
Expand Down
24 changes: 24 additions & 0 deletions src/animation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/***************************************************************************
* Copyright (C) 2008 by Sergey Popov <[email protected]> *
* *
* This file is part of Silver Tree. *
* *
* Silver Tree is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* Silver Tree is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/> *
***************************************************************************/

#include "animation.hpp"

namespace graphics {
boost::scoped_ptr<time_source> time_source::time_source_;
}
101 changes: 101 additions & 0 deletions src/animation.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/***************************************************************************
* Copyright (C) 2008 by Sergey Popov <[email protected]> *
* *
* This file is part of Silver Tree. *
* *
* Silver Tree is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* Silver Tree is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/> *
***************************************************************************/

#ifndef ANIMATION_HPP_INCLUDED
#define ANIMATION_HPP_INCLUDED

#include <boost/scoped_ptr.hpp>
#include <boost/utility.hpp>

#include <SDL.h>

namespace graphics {

class time_source : boost::noncopyable
{
Uint32 ticks_;

time_source() : ticks_(SDL_GetTicks()) {}

static boost::scoped_ptr<time_source> time_source_;

public:
void advance_time() { ticks_ = SDL_GetTicks(); }
Uint32 time() const { return ticks_; }

static time_source& instance()
{
if(!time_source_)
time_source_.reset(new time_source);
return *time_source_;
}
};

template <class ValueType> class animation
{
Uint32 start_;
float duration_;

float time_offset() const { return static_cast<float>(time_source::instance().time() - start_)/1000.0; }
public:
animation() : start_(time_source::instance().time()), duration_(0) {}
virtual ~animation() {}
virtual ValueType operator()(float time) const = 0;

ValueType play() const { return (*this)(time_offset()); }
void set_duration(float duration) { duration_ = duration; }
bool finished() const { return time_offset() > duration_; }
};

template <class ValueType, class Function> class function_animation : public animation<ValueType>
{
Function function_;
public:
function_animation() : function_() {}
function_animation(Function function) : function_(function) {}
ValueType operator()(float time) const { return function_(time); }
};

template <class ValueType> class linear_function
{
ValueType a_, b_;

public:
linear_function(ValueType a, ValueType b) : a_(a), b_(b) {}
ValueType operator()(float x) const { return a_ * x + b_; }
};

template <class ValueType, class Function> function_animation<ValueType, Function> make_animation(Function function)
{
return function_animation<ValueType, Function>(function);
}

template <class ValueType> class quadratic_function
{
ValueType a_, b_, c_;

public:
quadratic_function() : a_(), b_(), c_() {}
quadratic_function(ValueType a, ValueType b, ValueType c) : a_(a), b_(b), c_(c) {}
ValueType operator()(float x) const { return a_ * (x * x) + b_ * x + c_; }
};

}

#endif
23 changes: 11 additions & 12 deletions src/particle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ namespace graphics {

void particle::draw()
{
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color_);
glVertex3f(pos_[0]-size_, pos_[1], pos_[2]);
glVertex3f(pos_[0]+size_, pos_[1], pos_[2]);
glVertex3f(pos_[0], pos_[1]+size_, pos_[2]);
for(int n = 0; n != 3; ++n) {
pos_[n] += velocity_[n];
velocity_[n] += acceleration_[n];
}

for(int n = 0; n != 4; ++n) {
color_[n] += color_diff_[n];
}
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color_.array());
Eigen::Vector3f pos = position_anim_.play();
pos.x() -= size_;
glVertex3fv(pos.array());
pos.x() += 2 * size_;
glVertex3fv(pos.array());
pos.x() -= size_;
pos.y() += size_;
glVertex3fv(pos.array());

color_ += color_diff_;
ttl_--;
}

Expand Down
14 changes: 8 additions & 6 deletions src/particle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@

#include <GL/glew.h>

#include "eigen/vector.h"

#include "animation.hpp"

namespace graphics {

class particle {
public:
friend class particle_emitter;
void draw();
bool dead() const { return ttl_ <= 0; }
bool dead() const { return position_anim_.finished(); }
private:
GLfloat size_;
GLfloat pos_[3];
GLfloat velocity_[3];
GLfloat acceleration_[3];
GLfloat color_[4];
GLfloat color_diff_[4];
function_animation<Eigen::Vector3f, quadratic_function<Eigen::Vector3f> > position_anim_;
Eigen::Vector4f color_;
Eigen::Vector4f color_diff_;
int ttl_;
};

Expand Down
Loading

0 comments on commit 7c45499

Please sign in to comment.