r94 - in trunk/src: . objects

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Wed Feb 23 07:47:08 EST 2005


Author: jonas
Date: 2005-02-23 07:47:07 -0500 (Wed, 23 Feb 2005)
New Revision: 94

Modified:
   trunk/src/common.cpp
   trunk/src/common.h
   trunk/src/gfxeng.cpp
   trunk/src/gfxeng.h
   trunk/src/input.cpp
   trunk/src/input.h
   trunk/src/lost_penguins.cpp
   trunk/src/menu.cpp
   trunk/src/objects/baleog.cpp
   trunk/src/objects/baleog.h
   trunk/src/objects/erik.cpp
   trunk/src/objects/erik.h
   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/scorch.h
   trunk/src/physics.cpp
   trunk/src/physics.h
   trunk/src/players_common.cpp
   trunk/src/players_common.h
Log:
MAJOR INTERNAL UPDATE:
----------------------

Common updates:
  - Moved menu changes from common.cpp to menu.cpp
  - Introduced an enumerated ConfigKey list, see below
  - Simpler game loop, logic moved back to the individual handlers, see below

Object (Player) updates:
  - Changed player objects according to the changes to the Input/PhysicHandler,
    see below
  - idle is now responsible for updating player specific states/events
  - Menus now handle more by themself (they call the update the gfxeng if they
    are changed, etc)

Rewrite of the InputHandler:
  - Removed all input states
  - Introduced the arrays keystate (which keys are currently pressed)
    and keypressed (which keys were just pressed as an event in this loop)
  - Key bindings can be done in Config (keybind) using an enumerated list
    ConfigKey, example: config.keybind[KEY_SP1]=SDLK_LCTRL
  - ?\208?\134nputHandler is now simply called by update() which then chooses the right
    poll function (depending on game state) to update the key arrays.

Big change to the PhysicHandler (as the InputHandler changed):
  - PhysicHandler is now simply called by update() which then chooses the right
    Handler function (depending on game state) to update the game state.
  - No more key release events are passed to the objects
  - in_act,in_use,in_sp1,in_sp2 are just called if a key was pressed as an
    event, the virtual functions are all changed accordingly...
  - The only events that are catched and passed to the current player are:
    key press events, updates on left/right/up/down
  - The objects are responsible for updating their state in idle, querying
    the InputHandler
  - PhysicHandler now manages the FPS code, introduced minimal FPS

Big change to the GraphicsEngine:
  - GraphicsEngine is now simply called by draw() which then chooses the
    right draw function (depending on game state) to update the screen.
  - GraphicsEngine just draws as much as necessary (depending on game state).
    update(UpdateState) can be used to query for specific screen updates.
  - The background logic/functions is/are much simpler
  - Removed the fps handling code (see PhysicHandler)
  


Modified: trunk/src/common.cpp
===================================================================
--- trunk/src/common.cpp	2005-02-22 13:51:28 UTC (rev 93)
+++ trunk/src/common.cpp	2005-02-23 12:47:07 UTC (rev 94)
@@ -24,24 +24,3 @@
     if (a>=0) return a=max(0,a+b);
     else return a=min(0,a-b);
 }
-
-Menu* setMenu(Menu* newmenu) {
-    newmenu->setLast(menu);
-    return menu=newmenu;
-}
-
-Menu* closeMenu() {
-    if (menu) {
-        Menu* tmp=menu->getLast();
-        delete menu;
-        return menu=tmp;
-    } else {
-        return NULL;
-    }
-}
-
-void closeMenus() {
-    while (menu) {
-        closeMenu();
-    }
-}

Modified: trunk/src/common.h
===================================================================
--- trunk/src/common.h	2005-02-22 13:51:28 UTC (rev 93)
+++ trunk/src/common.h	2005-02-23 12:47:07 UTC (rev 94)
@@ -61,6 +61,26 @@
 #define DIR_DWL         0x0000000A
 #define DIR_LR          0x00000003
 
+enum ConfigKey {
+    KEY_START,
+    KEY_LEFT,
+    KEY_RIGHT,
+    KEY_UP,
+    KEY_DOWN,
+    KEY_SP1,
+    KEY_SP2,
+    KEY_ACT,
+    KEY_USE,
+    KEY_DROP,
+    KEY_SWITCH,
+    KEY_PAUSE,
+    KEY_MENU,
+    KEY_FPS,
+    KEY_BAR,
+    KEY_FULL,
+    KEY_QUIT
+};
+
 /**\brief Collision type
 
 */
@@ -82,6 +102,7 @@
     int audio_channels;
     string datadir;
     string map;
