r91 - in trunk/src: . objects

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Sun Feb 20 16:39:26 EST 2005


Author: jonas
Date: 2005-02-20 16:39:26 -0500 (Sun, 20 Feb 2005)
New Revision: 91

Added:
   trunk/src/physics.cpp
   trunk/src/physics.h
Removed:
   trunk/src/anim.cpp
   trunk/src/anim.h
Modified:
   trunk/src/Makefile
   trunk/src/characters_common.cpp
   trunk/src/common.h
   trunk/src/events.cpp
   trunk/src/events.h
   trunk/src/gfxeng.cpp
   trunk/src/input.cpp
   trunk/src/input.h
   trunk/src/lost_penguins.cpp
   trunk/src/menu.cpp
   trunk/src/monsters_common.cpp
   trunk/src/objects/baleog.cpp
   trunk/src/objects/erik.cpp
   trunk/src/objects/fang.cpp
   trunk/src/objects/olaf.cpp
   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/scenario.cpp
   trunk/src/scenario.h
Log:
Divided anim.* into animation.* and physics.*.
Renamed AnimHandler into PhysicHandler.
The name is a bit misleading (bad):
  PhysicHandler is responsible for changing (updating)
  the game state during one time period (one game loop).
  It might be used later to work as a mediator between
  objects...


Modified: trunk/src/Makefile
===================================================================
--- trunk/src/Makefile	2005-02-18 13:39:13 UTC (rev 90)
+++ trunk/src/Makefile	2005-02-20 21:39:26 UTC (rev 91)
@@ -6,10 +6,10 @@
 SDL = `sdl-config --cflags`
 SDL_LINK = `sdl-config --libs` -lSDL_mixer -lSDL_image -ldl -rdynamic
 
-OBJS  = common.o anim.o gfxeng.o input.o font.o lost_penguins.o scenario.o\
+OBJS  = common.o gfxeng.o input.o font.o lost_penguins.o scenario.o\
         objects_common.o sfxeng.o players_common.o monsters_common.o\
         characters_common.o objectpools.o weapons.o events.o imgcache.o\
-        sndcache.o menu.o
+        sndcache.o physics.o animation.o menu.o
 PLUGS = objects.a
 BIN   = ../lost_penguins
 

