r169 - trunk/src

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Mon Sep 12 12:09:22 EDT 2005


Author: jonas
Date: 2005-09-12 12:09:21 -0400 (Mon, 12 Sep 2005)
New Revision: 169

Modified:
   trunk/src/editor.cpp
   trunk/src/editor.h
   trunk/src/gfxeng.cpp
   trunk/src/gfxeng.h
   trunk/src/input.cpp
   trunk/src/monsters_common.cpp
   trunk/src/objectpools.cpp
   trunk/src/objectpools.h
   trunk/src/physics.cpp
   trunk/src/players_common.cpp
Log:
Improvements of the Editor and related changes:
  o Support object selections with a visible rectangle during the selection
  o Support object movements
  o Support object previews when moving and placing
  o Introduced more buffer handling functions for changing/getting lines
  o ObjectsPool can now be used to add an object outside of the pools
  o ObjectsPool's addObject now handles all object addings,
    removed addCharacter, addPlayer, addMonster
  o GraphicsEngine has a better structured draw() function
  o GraphicsEngine's drawScene() is divided into drawGameScene() and
    drawEditScene()
  o PhysicHandler updates the editor's move_object animation
  o Monster and Players have a better default animation (anim_right/left)
  o Changed alpha values to 128 if possible to increase speed



Modified: trunk/src/editor.cpp
===================================================================
--- trunk/src/editor.cpp	2005-09-12 11:31:58 UTC (rev 168)
+++ trunk/src/editor.cpp	2005-09-12 16:09:21 UTC (rev 169)
@@ -10,27 +10,29 @@
 
 
 Editor::Editor() {
-    run_action(EDIT_RESET_ACTIONS);
     string place_name="";
     save_name="newmap.cfg";
     box=NULL;
     mask_surface=NULL;
+    move_object=NULL;
     reinit();
+    run_action(EDIT_RESET_ACTIONS);
 }
 
 Editor::~Editor() {
+    if (move_object) delete move_object;
     closeBox();
 }
 
 void Editor::reinit() {
     if (mask_surface) SDL_FreeSurface(mask_surface);
     mask_surface=gfxeng->createRGBAScreenSurface();
-    SDL_FillRect(mask_surface,0,SDL_MapRGBA(mask_surface->format,100,0,0,100));
+    //128 is a special case for an alpha value => faster
+    SDL_FillRect(mask_surface,0,SDL_MapRGBA(mask_surface->format,100,0,0,128));
     if (box) box->update();
 }
 
 void Editor::updateSelection(Sint16 x, Sint16 y) {
-    if (!select_start) return;
     select_rect.w=abs(x-select_start_x);
     select_rect.h=abs(y-select_start_y);
     if (x>select_start_x) select_rect.x=select_start_x;
@@ -39,6 +41,11 @@
     else select_rect.y=y;
 }
 
+bool Editor::updateMove(Sint16 x, Sint16 y) {
+    if (move_object) return move_object->setPos(x,y);
+    else return false;
+}
+
 void Editor::run_action(Uint32 action, Uint16 x, Uint16 y) {
     SDL_Rect shift=gfxeng->getShift();
     Sint16 xs=x-shift.x;
@@ -46,7 +53,14 @@
 
     gfxeng->update(UPDATE_ALL);
     if (action&EDIT_MOUSE_MOTION) {
-        updateSelection(xs,ys);
+        if (select_start) {
+            updateSelection(xs,ys);
+            gfxeng->update(UPDATE_ALL);
+        }
+        if (move_start) {
+            updateMove(xs,ys);
+            gfxeng->update(UPDATE_ALL);
+        }
     } else if (action&EDIT_RESET_ACTIONS) {
         for (Uint8 i=0; i<6; i++) {
             action_mouse_pressed[i]=NOTHING;
@@ -57,6 +71,10 @@
         action_mouse_pressed[SDL_BUTTON_RIGHT]=EDIT_BOX;
         action_mouse_released[SDL_BUTTON_RIGHT]=EDIT_ACT_BOX;
         select_start=false;
+        move_start=false;
+        // HACK
+        if (move_object) delete move_object;
+        move_object=NULL;
     } else if (action&EDIT_BOX) {
         setBox(new EditBox(x,y));
     } else if (action&EDIT_SEL_ACT_BOX) {
@@ -80,11 +98,14 @@
         }
         scenario->reloadMap();
     } else if (action&EDIT_PLACE_OBJECT) {
-        scenario->reloadMap();
-        if (scenario->pool->addObjectbyName(place_name,xs,ys,place_parameters)) {
+        updateMove(xs,ys);
+        if (scenario->pool->addObject(move_object)) {
             appendtoBuf(place_name+" "+itos(xs)+" "+itos(ys)+" "+putParameters(place_parameters));
         }
         place_parameters["name"]=scenario->pool->getNextObjectName(place_name);
+        editor->move_object=scenario->pool->addObjectbyName(place_name,-1000,-1000,place_parameters,true);
+        if (editor->move_object) editor->move_start=true;
+        else editor->move_start=false;
     } else if (action&EDIT_SELECT_START) {
         select_start=true;
         select_start_x=xs;
@@ -121,12 +142,64 @@
                 ++obit;
             }
         }
+    } else if (action&EDIT_MOVE_START) {
+        move_start_x=xs;
+        move_start_y=ys;
+        // HACK
+        if (move_object) delete move_object;
+        if ((move_object=scenario->pool->moveObject(scenario->getObjectAt(xs,ys)))) move_start=true;
+        else move_start=false;
+    } else if (action&EDIT_MOVE_END) {
+        if (move_object==NULL) {
+            move_start=false;
+            return;
+        }
+        updateMove(xs,ys);
+        if (scenario->pool->addObject(move_object)) {
+            istringstream tmpstream(getBufLine(move_object->getName()));
+            string name, x, y;
+            tmpstream >> name >> x >> y;
+            string nss((istreambuf_iterator<char>(tmpstream)), istreambuf_iterator<char>());
+            string newline=name+" "+itos(move_object->getPos()->x)+" "+itos(move_object->getPos()->y)+" "+nss;
+            changeBuf(newline,move_object->getName());
+        } else {
+            move_object->setPos(move_start_x,move_start_y);
+            if (!scenario->pool->addObject(move_object)) {
+                delete move_object;
+                move_object=NULL;
+                move_start=false;
+                scenario->reloadMap();
+            }
+        }
+        move_object=NULL;
+        move_start=false;
     } else { }
 }
 
 void Editor::appendtoBuf(string line) {
     scenario->mapbuf.push_back(line);
 }
