Changeset 186


Ignore:
Timestamp:
Aug 29, 2010, 12:51:13 AM (10 years ago)
Author:
sam
Message:

Support tilesets larger than 512x512 and switch the coordinates system to
(0,0) at the bottom left.

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/maps/testmap2.tmx

    r185 r186  
    44  <image source="../art/outdoor.png"/>
    55 </tileset>
    6  <layer name="fond" width="32" height="32">
     6 <layer name="h0a (fond)" width="32" height="32">
    77  <data encoding="csv">
    884,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
     
    4040</data>
    4141 </layer>
    42  <layer name="murs" width="32" height="32">
     42 <layer name="v0a (murs)" width="32" height="32">
    4343  <data encoding="csv">
    44441483,1486,1483,1484,1485,1486,1483,1484,1485,1486,1483,1484,1485,1486,1483,1484,1485,1486,1483,1484,1485,1486,0,0,0,0,0,0,0,0,0,0,
     
    7676</data>
    7777 </layer>
    78  <layer name="Calque 4" width="32" height="32">
     78 <layer name="h1a (Calque 4)" width="32" height="32">
    7979  <data encoding="csv">
    80800,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     
    112112</data>
    113113 </layer>
    114  <layer name="toit" width="32" height="32">
     114 <layer name="v1a (toit)" width="32" height="32">
    115115  <data encoding="csv">
    1161160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     
    1251250,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    1261260,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    127 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,420,427,427,427,425,426,428,0,0,0,0,
    128 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,498,500,501,502,503,504,506,0,0,0,0,
    129 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,576,578,579,580,581,582,584,0,0,0,0,
    130 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,654,656,657,658,659,660,662,0,0,0,0,
    131 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,732,734,735,736,737,738,740,2764,0,0,0,
     1270,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,419,420,421,422,423,424,425,0,0,0,0,
     1280,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,497,498,499,500,501,502,503,0,0,0,0,
     1290,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,575,576,577,578,579,580,581,0,0,0,0,
     1300,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,653,654,655,656,657,658,659,0,0,0,0,
     1310,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,731,732,733,734,735,736,737,2764,0,0,0,
    1321320,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2918,2920,2921,0,0,
    1331330,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     
    148148</data>
    149149 </layer>
    150  <layer name="Calque 5" width="32" height="32">
     150 <layer name="h2a (Calque 5)" width="32" height="32">
    151151  <data encoding="csv">
    1521520,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  • trunk/src/debugsprite.cpp

    r170 r186  
    6565    int z = data->z;
    6666
     67    data->game->GetScene()->AddTile((data->tiler << 16) | 31,
     68                                    x - 16, y, z + 32, 1);
    6769    data->game->GetScene()->AddTile((data->tiler << 16) | 15,
    68                                     x - 16, y - 32, z + 32, 1);
    69     data->game->GetScene()->AddTile((data->tiler << 16) | 31,
    70                                     x - 16, y - 32, z, 1);
     70                                    x - 16, y, z, 1);
    7171}
    7272
  • trunk/src/font.cpp

    r170 r186  
    121121        if (ch != ' ')
    122122        {
     123            glTexCoord2f(tx, ty + .0625f);
     124            glVertex2f(x, y);
     125            glTexCoord2f(tx + .0625f, ty + .0625f);
     126            glVertex2f(x + data->width, y);
     127            glTexCoord2f(tx + .0625f, ty);
     128            glVertex2f(x + data->width, y + data->height);
    123129            glTexCoord2f(tx, ty);
    124             glVertex2f(x, y);
    125             glTexCoord2f(tx + .0625f, ty);
    126             glVertex2f(x + data->width, y);
    127             glTexCoord2f(tx + .0625f, ty + .0625f);
    128             glVertex2f(x + data->width, y + data->height);
    129             glTexCoord2f(tx, ty + .0625f);
    130130            glVertex2f(x, y + data->height);
    131131        }
  • trunk/src/gtk/editor.cpp

    r170 r186  
    5757    g_object_unref(G_OBJECT(builder));
    5858
    59     glmapview->LoadMap("maps/testmap.tmx");
     59    glmapview->LoadMap("maps/testmap2.tmx");
    6060    new DebugFps();
    6161
  • trunk/src/gtk/glmapview.cpp

    r180 r186  
    105105    if (mapviewer)
    106106        mapviewer->SetPOV(gtk_adjustment_get_value(hadj),
    107                           gtk_adjustment_get_value(vadj));
     107                          mapviewer->GetHeight() - glarea->allocation.height
     108                           - gtk_adjustment_get_value(vadj));
    108109
    109110    /* Tick the game */
  • trunk/src/input.cpp

    r176 r186  
    4343    Uint8 *keystate = SDL_GetKeyState(NULL);
    4444    int left = keystate[SDLK_d] - (keystate[SDLK_a] | keystate[SDLK_q]);
    45     int up = keystate[SDLK_s] - (keystate[SDLK_w] | keystate[SDLK_z]);
     45    int up = (keystate[SDLK_w] | keystate[SDLK_z]) - keystate[SDLK_s] ;
     46    f.x += left;
    4647    f.y += up;
    47     f.x += left;
    4848    if (left && up)
    4949    {
  • trunk/src/map.cpp

    r150 r186  
    9191                }
    9292
    93                 tiles[ntiles++] = code;
     93                int x = ntiles % data->width;
     94                int y = data->height - 1 - (ntiles / data->width);
     95                tiles[y * data->width + x] = code;
     96                ntiles++;
     97
    9498                while (isdigit(*parser))
    9599                    parser++;
  • trunk/src/test-map.cpp

    r170 r186  
    4646
    4747    /* Create a game */
    48     Game *game = new Game("maps/testmap.tmx");
     48    Game *game = new Game("maps/testmap2.tmx");
    4949
    5050    /* Register an input driver and some debug stuff */
  • trunk/src/tileset.cpp

    r170 r186  
    3838    char *name;
    3939    int *tiles;
    40     int ntiles;
     40    int nw, nh, ntiles;
     41    float tx, ty;
    4142
    4243    SDL_Surface *img;
     
    5354    data->name = strdup(path);
    5455    data->tiles = NULL;
    55     data->ntiles = 0;
    5656    data->img = NULL;
    5757    data->texture = 0;
     
    6666        exit(1);
    6767    }
     68
     69    data->nw = data->img->w / 32;
     70    data->nh = data->img->h / 32;
     71    data->ntiles = data->nw * data->nh;
     72    data->tx = 32.0f / data->img->w;
     73    data->ty = 32.0f / data->img->h;
    6874}
    6975
     
    114120void TileSet::BlitTile(uint32_t id, int x, int y, int z, int o)
    115121{
    116     float tx = .0625f * (id & 0xf);
    117     float ty = .0625f * ((id >> 4) & 0xf);
     122    float tx = data->tx * ((id & 0xffff) % data->nw);
     123    float ty = data->ty * ((id & 0xffff) / data->nw);
    118124
    119125    float sqrt2 = sqrtf(2.0f);
     
    124130        glBindTexture(GL_TEXTURE_2D, data->texture);
    125131        glBegin(GL_QUADS);
     132            glTexCoord2f(tx, ty + data->ty);
     133            glVertex3f(x, sqrt2 * (y - 70 + off), sqrt2 * (z + off));
     134            glTexCoord2f(tx + data->tx, ty + data->ty);
     135            glVertex3f(x + 32, sqrt2 * (y - 70 + off), sqrt2 * (z + off));
     136            glTexCoord2f(tx + data->tx, ty);
     137            glVertex3f(x + 32, sqrt2 * (y - 38), sqrt2 * z);
    126138            glTexCoord2f(tx, ty);
    127             glVertex3f(x, sqrt2 * (y + off), sqrt2 * (z + off));
    128             glTexCoord2f(tx + .0625f, ty);
    129             glVertex3f(x + 32, sqrt2 * (y + off), sqrt2 * (z + off));
    130             glTexCoord2f(tx + .0625f, ty + .0625f);
    131             glVertex3f(x + 32, sqrt2 * (y + 32), sqrt2 * z);
    132             glTexCoord2f(tx, ty + .0625f);
    133             glVertex3f(x, sqrt2 * (y + 32), sqrt2 * z);
     139            glVertex3f(x, sqrt2 * (y - 38), sqrt2 * z);
    134140        glEnd();
    135141    }
  • trunk/src/video.cpp

    r150 r186  
    4444    glMatrixMode(GL_PROJECTION);
    4545    glLoadIdentity();
    46     glOrtho(0, width, height, 0, -(width + height), width + height);
     46    glOrtho(0, width, 0, height, -(width + height), width + height);
    4747}
    4848
Note: See TracChangeset for help on using the changeset viewer.