/[enigma]/enigma/src/display.cc
ViewVC logotype

Diff of /enigma/src/display.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by dheck, Tue Jan 7 15:15:16 2003 UTC revision 1.5 by dheck, Thu Jan 9 10:15:57 2003 UTC
# Line 57  static WorldArea screen_to_world (const Line 57  static WorldArea screen_to_world (const
57  static void mark_redraw_area (const WorldArea &wa);  static void mark_redraw_area (const WorldArea &wa);
58  static void mark_update_area (const WorldArea &wa);  static void mark_update_area (const WorldArea &wa);
59  static void mark_redraw_screen();  static void mark_redraw_screen();
60    static void mark_update_screen();
61    
62    
63  static void add_active_model(Model2d *m);  static void add_active_model(Model2d *m);
# Line 403  mark_redraw_screen() Line 404  mark_redraw_screen()
404  }  }
405    
406  static void  static void
407    mark_update_world()
408    {
409        mark_update_area(WorldArea(0,0, level->width, level->height));
410    }
411    
412    static void
413  mark_update_area (const WorldArea &wa)  mark_update_area (const WorldArea &wa)
414  {  {
415      int x2 = Min(level->width, wa.x+wa.w);      int x2 = Min(level->width, wa.x+wa.w);
# Line 557  define_model (const char *name, Model2d Line 564  define_model (const char *name, Model2d
564  }  }
565    
566  /* Create a new model of type `name' by cloning the corresponding  /* Create a new model of type `name' by cloning the corresponding
567     entry in model_templates. */     entry in model_templates.
568    
569       This implementation remembers the most recently cloned object. This
570       helps performance when filling big levels with identical floor
571       tiles.
572    */
573  static Model2d *  static Model2d *
574  make_model2d (const string &name)  make_model2d (const string &name)
575  {  {
576      Model2d *m = 0;      static Model2d *last_templ=0;
577      px::Dict<Model2d*>::iterator i;      static string last_name;
578    
579      i = model_templates.find(name);      if (name!=last_name) {
580      if (i != model_templates.end())          px::Dict<Model2d*>::iterator i;
581          m = i->second->clone();          
582      else          i = model_templates.find(name);
583            if (i != model_templates.end()) {
584                last_templ = i->second;
585                last_name = name;
586            }
587        }
588    
589        Model2d *m = 0;
590        if (last_templ)
591            m = last_templ->clone();
592        if (!m)
593          fprintf(stderr, "Unknown model '%s'\n",name.c_str());          fprintf(stderr, "Unknown model '%s'\n",name.c_str());
594      return m;      return m;
595  }  }
# Line 691  ShadowLayer_Alpha::new_surface() Line 713  ShadowLayer_Alpha::new_surface()
713  {  {
714      Surface *s = 0;      Surface *s = 0;
715      if (m_surface_avail.empty()) {      if (m_surface_avail.empty()) {
716          SDL_Surface *ss = SDL_CreateRGBSurface(SDL_SWSURFACE,          SDL_Surface *ss = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_RLEACCEL,
717                                                 TileWidth, TileHeight,                                                 TileWidth, TileHeight,
718                                                 16,0,0,0,0);                                                 16,0,0,0,0);
719  // #if 0  // #if 0
# Line 748  ShadowLayer_Alpha::update (int x, int y) Line 770  ShadowLayer_Alpha::update (int x, int y)
770      Surface *s=get_cache(x,y);      Surface *s=get_cache(x,y);
771    
772      GC gc(s);      GC gc(s);
773      gc.set_color(255,255,255);      set_color (gc, 255,255,255);
774      box(gc, s->size());      box(gc, s->size());
775    
776      if (x>0&&y>0)      if (x>0&&y>0)
# Line 760  ShadowLayer_Alpha::update (int x, int y) Line 782  ShadowLayer_Alpha::update (int x, int y)
782          has_sh |= draw_stone_shade(gc, 0, -TileHeight, fields(x,y-1));          has_sh |= draw_stone_shade(gc, 0, -TileHeight, fields(x,y-1));
783      has_sh |= draw_stone_shade(gc, 0, 0, fields(x,y));      has_sh |= draw_stone_shade(gc, 0, 0, fields(x,y));
784      has_shadow (x,y) = has_sh;      has_shadow (x,y) = has_sh;
785    
786        if (!has_sh) {
787    //        m_gridcache(x,y) = 0;
788    //        dispose(s);
789        }
790  }  }
791    
792  void  void
# Line 781  ShadowLayer_Alpha::draw(GC &gc, int xpos Line 808  ShadowLayer_Alpha::draw(GC &gc, int xpos
808    
809      if (has_actor || has_shadow(x,y)) {      if (has_actor || has_shadow(x,y)) {
810          Surface *s=get_cache(x,y);          Surface *s=get_cache(x,y);
         GC gc2(buffer);  
         blit (gc2, 0,0,s);  
811                    
812          for (unsigned i=0; i<sprites.size(); ++i)          if (!has_actor) {
813          {              SDL_Surface *ss = s->get_surface();
814              Sprite *s = sprites[i];              SDL_SetColorKey(ss, SDL_SRCCOLORKEY,
815              if (s && s->layer == SPRITE_ACTOR){                              SDL_MapRGB(ss->format, 255,255,255));
816                  int sx = static_cast<int>(s->pos[0]*TileWidth)-x*TileWidth;              SDL_SetAlpha (ss, SDL_SRCALPHA, 128);
817                  int sy = static_cast<int>(s->pos[1]*TileWidth)-y*TileHeight;              blit (gc, xpos,ypos,s);
818                  s->model->draw_shade(gc2, sx, sy);              SDL_SetAlpha (ss, 0, 0);
819                SDL_SetColorKey(ss, 0,0);
820            }
821            else {
822                GC gc2(buffer);
823                blit (gc2, 0,0,s);
824                for (unsigned i=0; i<sprites.size(); ++i) {
825                    Sprite *s = sprites[i];
826                    if (s && s->layer == SPRITE_ACTOR){
827                        int sx = int(s->pos[0]*TileWidth) - x*TileWidth;
828                        int sy = int(s->pos[1]*TileWidth) - y*TileHeight;
829                        s->model->draw_shade(gc2, sx, sy);
830                    }
831              }              }
832                blit(gc, xpos, ypos, buffer);
833          }          }
         blit(gc, xpos, ypos, buffer);  
834      }      }
835  }  }
836    
# Line 916  display::NewWorld(int w, int h) Line 953  display::NewWorld(int w, int h)
953    
954      status_bar->new_world();      status_bar->new_world();
955      shadow_layer->new_world(w,h);      shadow_layer->new_world(w,h);
956      mark_redraw_screen();      mark_update_world();
957  }  }
958    
959  //----------------------------------------------------------------------  //----------------------------------------------------------------------
# Line 944  namespace Line 981  namespace
981          void tick(double dtime);          void tick(double dtime);
982          void center();          void center();
983      private:      private:
984          bool currently_scrolling;          bool   currently_scrolling;
985          V3 curpos, destpos;          V3     curpos, destpos;
986          V3 dir;          V3     dir;
987          double scrollspeed;          double scrollspeed;
988          double resttime;          double resttime;
989      };      };
# Line 954  namespace Line 991  namespace
991    
992  namespace  namespace
993  {  {
994      const SpriteId magic_spriteid = 1000000;      const SpriteId  magic_spriteid = 1000000;
995      SpriteId follow_sprite = magic_spriteid;      SpriteId        follow_sprite  = magic_spriteid;
996      FollowMode follow_mode = FOLLOW_NONE;      FollowMode      follow_mode    = FOLLOW_NONE;
997      Follow *follower = 0;      Follow         *follower       = 0;
998  }  }
999    
1000  static void  static void
# Line 1103  Follow_Scrolling::tick(double dtime) Line 1140  Follow_Scrolling::tick(double dtime)
1140              if (!scrolly_p)              if (!scrolly_p)
1141                  destpos[1] = ScrollY;                  destpos[1] = ScrollY;
1142    
1143              scrollspeed = 30;              scrollspeed = Max(30, 0);
1144              resttime = length(destpos - curpos)/scrollspeed;              resttime = length(destpos - curpos)/scrollspeed;
1145              dir = normalize(destpos - curpos);              dir = normalize(destpos - curpos);
1146          }          }
# Line 1216  mark_change(const GridLoc &l) Line 1253  mark_change(const GridLoc &l)
1253      if (l.layer == enigma::GRID_STONES)      if (l.layer == enigma::GRID_STONES)
1254          mark_update_area (Rect(l.pos.x, l.pos.y, 2,2));          mark_update_area (Rect(l.pos.x, l.pos.y, 2,2));
1255      else      else
1256          mark_update_area (Rect(l.pos.x,l.pos.y, 1,1));          mark_redraw_area (Rect(l.pos.x,l.pos.y, 1,1));
1257  }  }
1258    
1259  static Model2d*  static Model2d*

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26