+Sint16 Editor::getBufLineNr(string match) {
+    for (Uint16 linenum=0; linenum<scenario->mapbuf.size(); linenum++) {
+        if (scenario->mapbuf[linenum].find(match)!=string::npos) return linenum;
+    }
+    return -1;
+}
+string Editor::getBufLine(string match) {
+    for (Uint16 linenum=0; linenum<scenario->mapbuf.size(); linenum++) {
+        if (scenario->mapbuf[linenum].find(match)!=string::npos) {
+            return scenario->mapbuf[linenum];
+        }
+    }
+    return "";
+}
+bool Editor::changeBuf(string newline, string match) {
+    Sint16 linenum=getBufLineNr(match);
+    if (linenum<0) return false;
+    if (linenum>=(int)scenario->mapbuf.size()) return false;
+    scenario->mapbuf[linenum]=newline;
+    return true;
+}
 
 string Editor::removefromBuf(string match) {
     for (Uint16 linenum=0; linenum<scenario->mapbuf.size(); linenum++) {
@@ -230,7 +303,7 @@
     if (surface!=NULL) SDL_FreeSurface(surface);
     surface=gfxeng->createRGBASurface(area.w, area.h);
 
-    SDL_FillRect(surface,0,SDL_MapRGBA(surface->format,200,200,200,180));
+    SDL_FillRect(surface,0,SDL_MapRGBA(surface->format,200,200,200,128));
     /* create a border */
     Sint16 tmph=0;
     SDL_Rect line;
@@ -238,21 +311,21 @@
     line.y=0;
     line.w=BORDERSIZE;
     line.h=area.h;
-    SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255));
+    SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,SDL_ALPHA_OPAQUE));
     line.x=area.w-BORDERSIZE;
-    SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255));
+    SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,SDL_ALPHA_OPAQUE));
     line.x=0;
     line.y=0;
     line.w=area.w;
     line.h=BORDERSIZE;
-    SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255));
+    SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,SDL_ALPHA_OPAQUE));
     line.y=area.h-BORDERSIZE;
-    SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255));
+    SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,SDL_ALPHA_OPAQUE));
 
     /* write title */
     font_title->writeCenter(surface,title,WFONT);
     line.y=font_title->getHeight()+(int)((DFONT-line.h)/2);
-    SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,255));
+    SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,SDL_ALPHA_OPAQUE));
     line.h=LINESIZE;
 
     /* write entries */
@@ -261,12 +334,13 @@
         if (centered) font->writeCenter(surface,entries[i],tmph);
         else font->write(surface,entries[i],WFONT,tmph);
         line.y=tmph+font->getHeight()+(int)((DFONT-line.h)/2);
-        SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,180));
+        SDL_FillRect(surface,&line,SDL_MapRGBA(surface->format,100,100,100,128));
     }
 }
  
 EditBox::EditBox(Sint16 x, Sint16 y): Box(x,y) {
     title="EDIT MAP";
+    entries.push_back("Reload");
     entries.push_back("New");
     entries.push_back("Save As...");
     entries.push_back("Save");
@@ -276,6 +350,7 @@
     entries.push_back("");
     entries.push_back("Place Objects");
     entries.push_back("Select Objects");
+    entries.push_back("Move Object");
     update();
 }
 
