Ignore:
Timestamp:
Sep 12, 2011, 10:17:23 PM (8 years ago)
Author:
Sam Hocevar
Message:

core: rename vec2i to ivec2 and update matrix.h from Lol Engine.

File:
1 edited

Legend:

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

    r678 r682  
    118118                                     no_space_msg, NULL);
    119119    button *b = new button(0, 0, ID_QUIT_OK, "Quit", inf);
    120     Jwindow *no_space = wm->CreateWindow(vec2i(0), vec2i(-1), b, "ERROR");
     120    Jwindow *no_space = wm->CreateWindow(ivec2(0), ivec2(-1), b, "ERROR");
    121121
    122122    Event ev;
     
    258258}
    259259
    260 view *Game::GetView(vec2i pos)
     260view *Game::GetView(ivec2 pos)
    261261{
    262262    for(view *f = first_view; f; f = f->next)
     
    271271}
    272272
    273 vec2i Game::GetFgTile(vec2i pos)
    274 {
    275     return MouseToGame(pos) / vec2i(ftile_width(), ftile_height());
    276 }
    277 
    278 vec2i Game::GetBgTile(vec2i pos)
     273ivec2 Game::GetFgTile(ivec2 pos)
     274{
     275    return MouseToGame(pos) / ivec2(ftile_width(), ftile_height());
     276}
     277
     278ivec2 Game::GetBgTile(ivec2 pos)
    279279{
    280280    view *f = GetView(pos);
    281281    if(!f)
    282         return vec2i(-1, -1);
    283 
    284     return vec2i((pos.x - f->m_aa.x + f->xoff() * bg_xmul / bg_xdiv) / b_wid,
     282        return ivec2(-1, -1);
     283
     284    return ivec2((pos.x - f->m_aa.x + f->xoff() * bg_xmul / bg_xdiv) / b_wid,
    285285                 (pos.y - f->m_aa.y + f->yoff() * bg_ymul / bg_ydiv) / b_hi);
    286286}
    287287
    288 vec2i Game::MouseToGame(vec2i pos, view *v)
     288ivec2 Game::MouseToGame(ivec2 pos, view *v)
    289289{
    290290    if (!v)
     
    293293        v = player_list;  // if not in a view use the first one
    294294    if (!v)
    295         return vec2i(-1, -1);
     295        return ivec2(-1, -1);
    296296
    297297    if(dev & MAP_MODE)
    298         return vec2i((pos.x - v->m_aa.x) * ftile_width()
     298        return ivec2((pos.x - v->m_aa.x) * ftile_width()
    299299                           / AUTOTILE_WIDTH + map_xoff * ftile_width(),
    300300                     (pos.y - v->m_aa.y) * ftile_height()
    301301                           / AUTOTILE_HEIGHT + map_yoff * ftile_height());
    302302
    303     return pos - v->m_aa + vec2i(v->xoff(), v->yoff());
    304 }
    305 
    306 vec2i Game::GameToMouse(vec2i pos, view *v)
     303    return pos - v->m_aa + ivec2(v->xoff(), v->yoff());
     304}
     305
     306ivec2 Game::GameToMouse(ivec2 pos, view *v)
    307307{
    308308    if (!(dev & MAP_MODE))
    309         return pos + v->m_aa - vec2i(v->xoff(), v->yoff());
    310 
    311     vec2i tmp;
     309        return pos + v->m_aa - ivec2(v->xoff(), v->yoff());
     310
     311    ivec2 tmp;
    312312
    313313    if (dev & EDIT_MODE)
    314         tmp = vec2i(map_xoff, map_yoff);
     314        tmp = ivec2(map_xoff, map_yoff);
    315315    else if(v->m_focus)
    316         tmp = vec2i(v->m_focus->x / ftile_width()
     316        tmp = ivec2(v->m_focus->x / ftile_width()
    317317                       - (v->m_bb.x - v->m_aa.x) / AUTOTILE_WIDTH / 2,
    318318                    v->m_focus->y / ftile_height()
    319319                       - (v->m_bb.y - v->m_aa.y) / AUTOTILE_HEIGHT / 2);
    320320    else
    321         tmp = vec2i(0, 0);
     321        tmp = ivec2(0, 0);
    322322
    323323    tmp.x = Max(tmp.x, 0);
    324324    tmp.y = Max(tmp.y, 0);
    325325
    326     vec2i ret(pos.x * AUTOTILE_WIDTH / ftile_width()
     326    ivec2 ret(pos.x * AUTOTILE_WIDTH / ftile_width()
    327327                 - tmp.x * AUTOTILE_WIDTH + v->m_aa.x,
    328328              pos.y * AUTOTILE_HEIGHT / ftile_height()
     
    409409
    410410    if(playing_state(state) &&  !(dev & EDIT_MODE))
    411         wm->SetMouseShape(cache.img(c_target)->copy(), vec2i(8));
     411        wm->SetMouseShape(cache.img(c_target)->copy(), ivec2(8));
    412412    else
    413         wm->SetMouseShape(cache.img(c_normal)->copy(), vec2i(1));
     413        wm->SetMouseShape(cache.img(c_normal)->copy(), ivec2(1));
    414414
    415415    if(old_state == SCENE_STATE && new_state != SCENE_STATE)
     
    442442        int dx = 20, dy = 5;
    443443        image *jim = cache.img(joy_picts[but * 9+(y + 1)*3 + x + 1]);
    444         joy_win->m_surf->Bar(vec2i(dx, dy), vec2i(dx + jim->Size().x + 6,
     444        joy_win->m_surf->Bar(ivec2(dx, dy), ivec2(dx + jim->Size().x + 6,
    445445                                                  dy + jim->Size().y + 6),
    446446                             wm->black());
    447         joy_win->m_surf->PutImage(jim, vec2i(dx + 3, dy + 3));
     447        joy_win->m_surf->PutImage(jim, ivec2(dx + 3, dy + 3));
    448448
    449449        if(but)
     
    482482                      int val, int max)
    483483{
    484     screen->Bar(vec2i(x, y), vec2i(x + w - 1, y + h), wm->dark_color());
    485     screen->Bar(vec2i(x, y + 1), vec2i(x + w * val / max, y + h - 1),
     484    screen->Bar(ivec2(x, y), ivec2(x + w - 1, y + h), wm->dark_color());
     485    screen->Bar(ivec2(x, y + 1), ivec2(x + w * val / max, y + h - 1),
    486486                wm->bright_color());
    487487}
     
    636636  backtile *bt;
    637637  int x1, y1, x2, y2, x, y, xo, yo, nxoff, nyoff;
    638   vec2i caa, cbb;
     638  ivec2 caa, cbb;
    639639  main_screen->GetClip(caa, cbb);
    640640
     
    644644    {
    645645      if(state == SCENE_STATE)
    646         main_screen->SetClip(v->m_aa, v->m_bb + vec2i(1));
     646        main_screen->SetClip(v->m_aa, v->m_bb + ivec2(1));
    647647      image *tit = cache.img(title_screen);
    648648      main_screen->PutImage(tit, main_screen->Size() / 2 - tit->Size() / 2);
     
    661661
    662662  if(small_render)
    663     main_screen->AddDirty(v->m_aa, (v->m_bb - v->m_aa + vec2i(1)) * 2 + vec2i(v->m_aa.x, 0) + vec2i(1));
     663    main_screen->AddDirty(v->m_aa, (v->m_bb - v->m_aa + ivec2(1)) * 2 + ivec2(v->m_aa.x, 0) + ivec2(1));
    664664  else
    665     main_screen->AddDirty(v->m_aa, v->m_bb + vec2i(1));
     665    main_screen->AddDirty(v->m_aa, v->m_bb + ivec2(1));
    666666
    667667  if(v->draw_solid != -1)      // fill the screen and exit..
     
    677677
    678678    // if we do a small render, we need to restore these
    679     vec2i old_aa(0), old_bb(0);
     679    ivec2 old_aa(0), old_bb(0);
    680680    image *old_screen = NULL;
    681681
     
    685685    old_bb = v->m_bb;
    686686
    687     v->m_aa = vec2i(0);
    688     v->m_bb = small_render->Size() - vec2i(1);
     687    v->m_aa = ivec2(0);
     688    v->m_bb = small_render->Size() - ivec2(1);
    689689
    690690    old_screen = main_screen;
     
    711711  current_vyadd = yoff - v->m_aa.y;
    712712
    713   main_screen->SetClip(v->m_aa, v->m_bb + vec2i(1));
     713  main_screen->SetClip(v->m_aa, v->m_bb + ivec2(1));
    714714
    715715  nxoff = xoff * bg_xmul / bg_xdiv;
     
    751751    else bt = get_bg(0);
    752752
    753         main_screen->PutImage(bt->im, vec2i(draw_x, draw_y));
     753        main_screen->PutImage(bt->im, ivec2(draw_x, draw_y));
    754754//        if(!(dev & EDIT_MODE) && bt->next)
    755755//      current_level->put_bg(x, y, bt->next);
     
    810810  if(dev & DRAW_FG_LAYER)
    811811  {
    812     vec2i ncaa, ncbb;
     812    ivec2 ncaa, ncbb;
    813813    main_screen->GetClip(ncaa, ncbb);
    814814
     
    873873          if(fort_num != BLACK)
    874874          {
    875             get_fg(fort_num)->im->PutImage(main_screen, vec2i(draw_x, draw_y));
     875            get_fg(fort_num)->im->PutImage(main_screen, ivec2(draw_x, draw_y));
    876876
    877877        if(!(dev & EDIT_MODE))
     
    915915        {
    916916          if(dev & DRAW_BG_LAYER)
    917           get_fg(fort_num)->im->PutImage(main_screen, vec2i(draw_x, draw_y));
     917          get_fg(fort_num)->im->PutImage(main_screen, ivec2(draw_x, draw_y));
    918918          else
    919           get_fg(fort_num)->im->PutFilled(main_screen, vec2i(draw_x, draw_y), 0);
     919          get_fg(fort_num)->im->PutFilled(main_screen, ivec2(draw_x, draw_y), 0);
    920920
    921921          if(!(dev & EDIT_MODE))
     
    923923          else
    924924          {
    925         main_screen->Line(vec2i(draw_x, draw_y), vec2i(draw_x + xinc, draw_y + yinc), wm->bright_color());
    926         main_screen->Line(vec2i(draw_x + xinc, draw_y), vec2i(draw_x, draw_y + yinc), wm->bright_color());
     925        main_screen->Line(ivec2(draw_x, draw_y), ivec2(draw_x + xinc, draw_y + yinc), wm->bright_color());
     926        main_screen->Line(ivec2(draw_x + xinc, draw_y), ivec2(draw_x, draw_y + yinc), wm->bright_color());
    927927          }
    928928        }
     
    958958        {
    959959          d += 2;
    960           main_screen->Line(vec2i(draw_x + *(d - 2), draw_y + *(d - 1)),
    961                             vec2i(draw_x + *d, draw_y + *(d + 1)), b);
     960          main_screen->Line(ivec2(draw_x + *(d - 2), draw_y + *(d - 1)),
     961                            ivec2(draw_x + *d, draw_y + *(d + 1)), b);
    962962        }
    963         main_screen->Line(vec2i(draw_x + *d, draw_y + *(d - 1)),
    964                           vec2i(draw_x + p->data[0], draw_y + p->data[1]), b);
     963        main_screen->Line(ivec2(draw_x + *d, draw_y + *(d - 1)),
     964                          ivec2(draw_x + p->data[0], draw_y + p->data[1]), b);
    965965          }
    966966        }
     
    979979    int color = 2 + Max(0, help_text_frames - 10);
    980980
    981     vec2i aa = v->m_aa;
    982     vec2i bb(v->m_bb.x, v->m_aa.y + wm->font()->Size().y + 10);
     981    ivec2 aa = v->m_aa;
     982    ivec2 bb(v->m_bb.x, v->m_aa.y + wm->font()->Size().y + 10);
    983983
    984984    remap_area(main_screen, aa.x, aa.y, bb.x, bb.y, white_light + 40 * 256);
    985     main_screen->Bar(aa, vec2i(bb.x, aa.y), color);
    986     main_screen->Bar(vec2i(aa.x, bb.y), bb, color);
    987 
    988     wm->font()->PutString(main_screen, aa + vec2i(5), help_text, color);
     985    main_screen->Bar(aa, ivec2(bb.x, aa.y), color);
     986    main_screen->Bar(ivec2(aa.x, bb.y), bb, color);
     987
     988    wm->font()->PutString(main_screen, aa + ivec2(5), help_text, color);
    989989    if(color > 30)
    990990        help_text_frames = -1;
     
    997997    dev_cont->dev_draw(v);
    998998    if(cache.in_use())
    999     main_screen->PutImage(cache.img(vmm_image), vec2i(v->m_aa.x, v->m_bb.y - cache.img(vmm_image)->Size().y+1));
     999    main_screen->PutImage(cache.img(vmm_image), ivec2(v->m_aa.x, v->m_bb.y - cache.img(vmm_image)->Size().y+1));
    10001000
    10011001    if(dev & DRAW_LIGHTS)
     
    10411041}
    10421042
    1043 void Game::PutFg(vec2i pos, int type)
     1043void Game::PutFg(ivec2 pos, int type)
    10441044{
    10451045    if (current_level->GetFg(pos) == type)
     
    10521052}
    10531053
    1054 void Game::PutBg(vec2i pos, int type)
     1054void Game::PutBg(ivec2 pos, int type)
    10551055{
    10561056    if (current_level->GetBg(pos) == type)
     
    10861086    {
    10871087        main_screen->clear();
    1088         main_screen->PutImage(im, vec2i(xres + 1, yres + 1) / 2
     1088        main_screen->PutImage(im, ivec2(xres + 1, yres + 1) / 2
    10891089                                   - im->Size() / 2);
    10901090    }
     
    11531153    // exit() will try to delete (through the desctructor of
    11541154    // image_list in image.cpp) the image on the stack -> boom.
    1155     image *blank = new image(vec2i(2, 2));
     1155    image *blank = new image(ivec2(2, 2));
    11561156    blank->clear();
    1157     wm->SetMouseShape(blank->copy(), vec2i(0, 0)); // hide mouse
     1157    wm->SetMouseShape(blank->copy(), ivec2(0, 0)); // hide mouse
    11581158    delete blank;
    11591159    fade_in(cache.img(cdc_logo), 32);
     
    11861186
    11871187        int dx = (xres + 1) / 2 - gray->Size().x / 2, dy = (yres + 1) / 2 - gray->Size().y / 2;
    1188         main_screen->PutImage(gray, vec2i(dx, dy));
    1189         main_screen->PutImage(smoke[0], vec2i(dx + 24, dy + 5));
     1188        main_screen->PutImage(gray, ivec2(dx, dy));
     1189        main_screen->PutImage(smoke[0], ivec2(dx + 24, dy + 5));
    11901190
    11911191        fade_in(NULL, 16);
     
    12071207                break;
    12081208
    1209             main_screen->PutImage(gray, vec2i(dx, dy));
    1210             main_screen->PutImage(smoke[i % 5], vec2i(dx + 24, dy + 5));
     1209            main_screen->PutImage(gray, ivec2(dx, dy));
     1210            main_screen->PutImage(smoke[i % 5], ivec2(dx + 24, dy + 5));
    12111211            text_draw(205 - i, dx + 15, dy, dx + 320 - 15, dy + 199, str, wm->font(), cmap, wm->bright_color());
    12121212            wm->flush_screen();
     
    13251325  recalc_local_view_space();   // now that we know what size the screen is...
    13261326
    1327   dark_color = get_color(cache.img(window_colors)->Pixel(vec2i(2, 0)));
    1328   bright_color = get_color(cache.img(window_colors)->Pixel(vec2i(0, 0)));
    1329   med_color = get_color(cache.img(window_colors)->Pixel(vec2i(1, 0)));
    1330 
    1331   morph_dark_color = get_color(cache.img(window_colors)->Pixel(vec2i(2, 1)));
    1332   morph_bright_color = get_color(cache.img(window_colors)->Pixel(vec2i(0, 1)));
    1333   morph_med_color = get_color(cache.img(window_colors)->Pixel(vec2i(1, 1)));
     1327  dark_color = get_color(cache.img(window_colors)->Pixel(ivec2(2, 0)));
     1328  bright_color = get_color(cache.img(window_colors)->Pixel(ivec2(0, 0)));
     1329  med_color = get_color(cache.img(window_colors)->Pixel(ivec2(1, 0)));
     1330
     1331  morph_dark_color = get_color(cache.img(window_colors)->Pixel(ivec2(2, 1)));
     1332  morph_bright_color = get_color(cache.img(window_colors)->Pixel(ivec2(0, 1)));
     1333  morph_med_color = get_color(cache.img(window_colors)->Pixel(ivec2(1, 1)));
    13341334  morph_sel_frame_color = pal->find_closest(255, 255, 0);
    13351335  light_connection_color = morph_sel_frame_color;
     
    14331433
    14341434    sprintf(str, "%d", total_active);
    1435     console_font->PutString(main_screen, first_view->m_aa + vec2i(0, 10), str);
     1435    console_font->PutString(main_screen, first_view->m_aa + ivec2(0, 10), str);
    14361436}
    14371437
     
    14791479    {
    14801480      for(view *f = first_view; f; f = f->next)
    1481         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);
     1481        main_screen->PutImage(cache.img(pause_image), ivec2((f->m_aa.x + f->m_bb.x) / 2 - cache.img(pause_image)->Size().x/2, f->m_aa.y + 5), 1);
    14821482    }
    14831483
     
    16361636                        if(!joy_win)
    16371637                        {
    1638                             joy_win = wm->CreateWindow(vec2i(80, 50), vec2i(-1),
     1638                            joy_win = wm->CreateWindow(ivec2(80, 50), ivec2(-1),
    16391639                                    new button(70, 9, JOY_OK, "OK",
    16401640                                    new info_field(0, 30, DEV_NULL,
     
    20252025void Game::draw(int scene_mode)
    20262026{
    2027     main_screen->AddDirty(vec2i(0), vec2i(xres, yres));
     2027    main_screen->AddDirty(ivec2(0), ivec2(xres, yres));
    20282028
    20292029    main_screen->clear();
     
    20322032    {
    20332033        char const *helpstr = "ARROW KEYS CHANGE TEXT SPEED";
    2034         vec2i span = wm->font()->Size() * vec2i(strlen(helpstr), 1);
    2035         vec2i pos = (main_screen->Size() - span) / vec2i(2, 1);
    2036         wm->font()->PutString(main_screen, pos + vec2i(1),
     2034        ivec2 span = wm->font()->Size() * ivec2(strlen(helpstr), 1);
     2035        ivec2 pos = (main_screen->Size() - span) / ivec2(2, 1);
     2036        wm->font()->PutString(main_screen, pos + ivec2(1),
    20372037                              helpstr, wm->dark_color());
    20382038        wm->font()->PutString(main_screen, pos, helpstr, wm->bright_color());
Note: See TracChangeset for help on using the changeset viewer.