r146 - in trunk/src: . objects

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Mon Sep 5 08:46:22 EDT 2005


Author: jonas
Date: 2005-09-05 08:46:21 -0400 (Mon, 05 Sep 2005)
New Revision: 146

Modified:
   trunk/src/animation.cpp
   trunk/src/animation.h
   trunk/src/common.h
   trunk/src/events.cpp
   trunk/src/events.h
   trunk/src/gfxeng.h
   trunk/src/lost_penguins.cpp
   trunk/src/monsters_common.cpp
   trunk/src/monsters_common.h
   trunk/src/objects/baleog.cpp
   trunk/src/objects/baleog.h
   trunk/src/objects/erik.cpp
   trunk/src/objects/fang.cpp
   trunk/src/objects/fang.h
   trunk/src/objects/olaf.cpp
   trunk/src/objects/olaf.h
   trunk/src/objects/scorch.cpp
   trunk/src/objects/zombie.cpp
   trunk/src/objects_common.cpp
   trunk/src/objects_common.h
   trunk/src/players_common.cpp
   trunk/src/players_common.h
Log:
o The EmptyAnimation works as a Decorator for Animation: It has a fallback
  Animation** pointer. This way we don't need to do too much conditional logic
  in updateAnimState() as the animations should fallback automatically. If a
  fallback is state dependent it can be temporarly changed with setFallBack().
  All NULL animations have been replaced with EmptyAnimations (with specified
  fallbacks).

o The allign type has changed it's behaviour: It now acts like a gravity type
  (as in ImageMagick). The gravity is based on the initial frame which is now
  a member of the Animation class. Example: If the allign type is AT_LD it will
  try to position the base frame into the lower left corner of the base
  and then keep the base point fixed. As a consequence the shift parameters
  have been removed.

o Minor fixes


Modified: trunk/src/animation.cpp
===================================================================
--- trunk/src/animation.cpp	2005-09-04 21:31:57 UTC (rev 145)
+++ trunk/src/animation.cpp	2005-09-05 12:46:21 UTC (rev 146)
@@ -1,26 +1,72 @@
 #include "common.h"
 #include "animation.h"
 
+EmptyAnimation::EmptyAnimation(EmptyAnimation** afallback) : fallback(afallback) { }
+void EmptyAnimation::setBasePos(SDL_Rect* abase_pos) {
+    if (fallback) (*fallback)->setBasePos(abase_pos);
+}
+void EmptyAnimation::unsetBasePos() {
+    if (fallback) (*fallback)->unsetBasePos();
+}
+void EmptyAnimation::runAnim() {
+    if (fallback) (*fallback)->runAnim();
+}
+bool EmptyAnimation::updateAnim(Uint16 dt) {
+    if (fallback) return (*fallback)->updateAnim(dt);
+    return false;
+}
+Frame EmptyAnimation::getFrame() const {
+    if (fallback) return (*fallback)->getFrame();
+    else return base_frame;
+}
+SDL_Rect EmptyAnimation::getDrawPos() const { 
+    if (fallback) return (*fallback)->getDrawPos();
+    else return base_frame.pos;
+}
+SDL_Rect EmptyAnimation::getFrameDim() const {
+    if (fallback) return (*fallback)->getDrawPos();
+    else return base_frame.pos;
+}
+Frame EmptyAnimation::getBaseFrame() const {
+    if (fallback) return (*fallback)->getBaseFrame(); 
+    return base_frame;
+}
+bool EmptyAnimation::isValid() const {
+    if (fallback) return (*fallback)->isValid();
+    else return false;
+}
+bool EmptyAnimation::isRunning() const {
+    if (fallback) return (*fallback)->isRunning();
+    else return false;
+}   
+bool EmptyAnimation::isImage() const {
+    if (fallback) return (*fallback)->isImage();
+    else return true;
+}   
+bool EmptyAnimation::isFixed() const {
+    if (fallback) return (*fallback)->isFixed();
+    else return true;
+}
+void EmptyAnimation::setFallBack(EmptyAnimation** newfallback) {
+    fallback=newfallback;
+}
+
 Animation::Animation(const Image& abase_image,
           Uint16 aframes,
+          BasePointType abp_type,
           Uint16 aanimation_type,
           double afps,
           Uint16 astart_pos,
-          BasePointType abp_type,
-          AllignType aallign_type,
-          Sint16 ashift_x,
-          Sint16 ashift_y):
+          AllignType aallign_type): EmptyAnimation(NULL),
   base_image(abase_image),
   frames(aframes),
+  bp_type(abp_type),
   animation_type(aanimation_type),
   fps(afps),
   start_pos(astart_pos),
-  bp_type(abp_type),
   allign_type(aallign_type),