Deleted: trunk/src/anim.cpp
===================================================================
--- trunk/src/anim.cpp	2005-02-18 13:39:13 UTC (rev 90)
+++ trunk/src/anim.cpp	2005-02-20 21:39:26 UTC (rev 91)
@@ -1,170 +0,0 @@
-#include "common.h"
-#include "input.h"
-#include "gfxeng.h"
-#include "objectpools.h"
-#include "players_common.h"
-#include "scenario.h"
-#include "anim.h"
-
-
-Animation::Animation(SDL_Surface* anim_image, Uint16 max_num, Uint16 total_time, bool an_once):
-  size(max_num),
-  time(total_time),
-  num(0),
-  tcurrent(0),
-  once(an_once) {
-    if (time==0 || once) running=false;
-    else running=true;
-    frame.image=anim_image;
-    w=(Uint16)((frame.image->w)/size);
-    h=frame.image->h;
-    frame.pos.x=0;
-    frame.pos.y=0;
-    frame.pos.w=w;
-    frame.pos.h=h;
-}
-
-Animation::Animation(Uint16 width, SDL_Surface* anim_image, Uint16 max_num, Uint16 total_time, bool an_once):
-  size(max_num),
-  time(total_time),
-  num(0),
-  tcurrent(0),
-  once(an_once) {
-    if (time==0 || once) running=false;
-    else running=true;
-    frame.image=anim_image;
-    w=width;
-    h=frame.image->h;
-    frame.pos.x=0;
-    frame.pos.y=0;
-    frame.pos.w=w;
-    frame.pos.h=h;
-}
-
-Animation::~Animation() { }
-
-bool Animation::updateAnim(Uint16 dt) {
-    if (!running) return false;
-    tcurrent+=dt;
-    if (tcurrent < time) {
-        num=(Uint16)((tcurrent*size)/time);
-        if (num>=size) num=0;
-    } else if (once || time==0) {
-        num=size;
-        tcurrent=time;
-        running=false;
-    } else {
-        num=0;
-        tcurrent=0;
-    }
-    frame.pos.x=num*w;
-    if (running) return true;
-    else return false;
-//The solution below would be better but it won't work with the 2nd constructor
-//    frame.pos.x=(Uint16)((num*frame.image->w)/size);
-}
-
-const Frame& Animation::setFrame(Uint16 num) {
-    frame.pos.x=num*w;
-    return frame;
-}
-
-AnimHandler::AnimHandler(): 
-  tstart(SDL_GetTicks()),
-  dt(0) {
-    tcurrent=tstart;
-}
-
-AnimHandler::~AnimHandler() {
-}
-
-Uint16 AnimHandler::resetTime() {
-    dt=0;
-    return (tcurrent=SDL_GetTicks());
-}
-
-void AnimHandler::runAnims() {
-    dt=(SDL_GetTicks()-tcurrent);
-    tcurrent=SDL_GetTicks();
-
-    //Game is running normally
-    if (!paused) {
-        //released keys of player
-        if (scenario->player != NULL) {
-            if (input->getState(INPUTR_USE)) scenario->player->in_use(-1);
-            input->unsetState(INPUTR_USE);
-            if (input->getState(INPUTR_ACT)) scenario->player->in_act(-1);
-            input->unsetState(INPUTR_ACT);
-            if (input->getState(INPUTR_RIGHT)) scenario->player->in_right(-1);
-            input->unsetState(INPUTR_RIGHT);
-            if (input->getState(INPUTR_LEFT)) scenario->player->in_left(-1);
-            input->unsetState(INPUTR_LEFT);
-            if (input->getState(INPUTR_SP1)) scenario->player->in_sp1(-1);
-            input->unsetState(INPUTR_SP1);
-            if (input->getState(INPUTR_SP2)) scenario->player->in_sp2(-1);
-            input->unsetState(INPUTR_SP2);
-            if (input->getState(INPUTR_UP)) scenario->player->in_up(-1);
-            input->unsetState(INPUTR_UP);
-            if (input->getState(INPUTR_DOWN)) scenario->player->in_down(-1);
-            input->unsetState(INPUTR_DOWN);
-            input->unsetState(INPUTR_DEL);
-        }
-        object_iterator obit=scenario->pool->objectspool.begin();
-        while (obit!=scenario->pool->objectspool.end()) {
-            //remove marked objects
-            if ((*obit)->isDeleted()) {
-                obit=scenario->pool->removeObject(*obit);
-            } else ++obit;
-        }
-        obit=scenario->pool->objectspool.begin();
-        while (obit!=scenario->pool->objectspool.end()) {
-            (*obit)->idle(dt);
-            (*obit)->updateEvents(dt);
-            ++obit;
-        }
-        //handle current (new) scenario->player
-        if ((scenario->player!=NULL) && (!(scenario->player->getState(ESTATE_BUSY)))) {
-            if (input->getState(INPUT_USE)) scenario->player->in_use(dt);
-            if (input->getState(INPUT_ACT)) scenario->player->in_act(dt);
-            if (input->getState(INPUT_RIGHT)) scenario->player->in_right(dt);
-            if (input->getState(INPUT_LEFT)) scenario->player->in_left(dt);
-            if ((!(scenario->player->getState(ESTATE_RUN)))||scenario->player->getState(ESTATE_ABORT)) {
-                if (input->getState(INPUT_SP1)) scenario->player->in_sp1(dt);
-                if (input->getState(INPUT_SP2)) scenario->player->in_sp2(dt);
-            }
-            if (input->getState(INPUT_UP)) scenario->player->in_up(dt);
-            if (input->getState(INPUT_DOWN)) scenario->player->in_down(dt);
-        }
-        //run end scenario->player effects
-        character_iterator cit=scenario->pool->characterspool.begin();
-        while (cit!=scenario->pool->characterspool.end()) {
-            (*cit)->fall(dt);
-            (*cit)->updateAnimState(!((*cit)->getState(ESTATE_ANIM)));
-            ++cit;
-        }
-        //update the animations of all objects
-        obit=scenario->pool->objectspool.begin();
-        while (obit!=scenario->pool->objectspool.end()) {
-            if ((*obit)->getState(ESTATE_ANIM)) { 
-                bool runs=(*obit)->updateAnim(dt);
-                if (!runs) (*obit)->stopEvent();
-            } else if ((*obit)->isRunning()) (*obit)->updateAnim(dt);
-            ++obit;
-        }
-    //Game is paused
-    } else {
-        if (input->getState(INPUT_RIGHT)) {
-            input->unsetState(INPUT_RIGHT);
-            scenario->player->switchItem(true);
-        }
-        if (input->getState(INPUT_LEFT)) {
-            input->unsetState(INPUT_LEFT);
-            scenario->player->switchItem(false);
-        }
-        if (input->getState(INPUT_DEL)) {
-            input->unsetState(INPUT_DEL);
-            scenario->player->dropItem();
-            gfxeng->renderScene(true);
-        }
-    }
-}