@@ -283,6 +358,9 @@
     gfxeng->update(UPDATE_ALL);
     if (curentry==-1 || curentry >= (Sint8)entries.size()) {
         editor->closeBox();
+    } else if (entries[curentry]=="Reload") {
+        scenario->reloadMap();
+        editor->closeBox();
     } else if (entries[curentry]=="New") {
         editor->setBox(new NewMapBox(area.x,area.y));
     } else if (entries[curentry]=="Save As...") {
@@ -306,6 +384,10 @@
         editor->action_mouse_pressed[SDL_BUTTON_LEFT]=EDIT_SELECT_START;
         editor->action_mouse_released[SDL_BUTTON_LEFT]=EDIT_SELECT_END;
         editor->closeBox();
+    } else if (entries[curentry]=="Move Object") {
+        editor->action_mouse_pressed[SDL_BUTTON_LEFT]=EDIT_MOVE_START;
+        editor->action_mouse_released[SDL_BUTTON_LEFT]=EDIT_MOVE_END;
+        editor->closeBox();
     } else if (entries[curentry]=="Quit") {
         quitGame(0);
     } else {
@@ -483,6 +565,14 @@
     for (Uint8 i=0; i<einput.size(); ++i) {
         if (!einput[i].empty()) editor->place_parameters[etitles[i]]=einput[i];
     }
-    editor->action_mouse_pressed[SDL_BUTTON_LEFT]=EDIT_PLACE_OBJECT;
-    editor->closeBox();
+    if (editor->move_object) { 
+        delete editor->move_object;
+        editor->move_start=false;
+    }
+    editor->move_object=scenario->pool->addObjectbyName(editor->place_name,-1000,-1000,editor->place_parameters,true);
+    if (editor->move_object) {
+        editor->move_start=true;
+        editor->action_mouse_pressed[SDL_BUTTON_LEFT]=EDIT_PLACE_OBJECT;
+        editor->closeBox();
+    }
 }

Modified: trunk/src/editor.h
===================================================================
--- trunk/src/editor.h	2005-09-12 11:31:58 UTC (rev 168)
+++ trunk/src/editor.h	2005-09-12 16:09:21 UTC (rev 169)
@@ -10,6 +10,8 @@
 #define EDIT_REMOVE_OBJECTS 0x00000040
 #define EDIT_SELECT_START   0x00000080
 #define EDIT_SELECT_END     0x00000100
+#define EDIT_MOVE_START     0x00000200
+#define EDIT_MOVE_END       0x00000400
 
 /** \brief abstract Box base class
 
@@ -160,6 +162,9 @@
         ParameterMap place_parameters;
         /// Append a command to the buffered map file
         void appendtoBuf(string);
+        string getBufLine(string match);
+        /// Change the specified line in the buffered map file
+        bool changeBuf(string,string);
         /* TODO: add header modifiers */
         /// Remove the first line in the buffered map file matching the specified string
         string removefromBuf(string);
@@ -174,9 +179,15 @@
         SDL_Rect select_rect;
         Sint16 select_start_x;
         Sint16 select_start_y;
+        bool move_start;
+        Sint16 move_start_x;
+        Sint16 move_start_y;
         SDL_Surface* mask_surface;
+        Object* move_object;
     private:
+        Sint16 getBufLineNr(string);
         void updateSelection(Sint16 x, Sint16 y);
+        bool updateMove(Sint16 x, Sint16 y);
 };
 
 #endif