-  shift_x(ashift_x),
-  shift_y(ashift_y),
-  end_pos(start_pos+frames),
-  base_pos(NULL) {
+  base_pos(NULL),
+  end_pos(start_pos+frames) {
     if (fps==0) {
         fps=calcFPS(frames,DATA_LVLDUR);
     } else if (fps<0) {
@@ -29,7 +75,7 @@
     duration=(Uint32)(frames*1000.0/fps+0.5);
     checkAnim();
 }
-Animation::~Animation() { }
+Animation::~Animation() { is_valid=false; }
 void Animation::runAnim() {
     if (!isValid()) {
         cout << "Starting an invalid animation!" << endl;
@@ -134,10 +180,7 @@
 }
 Frame Animation::getBaseFrame() const {
     if (!isValid()) cout << "Invalid Base Frame of an invalid animation!" << endl;
-    Uint16 num;
-    if (animation_type&ATYPE_ALL_NORMAL) num=start_pos;
-    else num=end_pos;
-    return Frame(base_image.surface,base_image.description[num]);
+    return base_frame;
 }
 SDL_Rect Animation::getDrawPos() const {
     SDL_Rect draw_pos=base_image.description[cur_frame_num];
@@ -147,85 +190,85 @@
         draw_pos.x=draw_pos.y=draw_pos.w=draw_pos.h=0;
         return draw_pos;
     }
-    draw_pos.x=base_pos->x;
-    draw_pos.y=base_pos->y;
 
     /* calculate the base point */
     Sint16 base_point_x=0;
     Sint16 base_point_y=0;
 
-    /* BP_MD is used most times */
     if        (bp_type==BP_MD) {
-        base_point_x=(Uint16)draw_pos.w/2;
+        base_point_x=(Uint16)(draw_pos.w/2+0.5);
         base_point_y=draw_pos.h;
+    } else if (bp_type==BP_LD) {
+        base_point_x=0;
+        base_point_y=draw_pos.h;
+    } else if (bp_type==BP_RD) {
+        base_point_x=draw_pos.w;
+        base_point_y=draw_pos.h;
     } else if (bp_type==BP_LU) {
         base_point_x=0;
         base_point_y=0;
+    } else if (bp_type==BP_RU) {
+        base_point_x=draw_pos.w;
+        base_point_y=0;
     } else if (bp_type==BP_LM) {
         base_point_x=0;
-        base_point_y=(Uint16)draw_pos.h/2;
-    } else if (bp_type==BP_LD) {
-        base_point_x=0;
-        base_point_y=draw_pos.h;
+        base_point_y=(Uint16)(draw_pos.h/2+0.5);
     } else if (bp_type==BP_MU) {
-        base_point_x=(Uint16)draw_pos.w/2;
+        base_point_x=(Uint16)(draw_pos.w/2+0.5);
         base_point_y=0;
     } else if (bp_type==BP_MM) {
-        base_point_x=(Uint16)draw_pos.w/2;
-        base_point_y=(Uint16)draw_pos.h/2;
-    } else if (bp_type==BP_RU) {
-        base_point_x=draw_pos.w;
-        base_point_y=0;
+        base_point_x=(Uint16)(draw_pos.w/2+0.5);
+        base_point_y=(Uint16)(draw_pos.h/2+0.5);
     } else if (bp_type==BP_RM) {
         base_point_x=draw_pos.w;
-        base_point_y=(Uint16)draw_pos.h/2;
-    } else if (bp_type==BP_RD) {
-        base_point_x=draw_pos.w;
-        base_point_y=draw_pos.h;
+        base_point_y=(Uint16)(draw_pos.h/2+0.5);
     } else {
         cout << "This shouldn't happen: Unknown base point type!" << endl;
-        base_point_x=(Uint16)draw_pos.w/2;
+        base_point_x=(Uint16)(draw_pos.w/2+0.5);
         base_point_y=draw_pos.h;
     }
 
-    /* calculate the draw_pos using the allignment type */
+    /* add the shift value */
+    base_point_x+=shift_x;
+    base_point_y+=shift_y;
+
+    /* calculate the draw position */
+    draw_pos.x=base_pos->x;
+    draw_pos.y=base_pos->y;
+
     if        (allign_type==AT_MD) {
-        draw_pos.x+=(Uint16)base_pos->w/2-base_point_x;
+        draw_pos.x+=(Uint16)(base_pos->w/2+0.5)-base_point_x;
         draw_pos.y+=base_pos->h-base_point_y;
     } else if (allign_type==AT_LU) {
         draw_pos.x-=base_point_x;
         draw_pos.y-=base_point_y;
     } else if (allign_type==AT_LM) {
         draw_pos.x-=base_point_x;
-        draw_pos.y+=(Uint16)base_pos->h/2-base_point_y;
+        draw_pos.y+=(Uint16)(base_pos->h/2+0.5)-base_point_y;
     } else if (allign_type==AT_LD) {
         draw_pos.x-=base_point_x;
         draw_pos.y+=base_pos->h-base_point_y;
     } else if (allign_type==AT_MU) {
-        draw_pos.x+=(Uint16)base_pos->w/2-base_point_x;
+        draw_pos.x+=(Uint16)(base_pos->w/2+0.5)-base_point_x;
         draw_pos.y-=base_point_y;
     } else if (allign_type==AT_MM) {
-        draw_pos.x+=(Uint16)base_pos->w/2-base_point_x;
-        draw_pos.y+=(Uint16)base_pos->h/2-base_point_y;
+        draw_pos.x+=(Uint16)(base_pos->w/2+0.5)-base_point_x;
+        draw_pos.y+=(Uint16)(base_pos->h/2+0.5)-base_point_y;
     } else if (allign_type==AT_RU) {
         draw_pos.x+=base_pos->w-base_point_x;
         draw_pos.y-=base_point_y;
     } else if (allign_type==AT_RM) {
         draw_pos.x+=base_pos->w-base_point_x;
-        draw_pos.y+=(Uint16)base_pos->h/2-base_point_y;
+        draw_pos.y+=(Uint16)(base_pos->h/2+0.5)-base_point_y;
     } else if (allign_type==AT_RD) {
         draw_pos.x+=base_pos->w-base_point_x;
         draw_pos.y+=base_pos->h-base_point_y;
     } else {
         cout << "This shouldn't happen: Unknown allign type!" << endl;
-        draw_pos.x+=(Uint16)base_pos->w/2-base_point_x;
+        draw_pos.x+=(Uint16)(base_pos->w/2+0.5)-base_point_x;
         draw_pos.y+=base_pos->h-base_point_y;
     }
 
-    /* substract shift ("add" it to the bp position) */
-    draw_pos.x-=shift_x;
-    draw_pos.y-=shift_y;
-
     return draw_pos;
 }
 
@@ -238,15 +281,92 @@
     return rect;
 }
 
+void Animation::setShift() {
+    /* calculate the base point */
+    Sint16 base_point_x=0;
+    Sint16 base_point_y=0;
+
+    if        (bp_type==BP_MD) {  
+        base_point_x=(Uint16)(base_frame.pos.w/2+0.5);
+        base_point_y=base_frame.pos.h;
+    } else if (bp_type==BP_LD) {
+        base_point_x=0;
+        base_point_y=base_frame.pos.h;
+    } else if (bp_type==BP_RD) {
+        base_point_x=base_frame.pos.w;
+        base_point_y=base_frame.pos.h;
+    } else if (bp_type==BP_LU) {
+        base_point_x=0;
+        base_point_y=0;
+    } else if (bp_type==BP_RU) {
+        base_point_x=base_frame.pos.w;
+        base_point_y=0;
+    } else if (bp_type==BP_LM) {
+        base_point_x=0;
+        base_point_y=(Uint16)(base_frame.pos.h/2+0.5);
+    } else if (bp_type==BP_MU) {
+        base_point_x=(Uint16)(base_frame.pos.w/2+0.5);
+        base_point_y=0;
+    } else if (bp_type==BP_MM) {
+        base_point_x=(Uint16)(base_frame.pos.w/2+0.5);
+        base_point_y=(Uint16)(base_frame.pos.h/2+0.5);
+    } else if (bp_type==BP_RM) {
+        base_point_x=base_frame.pos.w;
+        base_point_y=(Uint16)(base_frame.pos.h/2+0.5);
+    } else {
+        cout << "This shouldn't happen: Unknown base point type!" << endl;
+        base_point_x=(Uint16)(base_frame.pos.w/2+0.5);
+        base_point_y=base_frame.pos.h;
+    }
+
+    /* calculate the shift point */
+    Sint16 shift_point_x=0;
+    Sint16 shift_point_y=0;
+
+    /* AT_MD is used most times */
+    if        (allign_type==AT_MD) {  
+        shift_point_x=(Uint16)(base_frame.pos.w/2+0.5);
+        shift_point_y=base_frame.pos.h;
+    } else if (allign_type==AT_LU) {
+        shift_point_x=0;
+        shift_point_y=0;
+    } else if (allign_type==AT_LM) {
+        shift_point_x=0;
+        shift_point_y=(Uint16)(base_frame.pos.h/2+0.5);
+    } else if (allign_type==AT_LD) {
+        shift_point_x=0;
+        shift_point_y=base_frame.pos.h;
+    } else if (allign_type==AT_MU) {
+        shift_point_x=(Uint16)(base_frame.pos.w/2+0.5);
+        shift_point_y=0;
+    } else if (allign_type==AT_MM) {
+        shift_point_x=(Uint16)(base_frame.pos.w/2+0.5);
+        shift_point_y=(Uint16)(base_frame.pos.h/2+0.5);
+    } else if (allign_type==AT_RU) {
+        shift_point_x=base_frame.pos.w;
+        shift_point_y=0;
+    } else if (allign_type==AT_RM) {
+        shift_point_x=base_frame.pos.w;
+        shift_point_y=(Uint16)(base_frame.pos.h/2+0.5);
+    } else if (allign_type==AT_RD) {
+        shift_point_x=base_frame.pos.w;
+        shift_point_y=base_frame.pos.h;
+    } else {
+        cout << "This shouldn't happen: Unknown alling type!" << endl;
+        shift_point_x=(Uint16)(base_frame.pos.w/2+0.5);
+        shift_point_y=base_frame.pos.h;
+    }
+
+    /* set the shift values */
+    shift_x=shift_point_x-base_point_x;
+    shift_y=shift_point_y-base_point_y;
+}
+
 bool Animation::checkAnim() {
     if (base_image.surface==NULL || base_image.description.empty()) {
         is_valid=false;
     } else if (base_image.description.size()==1 || duration==0 || frames==1) {
         is_image=true;
-        cur_time=0;
-        forward=true;
-        cur_frame_num=0;
-        is_running=false;
         is_fixed=true;
         is_valid=true;
     } else if (frames==0 || start_pos>end_pos || (start_pos+frames)>base_image.description.size()) {
@@ -255,6 +375,8 @@
         is_valid=true;
         is_image=false;
         is_fixed=false;
+    }
+    if (is_valid) {
         if (animation_type&ATYPE_ALL_ONCE) is_running=false;
         else is_running=true;
         cur_time=0;
@@ -265,6 +387,8 @@
             forward=false;
             cur_frame_num=frames-1;
         }
+        base_frame=Frame(base_image.surface,base_image.description[(animation_type&ATYPE_ALL_NORMAL) ? start_pos : end_pos]);
+        setShift();
     }
     return is_valid;
 }

Modified: trunk/src/animation.h
===================================================================
--- trunk/src/animation.h	2005-09-04 21:31:57 UTC (rev 145)
+++ trunk/src/animation.h	2005-09-05 12:46:21 UTC (rev 146)
@@ -1,82 +1,114 @@
 #ifndef DEF_ANIMATION_H
 #define DEF_ANIMATION_H 1
 
+class EmptyAnimation {
+    public:
+        EmptyAnimation(EmptyAnimation** afallback=NULL);
+        virtual ~EmptyAnimation() { }
+        virtual void setBasePos(SDL_Rect*);
+        virtual void unsetBasePos();
+        virtual void runAnim();
+        virtual bool updateAnim(Uint16);
+        virtual Frame getFrame() const;
+        virtual SDL_Rect getDrawPos() const;
+        virtual SDL_Rect getFrameDim() const;
+        virtual Frame getBaseFrame() const;
+        virtual bool isValid() const;
+        virtual bool isRunning() const;
+        virtual bool isImage() const;
+        virtual bool isFixed() const;
+        virtual void setFallBack(EmptyAnimation** newfallback=NULL);
+    protected:
+        Frame base_frame;
+    private:
+        EmptyAnimation** fallback;
+};
+
 /** \brief Animation is responsible to return the correct frame of an animation
 
 */