Deleted: trunk/src/anim.h
===================================================================
--- trunk/src/anim.h	2005-02-18 13:39:13 UTC (rev 90)
+++ trunk/src/anim.h	2005-02-20 21:39:26 UTC (rev 91)
@@ -1,92 +0,0 @@
-#ifndef _ANIM_H
-#define _ANIM_H 1
-
-/** \brief A container for frames.
-
-    Animation format: a horizontal strip (image) with (num) frames
-    \todo Change this to an offset matrix or something similar or give each row a different animation
-*/
-class Animation {
-    public:
-        /// \brief Initialize the animation
-        /// \param image Image used for the animation
-        /// \param max_num Number of frames (will devide the image horizontally accordingly)
-        /// \param total_time Duration of the animation, if set to 0 assume it's one still image
-        /// \param once If true it run the animation only once when called by \fn start()
-        Animation(SDL_Surface* image, Uint16 max_num=1, Uint16 total_time=0, bool once=false);
-        /// \brief Initialize the animation
-        /// \param width Image width used from the left side
-        /// \param image Image used for the animation
-        /// \param max_num Number of frames (will devide the image horizontally accordingly)
-        /// \param total_time Duration of the animation, if set to 0 assume it's one still image
-        /// \param once If true: Run the animation only once when called by \fn start()
-        Animation(Uint16 width, SDL_Surface* image, Uint16 max_num=1, Uint16 total_time=0, bool once=false);
-        ~Animation();
-        /// Updates a running animation and stops it if necessary
-        /// return True if the animation is still running
-        /// \todo This should be more advanced
-        bool updateAnim(Uint16 dt);
-        /// Updates the frame status of a frame series (usually when not running)
-        /// return Current frame
-        const Frame& setFrame(Uint16 nr);
-        /// Starts an (usually non running) animation
-        void start() {
-            num=0;
-            tcurrent=0;
-            running=true;
-        }
-        const Frame& getFrame() const {
-            return frame;
-        }
-        Frame getFrame(Uint16 nr) const {
-            Frame newframe=frame;
-            newframe.pos.x=nr*w;
-            return newframe;
-        }
-        Uint16 getWidth() const {
-            return w;
-        }
-        Uint16 getHeight() const {
-            return h;
-        }
-        /// return True if the animation is running
-        bool isRunning() const {
-            return running;
-        }
-    private:
-        /// Frame pointer
-        Frame frame;
-        /// Number of frames
-        Uint16 size;
-        /// Total time (in ms)
-        Uint16 time;
-        /// Frame size
-        Uint16 w;
-        Uint16 h;
-        /// Current frame number
-        Uint16 num;
-        /// Current time position (in ms)
-        Uint16 tcurrent;
-        /// frame series or running?
-        bool running;
-        /// play the animation only once?
-        bool once;
-};
-
-/** \brief Updates all game states and animations
-
-*/
-class AnimHandler {
-    public:
-        AnimHandler();
-        ~AnimHandler();
-        /// Updates all game states and animations
-        void runAnims();
-        /// Resets the current time
-        /// \return New current time
-        Uint16 resetTime();
-    private:
-        Uint16 tstart, tcurrent, dt;
-};
-
-#endif

