Changeset 666


Ignore:
Timestamp:
May 16, 2011, 2:37:11 AM (9 years ago)
Author:
Sam Hocevar
Message:

game: refactor the GetFg? methods to use vec2i.

Location:
abuse/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/TODO

    r665 r666  
    6161  - scale_put, scale_put_trans
    6262  - tint_area, darken_area
     63  - fg_width, etc.
    6364
    6465Jwindow::_x1 _x2
     
    7071
    7172x, y in game_object?
    72 get_fg ?
    7373snap_x() snap_y()
    7474scatter_line, ascatter_line
  • abuse/trunk/src/clisp.cpp

    r658 r666  
    16681668        lbreak("%d %d is out of range of fg map",x,y);
    16691669      else
    1670         current_level->put_fg(x,y,type);
     1670        current_level->PutFg(vec2i(x, y), type);
    16711671    } break;
    16721672    case 193 :
     
    16761676      if (x<0 || y<0 || x>=current_level->foreground_width() || y>=current_level->foreground_width())
    16771677        lbreak("%d %d is out of range of fg map",x,y);
    1678       else return current_level->get_fg(x,y);
     1678      else return current_level->GetFg(vec2i(x, y));
    16791679    } break;
    16801680    case 194 :
     
    16861686        lbreak("%d %d is out of range of fg map",x,y);
    16871687      else
    1688         current_level->put_bg(x,y,type);
     1688        current_level->PutBg(vec2i(x, y), type);
    16891689    } break;
    16901690    case 195 :
     
    16941694      if (x<0 || y<0 || x>=current_level->background_width() || y>=current_level->background_width())
    16951695        lbreak("%d %d is out of range of fg map",x,y);
    1696       else return current_level->get_bg(x,y);
     1696      else return current_level->GetBg(vec2i(x, y));
    16971697    } break;
    16981698    case 196 : load_tiles(args); break;
  • abuse/trunk/src/dev.cpp

    r665 r666  
    10571057    for (y=0,i=cur_bg; y<h; y++)
    10581058          for (x=0; x<l; x++)
    1059             the_game->put_bg(tile.x+x,tile.y+y,i++);
     1059            the_game->PutBg(tile + vec2i(x, y), i++);
    10601060    dprintf("%dx%d\n",l,h);
    10611061      } else dprintf(symbol_str("unchop1"));
     
    12171217        tile.y < current_level->foreground_height())
    12181218    {
    1219       cur_fg=current_level->get_fg(tile.x, tile.y);
     1219      cur_fg=current_level->GetFg(tile);
    12201220      if (forew)
    12211221    ((tile_picker *)forew->read(DEV_FG_PICKER))->recenter(forew->m_surf);
     
    18621862          if (tile.x>=0 && tile.y>=0 && tile.x<current_level->foreground_width() &&
    18631863          tile.y<current_level->foreground_height())
    1864           current_level->put_fg(tile.x,tile.y,raise_all ? make_above_tile(cur_fg) : cur_fg);
     1864          current_level->PutFg(tile, raise_all ? make_above_tile(cur_fg) : cur_fg);
    18651865          the_game->need_refresh();
    18661866        } else if (ev.mouse_button==1 && !selected_object && !selected_light)
     
    18691869          if (tile.x>=0 && tile.y>=0 && tile.x<current_level->background_width() &&
    18701870          tile.y<current_level->background_height())
    1871           current_level->put_bg(tile.x,tile.y,cur_fg);
     1871          current_level->PutBg(tile, cur_fg);
    18721872          the_game->need_refresh();
    18731873        }
     
    19541954        if (tile.x>=0 && tile.y>=0 && tile.x<current_level->foreground_width() &&
    19551955            tile.y<current_level->foreground_height())
    1956         the_game->put_fg(tile.x,tile.y,raise_all ? make_above_tile(cur_fg) : cur_fg);
     1956        the_game->PutFg(tile, raise_all ? make_above_tile(cur_fg) : cur_fg);
    19571957          }
    19581958          if ((dev & DRAW_BG_LAYER) && ev.mouse_button==2)
     
    19611961        if (tile.x>=0 && tile.y>=0 && tile.x<current_level->background_width() &&
    19621962            tile.y<current_level->background_height())
    1963         the_game->put_bg(tile.x,tile.y,cur_bg);
     1963        the_game->PutBg(tile, cur_bg);
    19641964          }
    19651965        }
     
    31093109        if (xx>=0 && yy>=0 && xx<current_level->foreground_width() &&
    31103110            yy<current_level->foreground_height())
    3111           the_game->put_fg(xx,yy,raise_all ? make_above_tile(pat[xx-tile.x+(yy-tile.y)*w]) : pat[xx-tile.x+(yy-tile.y)*w] );
     3111          the_game->PutFg(vec2i(xx, yy), raise_all ? make_above_tile(pat[xx-tile.x+(yy-tile.y)*w]) : pat[xx-tile.x+(yy-tile.y)*w] );
    31123112          }
    31133113        }
  • abuse/trunk/src/game.cpp

    r665 r666  
    544544}
    545545
    546 void Game::put_block_fg(int x, int y, TransImage *im)
    547 {
    548   for(view *f = first_view; f; f = f->next)
    549   {
    550     if(f->drawable())
    551     {
    552       int xoff = f->xoff(), yoff = f->yoff(), viewx1 = f->cx1, viewy1 = f->cy1, viewx2 = f->cx2, viewy2 = f->cy2;
    553       if(xoff / ftile_width()>x || xoff / ftile_width()+(viewx2 - viewx1)/ftile_width()+1 < x ||
    554       yoff / ftile_height()>y || yoff / ftile_height()+(viewy2 - viewy1)/ftile_height()+1 < y) return;
    555       vec2i caa, cbb;
    556       main_screen->GetClip(caa, cbb);
    557       main_screen->SetClip(vec2i(viewx1, viewy1), vec2i(viewx2 + 1, viewy2 + 1));
    558       im->PutImage(main_screen, vec2i((x - xoff / ftile_width())*ftile_width()+viewx1 - xoff % ftile_width(),
    559             (y - yoff / ftile_height())*ftile_height()+viewy1 - yoff % ftile_height()));
    560       main_screen->SetClip(caa, cbb);
    561     }
    562   }
    563 }
    564 
    565 void Game::put_block_bg(int x, int y, image *im)
    566 {
    567   for(view *f = first_view; f; f = f->next)
    568   {
    569     if(f->drawable())
    570     {
    571       int xoff = f->xoff(), yoff = f->yoff(), viewx1 = f->cx1, viewy1 = f->cy1, viewx2 = f->cx2, viewy2 = f->cy2;
    572       int xo = xoff * bg_xmul / bg_xdiv;
    573       int yo = yoff * bg_ymul / bg_ydiv;
    574 
    575       if(xo / btile_width()>x || xo / btile_width()+(viewx2 - viewx1)/btile_width()+1 < x ||
    576       yo / btile_height()>y || yo / btile_height()+(viewy2 - viewy1)/btile_height()+1 < y) return;
    577       vec2i caa, cbb;
    578       main_screen->GetClip(caa, cbb);
    579       main_screen->SetClip(vec2i(viewx1, viewy1), vec2i(viewx2 + 1, viewy2 + 1));
    580       main_screen->PutImage(im, vec2i((x - xo / btile_width())*btile_width()+viewx1 - xo % btile_width(),
    581             (y - yo / btile_height())*btile_height()+viewy1 - yo % btile_height()), 0);
    582       main_screen->SetClip(caa, cbb);
    583     }
    584   }
    585 }
    586 
    587546int need_delay = 1;
    588547
     
    10991058}
    11001059
    1101 void Game::put_fg(int x, int y, int type)
    1102 {
    1103   if(current_level->get_fg(x, y)!=type)
    1104   {
    1105     current_level->put_fg(x, y, type);
     1060void Game::PutFg(vec2i pos, int type)
     1061{
     1062    if (current_level->GetFg(pos) == type)
     1063        return;
     1064
     1065    current_level->PutFg(pos, type);
    11061066    for(view *f = first_view; f; f = f->next)
    1107       if(f->drawable())
    1108         draw_map(f);
    1109   }
    1110 }
    1111 
    1112 void Game::put_bg(int x, int y, int type)
    1113 {
    1114   if(current_level->get_bg(x, y)!=type)
    1115   {
    1116     current_level->put_bg(x, y, type);
     1067        if(f->drawable())
     1068            draw_map(f);
     1069}
     1070
     1071void Game::PutBg(vec2i pos, int type)
     1072{
     1073    if (current_level->GetBg(pos) == type)
     1074        return;
     1075
     1076    current_level->PutBg(pos, type);
    11171077    for(view *f = first_view; f; f = f->next)
    1118       if(f->drawable())
    1119         draw_map(f);
    1120   }
     1078        if(f->drawable())
     1079            draw_map(f);
    11211080}
    11221081
  • abuse/trunk/src/game.h

    r657 r666  
    125125
    126126
    127   void put_fg(int x, int y, int type);
    128   void put_bg(int x, int y, int type);
     127    void PutFg(vec2i pos, int type);
     128    void PutBg(vec2i pos, int type);
    129129  void draw_map(view *v, int interpolate=0);
    130130  void dev_scroll();
    131   void put_block_fg(int x, int y, TransImage *im);
    132   void put_block_bg(int x, int y, image *im);
    133 
    134131
    135132  int in_area(Event &ev, int x1, int y1, int x2, int y2);
     
    137134  void set_level(level *nl);
    138135  void show_time();
    139   tile_type get_map_bg(int x, int y) { return current_level->get_bg(x,y); }
    140   tile_type get_map_fg(int x, int y) { return current_level->get_fg(x,y); }
     136    tile_type GetMapBg(vec2i pos) { return current_level->GetBg(pos); }
     137    tile_type GetMapFg(vec2i pos) { return current_level->GetFg(pos); }
    141138  void end_session();
    142139  void need_refresh() { refresh=1; }       // for development mode only
     
    156153  void request_level_load(char *name);
    157154  void request_end();
    158 } ;
     155};
    159156
    160157extern int playing_state(int state);
  • abuse/trunk/src/level.cpp

    r657 r666  
    844844  for (y=0; y<miny; y++)
    845845    for (x=0; x<minx; x++)
    846       new_fg[x+y*w]=get_fg(x,y);
     846      new_fg[x+y*w]=GetFg(vec2i(x, y));
    847847
    848848  miny=(nbh<bg_height) ? nbh : bg_height;
     
    851851  for (y=0; y<miny; y++)
    852852    for (x=0; x<minx; x++)
    853       new_bg[x+y*nbw]=get_bg(x,y);
     853      new_bg[x+y*nbw]=GetBg(vec2i(x, y));
    854854
    855855  free(map_fg);
     
    26382638    for (by=blocky1; by<=blocky2; by++)
    26392639    {
    2640       block=the_game->get_map_fg(bx,by);
     2640      block=the_game->GetMapFg(vec2i(bx, by));
    26412641      if (block>BLACK)        // don't check BLACK, should be no points in it
    26422642      {
     
    27122712  for (by=blocky1; by<=blocky2; by++,y1-=f_hi,y2-=f_hi,y_addback+=f_hi)
    27132713  {
    2714     block=the_game->get_map_fg(bx,by);
     2714    block=the_game->GetMapFg(vec2i(bx, by));
    27152715
    27162716    // now check the all the line segments in the block
  • abuse/trunk/src/level.h

    r555 r666  
    117117  uint16_t *get_fgline(int y) { CHECK(y>=0 && y<fg_height); return map_fg+y*fg_width; }
    118118  uint16_t *get_bgline(int y) { CHECK(y>=0 && y<bg_height); return map_bg+y*bg_width; }
    119   uint16_t get_fg(int x, int y) { if (x>=0 && y>=0 && x<fg_width && y<fg_height)
    120                               return fgvalue(*(map_fg+x+y*fg_width));
     119  uint16_t GetFg(vec2i pos) { if (pos >= vec2i(0) && pos < vec2i(fg_width, fg_height))
     120                              return fgvalue(*(map_fg+pos.x+pos.y*fg_width));
    121121                                    else return 0;
    122122                      }
    123   uint16_t get_bg(int x, int y) { if (x>=0 && y>=0 && x<bg_width && y<bg_height)
    124                       return *(map_bg+x+y*bg_width);
     123  uint16_t GetBg(vec2i pos) { if (pos >= vec2i(0) && pos < vec2i(bg_width, bg_height))
     124                      return *(map_bg+pos.x+pos.y*bg_width);
    125125                                     else return 0;
    126126                    }
    127   void put_fg(int x, int y, uint16_t tile) { *(map_fg+x+y*fg_width)=tile; }
    128   void put_bg(int x, int y, uint16_t tile) { *(map_bg+x+y*bg_width)=tile; }
     127  void PutFg(vec2i pos, uint16_t tile) { *(map_fg+pos.x+pos.y*fg_width)=tile; }
     128  void PutBg(vec2i pos, uint16_t tile) { *(map_bg+pos.x+pos.y*bg_width)=tile; }
    129129  void draw_objects(view *v);
    130130  void interpolate_draw_objects(view *v);
Note: See TracChangeset for help on using the changeset viewer.