-class Animation {
+class Animation : public EmptyAnimation {
     public:
         /// \brief Initialize the animation
         /// \param abase_image Base image used for the animation
         /// \param aframes Number of frames
+        /// \param abp_type Base point type
+        /// \param aanimation_type Animation type
         /// \param afps FPS of the animation, if (afps < 0) it is considered to be the duration in ms, if (afps==0) a default duration DATA_LVLDUR is taken
-        /// \param aanimation_type Animation type
         /// \param astart_pos Start position from the frame array of the base_image
-        /// \param abp_type Base point type
         /// \param aallign_type Allignment type
-        /// \param ashift_x x shift value
-        /// \param ashift_y y shift value
         ///
         /// To load one still image simply use: Animation(imgcache->loadImage(1,"image_name.png"))
         Animation(const Image& abase_image,
                   Uint16 aframes=1,
+                  BasePointType abp_type=BP_MD,
                   Uint16 aanimation_type=ATYPE_LOOP,
                   double afps=0,
                   Uint16 astart_pos=0,
-                  BasePointType abp_type=BP_MD,
-                  AllignType aallign_type=AT_MD,
-                  Sint16 ashift_x=0,
-                  Sint16 ashift_y=0);
-        ~Animation();
+                  AllignType aallign_type=AT_MD);
+        Animation();
+        virtual ~Animation();
         /// Set the base position of the animation
-        void setBasePos(SDL_Rect* abase_pos) {
+        virtual void setBasePos(SDL_Rect* abase_pos) {
             base_pos=abase_pos;
             checkAnim();
         }
         /// Unsets the base position of the animation
-        void unsetBasePos() {
+        virtual void unsetBasePos() {
             base_pos=NULL;
         }
         /// Start the animation from the beginning (used when the animation was still)
-        void runAnim();
+        virtual void runAnim();
         /// Updates a running animation and stops it if necessary
         /// return True if the animation is still running
-        bool updateAnim(Uint16 dt);
+        virtual bool updateAnim(Uint16 dt);
         /// Calculates and returns the current frame
-        Frame getFrame() const;
+        virtual Frame getFrame() const;
         /// Calculates and returns the current draw position using:
-        /// base_pos,bp_type,allign_type,shift
-        SDL_Rect getDrawPos() const;
+        /// base_pos,bp_type,allign_type
+        virtual SDL_Rect getDrawPos() const;
         /// HACK: Return the dimensions of the first frame
-        SDL_Rect getFrameDim() const;
+        virtual SDL_Rect getFrameDim() const;
         /// HACK: Return the base frame
-        Frame getBaseFrame() const;
+        virtual Frame getBaseFrame() const;
         /// return True if the animation is valid
-        bool isValid() const {
+        virtual bool isValid() const {
             return is_valid;
         }
         /// return True if the animation is running
-        bool isRunning() const {
+        virtual bool isRunning() const {
             return is_running;
         }   
         /// return True if the animation is a still image
-        bool isImage() const {
+        virtual bool isImage() const {
             return is_image;
         }   
         /// return True if the animation dimensions stay the same
-        bool isFixed() const {
+        virtual bool isFixed() const {
             return is_fixed;
-        }   
-    private:
+        }
+        virtual void setFallBack(EmptyAnimation**) { }
+    protected:
+        /// Helper function to set the shift values of the animation
+        void setShift();
         /// Helper function to stop an animation
         bool stopAnim();
         /// check validity of the animation
         bool checkAnim();
-    private:
+    protected:
         /// Base image for the animation (big)
         Image base_image;
         /// Number of frames
         Uint16 frames;
+        ///\brief The base point of the animation
+        ///
+        /// The base point always stays fixed during the animation.
+        /// It's types are: BP_xy, where x may be either L,M or R and y may be either
+        /// U, M or D. L: left end, M: middle, R: right end, U: upper end, D: lower end
+        ///
+        /// Example: BP_MU means the BP is the upper middle point of each frame.
+        /// Default: BP_MD
+        BasePointType bp_type;
         /// Animation type: ATYPE_ONCE (play once), ATYPE_ONCE_END (play once and stop at end),
         /// ATYPE_LOOP (always play, jump back to the beginning), ATYPE_SWING (always play,
         /// reverse direction when finnished). The appended _REV means that the animation is
@@ -86,31 +118,23 @@
         double fps;
         /// Start position from the frame array of the base_image
         Uint16 start_pos;
-        ///\brief The base point of the animation
-        ///
-        /// The base point always stays fixed during the animation.
-        /// It's types are: BP_xy, where x may be either L,M or R and y may be either
-        /// U, M or D. L: left end, M: middle, R: right end, U: upper end, D: lower end
-        ///
-        /// Example: BP_MU means the BP is the upper middle point of each frame.
-        /// Default: BP_MD
-        BasePointType bp_type;
         ///\brief Allignment of the base point onto the base_pos
         ///
         /// The allignment specifies how the base point should be positioned wrt to the
         /// base_pos: It's type are basically the same as in BasePointType.
         ///
         /// Example: (Assuming BP_MD) AT_LD means the middle point of each frame (BP_MD)
-        ///          is mapped onto the lower left edge of the base_pos
+        ///          is stays fixed wrt to the base position and the animation is placed with
+        ///          a "south west gravity" (similar to ImageMagick) wrt to the base position
         /// Default: AT_MD
         AllignType allign_type;
-        //@{
+        
+        /* calculated (checkAnim()) or given values */
+        /// Pointer to the current base position of the animation
+        SDL_Rect* base_pos;
         /// shift is added as an additional value to the designated BP position.
         Sint16 shift_x;
         Sint16 shift_y;
-        //@}
-        
-        /* calculated or given values/functions */
         /// Duration of the animation in ms
         Uint32 duration;
         /// End position from the frame array of the base_image
@@ -123,8 +147,6 @@
         bool is_fixed;
 
         /* temporary values */
-        /// Pointer to the current base position of the animation
-        SDL_Rect* base_pos;
         /// True if the animation is running
         bool is_running;
         /// True if the animation is running forward at the moment

Modified: trunk/src/common.h
===================================================================
--- trunk/src/common.h	2005-09-04 21:31:57 UTC (rev 145)
+++ trunk/src/common.h	2005-09-05 12:46:21 UTC (rev 146)
@@ -38,6 +38,7 @@
 class Font;
 class Event;
 class Weapon;
+class EmptyAnimation;
 class Animation;
 class Menu;
 class Box;

Modified: trunk/src/events.cpp
===================================================================
--- trunk/src/events.cpp	2005-09-04 21:31:57 UTC (rev 145)
+++ trunk/src/events.cpp	2005-09-05 12:46:21 UTC (rev 146)
@@ -52,12 +52,12 @@
     delete this;
 }
 
-AnimEvent::AnimEvent(Object* obj, Uint16 length, Uint16 edelay, Uint32 switchstate, Mix_Chunk* asound, Animation* runanim, bool delanim):
+AnimEvent::AnimEvent(Object* obj, Uint16 length, Uint16 edelay, Uint32 switchstate, Mix_Chunk* asound, EmptyAnimation* runanim, bool delanim):
   Event(obj,length,edelay,switchstate),
   anim(runanim),
   del(delanim),
   sound(asound) {
-    if (anim) {
+    if (anim && anim->isValid()) {
         state|=ESTATE_ANIM;
         duration=30000;
     }
@@ -93,13 +93,15 @@
   charowner(chr) { }
   
 //Exactly the same as AnimEvent with Character* instead of Object*
-CAnimEvent::CAnimEvent(Character* chr, Uint16 length, Uint16 edelay, Uint32 switchstate, Mix_Chunk* asound, Animation* runanim, bool delanim):
+CAnimEvent::CAnimEvent(Character* chr, Uint16 length, Uint16 edelay, Uint32 switchstate, Mix_Chunk* asound, EmptyAnimation* runanim, bool delanim):
   CEvent(chr,length,edelay,switchstate),
   anim(runanim),
   del(delanim),
   sound(asound) {
-    if (anim) state|=ESTATE_ANIM;
-    if (anim!=NULL) duration=30000;
+    if (anim && anim->isValid()) {
+        state|=ESTATE_ANIM;
+        duration=30000;
+    }
 }
 Uint16 CAnimEvent::update(Uint16 dt) {
     Uint16 evstate=CEvent::update(dt);
@@ -127,7 +129,7 @@
 }
 
 
-ERun::ERun(Character* chr, Uint16 length, Sint16 edmax, Uint16 edelay, Uint32 switchstate, Mix_Chunk* esound, Animation* runanim, bool delanim):
+ERun::ERun(Character* chr, Uint16 length, Sint16 edmax, Uint16 edelay, Uint32 switchstate, Mix_Chunk* esound, EmptyAnimation* runanim, bool delanim):
   CAnimEvent(chr,length,edelay,(switchstate|STATE_PRESS_LR),esound,runanim,delanim),
   dmax(edmax),
   t_reset(0) {
@@ -167,7 +169,7 @@
 }
 
 
-EAttack::EAttack(Character* chr, Uint16 length, Weapon* atweapon, Uint16 dir, Uint16 weap_range, Uint16 target_mask, Uint16 edelay, Uint32 switchstate, Mix_Chunk* esound, Animation* runanim, bool delanim):
+EAttack::EAttack(Character* chr, Uint16 length, Weapon* atweapon, Uint16 dir, Uint16 weap_range, Uint16 target_mask, Uint16 edelay, Uint32 switchstate, Mix_Chunk* esound, EmptyAnimation* runanim, bool delanim):
   CAnimEvent(chr,length,edelay,switchstate|ESTATE_BUSY,esound,runanim,delanim),
   weapon(atweapon),
   direction(dir),

Modified: trunk/src/events.h
===================================================================
--- trunk/src/events.h	2005-09-04 21:31:57 UTC (rev 145)
+++ trunk/src/events.h	2005-09-05 12:46:21 UTC (rev 146)
@@ -62,7 +62,7 @@
         /// \todo Get rid of the delanim parameter
         /// \param delanim True if the animation should be deleted
         AnimEvent(Object* obj, Uint16 length, Uint16 edelay=0, Uint32 switchstate=NOTHING,
-          Mix_Chunk* asound=NULL, Animation* runanim=NULL, bool delanim=false);
+          Mix_Chunk* asound=NULL, EmptyAnimation* runanim=NULL, bool delanim=false);
         /// \brief Updates the events
         /// \return Event state: either delayed (EV_DELAY), starting (EV_START),
         ///         running (EV_RUN), stopping (EV_END) or canceled (EV_CANCEL)
@@ -71,7 +71,7 @@
         virtual void end();  
         virtual void cancel();
     protected:
-        Animation* anim;
+        EmptyAnimation* anim;
         bool del;
         Mix_Chunk* sound;
 };
@@ -83,13 +83,13 @@
 class CAnimEvent : public CEvent {
     public:
         CAnimEvent(Character* chr, Uint16 length, Uint16 edelay=0, Uint32 switchstate=NOTHING,
-          Mix_Chunk* asound=NULL, Animation* runanim=NULL, bool delanim=false);
+          Mix_Chunk* asound=NULL, EmptyAnimation* runanim=NULL, bool delanim=false);
         virtual Uint16 update(Uint16 dt);
         virtual void start();
         virtual void end();  
         virtual void cancel();
     protected:
-        Animation* anim;
+        EmptyAnimation* anim;
         bool del;
         Mix_Chunk* sound;
 };
@@ -116,7 +116,7 @@
         /// \param delanim True if the animation should be deleted
         EAttack(Character* chr, Uint16 length, Weapon* atweapon, Uint16 dir, Uint16 weapon_range=0,
           Uint16 target_mask=NOTHING, Uint16 edelay=0, Uint32 switchstate=0, Mix_Chunk* esound=NULL,
-          Animation* runanim=NULL, bool delanim=false);
+          EmptyAnimation* runanim=NULL, bool delanim=false);
         virtual void end();
     protected:
         Weapon* weapon;
@@ -134,7 +134,7 @@
     public:
         /// Adds the initial speed
         ERun(Character* chr, Uint16 length, Sint16 edmax, Uint16 edelay=0,
-          Uint32 switchstate=0, Mix_Chunk* esound=NULL, Animation* runanim=NULL, bool delanim=false);
+          Uint32 switchstate=0, Mix_Chunk* esound=NULL, EmptyAnimation* runanim=NULL, bool delanim=false);
         virtual ~ERun();
         /// Forces the event to continue
         virtual void start(); 

Modified: trunk/src/gfxeng.h
===================================================================
--- trunk/src/gfxeng.h	2005-09-04 21:31:57 UTC (rev 145)
+++ trunk/src/gfxeng.h	2005-09-05 12:46:21 UTC (rev 146)
@@ -45,7 +45,7 @@
         /// player bar
         SDL_Rect bar;
         /// symbol for one life of a player
-        Animation* lifeimage;
+        EmptyAnimation* lifeimage;
         bool show_bar;
         bool show_fps;
         //visual flags

Modified: trunk/src/lost_penguins.cpp
===================================================================
--- trunk/src/lost_penguins.cpp	2005-09-04 21:31:57 UTC (rev 145)
+++ trunk/src/lost_penguins.cpp	2005-09-05 12:46:21 UTC (rev 146)
@@ -58,6 +58,7 @@
         input->update();
         scenario->physic->update();
         gfxeng->draw();
+        SDL_Delay(1);
     }
 
     quitGame(-2);

Modified: trunk/src/monsters_common.cpp
===================================================================
--- trunk/src/monsters_common.cpp	2005-09-04 21:31:57 UTC (rev 145)
+++ trunk/src/monsters_common.cpp	2005-09-05 12:46:21 UTC (rev 146)
@@ -21,12 +21,15 @@
     otype|=OTYPE_MONSTER;
     enemy_types|=OTYPE_PLAYER;
     dense_types|=OTYPE_PLAYER;
-    anim_left=animation;
-    anim_right=animation;
+    anim_left=new EmptyAnimation(&anim_right);
+    anim_right=new EmptyAnimation();
     au_hit=scenario->sndcache->loadWAV("monhit.wav");
 }
 