Modified: trunk/src/characters_common.cpp
===================================================================
--- trunk/src/characters_common.cpp	2005-02-18 13:39:13 UTC (rev 90)
+++ trunk/src/characters_common.cpp	2005-02-20 21:39:26 UTC (rev 91)
@@ -1,5 +1,5 @@
 #include "common.h"
-#include "anim.h"
+#include "animation.h"
 #include "events.h"
 #include "scenario.h"
 #include "weapons.h"

Modified: trunk/src/common.h
===================================================================
--- trunk/src/common.h	2005-02-18 13:39:13 UTC (rev 90)
+++ trunk/src/common.h	2005-02-20 21:39:26 UTC (rev 91)
@@ -35,7 +35,7 @@
 class Background;
 class Scenario;
 class InputHandler;
-class AnimHandler;
+class PhysicHandler;
 class Font;
 class Event;
 class Weapon;

Modified: trunk/src/events.cpp
===================================================================
--- trunk/src/events.cpp	2005-02-18 13:39:13 UTC (rev 90)
+++ trunk/src/events.cpp	2005-02-20 21:39:26 UTC (rev 91)
@@ -1,6 +1,6 @@
 #include "common.h"
 #include "events.h"
-#include "anim.h"
+#include "animation.h"
 #include "weapons.h"
 #include "scenario.h"
 #include "sfxeng.h"

Modified: trunk/src/events.h
===================================================================
--- trunk/src/events.h	2005-02-18 13:39:13 UTC (rev 90)
+++ trunk/src/events.h	2005-02-20 21:39:26 UTC (rev 91)
@@ -9,7 +9,7 @@
 
 /** \brief Base class for events (non instantanious effects)
 
-    Organize effects that aren't instantanious. Updated by AnimHandler, usually
+    Organize effects that aren't instantanious. Updated by PhysicHandler, usually
     a member of an Object (controlled by the object). An effect can be delayed and has a
     certain run period (marked by a state).
 */

Modified: trunk/src/gfxeng.cpp
===================================================================
--- trunk/src/gfxeng.cpp	2005-02-18 13:39:13 UTC (rev 90)
+++ trunk/src/gfxeng.cpp	2005-02-20 21:39:26 UTC (rev 91)
@@ -1,6 +1,6 @@
 #include "common.h"
 #include "font.h"
-#include "anim.h"
+#include "animation.h"
 #include "objectpools.h"
 #include "players_common.h"
 #include "imgcache.h"

Modified: trunk/src/input.cpp
===================================================================
--- trunk/src/input.cpp	2005-02-18 13:39:13 UTC (rev 90)
+++ trunk/src/input.cpp	2005-02-20 21:39:26 UTC (rev 91)
@@ -1,6 +1,5 @@
 #include "common.h"
 #include "events.h"
-#include "anim.h"
 #include "input.h"
 #include "sndcache.h"
 #include "gfxeng.h"
@@ -8,6 +7,7 @@
 #include "scenario.h"
 #include "objectpools.h"
 #include "menu.h"
+#include "physics.h"
 #include "objects_common.h"
 
 