+    SDLKey keybind[30];
 };
 
 /**\brief Frame format

Modified: trunk/src/gfxeng.cpp
===================================================================
--- trunk/src/gfxeng.cpp	2005-02-22 13:51:28 UTC (rev 93)
+++ trunk/src/gfxeng.cpp	2005-02-23 12:47:07 UTC (rev 94)
@@ -6,17 +6,15 @@
 #include "imgcache.h"
 #include "scenario.h"
 #include "menu.h"
+//Only needed for fps
+#include "scenario.h"
+#include "physics.h"
 #include "gfxeng.h"
 
 
 GraphicsEngine::GraphicsEngine():
   screen(NULL),
   menubg(NULL),
-  Dfps(0),
-  Dframes(0),
-  currentfps(0),
-  tcurrent(SDL_GetTicks()),
-  menu_done(false),
   show_bar(true),
   show_fps(true),
   fullscreen(config.full) {
@@ -41,6 +39,53 @@
     SDL_FreeSurface(screen);
 }
 
+void GraphicsEngine::update(Uint8 upd) {
+    if (updatetype==UPDATE_ALL) return;
+    else updatetype=upd;
+}
+
+void GraphicsEngine::draw() {
+    //Menu
+    if (menu) {
+        //Assure we have a (correct) menu background
+        if (!menubg) {
+            if (running) {
+                setGameMenuBG();
+            } else {
+                setMenuBG();
+            }
+        }
+        if (updatetype==UPDATE_ALL) {
+            if (running) {
+                setGameMenuBG();
+                drawMenu();
+            } else {
+                setMenuBG();
+                drawMenu();
+            }
+        } else if (updatetype==UPDATE_MENU) {
+            drawMenu();
+        }
+    //Paused game
+    } else if (paused) {
+        if (updatetype==UPDATE_ALL) {
+            drawScene();
+            drawPlayerBar();
+        } else if (updatetype==UPDATE_BAR) {
+            drawPlayerBar();
+        }
+    //Not paused running game
+    } else if (running) {
+        drawScene();
+        drawPlayerBar();
+        drawFPS();
+        updatetype=UPDATE_ALL;
+    } else return;
+    //This is the most time consuming operation
+    if (updatetype!=UPDATE_NOTHING) SDL_Flip(screen);
+    updatetype=UPDATE_NOTHING;
+}
+
 void GraphicsEngine::resize(Uint16 width, Uint16 height) {
     if (screen) SDL_FreeSurface(screen);
     
@@ -59,6 +104,7 @@
     vis_map.y=0;
     vis_map.w=screen->w;
     vis_map.h=screen->h-bar.h;
+    update(UPDATE_ALL);
 }
 
 inline SDL_Rect GraphicsEngine::clipToBG(SDL_Rect dest) const {
@@ -92,7 +138,43 @@
     return shift;    
 }
 
-inline void GraphicsEngine::drawPlayerBar() {
+void GraphicsEngine::drawScene() {
+    if (!running) return;
+
+    //We don't want to change pos!
+    SDL_Rect tmprect,shift,srcpos;
+    if (scenario->player!=NULL) {
+        shift=setShift(scenario->player->getCenter());
+    } else {
+        shift.x=0;
+        shift.y=0;
+    }
+
+    tmprect=*scenario->area;
+    srcpos=scenario->background->getFrame().pos;
+    shiftMapArea(tmprect,*scenario->background->getCurPos());
+    SDL_BlitSurface(scenario->background->getFrame().image,&srcpos,screen,shiftMapArea(tmprect,shift));
+    
+    object_iterator obit=scenario->pool->objectspool.begin();
+    while (obit!=scenario->pool->objectspool.end()) {
+        tmprect=*((*obit)->getPos());
+        srcpos=(*obit)->getFrame().pos;
+        shiftMapArea(tmprect,*((*obit)->getCurPos()));
+        SDL_BlitSurface((*obit)->getFrame().image,&srcpos,screen,shiftMapArea(tmprect,shift));
+        ++obit;
+    }
+
+    if (scenario->player!=NULL) {
+        tmprect=*(scenario->player->getPos());
+        srcpos=scenario->player->getFrame().pos;
+        shiftMapArea(tmprect,*(scenario->player->getCurPos()));
+        SDL_BlitSurface(scenario->player->getFrame().image,&srcpos,screen,shiftMapArea(tmprect,shift));
+    }
+}
+
+//TODO don't draw the whole screen, just till bar, just upgrade certain regions of the bar
+void GraphicsEngine::drawPlayerBar() {
+    if (!show_bar) return;
     //#players
     Uint8 pnum=scenario->pool->playerspool.size();
     //temporary dest pos, source pos, copy of dest pos
@@ -163,54 +245,9 @@
     }
 }
 
-void GraphicsEngine::renderScene(bool insist) {
-    resetMenuBG();
-    if (scenario->background && (!paused || insist)) {
-        //We don't want to change pos!
-        SDL_Rect tmprect,shift,srcpos;
-        if (scenario->player!=NULL) {
-            shift=setShift(scenario->player->getCenter());
-        } else {
-            shift.x=0;
-            shift.y=0;
-        }
-    
-        tmprect=*scenario->area;
-        srcpos=scenario->background->getFrame().pos;
-        shiftMapArea(tmprect,*scenario->background->getCurPos());
-        SDL_BlitSurface(scenario->background->getFrame().image,&srcpos,screen,shiftMapArea(tmprect,shift));
-        
-        object_iterator obit=scenario->pool->objectspool.begin();
-        while (obit!=scenario->pool->objectspool.end()) {
-            tmprect=*((*obit)->getPos());
-            srcpos=(*obit)->getFrame().pos;
-            shiftMapArea(tmprect,*((*obit)->getCurPos()));
-            SDL_BlitSurface((*obit)->getFrame().image,&srcpos,screen,shiftMapArea(tmprect,shift));
-            ++obit;
-        }
-    
-        if (scenario->player!=NULL) {
-            tmprect=*(scenario->player->getPos());
-            srcpos=scenario->player->getFrame().pos;
-            shiftMapArea(tmprect,*(scenario->player->getCurPos()));
-            SDL_BlitSurface(scenario->player->getFrame().image,&srcpos,screen,shiftMapArea(tmprect,shift));
-        }
-    }
-    
-    //TODO don't draw the whole screen, just till bar, just upgrade certain regions of the bar
-    if (show_bar) drawPlayerBar();
-    if (show_fps) {
-        Dfps+=(SDL_GetTicks()-tcurrent);
-        tcurrent=SDL_GetTicks();
-        ++Dframes;
-        if (Dfps>=100) {
-            currentfps=Uint16(Dframes*1000/Dfps);
-            Dfps=0;
-            Dframes=0;
-        }
-        font->write(screen,"FPS: " + itos(currentfps),screen->w-150,0);
-    }
-    SDL_Flip(screen);
+void GraphicsEngine::drawFPS() {
+    if (!show_fps) return;
+    font->write(screen,"FPS: " + itos(scenario->physic->getFPS()) + " [" + itos(scenario->physic->getMinFPS()) + "]",screen->w-170,0);
 }
 
 void GraphicsEngine::togglePlayerBar() {
@@ -250,57 +287,53 @@
 }
 
 void GraphicsEngine::drawMenu() {
-    if (!menu_done) {
-        menu_done=true;
-        //Semitransparent background
-        setGameMenuBG();
-        SDL_BlitSurface(menubg,NULL,screen,NULL);
+    if (menubg) SDL_BlitSurface(menubg,NULL,screen,NULL);
 
-        menu->font_title->writeCenter(screen,menu->title,0);
+    menu->font_title->writeCenter(screen,menu->title,0);
 
-        Uint16 h;
-        for (Uint8 i=0; i< menu->getSize(); i++) {
-            if (i<=menu->currententry) {
-                h=(screen->h+menu->font_title->getHeight()-(menu->getSize()-i-1)*DFONT-(menu->getSize()-i-1)*(menu->font->getHeight())-menu->font_high->getHeight())/2;
-            } else {
-                h=(screen->h+menu->font_title->getHeight()-(menu->getSize()-i-1)*DFONT-(menu->getSize()-i)*(menu->font->getHeight()))/2;
-            }
-            if (i==menu->currententry) menu->font_high->writeCenter(screen,menu->entries[i],h);
-            else menu->font->writeCenter(screen,menu->entries[i],h);
+    Uint16 h;
+    for (Uint8 i=0; i< menu->getSize(); i++) {
+        if (i<=menu->currententry) {
+            h=(screen->h+menu->font_title->getHeight()-(menu->getSize()-i-1)*DFONT-(menu->getSize()-i-1)*(menu->font->getHeight())-menu->font_high->getHeight())/2;
+        } else {
+            h=(screen->h+menu->font_title->getHeight()-(menu->getSize()-i-1)*DFONT-(menu->getSize()-i)*(menu->font->getHeight()))/2;
         }
-
-        SDL_Flip(screen);
+        if (i==menu->currententry) menu->font_high->writeCenter(screen,menu->entries[i],h);
+        else menu->font->writeCenter(screen,menu->entries[i],h);
     }
 }
 
 //this could probably be done much easier ;)
 inline void GraphicsEngine::setGameMenuBG() {
-    if (!menubg) {
-        SDL_Surface* tmp = SDL_CreateRGBSurface (
-          SDL_HWSURFACE,
-          screen->w,
-          screen->h,
-          32,
-          rmask,gmask,bmask,0);
+    if (menubg) SDL_FreeSurface(menubg);
+    drawScene();
+    drawPlayerBar();
+    SDL_Flip(screen);
+    
+    SDL_Surface* tmp = SDL_CreateRGBSurface (
+      SDL_HWSURFACE,
+      screen->w,
+      screen->h,
+      32,
+      rmask,gmask,bmask,0);
 #ifdef ALPHA
-        menubg = SDL_CreateRGBSurface (
-          SDL_HWSURFACE,
-          screen->w,
-          screen->h,
-          32,
-          rmask,gmask,bmask,0);
-        SDL_BlitSurface(screen,NULL,menubg,NULL);
-        SDL_SetAlpha(menubg,SDL_SRCALPHA,60);
-        SDL_FillRect(tmp,NULL,SDL_MapRGB(screen->format,0,0,0));
-        SDL_BlitSurface(menubg,NULL,tmp,NULL);
-        SDL_FreeSurface(menubg);
-        menubg=SDL_DisplayFormatAlpha(tmp);
+    menubg = SDL_CreateRGBSurface (
+      SDL_HWSURFACE,
+      screen->w,
+      screen->h,
+      32,
+      rmask,gmask,bmask,0);
+    SDL_BlitSurface(screen,NULL,menubg,NULL);
+    SDL_SetAlpha(menubg,SDL_SRCALPHA,60);
+    SDL_FillRect(tmp,NULL,SDL_MapRGB(screen->format,0,0,0));
+    SDL_BlitSurface(menubg,NULL,tmp,NULL);
+    SDL_FreeSurface(menubg);
+    menubg=SDL_DisplayFormatAlpha(tmp);
 #else
-        SDL_FillRect(tmp,NULL,SDL_MapRGB(screen->format,0,0,0));
-        menubg=SDL_DisplayFormat(tmp);
+    SDL_FillRect(tmp,NULL,SDL_MapRGB(screen->format,0,0,0));
+    menubg=SDL_DisplayFormat(tmp);
 #endif
-        SDL_FreeSurface(tmp);
-    }
+    SDL_FreeSurface(tmp);
 }
 
 void GraphicsEngine::setMenuBG(SDL_Surface* menu_background) {

Modified: trunk/src/gfxeng.h
===================================================================
--- trunk/src/gfxeng.h	2005-02-22 13:51:28 UTC (rev 93)
+++ trunk/src/gfxeng.h	2005-02-23 12:47:07 UTC (rev 94)
@@ -5,6 +5,11 @@
 #define ICON_SIZE       46
 #define DFONT           40
 
+#define UPDATE_NOTHING  0x00
+#define UPDATE_BAR      0x01
+#define UPDATE_MENU     0x02
+#define UPDATE_ALL      0x03
+
 /** \brief Graphics engine
 
     Draws each object in the pool and optionally a player bar and/or
@@ -15,66 +20,58 @@
     public:
         GraphicsEngine();
         ~GraphicsEngine();
+        /// Update what should be drawn to the screen
+        void update(Uint8);
+        /// Update the screen drawings...
+        void draw();
         /// Runs SDL_SetVideoMode with the new parameters.
         void resize(Uint16 width, Uint16 height);
-        ///\brief update the scene in a running scenario
-        ///
-        /// If a scenario is running this draws the background and all objects
-        /// in the pool. If the game is paused, only the player bar is drawn.
-        /// Optionally also the player bar and/or the current frames per second
-        /// are displayed.
-        /// \param insist True if the objects should be drawn even if the game
-        ///        is paused
-        void renderScene(bool insist=false);
         void togglePlayerBar();
         void toggleFPS();
         void toggleFullScreen();
-        ///\brief draw the menu
-        ///
-        /// If no scenario is running or the scenario was interrupted this will
-        /// draw the menu.
-        void drawMenu();
-        void updateMenu() {
-            menu_done=false;
-        }
         void setMenuBG(SDL_Surface* menu_background=NULL);
-        void resetMenuBG();
-        Uint16 getFPS() {
-            if (show_fps) return currentfps;
-            else return 0;
-        }
     protected:
         Uint32 rmask;
         Uint32 gmask;
         Uint32 bmask;
         Uint32 amask;
-        inline SDL_Rect clipToBG(SDL_Rect dest) const;
-        /// updates backpos and returns the new shift vector (ignore w,h)
-        inline SDL_Rect setShift(SDL_Rect center);
-        /// simple vector addition, should be replaced by operator
-        inline SDL_Rect* shiftMapArea(SDL_Rect& area, const SDL_Rect& shift);
-        /// draw player bar
-        inline void drawPlayerBar();
         /// currently visible part of the map area
         SDL_Rect vis_map;
         /// main screen
         SDL_Surface* screen;
         /// menu background
         SDL_Surface* menubg;
-        /// sets the menu background while playing a scenario
-        inline void setGameMenuBG();
         /// player bar
         SDL_Rect bar;
         /// symbol for one life of a player
         Animation* lifeimage;
-        //fps stuff
-        Uint16 Dfps,Dframes,currentfps,tcurrent;
-        //for drawMenu
-        bool menu_done;
-        //visual flags
         bool show_bar;
         bool show_fps;
+        //visual flags
         bool fullscreen;
+        //update state
+        Uint8 updatetype;
+    protected:
+        /// Draw the background and all objects in the pool. This is a very time
+        /// consuming function...
+        inline void drawScene();
+        /// Draw player bar
+        inline void drawPlayerBar();
+        /// Draw the frames per second
+        inline void drawFPS();
+        ///\brief draw the menu
+        ///
+        /// If no scenario is running or the scenario was interrupted this will
+        /// draw the menu.
+        inline void drawMenu();
+        inline void resetMenuBG();
+        inline SDL_Rect clipToBG(SDL_Rect dest) const;
+        /// updates backpos and returns the new shift vector (ignore w,h)
+        inline SDL_Rect setShift(SDL_Rect center);
+        /// simple vector addition, should be replaced by operator
+        inline SDL_Rect* shiftMapArea(SDL_Rect& area, const SDL_Rect& shift);
+        /// sets the menu background while playing a scenario
+        inline void setGameMenuBG();
 };
 
 #endif

Modified: trunk/src/input.cpp
===================================================================
--- trunk/src/input.cpp	2005-02-22 13:51:28 UTC (rev 93)
+++ trunk/src/input.cpp	2005-02-23 12:47:07 UTC (rev 94)
@@ -11,161 +11,66 @@
 #include "objects_common.h"
 
 
-InputHandler::InputHandler():
-  state(NOTHING) {
-    paused=false;
+InputHandler::InputHandler() {
     au_pause=sndcache->loadWAV("pause.wav");
+    SDL_PumpEvents();
+    keystate = SDL_GetKeyState(NULL);
 }
 
 InputHandler::~InputHandler() {
 }
 
-void InputHandler::pollMEvents() {
-    SDL_Event event;
+bool InputHandler::keyPressed(ConfigKey key) {
+    return keypressed[config.keybind[key]];
+}
+bool InputHandler::keyState(ConfigKey key) {
+    return keystate[config.keybind[key]];
+}   
 
+void InputHandler::update() {
+    if (menu) {
+        pollMenuEvents();
+    } else if (paused) {
+        pollPausedEvents();
+    } else {
+        pollGameEvents();
+    }
+}
+
+inline void InputHandler::pollMenuEvents() {
     while(SDL_PollEvent(&event)) {
         switch(event.type) {
            // special events
          case SDL_VIDEORESIZE: {
              gfxeng->resize(event.resize.w, event.resize.h);
-             gfxeng->renderScene(true);
-             gfxeng->updateMenu();
-             gfxeng->drawMenu();
              break;
          }
             // keyboard events
             case SDL_QUIT: {
                 quitGame(0);
             }
-            case SDL_KEYUP: {
-                switch(event.key.keysym.sym) {
-                    case SDLK_LEFT: {
-                        if (state&INPUT_LEFT) setState(INPUTR_LEFT);
-                        state&=~INPUT_LEFT;
-                        break;
-                    }
-                    case SDLK_RIGHT: {
-                        if (state&INPUT_RIGHT) state|=INPUTR_RIGHT;
-                        state&=~INPUT_RIGHT;
-                        break;
-                    }
-                    case SDLK_UP: {
-                        if (state&INPUT_UP) setState(INPUTR_UP);
-                        state&=~INPUT_UP;
-                        break;
-                    }
-                    case SDLK_DOWN: {
-                        if (state&INPUT_DOWN) setState(INPUTR_DOWN);
-                        state&=~INPUT_DOWN;
-                        break;
-                    }
-                    case SDLK_SPACE: {
-                        if (state&INPUT_SP1) setState(INPUTR_SP1);
-                        state&=~INPUT_SP1;
-                        break;
-                    }
-                    case SDLK_LSHIFT: {
-                        if (state&INPUT_SP2) setState(INPUTR_SP2);
-                        state&=~INPUT_SP2;
-                        break;
-                    }
-                    case SDLK_RETURN: {
-                        if (state&INPUT_ACT) setState(INPUTR_ACT);
-                        state&=~INPUT_ACT;
-                        break;
-                    }
-                    case SDLK_INSERT: {
-                        if (state&INPUT_USE) setState(INPUTR_USE);
-                        state&=~INPUT_USE;
-                        break;
-                    }
-                    case SDLK_DELETE: {
-                        if (state&INPUT_DEL) setState(INPUTR_DEL);
-                        state&=~INPUT_DEL;
-                        break;
-                    }
-                    default: {
-                        break;
-                    }
-                }
-                break;
-            }
             case SDL_KEYDOWN: {
-                switch(event.key.keysym.sym) {
-                    case SDLK_LEFT: {
-                        state|=INPUT_LEFT;
-                        gfxeng->updateMenu();
-                        break;
-                    }
-                    case SDLK_RIGHT: {
-                        state|=INPUT_RIGHT;
-                        gfxeng->updateMenu();
-                        break;
-                    }
-                    case SDLK_UP: {
-                        if (state&INPUT_UP) break;
-                        menu->increaseEntry(false);
-                        state|=INPUT_UP;
-                        gfxeng->updateMenu();
-                        break;
-                    }
-                    case SDLK_DOWN: {
-                        if (state&INPUT_DOWN) break;
-                        menu->increaseEntry();
-                        state|=INPUT_DOWN;
-                        gfxeng->updateMenu();
-                        break;
-                    }
-                    case SDLK_SPACE: {
-                        state|=INPUT_SP1;
-                        gfxeng->updateMenu();
-                        break;
-                    }
-                    case SDLK_LSHIFT: {
-                        state|=INPUT_SP2;
-                        gfxeng->updateMenu();
-                        break;
-                    }
-                    case SDLK_RETURN: {
-                        if (state&INPUT_ACT) break;
-                        state|=INPUT_ACT;
-                        menu->act();
-                        gfxeng->updateMenu();
-                        break;
-                    }
-                    case SDLK_INSERT: {
-                        state|=INPUT_USE;
-                        gfxeng->updateMenu();
-                        break;
-                    }
-                    case SDLK_DELETE: {
-                        state|=INPUT_DEL;
-                        gfxeng->updateMenu();
-                        break;
-                    }
-                    case SDLK_ESCAPE: {
-                         if (!closeMenu()) {
-                             gfxeng->renderScene(true);
-                             scenario->physic->resetTime();
+                SDLKey key=event.key.keysym.sym;
+                if (key==config.keybind[KEY_UP]) {
+                    menu->increaseEntry(false);
+                } else if (key==config.keybind[KEY_DOWN]) {
+                    menu->increaseEntry();  
+                } else if (key==config.keybind[KEY_ACT]) {
+                    menu->act();
+                } else if (key==config.keybind[KEY_MENU]) {
+                     if (!closeMenu()) {
+                         if (running) {
                              sfxeng->resumeMusic();
+                         } else {
+                             quitGame(0);
                          }
-                         gfxeng->updateMenu();
-                         break;
-                    }
-                    case SDLK_f: {
-                         gfxeng->toggleFullScreen();
-                         gfxeng->updateMenu();
-                         break;
-                    }
-                    case SDLK_q: {
-                         quitGame(0);
-                         gfxeng->updateMenu();
-                         break;
-                    }
-                    default: {
-                        break;
-                    }
+                     }
+                } else if (key==config.keybind[KEY_FULL]) { 
+                     gfxeng->toggleFullScreen();
+                } else if (key==config.keybind[KEY_QUIT]) { 
+                     quitGame(0);
                 }
+                gfxeng->update(UPDATE_MENU);
                 break;
             }
             default: {
@@ -175,149 +80,34 @@
     }    
 }
 
-void InputHandler::pollPEvents() {
-    SDL_Event event;
-
+inline void InputHandler::pollPausedEvents() {
     while(SDL_PollEvent(&event)) {
         switch(event.type) {
            // special events
          case SDL_VIDEORESIZE: {
              gfxeng->resize(event.resize.w, event.resize.h);
-             gfxeng->renderScene(true);
              break;
          }
             // keyboard events
             case SDL_QUIT: {
                 quitGame(0);
             }
-            case SDL_KEYUP: {
-                switch(event.key.keysym.sym) {
-                    case SDLK_LEFT: {
-                        if (state&INPUT_LEFT) setState(INPUTR_LEFT);
-                        state&=~INPUT_LEFT;
-                        break;
-                    }
-                    case SDLK_RIGHT: {
-                        if (state&INPUT_RIGHT) state|=INPUTR_RIGHT;
-                        state&=~INPUT_RIGHT;
-                        break;
-                    }
-                    case SDLK_UP: {
-                        if (state&INPUT_UP) setState(INPUTR_UP);
-                        state&=~INPUT_UP;
-                        break;
-                    }
-                    case SDLK_DOWN: {
-                        if (state&INPUT_DOWN) setState(INPUTR_DOWN);
-                        state&=~INPUT_DOWN;
-                        break;
-                    }
-                    case SDLK_SPACE: {
-                        if (state&INPUT_SP1) setState(INPUTR_SP1);
-                        state&=~INPUT_SP1;
-                        break;
-                    }
-                    case SDLK_LSHIFT: {
-                        if (state&INPUT_SP2) setState(INPUTR_SP2);
-                        state&=~INPUT_SP2;
-                        break;
-                    }
-                    case SDLK_RETURN: {
-                        if (state&INPUT_ACT) setState(INPUTR_ACT);
-                        state&=~INPUT_ACT;
-                        break;
-                    }
-                    case SDLK_INSERT: {
-                        if (state&INPUT_USE) setState(INPUTR_USE);
-                        state&=~INPUT_USE;
-                        break;
-                    }
-                    case SDLK_DELETE: {
-                        if (state&INPUT_DEL) setState(INPUTR_DEL);
-                        state&=~INPUT_DEL;
-                        break;
-                    }
-                    default: {
-                        break;
-                    }
-                }
-                break;
-            }
             case SDL_KEYDOWN: {
-                switch(event.key.keysym.sym) {
-                    case SDLK_LCTRL: {
-                        scenario->pool->switchPlayer();
-                        state=NOTHING;
-                        break;
-                    }
-                    case SDLK_LEFT: {
-                        state|=INPUT_LEFT;
-                        break;
-                    }
-                    case SDLK_RIGHT: {
-                        state|=INPUT_RIGHT;
-                        break;
-                    }
-                    case SDLK_UP: {
-                        state|=INPUT_UP;
-                        break;
-                    }
-                    case SDLK_DOWN: {
-                        state|=INPUT_DOWN;
-                        break;
-                    }
-                    case SDLK_SPACE: {
-                        state|=INPUT_SP1;
-                        break;
-                    }
-                    case SDLK_LSHIFT: {
-                        state|=INPUT_SP2;
-                        break;
-                    }
-                    case SDLK_RETURN: {
-                        state|=INPUT_ACT;
-                        break;
-                    }
-                    case SDLK_INSERT: {
-                        state|=INPUT_USE;
-                        break;
-                    }
-                    case SDLK_DELETE: {
-                        state|=INPUT_DEL;
-                        break;
-                    }
-                    //change game state!
-                    case SDLK_TAB: {
-                         paused=false;
-                         scenario->physic->resetTime();
-                         sfxeng->resumeMusic();
-                         break;
-                    }
-                    case SDLK_ESCAPE: {
-                         sfxeng->pauseMusic();
-                         menu=new GameMenu();
-                         break;
-                    }
-                    case SDLK_F1: {
-                         gfxeng->togglePlayerBar();
-                         break;
-                    }
-                    case SDLK_F2: {
-                         gfxeng->toggleFPS();
-                         break;
-                    }
-                    case SDLK_f: {
-                         gfxeng->toggleFullScreen();
-                         break;
-                    }
-                    case SDLK_q: {
-                         quitGame(0);
-                         break;
-                    }
-                    default: {
-                        break;
-                    }
+                SDLKey key=event.key.keysym.sym;
+                if (key==config.keybind[KEY_SWITCH]) {
+                     scenario->pool->switchPlayer();
+                } else if (key==config.keybind[KEY_PAUSE]) {
+                     paused=false;
+                     sfxeng->resumeMusic();
+                } else if (key==config.keybind[KEY_MENU]) {
+                     sfxeng->pauseMusic();
+                     setMenu(new GameMenu());
+                } else if (key==config.keybind[KEY_FULL]) {
+                     gfxeng->toggleFullScreen();
+                } else if (key==config.keybind[KEY_QUIT]) {
+                     quitGame(0);
                 }
+                gfxeng->update(UPDATE_BAR);
                 break;
             }
             default: {
@@ -327,148 +117,42 @@
     }    
 }
 
-void InputHandler::pollEvents() {
-    SDL_Event event;
-
+inline void InputHandler::pollGameEvents() {
+    for (Uint16 i=0; i<SDLK_LAST; i++) {
+        keypressed[i]=false;
+    }
     while(SDL_PollEvent(&event)) {
         switch(event.type) {
            // special events
          case SDL_VIDEORESIZE: {
              gfxeng->resize(event.resize.w, event.resize.h);
-             gfxeng->renderScene(true);
              break;
          }
             // keyboard events
             case SDL_QUIT: {
                 quitGame(0);
             }
-            case SDL_KEYUP: {
-                switch(event.key.keysym.sym) {
-                    case SDLK_LEFT: {
-                        if (state&INPUT_LEFT) setState(INPUTR_LEFT);
-                        state&=~INPUT_LEFT;
-                        break;
-                    }
-                    case SDLK_RIGHT: {
-                        if (state&INPUT_RIGHT) state|=INPUTR_RIGHT;
-                        state&=~INPUT_RIGHT;
-                        break;
-                    }
-                    case SDLK_UP: {
-                        if (state&INPUT_UP) setState(INPUTR_UP);
-                        state&=~INPUT_UP;
-                        break;
-                    }
-                    case SDLK_DOWN: {
-                        if (state&INPUT_DOWN) setState(INPUTR_DOWN);
-                        state&=~INPUT_DOWN;
-                        break;
-                    }
-                    case SDLK_SPACE: {
-                        if (state&INPUT_SP1) setState(INPUTR_SP1);
-                        state&=~INPUT_SP1;
-                        break;
-                    }
-                    case SDLK_LSHIFT: {
-                        if (state&INPUT_SP2) setState(INPUTR_SP2);
-                        state&=~INPUT_SP2;
-                        break;
-                    }
-                    case SDLK_RETURN: {
-                        if (state&INPUT_ACT) setState(INPUTR_ACT);
-                        state&=~INPUT_ACT;
-                        break;
-                    }
-                    case SDLK_INSERT: {
-                        if (state&INPUT_USE) setState(INPUTR_USE);
-                        state&=~INPUT_USE;
-                        break;
-                    }
-                    case SDLK_DELETE: {
-                        if (state&INPUT_DEL) setState(INPUTR_DEL);
-                        state&=~INPUT_DEL;
-                        break;
-                    }
-                    default: {
-                        break;
-                    }
-                }
-                break;
-            }
             case SDL_KEYDOWN: {
-                switch(event.key.keysym.sym) {
-                    case SDLK_LCTRL: {
-                        scenario->pool->switchPlayer();
-                        state=NOTHING;
-                        break;
-                    }
-                    case SDLK_LEFT: {
-                        state|=INPUT_LEFT;
-                        break;
-                    }
-                    case SDLK_RIGHT: {
-                        state|=INPUT_RIGHT;
-                        break;
-                    }
-                    case SDLK_UP: {
-                        state|=INPUT_UP;
-                        break;
-                    }
-                    case SDLK_DOWN: {
-                        state|=INPUT_DOWN;
-                        break;
-                    }
-                    case SDLK_SPACE: {
-                        state|=INPUT_SP1;
-                        break;
-                    }
-                    case SDLK_LSHIFT: {
-                        state|=INPUT_SP2;
-                        break;
-                    }
-                    case SDLK_RETURN: {
-                        state|=INPUT_ACT;
-                        break;
-                    }
-                    case SDLK_INSERT: {
-                        state|=INPUT_USE;
-                        break;
-                    }
-                    case SDLK_DELETE: {
-                        state|=INPUT_DEL;
-                        break;
-                    }
-                    //change game state!
-                    case SDLK_TAB: {
-                         paused=true;
-                         sfxeng->playWAV(au_pause);
-                         sfxeng->pauseMusic();
-                         break;
-                    }
-                    case SDLK_ESCAPE: {
-                         sfxeng->pauseMusic();
-                         menu=new GameMenu();
-                         break;
-                    }
-                    case SDLK_F1: {
-                         gfxeng->togglePlayerBar();
-                         break;
-                    }
-                    case SDLK_F2: {
-                         gfxeng->toggleFPS();
-                         break;
-                    }
-                    case SDLK_f: {
-                         gfxeng->toggleFullScreen();
-                         break;
-                    }
-                    case SDLK_q: {
-                         quitGame(0);
-                         break;
-                    }
-                    default: {
-                        break;
-                    }
+                SDLKey key=event.key.keysym.sym;
+                keypressed[key]=true;
+                if (key==config.keybind[KEY_SWITCH]) {
+                     scenario->pool->switchPlayer();
+                } else if (key==config.keybind[KEY_PAUSE]) {  
+                     paused=true;
+                     sfxeng->playWAV(au_pause);
+                     sfxeng->pauseMusic();
+                } else if (key==config.keybind[KEY_MENU]) {
+                     sfxeng->pauseMusic();
+                     setMenu(new GameMenu());
+                     gfxeng->update(UPDATE_ALL); 
+                } else if (key==config.keybind[KEY_BAR]) {   
+                     gfxeng->togglePlayerBar();
+                } else if (key==config.keybind[KEY_FPS]) {
+                     gfxeng->toggleFPS(); 
+                } else if (key==config.keybind[KEY_FULL]) {
+                     gfxeng->toggleFullScreen();
+                } else if (key==config.keybind[KEY_QUIT]) {
+                     quitGame(0);
                 }
                 break;
             }
@@ -477,5 +161,5 @@
             }
         }
     }    
+    keystate = SDL_GetKeyState(NULL);
 }
-

Modified: trunk/src/input.h
===================================================================
--- trunk/src/input.h	2005-02-22 13:51:28 UTC (rev 93)
+++ trunk/src/input.h	2005-02-23 12:47:07 UTC (rev 94)
@@ -1,26 +1,6 @@
 #ifndef _INPUT_H
 #define _INPUT_H 1
 
-//Input events
-#define INPUT_LEFT      0x00000001
-#define INPUT_RIGHT     0x00000002
-#define INPUT_UP        0x00000004
-#define INPUT_DOWN      0x00000008
-#define INPUT_SP1       0x00000010
-#define INPUT_SP2       0x00000020
-#define INPUT_ACT       0x00000040
-#define INPUT_USE       0x00000080
-#define INPUT_DEL       0x00000100
-#define INPUTR_LEFT     0x00010000
-#define INPUTR_RIGHT    0x00020000
-#define INPUTR_UP       0x00040000
-#define INPUTR_DOWN     0x00080000
-#define INPUTR_SP1      0x00100000
-#define INPUTR_SP2      0x00200000
-#define INPUTR_ACT      0x00400000
-#define INPUTR_USE      0x00800000
-#define INPUTR_DEL      0x01000000
-
 /** \brief Handels keyboard events
 
     \remark A key release event which is passed on to the PhysicHandler
@@ -31,29 +11,23 @@
     public:
         InputHandler();
         ~InputHandler();
-        /// Check for keyboard events in game
-        void pollEvents();
-        /// Check for keyboard events in paused game
-        void pollPEvents();
-        /// Check for keyboard events in menu
-        void pollMEvents();
-        bool getState(Uint32 cstate) {
-            return (state&cstate);
-        }
-        void setState(Uint32 cstate) {
-            state|=cstate;
-        }
-        void unsetState(Uint32 cstate) {
-            state&=~cstate;
-        }
-        void clearStates() {
-            state=NOTHING;
-        }
+        /// Update the input status
+        void update();
+        bool keyPressed(ConfigKey key);
+        bool keyState(ConfigKey key);
     private:
-        /// Information about which buttons are pressed
-        Uint32 state;
         /// Sound: When the game is paused
         Mix_Chunk* au_pause;
+        Uint8* keystate;
+        bool keypressed[SDLK_LAST];
+    private:
+        SDL_Event event;
+        /// Check for keyboard events in game
+        inline void pollGameEvents();
+        /// Check for keyboard events in paused game
+        inline void pollPausedEvents();
+        /// Check for keyboard events in menu
+        inline void pollMenuEvents();
 };
 
 #endif

Modified: trunk/src/lost_penguins.cpp
===================================================================
--- trunk/src/lost_penguins.cpp	2005-02-22 13:51:28 UTC (rev 93)
+++ trunk/src/lost_penguins.cpp	2005-02-23 12:47:07 UTC (rev 94)
@@ -51,27 +51,13 @@
     scenario=new Scenario();
 
     gfxeng->setMenuBG();
-    menu=new StartMenu();
+    menu=NULL;
+    setMenu(new StartMenu());
 
     while (true) {
-        if (menu) {
-            gfxeng->drawMenu();
-            //Check menu input
-            input->pollMEvents();
-        } else if (running) {
-            if (paused) {
-                //Check pause input
-                input->pollPEvents();
-            } else {
-                gfxeng->renderScene();
-                //Check normal input
-                input->pollEvents();
-                //Run Animations
-                scenario->physic->update();
-            }
-        } else {
-            quitGame(-6);
-        }
+        input->update();
+        if (running) scenario->physic->update();
+        gfxeng->draw();
     }
 
     quitGame(-2);
@@ -112,6 +98,24 @@
     config.datadir="data/";
     config.map="map1.cfg";
 
+    //key bindings
+    config.keybind[KEY_LEFT]    = SDLK_LEFT;
+    config.keybind[KEY_RIGHT]   = SDLK_RIGHT;
+    config.keybind[KEY_UP]      = SDLK_UP;
+    config.keybind[KEY_DOWN]    = SDLK_DOWN;
+    config.keybind[KEY_SP1]     = SDLK_SPACE;
+    config.keybind[KEY_SP2]     = SDLK_LSHIFT;
+    config.keybind[KEY_ACT]     = SDLK_RETURN;
+    config.keybind[KEY_USE]     = SDLK_INSERT;
+    config.keybind[KEY_DROP]    = SDLK_DELETE;
+    config.keybind[KEY_SWITCH]  = SDLK_LCTRL;
+    config.keybind[KEY_PAUSE]   = SDLK_TAB;
+    config.keybind[KEY_MENU]    = SDLK_ESCAPE;
+    config.keybind[KEY_FPS]     = SDLK_F2;
+    config.keybind[KEY_BAR]     = SDLK_F1;
+    config.keybind[KEY_FULL]    = SDLK_f;
+    config.keybind[KEY_QUIT]    = SDLK_q;
+
     configfile.open(filename.c_str());
     if (!configfile) return 0;
 
@@ -136,6 +140,7 @@
             config.full=true;
         } else if (option=="map") {
             config.map=arg1;
+        //TODO: add keybindings
         } else {
             cout << "Unknown option: " << option << endl;
         }

Modified: trunk/src/menu.cpp
===================================================================
--- trunk/src/menu.cpp	2005-02-22 13:51:28 UTC (rev 93)
+++ trunk/src/menu.cpp	2005-02-23 12:47:07 UTC (rev 94)
@@ -5,6 +5,32 @@
 #include "sfxeng.h"
 #include "menu.h"
 
+Menu* setMenu(Menu* newmenu) {
+    if (menu) gfxeng->update(UPDATE_MENU);
+    else gfxeng->update(UPDATE_ALL);
+    newmenu->setLast(menu);
+    return menu=newmenu;   
+}
+ 
+Menu* closeMenu() {
+    gfxeng->update(UPDATE_MENU);
+    if (menu) {
+        Menu* tmp=menu->getLast();
+        delete menu;
+        if (!tmp) gfxeng->update(UPDATE_ALL);
+        return menu=tmp;
+    } else {
+        gfxeng->update(UPDATE_ALL);
+        return NULL;
+    }
+}
+ 
+void closeMenus() {
+    while (menu) { 
+        closeMenu();
+    }
+}
+
 Menu::Menu():
   title("MENU"),
   last(NULL),
@@ -74,8 +100,7 @@
     switch (currententry) {
     case 0: {
         if (!closeMenu()) {
-            gfxeng->renderScene(true);
-            scenario->physic->resetTime();
+            gfxeng->update(UPDATE_ALL);
             sfxeng->resumeMusic();
         }
         break;
@@ -121,21 +146,19 @@
     switch (currententry) {
     case 0: {
         gfxeng->toggleFPS();
-        update();
-        gfxeng->updateMenu();
+        gfxeng->update(UPDATE_MENU);
         break;
     }
     case 1: {
         gfxeng->togglePlayerBar();
-        gfxeng->renderScene(true);
-        update();
-        gfxeng->updateMenu();
+        gfxeng->update(UPDATE_ALL);
         break;
     }
     default: {
         break;
     }
     }
+    update();
 }
 void ConfigMenu::update() {
     entries[0]="Show FPS: "+string((gfxeng->show_fps) ? "ON" : "OFF");

Modified: trunk/src/objects/baleog.cpp
===================================================================
--- trunk/src/objects/baleog.cpp	2005-02-22 13:51:28 UTC (rev 93)
+++ trunk/src/objects/baleog.cpp	2005-02-23 12:47:07 UTC (rev 94)
@@ -38,9 +38,6 @@
 }
 
 //Baleog1: Sword attack
-void Baleog::in_sp1(Sint16 dt) {
-    if (dt < 0) return;
-    input->unsetState(INPUT_SP1);
-
+void Baleog::in_sp1() {
     setEvent(new EAttack(this,10,&weapon,(state&STATE_LEFT) ? DIR_LEFT : DIR_RIGHT,10,enemy_types,0,0,au_sword,(state&STATE_LEFT) ? im_sword_left : im_sword_right));
 }

Modified: trunk/src/objects/baleog.h
===================================================================
--- trunk/src/objects/baleog.h	2005-02-22 13:51:28 UTC (rev 93)
+++ trunk/src/objects/baleog.h	2005-02-23 12:47:07 UTC (rev 94)
@@ -8,7 +8,7 @@
         Baleog(string imagename, Sint16 xpos=0, Sint16 ypos=0, string name="Baleog");
         virtual ~Baleog();
         /// \brief Baleog attacks with a sword
-        virtual void in_sp1(Sint16);
+        virtual void in_sp1();
     private:
         Mix_Chunk* au_sword;
         Animation* im_sword_left;

Modified: trunk/src/objects/erik.cpp
===================================================================
--- trunk/src/objects/erik.cpp	2005-02-22 13:51:28 UTC (rev 93)
+++ trunk/src/objects/erik.cpp	2005-02-23 12:47:07 UTC (rev 94)
@@ -36,11 +36,29 @@
     delete im_land_right;
 }
 
-void Erik::in_sp1(Sint16 dt) {
+void Erik::idle(Uint16 dt) {
+    Player::idle(dt);
+    //TODO: this is an ugly hack...
+    if (!input->keyState(KEY_SP2)) {
+        dense_types&=~OTYPE_MONSTER;
+        if (state&STATE_RUN) cancelEvent();
+    } else if (state&STATE_RUN) {
+        dense_types|=OTYPE_MONSTER;
+        if (state&STATE_FALL) cancelEvent();
+        if ((!state&STATE_MRIGHT) && run_right) cancelEvent();
+        if ((!state&STATE_MLEFT) && (!run_right)) cancelEvent();
+    } else {
+        //TODO: check STATE_WATER
+        if (state&(STATE_MLEFT|STATE_MRIGHT)) {
+            if (state&STATE_MRIGHT) run_right=true;
+            else run_right=false;
+            setEvent(new ERun(this,10000,maxspeedx,500,ESTATE_ABORT,au_run));
+        }
+    }
+}
+
+void Erik::in_sp1() {
     //TODO: check STATE_WATER
-    if (dt < 0) return;
-    input->unsetState(INPUT_SP1);
-
     if (state&STATE_FALL) setState(STATE_ACT_1);
 
     if (state&STATE_ACT_2) {
@@ -55,27 +73,17 @@
     }
 }
 
-void Erik::in_sp2(Sint16 dt) {
+void Erik::in_sp2() {
     //TODO: check STATE_WATER
-    if (dt < 0) {
-        input->unsetState(INPUT_SP2);
-        dense_types&=~OTYPE_MONSTER;
-        if (state&STATE_RUN) cancelEvent();
-        return;
-    }
-    if (state&STATE_RUN) {
-        dense_types|=OTYPE_MONSTER;
-        if (state&STATE_FALL) cancelEvent();
-    } else if (state&(STATE_MLEFT|STATE_MRIGHT)) {
+    if (state&(STATE_MLEFT|STATE_MRIGHT)) {
+        if (state&STATE_MRIGHT) run_right=true;
+        else run_right=false;
         setEvent(new ERun(this,10000,maxspeedx,500,ESTATE_ABORT,au_run));
     }
 }
 
-void Erik::in_left(Sint16 dt) {
-    if (dt < 0) {
-        //TODO: play decelerate animation (setEvent instead)
-        if (state&STATE_RUN) cancelEvent();
-    } else if (state&STATE_RUN) {
+void Erik::in_left(Uint16 dt) {
+    if (state&STATE_RUN) {
         if (state&STATE_LEFT) event->reset();
         //changed directions, TODO: play decelerate animation
         else cancelEvent();
@@ -83,11 +91,8 @@
     Player::in_left(dt);
 }
 
-void Erik::in_right(Sint16 dt) {
-    if (dt < 0) {
-        //TODO: play decelerate animation (setEvent instead)
-        if (state&STATE_RUN) cancelEvent();
-    } else if (state&STATE_RUN) {
+void Erik::in_right(Uint16 dt) {
+    if (state&STATE_RUN) {
         if (!(state&STATE_LEFT)) event->reset();
         //changed directions, TODO: play decelerate animation
         else cancelEvent();

Modified: trunk/src/objects/erik.h
===================================================================
--- trunk/src/objects/erik.h	2005-02-22 13:51:28 UTC (rev 93)
+++ trunk/src/objects/erik.h	2005-02-23 12:47:07 UTC (rev 94)
@@ -15,16 +15,18 @@
     public:
         Erik(string imagename, Sint16 xpos=0, Sint16 ypos=0, string name="Erik");
         virtual ~Erik();
-        /// \brief Erik jumps
-        virtual void in_sp1(Sint16);
-        // \brief Erik runs
-        virtual void in_sp2(Sint16);
-        virtual void in_left(Sint16);
-        virtual void in_right(Sint16);
+        virtual void idle(Uint16); 
+       /// \brief Erik jumps
+        virtual void in_sp1();
+        /// \brief Erik runs
+        virtual void in_sp2();
+        virtual void in_left(Uint16);
+        virtual void in_right(Uint16);
         virtual void crash(Uint16 dir);
         virtual Uint16 hit(Uint16 direction,Weapon& weap);
     private:
         Mix_Chunk* au_jump;
         Mix_Chunk* au_run;
         Sint16 jump,jump2;
+        bool run_right;
 };

Modified: trunk/src/objects/fang.cpp
===================================================================
--- trunk/src/objects/fang.cpp	2005-02-22 13:51:28 UTC (rev 93)
+++ trunk/src/objects/fang.cpp	2005-02-23 12:47:07 UTC (rev 94)
@@ -39,13 +39,13 @@
     delete im_claw_right;
 }
 
-void Fang::in_left(Sint16 dt) {
+void Fang::in_left(Uint16 dt) {
     Player::in_left(dt);
-    if (dt >= 0) unsetState(STATE_CLIMB_R);
+    unsetState(STATE_CLIMB_R);
 }
-void Fang::in_right(Sint16 dt) {
+void Fang::in_right(Uint16 dt) {
     Player::in_right(dt);
-    if (dt >= 0) unsetState(STATE_CLIMB_L);
+    unsetState(STATE_CLIMB_L);
 }
 
 void Fang::fall(Uint16 dt) {
@@ -71,10 +71,7 @@
     }
 }
 
-void Fang::in_sp1(Sint16 dt) {
-    if (dt < 0) return;
-    input->unsetState(INPUT_SP1);
-
+void Fang::in_sp1() {
     if (state&STATE_CLIMB_L) {
         unsetState(STATE_LEFT);
         unsetState(STATE_CLIMB_L);
@@ -96,10 +93,7 @@
     }
 }
 
-void Fang::in_sp2(Sint16 dt) {
-    if (dt < 0) return;
-    input->unsetState(INPUT_SP2);
-
+void Fang::in_sp2() {
     setEvent(new EAttack(this,10,&weapon,(state&STATE_LEFT) ? DIR_LEFT : DIR_RIGHT,10,enemy_types,0,0,au_claw,(state&STATE_LEFT) ? im_claw_left : im_claw_right));
 }
 

Modified: trunk/src/objects/fang.h
===================================================================
--- trunk/src/objects/fang.h	2005-02-22 13:51:28 UTC (rev 93)
+++ trunk/src/objects/fang.h	2005-02-23 12:47:07 UTC (rev 94)
@@ -25,12 +25,12 @@
         Fang(string imagename, Sint16 xpos=0, Sint16 ypos=0, string name="Fang");
         virtual ~Fang();
         virtual void fall(Uint16);
-        virtual void in_left(Sint16);
-        virtual void in_right(Sint16);
+        virtual void in_left(Uint16);
+        virtual void in_right(Uint16);
         /// \brief Fang jumps
-        virtual void in_sp1(Sint16);
+        virtual void in_sp1();
         /// \brief Fang attacks
-        virtual void in_sp2(Sint16);
+        virtual void in_sp2();
         virtual void clearStates(bool reset=false);
     private:
         virtual void crash(Uint16 dir=DIR_DOWN);

Modified: trunk/src/objects/olaf.cpp
===================================================================
--- trunk/src/objects/olaf.cpp	2005-02-22 13:51:28 UTC (rev 93)
+++ trunk/src/objects/olaf.cpp	2005-02-23 12:47:07 UTC (rev 94)
@@ -91,15 +91,15 @@
     curpos.y=(pos.h-curpos.h);
 }
 
-void Olaf::in_left(Sint16 dt) {
+void Olaf::in_left(Uint16 dt) {
     //No navigation while farting from ground (replace this by a busy event)
-    if ((dt < 0) || (!(state&STATE_ACT_2))) {
+    if (!(state&STATE_ACT_2)) {
         Player::in_left(dt);
     }
 }
-void Olaf::in_right(Sint16 dt) {
+void Olaf::in_right(Uint16 dt) {
     //No navigation while farting from ground (replace this by a busy event)
-    if ((dt < 0) || (!(state&STATE_ACT_2))) {
+    if (!(state&STATE_ACT_2)) {
         Player::in_right(dt);
     }
 }
@@ -135,32 +135,24 @@
     } else return false;
 }
 
-void Olaf::in_down(Sint16 dt) {
-    if (dt < 0) return;
-    input->unsetState(INPUT_DOWN);
+void Olaf::in_down() {
     //TODO: ladder
     if (!(state&STATE_FALL)) trySmall(true);
 }
 
-void Olaf::in_up(Sint16 dt) {
-    if (dt < 0) return;
-    input->unsetState(INPUT_UP);
+void Olaf::in_up() {
     //TODO: ladder
     if (!(state&STATE_FALL)) trySmall(false);
 }
 
-void Olaf::in_sp1(Sint16 dt) {
-    if (dt < 0) return;
-    input->unsetState(INPUT_SP1);
+void Olaf::in_sp1() {
     //no specials while small
     if (!(state&STATE_SMALL)) {
         switchState(STATE_SHIELD);
     }
 }
 
-void Olaf::in_sp2(Sint16 dt) {
-    if (dt < 0) return;
-    input->unsetState(INPUT_SP2);
+void Olaf::in_sp2() {
     //no specials while small
     if (!(state&STATE_SMALL)) {
         //Don't fart while falling without shield

Modified: trunk/src/objects/olaf.h
===================================================================
--- trunk/src/objects/olaf.h	2005-02-22 13:51:28 UTC (rev 93)
+++ trunk/src/objects/olaf.h	2005-02-23 12:47:07 UTC (rev 94)
@@ -20,17 +20,17 @@
         virtual ~Olaf();
         /// Additionally checks if Olaf is small and how he wears his shield
         virtual void updateAnimState(bool change=true);
-        virtual void in_left(Sint16);
-        virtual void in_right(Sint16);
+        virtual void in_left(Uint16);
+        virtual void in_right(Uint16);
         /// \brief Olaf tries to shrink (if he was big)
-        virtual void in_down(Sint16);
+        virtual void in_down();
         /// \brief Olaf tries to get big again (if he was small)
-        virtual void in_up(Sint16);
-        virtual void fall(Uint16);
+        virtual void in_up();
         /// \brief Olaf switches his shield state if possible
-        virtual void in_sp1(Sint16);
+        virtual void in_sp1();
         /// \brief Olaf farts
-        virtual void in_sp2(Sint16);
+        virtual void in_sp2();
+        virtual void fall(Uint16);
         virtual Uint16 hit(Uint16 direction,Weapon& weap);
     private:
         /// \brief Tries to change the size

Modified: trunk/src/objects/scorch.cpp
===================================================================
--- trunk/src/objects/scorch.cpp	2005-02-22 13:51:28 UTC (rev 93)
+++ trunk/src/objects/scorch.cpp	2005-02-23 12:47:07 UTC (rev 94)
@@ -35,6 +35,15 @@
     delete im_land_right;
 }
 
+void Scorch::idle(Uint16 dt) {
+    Player::idle(dt);
+    if (!input->keyState(KEY_SP1)) {
+        unsetState(STATE_GLIDE);
+    } else if (!(state&STATE_ACT_2)) {
+        setState(STATE_GLIDE);
+    }
+}
+
 void Scorch::fall(Uint16 dt) {
     if (!getState(STATE_MRIGHT|STATE_MLEFT)) {
         if (!getState(STATE_FALL)) hspeed=boost(hspeed,-dt*HSPEED_MULT/100);
@@ -52,29 +61,17 @@
     }
 }
 
-void Scorch::in_sp1(Sint16 dt) {
-    if (dt < 0) {
-        unsetState(STATE_ACT_1);
-        unsetState(STATE_GLIDE);
-        input->unsetState(INPUT_SP1);
-        return;
-    }
+void Scorch::in_sp1() {
     setState(STATE_FALL);
-    //if not exhausted -> glide
-    if (!(state&STATE_ACT_2)) {
-        setState(STATE_GLIDE);
-    }
     //Can't fly anymore
-    if ((state&STATE_ACT_1)||(state&STATE_ACT_2)) {
+    if (state&STATE_ACT_2) {
     } else if (left_wings<=0) {
-        setState(STATE_ACT_1);
         setState(STATE_ACT_2);
         unsetState(STATE_GLIDE);
         addSpeed(V_FLY);
         setEvent(new CAnimEvent(this,DE_WING,0,0,au_tired));
     //Use Wings
     } else {
-        setState(STATE_ACT_1);
         left_wings--;
         addSpeed(V_FLY);
         setEvent(new CAnimEvent(this,DE_WING,0,0,au_swing));
@@ -85,7 +82,6 @@
     Player::clearStates(reset);
     if (reset) {
         unsetState(STATE_GLIDE);
-        input->unsetState(INPUT_SP1);
         left_wings=SCORCH_MAX_WINGS;
     }
 }

Modified: trunk/src/objects/scorch.h
===================================================================
--- trunk/src/objects/scorch.h	2005-02-22 13:51:28 UTC (rev 93)
+++ trunk/src/objects/scorch.h	2005-02-23 12:47:07 UTC (rev 94)
@@ -20,7 +20,8 @@
         virtual ~Scorch();
         virtual void fall(Uint16);
         /// \brief Scorch uses his wings
-        virtual void in_sp1(Sint16);
+        virtual void idle(Uint16);
+        virtual void in_sp1();
         virtual void clearStates(bool reset=false);
     private:
         Uint8 left_wings;

Modified: trunk/src/physics.cpp
===================================================================
--- trunk/src/physics.cpp	2005-02-22 13:51:28 UTC (rev 93)
+++ trunk/src/physics.cpp	2005-02-23 12:47:07 UTC (rev 94)
@@ -9,100 +9,124 @@
 
 PhysicHandler::PhysicHandler(): 
   tstart(SDL_GetTicks()),
-  dt(0) {
+  dt(0),
+  reset_time(true),
+  Dfps(0),
+  Dframes(0),
+  currentfps(0),
+  minfps(1000) {
     tcurrent=tstart;
 }
 
 PhysicHandler::~PhysicHandler() {
 }
 
-Uint16 PhysicHandler::resetTime() {
-    dt=0;
-    return (tcurrent=SDL_GetTicks());
+void PhysicHandler::update() {
+    if (menu) {
+        reset_time=true;
+    } else if (paused) {
+        reset_time=true;
+        updatePaused();
+    } else {
+        if (reset_time) {
+            Dfps=Dframes=currentfps=dt=0;
+            minfps=1000;
+        } else {
+            dt=(SDL_GetTicks()-tcurrent);
+            updateFPS();
+        }
+        reset_time=false;
+        tcurrent=SDL_GetTicks();
+        updateGame();
+    }
 }
 
-void PhysicHandler::update() {
-    dt=(SDL_GetTicks()-tcurrent);
-    tcurrent=SDL_GetTicks();
+inline void PhysicHandler::updateGame() {
+    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
 
-    //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);
+    if ((scenario->player!=NULL) && (!(scenario->player->getState(ESTATE_BUSY)))) {
+        if (input->keyPressed(KEY_USE)) scenario->player->in_use();
+        if (input->keyPressed(KEY_ACT)) scenario->player->in_act();
+        if (input->keyPressed(KEY_LEFT))   scenario->player->in_left();
+        if (input->keyPressed(KEY_RIGHT))  scenario->player->in_right();
+        if (input->keyPressed(KEY_UP))     scenario->player->in_up();
+        if (input->keyPressed(KEY_DOWN))   scenario->player->in_down();
+        if (input->keyState(KEY_LEFT)) {
+            scenario->player->unsetState(STATE_MRIGHT);
+            scenario->player->setState(STATE_MLEFT);
+        } else {
+            scenario->player->unsetState(STATE_MLEFT);
         }
-        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;
+        if (input->keyState(KEY_RIGHT)) {
+            scenario->player->unsetState(STATE_MLEFT);
+            scenario->player->setState(STATE_MRIGHT);
+        } else {
+            scenario->player->unsetState(STATE_MRIGHT);
         }
-        obit=scenario->pool->objectspool.begin();
-        while (obit!=scenario->pool->objectspool.end()) {
-            (*obit)->idle(dt);
-            (*obit)->updateEvents(dt);
-            ++obit;
+        if ((!(scenario->player->getState(ESTATE_RUN)))||scenario->player->getState(ESTATE_ABORT)) {
+            if (input->keyPressed(KEY_SP1))  scenario->player->in_sp1();
+            if (input->keyPressed(KEY_SP2)) scenario->player->in_sp2();
         }
-        //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
+
+        if (input->keyState(KEY_LEFT))  scenario->player->in_left(dt);
+        if (input->keyState(KEY_RIGHT)) scenario->player->in_right(dt);
+        if (input->keyState(KEY_UP))    scenario->player->in_up(dt);
+        if (input->keyState(KEY_DOWN))  scenario->player->in_down(dt);
     } 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);
-        }
+        scenario->player->unsetState(STATE_MLEFT);
+        scenario->player->unsetState(STATE_MRIGHT);
     }
+    //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;
+    }
 }
+
+inline void PhysicHandler::updatePaused() {
+    if (input->keyPressed(KEY_RIGHT)) {
+        scenario->player->switchItem(true);
+    }
+    if (input->keyPressed(KEY_LEFT)) {
+        scenario->player->switchItem(false);
+    }
+    if (input->keyPressed(KEY_DROP)) {
+        scenario->player->dropItem();
+        gfxeng->update(UPDATE_ALL);
+    }
+}
+
+inline void PhysicHandler::updateFPS() {
+    Dfps+=dt;
+    ++Dframes;
+    if (Dfps>=100) {
+        currentfps=Uint16(Dframes*1000/Dfps);
+        if (currentfps < minfps) minfps=currentfps;
+        Dfps=Dframes=0;
+    }
+
+}

Modified: trunk/src/physics.h
===================================================================
--- trunk/src/physics.h	2005-02-22 13:51:28 UTC (rev 93)
+++ trunk/src/physics.h	2005-02-23 12:47:07 UTC (rev 94)
@@ -10,11 +10,20 @@
         ~PhysicHandler();
         /// Updates all game states and animations
         void update();
-        /// Resets the current time
-        /// \return New current time
-        Uint16 resetTime();
+        Uint16 getFPS() {
+            return currentfps;
+        }
+        Uint16 getMinFPS() {
+            return minfps;
+        }
     private:
         Uint16 tstart, tcurrent, dt;
+        bool reset_time;
+        Uint16 Dfps,Dframes,currentfps,minfps;
+    private:
+        inline void updateGame();
+        inline void updatePaused();
+        inline void updateFPS();
 };
 
 #endif

Modified: trunk/src/players_common.cpp
===================================================================
--- trunk/src/players_common.cpp	2005-02-22 13:51:28 UTC (rev 93)
+++ trunk/src/players_common.cpp	2005-02-23 12:47:07 UTC (rev 94)
@@ -177,9 +177,7 @@
     Character::idle(dt);
 }
 
-void Player::in_act(Sint16 dt) {
-    if (dt < 0) return;
-    input->unsetState(INPUT_ACT);
+void Player::in_act() {
     object_iterator i=enter.begin();
     while (i!=enter.end()) {
         if ((*i)->act(this)) {
@@ -190,39 +188,23 @@
     }
 }
 
-void Player::in_use(Sint16 dt) {
-    if (dt < 0) return;
-    input->unsetState(INPUT_USE);
+void Player::in_use() {
     if (items[currentitem]) {
         if (!(items[currentitem]->act(this))) sfxeng->playWAV(au_useerror);
     }
 }
 
-void Player::in_right(Sint16 dt) {
-    if (dt < 0) {
-        unsetState(STATE_MRIGHT);
-        return;
-    }
+void Player::in_right(Uint16 dt) {
     unsetState(STATE_LEFT);
-    setState(STATE_MRIGHT);
     if ((hspeed+HSPEED_MULT*dt/100)<maxspeedx) hspeed+=HSPEED_MULT*dt/100;
     else if (hspeed<maxspeedx) hspeed=maxspeedx;
 }
 
-void Player::in_left(Sint16 dt) {
-    if (dt < 0) {
-        unsetState(STATE_MLEFT);
-        return;
-    }
+void Player::in_left(Uint16 dt) {
     setState(STATE_LEFT);
-    setState(STATE_MLEFT);
     if ((hspeed-HSPEED_MULT*dt/100)>(-maxspeedx)) hspeed-=HSPEED_MULT*dt/100;
     else if (hspeed>(-maxspeedx)) hspeed=-maxspeedx;
 }
-void Player::in_up(Sint16) { }
-void Player::in_down(Sint16) { }
-void Player::in_sp1(Sint16) { }
-void Player::in_sp2(Sint16) { }
 
 Hit Player::move(Uint16 dt, bool check) {
     return Character::move(dt,check);
@@ -276,10 +258,6 @@
 }
 
 void Player::clearStates(bool reset) {
-    if (getState(STATE_MLEFT)) in_left(-1);
-    if (getState(STATE_MRIGHT)) in_right(-1);
-    if (getState(STATE_MUP)) in_up(-1);
-    if (getState(STATE_MDOWN)) in_down(-1);
     if (reset) {
         unsetState(STATE_ACT_1);
         unsetState(STATE_ACT_2);

Modified: trunk/src/players_common.h
===================================================================
--- trunk/src/players_common.h	2005-02-22 13:51:28 UTC (rev 93)
+++ trunk/src/players_common.h	2005-02-23 12:47:07 UTC (rev 94)
@@ -68,23 +68,27 @@
         //Input methods
         //@{
         /// \brief Called when using the move right key (right arrow)
-        virtual void in_right(Sint16);
+        virtual void in_right() { }
+        virtual void in_right(Uint16);
         /// \brief Called when using the move left key (left arrow)
-        virtual void in_left(Sint16);
+        virtual void in_left() { }
+        virtual void in_left(Uint16);
         /// \brief Called when using the move up key (up arrow)
-        virtual void in_up(Sint16);
+        virtual void in_up() { }
+        virtual void in_up(Uint16) { }
         /// \brief Called when using the move down key (down arrow)
-        virtual void in_down(Sint16);
+        virtual void in_down() { }
+        virtual void in_down(Uint16) { }
         /// \brief Called when using the special 1 key (space)
-        virtual void in_sp1(Sint16);
+        virtual void in_sp1() { }
         /// \brief Called when using the special 2 key (left shift)
-        virtual void in_sp2(Sint16);
+        virtual void in_sp2() { }
         /// \brief Called when using the activation key (enter)
         ///
         /// This should be the same for all players.
-        virtual void in_act(Sint16);
+        virtual void in_act();
         /// \brief Called when using the use key (insert)
-        virtual void in_use(Sint16);
+        virtual void in_use();
         //@}
     protected:
         //@{




More information about the lostpenguins-commits mailing list