-Monster::~Monster() { }
+Monster::~Monster() {
+    delete anim_left;
+    delete anim_right;
+}
 
 void Monster::addEnter(std::set<Object *>& aset) {
     Character::addEnter(aset);    

Modified: trunk/src/monsters_common.h
===================================================================
--- trunk/src/monsters_common.h	2005-09-04 21:31:57 UTC (rev 145)
+++ trunk/src/monsters_common.h	2005-09-05 12:46:21 UTC (rev 146)
@@ -36,8 +36,8 @@
         std::set<Player *> targets;
         virtual Hit move(Uint16 dt, bool check=false);
         //common animations
-        Animation* anim_left;
-        Animation* anim_right;
+        EmptyAnimation* anim_left;
+        EmptyAnimation* anim_right;
         Mix_Chunk* au_hit;
         Sint16 Dai,Dattack;
 };

Modified: trunk/src/objects/baleog.cpp
===================================================================
--- trunk/src/objects/baleog.cpp	2005-09-04 21:31:57 UTC (rev 145)
+++ trunk/src/objects/baleog.cpp	2005-09-05 12:46:21 UTC (rev 146)
@@ -14,11 +14,11 @@
     anim_right=loadAnimation(scenario->imgcache->loadImage(1,"baleog1_right.bmp"));
     anim_walk_left=loadAnimation(scenario->imgcache->loadImage("baleog1-run_left.png"),8);
     anim_walk_right=loadAnimation(scenario->imgcache->loadImage(8,"baleog1-run_right.png"),8);
-    anim_crash_left=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_land_left.bmp"),1,ATYPE_ONCE_END,calcFPS(1,T_IRR));
-    anim_crash_right=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_land_right.bmp"),1,ATYPE_ONCE_END,calcFPS(1,T_IRR));
+    anim_crash_left=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_land_left.bmp"),1,BP_LD,ATYPE_ONCE_END,calcFPS(1,T_IRR));
+    anim_crash_right=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_land_right.bmp"),1,BP_RD,ATYPE_ONCE_END,calcFPS(1,T_IRR));
     weapon=Weapon(-1,W_STRIKE);
-    anim_sword_left=loadAnimation(scenario->imgcache->loadImage(8,"BaleogCyborg_Slash_left.png"),8,ATYPE_ONCE_END);
-    anim_sword_right=loadAnimation(scenario->imgcache->loadImage(8,"BaleogCyborg_Slash_right.png"),8,ATYPE_ONCE_END);
+    anim_sword_left=loadAnimation(scenario->imgcache->loadImage(8,"BaleogCyborg_Slash_left.png"),8,BP_MD,ATYPE_ONCE_END);
+    anim_sword_right=loadAnimation(scenario->imgcache->loadImage(8,"BaleogCyborg_Slash_right.png"),8,BP_MD,ATYPE_ONCE_END);
     au_sword=scenario->sndcache->loadWAV("swrdsw2.wav");
 }
 

Modified: trunk/src/objects/baleog.h
===================================================================
--- trunk/src/objects/baleog.h	2005-09-04 21:31:57 UTC (rev 145)
+++ trunk/src/objects/baleog.h	2005-09-05 12:46:21 UTC (rev 146)
@@ -11,6 +11,6 @@
         virtual void in_sp1();
     private:
         Mix_Chunk* au_sword;
-        Animation* anim_sword_left;
-        Animation* anim_sword_right;
+        EmptyAnimation* anim_sword_left;
+        EmptyAnimation* anim_sword_right;
 };

Modified: trunk/src/objects/erik.cpp
===================================================================
--- trunk/src/objects/erik.cpp	2005-09-04 21:31:57 UTC (rev 145)
+++ trunk/src/objects/erik.cpp	2005-09-05 12:46:21 UTC (rev 146)
@@ -18,43 +18,43 @@
 /*
     anim_left=loadAnimation(scenario->imgcache->loadImage("erik1_left.bmp"));
     anim_right=loadAnimation(scenario->imgcache->loadImage(1,"erik1_right.bmp"));
-    anim_land_left=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_land_left.bmp"),1,ATYPE_ONCE_END,calcFPS(1,T_IRR));
-    anim_land_right=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_land_right.bmp"),1,ATYPE_ONCE_END,calcFPS(1,T_IRR));
-    anim_crash_left=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_land_left.bmp"),1,ATYPE_ONCE_END,calcFPS(1,T_IRR));
-    anim_crash_right=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_land_right.bmp"),1,ATYPE_ONCE_END,calcFPS(1,T_IRR));
+    anim_land_left=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_land_left.bmp"),1,BP_LD,ATYPE_ONCE_END,calcFPS(1,T_IRR));
+    anim_land_right=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_land_right.bmp"),1,BP_RD,ATYPE_ONCE_END,calcFPS(1,T_IRR));
+    anim_crash_left=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_land_left.bmp"),1,BP_LD,ATYPE_ONCE_END,calcFPS(1,T_IRR));
+    anim_crash_right=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_land_right.bmp"),1,BP_RD,ATYPE_ONCE_END,calcFPS(1,T_IRR));
 */