@@ -158,7 +158,7 @@
                              state|=INPUT_MENU;
                              if (!closeMenu()) {
                                  gfxeng->renderScene(true);
-                                 scenario->anim->resetTime();
+                                 scenario->physic->resetTime();
                                  sfxeng->resumeMusic();
                              }
                          } else {
@@ -318,7 +318,7 @@
                          } else if (paused) {
                              state|=INPUT_PAUSE;
                              paused=false;
-                             scenario->anim->resetTime();
+                             scenario->physic->resetTime();
                              sfxeng->resumeMusic();
                          } else {
                              state|=INPUT_PAUSE;
@@ -335,7 +335,7 @@
                              state|=INPUT_MENU;
                              if (!closeMenu()) {
                                  gfxeng->renderScene(true);
-                                 scenario->anim->resetTime();
+                                 scenario->physic->resetTime();
                                  sfxeng->resumeMusic();
                              }
                          } else {

Modified: trunk/src/input.h
===================================================================
--- trunk/src/input.h	2005-02-18 13:39:13 UTC (rev 90)
+++ trunk/src/input.h	2005-02-20 21:39:26 UTC (rev 91)
@@ -25,7 +25,7 @@
 
 /** \brief Handels keyboard events
 
-    \remark A key release event which is passed on to the AnimHandler
+    \remark A key release event which is passed on to the PhysicHandler
       mustn't be cummulative (see player code as well). Ie. If the event
       is triggered twice it should do the same as if once... 
 */

Modified: trunk/src/lost_penguins.cpp
===================================================================
--- trunk/src/lost_penguins.cpp	2005-02-18 13:39:13 UTC (rev 90)
+++ trunk/src/lost_penguins.cpp	2005-02-20 21:39:26 UTC (rev 91)
@@ -1,6 +1,6 @@
 #include "common.h"
 #include "events.h"
-#include "anim.h"
+#include "physics.h"
 #include "input.h"
 #include "font.h"
 #include "scenario.h"
@@ -63,7 +63,7 @@
             //Check input
             input->pollEvents();
             //Run Animations
-            scenario->anim->runAnims();
+            scenario->physic->update();
         } else {
             quitGame(-6);
         }

Modified: trunk/src/menu.cpp
===================================================================
--- trunk/src/menu.cpp	2005-02-18 13:39:13 UTC (rev 90)
+++ trunk/src/menu.cpp	2005-02-20 21:39:26 UTC (rev 91)
@@ -1,6 +1,6 @@
 #include "common.h"
 #include "scenario.h"
-#include "anim.h"
+#include "physics.h"
 #include "gfxeng.h"
 #include "sfxeng.h"
 #include "menu.h"