Modified: trunk/src/gfxeng.cpp
===================================================================
--- trunk/src/gfxeng.cpp	2005-09-12 11:31:58 UTC (rev 168)
+++ trunk/src/gfxeng.cpp	2005-09-12 16:09:21 UTC (rev 169)
@@ -49,49 +49,62 @@
 }
 
 void GraphicsEngine::draw() {
-    //Menu
-    if (game_mode&GAME_MENU) {
-        //Assure we have a (correct) menu background
-        if (!menubg) {
-            if (game_mode&(GAME_PLAY|GAME_EDIT)) {
+    if (game_mode&GAME_PLAY) {
+        if (game_mode&GAME_MENU) {
+            //Assure we have a (correct) menu background
+            if (!menubg || updatetype==UPDATE_ALL) setGameMenuBG();
+            if (updatetype==UPDATE_ALL) {
                 setGameMenuBG();
-            } else {
-                setMenuBG();
+                drawMenu();
+            } else if (updatetype==UPDATE_MENU) {
+                drawMenu();
             }
-        }
-        if (updatetype==UPDATE_ALL) {
-            if (game_mode&(GAME_PLAY|GAME_EDIT)) {
-                setGameMenuBG();
-            } else {
-                setMenuBG();
+        } else if (game_mode&GAME_PAUSED) {
+            if (updatetype==UPDATE_ALL) {
+                drawGameScene();
+                drawPlayerBar();
+            } else if (updatetype==UPDATE_BAR) {
+                drawPlayerBar();
             }
-            drawMenu();
-        } else if (updatetype==UPDATE_MENU) {
-            drawMenu();
-        }
-    //Paused game
-    } else if (game_mode&GAME_PAUSED) {
-        if (updatetype==UPDATE_ALL) {
-            drawScene();
+        } else {
+            drawGameScene();
             drawPlayerBar();
-        } else if (updatetype==UPDATE_BAR) {
-            drawPlayerBar();
+            drawFPS();
+            updatetype=UPDATE_ALL;
         }
-    //Not paused running game
-    } else if (game_mode&GAME_PLAY) {
-        drawScene();
-        drawPlayerBar();
-        drawFPS();
-        updatetype=UPDATE_ALL;
     } else if (game_mode&GAME_EDIT) {
-        if (show_fps) toggleFPS();
-        if (show_bar) togglePlayerBar();
-        if (!(game_mode&GAME_EDIT_NOANIM) || updatetype==UPDATE_ALL) {
-            drawScene();
+        if (game_mode&GAME_MENU) {
+            //Assure we have a (correct) menu background
+            if (!menubg || updatetype==UPDATE_ALL) setGameMenuBG();
+            if (updatetype==UPDATE_ALL) {
+                setGameMenuBG();
+                drawMenu();
+            } else if (updatetype==UPDATE_MENU) {
+                drawMenu();
+            }
+        } else if (game_mode&GAME_EDIT_NOANIM) {
+            if (updatetype==UPDATE_ALL) {
+                drawEditScene();
+                drawBox();
+            }
+        } else {
+            drawEditScene();
             drawBox();
             updatetype=UPDATE_ALL;
         }
-    } else return;
+    } else {
+        if (game_mode&GAME_MENU) {
+            //Assure we have a (correct) menu background
+            if (!menubg) setMenuBG();
+            if (updatetype==UPDATE_ALL) {
+                setMenuBG();
+                drawMenu();
+            } else if (updatetype==UPDATE_MENU) {
+                drawMenu();
+            }
+        } else return;
+    }
+
     //This is the most time consuming operation
     if (updatetype!=UPDATE_NOTHING) SDL_Flip(screen);
     updatetype=UPDATE_NOTHING;
@@ -152,20 +165,44 @@
     return shift;    
 }
 
-void GraphicsEngine::drawScene() {
+void GraphicsEngine::drawGameScene() {
+    assert(game_mode&GAME_PLAY);
     //We don't want to change pos!
     SDL_Rect tmprect,srcpos,debugrect;
-    if (game_mode&GAME_PLAY) {
-        if (scenario->player!=NULL) {
-            shift=setShift(scenario->player->getCenter());
-        } else {
-            shift.x=0;
-            shift.y=0;
+    if (scenario->player!=NULL) {
+        shift=setShift(scenario->player->getCenter());
+    } else {
+        shift.x=0;
+        shift.y=0;
+    }
+
+    tmprect=*scenario->area;
+    srcpos=scenario->background->getFrame().pos;
+    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)->getDrawPos());
+        srcpos=(*obit)->getFrame().pos;
+        SDL_BlitSurface((*obit)->getFrame().image,&srcpos,screen,shiftMapArea(tmprect,shift));
+        if (show_debug) {
+            debugrect=*(*obit)->getPos();
+            drawRectangle(debugrect,1,SDL_MapRGB(screen->format,100,20,0));
         }
-    } else if (game_mode&GAME_EDIT) {
-        SDL_FillRect(screen,NULL,0);
+        ++obit;
     }
+    if (scenario->player!=NULL) {
+        tmprect=(scenario->player->getDrawPos());
+        srcpos=scenario->player->getFrame().pos;
+        SDL_BlitSurface(scenario->player->getFrame().image,&srcpos,screen,shiftMapArea(tmprect,shift));
+    }
+}
 
+void GraphicsEngine::drawEditScene() {
+    assert(editor && game_mode&GAME_EDIT);
+    SDL_Rect tmprect,srcpos,debugrect;
+
+    SDL_FillRect(screen,NULL,0);
     tmprect=*scenario->area;
     srcpos=scenario->background->getFrame().pos;
     SDL_BlitSurface(scenario->background->getFrame().image,&srcpos,screen,shiftMapArea(tmprect,shift));
@@ -179,37 +216,44 @@
             debugrect=*(*obit)->getPos();
             drawRectangle(debugrect,1,SDL_MapRGB(screen->format,100,20,0));
         }
-        // TODO: fix this gfxeng mess
-        if (editor && game_mode&GAME_EDIT) {
-            if (editor->selection.find((*obit)->getName())!=editor->selection.end()) {
-                if (editor->mask_surface) {
-                    debugrect=*(*obit)->getPos();
-                    SDL_Rect area=debugrect;
-                    area.x=area.y=0;
-                    SDL_BlitSurface(editor->mask_surface,&area,screen,shiftMapArea(debugrect,shift));
-                } else {
-                    debugrect=*(*obit)->getPos();
-                    drawRectangle(debugrect,3,SDL_MapRGB(screen->format,100,100,0));
-                }
+        if (editor->selection.find((*obit)->getName())!=editor->selection.end()) {
+            if (editor->mask_surface) {
+                debugrect=*(*obit)->getPos();
+                SDL_Rect area=debugrect;
+                area.x=area.y=0;
+                SDL_BlitSurface(editor->mask_surface,&area,screen,shiftMapArea(debugrect,shift));
+            } else {
+                debugrect=*(*obit)->getPos();
+                drawRectangle(debugrect,3,SDL_MapRGB(screen->format,100,100,0));
             }
         }
         ++obit;
     }
-    // TODO: fix this gfxeng mess
+
+    if (editor->move_object) {
+        tmprect=editor->move_object->getDrawPos();
+        srcpos=editor->move_object->getFrame().pos;
+        SDL_BlitSurface(editor->move_object->getFrame().image,&srcpos,screen,shiftMapArea(tmprect,shift));
+
+        if (editor->mask_surface) {
+            debugrect=*(editor->move_object->getPos());
+            SDL_Rect area=debugrect;
+            area.x=area.y=0;
+            SDL_BlitSurface(editor->mask_surface,&area,screen,shiftMapArea(debugrect,shift));
+        } else {
+            debugrect=*(editor->move_object->getPos());
+            drawRectangle(debugrect,3,SDL_MapRGB(screen->format,100,100,0));
+        }
+    }
     if (editor->select_start) {
         debugrect=editor->select_rect;
         drawRectangle(debugrect,1,SDL_MapRGB(screen->format,50,50,50));
     }
-
-    if (game_mode&GAME_PLAY && scenario->player!=NULL) {
-        tmprect=(scenario->player->getDrawPos());
-        srcpos=scenario->player->getFrame().pos;
-        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() {
+    assert(game_mode&GAME_PLAY);
     if (!show_bar) return;
     //#players
     Uint8 pnum=scenario->pool->playerspool.size();
@@ -384,9 +428,9 @@
 inline void GraphicsEngine::setGameMenuBG() {
     if (menubg) SDL_FreeSurface(menubg);
     if (game_mode&GAME_PLAY) {
-        drawScene();
+        drawGameScene();
         drawPlayerBar();
-    } else if (game_mode&GAME_EDIT) drawScene();
+    } else if (game_mode&GAME_EDIT) drawEditScene();
     SDL_Flip(screen);
     
     SDL_Surface* tmp = SDL_CreateRGBSurface (
@@ -420,14 +464,8 @@
     if (menu_background) {
         menubg=menu_background;
     } else {
-        SDL_Surface* tmp = SDL_CreateRGBSurface (
-          SDL_HWSURFACE,
-          screen->w,
-          screen->h,
-          32,
-          rmask,gmask,bmask,0);
-        SDL_FillRect(tmp,NULL,SDL_MapRGB(screen->format,0,0,0));
-        menubg=SDL_DisplayFormat(tmp);
+        menubg=createRGBScreenSurface();
+        SDL_FillRect(menubg,NULL,SDL_MapRGB(menubg->format,0,0,0));
     }
 }
 
@@ -490,12 +528,24 @@
 }
 
 SDL_Surface* GraphicsEngine::createRGBASurface(Uint16 width, Uint16 height) {
+#ifdef ALPHA
     SDL_Surface* tmp_surface=SDL_CreateRGBSurface(vflags, width, height, 32, rmask, gmask, bmask, amask);
     SDL_Surface* return_surface=SDL_DisplayFormatAlpha(tmp_surface);
     SDL_FreeSurface(tmp_surface);
     return return_surface;
+#else
+    return createRGBSurface(width,height);
+#endif
 }
 
+SDL_Surface* GraphicsEngine::createRGBScreenSurface() {
+    return createRGBASurface(screen->w, screen->h);
+}
+
 SDL_Surface* GraphicsEngine::createRGBAScreenSurface() {
+#ifdef ALPHA
     return createRGBASurface(screen->w, screen->h);
+#else
+    return createRGBScreenSurface();
+#endif
 }

Modified: trunk/src/gfxeng.h
===================================================================
--- trunk/src/gfxeng.h	2005-09-12 11:31:58 UTC (rev 168)
+++ trunk/src/gfxeng.h	2005-09-12 16:09:21 UTC (rev 169)
@@ -44,6 +44,7 @@
         void drawRectangle(SDL_Rect rect, Uint8 border=1, Uint32 color=0);
         SDL_Surface* createRGBSurface(Uint16 width, Uint16 height);
         SDL_Surface* createRGBASurface(Uint16 width, Uint16 height);
+        SDL_Surface* createRGBScreenSurface();
         SDL_Surface* createRGBAScreenSurface();
     protected:
         /// masks
@@ -75,7 +76,10 @@
     protected:
         /// Draw the background and all objects in the pool. This is a very time
         /// consuming function...
-        inline void drawScene();
+        ///@{
+        inline void drawGameScene();
+        inline void drawEditScene();
+        ///@}
         /// Draw player bar
         inline void drawPlayerBar();
         /// Draw the frames per second

Modified: trunk/src/input.cpp
===================================================================
--- trunk/src/input.cpp	2005-09-12 11:31:58 UTC (rev 168)
+++ trunk/src/input.cpp	2005-09-12 16:09:21 UTC (rev 169)
@@ -221,6 +221,8 @@
                         gfxeng->update(UPDATE_ALL);
                     } else if (key==config.keybind[KEY_DEL]) {
                         editor->run_action(EDIT_REMOVE_OBJECTS);
+                    } else if (key==config.keybind[KEY_DEBUG]) {
+                        gfxeng->toggleShowDebug();
                     } else if (key==config.keybind[KEY_QUIT]) {
                         quitGame(0);
                     } else if (key==config.keybind[KEY_NOANIM]) {

Modified: trunk/src/monsters_common.cpp
===================================================================
--- trunk/src/monsters_common.cpp	2005-09-12 11:31:58 UTC (rev 168)
+++ trunk/src/monsters_common.cpp	2005-09-12 16:09:21 UTC (rev 169)
@@ -30,6 +30,8 @@
     if (!hasParam(parameters,"maxspeedy")) maxspeedy=0;
     if (hasParam(parameters,"audio_hit")) au_hit=scenario->sndcache->loadWAV(parameters["audio_hit"]);
       else au_hit=scenario->sndcache->loadWAV("monhit.wav");
+
+    animation.reset(new EmptyAnimation((state&STATE_LEFT) ? &anim_left : &anim_right));
 }
 
 Monster::~Monster() {

Modified: trunk/src/objectpools.cpp
===================================================================
--- trunk/src/objectpools.cpp	2005-09-12 11:31:58 UTC (rev 168)
+++ trunk/src/objectpools.cpp	2005-09-12 16:09:21 UTC (rev 169)
@@ -215,7 +215,7 @@
     else return empty_parameter;
 }
 
-Object* ObjectsPool::addObjectbyName(const string& obj, Sint16 x, Sint16 y, ParameterMap& objparam) {
+Object* ObjectsPool::addObjectbyName(const string& obj, Sint16 x, Sint16 y, ParameterMap& objparam, bool outside) {
     ParameterMap parameters;
     if (hasParam(objparam,"file")) {
         parameters=getFileParameters(objparam["file"]);
@@ -230,27 +230,27 @@
     //Set names...
     if (!hasParam(parameters,"name")) parameters["name"]=getNextObjectName(obj);
 
-    if      (obj=="Wall")           return (addObject(new Wall(x,y,parameters)));
-    else if (obj=="Exit")           return (addObject(new Exit(x,y,parameters)));
-    else if (obj=="Water")          return (addObject(new Water(x,y,parameters)));
-    else if (obj=="Teleporter")     return (addObject(new Teleporter(x,y,parameters)));
-    else if (obj=="Wind")           return (addObject(new Wind(x,y,parameters)));
-    else if (obj=="Geyser")         return (addObject(new Geyser(x,y,parameters)));
-    else if (obj=="Trigger")        return (addObject(new Trigger(x,y,parameters)));
-    else if (obj=="Door")           return (addObject(new Door(x,y,parameters)));
-    else if (obj=="Spike")          return (addObject(new Spike(x,y,parameters)));
-    else if (obj=="Heart")          return (addObject(new Heart(x,y,parameters)));
-    else if (obj=="Key")            return (addObject(new Key(x,y,parameters)));
-    else if (obj=="Bomb")           return (addObject(new Bomb(x,y,parameters)));
-    else if (obj=="TriggeredBomb")  return (addCharacter(new TriggeredBomb(x,y,parameters)));
-    else if (obj=="DeadPlayer")     return (addCharacter(new DeadPlayer(x,y,parameters)));
-    else if (obj=="Erik")           return (addPlayer(new Erik(x,y,parameters)));
-    else if (obj=="Olaf")           return (addPlayer(new Olaf(x,y,parameters)));
-    else if (obj=="Baleog")         return (addPlayer(new Baleog(x,y,parameters)));
-    else if (obj=="Fang")           return (addPlayer(new Fang(x,y,parameters)));  
-    else if (obj=="Scorch")         return (addPlayer(new Scorch(x,y,parameters)));
-    else if (obj=="Plant")          return (addMonster(new Plant(x,y,parameters)));
-    else if (obj=="Zombie")         return (addMonster(new Zombie(x,y,parameters)));
+    if      (obj=="Wall")           return (addObject(new Wall(x,y,parameters), outside));
+    else if (obj=="Exit")           return (addObject(new Exit(x,y,parameters), outside));
+    else if (obj=="Water")          return (addObject(new Water(x,y,parameters), outside));
+    else if (obj=="Teleporter")     return (addObject(new Teleporter(x,y,parameters), outside));
+    else if (obj=="Wind")           return (addObject(new Wind(x,y,parameters), outside));
+    else if (obj=="Geyser")         return (addObject(new Geyser(x,y,parameters), outside));
+    else if (obj=="Trigger")        return (addObject(new Trigger(x,y,parameters), outside));
+    else if (obj=="Door")           return (addObject(new Door(x,y,parameters), outside));
+    else if (obj=="Spike")          return (addObject(new Spike(x,y,parameters), outside));
+    else if (obj=="Heart")          return (addObject(new Heart(x,y,parameters), outside));
+    else if (obj=="Key")            return (addObject(new Key(x,y,parameters), outside));
+    else if (obj=="Bomb")           return (addObject(new Bomb(x,y,parameters), outside));
+    else if (obj=="TriggeredBomb")  return (addObject(new TriggeredBomb(x,y,parameters), outside));
+    else if (obj=="DeadPlayer")     return (addObject(new DeadPlayer(x,y,parameters), outside));
+    else if (obj=="Erik")           return (addObject(new Erik(x,y,parameters), outside));
+    else if (obj=="Olaf")           return (addObject(new Olaf(x,y,parameters), outside));
+    else if (obj=="Baleog")         return (addObject(new Baleog(x,y,parameters), outside));
+    else if (obj=="Fang")           return (addObject(new Fang(x,y,parameters), outside));  
+    else if (obj=="Scorch")         return (addObject(new Scorch(x,y,parameters), outside));
+    else if (obj=="Plant")          return (addObject(new Plant(x,y,parameters), outside));
+    else if (obj=="Zombie")         return (addObject(new Zombie(x,y,parameters), outside));
     else {
         cout << "Object " << obj << " unknown, skipping...\n";
         return NULL;
@@ -266,9 +266,22 @@
     return NULL;
 }
 
-Object* ObjectsPool::addObject(Object* object) {
-    if ( (object!=NULL) && (scenario->area==NULL || (scenario->checkPlace(*(object->getPos()),*scenario->area).enter==NOTHING)) ) {
+Object* ObjectsPool::addObject(Object* object, bool outside) {
+    if (outside) return object;
+    else if ( (object!=NULL) && (scenario->area==NULL || (scenario->checkPlace(*(object->getPos()),*scenario->area).enter==NOTHING)) ) {
         objectspool.insert(object);
+        if (Character* ptrc = dynamic_cast<Character*>(object)) {
+            characterspool.insert(ptrc);
+            if (Player* ptrv = dynamic_cast<Player*>(object)) {
+                playerspool.insert(ptrv);
+                if (playerspool.size()==1) {
+                    currentplayer=playerspool.begin();
+                    scenario->player=*currentplayer;
+                }
+            } else if (Monster* ptrm = dynamic_cast<Monster*>(object)) {
+                monsterspool.insert(ptrm);
+            }
+        }
         return object;
     } else {
         cout << "Couldn't place object!\n";
@@ -314,6 +327,7 @@
 }
 
 Object* ObjectsPool::moveObject(Object* object) {
+    if (object==NULL) return NULL;
     objectspool.erase(object);
     if (Character* ptrc = dynamic_cast<Character*>(object)) {
         characterspool.erase(ptrc);
@@ -330,30 +344,6 @@
     return object;
 }
 
-
-Character* ObjectsPool::addCharacter(Character* newcharacter) {
-    if ( (newcharacter!=NULL) && (scenario->checkPlace(*(newcharacter->getPos()),*scenario->area).enter==NOTHING) ) {
-        characterspool.insert(newcharacter);
-        scenario->pool->addObject(newcharacter);
-        return newcharacter;
-    } else {
-        cout << "Couldn't place character!\n";
-        return NULL;
-    }
-}
-
-Player* ObjectsPool::addPlayer(Player* newplayer) {
-    if ( (newplayer!=NULL) && (scenario->checkPlace(*(newplayer->getPos()),*scenario->area).enter==NOTHING) ) {
-        playerspool.insert(newplayer);
-        currentplayer=playerspool.begin();
-        scenario->pool->addCharacter(newplayer);
-        return newplayer;
-    } else {
-        cout << "Couldn't place player!\n";
-        return NULL;
-    }
-}
-
 Player* ObjectsPool::switchPlayer() {
     if (currentplayer != playerspool.end()) {
         sfxeng->playWAV(au_switch);
@@ -368,18 +358,6 @@
     } else return (scenario->player=NULL);
 }
 
-
-Monster* ObjectsPool::addMonster(Monster* newmonster) {
-    if ( (newmonster!=NULL) && (scenario->checkPlace(*(newmonster->getPos()),*scenario->area).enter==NOTHING) ) {
-        monsterspool.insert(newmonster);
-        scenario->pool->addCharacter(newmonster);
-        return newmonster;
-    } else {
-        cout << "Couldn't place monster!\n";
-        return NULL;
-    }
-}
-
 bool ObjectsPool::empty() {
     if (scenario->pool->objectspool.empty()) return true;
     else return false;

Modified: trunk/src/objectpools.h
===================================================================
--- trunk/src/objectpools.h	2005-09-12 11:31:58 UTC (rev 168)
+++ trunk/src/objectpools.h	2005-09-12 16:09:21 UTC (rev 169)
@@ -33,39 +33,29 @@
         /// \param x x coordinate
         /// \param y y coordinate
         /// \param parameters A map<string,string> of all parameters
+        /// \param outside True if the object shouldn't be added to the pools
         /// \return Pointer to the new entry in the objectspool or NULL if
         ///   the object was not recognized
-        Object* addObjectbyName(const string& obj, Sint16 x=0, Sint16 y=0, ParameterMap& parameters=ParameterMap());
-        //@{
-        /// Add an Object to the objectspool
+        Object* addObjectbyName(const string& obj, Sint16 x=0, Sint16 y=0, ParameterMap& parameters=ParameterMap(), bool outside=false);
+        /// Add an Object to all corresponding pools
         /// \return Pointer to the new entry in the objectspool or NULL if it failed
-        Object*            addObject(Object* object);
-        /// Add a Character to the characterspool (and objectspool)
-        /// \return Pointer to the new entry in the characterspool or NULL if it failed
-        Character*         addCharacter(Character* newcharacter);
-        /// Add a Player to the playerspool (and objects/characterspool)
-        /// \return Pointer to the new entry in the playerspool or NULL if it failed
-        Player*            addPlayer(Player* newplayer);
-        /// Add a Monster to the monsterspool
-        /// \return Pointer to the new entry in the monsterspool or NULL if it failed
-        Monster*           addMonster(Monster* newmonster);
-        //@}
+        Object* addObject(Object* object, bool outside=false);
         /// Gets an object by it's name
         /// \pre The name must be unique (otherwise it's basically random)
         /// \return Pointer to the Object or NULL if it wasn't found
-        Object*            getObject(const string& oname);
+        Object* getObject(const string& oname);
         /// Helper function to return the next available object name corresponding to the given base name
-        string             getNextObjectName(const string& basename);
+        string getNextObjectName(const string& basename);
         //@{
         /// Remove an Object (using an object_iterator) from all pools it belongs to
         /// \return object_iterator to the next entry in the pool or the end()
-        object_iterator    removeObject(object_iterator it);
+        object_iterator removeObject(object_iterator it);
         /// Remove an Object (using a pointer to it)
         /// \return object_iterator to the next entry in the pool or the end()
-        object_iterator    removeObject(Object* object);
+        object_iterator removeObject(Object* object);
         /// Detaches an Object from the objectspool
         /// \return Pointer to the detached Object
-        Object*            moveObject(Object* object);
+        Object* moveObject(Object* object);
         //@}
         /// Selects a new current player (circular from left to right) if possible
         Player* switchPlayer();

Modified: trunk/src/physics.cpp
===================================================================
--- trunk/src/physics.cpp	2005-09-12 11:31:58 UTC (rev 168)
+++ trunk/src/physics.cpp	2005-09-12 16:09:21 UTC (rev 169)
@@ -5,6 +5,7 @@
 #include "players_common.h"
 #include "scenario.h"
 #include "physics.h"
+#include "editor.h"
 
 
 PhysicHandler::PhysicHandler(): 
@@ -126,6 +127,7 @@
 }
 
 inline void PhysicHandler::updateEdit() {
+    assert(editor);
     object_iterator obit=scenario->pool->objectspool.begin();
     while (obit!=scenario->pool->objectspool.end()) {
         //remove marked objects
@@ -155,6 +157,9 @@
         } else if ((*obit)->isRunning()) (*obit)->updateAnim(dt);
         ++obit;
     }
+    if (editor->move_object) {
+        if (editor->move_object->isRunning()) editor->move_object->updateAnim(dt);
+    }
 }
 
 inline void PhysicHandler::updatePaused() {

Modified: trunk/src/players_common.cpp
===================================================================
--- trunk/src/players_common.cpp	2005-09-12 11:31:58 UTC (rev 168)
+++ trunk/src/players_common.cpp	2005-09-12 16:09:21 UTC (rev 169)
@@ -27,7 +27,7 @@
     if (hasParam(parameters,"anim_left")) anim_left=loadAnimation(getParameters(parameters["anim_left"],':'));
       else anim_left.reset(new EmptyAnimation(&anim_right));
     if (hasParam(parameters,"anim_right")) anim_right=loadAnimation(getParameters(parameters["anim_right"],':'));
-      else anim_right.reset(new EmptyAnimation());
+      else anim_right.reset(new EmptyAnimation(&anim_orig));
     if (hasParam(parameters,"anim_rock_left")) anim_rock_left=loadAnimation(getParameters(parameters["anim_rock_left"],':'));
       else anim_rock_left.reset(new EmptyAnimation(&anim_left));
     if (hasParam(parameters,"anim_rock_right")) anim_rock_right=loadAnimation(getParameters(parameters["anim_rock_right"],':'));




More information about the lostpenguins-commits mailing list