-    anim_left=loadAnimation("erik_idle_left",config.lvlscale);
-    anim_right=loadAnimation("erik_idle_right",config.lvlscale);
-    anim_rock_left=loadAnimation("erik_rock_left",config.lvlscale);
-    anim_rock_right=loadAnimation("erik_rock_right",config.lvlscale);
-    anim_walk_left=loadAnimation("erik_walk_left",config.lvlscale);
-    anim_walk_right=loadAnimation("erik_walk_right",config.lvlscale);
-    anim_push_left=loadAnimation("erik_push_left",config.lvlscale);
-    anim_push_right=loadAnimation("erik_push_right",config.lvlscale);
+    anim_left=loadAnimation("erik_idle_left",config.lvlscale,BP_RD);
+    anim_right=loadAnimation("erik_idle_right",config.lvlscale,BP_LD);
+    anim_rock_left=loadAnimation("erik_rock_left",config.lvlscale,BP_RD);
+    anim_rock_right=loadAnimation("erik_rock_right",config.lvlscale,BP_LD);
+    anim_walk_left=loadAnimation("erik_walk_left",config.lvlscale,BP_RD);
+    anim_walk_right=loadAnimation("erik_walk_right",config.lvlscale,BP_LD);
+    anim_push_left=loadAnimation("erik_push_left",config.lvlscale,BP_RD);
+    anim_push_right=loadAnimation("erik_push_right",config.lvlscale,BP_LD);
     anim_fall_middle=loadAnimation("erik_fall_middle",config.lvlscale);
-    anim_fall_left=loadAnimation("erik_fall_left",config.lvlscale);
-    anim_fall_right=loadAnimation("erik_fall_right",config.lvlscale);
-    anim_fall_fast_left=loadAnimation("erik_fall_fast_left",config.lvlscale);
-    anim_fall_fast_right=loadAnimation("erik_fall_fast_right",config.lvlscale);
-    anim_land_left=loadAnimation("erik_land_left",config.lvlscale,ATYPE_ONCE_END);
-    anim_land_right=loadAnimation("erik_land_right",config.lvlscale,ATYPE_ONCE_END);
-    anim_crash_left=loadAnimation("erik_crash_left",config.lvlscale,ATYPE_ONCE_END,calcFPS(1,T_IRR));
-    anim_crash_right=loadAnimation("erik_crash_right",config.lvlscale,ATYPE_ONCE_END,calcFPS(1,T_IRR));
-    anim_rope_left=loadAnimation("erik_rope_left",config.lvlscale);
-    anim_rope_right=loadAnimation("erik_rope_right",config.lvlscale);
-    anim_teleport_left=loadAnimation("erik_teleport_left",config.lvlscale,ATYPE_ONCE_END);
-    anim_teleport_right=loadAnimation("erik_teleport_right",config.lvlscale,ATYPE_ONCE_END);
-    anim_die_crash_left=loadAnimation("erik_die_crash_left",config.lvlscale,ATYPE_ONCE_END);
-    anim_die_crash_right=loadAnimation("erik_die_crash_right",config.lvlscale,ATYPE_ONCE_END);
-    anim_die_burn_left=loadAnimation("erik_die_burn_left",config.lvlscale,ATYPE_ONCE_END);
-    anim_die_burn_right=loadAnimation("erik_die_burn_right",config.lvlscale,ATYPE_ONCE_END);
-    anim_die_bones_left=loadAnimation("erik_die_bones_left",config.lvlscale,ATYPE_ONCE_END);
-    anim_die_bones_right=loadAnimation("erik_die_bones_right",config.lvlscale,ATYPE_ONCE_END);
-    anim_die_elec_left=loadAnimation("erik_die_elec_left",config.lvlscale,ATYPE_ONCE_END);
-    anim_die_elec_right=loadAnimation("erik_die_elec_right",config.lvlscale,ATYPE_ONCE_END);
-    anim_die_spike_left=loadAnimation("erik_die_spike_left",config.lvlscale,ATYPE_ONCE_END);
-    anim_die_spike_right=loadAnimation("erik_die_spike_right",config.lvlscale,ATYPE_ONCE_END);
-    anim_bar=loadAnimation("bar_erik",config.lvlscale,ATYPE_ONCE);
+    anim_fall_left=loadAnimation("erik_fall_left",config.lvlscale,BP_RD);
+    anim_fall_right=loadAnimation("erik_fall_right",config.lvlscale,BP_LD);
+    anim_fall_fast_left=loadAnimation("erik_fall_fast_left",config.lvlscale,BP_RD);
+    anim_fall_fast_right=loadAnimation("erik_fall_fast_right",config.lvlscale,BP_LD);
+    anim_land_left=loadAnimation("erik_land_left",config.lvlscale,BP_RD,ATYPE_ONCE_END);
+    anim_land_right=loadAnimation("erik_land_right",config.lvlscale,BP_LD,ATYPE_ONCE_END);
+    anim_crash_left=loadAnimation("erik_crash_left",config.lvlscale,BP_RD,ATYPE_ONCE_END,calcFPS(1,T_IRR));
+    anim_crash_right=loadAnimation("erik_crash_right",config.lvlscale,BP_LD,ATYPE_ONCE_END,calcFPS(1,T_IRR));
+    anim_rope_left=loadAnimation("erik_rope_left",config.lvlscale,BP_RD);
+    anim_rope_right=loadAnimation("erik_rope_right",config.lvlscale,BP_LD);
+    anim_teleport_left=loadAnimation("erik_teleport_left",config.lvlscale,BP_RD,ATYPE_ONCE_END);
+    anim_teleport_right=loadAnimation("erik_teleport_right",config.lvlscale,BP_LD,ATYPE_ONCE_END);
+    anim_die_crash_left=loadAnimation("erik_die_crash_left",config.lvlscale,BP_RD,ATYPE_ONCE_END);
+    anim_die_crash_right=loadAnimation("erik_die_crash_right",config.lvlscale,BP_LD,ATYPE_ONCE_END);
+    anim_die_burn_left=loadAnimation("erik_die_burn_left",config.lvlscale,BP_RD,ATYPE_ONCE_END);
+    anim_die_burn_right=loadAnimation("erik_die_burn_right",config.lvlscale,BP_LD,ATYPE_ONCE_END);
+    anim_die_bones_left=loadAnimation("erik_die_bones_left",config.lvlscale,BP_RD,ATYPE_ONCE_END);
+    anim_die_bones_right=loadAnimation("erik_die_bones_right",config.lvlscale,BP_LD,ATYPE_ONCE_END);
+    anim_die_elec_left=loadAnimation("erik_die_elec_left",config.lvlscale,BP_RD,ATYPE_ONCE_END);
+    anim_die_elec_right=loadAnimation("erik_die_elec_right",config.lvlscale,BP_LD,ATYPE_ONCE_END);
+    anim_die_spike_left=loadAnimation("erik_die_spike_left",config.lvlscale,BP_RD,ATYPE_ONCE_END);
+    anim_die_spike_right=loadAnimation("erik_die_spike_right",config.lvlscale,BP_LD,ATYPE_ONCE_END);
+    anim_bar=loadAnimation("bar_erik",config.lvlscale,BP_MD,ATYPE_ONCE);
 
     /* anim_die_water is missing as eric doesn't die under water, anim_climb is missing as well */
     au_jump=scenario->sndcache->loadWAV("rboots.wav");

Modified: trunk/src/objects/fang.cpp
===================================================================
--- trunk/src/objects/fang.cpp	2005-09-04 21:31:57 UTC (rev 145)
+++ trunk/src/objects/fang.cpp	2005-09-05 12:46:21 UTC (rev 146)
@@ -16,8 +16,8 @@
     anim_right=loadAnimation(scenario->imgcache->loadImage(4,"Fang_Breath_right.png"),4);
     anim_walk_left=loadAnimation(scenario->imgcache->loadImage(8,"Fang_walk_left.png"),8);
     anim_walk_right=loadAnimation(scenario->imgcache->loadImage(8,"Fang_walk_right.png"),8);