@@ -75,7 +75,7 @@
     case 0: {
         if (!closeMenu()) {
             gfxeng->renderScene(true);
-            scenario->anim->resetTime();
+            scenario->physic->resetTime();
             sfxeng->resumeMusic();
         }
         break;

Modified: trunk/src/monsters_common.cpp
===================================================================
--- trunk/src/monsters_common.cpp	2005-02-18 13:39:13 UTC (rev 90)
+++ trunk/src/monsters_common.cpp	2005-02-20 21:39:26 UTC (rev 91)
@@ -1,5 +1,5 @@
 #include "common.h"
-#include "anim.h"
+#include "animation.h"
 #include "weapons.h"
 #include "events.h"
 #include "sfxeng.h"

Modified: trunk/src/objects/baleog.cpp
===================================================================
--- trunk/src/objects/baleog.cpp	2005-02-18 13:39:13 UTC (rev 90)
+++ trunk/src/objects/baleog.cpp	2005-02-20 21:39:26 UTC (rev 91)
@@ -1,6 +1,6 @@
 #include "common.h"
 #include "events.h"
-#include "anim.h"
+#include "animation.h"
 #include "imgcache.h"
 #include "sndcache.h"
 #include "input.h"

Modified: trunk/src/objects/erik.cpp
===================================================================
--- trunk/src/objects/erik.cpp	2005-02-18 13:39:13 UTC (rev 90)
+++ trunk/src/objects/erik.cpp	2005-02-20 21:39:26 UTC (rev 91)
@@ -1,6 +1,6 @@
 #include "common.h"
 #include "events.h"
-#include "anim.h"
+#include "animation.h"
 #include "input.h"
 #include "scenario.h"
 #include "weapons.h"

Modified: trunk/src/objects/fang.cpp
===================================================================
--- trunk/src/objects/fang.cpp	2005-02-18 13:39:13 UTC (rev 90)
+++ trunk/src/objects/fang.cpp	2005-02-20 21:39:26 UTC (rev 91)
@@ -1,6 +1,6 @@
 #include "common.h"
 #include "events.h"
-#include "anim.h"
+#include "animation.h"
 #include "input.h"
 #include "imgcache.h"
 #include "sndcache.h"

Modified: trunk/src/objects/olaf.cpp
===================================================================
--- trunk/src/objects/olaf.cpp	2005-02-18 13:39:13 UTC (rev 90)
+++ trunk/src/objects/olaf.cpp	2005-02-20 21:39:26 UTC (rev 91)
@@ -1,6 +1,6 @@
 #include "common.h"
 #include "events.h"
-#include "anim.h"
+#include "animation.h"
 #include "input.h"
 #include "imgcache.h"
 #include "sndcache.h"

Modified: trunk/src/objects/scorch.cpp
===================================================================
--- trunk/src/objects/scorch.cpp	2005-02-18 13:39:13 UTC (rev 90)
+++ trunk/src/objects/scorch.cpp	2005-02-20 21:39:26 UTC (rev 91)
@@ -1,6 +1,6 @@
 #include "common.h"
 #include "events.h"
-#include "anim.h"
+#include "animation.h"
 #include "input.h"
 #include "imgcache.h"
 #include "scenario.h"

Modified: trunk/src/objects/zombie.cpp
===================================================================
--- trunk/src/objects/zombie.cpp	2005-02-18 13:39:13 UTC (rev 90)
+++ trunk/src/objects/zombie.cpp	2005-02-20 21:39:26 UTC (rev 91)
@@ -1,6 +1,6 @@
 #include "common.h"
 #include "events.h"
-#include "anim.h"
+#include "animation.h"
 #include "weapons.h"
 #include "imgcache.h"
 #include "sndcache.h"

Modified: trunk/src/objects_common.cpp
===================================================================
--- trunk/src/objects_common.cpp	2005-02-18 13:39:13 UTC (rev 90)
+++ trunk/src/objects_common.cpp	2005-02-20 21:39:26 UTC (rev 91)
@@ -1,6 +1,6 @@
 #include "common.h"
 #include "imgcache.h"
-#include "anim.h"
+#include "animation.h"
 #include "events.h"
 #include "objects_common.h"
 //HACK!

Modified: trunk/src/objects_common.h
===================================================================
--- trunk/src/objects_common.h	2005-02-18 13:39:13 UTC (rev 90)
+++ trunk/src/objects_common.h	2005-02-20 21:39:26 UTC (rev 91)
@@ -118,7 +118,7 @@
         /// Schedules a new event and cancels any currently running event
         /// \param ev New event
         virtual void setEvent(Event* ev);
-        /// Updates the event (run by the AnimHandler) and react on the new event
+        /// Updates the event (run by the PhysicHandler) and react on the new event
         /// state (start, end or cancel an event).
         /// \return New event state
         Uint16 updateEvents(Uint16 dt);

Copied: trunk/src/physics.cpp (from rev 90, trunk/src/anim.cpp)
===================================================================
--- trunk/src/anim.cpp	2005-02-18 13:39:13 UTC (rev 90)
+++ trunk/src/physics.cpp	2005-02-20 21:39:26 UTC (rev 91)
@@ -0,0 +1,108 @@
+#include "common.h"
+#include "input.h"
+#include "gfxeng.h"
+#include "objectpools.h"
+#include "players_common.h"
+#include "scenario.h"
+#include "physics.h"
+
+
+PhysicHandler::PhysicHandler(): 
+  tstart(SDL_GetTicks()),
+  dt(0) {
+    tcurrent=tstart;
+}
+
+PhysicHandler::~PhysicHandler() {
+}
+
+Uint16 PhysicHandler::resetTime() {
+    dt=0;
+    return (tcurrent=SDL_GetTicks());
+}
+
+void PhysicHandler::update() {
+    dt=(SDL_GetTicks()-tcurrent);
+    tcurrent=SDL_GetTicks();
+
+    //Game is running normally
+    if (!paused) {
+        //released keys of player
+        if (scenario->player != NULL) {
+            if (input->getState(INPUTR_USE)) scenario->player->in_use(-1);
+            input->unsetState(INPUTR_USE);
+            if (input->getState(INPUTR_ACT)) scenario->player->in_act(-1);
+            input->unsetState(INPUTR_ACT);
+            if (input->getState(INPUTR_RIGHT)) scenario->player->in_right(-1);
+            input->unsetState(INPUTR_RIGHT);
+            if (input->getState(INPUTR_LEFT)) scenario->player->in_left(-1);
+            input->unsetState(INPUTR_LEFT);
+            if (input->getState(INPUTR_SP1)) scenario->player->in_sp1(-1);
+            input->unsetState(INPUTR_SP1);
+            if (input->getState(INPUTR_SP2)) scenario->player->in_sp2(-1);
+            input->unsetState(INPUTR_SP2);
+            if (input->getState(INPUTR_UP)) scenario->player->in_up(-1);
+            input->unsetState(INPUTR_UP);
+            if (input->getState(INPUTR_DOWN)) scenario->player->in_down(-1);
+            input->unsetState(INPUTR_DOWN);
+            input->unsetState(INPUTR_DEL);
+        }
+        object_iterator obit=scenario->pool->objectspool.begin();
+        while (obit!=scenario->pool->objectspool.end()) {
+            //remove marked objects
+            if ((*obit)->isDeleted()) {
+                obit=scenario->pool->removeObject(*obit);
+            } else ++obit;
+        }
+        obit=scenario->pool->objectspool.begin();
+        while (obit!=scenario->pool->objectspool.end()) {
+            (*obit)->idle(dt);
+            (*obit)->updateEvents(dt);
+            ++obit;
+        }
+        //handle current (new) scenario->player
+        if ((scenario->player!=NULL) && (!(scenario->player->getState(ESTATE_BUSY)))) {
+            if (input->getState(INPUT_USE)) scenario->player->in_use(dt);
+            if (input->getState(INPUT_ACT)) scenario->player->in_act(dt);
+            if (input->getState(INPUT_RIGHT)) scenario->player->in_right(dt);
+            if (input->getState(INPUT_LEFT)) scenario->player->in_left(dt);
+            if ((!(scenario->player->getState(ESTATE_RUN)))||scenario->player->getState(ESTATE_ABORT)) {
+                if (input->getState(INPUT_SP1)) scenario->player->in_sp1(dt);
+                if (input->getState(INPUT_SP2)) scenario->player->in_sp2(dt);
+            }
+            if (input->getState(INPUT_UP)) scenario->player->in_up(dt);
+            if (input->getState(INPUT_DOWN)) scenario->player->in_down(dt);
+        }
+        //run end scenario->player effects
+        character_iterator cit=scenario->pool->characterspool.begin();
+        while (cit!=scenario->pool->characterspool.end()) {
+            (*cit)->fall(dt);
+            (*cit)->updateAnimState(!((*cit)->getState(ESTATE_ANIM)));
+            ++cit;
+        }
+        //update the animations of all objects
+        obit=scenario->pool->objectspool.begin();
+        while (obit!=scenario->pool->objectspool.end()) {
+            if ((*obit)->getState(ESTATE_ANIM)) { 
+                bool runs=(*obit)->updateAnim(dt);
+                if (!runs) (*obit)->stopEvent();
+            } else if ((*obit)->isRunning()) (*obit)->updateAnim(dt);
+            ++obit;
+        }
+    //Game is paused
+    } else {
+        if (input->getState(INPUT_RIGHT)) {
+            input->unsetState(INPUT_RIGHT);
+            scenario->player->switchItem(true);
+        }
+        if (input->getState(INPUT_LEFT)) {
+            input->unsetState(INPUT_LEFT);
+            scenario->player->switchItem(false);
+        }
+        if (input->getState(INPUT_DEL)) {
+            input->unsetState(INPUT_DEL);
+            scenario->player->dropItem();
+            gfxeng->renderScene(true);
+        }
+    }
+}

Copied: trunk/src/physics.h (from rev 90, trunk/src/anim.h)
===================================================================
--- trunk/src/anim.h	2005-02-18 13:39:13 UTC (rev 90)
+++ trunk/src/physics.h	2005-02-20 21:39:26 UTC (rev 91)
@@ -0,0 +1,20 @@
+#ifndef _PHYSICS_H  
+#define _PHYSICS_H 1
+
+/** \brief Updates all game states and animations, acts as a Mediator between objects
+
+*/
+class PhysicHandler  {
+    public:
+        PhysicHandler();
+        ~PhysicHandler();
+        /// Updates all game states and animations
+        void update();
+        /// Resets the current time
+        /// \return New current time
+        Uint16 resetTime();
+    private:
+        Uint16 tstart, tcurrent, dt;
+};
+
+#endif

Modified: trunk/src/players_common.cpp
===================================================================
--- trunk/src/players_common.cpp	2005-02-18 13:39:13 UTC (rev 90)
+++ trunk/src/players_common.cpp	2005-02-20 21:39:26 UTC (rev 91)
@@ -1,7 +1,7 @@
 #include "common.h"
 #include "events.h"
 #include "input.h"
-#include "anim.h"
+#include "animation.h"
 #include "weapons.h"
 #include "sfxeng.h"
 #include "imgcache.h"

Modified: trunk/src/scenario.cpp
===================================================================
--- trunk/src/scenario.cpp	2005-02-18 13:39:13 UTC (rev 90)
+++ trunk/src/scenario.cpp	2005-02-20 21:39:26 UTC (rev 91)
@@ -3,7 +3,7 @@
 #include "players_common.h"
 #include "imgcache.h"
 #include "sndcache.h"
-#include "anim.h"
+#include "physics.h"
 #include "scenario.h"
 
 
@@ -17,8 +17,8 @@
     imgcache=new ImageCache();
     cout << "Scenario: SoundCache...\n";
     sndcache=new SoundCache();
-    cout << "Scenario: AnimHandler...\n"; 
-    anim=new AnimHandler();
+    cout << "Scenario: PhysicHandler...\n"; 
+    physic=new PhysicHandler();
     cout << "Map: ObjectsPool...\n";
     pool=new ObjectsPool();
 }
