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

game: convert a few View members to vec2i.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/src/game.cpp

    r673 r674  
    226226            continue;
    227227
    228         f->suggest.cx1=(f->cx1 - amount);
    229         f->suggest.cy1 = f->cy1 - amount / 2;
    230         f->suggest.cx2=(f->cx2 + amount);
    231         f->suggest.cy2 = f->cy2 + amount / 2;
     228        f->suggest.cx1=(f->m_aa.x - amount);
     229        f->suggest.cy1 = f->m_aa.y - amount / 2;
     230        f->suggest.cx2=(f->m_bb.x + amount);
     231        f->suggest.cy2 = f->m_bb.y + amount / 2;
    232232        f->suggest.shift_down = f->shift_down;
    233233        f->suggest.shift_right = f->shift_right;
     
    249249
    250250        if(f->next && f->next->local_player()
    251            && f->suggest.cy2 >= f->next->cy1)
     251           && f->suggest.cy2 >= f->next->m_aa.y)
    252252            f->suggest.send_view = 0;
    253253    }
     
    263263{
    264264    for(view *f = first_view; f; f = f->next)
    265         if(f->drawable() && pos.x >= f->cx1 && pos.y >= f->cy1
    266            && pos.x <= f->cx2 && pos.y <= f->cy2)
     265        if(f->drawable() && pos >= f->m_aa && pos <= f->m_bb)
    267266            return f;
    268267    return NULL;
     
    285284        return vec2i(-1, -1);
    286285
    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);
     286    return vec2i((pos.x - f->m_aa.x + f->xoff() * bg_xmul / bg_xdiv) / b_wid,
     287                 (pos.y - f->m_aa.y + f->yoff() * bg_ymul / bg_ydiv) / b_hi);
    289288}
    290289
     
    299298
    300299    if(dev & MAP_MODE)
    301         return vec2i((pos.x - v->cx1) * ftile_width()
     300        return vec2i((pos.x - v->m_aa.x) * ftile_width()
    302301                           / AUTOTILE_WIDTH + map_xoff * ftile_width(),
    303                      (pos.y - v->cy1) * ftile_height()
     302                     (pos.y - v->m_aa.y) * ftile_height()
    304303                           / AUTOTILE_HEIGHT + map_yoff * ftile_height());
    305304
    306     return pos - vec2i(v->cx1 - v->xoff(), v->cy1 - v->yoff());
     305    return pos - v->m_aa + vec2i(v->xoff(), v->yoff());
    307306}
    308307
     
    310309{
    311310    if (!(dev & MAP_MODE))
    312         return pos + vec2i(v->cx1 - v->xoff(), v->cy1 - v->yoff());
     311        return pos + v->m_aa - vec2i(v->xoff(), v->yoff());
    313312
    314313    vec2i tmp;
     
    318317    else if(v->focus)
    319318        tmp = vec2i(v->focus->x / ftile_width()
    320                        - (v->cx2 - v->cx1) / AUTOTILE_WIDTH / 2,
     319                       - (v->m_bb.x - v->m_aa.x) / AUTOTILE_WIDTH / 2,
    321320                    v->focus->y / ftile_height()
    322                        - (v->cy2 - v->cy1) / AUTOTILE_HEIGHT / 2);
     321                       - (v->m_bb.y - v->m_aa.y) / AUTOTILE_HEIGHT / 2);
    323322    else
    324323        tmp = vec2i(0, 0);
     
    328327
    329328    vec2i ret(pos.x * AUTOTILE_WIDTH / ftile_width()
    330                  - tmp.x * AUTOTILE_WIDTH + v->cx1,
     329                 - tmp.x * AUTOTILE_WIDTH + v->m_aa.x,
    331330              pos.y * AUTOTILE_HEIGHT / ftile_height()
    332                  - tmp.y * AUTOTILE_HEIGHT + v->cy1);
     331                 - tmp.y * AUTOTILE_HEIGHT + v->m_aa.y);
    333332    if (tmp.x > 0)
    334333        ret.x -= (v->focus->x * AUTOTILE_WIDTH / ftile_width())
     
    392391        else
    393392            first_view = new view(NULL, NULL, 0);
    394         first_view->cx1 = (xres + 1) / 2 - 155;
    395         first_view->cy1 = (yres + 1) / 2 - 95;
    396         first_view->cx2 = (xres + 1) / 2 + 155;
    397         if(total_weapons)
    398             first_view->cy2 = (yres + 1) / 2 + 68;
    399         else
    400             first_view->cy2 = (yres + 1) / 2 + 95;
     393        first_view->m_aa.x = (xres + 1) / 2 - 155;
     394        first_view->m_aa.y = (yres + 1) / 2 - 95;
     395        first_view->m_bb.x = (xres + 1) / 2 + 155;
     396        first_view->m_bb.y = (yres + 1) / 2 + (total_weapons ? 68 : 95);
    401397        d = 1;
    402398    }
     
    415411
    416412    if(playing_state(state) &&  !(dev & EDIT_MODE))
    417         wm->SetMouseShape(cache.img(c_target)->copy(), vec2i(8, 8));
     413        wm->SetMouseShape(cache.img(c_target)->copy(), vec2i(8));
    418414    else
    419         wm->SetMouseShape(cache.img(c_normal)->copy(), vec2i(1, 1));
     415        wm->SetMouseShape(cache.img(c_normal)->copy(), vec2i(1));
    420416
    421417    if(old_state == SCENE_STATE && new_state != SCENE_STATE)
     
    650646    {
    651647      if(state == SCENE_STATE)
    652         main_screen->SetClip(vec2i(v->cx1, v->cy1), vec2i(v->cx2 + 1, v->cy2 + 1));
     648        main_screen->SetClip(v->m_aa, v->m_bb + vec2i(1));
    653649      image *tit = cache.img(title_screen);
    654650      main_screen->PutImage(tit, main_screen->Size() / 2 - tit->Size() / 2);
     
    667663
    668664  if(small_render)
    669     main_screen->AddDirty(vec2i(v->cx1, v->cy1), vec2i((v->cx2 - v->cx1 + 1)*2 + v->cx1 + 1, v->cy1+(v->cy2 - v->cy1 + 1)*2 + 1));
     665    main_screen->AddDirty(v->m_aa, (v->m_bb - v->m_aa + vec2i(1)) * 2 + vec2i(v->m_aa.x, 0) + vec2i(1));
    670666  else
    671     main_screen->AddDirty(vec2i(v->cx1, v->cy1), vec2i(v->cx2 + 1, v->cy2 + 1));
     667    main_screen->AddDirty(v->m_aa, v->m_bb + vec2i(1));
    672668
    673669  if(v->draw_solid != -1)      // fill the screen and exit..
     
    675671    int c = v->draw_solid;
    676672    main_screen->Lock();
    677     for(int y = v->cy1; y <= v->cy2; y++)
    678       memset(main_screen->scan_line(y)+v->cx1, c, v->cx2 - v->cx1 + 1);
     673    for(int y = v->m_aa.y; y <= v->m_bb.y; y++)
     674      memset(main_screen->scan_line(y)+v->m_aa.x, c, v->m_bb.x - v->m_aa.x + 1);
    679675    main_screen->Unlock();
    680676    v->draw_solid = -1;
     
    682678  }
    683679
    684   int32_t old_cx1 = 0, old_cy1 = 0, old_cx2 = 0, old_cy2 = 0;   // if we do a small render, we need to restore these
    685   image *old_screen = NULL;
     680    // if we do a small render, we need to restore these
     681    vec2i old_aa(0), old_bb(0);
     682    image *old_screen = NULL;
     683
    686684  if(small_render && (dev & DRAW_LIGHTS))  // cannot do this if we skip lighting
    687685  {
    688     old_cx1 = v->cx1;
    689     old_cy1 = v->cy1;
    690     old_cx2 = v->cx2;
    691     old_cy2 = v->cy2;
    692 
    693     v->cx1 = 0;
    694     v->cy1 = 0;
    695     v->cx2 = small_render->Size().x-1;
    696     v->cy2 = small_render->Size().y-1;
     686    old_aa = v->m_aa;
     687    old_bb = v->m_bb;
     688
     689    v->m_aa = vec2i(0);
     690    v->m_bb = small_render->Size() - vec2i(1);
    697691
    698692    old_screen = main_screen;
     
    716710//  if(yoff > max_yoff) yoff = max_yoff;
    717711
    718   current_vxadd = xoff - v->cx1;
    719   current_vyadd = yoff - v->cy1;
    720 
    721   main_screen->SetClip(vec2i(v->cx1, v->cy1), vec2i(v->cx2 + 1, v->cy2 + 1));
     712  current_vxadd = xoff - v->m_aa.x;
     713  current_vyadd = yoff - v->m_aa.y;
     714
     715  main_screen->SetClip(v->m_aa, v->m_bb + vec2i(1));
    722716
    723717  nxoff = xoff * bg_xmul / bg_xdiv;
     
    725719
    726720
    727   x1 = nxoff / btile_width(); y1 = nyoff / btile_height();
    728   x2 = x1+(v->cx2 - v->cx1 + btile_width())/btile_width();
    729   y2 = y1+(v->cy2 - v->cy1 + btile_height())/btile_height();
    730 
    731 
    732   xo = v->cx1 - nxoff % btile_width();
    733   yo = v->cy1 - nyoff % btile_height();
     721  x1 = nxoff / btile_width();
     722  y1 = nyoff / btile_height();
     723  x2 = x1 + (v->m_bb.x - v->m_aa.x + btile_width()) / btile_width();
     724  y2 = y1 + (v->m_bb.y - v->m_aa.y + btile_height()) / btile_height();
     725
     726  xo = v->m_aa.x - nxoff % btile_width();
     727  yo = v->m_aa.y - nyoff % btile_height();
    734728
    735729  int xinc, yinc, draw_x, draw_y;
     
    785779    if(v->focus)
    786780    {
    787       x1 = v->focus->x / ftile_width()-(v->cx2 - v->cx1)/fw / 2;
    788       y1 = v->focus->y / ftile_height()-(v->cy2 - v->cy1)/fh / 2;
     781      x1 = v->focus->x / ftile_width() - (v->m_bb.x - v->m_aa.x) / fw / 2;
     782      y1 = v->focus->y / ftile_height() - (v->m_bb.y - v->m_aa.y) / fh / 2;
    789783    } else x1 = y1 = 0;
    790784      }
    791785      if(x1 > 0)
    792         xo = v->cx1-((v->focus->x * fw / ftile_width()) %fw);
    793       else xo = v->cx1;
     786        xo = v->m_aa.x - ((v->focus->x * fw / ftile_width()) % fw);
     787      else xo = v->m_aa.x;
    794788      if(y1 > 0)
    795         yo = v->cy1-((v->focus->y * fh / ftile_height()) %fh);
    796       else yo = v->cy1;
     789        yo = v->m_aa.y - ((v->focus->y * fh / ftile_height()) % fh);
     790      else yo = v->m_aa.y;
    797791    } else
    798792    {
    799793      fw = ftile_width();
    800794      fh = ftile_height();
    801       x1=(xoff)/fw; y1=(yoff)/fh;
    802       xo = v->cx1 - xoff % fw;
    803       yo = v->cy1 - yoff % fh;
     795      x1 = xoff / fw;
     796      y1 = yoff / fh;
     797      xo = v->m_aa.x - xoff % fw;
     798      yo = v->m_aa.y - yoff % fh;
    804799
    805800    }
     
    807802    if(y1 < 0) y1 = 0;
    808803
    809     x2 = x1+(v->cx2 - v->cx1 + fw)/fw;
    810     y2 = y1+(v->cy2 - v->cy1 + fh)/fh;
    811     if(x2 >= current_level->foreground_width())
    812       x2 = current_level->foreground_width()-1;
    813     if(y2 >= current_level->foreground_height())
    814       y2 = current_level->foreground_height()-1;
    815 
     804      x2 = x1 + (v->m_bb.x - v->m_aa.x + fw) / fw;
     805      y2 = y1 + (v->m_bb.y - v->m_aa.y + fh) / fh;
     806      x2 = Min(x2, current_level->foreground_width() - 1);
     807      y2 = Min(y2, current_level->foreground_height() - 1);
    816808
    817809    xinc = fw;
     
    987979      if(help_text_frames >= 0)
    988980      {
    989     int color;
    990 
    991     if(help_text_frames < 10)
    992         color = 2;
    993     else
    994         color = 2+(help_text_frames - 10);
    995 
    996     int x1 = v->cx1, y1 = v->cy1, x2 = v->cx2, y2 = v->cy1 + wm->font()->Size().y+10;
    997 
    998     remap_area(main_screen, x1, y1, x2, y2, white_light + 40 * 256);
    999     main_screen->Bar(vec2i(x1, y1), vec2i(x2, y1), color);
    1000     main_screen->Bar(vec2i(x1, y2), vec2i(x2, y2), color);
    1001 
    1002     wm->font()->PutString(main_screen, vec2i(x1 + 5, y1 + 5),
    1003                           help_text, color);
     981    int color = 2 + Max(0, help_text_frames - 10);
     982
     983    vec2i aa = v->m_aa;
     984    vec2i bb(v->m_bb.x, v->m_aa.y + wm->font()->Size().y + 10);
     985
     986    remap_area(main_screen, aa.x, aa.y, bb.x, bb.y, white_light + 40 * 256);
     987    main_screen->Bar(aa, vec2i(bb.x, aa.y), color);
     988    main_screen->Bar(vec2i(aa.x, bb.y), bb, color);
     989
     990    wm->font()->PutString(main_screen, aa + vec2i(5), help_text, color);
    1004991    if(color > 30)
    1005992        help_text_frames = -1;
     
    1012999    dev_cont->dev_draw(v);
    10131000    if(cache.in_use())
    1014     main_screen->PutImage(cache.img(vmm_image), vec2i(v->cx1, v->cy2 - cache.img(vmm_image)->Size().y+1));
     1001    main_screen->PutImage(cache.img(vmm_image), vec2i(v->m_aa.x, v->m_bb.y - cache.img(vmm_image)->Size().y+1));
    10151002
    10161003    if(dev & DRAW_LIGHTS)
     
    10181005      if(small_render)
    10191006      {
    1020     double_light_screen(main_screen, xoff, yoff, white_light, v->ambient, old_screen, old_cx1, old_cy1);
    1021 
    1022     v->cx1 = old_cx1;
    1023     v->cy1 = old_cy1;
    1024     v->cx2 = old_cx2;
    1025     v->cy2 = old_cy2;
     1007    double_light_screen(main_screen, xoff, yoff, white_light, v->ambient, old_screen, old_aa.x, old_aa.y);
     1008
     1009    v->m_aa = old_aa;
     1010    v->m_bb = old_bb;
    10261011    main_screen = old_screen;
    10271012      } else
     
    14471432    char str[16];
    14481433    sprintf(str, "%ld", (long)(10000.0f / avg_ms));
    1449     console_font->PutString(main_screen, vec2i(first_view->cx1, first_view->cy1), str);
     1434    console_font->PutString(main_screen, first_view->m_aa, str);
    14501435
    14511436    sprintf(str, "%d", total_active);
    1452     console_font->PutString(main_screen, vec2i(first_view->cx1, first_view->cy1 + 10), str);
     1437    console_font->PutString(main_screen, first_view->m_aa + vec2i(0, 10), str);
    14531438}
    14541439
     
    14691454      int w, h;
    14701455
    1471       w=(f->cx2 - f->cx1 + 1);
    1472       h=(f->cy2 - f->cy1 + 1);
     1456      w = (f->m_bb.x - f->m_aa.x + 1);
     1457      h = (f->m_bb.y - f->m_aa.y + 1);
    14731458
    14741459      total_active += current_level->add_drawables(f->xoff()-w / 4, f->yoff()-h / 4,
     
    14961481    {
    14971482      for(view *f = first_view; f; f = f->next)
    1498         main_screen->PutImage(cache.img(pause_image), vec2i((f->cx1 + f->cx2)/2 - cache.img(pause_image)->Size().x/2,
    1499                    f->cy1 + 5), 1);
     1483        main_screen->PutImage(cache.img(pause_image), vec2i((f->m_aa.x + f->m_bb.x) / 2 - cache.img(pause_image)->Size().x/2, f->m_aa.y + 5), 1);
    15001484    }
    15011485
     
    19071891    int w, h;
    19081892
    1909     w=(f->cx2 - f->cx1 + 1);
    1910     h=(f->cy2 - f->cy1 + 1);
     1893    w = (f->m_bb.x - f->m_aa.x + 1);
     1894    h = (f->m_bb.y - f->m_aa.y + 1);
    19111895        total_active += current_level->add_actives(f->xoff()-w / 4, f->yoff()-h / 4,
    19121896                         f->xoff()+w + w / 4, f->yoff()+h + h / 4);
Note: See TracChangeset for help on using the changeset viewer.