-    anim_crash_left=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_land_left.bmp"),1,ATYPE_ONCE_END,calcFPS(1,T_IRR));
-    anim_crash_right=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_land_right.bmp"),1,ATYPE_ONCE_END,calcFPS(1,T_IRR));
+    anim_crash_left=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_land_left.bmp"),1,BP_MD,ATYPE_ONCE_END,calcFPS(1,T_IRR));
+    anim_crash_right=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_land_right.bmp"),1,BP_MD,ATYPE_ONCE_END,calcFPS(1,T_IRR));
     anim_claw_left=loadAnimation(scenario->imgcache->loadImage(8,"Fang_Clawslash_left.png"),8);
     anim_claw_right=loadAnimation(scenario->imgcache->loadImage(8,"Fang_Clawslash_right.png"),8);
     au_hit=scenario->sndcache->loadWAV("wolfhit.wav");

Modified: trunk/src/objects/fang.h
===================================================================
--- trunk/src/objects/fang.h	2005-09-04 21:31:57 UTC (rev 145)
+++ trunk/src/objects/fang.h	2005-09-05 12:46:21 UTC (rev 146)
@@ -34,8 +34,8 @@
         virtual void clearStates(bool reset=false);
     private:
         virtual void crash(Uint16 dir=DIR_DOWN);
-        Animation* anim_claw_left;
-        Animation* anim_claw_right;
+        EmptyAnimation* anim_claw_left;
+        EmptyAnimation* anim_claw_right;
         Mix_Chunk* au_jump;
         Mix_Chunk* au_claw;
         Sint16 jump;

Modified: trunk/src/objects/olaf.cpp
===================================================================
--- trunk/src/objects/olaf.cpp	2005-09-04 21:31:57 UTC (rev 145)
+++ trunk/src/objects/olaf.cpp	2005-09-05 12:46:21 UTC (rev 146)
@@ -16,20 +16,20 @@
     anim_right=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_right.bmp"));
     anim_walk_left=loadAnimation(scenario->imgcache->loadImage(8,"olaf1-run_left.png"),8);
     anim_walk_right=loadAnimation(scenario->imgcache->loadImage(8,"olaf1-run_right.png"),8);
-    anim_crash_left=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_land_left.bmp"),1,ATYPE_ONCE_END,calcFPS(1,T_IRR));
-    anim_crash_right=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_land_right.bmp"),1,ATYPE_ONCE_END,calcFPS(1,T_IRR));
-    anim_die_bones_left=loadAnimation(scenario->imgcache->loadImage(60,0,"kuru.bmp"),12,ATYPE_ONCE_END,25);
+    anim_crash_left=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_land_left.bmp"),1,BP_MD,ATYPE_ONCE_END,calcFPS(1,T_IRR));
+    anim_crash_right=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_land_right.bmp"),1,BP_MD,ATYPE_ONCE_END,calcFPS(1,T_IRR));
+    anim_die_bones_left=loadAnimation(scenario->imgcache->loadImage(60,0,"kuru.bmp"),12,BP_MD,ATYPE_ONCE_END,25);
 
     anim_small_left=loadAnimation(scenario->imgcache->loadImage(7,"Olaf_Small_Walk_left.png"),1);
     anim_small_right=loadAnimation(scenario->imgcache->loadImage(7,"Olaf_Small_Walk_right.png"),1);
-    anim_walk_small_left=loadAnimation(scenario->imgcache->loadImage(7,"Olaf_Small_Walk_left.png"),7,ATYPE_LOOP,3.5);
-    anim_walk_small_right=loadAnimation(scenario->imgcache->loadImage(7,"Olaf_Small_Walk_right.png"),7,ATYPE_LOOP,3.5);
+    anim_walk_small_left=loadAnimation(scenario->imgcache->loadImage(7,"Olaf_Small_Walk_left.png"),7,BP_MD,ATYPE_LOOP,3.5);
+    anim_walk_small_right=loadAnimation(scenario->imgcache->loadImage(7,"Olaf_Small_Walk_right.png"),7,BP_MD,ATYPE_LOOP,3.5);
     anim_shield_left=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_fall_shield_left.bmp"));
     anim_shield_right=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_fall_shield_right.bmp"));
-    anim_walk_shield_left=NULL;
-    anim_walk_shield_right=NULL;
-    anim_fall_shield_left=NULL;
-    anim_fall_shield_right=NULL;
+    anim_walk_shield_left=new EmptyAnimation(&anim_shield_left);
+    anim_walk_shield_right=new EmptyAnimation(&anim_shield_right);
+    anim_fall_shield_left=new EmptyAnimation(&anim_shield_left);
+    anim_fall_shield_right=new EmptyAnimation(&anim_shield_right);
     au_small=scenario->sndcache->loadWAV("blob.wav");
     au_big=scenario->sndcache->loadWAV("unblob.wav");
     au_fart=scenario->sndcache->loadWAV("fart1.wav");