@@ -29,8 +29,8 @@
     cout << "Map: Deleted Pools...\n";
     if (background) delete background;
     cout << "Map: Deleted Background...\n";
-    delete anim;
-    cout << "Scenario: Deleted Animhandler...\n";
+    delete physic;
+    cout << "Scenario: Deleted PhysicHandler...\n";
     delete sndcache;
     cout << "Scenario: Deleted SoundCache...\n";
     delete imgcache;
@@ -43,8 +43,8 @@
         pool=new ObjectsPool();
     } else if (!pool) pool=new ObjectsPool();
     if (background) delete background;
-    if (anim) delete anim;
-    anim=new AnimHandler();
+    if (physic) delete physic;
+    physic=new PhysicHandler();
     background=NULL;
     area=NULL;
     player=NULL;

Modified: trunk/src/scenario.h
===================================================================
--- trunk/src/scenario.h	2005-02-18 13:39:13 UTC (rev 90)
+++ trunk/src/scenario.h	2005-02-20 21:39:26 UTC (rev 91)
@@ -59,16 +59,16 @@
         SoundCache* sndcache;
         /// Object pool
         ObjectsPool* pool;
-        /// Animation Handler
-        AnimHandler* anim;
-        /// True if the mission failed
-        bool failed;
+        /// Physic Handler
+        PhysicHandler* physic;
         ///\brief Loads and initializes the map data
         ///
         /// Parses the map file and tries to add the objects by using addObjectByName()
         /// \param mapname Map file name without the data directory in it
         /// \return 0 if a Background was found, -1 if not, -2 if the loading failed
         int loadMap(string mapname);
+        /// True if the mission failed
+        bool failed;
         /// Name of the map file
         string name;
     private:




More information about the lostpenguins-commits mailing list