Changeset 657


Ignore:
Timestamp:
May 15, 2011, 6:22:17 AM (9 years ago)
Author:
Sam Hocevar
Message:

game: refactor the mouse/game coordinate conversion logic.

Location:
abuse/trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/TODO

    r656 r657  
    5656REFACTOR
    5757--------
    58 game_to_mouse : utiliser vec2i
     58game_to_mouse : utiliser vec2i, ftile_on btile_on
    5959console::draw_char : pareil
    6060VolumeWindow::draw_vol plus grand !!
    6161
     62dlastx, dlasty, x, y (apparemment des membres de object)
     63last_demo_mx, last_demo_my
     64get_fg ?
     65snap_x() snap_y()
     66scatter_line, ascatter_line
     67
  • abuse/trunk/src/clisp.cpp

    r656 r657  
    906906    case 49 :
    907907    {
    908       int32_t x=lnumber_value(CAR(args)->Eval()); args=CDR(args);
    909       int32_t y=lnumber_value(CAR(args)->Eval()); args=CDR(args);
    910 
    911       int32_t rx,ry;
    912       the_game->mouse_to_game(x,y,rx,ry);
    913       void *ret=NULL;
    914       {
    915     PtrRef r1(ret);
    916     push_onto_list(LNumber::Create(ry),ret);
    917     push_onto_list(LNumber::Create(rx),ret);
     908      int x = lnumber_value(CAR(args)->Eval()); args = CDR(args);
     909      int y = lnumber_value(CAR(args)->Eval()); args = CDR(args);
     910
     911      vec2i pos = the_game->MouseToGame(vec2i(x, y));
     912      void *ret = NULL;
     913      {
     914          PtrRef r1(ret);
     915          push_onto_list(LNumber::Create(pos.y), ret);
     916          push_onto_list(LNumber::Create(pos.x), ret);
    918917      }
    919918      return ret;
     
    921920    case 50 :
    922921    {
    923       int32_t x=lnumber_value(CAR(args)->Eval()); args=CDR(args);
    924       int32_t y=lnumber_value(CAR(args)->Eval()); args=CDR(args);
    925 
    926       int32_t rx,ry;
    927       the_game->game_to_mouse(x,y,current_view,rx,ry);
    928       void *ret=NULL;
    929       {
    930     PtrRef r1(ret);
    931     push_onto_list(LNumber::Create(ry),ret);
    932     push_onto_list(LNumber::Create(rx),ret);
     922      int x = lnumber_value(CAR(args)->Eval()); args=CDR(args);
     923      int y = lnumber_value(CAR(args)->Eval()); args=CDR(args);
     924
     925      vec2i pos = the_game->GameToMouse(vec2i(x, y), current_view);
     926      void *ret = NULL;
     927      {
     928        PtrRef r1(ret);
     929        push_onto_list(LNumber::Create(pos.y), ret);
     930        push_onto_list(LNumber::Create(pos.x), ret);
    933931      }
    934932      return ret;
     
    12871285    case 92 :
    12881286    {
    1289       int32_t cx1,x1=lnumber_value(CAR(args)); args=lcdr(args);
    1290       int32_t cy1,y1=lnumber_value(CAR(args)); args=lcdr(args);
    1291       int32_t cx2,x2=lnumber_value(CAR(args)); args=lcdr(args);
    1292       int32_t cy2,y2=lnumber_value(CAR(args)); args=lcdr(args);
    1293       int32_t c=lnumber_value(CAR(args));
    1294       the_game->game_to_mouse(x1,y1,current_view,cx1,cy1);
    1295       the_game->game_to_mouse(x2,y2,current_view,cx2,cy2);
    1296       main_screen->Line(vec2i(cx1, cy1), vec2i(cx2, cy2), c);
     1287      int32_t x1 = lnumber_value(CAR(args)); args = lcdr(args);
     1288      int32_t y1 = lnumber_value(CAR(args)); args = lcdr(args);
     1289      int32_t x2 = lnumber_value(CAR(args)); args = lcdr(args);
     1290      int32_t y2 = lnumber_value(CAR(args)); args = lcdr(args);
     1291      int32_t c = lnumber_value(CAR(args));
     1292      vec2i pos1 = the_game->GameToMouse(vec2i(x1, y1), current_view);
     1293      vec2i pos2 = the_game->GameToMouse(vec2i(x2, y2), current_view);
     1294      main_screen->Line(pos1, pos2, c);
    12971295      return 1;
    12981296    } break;
     
    19641962    case 234 :
    19651963    {
    1966       int32_t cx1,x1=lnumber_value(CAR(args)); args=lcdr(args);
    1967       int32_t cy1,y1=lnumber_value(CAR(args)); args=lcdr(args);
    1968       int32_t cx2,x2=lnumber_value(CAR(args)); args=lcdr(args);
    1969       int32_t cy2,y2=lnumber_value(CAR(args)); args=lcdr(args);
    1970       int32_t c=lnumber_value(CAR(args)); args=lcdr(args);
    1971       int32_t s=lnumber_value(CAR(args));
    1972       the_game->game_to_mouse(x1,y1,current_view,cx1,cy1);
    1973       the_game->game_to_mouse(x2,y2,current_view,cx2,cy2);
    1974       scatter_line(cx1,cy1,cx2,cy2,c,s);
     1964      int32_t x1 = lnumber_value(CAR(args)); args = lcdr(args);
     1965      int32_t y1 = lnumber_value(CAR(args)); args = lcdr(args);
     1966      int32_t x2 = lnumber_value(CAR(args)); args = lcdr(args);
     1967      int32_t y2 = lnumber_value(CAR(args)); args = lcdr(args);
     1968      int32_t c = lnumber_value(CAR(args)); args = lcdr(args);
     1969      int32_t s = lnumber_value(CAR(args));
     1970      vec2i pos1 = the_game->GameToMouse(vec2i(x1, y1), current_view);
     1971      vec2i pos2 = the_game->GameToMouse(vec2i(x2, y2), current_view);
     1972      scatter_line(pos1.x, pos1.y, pos2.x, pos2.y, c, s);
    19751973      return 1;
    19761974
     
    20162014    case 244 :
    20172015    {
    2018       int32_t cx1,x1=lnumber_value(CAR(args)); args=lcdr(args);
    2019       int32_t cy1,y1=lnumber_value(CAR(args)); args=lcdr(args);
    2020       int32_t cx2,x2=lnumber_value(CAR(args)); args=lcdr(args);
    2021       int32_t cy2,y2=lnumber_value(CAR(args)); args=lcdr(args);
    2022       int32_t c1=lnumber_value(CAR(args)); args=lcdr(args);
    2023       int32_t c2=lnumber_value(CAR(args)); args=lcdr(args);
    2024       int32_t s=lnumber_value(CAR(args));
    2025       the_game->game_to_mouse(x1,y1,current_view,cx1,cy1);
    2026       the_game->game_to_mouse(x2,y2,current_view,cx2,cy2);
    2027       ascatter_line(cx1,cy1,cx2,cy2,c1,c2,s);
     2016      int32_t x1 = lnumber_value(CAR(args)); args = lcdr(args);
     2017      int32_t y1 = lnumber_value(CAR(args)); args = lcdr(args);
     2018      int32_t x2 = lnumber_value(CAR(args)); args = lcdr(args);
     2019      int32_t y2 = lnumber_value(CAR(args)); args = lcdr(args);
     2020      int32_t c1 = lnumber_value(CAR(args)); args = lcdr(args);
     2021      int32_t c2 = lnumber_value(CAR(args)); args = lcdr(args);
     2022      int32_t s = lnumber_value(CAR(args));
     2023      vec2i pos1 = the_game->GameToMouse(vec2i(x1, y1), current_view);
     2024      vec2i pos2 = the_game->GameToMouse(vec2i(x2, y2), current_view);
     2025      ascatter_line(pos1.x, pos1.y, pos2.x, pos2.y, c1, c2, s);
    20282026      return 1;
    20292027
  • abuse/trunk/src/demo.cpp

    r656 r657  
    120120      if (get_packet(buf,size))              // get starting inputs
    121121      {
    122         process_packet_commands(buf,size);
    123     int32_t mx,my;
    124     the_game->game_to_mouse(player_list->pointer_x,player_list->pointer_y,player_list,mx,my);
    125     wm->SetMousePos((small_render ? 2 : 1) * vec2i(mx, my));
     122        process_packet_commands(buf, size);
     123        vec2i mouse = the_game->GameToMouse(vec2i(player_list->pointer_x,
     124                                                  player_list->pointer_y),
     125                                            player_list);
     126        wm->SetMousePos((small_render ? 2 : 1) * mouse);
    126127      }
    127128      else
  • abuse/trunk/src/dev.cpp

    r656 r657  
    491491    if (link_object)
    492492    {
    493       int32_t rx1,ry1;
    494       the_game->game_to_mouse(link_object->x,link_object->y,v,rx1,ry1);
    495       main_screen->Line(vec2i(rx1, ry1), vec2i(dlastx, dlasty), yellow);
     493      vec2i pos = the_game->GameToMouse(vec2i(link_object->x, link_object->y), v);
     494      main_screen->Line(pos, vec2i(dlastx, dlasty), yellow);
    496495    }
    497496
    498497    if (selected_light)
    499498    {
    500       image *i=cache.img(light_buttons[0]);
    501       int l=i->Size().x/2,h=i->Size().y/2;
    502       int32_t rx1,ry1;
    503       the_game->game_to_mouse(selected_light->x,selected_light->y,v,rx1,ry1);
    504       main_screen->Rectangle(vec2i(rx1 - l, ry1 - h), vec2i(rx1 + l, ry1 + h),
     499      image *im = cache.img(light_buttons[0]);
     500      vec2i pos = the_game->GameToMouse(vec2i(selected_light->x, selected_light->y), v);
     501      main_screen->Rectangle(pos - im->Size() / 2, pos + im->Size() / 2,
    505502                             wm->bright_color());
    506503    }
     
    510507      for (o=current_level->first_object(); o; o=o->next)
    511508      {
    512     the_game->game_to_mouse(o->x,o->y,current_view,x1,y1);
     509    vec2i pos = the_game->GameToMouse(vec2i(o->x, o->y), current_view);
    513510    char *nm=object_names[o->otype];
    514     console_font->put_string(main_screen,x1-strlen(nm)*console_font->width()/2,y1+2,nm);
     511    console_font->put_string(main_screen, pos.x - strlen(nm) * console_font->width() / 2, pos.y + 2, nm);
    515512      }
    516513
     
    520517      for (o=current_level->first_object(); o; o=o->next)
    521518      {
    522     the_game->game_to_mouse(o->x,o->y,current_view,x1,y1);
     519    vec2i pos1 = the_game->GameToMouse(vec2i(o->x, o->y), current_view);
    523520
    524521    int i=0;
     
    526523    {
    527524      game_object *other=o->get_object(i);
    528       the_game->game_to_mouse(other->x,other->y,current_view,x2,y2);
    529       main_screen->Line(vec2i(x1, y1), vec2i(x2, y2), wm->bright_color());
     525      vec2i pos2 = the_game->GameToMouse(vec2i(other->x, other->y), current_view);
     526      main_screen->Line(pos1, pos2, wm->bright_color());
    530527    }
    531528
     
    533530    {
    534531      light_source *l=o->get_light(i);
    535       the_game->game_to_mouse(l->x,l->y,current_view,x2,y2);
    536       main_screen->Line(vec2i(x1, y1), vec2i(x2, y2), light_connection_color);
     532      vec2i pos2 = the_game->GameToMouse(vec2i(l->x, l->y), current_view);
     533      main_screen->Line(pos1, pos2, light_connection_color);
    537534    }
    538535
     
    543540    {
    544541      selected_object->picture_space(x1,y1,x2,y2);
    545       int32_t rx1,ry1,rx2,ry2;
    546       the_game->game_to_mouse(x1,y1,v,rx1,ry1);
    547       the_game->game_to_mouse(x2,y2,v,rx2,ry2);
    548       main_screen->Rectangle(vec2i(rx1, ry1), vec2i(rx2, ry2),
    549                              wm->bright_color());
    550 
    551       the_game->game_to_mouse(selected_object->x,selected_object->y,current_view,x1,y1);
     542      vec2i pos1 = the_game->GameToMouse(vec2i(x1, y1), v);
     543      vec2i pos2 = the_game->GameToMouse(vec2i(x2, y2), v);
     544      main_screen->Rectangle(pos1, pos2, wm->bright_color());
     545
     546      pos1 = the_game->GameToMouse(vec2i(selected_object->x, selected_object->y), current_view);
    552547      for (int i=0; i<selected_object->total_objects(); i++)
    553548      {
    554     game_object *other=selected_object->get_object(i);
    555     the_game->game_to_mouse(other->x,other->y,current_view,x2,y2);
    556     main_screen->Line(vec2i(x1, y1), vec2i(x2, y2), light_connection_color);
    557       }
    558     }
    559 
    560 
     549        game_object *other = selected_object->get_object(i);
     550        pos2 = the_game->GameToMouse(vec2i(other->x, other->y), current_view);
     551        main_screen->Line(pos1, pos2, light_connection_color);
     552      }
     553    }
    561554  }
    562555}
     
    10531046  if (!strcmp(fword,"unchop"))
    10541047  {
    1055     int32_t rx,ry;
    1056     the_game->btile_on(dlastx,dlasty,rx,ry);
    1057     if (rx>=0 && ry>=0)
     1048    vec2i tile = the_game->GetBgTile(vec2i(dlastx, dlasty));
     1049    if (tile.x>=0 && tile.y>=0)
    10581050    {
    10591051      if (sscanf(command,"%s%d%d",fword,&l,&h)==3)
     
    10641056    for (y=0,i=cur_bg; y<h; y++)
    10651057          for (x=0; x<l; x++)
    1066             the_game->put_bg(rx+x,ry+y,i++);
     1058            the_game->put_bg(tile.x+x,tile.y+y,i++);
    10671059    dprintf("%dx%d\n",l,h);
    10681060      } else dprintf(symbol_str("unchop1"));
     
    11751167    if (t>=0)                                 // did we find it?
    11761168    {
    1177       int32_t rx,ry;
    1178       the_game->mouse_to_game(dlastx,dlasty,rx,ry);
    1179       edit_object=create(t,rx,ry);
     1169      vec2i pos = the_game->MouseToGame(vec2i(dlastx, dlasty));
     1170      edit_object=create(t, pos.x, pos.y);
    11801171      current_level->add_object(edit_object);
    11811172      the_game->need_refresh();
     
    12201211  if (!strcmp(fword,"fg_select"))
    12211212  {
    1222     int32_t x,y;
    1223     the_game->ftile_on(dlastx,dlasty,x,y);
    1224     if (x>=0 && y>=0 && x<current_level->foreground_width() &&
    1225     y<current_level->foreground_height())
    1226     {
    1227       cur_fg=current_level->get_fg(x,y);
     1213    vec2i tile = the_game->GetFgTile(vec2i(dlastx, dlasty));
     1214    if (tile.x >= 0 && tile.y >= 0 &&
     1215        tile.x < current_level->foreground_width() &&
     1216        tile.y < current_level->foreground_height())
     1217    {
     1218      cur_fg=current_level->get_fg(tile.x, tile.y);
    12281219      if (forew)
    12291220    ((tile_picker *)forew->read(DEV_FG_PICKER))->recenter(forew->m_surf);
     
    12341225  if (!strcmp(fword,"toggle_fg_raise"))
    12351226  {
    1236     int32_t x,y;
    1237     the_game->ftile_on(dlastx,dlasty,x,y);
    1238     if (x>=0 && y>=0 && x<current_level->foreground_width() &&
    1239     y<current_level->foreground_height())
    1240       current_level->fg_set_raised(x,y,!current_level->fg_raised(x,y));
     1227    vec2i tile = the_game->GetFgTile(vec2i(dlastx, dlasty));
     1228    if (tile.x >= 0 && tile.y >= 0 &&
     1229        tile.x < current_level->foreground_width() &&
     1230        tile.y < current_level->foreground_height())
     1231      current_level->fg_set_raised(tile.x, tile.y,!current_level->fg_raised(tile.x,tile.y));
    12411232  }
    12421233
     
    15231514  if (ev.type==EV_MOUSE_BUTTON && ev.mouse_button)
    15241515  {
    1525     int32_t gx,gy;
    1526     the_game->mouse_to_game(last_demo_mx,last_demo_my,gx,gy);
     1516    vec2i pos = the_game->MouseToGame(vec2i(last_demo_mx, last_demo_my));
    15271517    if (!current_level) return ;
    1528     current_area=current_level->area_list=new area_controller(gx,gy,
     1518    current_area=current_level->area_list=new area_controller(pos.x, pos.y,
    15291519                                  the_game->ftile_width(),
    15301520                                  the_game->ftile_height(),
     
    15641554  {
    15651555    int32_t mx=last_demo_mx,my=last_demo_my;
    1566     view *v=the_game->view_in(mx,my);
     1556    view *v = the_game->GetView(vec2i(mx, my));
    15671557    for (area_controller *a=current_level->area_list; a; a=a->next)
    15681558    {
    1569       int32_t x1,y1,x2,y2;
    1570       the_game->game_to_mouse(a->x,a->y,v,x1,y1);
    1571       the_game->game_to_mouse(a->x+a->w,a->y+a->h,v,x2,y2);
    1572       if (abs(x1-mx)<2 && abs(y1-my)<2)
    1573       { find=a;    find_top=1; }
    1574       else if (abs(x2-mx)<2 && abs(y2-my)<2)
    1575       { find=a;    find_top=0; }
     1559      vec2i pos1 = the_game->GameToMouse(vec2i(a->x, a->y), v);
     1560      vec2i pos2 = the_game->GameToMouse(vec2i(a->x + a->w, a->y + a->h), v);
     1561      if (abs(pos1.x - mx) < 2 && abs(pos1.y - my) < 2)
     1562      { find = a; find_top = 1; }
     1563      else if (abs(pos2.x - mx) < 2 && abs(pos2.y - my) < 2)
     1564      { find = a; find_top = 0; }
    15761565    }
    15771566
     
    16971686    if (ev.type==EV_MOUSE_MOVE)
    16981687    {
    1699       the_game->mouse_to_game(last_demo_mx,last_demo_my,edit_object->x,edit_object->y);
    1700       edit_object->x=snap_x(edit_object->x);
    1701       edit_object->y=snap_y(edit_object->y);
     1688      vec2i pos = the_game->MouseToGame(vec2i(last_demo_mx, last_demo_my));
     1689      edit_object->x = snap_x(pos.x);
     1690      edit_object->y = snap_y(pos.y);
    17021691      the_game->need_refresh();
    17031692    }
     
    17251714    if (ev.type==EV_MOUSE_MOVE)
    17261715    {
    1727       the_game->mouse_to_game(last_demo_mx,last_demo_my,edit_light->x,edit_light->y);
    1728       edit_light->x=snap_x(edit_light->x);
    1729       edit_light->y=snap_y(edit_light->y);
     1716      vec2i pos = the_game->MouseToGame(vec2i(last_demo_mx, last_demo_my));
     1717      edit_light->x = snap_x(pos.x);
     1718      edit_light->y = snap_y(pos.y);
    17301719
    17311720      edit_light->calc_range();
     
    18071796      if (current_area)
    18081797      {
    1809     int32_t gx,gy;
    1810     the_game->mouse_to_game(last_demo_mx,last_demo_my,gx,gy);
    1811     if (gx>current_area->x && gy>current_area->y)
    1812     {
    1813       if (gx-current_area->x!=current_area->w || gy-current_area->y!=current_area->h)
     1798    vec2i pos = the_game->MouseToGame(vec2i(last_demo_mx, last_demo_my));
     1799    if (pos.x>current_area->x && pos.y>current_area->y)
     1800    {
     1801      if (pos.x-current_area->x!=current_area->w || pos.y-current_area->y!=current_area->h)
    18141802      {
    18151803        the_game->need_refresh();
    1816         current_area->w=gx-current_area->x;
    1817         current_area->h=gy-current_area->y;
     1804        current_area->w=pos.x-current_area->x;
     1805        current_area->h=pos.y-current_area->y;
    18181806      }
    18191807    }
     
    18301818      if (current_area)
    18311819      {
    1832     int32_t gx,gy;
    1833     the_game->mouse_to_game(last_demo_mx,last_demo_my,gx,gy);
    1834     if (gx<current_area->x+current_area->w && gy<current_area->y+current_area->h)
    1835     {
    1836       if (gx!=current_area->x || gy!=current_area->y)
     1820    vec2i pos = the_game->MouseToGame(vec2i(last_demo_mx, last_demo_my));
     1821    if (pos.x<current_area->x+current_area->w && pos.y<current_area->y+current_area->h)
     1822    {
     1823      if (pos.x!=current_area->x || pos.y!=current_area->y)
    18371824      {
    18381825        the_game->need_refresh();
    1839         current_area->x=gx;
    1840         current_area->y=gy;
     1826        current_area->x=pos.x;
     1827        current_area->y=pos.y;
    18411828      }
    18421829    }
     
    18571844    if (ev.window==NULL)
    18581845    {
    1859       int32_t rx,ry;
    1860       the_game->mouse_to_game(last_demo_mx,last_demo_my,rx,ry);
     1846      vec2i pos = the_game->MouseToGame(vec2i(last_demo_mx, last_demo_my));
    18611847
    18621848      if (!(dev & MAP_MODE))
    18631849      {
    18641850        if (dev&DRAW_PEOPLE_LAYER)
    1865               selected_object=current_level->find_object(rx,ry);
     1851              selected_object=current_level->find_object(pos.x, pos.y);
    18661852        light_source *old_light=selected_light;
    1867         if (selected_object)
    1868           selected_light=NULL;
    1869         else
    1870           selected_light=find_light(rx,ry);
     1853        selected_light = selected_object ? NULL : find_light(pos.x, pos.y);
    18711854        if (selected_light!=old_light)
    18721855          the_game->need_refresh();
     
    18751858      if (edit_mode==ID_DMODE_DRAW)
    18761859      {
     1860        // FIXME: there is a bug here, the two if conditionals are the same
    18771861        if (ev.mouse_button==1 && !selected_object && !selected_light)
    18781862        {
    1879           int32_t xs,ys;
    1880           the_game->ftile_on(last_demo_mx,last_demo_my,xs,ys);
    1881           if (xs>=0 && ys>=0 && xs<current_level->foreground_width() &&
    1882           ys<current_level->foreground_height())
    1883           current_level->put_fg(xs,ys,raise_all ? make_above_tile(cur_fg) : cur_fg);
     1863          vec2i tile = the_game->GetFgTile(vec2i(last_demo_mx, last_demo_my));
     1864          if (tile.x>=0 && tile.y>=0 && tile.x<current_level->foreground_width() &&
     1865          tile.y<current_level->foreground_height())
     1866          current_level->put_fg(tile.x,tile.y,raise_all ? make_above_tile(cur_fg) : cur_fg);
    18841867          the_game->need_refresh();
    18851868        } else if (ev.mouse_button==1 && !selected_object && !selected_light)
    18861869        {
    1887           int32_t xs,ys;
    1888           the_game->btile_on(last_demo_mx,last_demo_my,xs,ys);
    1889           if (xs>=0 && ys>=0 && xs<current_level->background_width() &&
    1890           ys<current_level->background_height())
    1891           current_level->put_bg(xs,ys,cur_fg);
     1870          vec2i tile = the_game->GetBgTile(vec2i(last_demo_mx, last_demo_my));
     1871          if (tile.x>=0 && tile.y>=0 && tile.x<current_level->background_width() &&
     1872          tile.y<current_level->background_height())
     1873          current_level->put_bg(tile.x,tile.y,cur_fg);
    18921874          the_game->need_refresh();
    18931875        }
     
    19711953          if ((dev & DRAW_FG_LAYER) && ev.mouse_button==1)
    19721954          {
    1973         the_game->ftile_on(last_demo_mx,last_demo_my,x,y);
    1974         if (x>=0 && y>=0 && x<current_level->foreground_width() &&
    1975             y<current_level->foreground_height())
    1976         the_game->put_fg(x,y,raise_all ? make_above_tile(cur_fg) : cur_fg);
     1955        vec2i tile = the_game->GetFgTile(vec2i(last_demo_mx, last_demo_my));
     1956        if (tile.x>=0 && tile.y>=0 && tile.x<current_level->foreground_width() &&
     1957            tile.y<current_level->foreground_height())
     1958        the_game->put_fg(tile.x,tile.y,raise_all ? make_above_tile(cur_fg) : cur_fg);
    19771959          }
    19781960          if ((dev & DRAW_BG_LAYER) && ev.mouse_button==2)
    19791961          {
    1980         the_game->btile_on(last_demo_mx,last_demo_my,x,y);
    1981         if (x>=0 && y>=0 && x<current_level->background_width() &&
    1982             y<current_level->background_height())
    1983         the_game->put_bg(x,y,cur_bg);
     1962        vec2i tile = the_game->GetBgTile(vec2i(last_demo_mx, last_demo_my));
     1963        if (tile.x>=0 && tile.y>=0 && tile.x<current_level->background_width() &&
     1964            tile.y<current_level->background_height())
     1965        the_game->put_bg(tile.x,tile.y,cur_bg);
    19841966          }
    19851967        }
     
    25032485    case DEV_LIGHT9 :
    25042486    {
    2505       int32_t lx,ly;
    2506       the_game->mouse_to_game(last_demo_mx,last_demo_my,lx,ly);
    2507       lx=snap_x(lx);
    2508       ly=snap_y(ly);
    2509       edit_light=add_light_source(ev.message.id-DEV_LIGHT0,lx,ly,
    2510                        atoi(lightw->read(DEV_LIGHTR1)),
    2511                        atoi(lightw->read(DEV_LIGHTR2)),
    2512                        atoi(lightw->read(DEV_LIGHTW)),
    2513                        atoi(lightw->read(DEV_LIGHTH)));
     2487      vec2i pos = the_game->MouseToGame(vec2i(last_demo_mx, last_demo_my));
     2488      edit_light = add_light_source(ev.message.id - DEV_LIGHT0,
     2489                                    snap_x(pos.x), snap_y(pos.y),
     2490                                    atoi(lightw->read(DEV_LIGHTR1)),
     2491                                    atoi(lightw->read(DEV_LIGHTR2)),
     2492                                    atoi(lightw->read(DEV_LIGHTW)),
     2493                                    atoi(lightw->read(DEV_LIGHTH)));
    25142494      state=DEV_MOVE_LIGHT;
    25152495    } break;
     
    27522732        if (ev.window==NULL || ev.window==forew)
    27532733        {
    2754           the_game->ftile_on(last_demo_mx,last_demo_my,x,y);
    2755           fg_fill(cur_fg,x,y,NULL);
     2734          vec2i tile = the_game->GetFgTile(vec2i(last_demo_mx, last_demo_my));
     2735          fg_fill(cur_fg, tile.x, tile.y, NULL);
    27562736        }
    27572737      } break;
     
    28382818      case 'w' :
    28392819      {
    2840         int32_t rx,ry;
    2841         the_game->mouse_to_game(dlastx,dlasty,rx,ry);
    2842         char msg[100]; sprintf(msg,symbol_str("mouse_at"),rx,ry);
     2820        vec2i pos = the_game->MouseToGame(vec2i(dlastx, dlasty));
     2821        char msg[100]; sprintf(msg, symbol_str("mouse_at"), pos.x, pos.y);
    28432822        the_game->show_help(msg);
    28442823        the_game->need_refresh();
     
    28602839        if (current_level && player_list && player_list->focus)
    28612840        {
    2862           int32_t rx,ry;
    2863           the_game->mouse_to_game(dlastx,dlasty,rx,ry);
    2864           player_list->focus->x=rx;
    2865           player_list->focus->y=ry;
     2841          vec2i pos = the_game->MouseToGame(vec2i(dlastx, dlasty));
     2842          player_list->focus->x = pos.x;
     2843          player_list->focus->y = pos.y;
    28662844          do_command("center",ev);
    28672845          the_game->need_refresh();
     
    28702848      case 'z' : do_command("clear_weapons",ev); break;
    28712849      case 'Z' : if (dev&EDIT_MODE)
    2872       { view *v=the_game->view_in(last_demo_mx,last_demo_my);
     2850      { view *v = the_game->GetView(vec2i(last_demo_mx, last_demo_my));
    28732851        if (v)
    28742852        {
     
    31243102      case ' ' :
    31253103      {
    3126         int32_t xs,ys,xx,yy;
    3127         the_game->ftile_on(me->x,me->y,xs,ys);
    3128 
    3129         for (xx=xs; xx<xs+w; xx++)
     3104        int32_t xx, yy;
     3105        vec2i tile = the_game->GetFgTile(vec2i(me->x, me->y));
     3106
     3107        for (xx=tile.x; xx<tile.x+w; xx++)
    31303108        {
    3131           for (yy=ys; yy<ys+h; yy++)
     3109          for (yy=tile.y; yy<tile.y+h; yy++)
    31323110          {
    31333111        if (xx>=0 && yy>=0 && xx<current_level->foreground_width() &&
    31343112            yy<current_level->foreground_height())
    3135           the_game->put_fg(xx,yy,raise_all ? make_above_tile(pat[xx-xs+(yy-ys)*w]) : pat[xx-xs+(yy-ys)*w] );
     3113          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] );
    31363114          }
    31373115        }
     
    31393117      case 't' :
    31403118      {
    3141         int32_t xs,ys;
    3142         the_game->ftile_on(me->x,me->y,xs,ys);
    3143         dev_cont->fg_fill(-1,xs,ys,this);
     3119        vec2i tile = the_game->GetFgTile(vec2i(me->x, me->y));
     3120        dev_cont->fg_fill(-1, tile.x, tile.y, this);
    31443121      } break;
    31453122
  • abuse/trunk/src/game.cpp

    r656 r657  
    260260}
    261261
    262 view *Game::view_in(int mousex, int mousey)
     262view *Game::GetView(vec2i pos)
    263263{
    264264    for(view *f = first_view; f; f = f->next)
    265         if(f->drawable() && mousex >= f->cx1 && mousey >= f->cy1
    266            && mousex <= f->cx2 && mousey <= f->cy2)
     265        if(f->drawable() && pos.x >= f->cx1 && pos.y >= f->cy1
     266           && pos.x <= f->cx2 && pos.y <= f->cy2)
    267267            return f;
    268268    return NULL;
     
    274274}
    275275
    276 void Game::ftile_on(int screenx, int screeny, int32_t &x, int32_t &y)
    277 {
    278     mouse_to_game(screenx, screeny, x, y);
    279     x /= ftile_width();
    280     y /= ftile_height();
    281 }
    282 
    283 void Game::btile_on(int screenx, int screeny, int32_t &x, int32_t &y)
    284 {
    285     view *f = view_in(screenx, screeny);
    286     if(f)
    287     {
    288         x = ((int32_t)screenx - (int32_t)f->cx1
    289                 + f->xoff() * bg_xmul / bg_xdiv) / (int32_t)b_wid;
    290         y = ((int32_t)screeny - (int32_t)f->cy1
    291                 + f->yoff() * bg_ymul / bg_ydiv) / (int32_t)b_hi;
    292     }
     276vec2i Game::GetFgTile(vec2i pos)
     277{
     278    return MouseToGame(pos) / vec2i(ftile_width(), ftile_height());
     279}
     280
     281vec2i Game::GetBgTile(vec2i pos)
     282{
     283    view *f = GetView(pos);
     284    if(!f)
     285        return vec2i(-1, -1);
     286
     287    return vec2i((pos.x - f->cx1 + f->xoff() * bg_xmul / bg_xdiv) / b_wid,
     288                 (pos.y - f->cy1 + f->yoff() * bg_ymul / bg_ydiv) / b_hi);
     289}
     290
     291vec2i Game::MouseToGame(vec2i pos, view *v)
     292{
     293    if (!v)
     294        v = GetView(pos);
     295    if (!v)
     296        v = player_list;  // if not in a view use the first one
     297    if (!v)
     298        return vec2i(-1, -1);
     299
     300    if(dev & MAP_MODE)
     301        return vec2i((pos.x - v->cx1) * ftile_width()
     302                           / AUTOTILE_WIDTH + map_xoff * ftile_width(),
     303                     (pos.y - v->cy1) * ftile_height()
     304                           / AUTOTILE_HEIGHT + map_yoff * ftile_height());
     305
     306    return pos - vec2i(v->cx1 - v->xoff(), v->cy1 - v->yoff());
     307}
     308
     309vec2i Game::GameToMouse(vec2i pos, view *v)
     310{
     311    if (!(dev & MAP_MODE))
     312        return pos + vec2i(v->cx1 - v->xoff(), v->cy1 - v->yoff());
     313
     314    vec2i tmp;
     315
     316    if (dev & EDIT_MODE)
     317        tmp = vec2i(map_xoff, map_yoff);
     318    else if(v->focus)
     319        tmp = vec2i(v->focus->x / ftile_width()
     320                       - (v->cx2 - v->cx1) / AUTOTILE_WIDTH / 2,
     321                    v->focus->y / ftile_height()
     322                       - (v->cy2 - v->cy1) / AUTOTILE_HEIGHT / 2);
    293323    else
    294     {
    295         x = -1;
    296         y = -1;
    297     }
    298 }
    299 
    300 void Game::mouse_to_game(int32_t x, int32_t y,
    301                          int32_t &gamex, int32_t &gamey, view *f)
    302 {
    303     if(!f)
    304         f = view_in(x, y);
    305     if(!f)
    306         f = player_list;  // if not in a view use the first one
    307 
    308     if(f)
    309     {
    310         if(dev & MAP_MODE)
    311         {
    312             gamex = (x - (int32_t)f->cx1) * ftile_width() / AUTOTILE_WIDTH + map_xoff * ftile_width();
    313             gamey = (y - (int32_t)f->cy1) * ftile_height() / AUTOTILE_HEIGHT + map_yoff * ftile_height();
    314         }
    315         else
    316         {
    317             gamex = x - (int32_t)f->cx1 + f->xoff();
    318             gamey = y - (int32_t)f->cy1 + f->yoff();
    319         }
    320     }
    321 }
    322 
    323 void Game::game_to_mouse(int32_t gamex, int32_t gamey, view *which,
    324                          int32_t &x, int32_t &y)
    325 {
    326     if(!(dev & MAP_MODE))
    327     {
    328         x = gamex - which->xoff() + which->cx1;
    329         y = gamey - which->yoff() + which->cy1;
    330         return;
    331     }
    332 
    333     int32_t x1, y1;
    334 
    335     if(dev & EDIT_MODE)
    336     {
    337         x1 = map_xoff;
    338         y1 = map_yoff;
    339     }
    340     else
    341     {
    342         if(which->focus)
    343         {
    344             x1 = which->focus->x / ftile_width()
    345                   - (which->cx2 - which->cx1) / AUTOTILE_WIDTH / 2;
    346             y1 = which->focus->y / ftile_height()
    347                   - (which->cy2 - which->cy1) / AUTOTILE_HEIGHT / 2;
    348         }
    349         else
    350             x1 = y1 = 0;
    351     }
    352 
    353     if(x1 < 0)
    354         x1 = 0;
    355     if(y1 < 0)
    356         y1 = 0;
    357 
    358     x = gamex * AUTOTILE_WIDTH / ftile_width()
    359           - x1 * AUTOTILE_WIDTH + which->cx1;
    360     if(x1 > 0)
    361         x -= (which->focus->x * AUTOTILE_WIDTH / ftile_width())
    362                % AUTOTILE_WIDTH;
    363 
    364     y = gamey * AUTOTILE_HEIGHT / ftile_height()
    365           - y1 * AUTOTILE_HEIGHT + which->cy1;
    366     if(y1 > 0)
    367         y -= (which->focus->y * AUTOTILE_HEIGHT / ftile_height())
    368                % AUTOTILE_HEIGHT;
     324        tmp = vec2i(0, 0);
     325
     326    tmp.x = Max(tmp.x, 0);
     327    tmp.y = Max(tmp.y, 0);
     328
     329    vec2i ret(pos.x * AUTOTILE_WIDTH / ftile_width()
     330                 - tmp.x * AUTOTILE_WIDTH + v->cx1,
     331              pos.y * AUTOTILE_HEIGHT / ftile_height()
     332                 - tmp.y * AUTOTILE_HEIGHT + v->cy1);
     333    if (tmp.x > 0)
     334        ret.x -= (v->focus->x * AUTOTILE_WIDTH / ftile_width())
     335                     % AUTOTILE_WIDTH;
     336    if(tmp.y > 0)
     337        ret.y -= (v->focus->y * AUTOTILE_HEIGHT / ftile_height())
     338                     % AUTOTILE_HEIGHT;
     339
     340    return ret;
    369341}
    370342
  • abuse/trunk/src/game.h

    r643 r657  
    6363class Game
    6464{
     65public:
     66    Game(int argc, char **argv);
     67    ~Game();
     68
    6569private:
    6670  JCFont *fnt;
     
    8993  int state,zoom;
    9094
    91   Game(int argc, char **argv);
    92   ~Game();
    93 
    9495  void step();
    9596  void show_help(char const *st);
     
    106107               return cache.foret(foretiles[x]); }
    107108
    108   void ftile_on(int screenx, int screeny, int32_t &x, int32_t &y);
    109   void btile_on(int screenx, int screeny, int32_t &x, int32_t &y);
     109    vec2i GetFgTile(vec2i pos);
     110    vec2i GetBgTile(vec2i pos);
    110111  void toggle_delay();
    111112  void set_delay(int on) { no_delay=!on; }
    112113  void pan(int xv, int yv);
    113114
    114   void mouse_to_game(int32_t x, int32_t y, int32_t &gamex, int32_t &gamey, view *v=NULL);
    115   void game_to_mouse(int32_t gamex, int32_t gamey, view *which, int32_t &x, int32_t &y);
    116   view *view_in(int mousex, int mousey);
     115    vec2i MouseToGame(vec2i pos, view *v = NULL);
     116    vec2i GameToMouse(vec2i pos, view *v);
     117    view *GetView(vec2i pos);
    117118
    118119  int calc_speed();
  • abuse/trunk/src/level.cpp

    r655 r657  
    785785void level::draw_areas(view *v)
    786786{
    787   int32_t sx1,sy1,sx2,sy2;
    788   area_controller *a=area_list;
    789   for (; a; a=a->next)
    790   {
    791     int c1,c2;
    792     if (a->active)
    793     {
    794       c1=morph_sel_frame_color;
    795       c2=wm->bright_color();
    796     } else
    797     {
    798       c2=morph_sel_frame_color;
    799       c1=wm->bright_color();
    800     }
    801 
    802     the_game->game_to_mouse(a->x,a->y,v,sx1,sy1);
    803     the_game->game_to_mouse(a->x+a->w,a->y+a->h,v,sx2,sy2);
    804     main_screen->Rectangle(vec2i(sx1, sy1), vec2i(sx2, sy2), c1);
    805     main_screen->Bar(vec2i(sx1 - 1, sy1 - 1), vec2i(sx1 + 1, sy1 + 1), c2);
    806     main_screen->Bar(vec2i(sx2 - 1, sy2 - 1), vec2i(sx2 + 1, sy2 + 1), c2);
    807   }
     787    for (area_controller *a = area_list; a; a = a->next)
     788    {
     789        int c1 = a->active ? morph_sel_frame_color : wm->bright_color();
     790        int c2 = a->active ? wm->bright_color() : morph_sel_frame_color;
     791
     792        vec2i pos1 = the_game->GameToMouse(vec2i(a->x, a->y), v);
     793        vec2i pos2 = the_game->GameToMouse(vec2i(a->x + a->w, a->y + a->h), v);
     794        main_screen->Rectangle(pos1, pos2, c1);
     795        main_screen->Bar(pos1 - vec2i(1, 1), pos1 + vec2i(1, 1), c2);
     796        main_screen->Bar(pos2 - vec2i(1, 1), pos2 + vec2i(1, 1), c2);
     797    }
    808798}
    809799
  • abuse/trunk/src/morpher.cpp

    r643 r657  
    2222void morph_char::draw(game_object *who, view *v)
    2323{
    24   if (fleft)
    25   {
    26     int32_t rx,ry;
    27     the_game->game_to_mouse(who->x-(cx>>16),who->y-(cy>>16),v,rx,ry);
    28     mor->show(main_screen,rx,ry,color_table,pal,1000);
    29     cx+=dcx;
    30     cy+=dcy;
    31     fleft--;
    32   }
     24    if (fleft)
     25    {
     26        vec2i pos = the_game->GameToMouse(vec2i(who->x - (cx >> 16),
     27                                                who->y - (cy >> 16)), v);
     28        mor->show(main_screen, pos.x, pos.x, color_table, pal, 1000);
     29        cx += dcx;
     30        cy += dcy;
     31        fleft--;
     32    }
    3333}
    3434
  • abuse/trunk/src/objects.cpp

    r643 r657  
    378378void game_object::draw_above(view *v)
    379379{
    380   int32_t x1,y1,x2,y2,sy1,sy2,sx,i;
     380  int32_t x1, y1, x2, y2;
    381381  picture_space(x1,y1,x2,y2);
    382382
    383   the_game->game_to_mouse(x1,y1,v,sx,sy2);
    384   if (sy2>=v->cy1)
    385   {
    386     int32_t draw_to=y1-(sy2-v->cy1),tmp=x;
    387     current_level->foreground_intersect(x,y1,tmp,draw_to);
    388     the_game->game_to_mouse(x1,draw_to,v,i,sy1);     // calculate sy1
    389 
    390     sy1 = Max(v->cy1, sy1);
    391     sy2 = Min(v->cy2, sy2);
    392     TransImage *p=picture();
    393 
    394     for (i=sy1; i<=sy2; i++)
    395       p->PutScanLine(main_screen,vec2i(sx,i),0);
     383  vec2i pos1 = the_game->GameToMouse(vec2i(x1, y1), v);
     384  if (pos1.y >= v->cy1)
     385  {
     386    int32_t draw_to = y1 - (pos1.y - v->cy1), tmp = x;
     387    current_level->foreground_intersect(x, y1, tmp, draw_to);
     388    // calculate pos2.y
     389    vec2i pos2 = the_game->GameToMouse(vec2i(x1, draw_to), v);
     390
     391    pos2.y = Max(v->cy1, pos2.y);
     392    pos1.y = Min(v->cy2, pos1.y);
     393    TransImage *p = picture();
     394
     395    for (int i = pos2.y; i <= pos1.y; i++)
     396      p->PutScanLine(main_screen, vec2i(pos1.x, i), 0);
    396397  }
    397398}
  • abuse/trunk/src/view.cpp

    r651 r657  
    341341{
    342342    int sug_x,sug_y,sug_b1,sug_b2,sug_b3,sug_b4;
    343     int32_t sug_px,sug_py;
     343    vec2i sug_p(0, 0);
    344344
    345345// NOTE:(AK) I have commented this out so we don't use the lisp
     
    384384        if( focus )
    385385        {
    386             the_game->mouse_to_game( last_demo_mx, last_demo_my, sug_px, sug_py, this );
    387             if( last_demo_mbut & 1 )
     386            sug_p = the_game->MouseToGame(vec2i(last_demo_mx, last_demo_my));
     387            if(last_demo_mbut & 1)
    388388                sug_b2 = 1;
    389             if( last_demo_mbut & 2 )
     389            if(last_demo_mbut & 2)
    390390                sug_b1 = 1;
    391391        }
    392         else
    393             sug_px = sug_py = 0;
    394392    }
    395393
     
    439437        mflags |= 128;
    440438
    441     base->packet.write_uint8( mflags );
    442     base->packet.write_uint16((uint16_t)((int16_t)sug_px));
    443     base->packet.write_uint16((uint16_t)((int16_t)sug_py));
     439    base->packet.write_uint8(mflags);
     440    base->packet.write_uint16((uint16_t)sug_p.x);
     441    base->packet.write_uint16((uint16_t)sug_p.y);
    444442}
    445443
Note: See TracChangeset for help on using the changeset viewer.