@@ -51,58 +51,42 @@
 void Olaf::updateAnimState() {
     if (state&STATE_SMALL) {
         if (state&STATE_LEFT) {
-            if (!setAnim(anim_walk_small_left)) {
-                if (!setAnim(anim_small_left)) setAnim(anim_left);
-            }
+            anim_small_left->setFallBack(&anim_walk_left);
+            setAnim(anim_walk_small_left);
+            anim_small_left->setFallBack(&anim_left);
         } else {
-            if (!setAnim(anim_walk_small_right)) {
-                if (!setAnim(anim_small_right)) setAnim(anim_right);
-            }
+            anim_small_right->setFallBack(&anim_walk_right);
+            setAnim(anim_walk_small_right);
+            anim_small_right->setFallBack(&anim_right);
         }
     } else if (state&STATE_SHIELD) {
         otype|=OTYPE_DENSE_D;
         if (state&STATE_LEFT) {
             if (state&STATE_FALL) {
-                if (state&STATE_MLEFT) {
-                    if (!setAnim(anim_fall_shield_left)) {
-                        if (!setAnim(anim_shield_left)) {
-                            if (!setAnim(anim_fall_left)) setAnim(anim_left);
-                        }
-                    }
-                } else if (!setAnim(anim_fall_shield_left)) {
-                    if (!setAnim(anim_fall_left)) setAnim(anim_left);
-                }
+                anim_shield_left->setFallBack(&anim_fall_left);
+                setAnim(anim_fall_shield_left);
+                anim_shield_left->setFallBack(&anim_left);
             } else {
                 if (state&STATE_MLEFT) {
-                    if (!setAnim(anim_walk_shield_left)) {
-                        if (!setAnim(anim_shield_left)) {
-                            if (!setAnim(anim_walk_left)) setAnim(anim_left);
-                        }
-                    }
+                    anim_shield_left->setFallBack(&anim_walk_left);
+                    setAnim(anim_walk_shield_left);
+                    anim_shield_left->setFallBack(&anim_left);
                 } else {
-                    if (!setAnim(anim_shield_left)) setAnim(anim_left);
+                    setAnim(anim_shield_left);
                 }
             }
         } else {
             if (state&STATE_FALL) {
-                if (state&STATE_MRIGHT) {
-                    if (!setAnim(anim_fall_shield_right)) {
-                        if (!setAnim(anim_shield_right)) {
-                            if (!setAnim(anim_fall_right)) setAnim(anim_right);
-                        }
-                    }
-                } else if (!setAnim(anim_fall_shield_right)) {
-                    if (!setAnim(anim_fall_right)) setAnim(anim_right);
-                }
+                anim_shield_right->setFallBack(&anim_fall_right);
+                setAnim(anim_fall_shield_right);
+                anim_shield_right->setFallBack(&anim_right);
             } else {
                 if (state&STATE_MRIGHT) {
-                    if (!setAnim(anim_walk_shield_right)) {
-                        if (!setAnim(anim_shield_right)) {
-                            if (!setAnim(anim_walk_right)) setAnim(anim_right);
-                        }
-                    }
+                    anim_shield_right->setFallBack(&anim_walk_right);
+                    setAnim(anim_walk_shield_right);
+                    anim_shield_right->setFallBack(&anim_right);
                 } else {
-                    if (!setAnim(anim_shield_right)) setAnim(anim_right);
+                    setAnim(anim_shield_right);
                 }
             }
         }
@@ -129,7 +113,7 @@
     //Are we already small?
     if ((small && (state&STATE_SMALL)) || ((!small) && (!(state&STATE_SMALL)))) return true;
 
-    Animation* tmpanim;
+    EmptyAnimation* tmpanim;
     SDL_Rect tmppos=pos;
     if (small) tmpanim=anim_small_left;
     //Assume both images have the same dimension

Modified: trunk/src/objects/olaf.h
===================================================================
--- trunk/src/objects/olaf.h	2005-09-04 21:31:57 UTC (rev 145)
+++ trunk/src/objects/olaf.h	2005-09-05 12:46:21 UTC (rev 146)
@@ -41,16 +41,16 @@
         /// \return True if successfull
         inline bool trySmall(bool small);
         //@{
-        Animation* anim_small_left;
-        Animation* anim_small_right;
-        Animation* anim_walk_small_left;
-        Animation* anim_walk_small_right;
-        Animation* anim_shield_left;
-        Animation* anim_shield_right;
-        Animation* anim_walk_shield_left;
-        Animation* anim_walk_shield_right;
-        Animation* anim_fall_shield_left;
-        Animation* anim_fall_shield_right;
+        EmptyAnimation* anim_small_left;
+        EmptyAnimation* anim_small_right;
+        EmptyAnimation* anim_walk_small_left;
+        EmptyAnimation* anim_walk_small_right;
+        EmptyAnimation* anim_shield_left;
+        EmptyAnimation* anim_shield_right;
+        EmptyAnimation* anim_walk_shield_left;
+        EmptyAnimation* anim_walk_shield_right;
+        EmptyAnimation* anim_fall_shield_left;
+        EmptyAnimation* anim_fall_shield_right;
         //@}
         //@{
         Mix_Chunk* au_small;

Modified: trunk/src/objects/scorch.cpp
===================================================================
--- trunk/src/objects/scorch.cpp	2005-09-04 21:31:57 UTC (rev 145)
+++ trunk/src/objects/scorch.cpp	2005-09-05 12:46:21 UTC (rev 146)
@@ -16,8 +16,8 @@
     anim_right=loadAnimation(scenario->imgcache->loadImage(1,"baleog1_right.bmp"));
     anim_walk_left=loadAnimation(scenario->imgcache->loadImage(8,"baleog1-run_left.png"),8);
     anim_walk_right=loadAnimation(scenario->imgcache->loadImage(8,"baleog1-run_right.png"),8);
-    anim_crash_left=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_land_left.bmp"),1,ATYPE_ONCE_END,calcFPS(1,T_IRR));
-    anim_crash_right=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_land_right.bmp"),1,ATYPE_ONCE_END,calcFPS(1,T_IRR));
+    anim_crash_left=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_land_left.bmp"),1,BP_MD,ATYPE_ONCE_END,calcFPS(1,T_IRR));
+    anim_crash_right=loadAnimation(scenario->imgcache->loadImage(1,"olaf1_land_right.bmp"),1,BP_MD,ATYPE_ONCE_END,calcFPS(1,T_IRR));
     au_swing=scenario->sndcache->loadWAV("flapwngs.wav");
     au_tired=scenario->sndcache->loadWAV("flwings.wav");
     au_hit=scenario->sndcache->loadWAV("draghit.wav");

Modified: trunk/src/objects/zombie.cpp
===================================================================
--- trunk/src/objects/zombie.cpp	2005-09-04 21:31:57 UTC (rev 145)
+++ trunk/src/objects/zombie.cpp	2005-09-05 12:46:21 UTC (rev 146)
@@ -15,8 +15,8 @@
   au_attack(scenario->sndcache->loadWAV("clang.wav")),
   T_Attack_Bite(1500) {
     maxspeedx=80;
-    anim_left=loadAnimation(scenario->imgcache->loadImage(2,"olaf1_left.bmp"),2,ATYPE_LOOP,2);
-    anim_right=loadAnimation(scenario->imgcache->loadImage(2,"olaf1_right.bmp"),2,ATYPE_LOOP,2);
+    anim_left=loadAnimation(scenario->imgcache->loadImage(2,"olaf1_left.bmp"),2,BP_MD,ATYPE_LOOP,2);
+    anim_right=loadAnimation(scenario->imgcache->loadImage(2,"olaf1_right.bmp"),2,BP_MD,ATYPE_LOOP,2);
     weapon=Weapon(-1,W_STRIKE);
 }
 

Modified: trunk/src/objects_common.cpp
===================================================================
--- trunk/src/objects_common.cpp	2005-09-04 21:31:57 UTC (rev 145)
+++ trunk/src/objects_common.cpp	2005-09-05 12:46:21 UTC (rev 146)
@@ -61,12 +61,10 @@
 
 Animation* Object::loadAnimation(string anim_name,
                          double scale_factor,
+                         BasePointType abp_type,
                          Uint16 aanimation_type,
                          double afps,
-                         BasePointType abp_type,
-                         AllignType aallign_type,
-                         Sint16 ashift_x,
-                         Sint16 ashift_y) {
+                         AllignType aallign_type) {
 
     /* Parse animation data file */
     ifstream file;
@@ -110,7 +108,7 @@
                     aframes=(Uint16)atoi(arg4.c_str());
 
                     if (anim_name==tmp_anim_name) {
-                        return loadAnimation(imgcache->loadImage(imagename,scale_factor),aframes,aanimation_type,afps,astart_pos,abp_type,aallign_type,ashift_x,ashift_y);
+                        return loadAnimation(imgcache->loadImage(imagename,scale_factor),aframes,abp_type,aanimation_type,afps,astart_pos,aallign_type);
                     }
                 }
             }
@@ -121,14 +119,12 @@
 
 Animation* Object::loadAnimation(const Image& abase_image,
                          Uint16 aframes,
+                         BasePointType abp_type, 
                          Uint16 aanimation_type,
                          double afps,
                          Uint16 astart_pos,
-                         BasePointType abp_type, 
-                         AllignType aallign_type,
-                         Sint16 ashift_x, 
-                         Sint16 ashift_y) {
-    Animation* anim=new Animation(abase_image,aframes,aanimation_type,afps,astart_pos,abp_type,aallign_type,ashift_x,ashift_y);
+                         AllignType aallign_type) {
+    Animation* anim=new Animation(abase_image,aframes,abp_type,aanimation_type,afps,astart_pos,aallign_type);
     anim->setBasePos(&pos);
     return anim;
 }
@@ -142,8 +138,8 @@
 bool Object::updateAnim(Uint16 dt) {
     return (animation->updateAnim(dt));
 }
-bool Object::setAnim(Animation* anim, bool start) {
-    if (anim) {
+bool Object::setAnim(EmptyAnimation* anim, bool start) {
+    if (anim && anim->isValid()) {
         animation=anim;
         if (start) {
             animation->setBasePos(&pos);
@@ -151,7 +147,7 @@
         }
         return true;
     } else {
-        animation=anim_orig;
+        if (anim==NULL) animation=anim_orig;
         return false;
     }
 }

Modified: trunk/src/objects_common.h
===================================================================
--- trunk/src/objects_common.h	2005-09-04 21:31:57 UTC (rev 145)
+++ trunk/src/objects_common.h	2005-09-05 12:46:21 UTC (rev 146)
@@ -88,7 +88,7 @@
         /// and starts it right away. Should not be used with updateAnimState,
         /// set ESTATE_ANIM to deactivate an updateAnimState. This is usually
         /// controlled by an AnimationEvent
-        bool setAnim(Animation* anim, bool start=false);
+        bool setAnim(EmptyAnimation* anim, bool start=false);
         /// Sets the animation back to the default one.
         virtual void resetAnimState();
         bool isRunning() const;
@@ -108,22 +108,18 @@
         /// Load an animation bound onto this object from an animation data file
         Animation* loadAnimation(string anim_name,
                                  double scale_factor=1,
-                                 Uint16 aanimation_type=ATYPE_LOOP,
-                                 double afps=DATA_LVLFPS,
                                  BasePointType abp_type=BP_MD,
-                                 AllignType aallign_type=AT_MD,
-                                 Sint16 ashift_x=0,
-                                 Sint16 ashift_y=0);
+                                 Uint16 aanimation_type=ATYPE_LOOP,
+                                 double afps=0,
+                                 AllignType aallign_type=AT_MD);
         /// Load an animation bound onto this object
         Animation* loadAnimation(const Image& abase_image,
                                  Uint16 aframes=1,
+                                 BasePointType abp_type=BP_MD,
                                  Uint16 aanimation_type=ATYPE_LOOP,
-                                 double afps=DATA_LVLFPS,
+                                 double afps=0,
                                  Uint16 astart_pos=0,
-                                 BasePointType abp_type=BP_MD,
-                                 AllignType aallign_type=AT_MD,
-                                 Sint16 ashift_x=0,
-                                 Sint16 ashift_y=0);
+                                 AllignType aallign_type=AT_MD);
         //Events (triggered animations/effects)
         //@{
         /// Clears the event field (sets it to NULL). This should only be used by
@@ -183,8 +179,8 @@
     protected:
         Uint32 state;
         Event* event;
-        Animation* anim_orig;
-        Animation* animation;
+        EmptyAnimation* anim_orig;
+        EmptyAnimation* animation;
         ///\todo Document this!
         /// Upper left logical position of the object (used for decisions)
         SDL_Rect pos;

Modified: trunk/src/players_common.cpp
===================================================================
--- trunk/src/players_common.cpp	2005-09-04 21:31:57 UTC (rev 145)
+++ trunk/src/players_common.cpp	2005-09-05 12:46:21 UTC (rev 146)
@@ -26,25 +26,41 @@
     state=STATE_FALL;
     otype|=OTYPE_PLAYER;
     enemy_types|=OTYPE_MONSTER;
-    anim_left=anim_right=NULL;
-    anim_rock_left=anim_rock_right=NULL;
-    anim_walk_left=anim_walk_right=NULL;
-    anim_push_left=anim_push_right=NULL;
-    anim_fall_left=anim_fall_right=NULL;
-    anim_fall_fast_left=anim_fall_fast_right=NULL;
-    anim_land_left=anim_land_right=NULL;
-    anim_crash_left=anim_crash_right=NULL;
-    anim_rope_left=anim_rope_right=NULL;
-    anim_teleport_left=anim_teleport_right=NULL;
-    anim_die_crash_left=anim_die_crash_right=NULL;
-    anim_die_burn_left=anim_die_burn_right=NULL;
-    anim_die_bones_left=anim_die_bones_right=NULL;
-    anim_die_elec_left=anim_die_elec_right=NULL;
-    anim_die_spike_left=anim_die_spike_right=NULL;
-    anim_die_water_left=anim_die_water_right=NULL;
-    anim_fall_middle=NULL;
-    anim_climb=NULL;
-    anim_bar=NULL;
+    anim_left=new EmptyAnimation(&anim_right);
+    anim_right=new EmptyAnimation();
+    anim_rock_left=new EmptyAnimation(&anim_left);
+    anim_rock_right=new EmptyAnimation(&anim_right);
+    anim_walk_left=new EmptyAnimation(&anim_left);
+    anim_walk_right=new EmptyAnimation(&anim_right);
+    anim_push_left=new EmptyAnimation(&anim_left);
+    anim_push_right=new EmptyAnimation(&anim_right);
+    anim_fall_left=new EmptyAnimation(&anim_left);
+    anim_fall_right=new EmptyAnimation(&anim_right);
+    anim_fall_fast_left=new EmptyAnimation(&anim_fall_left);
+    anim_fall_fast_right=new EmptyAnimation(&anim_fall_right);
+    anim_land_left=new EmptyAnimation();
+    anim_land_right=new EmptyAnimation();
+    anim_crash_left=new EmptyAnimation();
+    anim_crash_right=new EmptyAnimation();
+    anim_rope_left=new EmptyAnimation(&anim_left);
+    anim_rope_right=new EmptyAnimation(&anim_right);
+    anim_teleport_left=new EmptyAnimation();
+    anim_teleport_right=new EmptyAnimation();
+    anim_die_crash_left=new EmptyAnimation(&anim_die_bones_left);
+    anim_die_crash_right=new EmptyAnimation(&anim_die_bones_right);
+    anim_die_burn_left=new EmptyAnimation(&anim_die_bones_left);
+    anim_die_burn_right=new EmptyAnimation(&anim_die_bones_right);
+    anim_die_bones_left=new EmptyAnimation(&anim_die_bones_right);
+    anim_die_bones_right=new EmptyAnimation();
+    anim_die_elec_left=new EmptyAnimation(&anim_die_bones_left);
+    anim_die_elec_right=new EmptyAnimation(&anim_die_bones_right);
+    anim_die_spike_left=new EmptyAnimation(&anim_die_bones_left);
+    anim_die_spike_right=new EmptyAnimation(&anim_die_bones_right);
+    anim_die_water_left=new EmptyAnimation(&anim_die_bones_left);
+    anim_die_water_right=new EmptyAnimation(&anim_die_bones_right);
+    anim_fall_middle=new EmptyAnimation(&anim_fall_right);
+    anim_climb=new EmptyAnimation(&anim_right);
+    anim_bar=new EmptyAnimation(&anim_right);
     au_land=scenario->sndcache->loadWAV("dizzy.wav");
     au_act=scenario->sndcache->loadWAV("button.wav");
     au_useerror=scenario->sndcache->loadWAV("useerror.wav");
@@ -196,36 +212,30 @@
     if (state&STATE_LEFT) {
         if (state&STATE_FALL) {
             if (speed>V_KRIT) {
-                if (!setAnim(anim_fall_fast_left)) {
-                    if (!setAnim(anim_fall_left)) setAnim(anim_left);
-                }
+                setAnim(anim_fall_fast_left);
             } else if (state&STATE_MLEFT || speed < 0) {
-                if (!setAnim(anim_fall_left)) setAnim(anim_left);
+                setAnim(anim_fall_left);
             } else {
-                if (!setAnim(anim_fall_middle)) {
-                    if (!setAnim(anim_fall_left)) setAnim(anim_left);
-                }
+                anim_fall_middle->setFallBack(&anim_fall_left);
+                setAnim(anim_fall_middle);
             }
         } else if (state&STATE_MLEFT) {
-            if (!setAnim(anim_walk_left)) setAnim(anim_left);
+            setAnim(anim_walk_left);
         } else {
             setAnim(anim_left);
         }
     } else {
         if (state&STATE_FALL) {
             if (speed>V_KRIT) {
-                if (!setAnim(anim_fall_fast_right)) {
-                    if (!setAnim(anim_fall_right)) setAnim(anim_right);
-                }
+                setAnim(anim_fall_fast_right);
             } else if (state&STATE_MRIGHT || speed < 0) {
-                if (!setAnim(anim_fall_right)) setAnim(anim_right);
+                setAnim(anim_fall_right);
             } else {
-                if (!setAnim(anim_fall_middle)) {
-                    if (!setAnim(anim_fall_right)) setAnim(anim_right);
-                }
+                anim_fall_middle->setFallBack(&anim_fall_right);
+                setAnim(anim_fall_middle);
             }
         } else if (state&STATE_MRIGHT) {
-            if (!setAnim(anim_walk_right)) setAnim(anim_right);
+            setAnim(anim_walk_right);
         } else {
             setAnim(anim_right);
         }

Modified: trunk/src/players_common.h
===================================================================
--- trunk/src/players_common.h	2005-09-04 21:31:57 UTC (rev 145)
+++ trunk/src/players_common.h	2005-09-05 12:46:21 UTC (rev 146)
@@ -114,41 +114,41 @@
         virtual void die();
         virtual Hit move(Uint16 dt, bool check=false);
         //@{
-        Animation* anim_left;
-        Animation* anim_right;
-        Animation* anim_rock_left;
-        Animation* anim_rock_right;
-        Animation* anim_walk_left;
-        Animation* anim_walk_right;
-        Animation* anim_push_left;
-        Animation* anim_push_right;
-        Animation* anim_fall_left;
-        Animation* anim_fall_right;
-        Animation* anim_fall_fast_left;
-        Animation* anim_fall_fast_right;
-        Animation* anim_land_left;
-        Animation* anim_land_right;
-        Animation* anim_crash_left;
-        Animation* anim_crash_right;
-        Animation* anim_rope_left;
-        Animation* anim_rope_right;
-        Animation* anim_teleport_left;
-        Animation* anim_teleport_right;
-        Animation* anim_die_crash_left;
-        Animation* anim_die_crash_right;
-        Animation* anim_die_burn_left;
-        Animation* anim_die_burn_right;
-        Animation* anim_die_bones_left;
-        Animation* anim_die_bones_right;
-        Animation* anim_die_elec_left;
-        Animation* anim_die_elec_right;
-        Animation* anim_die_spike_left;
-        Animation* anim_die_spike_right;
-        Animation* anim_die_water_left;
-        Animation* anim_die_water_right;
-        Animation* anim_fall_middle;
-        Animation* anim_climb;
-        Animation* anim_bar;
+        EmptyAnimation* anim_left;
+        EmptyAnimation* anim_right;
+        EmptyAnimation* anim_rock_left;
+        EmptyAnimation* anim_rock_right;
+        EmptyAnimation* anim_walk_left;
+        EmptyAnimation* anim_walk_right;
+        EmptyAnimation* anim_push_left;
+        EmptyAnimation* anim_push_right;
+        EmptyAnimation* anim_fall_left;
+        EmptyAnimation* anim_fall_right;
+        EmptyAnimation* anim_fall_fast_left;
+        EmptyAnimation* anim_fall_fast_right;
+        EmptyAnimation* anim_land_left;
+        EmptyAnimation* anim_land_right;
+        EmptyAnimation* anim_crash_left;
+        EmptyAnimation* anim_crash_right;
+        EmptyAnimation* anim_rope_left;
+        EmptyAnimation* anim_rope_right;
+        EmptyAnimation* anim_teleport_left;
+        EmptyAnimation* anim_teleport_right;
+        EmptyAnimation* anim_die_crash_left;
+        EmptyAnimation* anim_die_crash_right;
+        EmptyAnimation* anim_die_burn_left;
+        EmptyAnimation* anim_die_burn_right;
+        EmptyAnimation* anim_die_bones_left;
+        EmptyAnimation* anim_die_bones_right;
+        EmptyAnimation* anim_die_elec_left;
+        EmptyAnimation* anim_die_elec_right;
+        EmptyAnimation* anim_die_spike_left;
+        EmptyAnimation* anim_die_spike_right;
+        EmptyAnimation* anim_die_water_left;
+        EmptyAnimation* anim_die_water_right;
+        EmptyAnimation* anim_fall_middle;
+        EmptyAnimation* anim_climb;
+        EmptyAnimation* anim_bar;
         //@}
         //@{
         Mix_Chunk*  au_hit;




More information about the lostpenguins-commits mailing list